Browse Source

出院带药优化

DESKTOP-0GD05B0\Administrator 2 years ago
parent
commit
3abb764bca

+ 7 - 0
src/main/java/thyyxxk/webserver/controller/zhuyuanyizheng/YizhuLuRuController.java

@@ -231,4 +231,11 @@ public class YizhuLuRuController {
         return server.associateOrders(param);
     }
 
+
+    @GetMapping("/confirmTheDoctorSOrderWithMedicine")
+    public ResultVo<Map<String, Object>> confirmTheDoctorSOrderWithMedicine(@RequestParam("patNo") String patNo,
+                                                                            @RequestParam("times") Integer times) {
+        return server.confirmTheDoctorSOrderWithMedicine(patNo, times);
+    }
+
 }

+ 33 - 1
src/main/java/thyyxxk/webserver/dao/his/zhuyuanyisheng/YiZhuLuRuDao.java

@@ -824,6 +824,36 @@ public interface YiZhuLuRuDao {
                                              @Param("dept") String dept);
 
 
+    @Select("select rtrim(code)                       order_code, " +
+            "       rtrim(a.serial)                     serial, " +
+            "       rtrim(name)                       order_name," +
+            "       case infusion_flag " +
+            "           when '1' then 'i' " +
+            "           else " +
+            "               (case " +
+            "                    when rtrim(code) >= '30000' and rtrim(code) < '50000' then 'z' " +
+            "                    else 'd' end) end as drug_flag, " +
+            "       mini_unit, " +
+            "       isnull(weight,1)                  drug_weight, " +
+            "       weigh_unit                        drug_weight_unit, " +
+            "       isnull(volum,1)                   drug_volume, " +
+            "       vol_unit                          drug_vol_unit," +
+            "       isnull(pack_size,1) pack_size,  " +
+            "       pack_unit," +
+            "       a.pack_retprice,  " +
+            "       national_code," +
+            "       cast(isnull(NULLIF(kjyw_flag, ''), 0) as int) as kjyw_flag," +
+            "       cast(isnull(NULLIF(yp_level, ''), 0) as int)  as yp_level," +
+            "       cast(isnull(NULLIF(del_flag, ''), 0) as int)  as del_flag,  " +
+            "       stock_amount," +
+            "       cast(isnull(nullif(visible_flag_zy, ''), 0) as int) as visible_flag_zy " +
+            " from yp_zd_dict a with (NOLOCK)  " +
+            " left join  yp_base_yf b on ( code = b.charge_code and  a.serial = b.serial) " +
+            "where rtrim(code) + rtrim(a.serial) = '${code}' " +
+            " and group_no = #{groupNo} ")
+    XinZhenYzActOrder getDrugOne(String code, String groupNo);
+
+
     @Select("<script>" +
             "select          b.order_code, " +
             "                rtrim(c.name)                 order_name, " +
@@ -853,7 +883,8 @@ public interface YiZhuLuRuDao {
             "                times_billed, " +
             "                admiss_date, " +
             "                small_dept, " +
-            "                bed_no, " +
+            "                bed_no," +
+            "                zk_ward, " +
             "    ledger_sn = (select max(ledger_sn) " +
             "                 from zy_ledger_file with (NOLOCK) " +
             "                 where zy_actpatient.inpatient_no = zy_ledger_file.inpatient_no " +
@@ -1563,4 +1594,5 @@ public interface YiZhuLuRuDao {
             "</script>")
     void associateOrders(List<BigDecimal> list, String actOrderNo);
 
+
 }

+ 6 - 1
src/main/java/thyyxxk/webserver/entity/zhuyuanyisheng/yizhuluru/XinZhenYiZhu.java

@@ -78,10 +78,15 @@ public class XinZhenYiZhu {
     private Date admissDate;
 
     /**
-     * 患者科室
+     * 患者入院小科室
      */
     private String smallDept;
 
+    /**
+     * 患者现在的科室
+     */
+    private String zkWard;
+
     /**
      * 床位
      */

+ 1 - 2
src/main/java/thyyxxk/webserver/service/heliyongyao/RationalUseServer.java

@@ -77,7 +77,7 @@ public class RationalUseServer {
         Map<String, YaoPin> yaoPinMap = dao.yaoPingXinXi(qw).stream().collect(
                 Collectors.toMap(YaoPin::getId, a -> a, (k1, k2) -> k1)
         );
-        String detailsXml = yaoPinXinXi(param.getInpatientNo(), param.getAdmissTimes(), param.getCfType(), yp, doct, yaoPinMap);
+        String detailsXml = yaoPinXinXi(param.getInpatientNo(), param.getAdmissTimes(), yp, doct, yaoPinMap);
         String js = String.format("{\"BaseXml\": \"%s\", \"DetailsXml\" : \"%s\"}", baseXml, detailsXml);
 
         try {
@@ -148,7 +148,6 @@ public class RationalUseServer {
 
     public String yaoPinXinXi(String patNo,
                               Integer times,
-                              String cfType,
                               List<XinZhenYzActOrder> yaoPinShuZu,
                               String doct,
                               Map<String, YaoPin> yaoPinMap) {

+ 149 - 24
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/YiZhuLuRuServer.java

@@ -9,7 +9,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.ListUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.client.RestTemplate;
 import thyyxxk.webserver.config.exception.BizException;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.constants.Capacity;
@@ -221,9 +220,12 @@ public class YiZhuLuRuServer {
      */
     public ResultVo<Map<String, Object>> confirmOrders(XinZhenYiZhu param) {
         QueryWrapper<?> qw = new QueryWrapper<>();
-        qw.eq("a.inpatient_no", param.getInpatientNo()).eq("a.admiss_times", param.getAdmissTimes());
-        qw.eq("a.status_flag", "1");
-        qw.eq("a.enter_oper", TokenUtil.getTokenUserId());
+        qw.eq("a.inpatient_no", param.getInpatientNo())
+                .eq("a.admiss_times", param.getAdmissTimes())
+                .eq("a.status_flag", "1")
+                .eq("a.enter_oper", TokenUtil.getTokenUserId())
+                // 排除出院带药的医嘱
+                .ne("a.self_buy", "4");
         param.setList(dao.huoQuYiZhuShuJu(qw));
         List<XinZhenYzActOrder> yiZhuList = param.getList();
         if (ListUtil.isBlank(yiZhuList)) {
@@ -233,8 +235,6 @@ public class YiZhuLuRuServer {
         Set<String> yaoPingCode = new HashSet<>();
         // 项目的 code
         Set<String> xiangMuCode = new HashSet<>();
-        // 出院带药需要生成药单 key 是不同的药房。不同的药房就要
-        Map<String, List<XinZhenYzActOrder>> takeTheMedicineList = new HashMap<>(Capacity.TWO);
 
         for (XinZhenYzActOrder item : yiZhuList) {
             if (ITEM.equals(item.getSerial())) {
@@ -242,16 +242,6 @@ public class YiZhuLuRuServer {
             } else {
                 yaoPingCode.add(item.getOrderCode().trim() + item.getSerial().trim());
             }
-            // 费用标志为 4 的就是出院带药
-            if ("4".equals(item.getSelfBuy())) {
-                if (takeTheMedicineList.containsKey(item.getGroupNo())) {
-                    takeTheMedicineList.get(item.getGroupNo()).add(item);
-                } else {
-                    List<XinZhenYzActOrder> temp = new ArrayList<>();
-                    temp.add(item);
-                    takeTheMedicineList.put(item.getGroupNo(), temp);
-                }
-            }
         }
 
         // 合理用药校验
@@ -301,10 +291,11 @@ public class YiZhuLuRuServer {
                 if (!isThereAnyErrorMessage && errorMessageMap.containsKey("error")) {
                     isThereAnyErrorMessage = true;
                 }
-                map.put(item.getId(), errorMessageMap);
                 errorMessageMap.put("data", item);
+                map.put(item.getId(), errorMessageMap);
             }
         }
+
         if (isThereAnyErrorMessage) {
             return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改错误的医嘱", map);
         }
@@ -316,7 +307,6 @@ public class YiZhuLuRuServer {
             }
             dao.stopOrder(param.getInpatientNo(), param.getAdmissTimes(), excludeOrders, userCode, orderNo);
         }
-        dischargeMedicineList(takeTheMedicineList, huanZheXinXi);
         for (BigDecimal decimal : confirmOrderInformation) {
             dao.confirmOrders(decimal, userCode, new Date());
         }
@@ -344,7 +334,6 @@ public class YiZhuLuRuServer {
             dao.summarySheetOfDrugs(pageNo, huanZheXinXi, userCode, entry.getKey());
             dao.insertDetailedMedicineList(pageNo, huanZheXinXi, userCode, entry.getKey(), entry.getValue());
         }
-
     }
 
 
@@ -378,7 +367,6 @@ public class YiZhuLuRuServer {
         if (data.getParentNo() != null) {
             data.setSupplyCode("044");
         }
-
         // 药品的 code
         Set<String> yaoPingCode = new HashSet<>();
         // 项目的 code
@@ -1062,10 +1050,6 @@ public class YiZhuLuRuServer {
                         item.setDrugOcc(DecimalUtil.multiply(DecimalUtil.divide(item.getDose(), feiYongXinXi.getPackSize(), 2), total));
                         item.setDrugQuan(DecimalUtil.multiply(DecimalUtil.divide(item.getDose(), feiYongXinXi.getPackSize()), total));
                     }
-                    dao.updateThePickup(item);
-
-                    log.info("领量:{},occ:{},天数:{},服用次数:{}", item.getDrugQuan(), item.getDrugOcc(), day, total);
-                    log.info("出院带药确认频次:{},一天服用次数:{}", item.getFrequCode(), times);
                 } else {
                     // 计算普通药品的领量 durg_quan durg_occ
                     calculateDrugAmount(item, feiYongXinXi, 错误信息);
@@ -1520,4 +1504,145 @@ public class YiZhuLuRuServer {
     }
 
 
+    /**
+     * 批量检验医嘱是否正确
+     *
+     * @param list         医嘱数据
+     * @param huanZheXinXi 患者信息
+     * @param rationalUse  是否要用合理用药
+     * @return
+     */
+    public Map<String, Object> batchVerification(List<XinZhenYzActOrder> list,
+                                                 XinZhenYiZhu huanZheXinXi,
+                                                 boolean rationalUse) {
+        Map<String, Object> returnMap = new HashMap<>();
+        // 药品 code
+        Set<String> yaoPingCode = new HashSet<>();
+        // 项目的 code
+        Set<String> xiangMuCode = new HashSet<>();
+        huanZheXinXi.setList(list);
+        // 合理用药校验
+        Map<String, List<String>> rationalUseOfMedicine = rationalUse ? rationalUseServer.jiaoYan(huanZheXinXi) : new HashMap<>(list.size());
+
+        for (XinZhenYzActOrder item : list) {
+            if (ITEM.equals(item.getSerial())) {
+                xiangMuCode.add(item.getOrderCode());
+            } else {
+                yaoPingCode.add(item.getOrderCode().trim() + item.getSerial().trim());
+            }
+        }
+        String userCode = TokenUtil.getTokenUserId();
+        // 获取医生开药品的权限
+        Integer doctorLevel = dao.huoQuYiShenDengJi(userCode);
+        Map<String, XinZhenYzActOrder> drug = getDrugInformation(yaoPingCode, huanZheXinXi.getZkWard());
+        Map<String, List<XinZhenYzActOrder>> project = getProjectInformation(xiangMuCode);
+        for (XinZhenYzActOrder item : list) {
+            String key = item.getId();
+            Map<String, Object> errorMessageMap = checkData(item, drug, project, huanZheXinXi, doctorLevel);
+            if (rationalUseOfMedicine.containsKey(key)) {
+                List<String> temp = (List<String>) errorMessageMap.get("error");
+                if (temp == null) {
+                    errorMessageMap.put("error", rationalUseOfMedicine.get(key));
+                } else {
+                    temp.addAll(rationalUseOfMedicine.get(key));
+                }
+            }
+
+            if (!errorMessageMap.isEmpty()) {
+                if (errorMessageMap.get("error") != null) {
+                    errorMessageMap.put("data", item);
+                    returnMap.put(item.getId(), errorMessageMap);
+                }
+            }
+        }
+        return returnMap;
+    }
+
+
+    /**
+     * 确认出院带药医嘱
+     *
+     * @param patNo
+     * @param times
+     * @return
+     */
+    public ResultVo<Map<String, Object>> confirmTheDoctorSOrderWithMedicine(String patNo, Integer times) {
+        QueryWrapper<?> qw = new QueryWrapper<>();
+        qw.eq("a.inpatient_no", patNo)
+                .eq("a.admiss_times", times)
+                .eq("a.status_flag", "1")
+                .eq("a.enter_oper", TokenUtil.getTokenUserId())
+                .eq("a.self_buy", "4");
+        XinZhenYiZhu patInfo = dao.huoQuHuanZheXinXi(patNo, times);
+        patInfo.setList(dao.huoQuYiZhuShuJu(qw));
+        if (dao.obtainTheNumberOfDischargedDrugs(patNo, times) > 4) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "出院带药医嘱不得超过 4 种,且不得超过 15 天。");
+        }
+        String userCode = TokenUtil.getTokenUserId();
+        // 出院带药需要生成药单 key 是不同的药房。不同的药房就要
+        Map<String, List<XinZhenYzActOrder>> takeTheMedicineList = new HashMap<>(Capacity.TWO);
+
+        for (XinZhenYzActOrder item : patInfo.getList()) {
+            XinZhenYzActOrder feiYongXinXi = dao.getDrugOne(item.getOrderCode() + item.getSerial(), item.getGroupNo());
+            int day = 1;
+            // 如果是临时医嘱 开了就结束了.
+            if ("ONCE".equals(item.getFrequCode())) {
+                item.setEndTime(item.getStartTime());
+            }
+            if (item.getStartTime() != null && item.getEndTime() != null) {
+                long cha = item.getEndTime().getTime() - item.getStartTime().getTime();
+                long nd = 1000 * 24 * 60 * 60;
+                day = (int) (cha / nd);
+            }
+            // 计算出院带药的领量
+            Map<String, Short> numberOfTimesADay = dao.numberOfTimesADay(item.getFrequCode());
+            int tempTimes = 1;
+            for (Map.Entry<String, Short> entry : numberOfTimesADay.entrySet()) {
+                if (entry.getValue() != null) {
+                    tempTimes += entry.getValue();
+                }
+            }
+            // 最小天数一天
+            BigDecimal total = new BigDecimal((day <= 0 ? 1 : day) * tempTimes);
+            if (StringUtil.notBlank(feiYongXinXi.getDrugWeightUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getDrugWeightUnit().trim())) {
+                item.setDrugOcc(DecimalUtil.multiply(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugWeight(), 2), total));
+                item.setDrugQuan(DecimalUtil.multiply(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugWeight()), total));
+
+            } else if (StringUtil.notBlank(feiYongXinXi.getDrugVolUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getDrugVolUnit())) {
+                item.setDrugOcc(DecimalUtil.multiply(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugVolume(), 2), total));
+                item.setDrugQuan(DecimalUtil.multiply(DecimalUtil.divide(item.getDose(), feiYongXinXi.getDrugVolume()), total));
+            } else if (StringUtil.notBlank(feiYongXinXi.getPackUnit()) && item.getDoseUnit().trim().equals(feiYongXinXi.getPackUnit())) {
+                item.setDrugOcc(DecimalUtil.multiply(DecimalUtil.divide(item.getDose(), feiYongXinXi.getPackSize(), 2), total));
+                item.setDrugQuan(DecimalUtil.multiply(DecimalUtil.divide(item.getDose(), feiYongXinXi.getPackSize()), total));
+            }
+            // 在这里更新出院带药领量
+            dao.updateThePickup(item);
+            // 费用标志为 4 的就是出院带药
+            if ("4".equals(item.getSelfBuy())) {
+                if (takeTheMedicineList.containsKey(item.getGroupNo())) {
+                    takeTheMedicineList.get(item.getGroupNo()).add(item);
+                } else {
+                    List<XinZhenYzActOrder> temp = new ArrayList<>();
+                    temp.add(item);
+                    takeTheMedicineList.put(item.getGroupNo(), temp);
+                }
+            }
+        }
+
+        Map<String, Object> check = batchVerification(patInfo.getList(), patInfo, true);
+        if (check.isEmpty()) {
+            for (XinZhenYzActOrder order : patInfo.getList()) {
+                // 确认医嘱
+                dao.confirmOrders(order.getActOrderNo(), userCode, new Date());
+            }
+            // 生成药单
+            dischargeMedicineList(takeTheMedicineList, patInfo);
+            return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
+        } else {
+            return ResultVoUtil.fail(ExceptionEnum.ERROR_MESSAGE, "请修改有错误的医嘱。", check);
+        }
+
+    }
+
+
 }