Просмотр исходного кода

增加禁饮禁食提示接口信息

wangzl 3 месяцев назад
Родитель
Сommit
0a09648d16

+ 47 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/enums/FastingEnums.java

@@ -0,0 +1,47 @@
+package cn.tr.module.smart.common.enums;
+
+import lombok.Getter;
+
+import java.util.EnumSet;
+
+/**
+ * TODO
+ *
+ * @author wangzl
+ * @date 2025/9/19 9:46
+ */
+@Getter
+public enum FastingEnums {
+
+    // 定义所有区间(起始值,结束值,描述)
+    RANGE_0_2(0, 2, "清水", "%s后可以少量饮用清水,一般不超过体重的5mL/kg"),
+    RANGE_2_4(2, 4, "母乳", "%s后可以喂养母乳,但不要过量喂养"),
+    RANGE_4_6(4, 6, "固体食物", "%s后可以食用配方奶粉、牛奶和易消化的固体食物,但同样要按照正常的饮食量进食,不宜过量进食"),
+    RANGE_6_8(6, 8, "牛奶/豆浆/粥", "%s后不能食用难消化的食物,如肉类,需要禁食8小时后才能进行麻醉和手术"),
+    RANGE_OVER_8(8, Long.MAX_VALUE, "无", "%s前饮食无特殊限制");
+    private final long start;  // 区间起始(包含)
+    private final long end;    // 区间结束(包含)
+    private final String type;
+    private final String desc; // 区间描述
+
+    FastingEnums(long start, long end, String type, String desc) {
+        this.start = start;
+        this.end = end;
+        this.type = type;
+        this.desc = desc;
+    }
+
+    // 判断当前值是否在区间内
+    public boolean contains(long value) {
+        return value > start && value <= end;
+    }
+
+    // 根据值获取对应的区间
+    public static FastingEnums getMatchedInterval(long value) {
+        return EnumSet.allOf(FastingEnums.class)
+                .stream()
+                .filter(interval -> interval.contains(value))
+                .findFirst()
+                .orElseThrow(() -> new IllegalArgumentException("未找到匹配的时间区间"));
+    }
+}

+ 20 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/service/IBizFastingService.java

@@ -0,0 +1,20 @@
+package cn.tr.module.smart.common.service;
+
+import cn.tr.module.smart.wx.controller.vo.BizFastingVo;
+import cn.tr.module.smart.wx.dto.BizFastingDTO;
+
+/**
+ * TODO
+ *
+ * @author wangzl
+ * @date 2025/9/19 8:27
+ */
+public interface IBizFastingService {
+
+    /**
+     * @description: 禁饮禁食提示信息
+     * @author wangzl
+     * @date 2025/9/19
+     */
+    BizFastingVo getTips(BizFastingDTO source);
+}

+ 85 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/service/impl/BizFastingServiceImpl.java

@@ -0,0 +1,85 @@
+package cn.tr.module.smart.common.service.impl;
+
+import cn.hutool.core.date.DateUnit;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.tr.core.exception.ServiceException;
+import cn.tr.core.exception.TRExcCode;
+import cn.tr.module.smart.common.enums.ClinicPhaseEnums;
+import cn.tr.module.smart.common.enums.FastingEnums;
+import cn.tr.module.smart.common.po.BizClinicRoomPO;
+import cn.tr.module.smart.common.repository.BizClinicRoomRepository;
+import cn.tr.module.smart.common.service.IBizFastingService;
+import cn.tr.module.smart.wx.controller.vo.BizFastingTipsVO;
+import cn.tr.module.smart.wx.controller.vo.BizFastingVo;
+import cn.tr.module.smart.wx.dto.BizFastingDTO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+import java.util.function.BiFunction;
+import java.util.stream.Collectors;
+import java.util.stream.LongStream;
+
+/**
+ * TODO
+ *
+ * @author wangzl
+ * @date 2025/9/19 8:28
+ */
+@Service
+public class BizFastingServiceImpl implements IBizFastingService {
+    @Autowired
+    private BizClinicRoomRepository bizClinicRoomRepository;
+
+    private static final long[] FASTING_TIME_RANGE = {0, 2, 4, 6, 8, Long.MAX_VALUE};
+
+
+    /**
+     * @param source
+     * @description: 禁饮禁食提示信息
+     * @author wangzl
+     * @date 2025/9/19
+     */
+    @Override
+    public BizFastingVo getTips(BizFastingDTO source) {
+        BizClinicRoomPO bizClinicRoomPO = bizClinicRoomRepository.selectById(source.getClinicId());
+        if (ObjectUtil.isNull(bizClinicRoomPO)) {
+            throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "未查询到手术信息");
+        }
+        if (StrUtil.equals(bizClinicRoomPO.getClinicStatus(), ClinicPhaseEnums.AFTER)) {
+            throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001, "手术已经结束");
+        }
+        if (ObjectUtil.compare(new Date(),bizClinicRoomPO.getClinicStartTime()) > 0) {
+            throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001
+                    , String.format("手术开始时间[%s],在当前时间[%s]之前请结束手术"
+                    , DateUtil.formatDateTime(bizClinicRoomPO.getClinicStartTime())
+                    , DateUtil.formatDateTime(new Date())));
+        }
+        //计算当前时间与手术开始时间的间隔
+        long between = DateUtil.between(new Date(), bizClinicRoomPO.getClinicStartTime(), DateUnit.HOUR);
+        //计算时间间隔对应时间
+        List<BizFastingTipsVO> collect = EnumSet.allOf(FastingEnums.class)
+                .stream()
+                .map(fasting -> {
+                    int currentTime = fasting.getEnd() > 8 ? (int) between : (int) fasting.getEnd();
+                    return BizFastingTipsVO.builder()
+                            .type(fasting.getType())
+                            .flag(fasting.contains(between))
+                            .tip(String.format(fasting.getDesc(),
+                                    DateUtil.format(DateUtil.offsetHour(bizClinicRoomPO.getClinicStartTime(),
+                                            -currentTime), "MM月dd日 HH:mm")))
+                            .interval(String.format("手术前%d小时", currentTime))
+                            .build();
+                }).collect(Collectors.toList());
+
+        String attention = "1.若不慎进食或饮水,无论量多少,必须立即联系主管护士,可能需调整手术时间(隐瞒会导致麻醉误吸风险,危及安全);" +
+                "2.术前可少量清水漱口(禁止吞咽),取下假牙、首饰,携带必需药物(需经医护核对);" +
+                "3.若术前出现发热(>37.3℃)、咳嗽、呕吐,请立即告知医护人员,评估是否暂停手术。";
+        return BizFastingVo.builder()
+                .attention(attention)
+                .tips(collect)
+                .build();
+    }
+}

+ 43 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/controller/BizWxFastingController.java

@@ -0,0 +1,43 @@
+package cn.tr.module.smart.wx.controller;
+
+import cn.dev33.satoken.annotation.SaCheckLogin;
+import cn.tr.core.annotation.TenantIgnore;
+import cn.tr.core.pojo.CommonResult;
+import cn.tr.module.smart.common.service.IBizFastingService;
+import cn.tr.module.smart.wx.controller.vo.BizFastingVo;
+import cn.tr.module.smart.wx.dto.BizFastingDTO;
+import cn.tr.module.sys.oauth2.LoginTypeConstant;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * TODO
+ *
+ * @author wangzl
+ * @date 2025/9/19 7:55
+ */
+@Api(tags = "禁饮禁食管理")
+@RestController
+@RequestMapping("/wx/fasting")
+@AllArgsConstructor
+//@SaCheckLogin(type = LoginTypeConstant.WX_APPLET)
+public class BizWxFastingController {
+    @Autowired
+    private IBizFastingService bizFastingService;
+
+    @ApiOperationSupport(author = "wangzl", order = 1)
+    @ApiOperation(value = "查询禁食禁饮提示信息", notes = "权限: 无")
+    @PostMapping("/tips")
+    public CommonResult<BizFastingVo> getTips(@RequestBody BizFastingDTO source){
+        return CommonResult.success(bizFastingService.getTips(source));
+    }
+
+
+}

+ 37 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/controller/vo/BizFastingTipsVO.java

@@ -0,0 +1,37 @@
+package cn.tr.module.smart.wx.controller.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.*;
+
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * TODO
+ *
+ * @author wangzl
+ * @date 2025/9/19 7:58
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@ToString
+@ApiModel("禁饮禁食提示信息实体")
+public class BizFastingTipsVO implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "禁止类型", position = 1)
+    private String type;
+
+    @ApiModelProperty(value = "间隔时长 2 4 6 8 大于8小时", position = 2)
+    private String interval;
+
+    @ApiModelProperty(value = "标记", position = 3)
+    private Boolean flag;
+
+    @ApiModelProperty(value = "提示信息", position = 4)
+    private String tip;
+
+}

+ 30 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/controller/vo/BizFastingVo.java

@@ -0,0 +1,30 @@
+package cn.tr.module.smart.wx.controller.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.*;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * TODO
+ *
+ * @author wangzl
+ * @date 2025/9/19 8:21
+ */
+@ApiModel("禁饮禁食整体")
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@Data
+@ToString
+public class BizFastingVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "提示", position = 1)
+    private List<BizFastingTipsVO> tips;
+
+    @ApiModelProperty(value = "注意事项", position = 2)
+    private String attention;
+}

+ 21 - 0
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/wx/dto/BizFastingDTO.java

@@ -0,0 +1,21 @@
+package cn.tr.module.smart.wx.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.ToString;
+
+/**
+ * TODO
+ *
+ * @author wangzl
+ * @date 2025/9/19 8:25
+ */
+@Data
+@ToString
+@ApiModel("禁饮禁食请求参数")
+public class BizFastingDTO {
+
+    @ApiModelProperty(value = "手术ID", position = 1)
+    private String clinicId;
+}