Browse Source

医保超天数限制

xiaochan 3 months ago
parent
commit
d10ed7789d

+ 29 - 0
src/main/java/thyyxxk/webserver/dao/his/zhuyuanyisheng/YiZhuLuRuDao.java

@@ -12,6 +12,7 @@ import thyyxxk.webserver.entity.dictionary.CodeName;
 import thyyxxk.webserver.entity.inpatient.patient.Overview;
 import thyyxxk.webserver.entity.inpatient.patient.Patient;
 import thyyxxk.webserver.entity.login.UserInfo;
+import thyyxxk.webserver.entity.yzcheck.ChargeLimitations;
 import thyyxxk.webserver.entity.zhuyuanyisheng.DoctorSOrderFee;
 import thyyxxk.webserver.entity.zhuyuanyisheng.OneClickOrder;
 import thyyxxk.webserver.entity.zhuyuanyisheng.ZyOrderZk;
@@ -22,6 +23,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;
 
 /**
@@ -826,6 +828,12 @@ public interface YiZhuLuRuDao {
     List<XinZhenYzActOrder> itemDataOne(String code);
 
 
+    @Select("select order_code, order_name, cast(ISNULL(del_flag, 0) as int) as del_flag  \n" +
+            "from yz_order_item\n" +
+            "where order_code = '${code}'")
+    XinZhenYzActOrder yzItem(String code);
+
+
     @Select("select                 rtrim(code)                                            order_code, " +
             "                       rtrim(a.serial)                                     as serial, " +
             "                       rtrim(group_no)                                     as group_no, " +
@@ -1414,4 +1422,25 @@ public interface YiZhuLuRuDao {
             "  and ward_code = '${ssWard}'")
     void updateChargeWard(String patNo, Integer times, String ward, String ssWard);
 
+
+    @Select("select *\n" +
+            "from zd_charge_limitations\n" +
+            "where charge_code = '${code}'")
+    ChargeLimitations hasCharge(String code);
+
+
+    @Select("select a.limit_day, limit_times, convert(varchar(10), charge_date, 21) as charge_date " +
+            "from zd_charge_limitations a,\n" +
+            "     zy_detail_charge b\n" +
+            "where a.charge_code = '${chargeCode}'\n" +
+            "  and b.inpatient_no = '${patNo}'\n" +
+            "  and b.admiss_times = ${times} \n" +
+            "  and a.charge_code = b.charge_code_mx\n" +
+            "  and ledger_sn =  ${ledgerSn}\n" +
+            "  and ori_detail_sn is null\n" +
+            "  and a.del_flag <> '1'\n" +
+            "  and isnull(yb_self_flag, '0') != '1' " +
+            "group by charge_date, limit_day, limit_times")
+    List<ChargeLimitations> getChargeDay(String patNo, Integer times, Integer ledgerSn, String chargeCode);
+
 }

+ 13 - 0
src/main/java/thyyxxk/webserver/entity/yzcheck/ChargeLimitations.java

@@ -0,0 +1,13 @@
+package thyyxxk.webserver.entity.yzcheck;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class ChargeLimitations {
+    private Date startTime;
+    private Date endTime;
+    private Integer limitDay;
+    private Integer limitTimes;
+}

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

@@ -27,7 +27,7 @@ public class XinZhenYiZhu {
     /**
      * 账页号
      */
-    private String ledgerSn;
+    private Integer ledgerSn;
     /**
      * 管床医生
      */

+ 1 - 0
src/main/java/thyyxxk/webserver/enums/authorize/RuleId.java

@@ -5,6 +5,7 @@ import lombok.Getter;
 @Getter
 public enum RuleId {
 
+    医务部(38),
     财务(14),
     住院医生(33);
 

+ 4 - 3
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/YiZhuLuRuServer.java

@@ -222,7 +222,6 @@ public class YiZhuLuRuServer {
      * @return 返回提示
      */
     public ResultVo<Map<String, Object>> confirmOrders(XinZhenYiZhu param) {
-
         // 判断是否开了出院医嘱后的医嘱
         if (!yzConfig.getPrescribeMedicalAdviceAfterDischarge()) {
             if (dao.prescribeMedicalAdviceAfterDischarge(param.getInpatientNo(), param.getAdmissTimes()) > 0) {
@@ -245,7 +244,7 @@ public class YiZhuLuRuServer {
 
         List<XinZhenYzActOrder> confirmYzList = new ArrayList<>();
 
-        YiZhuCheckData checkData = new YiZhuCheckData(dao);
+        YiZhuCheckData checkData = new YiZhuCheckData(dao).checkForRestrictedMedication();
         checkData.init(yiZhuList, patInfo).judgeExclusion();
 
         Map<String, Object> checkMap = checkData.startCheck(confirmYzList::add);
@@ -1273,7 +1272,9 @@ public class YiZhuLuRuServer {
         String userCode = TokenUtil.getInstance().getTokenUserId();
         // 出院带药需要生成药单 key 是不同的药房。不同的药房就要
 
-        YiZhuCheckData checkData = new YiZhuCheckData(dao);
+        YiZhuCheckData checkData = new YiZhuCheckData(dao)
+                .checkForRestrictedMedication();
+
         checkData.init(patInfo.getList(), patInfo);
         Map<String, Object> map = checkData.startCheck(null);
 

+ 66 - 3
src/main/java/thyyxxk/webserver/service/zhuyuanyisheng/yizhuverify/YiZhuCheckData.java

@@ -1,5 +1,7 @@
 package thyyxxk.webserver.service.zhuyuanyisheng.yizhuverify;
 
+import cn.hutool.core.convert.Convert;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
@@ -7,6 +9,7 @@ import thyyxxk.webserver.config.envionment.YzConfig;
 import thyyxxk.webserver.constants.Capacity;
 import thyyxxk.webserver.dao.his.zhuyuanyisheng.YiZhuLuRuDao;
 import thyyxxk.webserver.entity.login.UserInfo;
+import thyyxxk.webserver.entity.yzcheck.ChargeLimitations;
 import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.XinZhenYiZhu;
 import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.XinZhenYzActOrder;
 import thyyxxk.webserver.entity.zhuyuanyisheng.yizhuluru.YzZdOrderItemConfirm;
@@ -22,7 +25,6 @@ public class YiZhuCheckData {
     private final ExtraCache extraCache = SpringUtil.getBean(ExtraCache.class);
     private final YzConfig yzConfig = SpringUtil.getBean(YzConfig.class);
 
-
     /**
      * 医嘱数组
      */
@@ -43,6 +45,16 @@ public class YiZhuCheckData {
      */
     private final CacheOnce<List<XinZhenYzActOrder>> project = new CacheOnce<>();
 
+    /**
+     * 医嘱
+     */
+    private final CacheOnce<XinZhenYzActOrder> yzItem = new CacheOnce<>();
+
+    /**
+     * 医保限制
+     */
+    private final CacheOnce<ChargeLimitations> yiBaoLimitation = new CacheOnce<>();
+
     /**
      * 患者信息
      */
@@ -62,6 +74,8 @@ public class YiZhuCheckData {
     private Boolean passTheAudit = true;
     private final List<String> groupList = Arrays.asList("71", "73");
 
+    private boolean checkForRestrictedMedication = false;
+
     /**
      * 全排斥医嘱
      */
@@ -92,7 +106,6 @@ public class YiZhuCheckData {
     }
 
     public Map<String, Object> startCheck(Consumer<XinZhenYzActOrder> action) {
-
         for (XinZhenYzActOrder item : list) {
             clearErrorMessage();
             if (strictVerification) {
@@ -141,6 +154,14 @@ public class YiZhuCheckData {
 
     private void itemCheck(XinZhenYzActOrder item) {
         List<XinZhenYzActOrder> projectDetails = project.get(item.getOrderCode(), dao::itemDataOne);
+        XinZhenYzActOrder yzItemInio = yzItem.get(item.getOrderCode(), dao::yzItem);
+
+        if (yzItemInio != null) {
+            if (yzItemInio.getDelFlag() == 1) {
+                errorMessage.add("该医嘱已被停用,请联系物价。");
+            }
+        }
+
 
         List<String> ZK_CODE_LIST = new ArrayList<>();
         Map<String, YzZdOrderItemConfirm> specialMedicalAdvice = new HashMap<>();
@@ -214,8 +235,8 @@ public class YiZhuCheckData {
         item.setDrugOcc(item.getDrugQuan());
     }
 
-    private void drugCheck(XinZhenYzActOrder item) {
 
+    private void drugCheck(XinZhenYzActOrder item) {
         if (StringUtil.isBlank(item.getGroupNo())) {
             errorMessage.add("没有药房请重新开。");
             return;
@@ -283,6 +304,7 @@ public class YiZhuCheckData {
         if (BigUtils.bigDaYu(item.getDrugQuan(), detailsOfDrugs.getStockAmount())) {
             errorMessage.add("药品领量大于药品的库存,当前库存量" + detailsOfDrugs.getStockAmount().stripTrailingZeros().toPlainString());
         }
+        //  严格校验
         if (strictVerification) {
             if (detailsOfDrugs.getDeptRestrictions() > 0) {
                 errorMessage.add("该药品禁止在患者所在的科室使用。");
@@ -300,6 +322,7 @@ public class YiZhuCheckData {
                     }
                 }
             }
+            校验医保限制用药(item);
         }
         String 出院带药 = "007";
         if (item.getSupplyCode() != null && 出院带药.equals(item.getSupplyCode())) {
@@ -316,6 +339,41 @@ public class YiZhuCheckData {
         }
     }
 
+
+    void 校验医保限制用药(XinZhenYzActOrder item) {
+        if (!checkForRestrictedMedication) return;
+        // 自费不管
+        if ("1".equals(item.getYbSelfFlag())) return;
+
+        ChargeLimitations chargeLimitations = yiBaoLimitation.get(item.getOrderCode(), dao::hasCharge);
+
+        if (chargeLimitations == null) {
+            return;
+        }
+
+        List<ChargeLimitations> data = dao.getChargeDay(patientInformation.getInpatientNo(),
+                patientInformation.getAdmissTimes(),
+                patientInformation.getLedgerSn(),
+                item.getOrderCode());
+
+        // 已经使用
+        int usedAlready = ListUtil.isBlank(data) ? 0 : data.size();
+        //可以使用天数
+        int canBeUsed = chargeLimitations.getLimitDay() - usedAlready;
+
+        Date latestNumberOfDays = DateUtil.addNaturalDays(item.getStartTime(), canBeUsed);
+        int compare = DateUtil.compare(item.getEndTime(), latestNumberOfDays);
+        if (item.getEndTime() == null) {
+            errorMessage.add(StrUtil.format(
+                    "医保限制:【{}】天,请设置停止时间,不得超过【{}】",
+                    chargeLimitations.getLimitDay(), DateUtil.formatDate(latestNumberOfDays, DateUtil.DEFAULT_PATTERN)));
+        } else if (compare > 0) {
+            errorMessage.add(StrUtil.format(
+                    "医保限制:【{}】天,请设置停止时间,不得超过【{}】",
+                    chargeLimitations.getLimitDay(), DateUtil.formatDate(latestNumberOfDays, DateUtil.DEFAULT_PATTERN)));
+        }
+    }
+
     private void strictVerificationFunc(XinZhenYzActOrder item) {
         if (item.getParentNo() != null && item.getActOrderNo() != null) {
             if (BigUtils.bigXiaoYu(item.getActOrderNo(), item.getParentNo())) {
@@ -417,4 +475,9 @@ public class YiZhuCheckData {
         return repel.getCount() > 1;
     }
 
+    public YiZhuCheckData checkForRestrictedMedication() {
+        checkForRestrictedMedication = true;
+        return this;
+    }
+
 }

+ 29 - 1
src/main/java/thyyxxk/webserver/utils/DateUtil.java

@@ -1,5 +1,6 @@
 package thyyxxk.webserver.utils;
 
+import cn.hutool.core.date.DateTime;
 import lombok.extern.slf4j.Slf4j;
 import thyyxxk.webserver.constants.GetDateFormat;
 
@@ -533,7 +534,7 @@ public class DateUtil extends cn.hutool.core.date.DateUtil {
             return null;
         }
         return idNumber.substring(6, 10) + "-" + idNumber.substring(10, 12) +
-                "-" + idNumber.substring(12, 14);
+               "-" + idNumber.substring(12, 14);
     }
 
     public static String calculateAgeLabelByDays(Integer ageDays) {
@@ -554,5 +555,32 @@ public class DateUtil extends cn.hutool.core.date.DateUtil {
         return ageDays + "天";
     }
 
+    /**
+     * printExample("2025-05-21 13:00:00", 3); // 2025-05-23 23:59:59
+     * // 更多示例
+     * printExample("2025-05-21 00:00:01", 1); // 当天结束
+     * printExample("2025-05-21 23:59:59", 2); // 2025-05-22 23:59:59
+     * printExample("2025-12-31 12:00:00", 1); // 2025-12-31 23:59:59
+     * printExample("2025-12-31 12:00:00", 2); // 2026-01-01 23:59:59
+     *
+     * @param date 开始的时间
+     * @param days 加几天
+     * @return 返回日期
+     */
+    public static Date addNaturalDays(Date date, int days) {
+        if (date == null) {
+            return null;
+        }
+        Date addedDate = DateUtil.offsetDay(date, days - 1);
+        return DateUtil.endOfDay(addedDate);
+    }
+
+
+    public static Date addNaturalDays(String dateStr, int days) {
+        Date date = DateUtil.parse(dateStr);
+        return addNaturalDays(date, days);
+    }
+
+
 }