Browse Source

优化中间断账和出院结算。

lighter 3 years ago
parent
commit
4d202dc908

+ 2 - 3
src/main/java/thyyxxk/webserver/controller/medicalinsurance/SiInjuryController.java

@@ -128,11 +128,10 @@ public class SiInjuryController {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "获取医保结算费用失败。");
         }
         YbSettleFee settleFee = resultVo.getData();
-        if (p.getDismissFlag() == 2) {
+        if (p.getMidSetl()) {
             settleFee.setZjdzDatetime(p.getMidSetlDate());
         }
-        settleFee.setResponceType("02");
-        settleFee.setFlag(p.getDismissFlag());
+        settleFee.setMidSetl(p.getMidSetl());
         settleFee.setStaffId(TokenUtil.getTokenUserId());
         settleFee.setInpatientNo(p.getInpatientNo());
         settleFee.setAdmissTimes(p.getAdmissTimes());

+ 3 - 5
src/main/java/thyyxxk/webserver/controller/yibao/DismissController.java

@@ -56,7 +56,6 @@ public class DismissController {
     @PostMapping("/selfPayDismiss")
     public synchronized ResultVo<String> selfPayDismiss(@RequestBody YbSettleFee param) {
         param.setStaffId(TokenUtil.getTokenUserId());
-        param.setResponceType("01");
         return service.doDismiss(param);
     }
 
@@ -77,7 +76,7 @@ public class DismissController {
         }
         p.setTable(table);
         p.setStaffId(param.getStaffId());
-        p.setDismissFlag(param.getDismissFlag());
+        p.setMidSetl(param.getDismissFlag() == 2);
         return service.calculateForDismiss(p);
     }
 
@@ -100,11 +99,10 @@ public class DismissController {
         p.setTable(table);
         if (p.getResponceType().equals("01")) {
             YbSettleFee feePojo = new YbSettleFee();
-            feePojo.setResponceType("01");
             feePojo.setInpatientNo(p.getInpatientNo());
             feePojo.setAdmissTimes(p.getAdmissTimes());
             feePojo.setBedNo(p.getBedNo());
-            feePojo.setFlag(param.getDismissFlag());
+            feePojo.setMidSetl(param.getDismissFlag() == 2);
             feePojo.setZjdzDatetime(param.getZjdzDatetime());
             feePojo.setStaffId(param.getStaffId());
             feePojo.setWardCode(p.getAdmissWard());
@@ -115,7 +113,7 @@ public class DismissController {
             ZyPatientInfo zyPatientInfo = new ZyPatientInfo();
             zyPatientInfo.setInpatientNo(param.getInpatientNo());
             zyPatientInfo.setAdmissTimes(param.getAdmissTimes());
-            zyPatientInfo.setDismissFlag(param.getDismissFlag());
+            zyPatientInfo.setMidSetl(param.getDismissFlag() == 2);
             zyPatientInfo.setStaffId(param.getStaffId());
             return zyService.dischargeProcessing(zyPatientInfo);
         }

+ 29 - 12
src/main/java/thyyxxk/webserver/dao/his/medicalinsurance/SiZyDao.java

@@ -69,7 +69,7 @@ public interface SiZyDao {
             "from zy_actpatient a, t_si_pat_info b " +
             "where a.inpatient_no=#{inpatientNo} and b.pat_no=a.inpatient_no " +
             "and b.times=a.admiss_times and b.ledger_sn=#{ledgerSn}")
-    AdmMdtrtinfo selectAdmMdtrtinfo(@Param("inpatientNo") String inpatientNo, 
+    AdmMdtrtinfo selectAdmMdtrtinfo(@Param("inpatientNo") String inpatientNo,
                                     @Param("ledgerSn") int ledgerSn);
 
     @Select("select insuplc_admdvs as code, mdtrt_id as name from t_si_pat_info where " +
@@ -88,7 +88,7 @@ public interface SiZyDao {
     @Select("select isnull(max(ledger_sn), isnull(min(ledger_sn), 1)) from zy_ledger_file where " +
             "inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes}")
     Integer selectMaxLedgerSn(@Param("inpatientNo") String inpatientNo,
-                           @Param("admissTimes") int admissTimes);
+                              @Param("admissTimes") int admissTimes);
 
     /**
      * 撤销医保费用上传后,更改上传标志为0
@@ -133,9 +133,9 @@ public interface SiZyDao {
     /**
      * 获取预结算参数
      *
-     * @param patNo 住院号
-     * @param times 住院次数
-     * @param ledgerSn    账页号
+     * @param patNo    住院号
+     * @param times    住院次数
+     * @param ledgerSn 账页号
      * @return 预结算参数
      */
     @Select("select psn_no,certno as mdtrtCertNo,certno, " +
@@ -149,9 +149,17 @@ public interface SiZyDao {
                               @Param("ledgerSn") int ledgerSn,
                               @Param("today") String today);
 
-    @Select("select start_time from yz_act_order where inpatient_no=#{patNo} and admiss_times=#{times} " +
-            "and status_flag>'1' and isnull(group_no, '00')='00' and order_code in ('06026','06053','05973')")
-    List<Date> selectDscgDate(@Param("patNo") String patNo, @Param("times") int times);
+    @Select("select psn_no,certno as mdtrtCertNo,certno, " +
+            "psn_cert_type,psn_type,mdtrt_id,insutype,insuplc_admdvs, " +
+            "medfeeSumamt=(select sum(charge_fee) from zy_detail_charge b where b.inpatient_no=a.pat_no " +
+            "and b.admiss_times=a.times and b.ledger_sn=a.ledger_sn and isnull(b.infant_flag,0)=0 " +
+            "and trans_flag_yb!=2 and charge_date>=#{begntime} and charge_date<=#{endtime}) " +
+            "from t_si_pat_info a where pat_no=#{patNo} and times=#{times} and ledger_sn=#{ledgerSn}")
+    PreSetlmt selectPreSetlmtForMidSetl(@Param("patNo") String patNo,
+                                        @Param("times") int times,
+                                        @Param("ledgerSn") int ledgerSn,
+                                        @Param("begntime") Date begntime,
+                                        @Param("endtime") Date endtime);
 
     @Select("select a.mdtrt_id,a.psn_no,a.insutype,b.start_time as endtime,b.exec_unit as dscgDeptCodg, " +
             "dscgDeptName=(select rtrim(name) from zd_unit_code where code=b.exec_unit) " +
@@ -163,6 +171,15 @@ public interface SiZyDao {
                             @Param("times") int times,
                             @Param("ledgerSn") int ledgerSn);
 
+    @Select("select a.mdtrt_id,a.psn_no,a.insutype,b.small_dept as dscgDeptCodg, " +
+            "dscgDeptName=(select rtrim(name) from zd_unit_code where code=b.small_dept) " +
+            "from t_si_pat_info a, zy_actpatient b " +
+            "where a.pat_no=#{patNo} and a.times=#{times} and a.ledger_sn=#{ledgerSn} " +
+            "and a.pat_no=b.inpatient_no and a.times=b.admiss_times ")
+    Dscginfo selectDscginfoForMidSetl(@Param("patNo") String patNo,
+                                      @Param("times") int times,
+                                      @Param("ledgerSn") int ledgerSn);
+
     @Select("select insuplc_admdvs from t_si_pat_info where pat_no=#{patNo} and times=#{times} and ledger_sn=#{ledgerSn}")
     String selectAdmdvs(@Param("patNo") String patNo,
                         @Param("times") int times,
@@ -171,8 +188,8 @@ public interface SiZyDao {
     /**
      * 获取患者出院医保诊断
      *
-     * @param patNo 住院号
-     * @param times 住院次数
+     * @param patNo    住院号
+     * @param times    住院次数
      * @param ledgerSn 账页号
      * @return 患者出院医保诊断
      */
@@ -226,8 +243,8 @@ public interface SiZyDao {
 
     @Delete("delete from zy_receipt where inpatient_no=#{patNo} and admiss_times=#{times} and ledger_sn=#{ledgerSn}")
     void deleteZyReceipt(@Param("patNo") String patNo,
-                              @Param("times") int times,
-                              @Param("ledgerSn") int ledgerSn);
+                         @Param("times") int times,
+                         @Param("ledgerSn") int ledgerSn);
 
     @Update("update zy_ledger_file set settle_type=0 where inpatient_no=#{patNo} and admiss_times=#{times} and ledger_sn=#{ledgerSn}")
     void updateSettleType(@Param("patNo") String patNo,

+ 9 - 4
src/main/java/thyyxxk/webserver/dao/his/yibao/DismissDao.java

@@ -204,18 +204,18 @@ public interface DismissDao {
             "isnull((CASE WHEN b.xjzf!=0.00 then b.xjzf when b.xjzf=0.00 then b.total_cost-b.charge_yb end),0)," +
             "settle=deposit-(isnull((CASE WHEN b.xjzf!=0.00 then b.xjzf when " +
             "b.xjzf=0.00 then b.total_cost-b.charge_yb end),0))-0.00,ward_code=#{wardCode}," +
-            "dept_code=#{deptCode},op_id_code=#{codeRs},responce_type=#{responceType},charge_yb=0 from zy_ledger_file," +
+            "dept_code=#{deptCode},op_id_code=#{codeRs},charge_yb=0 from zy_ledger_file," +
             "zy_ledger_file_yb b where zy_ledger_file.inpatient_no=#{patNo} and zy_ledger_file.admiss_times=#{times} " +
             "and zy_ledger_file.ledger_sn=#{ledgerSn} and zy_ledger_file.inpatient_no=b.inpatient_no and " +
             "zy_ledger_file.admiss_times=b.admiss_times and zy_ledger_file.ledger_sn=b.ledger_sn")
     int updateCostStatusWithoutInfant(@Param("patNo") String patNo, @Param("times") Integer times,
                                       @Param("ledgerSn") int ledgerSn, @Param("wardCode") String wardCode,
                                       @Param("deptCode") String deptCode, @Param("codeRs") String codeRs,
-                                      @Param("dismissDate") Date dismissDate, @Param("responceType") String responceType);
+                                      @Param("dismissDate") Date dismissDate);
 
     @Update("update zy_ledger_file set account_date=#{dismissDate},settle_type='1',balance=0,last_balance=" +
             "(zy_ledger_file.total_charge-b.tczf),settle=deposit-(zy_ledger_file.total_charge-b.tczf)," +
-            "ward_code=#{wardCode},dept_code=#{deptCode},op_id_code=#{codeRs},responce_type=#{responceType}," +
+            "ward_code=#{wardCode},dept_code=#{deptCode},op_id_code=#{codeRs}," +
             "charge_yb=0 from zy_ledger_file,zy_ledger_file_yb b where zy_ledger_file.inpatient_no=#{patNo} " +
             "and zy_ledger_file.admiss_times=#{times} and zy_ledger_file.ledger_sn=#{ledgerSn} and " +
             "zy_ledger_file.inpatient_no=b.inpatient_no and zy_ledger_file.admiss_times=b.admiss_times and " +
@@ -223,7 +223,7 @@ public interface DismissDao {
     int updateCostStatusWithInfant(@Param("patNo") String patNo, @Param("times") Integer times,
                                    @Param("ledgerSn") int ledgerSn, @Param("wardCode") String wardCode,
                                    @Param("deptCode") String deptCode, @Param("codeRs") String codeRs,
-                                   @Param("dismissDate") Date dismissDate, @Param("responceType") String responceType);
+                                   @Param("dismissDate") Date dismissDate);
 
     @Update("update zy_detail_charge set charge_status=3 where charge_status=2 and " +
             "inpatient_no=#{patNo} AND admiss_times=#{times} AND ledger_sn=#{ledgerSn}")
@@ -334,6 +334,11 @@ public interface DismissDao {
     @Update("update a_patient_mi set hic_no=#{hicNew} where inpatient_no=#{zyh}")
     void updateHic(@Param("zyh") String zyh, @Param("hicNew") String hicNew);
 
+    @Select("select mdtrt_id from t_si_pat_info where pat_no=#{patNo} and times=#{times} and ledger_sn=#{ledgerSn}")
+    String selectMdtrtId(@Param("patNo") String patNo,
+                         @Param("times") Integer times,
+                         @Param("ledgerSn") int ledgerSn);
+
     @Select("select sum(charge_fee) from zy_detail_charge where inpatient_no=#{patNo} and admiss_times=#{times} " +
             "and ledger_sn=#{ledgerSn} and isnull(charge_status,'1')!='1' and isnull(infant_flag,'0')!='1' ")
     String selectAdultFee(@Param("patNo") String patNo,

+ 2 - 2
src/main/java/thyyxxk/webserver/entity/medicalinsurance/inpatient/ZyPatientInfo.java

@@ -33,8 +33,8 @@ public class ZyPatientInfo {
     private String bedNo;
     private Integer dismissWay;
     private Boolean isDbg;
-    private Integer dismissFlag;
-    private Date midSetlDate;
+    private Boolean midSetl;
+    private Date zjdzDatetime;
     private String staffId;
     private String admdvs;
 

+ 5 - 2
src/main/java/thyyxxk/webserver/entity/yibao/dismiss/YbSettleFee.java

@@ -28,11 +28,14 @@ public class YbSettleFee {
     private String yzsYyjm;
     private String yzsFplx;
     private String yzsMzlx;
-    private String responceType;
     private String bedNo;
-    private Integer flag; // 操作标志,1:出院结算,2:中间断账
+    private Boolean midSetl; // 操作标志,1:出院结算,2:中间断账
     private Date zjdzDatetime;
 
+    public Boolean getMidSetl() {
+        return null != midSetl && midSetl;
+    }
+
     public String getTable() {
         return null == table ? "zy_actpatient" : (table).trim();
     }

+ 6 - 0
src/main/java/thyyxxk/webserver/entity/yibao/patient/Overview.java

@@ -2,6 +2,8 @@ package thyyxxk.webserver.entity.yibao.patient;
 
 import lombok.Data;
 
+import java.util.Date;
+
 /**
  * @author dj
  */
@@ -18,4 +20,8 @@ public class Overview {
     private String staffId;
     private Integer ledgerSn;
     private Integer dismissOrder;
+    // 以下部分中间断账费用上传用
+    private Boolean midSetl;
+    private Date begntime;
+    private Date endtime;
 }

+ 5 - 1
src/main/java/thyyxxk/webserver/entity/yibao/patient/Patient.java

@@ -64,7 +64,7 @@ public class Patient {
     private String disDiagStatus;
     private String operation;
     private String chargeYb;
-    private Integer dismissFlag; // 结算标志,1:出院结算, 2:中间断账
+    private Boolean midSetl; // 中间断账标志
     private Date zjdzDatetime; // 中间断账时间
     private Date dismissOrderDate; // 口腔科生成出院医嘱的出院时间
     private String medType;
@@ -74,6 +74,10 @@ public class Patient {
     private String pretFlag; // 是否早产
     private String mdtrtId;
 
+    public Boolean getMidSetl() {
+        return null != midSetl && midSetl;
+    }
+
     public String getTable() {
         return null == table ? "zy_actpatient" : (table).trim();
     }

+ 26 - 22
src/main/java/thyyxxk/webserver/service/medicalinsurance/SiZyService.java

@@ -11,7 +11,6 @@ import thyyxxk.webserver.constants.sidicts.*;
 import thyyxxk.webserver.constants.YesOrNo;
 import thyyxxk.webserver.dao.his.medicalinsurance.*;
 import thyyxxk.webserver.entity.ResultVo;
-import thyyxxk.webserver.entity.dictionary.PureCodeName;
 import thyyxxk.webserver.entity.medicalinsurance.inpatient.*;
 import thyyxxk.webserver.entity.medicalinsurance.query.SiPatInfo;
 import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetldetail;
@@ -118,22 +117,22 @@ public class SiZyService {
     }
 
     public ResultVo<String> modifyAdmissionInfo(ZyPatientInfo p) {
-        PureCodeName codeName = dao.selectMdtrtId(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
-        if (null == codeName || StringUtil.isBlank(codeName.getName())) {
+        SiPatInfo siPatInfo = qrydao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
+        if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者医保不在院!");
         }
         List<AdmDiseinfo> admDiseinfos = dao.selectAdmDiags(p.getInpatientNo(), p.getAdmissTimes());
         if (null == admDiseinfos || admDiseinfos.isEmpty()) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请填写医保入院诊断!");
         }
-        admDiseinfos.forEach(item -> item.setMdtrtId(codeName.getName()));
-        JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.MODIFY_ADMISSION_INFO, codeName.getCode());
+        admDiseinfos.forEach(item -> item.setMdtrtId(siPatInfo.getMdtrtId()));
+        JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.MODIFY_ADMISSION_INFO, siPatInfo.getInsuplcAdmdvs());
         JSONObject adminfo = new JSONObject();
-        adminfo.put("mdtrt_id", codeName.getName());
-        adminfo.put("psn_no", p.getPsnNo());
+        adminfo.put("mdtrt_id", siPatInfo.getMdtrtId());
+        adminfo.put("psn_no", siPatInfo.getPsnNo());
         adminfo.put("begntime", DateUtil.formatDatetime(p.getYbRegisterDate()));
         adminfo.put("mdtrt_cert_type", MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
-        adminfo.put("med_type", p.getMedType());
+        adminfo.put("med_type", siPatInfo.getMedType());
         adminfo.put("ipt_otp_no", p.getInpatientNo());
         adminfo.put("atddr_no", p.getReferPhysician());
         adminfo.put("chfpdr_name", p.getReferPhysicianName());
@@ -266,17 +265,16 @@ public class SiZyService {
     }
 
     public ResultVo<String> dischargeProcessing(ZyPatientInfo p) {
-        List<Date> dscgDates = dao.selectDscgDate(p.getInpatientNo(), p.getAdmissTimes());
-        if (null == dscgDates || dscgDates.isEmpty()) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有出院医嘱,请检查!");
-        }
-        if (dscgDates.size() > 1) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者的出院医嘱不止1条,请检查!");
-        }
         if (null == p.getLedgerSn()) {
             p.setLedgerSn(dao.selectMaxLedgerSn(p.getInpatientNo(), p.getAdmissTimes()));
         }
-        Dscginfo dscginfo = dao.selectDscginfo(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
+        Dscginfo dscginfo;
+        if (p.getMidSetl()) {
+            dscginfo = dao.selectDscginfoForMidSetl(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
+            dscginfo.setEndtime(p.getZjdzDatetime());
+        } else {
+            dscginfo = dao.selectDscginfo(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
+        }
         if (null == dscginfo || StringUtil.isBlank(dscginfo.getMdtrtId())) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
         }
@@ -339,8 +337,15 @@ public class SiZyService {
     }
 
     private ResultVo<String> inpatientSettlement(ZyPatientInfo p) {
-        PreSetlmt preSetlmt = dao.selectPreSetlmt(p.getInpatientNo(), p.getAdmissTimes(),
-                p.getLedgerSn(), "2099-12-31 23:59:59.999");
+        PreSetlmt preSetlmt;
+        if (p.getMidSetl()) {
+            Date begntime = dismissService.getAdmissDate(p.getInpatientNo(), p.getAdmissTimes(), "zy_actpatient");
+            preSetlmt = dao.selectPreSetlmtForMidSetl(p.getInpatientNo(), p.getAdmissTimes(),
+                    p.getLedgerSn(), begntime, p.getZjdzDatetime());
+        } else {
+            preSetlmt = dao.selectPreSetlmt(p.getInpatientNo(), p.getAdmissTimes(),
+                    p.getLedgerSn(), "2999-12-31 23:59:59.999");
+        }
         if (null == preSetlmt || StringUtil.isBlank(preSetlmt.getMdtrtId())) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
         }
@@ -384,11 +389,10 @@ public class SiZyService {
             }
             // todo 结算,需要改造,慢慢删除responceType字段
             YbSettleFee settleFee = new YbSettleFee();
-            if (p.getDismissFlag() == 2) {
-                settleFee.setZjdzDatetime(p.getMidSetlDate());
+            if (p.getMidSetl()) {
+                settleFee.setZjdzDatetime(p.getZjdzDatetime());
             }
-            settleFee.setResponceType("03");
-            settleFee.setFlag(p.getDismissFlag());
+            settleFee.setMidSetl(p.getMidSetl());
             settleFee.setStaffId(TokenUtil.getTokenUserId());
             settleFee.setInpatientNo(p.getInpatientNo());
             settleFee.setAdmissTimes(p.getAdmissTimes());

+ 50 - 23
src/main/java/thyyxxk/webserver/service/yibao/DismissService.java

@@ -10,7 +10,9 @@ import thyyxxk.webserver.constants.Capacity;
 import thyyxxk.webserver.dao.his.yibao.DismissDao;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.yibao.dismiss.*;
+import thyyxxk.webserver.entity.yibao.patient.Overview;
 import thyyxxk.webserver.entity.yibao.patient.Patient;
+import thyyxxk.webserver.service.externalhttp.SiZySrvc;
 import thyyxxk.webserver.utils.*;
 
 import java.util.ArrayList;
@@ -25,10 +27,12 @@ import java.util.List;
 @Service
 public class DismissService {
     private final DismissDao dao;
+    private final SiZySrvc zySrvc;
 
     @Autowired
-    public DismissService(DismissDao dao) {
+    public DismissService(DismissDao dao, SiZySrvc zySrvc) {
         this.dao = dao;
+        this.zySrvc = zySrvc;
     }
 
     public ResultVo<Object> dismiss(Patient param) {
@@ -93,11 +97,11 @@ public class DismissService {
     }
 
     public ResultVo<List<NegativeFee>> calculateForDismiss(Patient param) {
-        String logtype = param.getDismissFlag() == 1 ? "出院结算" : "中间断账";
+        String logtype = param.getMidSetl() ? "中间断账" : "出院结算";
         log.info("{}费用计算:{}", logtype, param);
         final String patNo = param.getInpatientNo();
         final Integer times = param.getAdmissTimes();
-        if (param.getDismissFlag() == 1) {
+        if (!param.getMidSetl()) {
             Integer disActOrderCount = dao.countDisActOrders(patNo, times);
             if (null == disActOrderCount || disActOrderCount == 0) {
                 disActOrderCount = dao.countDisActOrders2(patNo, times);
@@ -121,7 +125,7 @@ public class DismissService {
             exception.setMessage("没有找到入院时间,请重新获取病人信息。");
             throw new BizException(exception);
         }
-        Date actOrderDisDate = getDismissDate(param.getDismissFlag(), patNo, times, param.getZjdzDatetime());
+        Date actOrderDisDate = getDismissDate(param.getMidSetl(), patNo, times, param.getZjdzDatetime());
         final int ledgerSn = dao.getLedgerSn(patNo, times);
         if (dao.hasUnsettledStepOne(patNo, times, ledgerSn) < 0) {
             ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
@@ -182,7 +186,7 @@ public class DismissService {
             exception.setMessage("此患者明细费用与账页费用不一致。");
             throw new BizException(exception);
         }
-        final Integer transFlag = param.getDismissFlag() == 1 ? 0 : 2;
+        final Integer transFlag = param.getMidSetl() ? 2 : 0;
         List<ReceiptFee> receiptFees = dao.calculateCost(patNo, times, ledgerSn, param.getStaffId(),
                 param.getAdmissDate(), actOrderDisDate, param.getAdmissWard(), param.getAdmissDept(), transFlag);
         if (null == receiptFees || receiptFees.isEmpty()) {
@@ -191,6 +195,28 @@ public class DismissService {
             throw new BizException(exception);
         }
         dao.deleteTemporaryTable(patNo, times);
+
+        String mdtrtId = dao.selectMdtrtId(patNo, times, ledgerSn);
+        if (StringUtil.notBlank(mdtrtId)) {
+            Overview o = new Overview();
+            o.setInpatientNo(patNo);
+            o.setAdmissTimes(times);
+            o.setLedgerSn(ledgerSn);
+            o.setStaffId(param.getStaffId());
+            o.setSid(param.getSid());
+            o.setMidSetl(param.getMidSetl());
+            if (o.getMidSetl()) {
+                Date begntime = getAdmissDate(patNo,times,"zy_actpatient");
+                o.setBegntime(begntime);
+                o.setEndtime(param.getZjdzDatetime());
+            }
+            ResultVo<String> feeCheck = zySrvc.uploadFeeDetail(o);
+            if (feeCheck.getCode() != ExceptionEnum.SUCCESS.getCode()) {
+                ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
+                exception.setMessage(feeCheck.getMessage());
+                throw new BizException(exception);
+            }
+        }
         return ResultVoUtil.success();
     }
 
@@ -198,8 +224,9 @@ public class DismissService {
     public ResultVo<String> doDismiss(YbSettleFee settleFee) throws BizException {
         updateHicNo(settleFee.getInpatientNo());
         settleFee.setLedgerSn(dao.getLedgerSn(settleFee.getInpatientNo(), settleFee.getAdmissTimes()));
-        // 自费病人不进行医保结算
-        if (!settleFee.getResponceType().trim().equals("01")) {
+        String mdtrtId = dao.selectMdtrtId(settleFee.getInpatientNo(), settleFee.getAdmissTimes(), settleFee.getLedgerSn());
+        // 医保病人进行医保结算
+        if (StringUtil.notBlank(mdtrtId)) {
             int write;
             dao.deleteZyLedgerFileYb(settleFee.getInpatientNo(), settleFee.getAdmissTimes(), settleFee.getLedgerSn());
             String cashPay = settleFee.getXjzf();
@@ -222,8 +249,8 @@ public class DismissService {
             exception.setMessage("写发票表失败。");
             throw new BizException(exception);
         }
-        int code = settleFee.getFlag() == 1 ? setHisStatusOut(settleFee) : hisMiddleSettle(settleFee);
-        if (updateCostStatusToSettled(settleFee) < 1) {
+        int code = settleFee.getMidSetl() ? setHisStatusOut(settleFee) : hisMiddleSettle(settleFee);
+        if (updateCostStatusToSettled(settleFee, StringUtil.notBlank(mdtrtId)) < 1) {
             ExceptionEnum exception = ExceptionEnum.LOGICAL_ERROR;
             exception.setMessage("更新费用状态失败。");
             throw new BizException(exception);
@@ -244,9 +271,9 @@ public class DismissService {
         final int infantFlag = dao.selectInfantFlag(indata.getInpatientNo(), indata.getAdmissTimes(),
                 indata.getLedgerSn()); // =0 无婴儿,>0 有婴儿
         final Date admissDate = getAdmissDate(indata.getInpatientNo(), indata.getAdmissTimes(), indata.getTable());
-        final Date dismissDate = getDismissDate(indata.getFlag(), indata.getInpatientNo(), indata.getAdmissTimes(),
+        final Date dismissDate = getDismissDate(indata.getMidSetl(), indata.getInpatientNo(), indata.getAdmissTimes(),
                 indata.getZjdzDatetime());
-        final Integer transFlag = indata.getFlag() == 1 ? 0 : 2;
+        final Integer transFlag = indata.getMidSetl() ? 2 : 0;
         final List<ReceiptFee> fees = dao.calculateCost(indata.getInpatientNo(), indata.getAdmissTimes(),
                 indata.getLedgerSn(), indata.getStaffId(), admissDate, dismissDate, indata.getWardCode(),
                 indata.getDeptCode(), transFlag);
@@ -295,7 +322,7 @@ public class DismissService {
         return new String[]{adultCharge, infantCharge};
     }
 
-    private Date getAdmissDate(String patNo, int times, String table) {
+    public Date getAdmissDate(String patNo, int times, String table) {
         Date admdate = dao.selectAccountDate(patNo, times);
         if (null == admdate) {
             admdate = dao.selectAdmissDate(patNo, times, table);
@@ -303,8 +330,8 @@ public class DismissService {
         return admdate;
     }
 
-    private Date getDismissDate(Integer flag, String patNo, Integer times, Date zjdzDate) {
-        if (flag == 2) {
+    private Date getDismissDate(Boolean midsetl, String patNo, Integer times, Date zjdzDate) {
+        if (midsetl) {
             return zjdzDate;
         }
         Date disdate = dao.selectActOrderDisDate(patNo, times);
@@ -314,19 +341,19 @@ public class DismissService {
         return disdate;
     }
 
-    private int updateCostStatusToSettled(YbSettleFee param) {
-        Date date = param.getFlag() == 1 ? new Date() : param.getZjdzDatetime();
+    private int updateCostStatusToSettled(YbSettleFee param, boolean medins) {
+        Date date = param.getMidSetl() ? param.getZjdzDatetime() : new Date();
         final int code;
-        if (param.getResponceType().equals("01")) {
-            code = dao.updateZifeiCostStatus(param.getInpatientNo(), param.getAdmissTimes(), param.getLedgerSn(),
-                    param.getWardCode(), param.getDeptCode(), param.getStaffId(), date);
-        } else {
+        if (medins) {
             final int hasInfant = dao.hasInfant(param.getInpatientNo(), param.getAdmissTimes());
             code = hasInfant == 0 ?
                     dao.updateCostStatusWithoutInfant(param.getInpatientNo(), param.getAdmissTimes(), param.getLedgerSn(),
-                            param.getWardCode(), param.getDeptCode(), param.getStaffId(), date, param.getResponceType()) :
+                            param.getWardCode(), param.getDeptCode(), param.getStaffId(), date) :
                     dao.updateCostStatusWithInfant(param.getInpatientNo(), param.getAdmissTimes(), param.getLedgerSn(),
-                            param.getWardCode(), param.getDeptCode(), param.getStaffId(), date, param.getResponceType());
+                            param.getWardCode(), param.getDeptCode(), param.getStaffId(), date);
+        } else {
+            code = dao.updateZifeiCostStatus(param.getInpatientNo(), param.getAdmissTimes(), param.getLedgerSn(),
+                    param.getWardCode(), param.getDeptCode(), param.getStaffId(), date);
         }
         if (code < 1) {
             return -1;
@@ -369,7 +396,7 @@ public class DismissService {
 
     private int insertNewZyWorkLog(YbSettleFee param) {
         final String userName = dao.getOperateName(param.getStaffId());
-        String logType = param.getFlag() == 1 ? "cyjs" : "zjdz";
+        String logType = param.getMidSetl() ? "zjdz" : "cyjs";
         return dao.insertNewZyWorkLog(param.getInpatientNo(), param.getAdmissTimes(), param.getLedgerSn(),
                 param.getWardCode(), logType, param.getDeptCode(), param.getStaffId(), userName);
     }