|
|
@@ -0,0 +1,100 @@
|
|
|
+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.BizFastingAttentionVO;
|
|
|
+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());
|
|
|
+
|
|
|
+ List<BizFastingAttentionVO> attentionVOS = new ArrayList<>();
|
|
|
+ attentionVOS.add(BizFastingAttentionVO.builder()
|
|
|
+ .serialNo(1)
|
|
|
+ .icon("")
|
|
|
+ .content("若不慎进食或饮水,无论量多少,必须立即联系主管护士,可能需调整手术时间(隐瞒会导致麻醉误吸风险,危及安全);")
|
|
|
+ .build());
|
|
|
+ attentionVOS.add(BizFastingAttentionVO.builder()
|
|
|
+ .serialNo(2)
|
|
|
+ .icon("")
|
|
|
+ .content("术前可少量清水漱口(禁止吞咽),取下假牙、首饰,携带必需药物(需经医护核对);")
|
|
|
+ .build());
|
|
|
+ attentionVOS.add(BizFastingAttentionVO.builder()
|
|
|
+ .serialNo(3)
|
|
|
+ .icon("")
|
|
|
+ .content("若术前出现发热(>37.3℃)、咳嗽、呕吐,请立即告知医护人员,评估是否暂停手术。")
|
|
|
+ .build());
|
|
|
+
|
|
|
+ return BizFastingVo.builder()
|
|
|
+ .attentions(attentionVOS)
|
|
|
+ .tips(collect)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+}
|