ソースを参照

完成出院带药。

xiaochan 2 年 前
コミット
4d968311f3

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

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import thyyxxk.webserver.config.auth.PassToken;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
@@ -127,10 +128,17 @@ public class YizhuLuRuController {
     }
 
     @GetMapping("/huoQuGeiYaoFangShi")
+    @PassToken
     public ResultVo<List<GetDropdownBox>> huoQuGeiYaoFangShi(String code) {
         return server.huoQuGeiYaoFangShi(code);
     }
 
+    @GetMapping("/getCostFreeDosing")
+    @PassToken
+    public ResultVo<List<GetDropdownBox>> getCostFreeDosing(String code) {
+        return server.getCostFreeDosing(code);
+    }
+
     @GetMapping("/huoQuZhiXinKeShi")
     public ResultVo<List<GetDropdownBox>> huoQuZhiXinKeShi(String code) {
         return server.huoQuZhiXinKeShi(code);

+ 55 - 9
src/main/java/thyyxxk/webserver/dao/his/zhuyuanyisheng/YiZhuLuRuDao.java

@@ -15,6 +15,7 @@ import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.*;
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.stream.Stream;
 
@@ -727,10 +728,37 @@ public interface YiZhuLuRuDao {
             "from yz_act_order " +
             "where inpatient_no = #{patNo} " +
             "  and admiss_times = #{times} " +
-            "  and self_buy = '4' " +
-            "  and status_flag in ('1', '2') ")
+            "  and self_buy = '4' ")
     int obtainTheNumberOfDischargedDrugs(String patNo, Integer times);
 
+    @Select("select day_800, day_830, day_900,\n" +
+            "       day_930, day_1000, day_1030, day_1100, day_1130, day_1200, day_1230, day_1300, day_1330,\n" +
+            "       day_1400, day_1430, day_1500, day_1530, day_1600, day_1630, day_1700, day_1730,\n" +
+            "       day_1800, day_1830, day_1900, day_1930, day_2000, day_2030, day_2100, day_2130,\n" +
+            "       day_2200, day_2230, day_2300, day_2330, day_2400, day_030, day_100, day_130, day_200,\n" +
+            "       day_230, day_300, day_330, day_400, day_430, day_500, day_530, day_600, day_630,\n" +
+            "       day_700, day_730\n" +
+            "from yz_order_frequency where code = #{code}")
+    Map<String, Short> numberOfTimesADay(String code);
+
+    /**
+     * 出院带药只能要这些给药方式
+     *
+     * @param code 编码
+     * @return 返回数量
+     */
+    @Select("select count(1)\n" +
+            "from (select b.charge_code, a.*\n" +
+            "      from yz_supply_type a\n" +
+            "               left join yz_supply_charge b on a.supply_code = b.supply_code) aa\n" +
+            "where charge_code is null and supply_code = #{code} ")
+    int dischargeWithMedicationAdministration(String code);
+
+
+    @Update("update yz_act_order set drug_quan = #{item.drugQuan}," +
+            "drug_occ = #{item.drugOcc} where act_order_no = #{item.actOrderNo} ")
+    void updateThePickup(@Param("item") XinZhenYzActOrder item);
+
     @Select("select rtrim(supply_code) code,rtrim(supply_name) name " +
             "from yz_supply_type with (NOLOCK) " +
             "where ps_flag in ('1', '0')")
@@ -748,6 +776,18 @@ public interface YiZhuLuRuDao {
     List<GetDropdownBox> huoQuGeiYaoFangShi(String code);
 
 
+    @Select("select rtrim(supply_code) code, rtrim(supply_name) name\n" +
+            "from (select b.charge_code, a.*\n" +
+            "      from yz_supply_type a\n" +
+            "               left join yz_supply_charge b on a.supply_code = b.supply_code) aa\n" +
+            "where charge_code is null\n" +
+            "  and (py_code like #{code} or d_code like #{code} or supply_name like #{code} or supply_code like #{code})")
+    List<GetDropdownBox> getCostFreeDosing(String code);
+
+
+
+
+
     @Select("SELECT a.code code, " +
             "       a.name name " +
             "FROM zd_unit_code a with (NOLOCK), " +
@@ -1503,18 +1543,24 @@ public interface YiZhuLuRuDao {
             "                           submit_name, submit_flag, " +
             "                           page_class, page_name, " +
             "                           start_date, end_date, group_no) " +
-            "values (#{pageNo}, '#{patInfo.deptCode}', #{patInfo.wardCode}, getdate()," +
+            "values (#{pageNo}, #{patInfo.deptCode}, #{patInfo.wardCode}, getdate()," +
             " #{userCode}, 1, 1, '出院带药', getdate(), getdate(), #{groupNo})")
     void summarySheetOfDrugs(Integer pageNo, XinZhenYiZhu patInfo, String userCode, String groupNo);
 
 
-    @Insert("insert into yz_yp_zy_order (inpatient_no, admiss_times, name, bed_no, dept_code, ward_code, charge_code, " +
-            "  amount,\n" +
-            " retprice, charge_date, infant_flag, drawer, always_flag, status_flag/*1*/, drug_class,\n" +
+    @Insert("<script>" +
+            "insert into yz_yp_zy_order (inpatient_no, admiss_times, name, bed_no, dept_code, ward_code, charge_code, " +
+            "  amount, retprice/*药品的单价*/, charge_date, infant_flag, drawer, always_flag, status_flag/*1*/, drug_class,\n" +
             " serail/*0*/,\n" +
             " occ_time, act_order_no, page_no, pay_self/*0*/, serial/*serial*/,\n" +
-            " group_no, doctor_name, page_class, yb_self_flag)\n" +
-            "values ();")
-    void insertDetailedMedicineList();
+            " group_no, doctor_name, page_class)\n" +
+            "values " +
+            "<foreach collection='list' item='item' separator=','>" +
+            "(#{patInfo.inpatientNo},#{patInfo.admissTimes},#{patInfo.name},#{patInfo.bedNo},#{patInfo.deptCode},#{patInfo.wardCode},#{item.orderCode}," +
+            "#{item.drugQuan},(select pack_retprice from yp_zd_dict where code = '${item.orderCode}' and serial = '${item.serial}'),getdate(),#{patInfo.infantFlag},#{userCode}," +
+            "'a','1',#{item.drugFlag},'0',getdate(),#{item.actOrderNo},#{pageNo},'0',#{item.serial},#{groupNo},#{userCode},'1')" +
+            "</foreach>" +
+            "</script>")
+    void insertDetailedMedicineList(Integer pageNo, XinZhenYiZhu patInfo, String userCode, String groupNo, List<XinZhenYzActOrder> list);
 
 }

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

@@ -117,7 +117,7 @@ public class XinZhenYzActOrder {
     private String drugSpecification;
 
     /**
-     * 药品执行用
+     * 
      */
     private BigDecimal drugQuan;
     private String drugQuanName;

+ 55 - 26
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/YiZhuLuRuServer.java

@@ -97,6 +97,7 @@ public class YiZhuLuRuServer {
      * @param times 住院次数
      * @return 返回自己的医嘱频率
      */
+    @Deprecated
     public ResultVo<List<GetDropdownBox>> huoQuGeRenPinLv(String patNo, Integer times) {
         return ResultVoUtil.success(dao.huoQuGeRenPinLv(patNo, times));
     }
@@ -218,10 +219,6 @@ public class YiZhuLuRuServer {
         if (ListUtil.isBlank(yiZhuList)) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有需要确认的医嘱.");
         }
-        if (dao.obtainTheNumberOfDischargedDrugs(param.getInpatientNo(), param.getAdmissTimes()) > 4) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "出院带药医嘱不得超过 4 种,却不得超过 7 天。");
-        }
-
         // 药品 code
         Set<String> yaoPingCode = new HashSet<>();
         // 项目的 code
@@ -292,21 +289,24 @@ public class YiZhuLuRuServer {
             if (count > 0) {
                 return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "有未确认和未执行的医嘱,无法确认全排斥医嘱。");
             }
-//            dao.stopOrder(param.getInpatientNo(), param.getAdmissTimes(), excludeOrders, userCode);
+            dao.stopOrder(param.getInpatientNo(), param.getAdmissTimes(), excludeOrders, userCode);
         }
-        // TODO 出院带药的问题
         dischargeMedicineList(takeTheMedicineList, huanZheXinXi);
-//        dao.confirmOrders(confirmOrderInformation, TokenUtil.getTokenUserId(), param.getInpatientNo(), param.getAdmissTimes());
+        dao.confirmOrders(confirmOrderInformation, TokenUtil.getTokenUserId(), param.getInpatientNo(), param.getAdmissTimes());
         log.info("确认的医嘱:{}", JSON.toJSONString(yiZhuList));
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
     }
 
     private void dischargeMedicineList(Map<String, List<XinZhenYzActOrder>> map, XinZhenYiZhu huanZheXinXi) {
-        log.info("出院带药药单:{}", JSON.toJSONString(map));
+        if (dao.obtainTheNumberOfDischargedDrugs(huanZheXinXi.getInpatientNo(), huanZheXinXi.getAdmissTimes()) > 4) {
+            throw new BizException(ExceptionEnum.LOGICAL_ERROR, "出院带药医嘱不得超过 4 种,且不得超过 15 天。");
+        }
         String userCode = TokenUtil.getTokenUserId();
+        // 根据不同的药房,生成不同的单子.
         for (Map.Entry<String, List<XinZhenYzActOrder>> entry : map.entrySet()) {
-//            Integer pageNo = publicServer.getTheDrugListNo();
-//            dao.summarySheetOfDrugs(pageNo, huanZheXinXi, userCode, entry.getKey());
+            Integer pageNo = publicServer.getTheDrugListNo();
+            dao.summarySheetOfDrugs(pageNo, huanZheXinXi, userCode, entry.getKey());
+            dao.insertDetailedMedicineList(pageNo, huanZheXinXi, userCode, entry.getKey(), entry.getValue());
         }
 
     }
@@ -702,7 +702,7 @@ public class YiZhuLuRuServer {
      * @return 返回对应的数据
      */
     public ResultVo<List<GetDropdownBox>> huoQuZhuYuanPinLv(String code) {
-        return ResultVoUtil.success(dao.huoQuZhuYuanPinLv(StringUtil.isContainChinese(code)));
+        return ResultVoUtil.success(dao.huoQuZhuYuanPinLv("%" + code.toUpperCase() + "%"));
     }
 
     /**
@@ -715,6 +715,10 @@ public class YiZhuLuRuServer {
         return ResultVoUtil.success(dao.huoQuGeiYaoFangShi(StringUtil.isContainChinese(code)));
     }
 
+    public ResultVo<List<GetDropdownBox>> getCostFreeDosing(String code) {
+        return ResultVoUtil.success(dao.getCostFreeDosing(StringUtil.isContainChinese(code)));
+    }
+
     /**
      * 获取执行科室
      *
@@ -941,7 +945,6 @@ public class YiZhuLuRuServer {
                         警告信息.add(String.format("项目:【%s】,没有匹配医保码", 明细.getOrderName()));
                     }
                 }
-
             }
         } else {
             XinZhenYzActOrder feiYongXinXi = drug.get(item.getOrderCode().trim() + item.getSerial().trim());
@@ -977,6 +980,15 @@ public class YiZhuLuRuServer {
                     }
                 }
                 if (item.getSelfBuy() != null && item.getSelfBuy().equals("4")) {
+                    // 如果是临时医嘱 开了就结束了.
+                    if (item.getFrequCode().equals("ONCE")) {
+                        item.setEndTime(item.getStartTime());
+                    }
+                    if (dao.dischargeWithMedicationAdministration(item.getFrequCode()) == 0) {
+                        错误信息.add("出院带药给药方式不能包含费用。");
+                    }
+
+                    int day = 1;
                     if (item.getStartTime() == null) {
                         错误信息.add("出院带药请输入开始时间。");
                     }
@@ -985,13 +997,41 @@ public class YiZhuLuRuServer {
                     } else {
                         long cha = item.getEndTime().getTime() - item.getStartTime().getTime();
                         long nd = 1000 * 24 * 60 * 60;
-                        if (cha / nd > 7) {
-                            错误信息.add("出院带药天数不得超过 7 天,计算方式结束时间减去开始时间。");
+                        day = (int) (cha / nd);
+                        if (day > 15) {
+                            错误信息.add("出院带药天数不得超过 15 天,计算方式结束时间减去开始时间。");
                         }
                     }
+                    // 计算出院带药的领量
+                    Map<String, Short> numberOfTimesADay = dao.numberOfTimesADay(item.getFrequCode());
+                    int times = 1;
+                    for (Map.Entry<String, Short> entry : numberOfTimesADay.entrySet()) {
+                        if (entry.getValue() != null) {
+                            times += entry.getValue();
+                        }
+                    }
+                    // 最小天数一天
+                    BigDecimal total = new BigDecimal((day <= 0 ? 1 : day) * times);
+                    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())) {
+                        if (new BigDecimal(item.getDose().intValue()).compareTo(item.getDose()) != 0) {
+                            错误信息.add("已经是最小单位了请不要带小数点");
+                        }
+                        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
+                    // 计算普通药品的领量 durg_quan durg_occ
                     calculateDrugAmount(item, feiYongXinXi, 错误信息);
                 }
 
@@ -1556,16 +1596,5 @@ public class YiZhuLuRuServer {
         return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION);
     }
 
-    /**
-     * 出院带药数据校验
-     *
-     * @param patInfo 患者信息
-     * @param param   参数
-     * @return 返回提示
-     */
-    public String verificationAfterDischarge(XinZhenYiZhu patInfo, XinZhenYzActOrder param) {
-        return "";
-    }
-
 
 }