Browse Source

完善违规收费分析规则。

lighter 4 years ago
parent
commit
22ea34a678

+ 37 - 7
src/main/java/thyyxxk/webserver/dao/his/reports/IllegalChargesAnalysisDao.java

@@ -20,8 +20,8 @@ public interface IllegalChargesAnalysisDao {
     @Select("select 1 from t_illegal_charge_template where id=#{id}")
     Integer selectCurrentId(@Param("id") String id);
 
-    @Insert("insert into t_illegal_charge_template (id, label, parent, personal) values " +
-            "(#{id}, #{label}, #{parent}, 1)")
+    @Insert("insert into t_illegal_charge_template (id, label, parent, personal, type) values " +
+            "(#{id}, #{label}, #{parent}, #{personal}, #{type})")
     void insertNewTemplate(IllegalChargeTemplate template);
 
     @Delete("delete from t_illegal_charge_template where id like #{id}")
@@ -39,15 +39,45 @@ public interface IllegalChargesAnalysisDao {
     @Update("update t_illegal_charge_template set label=#{label}, value=#{value},attribute=#{attribute} where id=#{id}")
     void updateTemplate(IllegalChargeTemplate template);
 
-    @Select("select rtrim(inpatient_no) as inpatientNo, " +
-            "admiss_times,detail_sn,charge_date, " +
+    @Select("select rtrim(inpatient_no) as inpatientNo,admiss_times, " +
+            "name=(select rtrim(name) from a_patient_mi where a_patient_mi.inpatient_no=a.inpatient_no), " +
+            "responceType=rtrim(isnull((select responce_type from zy_actpatient where zy_actpatient.inpatient_no=a.inpatient_no), " +
+            "(select responce_type from zy_inactpatient where zy_inactpatient.inpatient_no=a.inpatient_no and " +
+            "zy_inactpatient.admiss_times=a.admiss_times))), " +
+            "deptName=(select rtrim(name) from zd_unit_code where code=a.ward_code), " +
+            "wardName=(select rtrim(name) from zd_unit_code where code=a.dept_code), " +
+            "diag=rtrim(isnull((select admiss_diag_str from zy_actpatient where zy_actpatient.inpatient_no=a.inpatient_no), " +
+            "(select admiss_diag_str from zy_inactpatient where zy_inactpatient.inpatient_no=a.inpatient_no and " +
+            "zy_inactpatient.admiss_times=a.admiss_times))), " +
+            "detail_sn,charge_date, " +
             "rtrim(charge_code_mx) as chargeCode, " +
-            "chargeName=(select rtrim(name) from zd_charge_item where code=charge_code_mx), " +
+            "chargeName=rtrim(isnull((select name from zd_charge_item where code=charge_code_mx)," +
+            "(select top 1 name from yp_zd_dict where code=charge_code_mx))), " +
             "chargeDay=convert(varchar(10),charge_date,21), " +
-            "charge_fee,charge_amount,trans_flag_yb from zy_detail_charge " +
+            "charge_fee,charge_amount,trans_flag_yb from zy_detail_charge a " +
             "where charge_fee>0 and isnull(trans_flag_yb,0)!=2 and charge_date>=#{start} and " +
             "charge_date<=#{end} and charge_code_mx=#{code}")
-    List<IllegalChargeData> selectChargeData(@Param("start") String start,
+    List<IllegalChargeData> selectChargeDataForSameTime(@Param("start") String start,
+                                             @Param("end") String end,
+                                             @Param("code") String code);
+
+    @Select("select rtrim(inpatient_no) as inpatientNo,admiss_times, " +
+            "name=(select rtrim(name) from a_patient_mi where a_patient_mi.inpatient_no=a.inpatient_no), " +
+            "responceType=rtrim(isnull((select responce_type from zy_actpatient where zy_actpatient.inpatient_no=a.inpatient_no), " +
+            "(select responce_type from zy_inactpatient where zy_inactpatient.inpatient_no=a.inpatient_no and " +
+            "zy_inactpatient.admiss_times=a.admiss_times))), " +
+            "deptName=(select rtrim(name) from zd_unit_code where code=a.ward_code), " +
+            "wardName=(select rtrim(name) from zd_unit_code where code=a.dept_code), " +
+            "diag=rtrim(isnull((select admiss_diag_str from zy_actpatient where zy_actpatient.inpatient_no=a.inpatient_no), " +
+            "(select admiss_diag_str from zy_inactpatient where zy_inactpatient.inpatient_no=a.inpatient_no and " +
+            "zy_inactpatient.admiss_times=a.admiss_times))), " +
+            "rtrim(charge_code_mx) as chargeCode, " +
+            "chargeName=rtrim(isnull((select name from zd_charge_item where code=charge_code_mx)," +
+            "(select top 1 name from yp_zd_dict where code=charge_code_mx))), " +
+            "charge_fee,charge_amount from zy_detail_charge a " +
+            "where charge_fee>0 and isnull(trans_flag_yb,0)!=2 and charge_date>=#{start} and " +
+            "charge_date<=#{end} and charge_code_mx=#{code}")
+    List<IllegalChargeData> selectChargeDataForOverLimit(@Param("start") String start,
                                              @Param("end") String end,
                                              @Param("code") String code);
 }

+ 23 - 0
src/main/java/thyyxxk/webserver/entity/reports/illegalChargesAnalysis/IllegalChargeData.java

@@ -11,8 +11,14 @@ import java.util.Date;
  **/
 @Data
 public class IllegalChargeData {
+    private String name;
     private String inpatientNo;
     private Integer admissTimes;
+    private String responceType;
+    private String responceTypeName;
+    private String deptName;
+    private String wardName;
+    private String diag;
     private Integer detailSn;
     private String chargeCode;
     private String chargeName;
@@ -26,4 +32,21 @@ public class IllegalChargeData {
     private Date conflictChargeDate;
     private String conflictChargeFee;
     private String conflictChargeAmount;
+
+    public String getResponceTypeName() {
+        switch (responceType) {
+            case "02":
+                return "省医保";
+            case "03":
+                return "市城居医保";
+            case "04":
+                return "新农合";
+            case "09":
+                return "市城职医保";
+            case "10":
+                return "省医保-异地";
+            default:
+                return "自费";
+        }
+    }
 }

+ 8 - 3
src/main/java/thyyxxk/webserver/entity/reports/illegalChargesAnalysis/IllegalChargeTemplate.java

@@ -43,9 +43,9 @@ public class IllegalChargeTemplate implements Serializable {
 	private Integer personal;
 
 	/**
-	 * 模板属性:1-同时收费模板
+	 * 模板属性:1-同时收费模板 2-超量收费模板
 	 */
-	private String attribute;
+	private Integer attribute;
 
 	/**
 	 * 项目类型:0-目录,1-项目
@@ -67,11 +67,16 @@ public class IllegalChargeTemplate implements Serializable {
 	@TableField(exist = false)
 	private String end;
 
+	@TableField(exist = false)
+	private List<String> responces;
+
 	public void analyzeValue() {
 		if (StringUtil.notBlank(value)) {
 			String[] allCharges = value.split("\\$");
 			setMainCharges(genChargeListFromValue(allCharges[0]));
-			setConflictCharges(genChargeListFromValue(allCharges[1]));
+			if (allCharges.length > 1) {
+				setConflictCharges(genChargeListFromValue(allCharges[1]));
+			}
 		}
 	}
 

+ 66 - 9
src/main/java/thyyxxk/webserver/service/reports/IllegalChargesAnalysisService.java

@@ -4,12 +4,15 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.constants.Capacity;
+import thyyxxk.webserver.constants.ResponceType;
 import thyyxxk.webserver.dao.his.reports.IllegalChargesAnalysisDao;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.dictionary.PureCodeName;
 import thyyxxk.webserver.entity.reports.illegalChargesAnalysis.IllegalChargeData;
 import thyyxxk.webserver.entity.reports.illegalChargesAnalysis.IllegalChargeTemplate;
 import thyyxxk.webserver.entity.reports.illegalChargesAnalysis.SearchChargeItem;
+import thyyxxk.webserver.utils.DecimalUtil;
 import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.StringUtil;
 import thyyxxk.webserver.utils.TokenUtil;
@@ -98,6 +101,7 @@ public class IllegalChargesAnalysisService {
         }
         template.setId(id.toString());
         dao.insertNewTemplate(template);
+        log.info("创建模板:{}", template);
         return ResultVoUtil.success("创建成功。");
     }
 
@@ -122,15 +126,21 @@ public class IllegalChargesAnalysisService {
     }
 
     public ResultVo<String> saveTemplateChanges(IllegalChargeTemplate template) {
+        if (template.getType() == 0) {
+            dao.updateTemplate(template);
+            return ResultVoUtil.success();
+        }
         if (null == template.getMainCharges() || template.getMainCharges().isEmpty()) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "收费主体不能为空!");
         }
-        if (null == template.getConflictCharges() || template.getConflictCharges().isEmpty()) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "冲突收费不能为空!");
+        StringBuilder value = genTemplateValue(template.getMainCharges());
+        if (template.getAttribute() == 1) {
+            if (null == template.getConflictCharges() || template.getConflictCharges().isEmpty()) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "冲突收费不能为空!");
+            }
+            value.append("$").append(genTemplateValue(template.getConflictCharges()));
         }
-        String value = genTemplateValue(template.getMainCharges()).append("$")
-                .append(genTemplateValue(template.getConflictCharges())).toString();
-        template.setValue(value);
+        template.setValue(value.toString());
         dao.updateTemplate(template);
         return ResultVoUtil.success();
     }
@@ -148,15 +158,37 @@ public class IllegalChargesAnalysisService {
     }
 
     public ResultVo<List<IllegalChargeData>> analyzeTargetData(IllegalChargeTemplate template) {
-        String start = template.getStart() + " 00:00:00";
-        String end = template.getEnd() + " 23:59:59";
+        template.setStart(template.getStart() + " 00:00:00");
+        template.setEnd(template.getEnd() + " 23:59:59");
+        if (null == template.getResponces()) {
+            template.setResponces(new ArrayList<>());
+        }
+        if (template.getResponces().isEmpty()) {
+            template.getResponces().add(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE);
+            template.getResponces().add(ResponceType.HUNAN_PROVINCE_REMOTE_MEDICAL_INSURANCE);
+            template.getResponces().add(ResponceType.CHANGSHA_CITY_RESIDENTS_MEDICAL_INSURANCE);
+            template.getResponces().add(ResponceType.CHANGSHA_CITY_WORKERS_MEDICAL_INSURANCE);
+            template.getResponces().add(ResponceType.NEW_RURAL_COOPERATIVE_MEDICAL_INSURANCE);
+        }
+        log.info("违规收费分析:{}", template);
+        if (template.getAttribute() == 1) {
+            return sameTimeCharge(template);
+        }
+        return overLimitCharge(template);
+    }
+
+    private ResultVo<List<IllegalChargeData>> sameTimeCharge(IllegalChargeTemplate template) {
         List<IllegalChargeData> mainList = new ArrayList<>();
         for (PureCodeName mainCharge : template.getMainCharges()) {
-            mainList.addAll(dao.selectChargeData(start, end, mainCharge.getCode()));
+            List<IllegalChargeData> temp = dao.selectChargeDataForSameTime(template.getStart(), template.getEnd(), mainCharge.getCode());
+            temp.removeIf(item -> !template.getResponces().contains(item.getResponceType()));
+            mainList.addAll(temp);
         }
         List<IllegalChargeData> conflictList = new ArrayList<>();
         for (PureCodeName conflictCharge : template.getConflictCharges()) {
-            conflictList.addAll(dao.selectChargeData(start, end, conflictCharge.getCode()));
+            List<IllegalChargeData> temp = dao.selectChargeDataForSameTime(template.getStart(), template.getEnd(), conflictCharge.getCode());
+            temp.removeIf(item -> !template.getResponces().contains(item.getResponceType()));
+            conflictList.addAll(temp);
         }
         Map<String, IllegalChargeData> map = new HashMap<>(mainList.size());
         for (IllegalChargeData item : mainList) {
@@ -179,4 +211,29 @@ public class IllegalChargesAnalysisService {
         }
         return ResultVoUtil.success(resultList);
     }
+
+    private ResultVo<List<IllegalChargeData>> overLimitCharge(IllegalChargeTemplate template) {
+        List<IllegalChargeData> mainList = new ArrayList<>();
+        for (PureCodeName mainCharge : template.getMainCharges()) {
+            List<IllegalChargeData> temp = dao.selectChargeDataForOverLimit(template.getStart(), template.getEnd(), mainCharge.getCode());
+            temp.removeIf(item -> !template.getResponces().contains(item.getResponceType()));
+            mainList.addAll(temp);
+        }
+        Map<String, IllegalChargeData> map = new HashMap<>(Capacity.DEFAULT);
+        for (IllegalChargeData item : mainList) {
+            String key = item.getInpatientNo() + "-" + item.getAdmissTimes();
+            if (map.containsKey(key)) {
+                IllegalChargeData temp = map.get(key);
+                temp.setChargeAmount(DecimalUtil.add(temp.getChargeAmount(), item.getChargeAmount()));
+                temp.setChargeFee(DecimalUtil.add(temp.getChargeFee(), item.getChargeFee()));
+            } else {
+                map.put(key, item);
+            }
+        }
+        List<IllegalChargeData> resultList = new ArrayList<>();
+        for (Map.Entry<String, IllegalChargeData> entry : map.entrySet()) {
+            resultList.add(entry.getValue());
+        }
+        return ResultVoUtil.success(resultList);
+    }
 }