package thyyxxk.webserver.service.medicalinsurance; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; 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.YesOrNo; import thyyxxk.webserver.constants.sidicts.*; import thyyxxk.webserver.dao.his.medicalinsurance.SiQueryDao; import thyyxxk.webserver.dao.his.medicalinsurance.SiSetlinfoDao; import thyyxxk.webserver.entity.ResultVo; import thyyxxk.webserver.entity.dictionary.PureCodeName; import thyyxxk.webserver.entity.medicalinsurance.inpatient.InHspPsnInfo; import thyyxxk.webserver.entity.medicalinsurance.outpatient.SpcChrDiseAcct; import thyyxxk.webserver.entity.medicalinsurance.query.*; import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetldetail; import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetlinfo; import thyyxxk.webserver.entity.medicalinsurance.setlinfo.TimesList; import thyyxxk.webserver.entity.medicalinsurance.setllist.*; import thyyxxk.webserver.entity.inpatient.ZyActpatient; import thyyxxk.webserver.service.redislike.RedisLikeService; import thyyxxk.webserver.service.wxapi.SendWxInfoService; import thyyxxk.webserver.utils.*; import java.math.BigDecimal; import java.time.LocalDate; import java.util.*; /** * @description: 医保查询服务 * @author: DingJie * @create: 2021-06-23 16:35:23 **/ @Slf4j @Service public class SiQueryService { 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 SiQueryDao dao; private final SendWxInfoService wxsrvc; private final SiSetlinfoDao setlinfoDao; private final RedisLikeService redis; @Autowired public SiQueryService(ExecService exec, SiQueryDao dao, SendWxInfoService wxsrvc, SiSetlinfoDao setlinfoDao, RedisLikeService redis) { this.exec = exec; this.dao = dao; this.wxsrvc = wxsrvc; this.setlinfoDao = setlinfoDao; this.redis = redis; } public ResultVo getSiPatInfo(QryPsnBsInfo qryPsnBsInfo) { SiPatInfo siPatInfo = dao.selectSiPatInfoForZy(qryPsnBsInfo.getPatNo(), qryPsnBsInfo.getTimes(), qryPsnBsInfo.getLedgerSn()); if (null == siPatInfo) { siPatInfo = new SiPatInfo(); } return ResultVoUtil.success(siPatInfo); } public ResultVo fetchPsnNo(String socialNo, String admdvs) { if (StringUtil.isBlank(socialNo)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的身份证不能为空,请补充!"); } if (StringUtil.isBlank(admdvs)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的参保地区不能为空,请补充!"); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OBTAIN_BASIC_PERSON_INFO, admdvs); JSONObject data = new JSONObject(); data.put("mdtrt_cert_type", MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode()); data.put("psn_cert_type", "01"); data.put("mdtrt_cert_no", socialNo); data.put("certno", socialNo); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_BASIC_PERSON_INFO); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONObject baseinfo = output.getJSONObject("baseinfo"); String psnNo = baseinfo.getString("psn_no"); if (StringUtil.notBlank(psnNo)) { return ResultVoUtil.success(psnNo); } } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "无法查询到患者的医保个人编码。"); } public ResultVo obtainBasicPersonInfo(QryPsnBsInfo qryPsnBsInfo) { if (null == qryPsnBsInfo.getOnlyQry() && StringUtil.isBlank(qryPsnBsInfo.getMedType())) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "请选择患者的医疗类别!"); } if (StringUtil.isBlank(qryPsnBsInfo.getSocialNo()) && StringUtil.notBlank(qryPsnBsInfo.getPatNo()) && qryPsnBsInfo.getPatNo().length() >= 15) { qryPsnBsInfo.setSocialNo(qryPsnBsInfo.getPatNo()); } if (StringUtil.isBlank(qryPsnBsInfo.getSocialNo())) { QryPsnBsInfo qpbi = dao.selectMzSocialAndName(qryPsnBsInfo.getPatNo()); if (StringUtil.isBlank(qpbi.getSocialNo())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的身份证不能为空,请补充!"); } if (null == qryPsnBsInfo.getTimes()) { qryPsnBsInfo.setTimes(qpbi.getTimes()); } qryPsnBsInfo.setName(qpbi.getName()); qryPsnBsInfo.setSocialNo(qpbi.getSocialNo()); qryPsnBsInfo.setLedgerSn(0); } if (null != qryPsnBsInfo.getLedgerSn() && qryPsnBsInfo.getLedgerSn() != 0) { qryPsnBsInfo.setLedgerSn(dao.selectMaxLedgerSn(qryPsnBsInfo.getPatNo(), qryPsnBsInfo.getTimes())); } if (StringUtil.isBlank(qryPsnBsInfo.getStaffId())) { qryPsnBsInfo.setStaffId(TokenUtil.getTokenUserId()); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OBTAIN_BASIC_PERSON_INFO, qryPsnBsInfo.getAdmdvs()); JSONObject data = new JSONObject(); if (qryPsnBsInfo.getSocialNo().length() < 15) { data.put("mdtrt_cert_type", MdtrtCertType.OTHER.getCode()); data.put("psn_cert_type", PsnCertType.RESIDENCE_PERMIT_FOR_HMT.getCode()); } else { data.put("mdtrt_cert_type", MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode()); data.put("psn_cert_type", "01"); } data.put("mdtrt_cert_no", qryPsnBsInfo.getSocialNo()); data.put("certno", qryPsnBsInfo.getSocialNo()); if (StringUtil.notBlank(qryPsnBsInfo.getName())) { data.put("psn_name", qryPsnBsInfo.getName()); } input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_BASIC_PERSON_INFO); log.info("【操作员:{}】,人员基本信息获取:\n参数:{},\n结果:{}", qryPsnBsInfo.getStaffId(), 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) { JSONObject output = result.getJSONObject(OUTPUT); JSONObject baseinfo = output.getJSONObject("baseinfo"); PsnBaseInfo psnBaseinfo = JSONObject.parseObject(baseinfo.toJSONString(), PsnBaseInfo.class); psnBaseinfo.setPatNo(qryPsnBsInfo.getPatNo()); psnBaseinfo.setTimes(qryPsnBsInfo.getTimes()); psnBaseinfo.setLedgerSn(qryPsnBsInfo.getLedgerSn()); psnBaseinfo.setMedType(qryPsnBsInfo.getMedType()); psnBaseinfo.setGendName(Gend.get(psnBaseinfo.getGend()).getName()); psnBaseinfo.setPsnCertTypeName(PsnCertType.get(psnBaseinfo.getPsnCertType()).getName()); Naty naty = Naty.get(psnBaseinfo.getNaty()); if (null != naty) { psnBaseinfo.setNatyName(naty.getName()); } List idetInfos = new ArrayList<>(); JSONArray idet = output.getJSONArray("idetinfo"); for (int i = 0; i < idet.size(); i++) { JSONObject item = idet.getJSONObject(i); IdetInfo info = JSONObject.parseObject(item.toJSONString(), IdetInfo.class); PsnIdetType psnIdetType = PsnIdetType.get(info.getPsnIdetType()); if (null != psnIdetType) { psnBaseinfo.setPsnIdetType(psnIdetType.getCode()); info.setPsnIdetTypeName(psnIdetType.getName()); } idetInfos.add(info); } if (StringUtil.notBlank(psnBaseinfo.getPsnIdetType())) { dao.updatePsnIdetType(psnBaseinfo.getPsnIdetType(), psnBaseinfo.getPsnNo()); } psnBaseinfo.setIdetinfo(idetInfos); if (new Integer(1).equals(qryPsnBsInfo.getNeedSaving())) { dao.updateZyActpatient(psnBaseinfo); psnBaseinfo.setBalc("0"); int saved = dao.selectSiZyInfoCount(qryPsnBsInfo.getPatNo(), qryPsnBsInfo.getTimes(), qryPsnBsInfo.getLedgerSn()); if (saved == 0) { dao.insertSiZyInfoPsnNo(psnBaseinfo); } else { dao.updateSiZyInfoPsnNo(psnBaseinfo); } log.info("患者基本信息已更新:{}", psnBaseinfo); output.put("times", qryPsnBsInfo.getTimes()); } List list = new ArrayList<>(); JSONArray insuinfo = output.getJSONArray("insuinfo"); for (int i = 0; i < insuinfo.size(); i++) { JSONObject item = insuinfo.getJSONObject(i); InsuInfo info = JSONObject.parseObject(item.toJSONString(), InsuInfo.class); Insutype insutype = Insutype.get(info.getInsutype()); if (null != insutype) { info.setInsutypeName(insutype.getName()); } PsnType psnType = PsnType.get(info.getPsnType()); if (null != psnType) { info.setPsnTypeName(psnType.getName()); } if (null != info.getPsnInsuStas()) { if (info.getPsnInsuStas().equals(YesOrNo.YES.getCodeStr())) { info.setPsnInsuStasName("正常参保"); } else { info.setPsnInsuStasName("暂停参保"); } } if (null != info.getCvlservFlag()) { if (info.getCvlservFlag().equals(YesOrNo.YES.getCodeStr())) { info.setCvlservFlagName("是"); } else { info.setCvlservFlagName("否"); } } info.setInsuplcAdmdvsName(redis.getRegionName(info.getInsuplcAdmdvs())); list.add(info); } psnBaseinfo.setInsuinfo(list); return ResultVoUtil.success(psnBaseinfo); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> obtainMedicalInstitutionInfo(String type, String fuzzyName) { JSONObject input = exec.makeTradeHeader(SiFunction.OBTAIN_MEDICAL_INSTITUTION_INFO); JSONObject medinsinfo = new JSONObject(); medinsinfo.put("fixmedins_type", type); medinsinfo.put("fixmedins_name", fuzzyName); input.getJSONObject("input").put("medinsinfo", medinsinfo); JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_MEDICAL_INSTITUTION_INFO); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONArray output = result.getJSONObject(OUTPUT).getJSONArray("medinsinfo"); List list = new ArrayList<>(); for (int i = 0; i < output.size(); i++) { JSONObject item = output.getJSONObject(i); MedInsInfo info = JSONObject.parseObject(item.toJSONString(), MedInsInfo.class); info.setFixmedinsAdmdvs(info.getFixmedinsCode().substring(1, 7)); info.setFixmedinsAdmdvsName(redis.getRegionName(info.getFixmedinsAdmdvs())); FixmedinsType fixmedinsType = FixmedinsType.get(info.getFixmedinsType()); if (null != fixmedinsType) { info.setFixmedinsTypeName(fixmedinsType.getName()); } HospLv hospLv = HospLv.get(info.getHospLv()); if (null != hospLv) { info.setHospLvName(hospLv.getName()); } list.add(info); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryVisitInfo(BscQryPrm q) { PureCodeName codeName = dao.selectPsnNoByPatNoAndMedType(q.getPatNo(), q.getMedType()); if (null == codeName) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有找到患者该医疗类别的我院就诊记录。"); } q.setPsnNo(codeName.getName()); JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_VISIT_INFO, codeName.getCode()); String ref = JSONObject.toJSONStringWithDateFormat(q, "yyyy-MM-dd HH:mm:ss"); input.getJSONObject("input").put("data", JSONObject.parseObject(ref)); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_VISIT_INFO); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray mdts = output.getJSONArray("mdtrtinfo"); List list = new ArrayList<>(); for (int i = 0; i < mdts.size(); i++) { JSONObject item = mdts.getJSONObject(i); MdtrtInfo mdtrtInfo = JSONObject.parseObject(item.toJSONString(), MdtrtInfo.class); if (null != mdtrtInfo.getInsuOptins()) { mdtrtInfo.setInsuOptinsName(redis.getRegionName(mdtrtInfo.getInsuOptins())); } SiEnumReflectUtil.mdtrtInfoReflect(mdtrtInfo); list.add(mdtrtInfo); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryDiagnosisInfo(BscQryPrm q) { String admdvs = dao.selectAdmdvsByPsnNo(q.getPsnNo()); JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_DIAGNOSIS_INFO, admdvs); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("mdtrt_id", q.getMdtrtId()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_DIAGNOSIS_INFO); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); List list = new ArrayList<>(); JSONArray diseInfos = output.getJSONArray("diseinfo"); for (int i = 0; i < diseInfos.size(); i++) { JSONObject item = diseInfos.getJSONObject(i); DiseInfo diseInfo = JSONObject.parseObject(item.toJSONString(), DiseInfo.class); SiEnumReflectUtil.diseInfoReflect(diseInfo); list.add(diseInfo); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo querySettlementInfo(BscQryPrm q) { SiPatInfo siPatInfo; if (null == q.getMdtrtId()) { if (null == q.getLedgerSn()) { q.setLedgerSn(0); } siPatInfo = dao.selectSiPatInfoForZy(q.getPatNo(), q.getTimes(), q.getLedgerSn()); } else { siPatInfo = dao.selectSiPatInfoByMdtrtId(q.getMdtrtId()); } if (null == siPatInfo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该次就诊尚未结算,无法查询结算信息。"); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_SETTLEMENT_INFO, siPatInfo.getInsuplcAdmdvs()); JSONObject data = new JSONObject(); data.put("psn_no", siPatInfo.getPsnNo()); data.put("setl_id", siPatInfo.getSetlId()); data.put("mdtrt_id", siPatInfo.getMdtrtId()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_SETTLEMENT_INFO); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONObject obj = output.getJSONObject("setlinfo"); if (null == obj) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到该次就诊的结算明细。"); } SetlInfo setlInfo = JSONObject.parseObject(obj.toJSONString(), SetlInfo.class); ClrType clrType = ClrType.get(setlInfo.getClrType()); if (null != clrType) { setlInfo.setClrTypeName(clrType.getName()); } MedType medType = MedType.get(setlInfo.getMedType()); if (null != medType) { setlInfo.setMedTypeName(medType.getName()); } Insutype insutype = Insutype.get(setlInfo.getInsutype()); if (null != insutype) { setlInfo.setInsutypeName(insutype.getName()); } PsnType psnType = PsnType.get(setlInfo.getPsnType()); if (null != psnType) { setlInfo.setPsnTypeName(psnType.getName()); } JSONArray setldetail = output.getJSONArray("setldetail"); if (null != setldetail && setldetail.size() > 0) { List list = new ArrayList<>(); for (int i = 0; i < setldetail.size(); i++) { SiSetldetail setldtel = JSONObject.parseObject(setldetail.getJSONObject(i).toJSONString(), SiSetldetail.class); FundPayType fundPayType = FundPayType.get(setldtel.getFundPayType()); if (null != fundPayType) { setldtel.setFundPayTypeName(fundPayType.getName()); } list.add(setldtel); } setlInfo.setSetldetail(list); } return ResultVoUtil.success(setlInfo); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryFeeDetails(QryFeeDetl q) { SiPatInfo psninfo = dao.selectSiPatInfoByMdtrtId(q.getMdtrtId()); if (null == psninfo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的医保登记信息。"); } Map map = new HashMap<>(); map.put("psninfo", psninfo); if (!q.getType().equals("settled")) { List list = dao.selectTempCharge(psninfo.getPatNo(), psninfo.getTimes(), psninfo.getLedgerSn()); if (null == list || list.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有已经上传的医保费用。"); } map.put("feedtle", list); map.put("analyse", analyseFeedtle(list)); return ResultVoUtil.success(map); } List list = dao.selectFeeDetlList(psninfo.getMdtrtId(), psninfo.getPatNo(), psninfo.getTimes(), psninfo.getLedgerSn()); if (list.size() > 0) { map.put("feedtle", list); map.put("analyse", analyseFeedtle(list)); return ResultVoUtil.success(map); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_FEE_DETAILS, psninfo.getInsuplcAdmdvs()); JSONObject data = new JSONObject(); data.put("psn_no", psninfo.getPsnNo()); data.put("setl_id", psninfo.getSetlId()); data.put("mdtrt_id", psninfo.getMdtrtId()); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONArray output = result.getJSONArray(OUTPUT); if (null == output || output.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到费用明细。"); } for (int i = 0; i < output.size(); i++) { list.add(JSONObject.parseObject(output.getJSONObject(i).toJSONString(), SiSetlFeeDetl.class)); if (list.size() == 30) { dao.insertSetlFeeDetlBatch(list); list.clear(); } } if (list.size() > 0) { dao.insertSetlFeeDetlBatch(list); } list = dao.selectFeeDetlList(psninfo.getMdtrtId(), psninfo.getPatNo(), psninfo.getTimes(), psninfo.getLedgerSn()); map.put("feedtle", list); map.put("analyse", analyseFeedtle(list)); return ResultVoUtil.success(map); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } private Map analyseFeedtle(List fees) { Map map = new HashMap<>(); map.put("zhj", new String[]{"合计", "0.00", "0.00", "0.00", "0.00"}); fees.forEach(itm -> { ChrgitmLv chrgitmLv = ChrgitmLv.get(itm.getChrgitmLv()); if (null == chrgitmLv) { chrgitmLv = ChrgitmLv.SELF_PAY; itm.setChrgitmLvName(chrgitmLv.getName()); } String[] all = map.get("zhj"); sumChargeFeeByType(itm, chrgitmLv, all); if (map.containsKey(itm.getMedChrgitmType())) { String[] dtle = map.get(itm.getMedChrgitmType()); sumChargeFeeByType(itm, chrgitmLv, dtle); } else { String[] dtle = new String[5]; MedChrgitmType type = MedChrgitmType.get(itm.getMedChrgitmType()); if (type == null) { type = MedChrgitmType.OTH; itm.setMedChrgitmType(type.getCode()); } dtle[0] = type.getName(); dtle[1] = itm.getDetItemFeeSumamt(); switch (chrgitmLv) { case FIRST_CLASS: dtle[2] = itm.getDetItemFeeSumamt(); dtle[3] = "0.00"; dtle[4] = "0.00"; break; case SECOND_CLASS: dtle[3] = itm.getDetItemFeeSumamt(); dtle[2] = "0.00"; dtle[4] = "0.00"; break; case SELF_PAY: dtle[4] = itm.getDetItemFeeSumamt(); dtle[3] = "0.00"; dtle[2] = "0.00"; break; } map.put(type.getCode(), dtle); } }); String total = map.get("zhj")[1]; for (Map.Entry entry : map.entrySet()) { if (!entry.getKey().equals("zhj")) { String percentage = DecimalUtil.percentage(entry.getValue()[1], total); entry.getValue()[0] = entry.getValue()[0] + "(" + percentage + ")"; } } return map; } private void sumChargeFeeByType(SiSetlFeeDetl itm, ChrgitmLv chrgitmLv, String[] dtle) { dtle[1] = DecimalUtil.add(dtle[1], itm.getDetItemFeeSumamt()); switch (chrgitmLv) { case FIRST_CLASS: dtle[2] = DecimalUtil.add(dtle[2], itm.getDetItemFeeSumamt()); break; case SECOND_CLASS: dtle[3] = DecimalUtil.add(dtle[3], itm.getDetItemFeeSumamt()); break; case SELF_PAY: dtle[4] = DecimalUtil.add(dtle[4], itm.getDetItemFeeSumamt()); break; } } public ResultVo> checkPersonTreatment(BscQryPrm q) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.CHECK_PERSON_TREATMENT, dao.selectAdmdvs(q.getPatNo(), q.getTimes())); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("insutype", q.getInsutype()); data.put("fixmedins_code", SiUtil.INSTITUTION_ID); data.put("med_type", q.getMedType()); data.put("begntime", DateUtil.formatDatetime(q.getBegntime())); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.CHECK_PERSON_TREATMENT); 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 (result.getIntValue(RESULT_CODE) == 0) { List list = new ArrayList<>(); JSONObject output = result.getJSONObject(OUTPUT); JSONArray trtinfo = output.getJSONArray("trtinfo"); for (int i = 0; i < trtinfo.size(); i++) { JSONObject obj = trtinfo.getJSONObject(i); TrtInfo item = JSONObject.parseObject(obj.toJSONString(), TrtInfo.class); TrtChkType trtChkType = TrtChkType.get(item.getTrtChkType()); if (null != trtChkType) { item.setTrtChkTypeName(trtChkType.getName()); } FundPayType fundPayType = FundPayType.get(item.getFundPayType()); if (null != fundPayType) { item.setFundPayTypeName(fundPayType.getName()); } if (null != item.getTrtEnjymntFlag()) { if (item.getTrtEnjymntFlag().equals(YesOrNo.YES.getCodeStr())) { item.setTrtEnjymntFlagName("是"); } else { item.setTrtEnjymntFlagName("否"); } } list.add(item); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryInHospitalPatientsInfo(BscQryPrm q) { if (StringUtil.notBlank(q.getPatNo())) { String psnNo = dao.selectPsnNo(q.getPatNo()); if (null == psnNo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【住院号/门诊号:" + q.getPatNo() + "】没有找到此患者在我院的医保在院信息,请核实。"); } q.setPsnNo(psnNo); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_IN_HOSPITAL_PATIENTS_INFO, dao.selectAdmdvsByPatNoAndPsnNo(q.getPatNo(), q.getPsnNo())); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("begntime", DateUtil.formatDatetime(q.getBegntime())); data.put("endtime", null == q.getEndtime() ? DateUtil.now() : DateUtil.formatDatetime(q.getEndtime())); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_IN_HOSPITAL_PATIENTS_INFO); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray pts = output.getJSONArray("data"); if (pts.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到医保在院的患者信息。"); } List list = new ArrayList<>(); for (int i = 0; i < pts.size(); i++) { JSONObject item = pts.getJSONObject(i); InHspPsnInfo inHspPsnInfo = JSONObject.parseObject(item.toJSONString(), InHspPsnInfo.class); SiEnumReflectUtil.inHspPsnInfoReflect(inHspPsnInfo); list.add(inHspPsnInfo); } if (list.size() == 1 && null != q.getTimes()) { InHspPsnInfo info = list.get(0); dao.updateInhospInfo(q.getPatNo(), q.getTimes(), q.getLedgerSn(), info.getMdtrtId(), info.getInsutype()); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryPersonnelTransferHospitalInfo(BscQryPrm q) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_TRANSFER_HOSPITAL_INFO, dao.selectAdmdvsByPatNoAndPsnNo(q.getPatNo(), q.getPsnNo())); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("begntime", DateUtil.formatDatetime(q.getBegntime())); data.put("endtime", DateUtil.formatDatetime(q.getEndtime())); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_TRANSFER_HOSPITAL_INFO); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray array = output.getJSONArray("refmedin"); if (null == array || array.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到符合条件的转院信息。"); } List list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject obj = array.getJSONObject(i); RefMedin item = JSONObject.parseObject(obj.toJSONString(), RefMedin.class); Insutype insutype = Insutype.get(item.getInsutype()); if (null != insutype) { item.setInsutypeName(insutype.getName()); } DclaSouc dclaSouc = DclaSouc.get(item.getDclaSouc()); if (null != dclaSouc) { item.setDclaSoucName(dclaSouc.getName()); } PsnCertType psnCertType = PsnCertType.get(item.getPsnCertType()); if (null != psnCertType) { item.setPsnCertTypeName(psnCertType.getName()); } item.setGendName(Gend.get(item.getGend()).getName()); if (null != item.getInsuOptins()) { item.setInsuOptinsName(redis.getRegionName(item.getInsuOptins())); } if (null != item.getOutFlag()) { if (item.getOutFlag().equals(YesOrNo.YES.getCodeStr())) { item.setOutFlagName("是"); } else { item.setOutFlagName("否"); } } if (null != item.getHospAgreReflFlag()) { if (item.getHospAgreReflFlag().equals(YesOrNo.YES.getCodeStr())) { item.setHospAgreReflFlagName("是"); } else { item.setHospAgreReflFlagName("否"); } } list.add(item); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> querySpecialChronicDiseasesMedicalRecord(BscQryPrm q) { if (null == q.getPsnNo()) { String psnNo = dao.selectPsnNo(q.getPatNo()); if (null == psnNo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【住院号/门诊号:" + q.getPatNo() + "】未找到此患者的医保参保信息,请核实。"); } q.setPsnNo(psnNo); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_MEDICAL_RECORD, dao.selectAdmdvsByPsnNo(q.getPsnNo())); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("begntime", DateUtil.formatDatetime(q.getBegntime())); data.put("endtime", DateUtil.formatDatetime(q.getEndtime())); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_MEDICAL_RECORD); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray array = output.getJSONArray("feedetail"); if (null == array || array.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到此人的慢特病用药记录。"); } List list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject obj = array.getJSONObject(i); MedUseRcd item = JSONObject.parseObject(obj.toJSONString(), MedUseRcd.class); list.add(item); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryPersonnelCumulativeInfo(BscQryPrm q) { String admdvs = q.getAdmdvs(); if (StringUtil.isBlank(admdvs)) { admdvs = dao.selectAdmdvsByPsnNo(q.getPsnNo()); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO, admdvs); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("cum_ym", q.getCumYm()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray array = output.getJSONArray("cuminfo"); List list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject obj = array.getJSONObject(i); CumInfo item = JSONObject.parseObject(obj.toJSONString(), CumInfo.class); Insutype insutype = Insutype.get(item.getInsutype()); if (null != insutype) { item.setInsutypeName(insutype.getName()); } list.add(item); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> querySpecialChronicDiseasesAccreditation(BscQryPrm q) { if (null == q.getPsnNo()) { String psnNo = dao.selectPsnNo(q.getPatNo()); if (null == psnNo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【住院号/门诊号:" + q.getPatNo() + "】未找到此患者的医保参保信息,请核实。"); } q.setPsnNo(psnNo); } if (StringUtil.isBlank(q.getAdmdvs())) { String admdvs = StringUtil.isBlank(q.getPatNo()) ? dao.selectAdmdvsByPsnNo(q.getPsnNo()) : dao.selectAdmdvsByPatNo(q.getPatNo()); q.setAdmdvs(admdvs); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_ACCREDITATION, q.getAdmdvs()); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_ACCREDITATION); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray details = output.getJSONArray("feedetail"); if (null == details || details.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到此患者的慢特病备案信息。"); } List list = new ArrayList<>(); Date now = new Date(); for (int i = 0; i < details.size(); i++) { JSONObject detail = details.getJSONObject(i); SpcChrDiseAcct spcChrDiseAcct = JSONObject.parseObject(detail.toJSONString(), SpcChrDiseAcct.class); if (null != q.getNeedAllRcd() && 1 == q.getNeedAllRcd()) { list.add(spcChrDiseAcct); } else { if (now.before(spcChrDiseAcct.getEnddate())) { spcChrDiseAcct.setPatNo(q.getPatNo()); spcChrDiseAcct.setTimes(q.getTimes()); list.add(spcChrDiseAcct); } } } if (list.size() > 0) { return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的慢特病备案,或慢特病备案已过期!"); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> queryPersonnelAssignmentInfo(BscQryPrm q) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_ASSIGNMENT_INFO, q.getAdmdvs()); JSONObject data = new JSONObject(); data.put("psn_no", q.getPsnNo()); data.put("biz_appy_type", q.getBizAppyType()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_ASSIGNMENT_INFO); 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 (result.getIntValue(RESULT_CODE) == 0) { JSONObject output = result.getJSONObject(OUTPUT); JSONArray array = output.getJSONArray("psnfixmedin"); if (null == array || array.size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到对应的点定信息。"); } List list = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { JSONObject obj = array.getJSONObject(i); PsnFixMedin item = JSONObject.parseObject(obj.toJSONString(), PsnFixMedin.class); Insutype insutype = Insutype.get(item.getInsutype()); if (null != insutype) { item.setInsutypeName(insutype.getName()); } list.add(item); } return ResultVoUtil.success(list); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo> fetchSiTimesList(String patNo, Integer type) { List list = dao.fetchSiTimesList(patNo, type); if (null == list || list.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "此患者没有有效的结算信息。"); } return ResultVoUtil.success(list); } public ResultVo queryInsuplcAdmdvsByMdtrtId(String mdtrtId) { return ResultVoUtil.success(dao.selectInsuplcAdmdvsByMdtrtId(mdtrtId)); } public ResultVo queryInpatientSetlList(SetlIndex index) { if (null == index.getTimes() && StringUtil.isBlank(index.getLabel())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算条目不能为空!"); } if (StringUtil.notBlank(index.getLabel())) { String[] arr = index.getLabel().split("_"); index.setSetlId(arr[0]); index.setTimes(Integer.parseInt(arr[1])); index.setLedgerSn(Integer.parseInt(arr[2])); } else { index.setLedgerSn(0); index.setSetlId(dao.selectSetlId(index.getPatNo(), index.getTimes(), index.getLedgerSn())); } SiPatInfo siPatInfo = dao.selectSiPatInfo(index.getPatNo(), index.getTimes(), index.getLedgerSn()); if (null == siPatInfo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!"); } CuminfoInYear cuminfo = getYearCuminfo(siPatInfo.getPsnNo(), siPatInfo.getInsuplcAdmdvs()); if (cuminfo.getCode() != ExceptionEnum.SUCCESS.getCode()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, cuminfo.getMessage()); } InptntSetlmtLst lst = dao.selectZySetlinfo(index.getSetlId(), "zy_inactpatient"); if (null == lst) { lst = dao.selectZySetlinfo(index.getSetlId(), "zy_actpatient"); if (null == lst) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!"); } } lst.setInHospdays(DateUtil.daysBetween(lst.getEndtime(), lst.getBegntime())); PsnIdetType psnIdetType = PsnIdetType.get(lst.getPsnIdetType()); if (null != psnIdetType) { lst.setPsnIdetTypeName(psnIdetType.getName()); } Admdvs admdvs = Admdvs.get(lst.getInsuplcAdmdvs()); if (null == admdvs) { lst.setInsuplcAdmdvsName(redis.getRegionName(lst.getInsuplcAdmdvs())); } else { lst.setInsuplcAdmdvsName(admdvs.getName()); } lst.setFixmedinsName(SiUtil.INSTITUTION_NAME); lst.setGendName(Gend.get(lst.getGend()).getName()); SiEnumReflectUtil.inptntSetlmtLstReflect(lst); ResultVo> chrgrsvo = getChrgitems(lst.getPsnNo(), lst.getSetlId(), lst.getMdtrtId(), lst.getInsuplcAdmdvs()); if (!chrgrsvo.getCode().equals(ExceptionEnum.SUCCESS.getCode())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, chrgrsvo.getMessage()); } ChrgItemLvInfo chrgItemLvInfo = analyzeParticularChrgitmLv(chrgrsvo.getData()); lst.setChrgItemLvInfo(chrgItemLvInfo); lst.setCuminfo(cuminfo); ResultVo polItemRes = listPolItemCodePayInfo(lst.getPsnNo(), lst.getMdtrtId(), lst.getSetlId(), lst.getInsuplcAdmdvs()); if (polItemRes.getCode() != ExceptionEnum.SUCCESS.getCode()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, polItemRes.getMessage()); } lst.setPolItemInfo(polItemRes.getData()); return ResultVoUtil.success(lst); } public ResultVo queryOutpatientSetlList(SetlIndex index) { if (null == index.getTimes() && StringUtil.isBlank(index.getLabel())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算条目不能为空!"); } if (StringUtil.notBlank(index.getLabel())) { String[] arr = index.getLabel().split("_"); index.setSetlId(arr[0]); index.setTimes(Integer.parseInt(arr[1])); index.setLedgerSn(0); } else { index.setLedgerSn(0); index.setSetlId(dao.selectSetlId(index.getPatNo(), index.getTimes(), index.getLedgerSn())); } SiPatInfo siPatInfo = dao.selectSiPatInfo(index.getPatNo(), index.getTimes(), index.getLedgerSn()); if (null == siPatInfo) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!"); } CuminfoInYear cuminfo = getYearCuminfo(siPatInfo.getPsnNo(), siPatInfo.getInsuplcAdmdvs()); if (cuminfo.getCode() != ExceptionEnum.SUCCESS.getCode()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, cuminfo.getMessage()); } index.setLedgerSn(0); OtptntSetlmtLst lst = dao.selectMzSetlifo(index.getPatNo(), index.getTimes()); if (null == lst) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此患者的结算信息!"); } lst.setPsnCertTypeName(PsnCertType.get(lst.getPsnCertType()).getName()); lst.setPsnIdetTypeName(PsnIdetType.getName(lst.getPsnIdetType())); Admdvs admdvs = Admdvs.get(lst.getInsuplcAdmdvs()); if (null == admdvs) { lst.setInsuplcAdmdvsName(redis.getRegionName(lst.getInsuplcAdmdvs())); } else { lst.setInsuplcAdmdvsName(admdvs.getName()); } SiEnumReflectUtil.outptntSetlmtLstReflect(lst); List chrgitms = dao.selectMzBrfChrgitms(index.getPatNo(), index.getTimes()); lst.setCuminfo(cuminfo); lst.setFixmedinsName(SiUtil.INSTITUTION_NAME); Insutype insutype = Insutype.get(lst.getInsutype()); if (insutype == Insutype.BASIC_MEDICAL_INSURANCE_FOR_EMPLOYEES) { ResultVo> chrgrsvo = getChrgitems(lst.getPsnNo(), lst.getSetlId(), lst.getMdtrtId(), lst.getInsuplcAdmdvs()); if (!chrgrsvo.getCode().equals(ExceptionEnum.SUCCESS.getCode())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, chrgrsvo.getMessage()); } ChrgItemLvInfo chrgItemLvInfo = analyzeParticularChrgitmLv(chrgrsvo.getData()); lst.setChrgItemLvInfo(chrgItemLvInfo); ResultVo polItemRes = listPolItemCodePayInfo(lst.getPsnNo(), lst.getMdtrtId(), lst.getSetlId(), lst.getInsuplcAdmdvs()); if (polItemRes.getCode() != ExceptionEnum.SUCCESS.getCode()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, polItemRes.getMessage()); } lst.setPolItemInfo(polItemRes.getData()); } else { analyzeMzChrgitm(lst, chrgitms); } return ResultVoUtil.success(lst); } private ResultVo listPolItemCodePayInfo(String psnNo, String mdtrtId, String setlId, String insuplc) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.LIST_POL_ITEM_CODE_PAY_INFO, insuplc); JSONObject data = new JSONObject(); data.put("psn_no", psnNo); data.put("mdtrt_id", mdtrtId); data.put("setl_id", setlId); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.LIST_POL_ITEM_CODE_PAY_INFO); log.info("【操作员:{}】,政策信息查询:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result); if (null == result) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (null == result.getInteger("code")) { String message = result.getString("message"); if (null == message) { message = result.getString(ERROR_MESSAGE); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + message); } if (result.getIntValue("code") != 0) { String message = result.getString("message"); if (null == message) { message = result.getString(ERROR_MESSAGE); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心出错:" + message); } PolItemInfo polItemInfo = new PolItemInfo(); JSONArray array = result.getJSONArray("data"); BigDecimal selfPaySum = new BigDecimal(0); BigDecimal fundPaySum = new BigDecimal(0); for (int i = 0; i < array.size(); i++) { JSONObject itm = array.getJSONObject(i); BigDecimal selfPayAmt = BigDecimal.valueOf(itm.getDouble("selfPayAmt")); String selfPayProp = itm.getString("selfPayProp"); BigDecimal fundPayAmt = BigDecimal.valueOf(itm.getDouble("fundPayAmt")); String fundPayProp = itm.getString("fundPayProp"); BigDecimal polItemPaySum = BigDecimal.valueOf(itm.getDouble("polItemPaySum")); selfPaySum = selfPaySum.add(selfPayAmt); fundPaySum = fundPaySum.add(fundPayAmt); PolItemCode polItemCode = PolItemCode.get(itm.getString("polItemCode")); if (null == polItemCode) { String message = String.format("找到了字典缺失的政策项:%s", itm); log.info(message); wxsrvc.sendCorpWxMsg("2801", message); continue; } switch (polItemCode) { case QZF: polItemInfo.setSelfPayPsnAmt(selfPayAmt); polItemInfo.setSelfPayPsnProp(selfPayProp); polItemInfo.setSelfPayFundAmt(fundPayAmt); polItemInfo.setSelfPayFundProp(fundPayProp); polItemInfo.setSelfPaySum(polItemPaySum); break; case YLXZF: polItemInfo.setScndPrePayPsnAmt(selfPayAmt); polItemInfo.setScndPrePayPsnProp(selfPayProp); polItemInfo.setScndPrePayFundAmt(fundPayAmt); polItemInfo.setScndPrePayFundProp(fundPayProp); polItemInfo.setScndPrePaySum(polItemPaySum); break; case CXEZF: polItemInfo.setOvrlmtSelfPayPsnAmt(selfPayAmt); polItemInfo.setOvrlmtSelfPayPsnProp(selfPayProp); polItemInfo.setOvrlmtSelfPayFundAmt(fundPayAmt); polItemInfo.setOvrlmtSelfPayFundProp(fundPayProp); polItemInfo.setOvrlmtSelfPaySum(polItemPaySum); break; case BCYFQFBZ: polItemInfo.setBegnlinePsnAmt(selfPayAmt); polItemInfo.setBegnlinePsnProp(selfPayProp); polItemInfo.setBegnlineFundAmt(fundPayAmt); polItemInfo.setBegnlineFundProp(fundPayProp); polItemInfo.setBegnlineSum(polItemPaySum); break; case TCYD: polItemInfo.setFundFrstLvPsnAmt(selfPayAmt); polItemInfo.setFundFrstLvPsnProp(selfPayProp); polItemInfo.setFundFrstLvFundAmt(fundPayAmt); polItemInfo.setFundFrstLvFundProp(fundPayProp); polItemInfo.setFundFrstLvSum(polItemPaySum); break; case TCED: polItemInfo.setFundScndLvPsnAmt(selfPayAmt); polItemInfo.setFundScndLvPsnProp(selfPayProp); polItemInfo.setFundScndLvFundAmt(fundPayAmt); polItemInfo.setFundScndLvFundProp(fundPayProp); polItemInfo.setFundScndLvSum(polItemPaySum); break; case TCSD: polItemInfo.setFundThrdLvPsnAmt(selfPayAmt); polItemInfo.setFundThrdLvPsnProp(selfPayProp); polItemInfo.setFundThrdLvFundAmt(fundPayAmt); polItemInfo.setFundThrdLvFundProp(fundPayProp); polItemInfo.setFundThrdLvSum(polItemPaySum); break; case DEYD: polItemInfo.setBigAmtFrstLvPsnAmt(selfPayAmt); polItemInfo.setBigAmtFrstLvPsnProp(selfPayProp); polItemInfo.setBigAmtFrstLvFundAmt(fundPayAmt); polItemInfo.setBigAmtFrstLvFundProp(fundPayProp); polItemInfo.setBigAmtFrstLvSum(polItemPaySum); break; case STDTCZF: polItemInfo.setDualChannelFundPsnAmt(selfPayAmt); polItemInfo.setDualChannelFundPsnProp(selfPayProp); polItemInfo.setDualChannelFundFundAmt(fundPayAmt); polItemInfo.setDualChannelFundFundProp(fundPayProp); polItemInfo.setDualChannelFundSum(polItemPaySum); break; case STDDEZF: polItemInfo.setDualChannelBigAmtPsnAmt(selfPayAmt); polItemInfo.setDualChannelBigAmtPsnProp(selfPayProp); polItemInfo.setDualChannelBigAmtFundAmt(fundPayAmt); polItemInfo.setDualChannelBigAmtFundProp(fundPayProp); polItemInfo.setDualChannelBigAmtSum(polItemPaySum); break; case ZWZL: polItemInfo.setExternalSelfHandlePsnAmt(selfPayAmt); polItemInfo.setExternalSelfHandlePsnProp(selfPayProp); polItemInfo.setExternalSelfHandleFundAmt(fundPayAmt); polItemInfo.setExternalSelfHandleFundProp(fundPayProp); polItemInfo.setExternalSelfHandleSum(polItemPaySum); break; } } polItemInfo.setAllPsnAmt(selfPaySum); polItemInfo.setAllFundAmt(fundPaySum); polItemInfo.setAllSum(fundPaySum.add(selfPaySum)); return ResultVoUtil.success(polItemInfo); } private CuminfoInYear getYearCuminfo(String psnNo, String admdvs) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO, admdvs); JSONObject data = new JSONObject(); data.put("psn_no", psnNo); data.put("cum_ym", ""); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.QUERY_PERSONNEL_CUMULATIVE_INFO); CuminfoInYear cuminfo = new CuminfoInYear(); if (null == result) { cuminfo.setCode(ExceptionEnum.NETWORK_ERROR.getCode()); cuminfo.setMessage(ExceptionEnum.NETWORK_ERROR.getMessage()); return cuminfo; } if (null == result.getInteger(RESULT_CODE)) { cuminfo.setCode(ExceptionEnum.LOGICAL_ERROR.getCode()); cuminfo.setMessage("医保中心报错:" + result.getString("message")); return cuminfo; } if (result.getIntValue(RESULT_CODE) != 0) { cuminfo.setCode(ExceptionEnum.NETWORK_ERROR.getCode()); cuminfo.setMessage("医保中心出错:" + result.getString("message")); return cuminfo; } cuminfo.setCode(ExceptionEnum.SUCCESS.getCode()); String year = String.valueOf(LocalDate.now().getYear()); JSONArray cuminfos = result.getJSONObject(OUTPUT).getJSONArray("cuminfo"); log.info("累计信息:{}", cuminfos); for (int i = 0; i < cuminfos.size(); i++) { JSONObject itm = cuminfos.getJSONObject(i); if (itm.getString("year").equals(year)) { switch (itm.getString("cum_type_code")) { // 本年住院次数 case "C0000_BIZ2101": case "C0000_BIZ2102": case "C0000_BIZ2106": case "C0000_BIZ2107": case "C0000_BIZ22": case "C0000_BIZ52": cuminfo.addYearAdmtimesZy(itm.getDoubleValue("cum")); break; // 本年门诊次数 case "C0000_BIZ11": case "C0000_BIZ13": case "C0000_BIZ14": case "C0000_BIZ51": case "C0000_BIZ9901": case "C0000_BIZ9903": case "C0000_BIZ9904": cuminfo.addYearAdmtimesMz(itm.getDoubleValue("cum")); break; // 本年度住院分段计算费用累计 case "S0000_BIZ2101": case "S0000_BIZ2102": case "S0000_BIZ2106": case "S0000_BIZ2107": case "S0000_BIZ22": case "S0000_BIZ52": cuminfo.addYearPeriodFeeSumZy(itm.getDoubleValue("cum")); break; // 本年度门诊分段计算费用累计 case "S0000_BIZ11": case "S0000_BIZ13": case "S0000_BIZ14": case "S0000_BIZ51": case "S0000_BIZ9901": case "S0000_BIZ9903": case "S0000_BIZ9904": cuminfo.addYearPeriodFeeSumMz(itm.getDoubleValue("cum")); break; // 住院医疗费合计 case "F0000_BIZ2101": case "F0000_BIZ2102": case "F0000_BIZ2106": case "F0000_BIZ2107": case "F0000_BIZ22": case "F0000_BIZ52": cuminfo.addYearFeesumZy(itm.getDoubleValue("cum")); break; // 门诊医疗费合计 case "F0000_BIZ11": case "F0000_BIZ13": case "F0000_BIZ14": case "F0000_BIZ51": case "F0000_BIZ9901": case "F0000_BIZ9903": case "F0000_BIZ9904": cuminfo.addYearFeesumMz(itm.getDoubleValue("cum")); break; // 住院已付起付线 case "Q0000_BIZ2101": case "Q0000_BIZ2102": case "Q0000_BIZ2106": case "Q0000_BIZ2107": case "Q0000_BIZ22": case "Q0000_BIZ52": cuminfo.addYearPayedbegnlineZy(itm.getDoubleValue("cum")); break; // 门诊已付起付线 case "Q0000_BIZ11": case "Q0000_BIZ13": case "Q0000_BIZ14": case "Q0000_BIZ51": case "Q0000_BIZ9901": case "Q0000_BIZ9903": case "Q0000_BIZ9904": cuminfo.addYearPayedbegnlineMz(itm.getDoubleValue("cum")); break; // 住院统筹支付 case "D310101_BIZ2101": case "D310101_BIZ2102": case "D310101_BIZ2106": case "D310101_BIZ2107": case "D310101_BIZ22": case "D310101_BIZ52": case "D390101_BIZ2101": case "D390101_BIZ2102": case "D390101_BIZ2106": case "D390101_BIZ2107": case "D390101_BIZ22": case "D390101_BIZ52": cuminfo.addYearFundpaysZy(itm.getDoubleValue("cum")); break; // 门诊统筹支付 case "D310101_BIZ11": case "D310101_BIZ13": case "D310101_BIZ14": case "D310101_BIZ51": case "D310101_BIZ9901": case "D310101_BIZ9903": case "D310101_BIZ9904": case "D390101_BIZ11": case "D390101_BIZ13": case "D390101_BIZ14": case "D390101_BIZ51": case "D390101_BIZ9901": case "D390101_BIZ9903": case "D390101_BIZ9904": cuminfo.addYearFundpaysMz(itm.getDoubleValue("cum")); break; // 住院政策自费 case "Z0000_BIZ2101_LAB101": case "Z0000_BIZ2102_LAB101": case "Z0000_BIZ22_LAB101": case "Z0000_BIZ2106_LAB101": case "Z0000_BIZ2107_LAB101": case "Z0000_BIZ52_LAB101": case "Z0000_BIZ2101_LAB103": case "Z0000_BIZ2102_LAB103": case "Z0000_BIZ22_LAB103": case "Z0000_BIZ2106_LAB103": case "Z0000_BIZ2107_LAB103": case "Z0000_BIZ52_LAB103": cuminfo.addYearPolicySelfpayZy(itm.getDoubleValue("cum")); break; // 住院政策自付 case "Z0000_BIZ2101_LAB102": case "Z0000_BIZ2102_LAB102": case "Z0000_BIZ22_LAB102": case "Z0000_BIZ2106_LAB102": case "Z0000_BIZ2107_LAB102": case "Z0000_BIZ52_LAB102": cuminfo.addYearPreSelfpayZy(itm.getDoubleValue("cum")); break; // 门诊政策自费 case "Z0000_BIZ11_LAB101": case "Z0000_BIZ13_LAB101": case "Z0000_BIZ14_LAB101": case "Z0000_BIZ51_LAB101": case "Z0000_BIZ9901_LAB101": case "Z0000_BIZ9903_LAB101": case "Z0000_BIZ9904_LAB101": case "Z0000_BIZ11_LAB103": case "Z0000_BIZ13_LAB103": case "Z0000_BIZ14_LAB103": case "Z0000_BIZ51_LAB103": case "Z0000_BIZ9901_LAB103": case "Z0000_BIZ9903_LAB103": case "Z0000_BIZ9904_LAB103": cuminfo.addYearPolicySelfpayMz(itm.getDoubleValue("cum")); break; // 门诊政策自付 case "Z0000_BIZ11_LAB102": case "Z0000_BIZ13_LAB102": case "Z0000_BIZ14_LAB102": case "Z0000_BIZ51_LAB102": case "Z0000_BIZ9901_LAB102": case "Z0000_BIZ9903_LAB102": case "Z0000_BIZ9904_LAB102": cuminfo.addYearPreSelfpayMz(itm.getDoubleValue("cum")); break; // 住院大额基金支付 case "D330101_BIZ2101": case "D330101_BIZ2102": case "D330101_BIZ2106": case "D330101_BIZ2107": case "D330101_BIZ22": case "D330101_BIZ52": cuminfo.addYearBigAmtpaysZy(itm.getDoubleValue("cum")); break; // 门诊大额基金支付 case "D330101_BIZ11": case "D330101_BIZ13": case "D330101_BIZ14": case "D330101_BIZ51": case "D330101_BIZ9901": case "D330101_BIZ9903": case "D330101_BIZ9904": cuminfo.addYearBigAmtpaysMz(itm.getDoubleValue("cum")); break; // 住院大病保险支付 case "D390201_BIZ2101": case "D390201_BIZ2102": case "D390201_BIZ2106": case "D390201_BIZ2107": case "D390201_BIZ22": case "D390201_BIZ52": cuminfo.addYearBigdssInspaysZy(itm.getDoubleValue("cum")); break; // 门诊大病保险支付 case "D390201_BIZ11": case "D390201_BIZ13": case "D390201_BIZ14": case "D390201_BIZ51": case "D390201_BIZ9901": case "D390201_BIZ9903": case "D390201_BIZ9904": cuminfo.addYearBigdssInspaysMz(itm.getDoubleValue("cum")); break; // 住院医疗救助支付 case "D610101_BIZ2101": case "D610101_BIZ2102": case "D610101_BIZ2106": case "D610101_BIZ2107": case "D610101_BIZ22": case "D610101_BIZ52": cuminfo.addYearMafpaysZy(itm.getDoubleValue("cum")); break; // 门诊医疗救助支付 case "D610101_BIZ11": case "D610101_BIZ13": case "D610101_BIZ14": case "D610101_BIZ51": case "D610101_BIZ9901": case "D610101_BIZ9903": case "D610101_BIZ9904": cuminfo.addYearMafpaysMz(itm.getDoubleValue("cum")); break; // 门诊个人账户支付 case "D310201_BIZ11": case "D310201_BIZ13": case "D310201_BIZ14": case "D310201_BIZ51": case "D310201_BIZ9901": case "D310201_BIZ9903": case "D310201_BIZ9904": cuminfo.addYearAcctPayMz(itm.getDoubleValue("cum")); break; // 大病保险合规费用 case "TS390201": cuminfo.addYearBigdssLegalFee(itm.getDoubleValue("cum")); break; } } } return cuminfo; } public ResultVo> getChrgitems(SiSetlinfo setlinfo) { return getChrgitems(setlinfo.getPsnNo(), setlinfo.getSetlId(), setlinfo.getMdtrtId(), setlinfo.getInsuplcAdmdvs()); } private ResultVo> getChrgitems(String psnNo, String setlId, String mdtrtId, String admdvs) { List list = dao.selectAllSetlFeeDtle(mdtrtId); if (list.size() > 0) { return ResultVoUtil.success(list); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_FEE_DETAILS, admdvs); JSONObject data = new JSONObject(); data.put("psn_no", psnNo); 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, "没有查询到费用明细。"); } for (int i = 0; i < output.size(); i++) { JSONObject feeItem = output.getJSONObject(i); String[] mzFeeDetlSn = feeItem.getString("feedetl_sn").split("_"); feeItem.replace("feedetl_sn", Integer.parseInt(mzFeeDetlSn[mzFeeDetlSn.length - 1])); SiSetlFeeDetl fee = JSONObject.parseObject(feeItem.toJSONString(), SiSetlFeeDetl.class); if (StringUtil.isBlank(fee.getSetlId())) { fee.setSetlId(setlId); } list.add(fee); if (list.size() == 30) { dao.insertSetlFeeDetlBatch(list); list.clear(); } } if (list.size() > 0) { dao.insertSetlFeeDetlBatch(list); } return ResultVoUtil.success(dao.selectAllSetlFeeDtle(mdtrtId)); } return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, result.getString(ERROR_MESSAGE)); } private ChrgItemLvInfo analyzeParticularChrgitmLv(List chrgitms) { Map map = new HashMap<>(); map.put("allfeeSum", new BigDecimal(0)); map.put("totalFrst", new BigDecimal(0)); map.put("totalScnd", new BigDecimal(0)); map.put("totalThrd", new BigDecimal(0)); chrgitms.forEach(itm -> { BigDecimal itmfeeSum = new BigDecimal(itm.getDetItemFeeSumamt()); map.replace("allfeeSum", map.get("allfeeSum").add(itmfeeSum)); if (itm.getChrgitmLv().equals(ChrgitmLv.FIRST_CLASS.getCode())) { map.replace("totalFrst", map.get("totalFrst").add(itmfeeSum)); } else if (itm.getChrgitmLv().equals(ChrgitmLv.SECOND_CLASS.getCode())) { map.replace("totalScnd", map.get("totalScnd").add(itmfeeSum)); } else { map.replace("totalThrd", map.get("totalThrd").add(itmfeeSum)); } String typeKey = itm.getMedChrgitmType(); String lvKey = typeKey + "-" + itm.getChrgitmLv(); if (map.containsKey(typeKey)) { map.replace(typeKey, map.get(typeKey).add(itmfeeSum)); } else { map.put(typeKey, itmfeeSum); } if (map.containsKey(lvKey)) { map.replace(lvKey, map.get(lvKey).add(itmfeeSum)); } else { map.put(lvKey, itmfeeSum); } }); ChrgItemLvInfo chrgItemLvInfo = new ChrgItemLvInfo(); chrgItemLvInfo.setAllfeeSum(map.get("allfeeSum")); chrgItemLvInfo.setAllfeeFrst(map.get("totalFrst")); chrgItemLvInfo.setAllfeeScnd(map.get("totalScnd")); chrgItemLvInfo.setAllfeeThrd(map.get("totalThrd")); chrgItemLvInfo.setWestMedFeeSum(map.get("09")); chrgItemLvInfo.setWestMedFeeFrst(map.get("09-01")); chrgItemLvInfo.setWestMedFeeScnd(map.get("09-02")); chrgItemLvInfo.setWestMedFeeThrd(map.get("09-03")); chrgItemLvInfo.setHerbalSum(map.get("10")); chrgItemLvInfo.setHerbalFrst(map.get("10-01")); chrgItemLvInfo.setHerbalScnd(map.get("10-02")); chrgItemLvInfo.setHerbalThrd(map.get("10-03")); chrgItemLvInfo.setChnsPtntSum(map.get("11")); chrgItemLvInfo.setChnsPtntFrst(map.get("11-01")); chrgItemLvInfo.setChnsPtntScnd(map.get("11-02")); chrgItemLvInfo.setChnsPtntThrd(map.get("11-03")); chrgItemLvInfo.setClinicSum(map.get("02")); chrgItemLvInfo.setClinicFrst(map.get("02-01")); chrgItemLvInfo.setClinicScnd(map.get("02-02")); chrgItemLvInfo.setClinicThrd(map.get("02-03")); chrgItemLvInfo.setTreatSum(map.get("05")); chrgItemLvInfo.setTreatFrst(map.get("05-01")); chrgItemLvInfo.setTreatScnd(map.get("05-02")); chrgItemLvInfo.setTreatThrd(map.get("05-03")); chrgItemLvInfo.setSurgerySum(map.get("06")); chrgItemLvInfo.setSurgeryFrst(map.get("06-01")); chrgItemLvInfo.setSurgeryScnd(map.get("06-02")); chrgItemLvInfo.setSurgeryThrd(map.get("06-03")); chrgItemLvInfo.setNursingSum(map.get("07")); chrgItemLvInfo.setNursingFrst(map.get("07-01")); chrgItemLvInfo.setNursingScnd(map.get("07-02")); chrgItemLvInfo.setNursingThrd(map.get("07-03")); chrgItemLvInfo.setSntryMtrlsSum(map.get("08")); chrgItemLvInfo.setSntryMtrlsFrst(map.get("08-01")); chrgItemLvInfo.setSntryMtrlsScnd(map.get("08-02")); chrgItemLvInfo.setSntryMtrlsThrd(map.get("08-03")); chrgItemLvInfo.setExamSum(map.get("04")); chrgItemLvInfo.setExamFrst(map.get("04-01")); chrgItemLvInfo.setExamScnd(map.get("04-02")); chrgItemLvInfo.setExamThrd(map.get("04-03")); chrgItemLvInfo.setNrmlTrtmtSum(map.get("12")); chrgItemLvInfo.setNrmlTrtmtFrst(map.get("12-01")); chrgItemLvInfo.setNrmlTrtmtScnd(map.get("12-02")); chrgItemLvInfo.setNrmlTrtmtThrd(map.get("12-03")); chrgItemLvInfo.setInspectSum(map.get("03")); chrgItemLvInfo.setInspectFrst(map.get("03-01")); chrgItemLvInfo.setInspectScnd(map.get("03-02")); chrgItemLvInfo.setInspectThrd(map.get("03-03")); chrgItemLvInfo.setRegisterSum(map.get("13")); chrgItemLvInfo.setRegisterFrst(map.get("13-01")); chrgItemLvInfo.setRegisterScnd(map.get("13-02")); chrgItemLvInfo.setRegisterThrd(map.get("13-03")); chrgItemLvInfo.setBedfeeSum(map.get("01")); chrgItemLvInfo.setBedfeeFrst(map.get("01-01")); chrgItemLvInfo.setBedfeeScnd(map.get("01-02")); chrgItemLvInfo.setBedfeeThrd(map.get("01-03")); chrgItemLvInfo.setOthfeeSum(map.get("14")); chrgItemLvInfo.setOthfeeFrst(map.get("14-01")); chrgItemLvInfo.setOthfeeScnd(map.get("14-02")); chrgItemLvInfo.setOthfeeThrd(map.get("14-03")); return chrgItemLvInfo; } private void analyzeMzChrgitm(OtptntSetlmtLst lst, List chrgitms) { Map map = new HashMap<>(); map.put("allfeeSum", BigDecimal.valueOf(0)); map.put("totalThrd", BigDecimal.valueOf(0)); map.put("totalScnd", BigDecimal.valueOf(0)); map.put("othSum", BigDecimal.valueOf(0)); map.put("othThrd", BigDecimal.valueOf(0)); map.put("othScnd", BigDecimal.valueOf(0)); chrgitms.forEach(itm -> { map.replace("allfeeSum", map.get("allfeeSum").add(BigDecimal.valueOf(itm.getChargeFee()))); if (itm.getChrgitmLv().equals(ChrgitmLv.SELF_PAY.getCode())) { map.replace("totalThrd", map.get("totalThrd").add(BigDecimal.valueOf(itm.getChargeFee()))); } else if (itm.getChrgitmLv().equals(ChrgitmLv.SECOND_CLASS.getCode())) { map.replace("totalScnd", map.get("totalScnd").add(BigDecimal.valueOf(itm.getChargeFee()))); } String typeKey = itm.getMedChrgitmType(); if (!typeKey.equals("09") && !typeKey.equals("11")) { map.replace("othSum", map.get("othSum").add(BigDecimal.valueOf(itm.getChargeFee()))); if (itm.getChrgitmLv().equals(ChrgitmLv.SELF_PAY.getCode())) { map.replace("othThrd", map.get("othThrd").add(BigDecimal.valueOf(itm.getChargeFee()))); } else if (itm.getChrgitmLv().equals(ChrgitmLv.SECOND_CLASS.getCode())) { map.replace("othScnd", map.get("othScnd").add(BigDecimal.valueOf(itm.getChargeFee()))); } } else { String lvKey = typeKey + "-" + itm.getChrgitmLv(); if (map.containsKey(typeKey)) { map.replace(typeKey, map.get(typeKey).add(BigDecimal.valueOf(itm.getChargeFee()))); } else { map.put(typeKey, BigDecimal.valueOf(itm.getChargeFee())); } if (map.containsKey(lvKey)) { map.replace(lvKey, map.get(lvKey).add(BigDecimal.valueOf(itm.getChargeFee()))); } else { map.put(lvKey, BigDecimal.valueOf(itm.getChargeFee())); } } }); lst.setAllfeeSum(map.get("allfeeSum")); lst.setAllfeeThrd(map.get("totalThrd")); lst.setAllfeeScnd(map.get("totalScnd")); lst.setWestMedFeeSum(map.get("09")); lst.setWestMedFeeThrd(map.get("09-03")); lst.setWestMedFeeScnd(map.get("09-02")); lst.setChnsPtntSum(map.get("11")); lst.setChnsPtntThrd(map.get("11-03")); lst.setChnsPtntScnd(map.get("11-02")); lst.setMedsrvcSum(map.get("othSum")); lst.setMedsrvcThrd(map.get("othThrd")); lst.setMedsrvcScnd(map.get("othScnd")); } public ResultVo> queryMzMatnDises() { return ResultVoUtil.success(dao.selectAllMzMatnDises()); } public ResultVo> selectSetlinfoStatistics(SetlCondition condition) { String begntime = condition.getMonth() + "-01 00:00:00.000"; String endtime = DateUtil.getMonthEndtime(condition.getMonth()); String insutype = condition.getInsutype(); if (StringUtil.isBlank(insutype)) { insutype = "%%"; } List baseStatistics; switch (condition.getAdmdvsType()) { case 1: baseStatistics = dao.selectBaseSetlStatisticsInProvinceLevel(begntime, endtime, insutype, condition.getSetlType()); break; case 2: baseStatistics = dao.selectBaseSetlStatisticsInChangshaCity(begntime, endtime, insutype, condition.getSetlType()); break; case 3: baseStatistics = dao.selectBaseSetlStatisticsInProvinceOtherCities(begntime, endtime, insutype, condition.getSetlType()); break; case 4: baseStatistics = dao.selectBaseSetlStatisticsOutProvince(begntime, endtime, insutype, condition.getSetlType()); break; case 5: baseStatistics = dao.selectBaseSetlStatisticsInChangshaCounty(begntime, endtime, insutype, condition.getSetlType()); break; case 6: baseStatistics = dao.selectBaseSetlStatisticsInLiuYangCity(begntime, endtime, insutype, condition.getSetlType()); break; default: baseStatistics = dao.selectBaseSetlStatisticsInAllPlaces(begntime, endtime, insutype, condition.getSetlType()); break; } if (null == baseStatistics || baseStatistics.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST); } Map regionMap = new HashMap<>(); Map> admdvsSetldataMap = new HashMap<>(); List shangChuanJieSuanDan = new ArrayList<>(); baseStatistics.forEach(itm -> { itm.setInsutypeName(Insutype.getName(itm.getInsutype())); if (null != itm.getHospPay()) { itm.setFundPaySumamt(DecimalUtil.minus(itm.getFundPaySumamt(), itm.getHospPay())); } itm.setInsuplcAdmdvsName(redis.getRegionName(itm.getInsuplcAdmdvs())); String key; if (condition.getAdmdvsType() == 5 || condition.getAdmdvsType() == 6) { key = itm.getInsuplcAdmdvs(); } else { key = itm.getInsuplcAdmdvs().substring(0, 4) + "00"; } String admdvsName = regionMap.get(key); if (null == admdvsName) { PureCodeName region = dao.selectAdmdvsNameAndParentName(key); if (null == region) { region = dao.selectAdmdvsName(key); } admdvsName = region.getCode() + region.getName(); regionMap.put(key, admdvsName); } if (admdvsSetldataMap.containsKey(admdvsName)) { admdvsSetldataMap.get(admdvsName).add(itm); } else { List tempList = new ArrayList<>(); tempList.add(itm); admdvsSetldataMap.put(admdvsName, tempList); } itm.setMedTypeName(MedType.getName(itm.getMedType())); shangChuanJieSuanDan.add(itm); }); List resultList = new ArrayList<>(); for (Map.Entry> entry : admdvsSetldataMap.entrySet()) { List admdvsSetldataList = entry.getValue(); SetlStatisticResult resultItem = new SetlStatisticResult(); resultItem.setAdmdvsName(entry.getKey()); resultItem.setInsuplcAdmdvs(entry.getValue().get(0).getInsuplcAdmdvs().substring(0, 4) + "00"); resultItem.setPsnSumamt(admdvsSetldataList.size()); if (StringUtil.notBlank(condition.getInsutype())) { resultItem.setInsutype(condition.getInsutype()); resultItem.setInsutypeName(Insutype.getName(condition.getInsutype())); resultItem.setChildKey(entry.getKey() + "-" + resultItem.getInsutypeName()); } else { resultItem.setInsutypeName("-"); resultItem.setChildKey(entry.getKey()); } fillSetlStatisticResult(resultList, admdvsSetldataList, resultItem); } if (StringUtil.isBlank(condition.getInsutype())) { for (SetlStatisticResult resultItem : resultList) { Map> insutypeSetldataMap = new HashMap<>(); String admdvsName = resultItem.getAdmdvsName(); List admdvsSetldataList = admdvsSetldataMap.get(admdvsName); for (BaseSetlStatistics baseSetlStatistics : admdvsSetldataList) { if (insutypeSetldataMap.containsKey(baseSetlStatistics.getInsutypeName())) { insutypeSetldataMap.get(baseSetlStatistics.getInsutypeName()).add(baseSetlStatistics); } else { List tmpList = new ArrayList<>(); tmpList.add(baseSetlStatistics); insutypeSetldataMap.put(baseSetlStatistics.getInsutypeName(), tmpList); } } if (insutypeSetldataMap.size() == 1) { resultItem.setInsutype(admdvsSetldataList.get(0).getInsutype()); resultItem.setInsutypeName(admdvsSetldataList.get(0).getInsutypeName()); continue; } List children = new ArrayList<>(); for (Map.Entry> entry : insutypeSetldataMap.entrySet()) { List insutypeSetldataList = entry.getValue(); SetlStatisticResult result = new SetlStatisticResult(); result.setAdmdvsName(resultItem.getAdmdvsName()); result.setInsuplcAdmdvs(resultItem.getInsuplcAdmdvs()); result.setPsnSumamt(insutypeSetldataList.size()); result.setInsutype(entry.getValue().get(0).getInsutype()); result.setInsutypeName(entry.getValue().get(0).getInsutypeName()); result.setChildKey(resultItem.getAdmdvsName() + "-" + result.getInsutypeName()); result.setIsChildren(true); fillSetlStatisticResult(children, insutypeSetldataList, result); } resultItem.setChildren(children); } } resultList.get(0).setShangChuanJieSuanDan(shangChuanJieSuanDan); return ResultVoUtil.success(resultList); } private void fillSetlStatisticResult(List resultList, List admdvsSetldataList, SetlStatisticResult resultItem) { String medfeeSumamt = "0"; String baseMedFundpaySumamt = "0"; String bigDssFundpaySumamt = "0"; String clvFundpaySumamt = "0"; String acctpaySumamt = "0"; String othFundpaySumamt = "0"; String fundpaySumamt = "0"; for (BaseSetlStatistics itm : admdvsSetldataList) { medfeeSumamt = DecimalUtil.add(medfeeSumamt, itm.getMedfeeSumamt()); baseMedFundpaySumamt = DecimalUtil.add(baseMedFundpaySumamt, itm.getHifpPay()); bigDssFundpaySumamt = DecimalUtil.add(bigDssFundpaySumamt, itm.getHifmiPay()); clvFundpaySumamt = DecimalUtil.add(clvFundpaySumamt, itm.getCvlservPay()); acctpaySumamt = DecimalUtil.add(acctpaySumamt, itm.getAcctPay()); fundpaySumamt = DecimalUtil.add(fundpaySumamt, itm.getFundPaySumamt(), itm.getAcctPay()); String othpay = DecimalUtil.minusLink(itm.getFundPaySumamt(), itm.getHifpPay(), itm.getHifmiPay(), itm.getCvlservPay()); othFundpaySumamt = DecimalUtil.add(othFundpaySumamt, othpay); } resultItem.setMedfeeSumamt(medfeeSumamt); resultItem.setBaseMedFundpaySumamt(baseMedFundpaySumamt); resultItem.setBigDssFundpaySumamt(bigDssFundpaySumamt); resultItem.setClvFundpaySumamt(clvFundpaySumamt); resultItem.setAcctpaySumamt(acctpaySumamt); resultItem.setOthFundpaySumamt(othFundpaySumamt); resultItem.setFundpaySumamt(fundpaySumamt); resultList.add(resultItem); } public ResultVo> selectSetldetailStatistics(SetlCondition condition) { String begntime = condition.getMonth() + "-01 00:00:00.000"; String endtime = DateUtil.getMonthEndtime(condition.getMonth()); String insuplcAdmdvs; if (condition.getAdmdvsType() == 5) { insuplcAdmdvs = "430121"; } else if (condition.getAdmdvsType() == 6) { insuplcAdmdvs = "430181"; } else { insuplcAdmdvs = condition.getInsuplcAdmdvs().substring(0, 4) + "%"; } String insutype = condition.getInsutype(); if (StringUtil.isBlank(insutype)) { insutype = "%%"; } List list = setlinfoDao.selectMyList(insutype, insuplcAdmdvs, begntime, endtime); list.forEach(item -> { if (null != item.getHospPay()) { log.info("hosp: {}", item.getHospPay()); item.setFundPaySumamt(DecimalUtil.minusDouble(item.getFundPaySumamt(), item.getHospPay())); } item.setInsuplcAdmdvsName(redis.getRegionName(item.getInsuplcAdmdvs())); FilterUtil.filterCodeToName(item); }); return ResultVoUtil.success(list); } public ResultVo> weiJieSuanZaiYuanHuanZhe(String patNo, String startTime, String endTime, String name, String certno) { List actpatients = dao.zaiYuanHuanZheXinXi(patNo, startTime, endTime, StringUtil.isContainChinese(name), certno); Map insuplcAdmdvs = new HashMap<>(); for (ZyActpatient actpatient : actpatients) { if (StringUtil.isBlank(actpatient.getInsuplcAdmdvsName())) { String key = actpatient.getInsuplcAdmdvs().substring(0, 4) + "00"; if (insuplcAdmdvs.containsKey(key)) { actpatient.setInsuplcAdmdvsName(insuplcAdmdvs.get(key)); } else { String insuplcAdmdvsName = redis.getRegionName(key); insuplcAdmdvs.put(key, insuplcAdmdvsName); actpatient.setInsuplcAdmdvsName(insuplcAdmdvsName); } } } return ResultVoUtil.success(actpatients); } public ResultVo checkRegisterDate(String patNo, Integer times) { Date ledgerAccountDate = dao.selectMaxLedgerAccountDate(patNo, times); if (null == ledgerAccountDate) { return ResultVoUtil.success(); } Date registerDate = dao.selectRegisterDate(patNo); if (null == registerDate) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保登记日期不能为空。"); } Calendar ledgerCalendar = Calendar.getInstance(); ledgerCalendar.setTime(ledgerAccountDate); Calendar registerCalendar = Calendar.getInstance(); registerCalendar.setTime(registerDate); if (registerCalendar.after(ledgerCalendar)) { return ResultVoUtil.success(); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("医保登记日期【%s】不能小于断账日期【%s】,请修改。", DateUtil.formatDatetime(registerDate), DateUtil.formatDatetime(ledgerAccountDate))); } }