|
@@ -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"));
|
|
|
}
|
|
|
}
|