Browse Source

医保结算单上传

xiaochan 3 years ago
parent
commit
8602831eb0

+ 69 - 16
src/main/java/thyyxxk/webserver/dao/his/medicalinsurance/UpIdCollectionDao.java

@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import thyyxxk.webserver.entity.medicalinsurance.setllistupload.*;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -18,20 +19,6 @@ import java.util.List;
 @Mapper
 public interface UpIdCollectionDao {
 
-    @Select("select  rtrim(country) as ntly, " +  // 国籍
-            "        rtrim(social_no) as certno,  " + // 证件
-            "        rtrim(occupation_code) as prfs,  " + // -- 职业 在 Prfs 中有对应的
-            "        rtrim(home_street) as curr_addr ," + // -- 现住址
-            "        rtrim(employer_name) as emp_name, " + //-- 单位名称
-            "        rtrim(employer_street) as emp_addr,  " + //-- 单位地址
-            "        rtrim(employer_tel) as  emp_tel, " +
-            "        rtrim(employer_zipcode) as poscode, " +
-            "       rtrim(relation_name) as coner_name, " +
-            "       relation_code as  patn_rlts,  " + // -- 和患者的关系 (未建枚举)
-            "        rtrim(relation_tel) as  coner_tel " + //  联系人电话
-            "from a_patient_mi " +
-            "where inpatient_no = #{patNo} or mz_no = #{patNo}")
-    SetlinfoUpld setlinfo1(@Param("patNo") String patNo);
 
     @Select("select a.mdtrt_id,   " + // -- 就诊ID
             "       a.setl_id,    " + // -- 结算ID
@@ -57,9 +44,26 @@ public interface UpIdCollectionDao {
             "from t_si_setlinfo a, t_si_pat_info b " +
             "where a.pat_no=b.pat_no and a.times=b.times " +
             "and a.pat_no = #{patNo} and a.times = #{times}")
-    SetlinfoUpld setlinfo2(@Param("patNo") String patNo,
+    SetlinfoUpld setlinfo1(@Param("patNo") String patNo,
                            @Param("times") Integer times);
 
+
+    @Select("select  rtrim(country) as ntly, " +  // 国籍
+            "        rtrim(social_no) as certno,  " + // 证件
+            "        rtrim(occupation_code) as prfs,  " + // -- 职业 在 Prfs 中有对应的
+            "        rtrim(home_street) as curr_addr ," + // -- 现住址
+            "        rtrim(employer_name) as emp_name, " + //-- 单位名称
+            "        rtrim(employer_street) as emp_addr,  " + //-- 单位地址
+            "        rtrim(employer_tel) as  emp_tel, " +
+            "        rtrim(employer_zipcode) as poscode, " +
+            "       rtrim(relation_name) as coner_name, " +
+            "       relation_code as  patn_rlts,  " + // TODO: 2021/11/26  这里可能要转成医保的类型
+            "        rtrim(relation_tel) as  coner_tel " + //  联系人电话
+            "from a_patient_mi " +
+            "where inpatient_no = #{patNo} or mz_no = #{patNo}")
+    SetlinfoUpld setlinfo2(@Param("patNo") String patNo);
+
+
     @Select("select " +
             "       pwcry_bfadm_coma_dura = isnull(ryq_hmsj_day,0)  + '/' + isnull(ryq_hmsj_hour,0) + '/' + isnull(ryq_hmsj_min,0), " + //  -- 颅脑损伤患者入院前昏迷时长
             "       pwcry_afadm_coma_dura = isnull(ryh_hmsj_day,0)  + '/' + isnull(ryh_hmsj_hour,0) + '/' + isnull(ryh_hmsj_min,0),  " + // -- 颅脑损伤患者入院后昏迷时长
@@ -74,13 +78,53 @@ public interface UpIdCollectionDao {
             "       adm_caty = (select si_caty from zd_unit_code where code = b.small_dept),  " + // -- 入院科别
             "       refldept_dept = (select si_caty from zd_unit_code where code = b.zk_ward),  " + //--转科科别
             "        b.dis_date as dscg_time,  " + // -- 出院时间
-            "       dscg_caty = (select si_caty from zd_unit_code where code = b.dis_dept)  " + // -- 出院科别
+            "       dscg_caty = (select si_caty from zd_unit_code where code = b.dis_dept), " + // -- 出院科别
+            "       datediff(day ,b.admiss_date ,b.dis_date) as  act_ipt_days,  " +  // 实际住院天数
+            "       zy_serial_no as biz_sn " +       // 业务流水号
             "from batj_ba2 a,zy_inactpatient b " +
             "where a.bah = b.inpatient_no and a.zycs = b.admiss_times " +
             "and a.bah = #{patNo} and a.zycs = #{times}")
     SetlinfoUpld setlinfo3(@Param("patNo") String patNo,
                            @Param("times") Integer times);
 
+
+    @Select("select  case age_days when  '-' then 0 else age_days end as nwb_age, " +
+            "       rtrim(lxdz2) as  coner_addr, " +
+            "       rtrim(rytj) as  adm_way, " +
+            "        case new_born_weight when  '-' then 0 else age_days end as nwb_bir_wt, " +
+            "        case new_born_admiss_weight when  '-' then 0 else age_days end as nwb_bir_wt" +
+            "       from batj_ba1 where  zyh = #{patNo} and zycs = #{times} ")
+    SetlinfoUpld setlinfo4(@Param("patNo") String patNo,
+                           @Param("times") Integer times);
+
+    @Select("select isnull(sum(charge_amount),0) from zy_detail_charge where inpatient_no = #{patNo} and admiss_times = #{times} and ledger_sn = #{ledgerSn} and infant_flag = #{infantFlag}" +
+            " and charge_code_mx in ('F01464','017051')")
+    Integer teJiHuLi(@Param("patNo") String patNo,
+                     @Param("times") Integer times,
+                     @Param("ledgerSn") Integer ledgerSn,
+                     @Param("infantFlag") Integer infantFlag);
+
+    @Select("select isnull(sum(charge_amount),0) from zy_detail_charge where inpatient_no = #{patNo} and admiss_times = #{times} and ledger_sn = #{ledgerSn} and infant_flag = #{infantFlag}" +
+            " and charge_code_mx in ('F01465','017052')")
+    Integer yiJiHuLi(@Param("patNo") String patNo,
+                     @Param("times") Integer times,
+                     @Param("ledgerSn") Integer ledgerSn,
+                     @Param("infantFlag") Integer infantFlag);
+
+    @Select("select isnull(sum(charge_amount),0) from zy_detail_charge where inpatient_no = #{patNo} and admiss_times = #{times} and ledger_sn = #{ledgerSn} and infant_flag = #{infantFlag}" +
+            " and charge_code_mx in ('F01466','017053')")
+    Integer erJiHuLi(@Param("patNo") String patNo,
+                     @Param("times") Integer times,
+                     @Param("ledgerSn") Integer ledgerSn,
+                     @Param("infantFlag") Integer infantFlag);
+
+    @Select("select isnull(sum(charge_amount),0) from zy_detail_charge where inpatient_no = #{patNo} and admiss_times = #{times} and ledger_sn = #{ledgerSn} and infant_flag = #{infantFlag}" +
+            " and charge_code_mx in ('F01467','017054')")
+    Integer sanJiHuLi(@Param("patNo") String patNo,
+                      @Param("times") Integer times,
+                      @Param("ledgerSn") Integer ledgerSn,
+                      @Param("infantFlag") Integer infantFlag);
+
     // 这里是 住院诊断消息
     @Select("select si_diag_type as diag_type,  " +
             "        rtrim(dis_diag) as diag_code,  " +
@@ -134,4 +178,13 @@ public interface UpIdCollectionDao {
             "group by med_chrgitm_type")
     List<IteminfoUpld> yiLeiFeiYong(@Param("setlId") String setlId);
 
+
+    //   重症监护信息
+    @Select("select op_time from zy_zk_list where inpatient_no=#{patNo} and admiss_times=#{times} and " +
+            "(dept_code in ('1160000','8000160') or f_dept_code in ('1160000','8000160')) " +
+            "order by zk_times")
+    List<Date> zhuanKeShiJian(@Param("patNo") String patNo,
+                              @Param("times") Integer times);
+
+
 }

+ 3 - 1
src/main/java/thyyxxk/webserver/entity/medicalinsurance/setllistupload/UpldCollection.java

@@ -6,7 +6,7 @@ import java.util.List;
 
 /**
  * 【4101】医疗保障基金结算清单信息上传数据包
- * */
+ */
 @Data
 public class UpldCollection {
     private SetlinfoUpld setlinfo;
@@ -16,4 +16,6 @@ public class UpldCollection {
     private List<IteminfoUpld> iteminfo;
     private List<OprninfoUpld> oprninfo;
     private List<IcuinfoUpld> icuinfo;
+
+   
 }

+ 100 - 34
src/main/java/thyyxxk/webserver/service/medicalinsurance/SiManageService.java

@@ -1,10 +1,10 @@
 package thyyxxk.webserver.service.medicalinsurance;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.ListUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
@@ -14,14 +14,17 @@ import thyyxxk.webserver.constants.sidicts.*;
 import thyyxxk.webserver.dao.his.medicalinsurance.SiManageDao;
 import thyyxxk.webserver.dao.his.medicalinsurance.SiSetlinfoDao;
 import thyyxxk.webserver.dao.his.medicalinsurance.UpIdCollectionDao;
+import thyyxxk.webserver.dao.his.yibao.DismissDao;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.dictionary.PureCodeName;
 import thyyxxk.webserver.entity.medicalinsurance.manage.*;
 import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetlinfo;
 import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SlctSetlPrm;
+import thyyxxk.webserver.entity.medicalinsurance.setllistupload.IcuinfoUpld;
 import thyyxxk.webserver.entity.medicalinsurance.setllistupload.IteminfoUpld;
 import thyyxxk.webserver.entity.medicalinsurance.setllistupload.SetlinfoUpld;
 import thyyxxk.webserver.entity.medicalinsurance.setllistupload.UpldCollection;
+import thyyxxk.webserver.service.PublicServer;
 import thyyxxk.webserver.utils.*;
 
 import java.io.IOException;
@@ -49,16 +52,22 @@ public class SiManageService {
 
     private final UpIdCollectionDao upIdCollectionDao;
 
+    private final DismissDao dismissDao;
+
+    private final PublicServer publicServer;
+
 
     @Autowired
     public SiManageService(ExecService exec, SiUploadService upldServcie,
-                           SiDownloadService dldService, SiManageDao dao, SiSetlinfoDao setlinfoDao, UpIdCollectionDao upIdCollectionDao) {
+                           SiDownloadService dldService, SiManageDao dao, SiSetlinfoDao setlinfoDao, UpIdCollectionDao upIdCollectionDao, DismissDao dismissDao, PublicServer publicServer) {
         this.exec = exec;
         this.upldServcie = upldServcie;
         this.dldService = dldService;
         this.dao = dao;
         this.setlinfoDao = setlinfoDao;
         this.upIdCollectionDao = upIdCollectionDao;
+        this.dismissDao = dismissDao;
+        this.publicServer = publicServer;
     }
 
     public ResultVo<String> uploadCatalogueContrast(CatalogueContrast prm) {
@@ -299,48 +308,105 @@ public class SiManageService {
     }
 
     public ResultVo<String> upldCollection(String patNo, Integer times, Integer ledgerSn) throws Exception {
-        UpldCollection upldCollection = new UpldCollection();
+        UpldCollection data = new UpldCollection();
         log.info("入参 住院/门诊:{},次数:{}", patNo, times);
-        SetlinfoUpld setlinfoUpld = upIdCollectionDao.setlinfo1(patNo);
-        setlinfoUpld.setFixmedinsName("长沙泰和医院");
-        setlinfoUpld.setFixmedinsCode("H43010500370");
-        EntityCopy.Copy(upIdCollectionDao.setlinfo2(patNo, times), setlinfoUpld);
+        SetlinfoUpld setlinfoUpld = upIdCollectionDao.setlinfo1(patNo, times);
+        if (StringUtil.isBlank(setlinfoUpld.getSetlId())) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算id为空");
+        }
+        setlinfoUpld.setFixmedinsName(SiUtil.INSTITUTION_NAME);
+        // 特级护理
+        setlinfoUpld.setSpgaNurscareDays(upIdCollectionDao.teJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo)));
+        // 一级护理
+        setlinfoUpld.setLv1NurscareDays(upIdCollectionDao.yiJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo)));
+        // 二级护理
+        setlinfoUpld.setScdNurscareDays(upIdCollectionDao.erJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo)));
+        // 三级护理
+        setlinfoUpld.setLv3NurscareDays(upIdCollectionDao.sanJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo)));
+        setlinfoUpld.setFixmedinsCode(SiUtil.INSTITUTION_ID);
         EntityCopy.Copy(upIdCollectionDao.setlinfo3(patNo, times), setlinfoUpld);
-        upldCollection.setSetlinfo(setlinfoUpld);
+        EntityCopy.Copy(upIdCollectionDao.setlinfo4(patNo, times), setlinfoUpld);
+        EntityCopy.Copy(upIdCollectionDao.setlinfo2(patNo), setlinfoUpld);
+
+        data.setSetlinfo(setlinfoUpld);
 
         // 这里是 住院诊断消息
-        upldCollection.setDiseinfo(upIdCollectionDao.diseinfo(patNo, times));
+        data.setDiseinfo(upIdCollectionDao.diseinfo(patNo, times));
         // 这里是手术操作信息
-        upldCollection.setOprninfo(upIdCollectionDao.oprninfoUplds(patNo, times));
+        data.setOprninfo(upIdCollectionDao.oprninfoUplds(patNo, times));
         // 基金支付信息
-        upldCollection.setPayinfo(upIdCollectionDao.payinfoUpld(patNo, times, ledgerSn));
+        data.setPayinfo(upIdCollectionDao.payinfoUpld(patNo, times, ledgerSn));
 
-        if (StringUtil.isBlank(setlinfoUpld.getSetlId())) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算id为空");
-        } else {
-            String setlId = setlinfoUpld.getSetlId();
-            List<IteminfoUpld> amtAndOthAmt = upIdCollectionDao.amtAndOthAmt(setlId);
 
-            Map<String, IteminfoUpld> jiaLeiFeiYong = upIdCollectionDao.jiaLeiFeiYong(setlId).stream().collect(
-                    Collectors.toMap(IteminfoUpld::getMedChrgitm, a -> a, (k1, k2) -> k1)
-            );
-            Map<String, IteminfoUpld> yiLeiFeiYong = upIdCollectionDao.yiLeiFeiYong(setlId).stream().collect(
-                    Collectors.toMap(IteminfoUpld::getMedChrgitm, a -> a, (k1, k2) -> k1)
-            );
-            for (IteminfoUpld item : amtAndOthAmt) {
-                String key = item.getMedChrgitm();
-                if (jiaLeiFeiYong.containsKey(key)) {
-                    item.setClaaSumfee(jiaLeiFeiYong.get(key).getClaaSumfee());
-                }
-                if (yiLeiFeiYong.containsKey(key)) {
-                    item.setClabAmt(yiLeiFeiYong.get(key).getClabAmt());
-                }
-                item.setOthAmt(item.getAmt().subtract(item.getClaaSumfee()).subtract(item.getClabAmt()).subtract(item.getFulamtOwnpayAmt()));
+        String setlId = setlinfoUpld.getSetlId();
+        List<IteminfoUpld> amtAndOthAmt = upIdCollectionDao.amtAndOthAmt(setlId);
+
+        Map<String, IteminfoUpld> jiaLeiFeiYong = upIdCollectionDao.jiaLeiFeiYong(setlId).stream().collect(
+                Collectors.toMap(IteminfoUpld::getMedChrgitm, a -> a, (k1, k2) -> k1)
+        );
+        Map<String, IteminfoUpld> yiLeiFeiYong = upIdCollectionDao.yiLeiFeiYong(setlId).stream().collect(
+                Collectors.toMap(IteminfoUpld::getMedChrgitm, a -> a, (k1, k2) -> k1)
+        );
+        for (IteminfoUpld item : amtAndOthAmt) {
+            String key = item.getMedChrgitm();
+            if (jiaLeiFeiYong.containsKey(key)) {
+                item.setClaaSumfee(jiaLeiFeiYong.get(key).getClaaSumfee());
+            }
+            if (yiLeiFeiYong.containsKey(key)) {
+                item.setClabAmt(yiLeiFeiYong.get(key).getClabAmt());
             }
-            upldCollection.setIteminfo(amtAndOthAmt);
+            item.setOthAmt(item.getAmt().subtract(item.getClaaSumfee()).subtract(item.getClabAmt()).subtract(item.getFulamtOwnpayAmt()));
         }
+        data.setIteminfo(amtAndOthAmt);
 
-        log.info("医保结算信息上传:{}", JSON.toJSONStringWithDateFormat(upldCollection, DateUtil.DEFAULT_PATTERN));
-        return ResultVoUtil.success();
+        // 重症监护时间
+        List<IcuinfoUpld> zhongZhenJianHu = new ArrayList<>();
+        List<Date> zhuanKeShiJian = upIdCollectionDao.zhuanKeShiJian(patNo, times);
+        if (ListUtil.notBlank(zhuanKeShiJian)) {
+            List<List<Date>> fenGeJianHuShiJian = ListUtils.partition(zhuanKeShiJian, 2);
+            for (List<Date> dateList : fenGeJianHuShiJian) {
+                long diff;
+                Date inpoolTime;
+                Date exitTime;
+                if (dateList.size() == 2) {
+                    inpoolTime = dateList.get(0);
+                    exitTime = dateList.get(1);
+                    diff = dateList.get(1).getTime() - dateList.get(0).getTime();
+                } else {
+                    Date chuYuanShiJian = dismissDao.selectActOrderDisDate(patNo, times);
+                    if (chuYuanShiJian == null) {
+                        chuYuanShiJian = dismissDao.selectActOrderDisDate2(patNo, times);
+                    }
+                    inpoolTime = dateList.get(0);
+                    exitTime = chuYuanShiJian;
+                    diff = chuYuanShiJian.getTime() - dateList.get(0).getTime();
+                }
+                long days = diff / (1000 * 60 * 60 * 24); // 天
+                long hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60); // 小时
+                long minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60); // 分钟
+                String heJi = days + "/" + hours + "/" + minutes;
+                IcuinfoUpld icuinfoUpld = new IcuinfoUpld();
+                icuinfoUpld.setScsCutdWardType("1");
+                icuinfoUpld.setScsCutdInpoolTime(inpoolTime);
+                icuinfoUpld.setScsCutdExitTime(exitTime);
+                icuinfoUpld.setScsCutdSumDura(heJi);
+                zhongZhenJianHu.add(icuinfoUpld);
+            }
+            data.setIcuinfo(zhongZhenJianHu);
+        }
+        JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_SI_SETTLE_INFO, data.getSetlinfo().getInsuplc());
+        input.getJSONObject("input").put("data", data);
+        JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_SI_SETTLE_INFO);
+        log.info("医保结算信息上传:\n参数:{} \n结果:{}", input, result);
+        if (null == result) {
+            return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
+        }
+        if (null == result.getInteger(RESULT_CODE)) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
+        }
+        if (result.getIntValue(RESULT_CODE) == 0) {
+            return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "上传成功");
+        }
+        return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString("err_msg"));
     }
 }

+ 7 - 4
src/main/java/thyyxxk/webserver/utils/EntityCopy.java

@@ -1,7 +1,6 @@
 package thyyxxk.webserver.utils;
 
 import lombok.extern.slf4j.Slf4j;
-import sun.rmi.runtime.Log;
 
 import java.beans.BeanInfo;
 import java.beans.Introspector;
@@ -18,6 +17,10 @@ import java.beans.PropertyDescriptor;
 @Slf4j
 public class EntityCopy {
     public static void Copy(Object source, Object dest) throws Exception {
+        if (source == null) {
+            log.info("复制来源为空");
+            return;
+        }
         // 获取属性
         BeanInfo sourceBean = Introspector.getBeanInfo(source.getClass(), java.lang.Object.class);
         PropertyDescriptor[] sourceProperty = sourceBean.getPropertyDescriptors();
@@ -27,10 +30,10 @@ public class EntityCopy {
 
         try {
             for (int i = 0; i < sourceProperty.length; i++) {
-                            // 调用source的getter方法和dest的setter方法
-               if (destProperty[i].getReadMethod().invoke(dest)==null){
+                // 调用source的getter方法和dest的setter方法
+                if (destProperty[i].getReadMethod().invoke(dest) == null) {
                     destProperty[i].getWriteMethod().invoke(dest, sourceProperty[i].getReadMethod().invoke(source));
-               }
+                }
             }
         } catch (Exception e) {
             throw new Exception("属性复制失败:" + e.getMessage());