|
|
@@ -0,0 +1,524 @@
|
|
|
+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.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+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;
|
|
|
+import thyyxxk.webserver.constants.GetDateFormat;
|
|
|
+import thyyxxk.webserver.constants.sidicts.*;
|
|
|
+import thyyxxk.webserver.dao.his.medicalinsurance.SiManageDao;
|
|
|
+import thyyxxk.webserver.dao.his.medicalinsurance.SiQueryDao;
|
|
|
+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.datamodify.GetDropdownBox;
|
|
|
+import thyyxxk.webserver.entity.datamodify.TYbSetModifyTime;
|
|
|
+import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyDisDiagYb;
|
|
|
+import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyInactpatient;
|
|
|
+import thyyxxk.webserver.entity.medicalinsurance.query.SiSetlFeeDetl;
|
|
|
+import thyyxxk.webserver.entity.medicalinsurance.setllistupload.*;
|
|
|
+import thyyxxk.webserver.entity.querydata.JieSuanDanChaXun;
|
|
|
+import thyyxxk.webserver.entity.querydata.TSiSetlinfo;
|
|
|
+import thyyxxk.webserver.service.PublicServer;
|
|
|
+import thyyxxk.webserver.utils.*;
|
|
|
+import thyyxxk.webserver.websocket.WebSocketServer;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 医保管理服务,包涵项目对照等
|
|
|
+ * @author: DingJie
|
|
|
+ * @create: 2021/6/2914:44
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class SetlListUpldService {
|
|
|
+ private static final String RESULT_CODE = "infcode";
|
|
|
+ private static final String ERROR_MESSAGE = "err_msg";
|
|
|
+ private static final String OUTPUT = "output";
|
|
|
+ private final ExecService exec;
|
|
|
+ private final SiUploadService upldServcie;
|
|
|
+ private final SiDownloadService dldService;
|
|
|
+ private final SiManageDao dao;
|
|
|
+ private final SiSetlinfoDao setlinfoDao;
|
|
|
+ private final SiQueryDao queryDao;
|
|
|
+
|
|
|
+ private final UpIdCollectionDao upIdCollectionDao;
|
|
|
+
|
|
|
+ private final DismissDao dismissDao;
|
|
|
+
|
|
|
+ private final PublicServer publicServer;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public SetlListUpldService(ExecService exec, SiUploadService upldServcie,
|
|
|
+ SiDownloadService dldService, SiManageDao dao, SiSetlinfoDao setlinfoDao, SiQueryDao queryDao, UpIdCollectionDao upIdCollectionDao, DismissDao dismissDao, PublicServer publicServer) {
|
|
|
+ this.exec = exec;
|
|
|
+ this.upldServcie = upldServcie;
|
|
|
+ this.dldService = dldService;
|
|
|
+ this.dao = dao;
|
|
|
+ this.setlinfoDao = setlinfoDao;
|
|
|
+ this.queryDao = queryDao;
|
|
|
+ this.upIdCollectionDao = upIdCollectionDao;
|
|
|
+ this.dismissDao = dismissDao;
|
|
|
+ this.publicServer = publicServer;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<String> upldSetlList(String patNo, Integer times, Integer ledgerSn) throws Exception {
|
|
|
+ ResultVo<UpldCollection> upldCollection = getUploadInfo(patNo, times, ledgerSn);
|
|
|
+ if (upldCollection.getCode() != 200) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldCollection.getMessage());
|
|
|
+ }
|
|
|
+ JSONObject input = new JSONObject();
|
|
|
+ input.put("setlinfo", JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(upldCollection.getData().getSetlinfo(), "yyyy-MM-dd HH:mm:ss")));
|
|
|
+ input.put("payinfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getPayinfo())));
|
|
|
+ input.put("opspdiseinfo", new JSONArray());
|
|
|
+ input.put("diseinfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getDiseinfo())));
|
|
|
+ input.put("iteminfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getIteminfo())));
|
|
|
+ input.put("oprninfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getOprninfo())));
|
|
|
+ input.put("icuinfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getIcuinfo())));
|
|
|
+ JSONObject jsonObject = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_SI_SETTLE_INFO, upldCollection.getData().getSetlinfo().getInsuplc());
|
|
|
+ jsonObject.replace("input", input);
|
|
|
+ // 这里是上传
|
|
|
+ JSONObject result = exec.executeTrade(jsonObject, SiFunction.UPLOAD_SI_SETTLE_INFO);
|
|
|
+
|
|
|
+// JSONObject result = new JSONObject();
|
|
|
+// if (times % 2 == 0) {
|
|
|
+// result.put("infcode", 0);
|
|
|
+// } else {
|
|
|
+// result.put("infcode", -1);
|
|
|
+// result.put("err_msg", "知道你为啥失败吗?");
|
|
|
+// }
|
|
|
+ log.info("医保结算信息上传 \n操作人:{}\n参数:{} \n结果:{}", TokenUtil.getTokenUserId(), jsonObject, result);
|
|
|
+ if (null == result) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (null == result.getInteger(RESULT_CODE)) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("医保中心报错:【%s】 ", result.getString("message")));
|
|
|
+ }
|
|
|
+ if (result.getIntValue(RESULT_CODE) == 0) {
|
|
|
+ upIdCollectionDao.fanHuiLiuShuiHao(result.getJSONObject(OUTPUT).getString("setl_list_id"), upldCollection.getData().getSetlinfo().getSetlId());
|
|
|
+ return ResultVoUtil.success(ExceptionEnum.SUCCESS, "上传成功");
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("医保中心报错:【%s】 ", result.getString("err_msg")));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<UpldCollection> getUploadInfo(String patNo, Integer times, Integer ledgerSn) throws Exception {
|
|
|
+ log.info("住院号:{},次数:{},账页:{}", patNo, times, ledgerSn);
|
|
|
+ SetlinfoUpld setlinfoUpld = upIdCollectionDao.setlinfo1(patNo, times, ledgerSn);
|
|
|
+ if (StringUtil.isBlank(setlinfoUpld.getSetlId())) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算id为空");
|
|
|
+ }
|
|
|
+ if (!setlinfoUpld.getInsuplc().startsWith("4301") || setlinfoUpld.getInsuplc().equals("430182")) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者参保地不属于长沙市,无法上传结算清单。");
|
|
|
+ }
|
|
|
+ setlinfoUpld.setFixmedinsName(SiUtil.INSTITUTION_NAME);
|
|
|
+ // 特级护理
|
|
|
+ setlinfoUpld.setSpgaNurscareDays(String.valueOf(upIdCollectionDao.teJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn,
|
|
|
+ publicServer.getInfantFlag(patNo))));
|
|
|
+ // 一级护理
|
|
|
+ setlinfoUpld.setLv1NurscareDays(String.valueOf(upIdCollectionDao.yiJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo))));
|
|
|
+ // 二级护理
|
|
|
+ setlinfoUpld.setScdNurscareDays(String.valueOf(upIdCollectionDao.erJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo))));
|
|
|
+ // 三级护理
|
|
|
+ setlinfoUpld.setLv3NurscareDays(String.valueOf(upIdCollectionDao.sanJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo))));
|
|
|
+ setlinfoUpld.setFixmedinsCode(SiUtil.INSTITUTION_ID);
|
|
|
+
|
|
|
+ // TokenUtil.getTokenUserId()
|
|
|
+ GetDropdownBox getDropdownBox = upIdCollectionDao.userInfo(TokenUtil.getTokenUserId());
|
|
|
+ // 医疗机构填报人
|
|
|
+ setlinfoUpld.setMedinsFillPsn(getDropdownBox.getName());
|
|
|
+ // 医疗机构填报部门
|
|
|
+ setlinfoUpld.setMedinsFillDept(getDropdownBox.getDeptName());
|
|
|
+ // 医保机构经办人
|
|
|
+ setlinfoUpld.setHsorgOpter("未知");
|
|
|
+ setlinfoUpld.setBillNo(upIdCollectionDao.billNo(patNo, times, ledgerSn));
|
|
|
+ List<OprninfoUpld> oprninfoUpld = upIdCollectionDao.oprninfoUplds(patNo, times);
|
|
|
+
|
|
|
+ if (ListUtil.notBlank(oprninfoUpld)) {
|
|
|
+ // 用来存放最大的手术级别
|
|
|
+ int[] zhuYaoShouShu = new int[oprninfoUpld.size()];
|
|
|
+ for (int i = 0; i < oprninfoUpld.size(); i++) {
|
|
|
+ String ssjb = oprninfoUpld.get(i).getOprnOprtType();
|
|
|
+ if (ssjb.equals("")) { // 判断手术级别是否为空
|
|
|
+ ssjb = "1"; // 为空就设置为 1
|
|
|
+ }
|
|
|
+ zhuYaoShouShu[i] = Integer.parseInt(ssjb); // 存放手术级别
|
|
|
+ oprninfoUpld.get(i).setOprnOprtType("2"); //全部设置为 2
|
|
|
+ }
|
|
|
+ // 最大的设置为一
|
|
|
+ oprninfoUpld.get(getMaxIndex(zhuYaoShouShu)).setOprnOprtType("1");
|
|
|
+ }
|
|
|
+ // 手术计数
|
|
|
+ setlinfoUpld.setOprnOprtCodeCnt(String.valueOf(oprninfoUpld.size()));
|
|
|
+
|
|
|
+ EntityCopy.Copy(upIdCollectionDao.setlinfo2(patNo), setlinfoUpld);
|
|
|
+ EntityCopy.Copy(upIdCollectionDao.setlinfo3(patNo, times), setlinfoUpld);
|
|
|
+ EntityCopy.Copy(upIdCollectionDao.setlinfo4(patNo, times), setlinfoUpld);
|
|
|
+
|
|
|
+ String setlId = setlinfoUpld.getSetlId();
|
|
|
+ List<IteminfoUpld> amtAndOthAmt = upIdCollectionDao.amtAndOthAmt(setlId);
|
|
|
+ if (null == amtAndOthAmt || amtAndOthAmt.isEmpty()) {
|
|
|
+ ResultVo<String> chrgitems = getChrgitems(patNo, setlId, setlinfoUpld.getMdtrtId(), setlinfoUpld.getInsuplc());
|
|
|
+ if (chrgitems.getCode() != 200) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, chrgitems.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ setlinfoUpld.setSetlBegnDate(setlinfoUpld.getAdmTime());
|
|
|
+ setlinfoUpld.setBillCode(setlinfoUpld.getMedcasno() + "_" + ledgerSn);
|
|
|
+ setlinfoUpld.setBizSn(SnowFlakeId.instance().nextId());
|
|
|
+
|
|
|
+ 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)
|
|
|
+ );
|
|
|
+ if (ListUtil.notBlank(amtAndOthAmt)) {
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ String a = DecimalUtil.minus(item.getAmt(), item.getClaaSumfee());
|
|
|
+ a = DecimalUtil.minus(a, item.getClabAmt());
|
|
|
+ a = DecimalUtil.minus(a, item.getFulamtOwnpayAmt());
|
|
|
+ item.setOthAmt(a);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 重症监护时间
|
|
|
+ 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 zhongZhengJianHuShiJian = days + "/" + hours + "/" + minutes;
|
|
|
+ IcuinfoUpld icuinfoUpld = new IcuinfoUpld();
|
|
|
+ icuinfoUpld.setScsCutdWardType("1");
|
|
|
+ icuinfoUpld.setScsCutdInpoolTime(inpoolTime);
|
|
|
+ icuinfoUpld.setScsCutdExitTime(exitTime);
|
|
|
+ icuinfoUpld.setScsCutdSumDura(zhongZhengJianHuShiJian);
|
|
|
+ zhongZhenJianHu.add(icuinfoUpld);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<PayinfoUpld> payinfo = upIdCollectionDao.payinfoUpld(patNo, times, ledgerSn);
|
|
|
+ List<DiseinfoUpld> diseinfos = upIdCollectionDao.diseinfo(patNo, times);
|
|
|
+
|
|
|
+ UpldCollection upldCollection = new UpldCollection();
|
|
|
+ // 患者的基本信息
|
|
|
+ upldCollection.setSetlinfo(setlinfoUpld);
|
|
|
+ // 基金支付信息
|
|
|
+ upldCollection.setPayinfo(payinfo);
|
|
|
+ // 门特慢特病诊断信息 目前还没有
|
|
|
+ // upldCollection.setOpspdiseinfo(new ArrayList<>());
|
|
|
+ // 住院诊断信息
|
|
|
+ upldCollection.setDiseinfo(diseinfos);
|
|
|
+ // 收费项目信息
|
|
|
+ upldCollection.setIteminfo(amtAndOthAmt);
|
|
|
+ // 手术操作信息
|
|
|
+ upldCollection.setOprninfo(oprninfoUpld);
|
|
|
+ // 重症监护信息
|
|
|
+ upldCollection.setIcuinfo(zhongZhenJianHu);
|
|
|
+ return ResultVoUtil.success(upldCollection);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 多个患者上传
|
|
|
+ *
|
|
|
+ * @param param 患者信息
|
|
|
+ * @return 返回
|
|
|
+ */
|
|
|
+ public ResultVo<String> upldSetlListBatch(List<TSiSetlinfo> param) {
|
|
|
+ if (ListUtil.isBlank(param)) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请选择需要上传的患者。");
|
|
|
+ }
|
|
|
+ for (int i = 0; i < param.size(); i++) {
|
|
|
+ TSiSetlinfo siPatInfo = param.get(i);
|
|
|
+ int percentage = makePercentage(i + 1, param.size());
|
|
|
+ try {
|
|
|
+ ResultVo<String> resultVo = upldSetlList(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn());
|
|
|
+ upldSetlErrorMessage(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn(),
|
|
|
+ resultVo.getMessage(), resultVo.getCode() == 200 ? 0 : 1, percentage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("批量上传结算单错误:{}", JSON.toJSONString(e));
|
|
|
+ e.printStackTrace();
|
|
|
+ upldSetlErrorMessage(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn(),
|
|
|
+ e.getMessage(), 2, percentage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 全部上传
|
|
|
+ *
|
|
|
+ * @return 返回信息
|
|
|
+ */
|
|
|
+ public ResultVo<String> upldSetlListTimes(JieSuanDanChaXun param) {
|
|
|
+ try {
|
|
|
+ param.setPageSize(param.getTotal());
|
|
|
+ List<TSiSetlinfo> list = huoQuJieSuanRenYuan(param).getData().getRecords();
|
|
|
+ if (ListUtil.isBlank(list)) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有要上传的信息。");
|
|
|
+ }
|
|
|
+ upldSetlListBatch(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("时间范围上传结算单错误:{}", JSON.toJSONString(e));
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送医保上传的错误信息
|
|
|
+ *
|
|
|
+ * @param meg 错误消息
|
|
|
+ */
|
|
|
+ public void upldSetlErrorMessage(String patNo, Integer times, Integer ledgerSn, String meg, int type, int percentage) {
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("name", "upldSetlListMessage");
|
|
|
+ obj.put("patNo#住院号|1", patNo);
|
|
|
+ obj.put("times#住院次数|2", times);
|
|
|
+ obj.put("ledgerSn#账页号|3", ledgerSn);
|
|
|
+ obj.put("message#上传结果|4", meg);
|
|
|
+ obj.put("type#类型|5", type);
|
|
|
+ obj.put("percentage", percentage);
|
|
|
+ obj.put("title", String.format("住院号:【%s】,住院次数:【%d】,账页号:【%d】。", patNo, times, ledgerSn));
|
|
|
+ String message = obj.toJSONString();
|
|
|
+ WebSocketServer.sendMessageByUserCode(TokenUtil.getTokenUserId(), message);
|
|
|
+ log.info("发送错误通知:{}", message);
|
|
|
+ }
|
|
|
+
|
|
|
+ private int makePercentage(int index, int size) {
|
|
|
+ float per = (float) index / (float) size;
|
|
|
+ return (int) (per * 100);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取最大值的下标
|
|
|
+ *
|
|
|
+ * @param arr int 数组
|
|
|
+ * @return 返回下标
|
|
|
+ */
|
|
|
+ public int getMaxIndex(int[] arr) {
|
|
|
+ int maxIndex = 0; //获取到的最大值的角标
|
|
|
+ for (int i = 0; i < arr.length; i++) {
|
|
|
+ if (arr[i] > arr[maxIndex]) {
|
|
|
+ maxIndex = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return maxIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResultVo<String> getChrgitems(String patNo, String setlId, String mdtrtId, String admdvs) {
|
|
|
+ JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_FEE_DETAILS, admdvs);
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("psn_no", queryDao.selectPsnNo(patNo));
|
|
|
+ data.put("setl_id", setlId);
|
|
|
+ data.put("mdtrt_id", mdtrtId);
|
|
|
+ input.getJSONObject("input").put("data", data);
|
|
|
+ JSONObject result = exec.executeTrade(input, SiFunction.QUERY_FEE_DETAILS);
|
|
|
+ log.info("【操作员:{}】,【结算单上传】查询费用明细:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), 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 (0 == result.getInteger(RESULT_CODE)) {
|
|
|
+ JSONArray output = result.getJSONArray(OUTPUT);
|
|
|
+ if (null == output || output.size() == 0) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到费用明细。");
|
|
|
+ }
|
|
|
+ List<SiSetlFeeDetl> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < output.size(); i++) {
|
|
|
+ list.add(JSONObject.parseObject(output.getJSONObject(i).toJSONString(), SiSetlFeeDetl.class));
|
|
|
+ if (list.size() == 30) {
|
|
|
+ queryDao.insertSetlFeeDetlBatch(list);
|
|
|
+ list.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (list.size() > 0) {
|
|
|
+ queryDao.insertSetlFeeDetlBatch(list);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success("查询成功。");
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, result.getString(ERROR_MESSAGE));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取医保结算单信息
|
|
|
+ *
|
|
|
+ * @param param 参数
|
|
|
+ * @return 返回数据
|
|
|
+ */
|
|
|
+ public ResultVo<IPage<TSiSetlinfo>> huoQuJieSuanRenYuan(JieSuanDanChaXun param) {
|
|
|
+ IPage<TSiSetlinfo> page = new Page<>();
|
|
|
+ page.setRecords(upIdCollectionDao.huoQuJieSuanRenYuan(param.getStartTime(), param.getEndTime(), param.getClrType(), param.getPatNo(),
|
|
|
+ param.getInsutype(), param.getOutDept(), param.getMedType(), param.getPsnType(), param.getClrOptins(), param.getFlag(), param.getCurrentPage(),
|
|
|
+ param.getPageSize()));
|
|
|
+ if (ListUtil.isBlank(page.getRecords())) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
|
|
|
+ }
|
|
|
+ Set<String> inpatientNos = new HashSet<>();
|
|
|
+ for (TSiSetlinfo item : page.getRecords()) {
|
|
|
+ inpatientNos.add(item.getPatNo());
|
|
|
+ item.setGendName(item.getGend().equals("1") ? "男" : "女");
|
|
|
+ if (item.getClrOptinsName() == null) {
|
|
|
+ item.setClrOptinsName(Objects.requireNonNull(Admdvs.get(item.getClrOptins())).getName());
|
|
|
+ }
|
|
|
+ Insutype insutype = Insutype.get(item.getInsutype());
|
|
|
+ if (null != insutype) {
|
|
|
+ item.setInsutypeName(insutype.getName());
|
|
|
+ }
|
|
|
+ PsnType psnType = PsnType.get(item.getPsnType());
|
|
|
+ if (null != psnType) {
|
|
|
+ item.setPsnTypeName(psnType.getName());
|
|
|
+ }
|
|
|
+ MedType medType = MedType.get(item.getMedType());
|
|
|
+ if (null != medType) {
|
|
|
+ item.setMedTypeName(medType.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, ZyDisDiagYb> zhuZhenDuan = upIdCollectionDao.zhuZhenDuan(inpatientNos).stream().collect(
|
|
|
+ Collectors.toMap(item -> item.getInpatientNo() + item.getAdmissTimes(), a -> a, (k1, k2) -> k1)
|
|
|
+ );
|
|
|
+ for (TSiSetlinfo item : page.getRecords()) {
|
|
|
+ String key = item.getPatNo() + item.getTimes();
|
|
|
+ ZyDisDiagYb dis = zhuZhenDuan.get(key);
|
|
|
+ if (dis != null) {
|
|
|
+ item.setDisDiag(dis.getDisDiag());
|
|
|
+ item.setDisDiagComment(dis.getDisDiagComment());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (param.getTotal() == 0) {
|
|
|
+ page.setTotal(upIdCollectionDao.huoQuJieSuanRenYuanTotal(param.getStartTime(), param.getEndTime(), param.getClrType(), param.getPatNo(),
|
|
|
+ param.getInsutype(), param.getOutDept(), param.getMedType(), param.getPsnType(), param.getClrOptins(), param.getFlag()));
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取 医疗类别
|
|
|
+ *
|
|
|
+ * @return 返回 code name
|
|
|
+ */
|
|
|
+ public ResultVo<List<Object>> getMedType() {
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ for (MedType e : MedType.values()) {
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("code", e.getCode());
|
|
|
+ object.put("name", e.getName());
|
|
|
+ jsonArray.add(object);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(jsonArray);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 医保结算单上传导出 execl 表格
|
|
|
+ *
|
|
|
+ * @param response 返回
|
|
|
+ * @param param 参数
|
|
|
+ */
|
|
|
+ public void exportExcel(HttpServletResponse response, JieSuanDanChaXun param) {
|
|
|
+ param.setPageSize(param.getTotal());
|
|
|
+ log.info("医保结算单: {}", JSON.toJSONStringWithDateFormat(param, GetDateFormat.DATE));
|
|
|
+ List<TSiSetlinfo> list = huoQuJieSuanRenYuan(param).getData().getRecords();
|
|
|
+ String[] title = {"姓名", "出院科室", "住院号/门诊号", "次数", "性别", "出生日期", "险种类型", "人员类别", "就诊ID", "结算ID", "结算时间", "医疗类别", "总费用", "报销金额", "个人账户支出", "个人现金支出",
|
|
|
+ "清算机构"};
|
|
|
+ String[][] content = new String[list.size()][];
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ content[i] = new String[title.length];
|
|
|
+ TSiSetlinfo pojo = list.get(i);
|
|
|
+ content[i][0] = pojo.getPsnName();
|
|
|
+ content[i][1] = pojo.getOutDeptName();
|
|
|
+ content[i][2] = pojo.getPatNo();
|
|
|
+ content[i][3] = pojo.getGendName();
|
|
|
+ content[i][4] = pojo.getActIptDays();
|
|
|
+ content[i][5] = pojo.getDisDiag();
|
|
|
+ content[i][6] = pojo.getDisDiagComment();
|
|
|
+ content[i][7] = pojo.getOperationName();
|
|
|
+ content[i][8] = pojo.getMedfeeSumamt();
|
|
|
+ content[i][9] = pojo.getFundPaySumamt();
|
|
|
+ content[i][10] = pojo.getInsutypeName();
|
|
|
+ content[i][11] = pojo.getPsnTypeName();
|
|
|
+ content[i][12] = DateUtil.formatDatetime(pojo.getSetlTime(), GetDateFormat.DATE_TIME);
|
|
|
+ content[i][13] = pojo.getMedTypeName();
|
|
|
+ content[i][14] = pojo.getClrOptinsName();
|
|
|
+ }
|
|
|
+ //传三个参数 一个是 固定的 response ,excel的头部信息,excel的内容
|
|
|
+ ExcelUtil.exportExcel(response, title, content);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<ZyInactpatient> jieSuanDanKeXiuGaiXinXi(String patNo, Integer times, Integer ledgerSn) {
|
|
|
+ SetlinfoUpld setlinfoUpld = upIdCollectionDao.setlinfo1(patNo, times, ledgerSn);
|
|
|
+ if (StringUtil.isBlank(setlinfoUpld.getSetlId())) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算id为空");
|
|
|
+ }
|
|
|
+ if (!setlinfoUpld.getInsuplc().startsWith("4301") || setlinfoUpld.getInsuplc().equals("430182")) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者参保地不属于长沙市,无法上传结算清单。");
|
|
|
+ }
|
|
|
+ ZyInactpatient zy = upIdCollectionDao.huanZheXinXi(patNo, times);
|
|
|
+ String[] strNow1 = new SimpleDateFormat("yyyy-MM").format(setlinfoUpld.getSetlEndDate()).split("-");
|
|
|
+ String[] strNow2 = new SimpleDateFormat("yyyy-MM").format(new Date()).split("-");
|
|
|
+ List<Integer> code = publicServer.getRoleCode().getData();
|
|
|
+ log.info("code:{}", JSONObject.toJSONString(code));
|
|
|
+ if (!code.contains(1) && !code.contains(8)) {
|
|
|
+ if (!strNow1[0].equals(strNow2[0])) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "当前年份和患者的结算年份不一致。");
|
|
|
+ }
|
|
|
+ if (!strNow1[1].equals(strNow2[1])) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "当前月份和患者的结算月份不一致。");
|
|
|
+ }
|
|
|
+ TYbSetModifyTime modifyTime = upIdCollectionDao.keXiuGaiShiJian();
|
|
|
+ if (!DateUtil.isEffectiveDate(new Date(), modifyTime.getStartTime(), modifyTime.getEndTime())) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR,
|
|
|
+ String.format("当前不在医保科设置的修改时间范围内<br>开始时间:【%s】<br>结束时间:【%s】<br>这段结算时间范围内的患者可修改。",
|
|
|
+ DateUtil.formatDatetime(modifyTime.getStartTime(), "yyyy-MM-dd"),
|
|
|
+ DateUtil.formatDatetime(modifyTime.getEndTime(), "yyyy-MM-dd")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (zy == null) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未查询到患者信息。");
|
|
|
+ }
|
|
|
+ // 手术
|
|
|
+ zy.setBatjBa4(upIdCollectionDao.shouShuXinXi(patNo, times));
|
|
|
+ // 诊断编码
|
|
|
+ zy.setZyDisDiagYb(upIdCollectionDao.zhenDuanXinXi(patNo, times));
|
|
|
+ return ResultVoUtil.success(zy);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|