package thyyxxk.simzfeeoprnsystm.service; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSON; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.client.RestTemplate; import thyyxxk.simzfeeoprnsystm.dao.*; import thyyxxk.simzfeeoprnsystm.dicts.*; import thyyxxk.simzfeeoprnsystm.external.WebHisService; import thyyxxk.simzfeeoprnsystm.pojo.*; import thyyxxk.simzfeeoprnsystm.pojo.ResultVo; import thyyxxk.simzfeeoprnsystm.pojo.SiPatInfo; import thyyxxk.simzfeeoprnsystm.utils.*; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; import java.util.concurrent.TimeUnit; @Slf4j @Service public class SiMzFeeService { private final SiMzDao mzDao; private final SiSetlinfoDao setlinfoDao; private final SiSetldetailDao setldetailDao; private final ScheduledDao scheduledDao; private final ExecService exec; private final WebHisService webHisService; private final MariadbService mariadbService; private static final String RESULT_CODE = "infcode"; private static final String ERROR_MESSAGE = "err_msg"; private static final String OUTPUT = "output"; private final SiLogDao logDao; @Value("${web-his-url}") private String webHisUrl; @Value("${thmz-url}") private String thmzUrl; @Autowired public SiMzFeeService(SiMzDao mzDao, SiSetlinfoDao setlinfoDao, SiSetldetailDao setldetailDao, ScheduledDao scheduledDao, ExecService exec, WebHisService webHisService, MariadbService mariadbService, SiLogDao logDao) { this.mzDao = mzDao; this.setlinfoDao = setlinfoDao; this.setldetailDao = setldetailDao; this.scheduledDao = scheduledDao; this.exec = exec; this.webHisService = webHisService; this.mariadbService = mariadbService; this.logDao = logDao; } private boolean mipSettled(String hisOrdNum) { int count = mzDao.getMipSettleCount(hisOrdNum); return count > 0; } private boolean inMipSettleProcess(String hisOrdNum) { Integer lockFlag = mzDao.getLockFlag(hisOrdNum); return null != lockFlag && lockFlag == 1; } public ResultVo outpatientRegistration(MzPatientInfo p) { Regstrtn regstrtn; if (null != p.getVisitDate() && StringUtil.notBlank(p.getDeptCode()) && StringUtil.notBlank(p.getDoctorCode())) { regstrtn = mzDao.selectRegstrtn2(p); if (null != regstrtn) { regstrtn.setBegntime(p.getVisitDate()); regstrtn.setDeptCode(p.getDeptCode()); } } else { regstrtn = mzDao.selectRegstrtn(p.getPatNo(), p.getTimes()); } if (null == regstrtn) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "mz_visit_table或t_si_pat_info 信息为空,请联系医生重开处方。"); } if (StringUtil.notBlank(regstrtn.getMdtrtId())) { return ResultVoUtil.success("本次就诊已有医保登记[mdtrtId:" + regstrtn.getMdtrtId() + "],请勿重复办理。"); } String hisOrdNum = p.getPatNo() + "_" + p.getTimes() + "_1"; if (mipSettled(hisOrdNum)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者已完成移动医保支付,请勿重复办理。"); } if (inMipSettleProcess(hisOrdNum)) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者已进入移动医保支付流程,无法办理。"); } if (!p.abortBeforeUploadFees()) { List chargeCodeList = mzDao.selectHisChargeCodes(p.getPatNo(), p.getTimes()); if (chargeCodeList.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未找到收费明细,请先生成医保处方。"); } // 查询处方是否有折扣 String discount = queryDiscount(p.getPatNo(), p.getTimes(), chargeCodeList); if (!discount.equals("OK")) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, discount); } } if (null == p.getInsutype()) { SiPatInfo siPatInfo = mzDao.selectSiPatInfoForMz(p.getPatNo(), p.getTimes()); p.setInsuplcAdmdvs(siPatInfo.getInsuplcAdmdvs()); p.setInsutype(siPatInfo.getInsutype()); p.setPsnType(siPatInfo.getPsnType()); p.setName(siPatInfo.getPsnName()); p.setSocialNo(siPatInfo.getCertno()); } ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType()); if (readCardBizType != ReadCardBizType.REGISTRATION && !p.getInsuplcAdmdvs().startsWith("43")) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "省外异地的患者请读社保卡或医保电子凭证登记!"); } if (existSettledButNotPay(p.getPatNo(), p.getTimes())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "有HIS未缴费的医保结算,无法办理医保登记。请先完成门诊缴费再重新办理。"); } if (StringUtil.notBlank(p.getMedType())) { mzDao.updateMedtype(p.getMedType(), p.getPatNo(), p.getTimes()); } if (readCardBizType == ReadCardBizType.REGISTRATION) { MdtrtCertType mdtrtCertType = MdtrtCertType.getByLabel(p.getMdtrtCertType()); regstrtn.setMdtrtCertType(mdtrtCertType.getCode()); if (mdtrtCertType.getCode().equals(MdtrtCertType.SOCIAL_SECURITY_CARD.getCode())) { String[] out = p.getReadCardResult().split("\\|"); regstrtn.setMdtrtCertNo(out[2]); regstrtn.setCardSn(out[3]); } else if (mdtrtCertType.getCode().equals(MdtrtCertType.ELECTRONIC_VOUCHER.getCode())) { JSONObject qrinfo = JSONObject.parseObject(p.getReadCardResult()); JSONObject qrdata = qrinfo.getJSONObject("data"); if (null != qrdata) { qrinfo = qrdata; } regstrtn.setMdtrtCertNo(qrinfo.getString("ecToken")); } } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_REGISTRATION, p.getInsuplcAdmdvs(), p.getStaffId()); regstrtn.setInsutype(p.getInsutype()); regstrtn.setPsnType(p.getPsnType()); regstrtn.setIptOtpNo(p.getPatNo()); String ref = JSONObject.toJSONStringWithDateFormat(regstrtn, "yyyy-MM-dd HH:mm:ss"); input.getJSONObject("input").put("data", JSONObject.parseObject(ref)); JSONObject result = exec.executeTrade(input, SiFunction.OUTPATIENT_REGISTRATION); log.info("【操作员:{}】,门诊挂号:\n参数:{},\n结果:{}", p.getStaffId(), input, result); Integer infcode = result.getInteger(RESULT_CODE); logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, regstrtn.getPsnNo())); if (infcode == 0) { setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes()); JSONObject output = result.getJSONObject(OUTPUT).getJSONObject("data"); p.setMdtrtId(output.getString("mdtrt_id")); p.setVisitDate(regstrtn.getBegntime()); mzDao.afterRegistrtn(p); return ResultVoUtil.success(p.getMdtrtId()); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo revokeOutpatientRegistration(MzPatientInfo p) { if (null == p.getTimes()) { p.setTimes(mzDao.selectMaxTimes(p.getPatNo())); } SiPatInfo siPatInfo = mzDao.selectSiPatInfoForMz(p.getPatNo(), p.getTimes()); if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保挂号信息。"); } MzgjUtil.finishProcessing(p.getPatNo()); RevokeRegRequest request = new RevokeRegRequest(); request.setInsuplcAdmdvs(siPatInfo.getInsuplcAdmdvs()); ; request.setStaffId(p.getStaffId()); request.setPsnNo(siPatInfo.getPsnNo()); request.setMdtrtId(siPatInfo.getMdtrtId()); request.setPatNo(p.getPatNo()); request.setTimes(p.getTimes()); return executeOutpatientRegRevoke(request); } public ResultVo executeOutpatientRegRevoke(RevokeRegRequest request) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_REGISTRATION, request.getInsuplcAdmdvs(), request.getStaffId()); JSONObject data = new JSONObject(); data.put("psn_no", request.getPsnNo()); data.put("mdtrt_id", request.getMdtrtId()); data.put("ipt_otp_no", request.getPatNo()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_REGISTRATION); log.info("【操作员:{}】,取消门诊挂号:\n参数:{},\n结果:{}", request.getStaffId(), input, result); Integer infcode = result.getInteger(RESULT_CODE); logDao.insert(new SiLog(input, result, request.getPatNo(), request.getTimes(), infcode, request.getPsnNo())); String errMsg = result.getString(ERROR_MESSAGE); if (infcode == 0 || (null != errMsg && errMsg.contains("不存在该就诊信息"))) { mzDao.clearMdtrtIdForMz(request.getPatNo(), request.getTimes(), null); setlinfoDao.deletePreSettleInfo(request.getPatNo(), request.getTimes()); return ResultVoUtil.success("取消门诊挂号成功。"); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, errMsg); } public ResultVo uploadOutpatientInfo(MzPatientInfo mzptnt, SpcChrDiseAcct spcChrDiseAcct, SiPatInfo siPatInfo) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_OUTPATIENT_INFO, siPatInfo.getInsuplcAdmdvs(), spcChrDiseAcct.getStaffId()); JSONObject mdtrtinfo = new JSONObject(); List diagnosesList = new ArrayList<>(); String icdCodeNew = mzDao.selectIcdCodeNew(siPatInfo.getPatNo(), siPatInfo.getTimes()); if (StringUtil.isBlank(icdCodeNew) && null != mzptnt) { icdCodeNew = mzptnt.getIcdCodeNew(); } if (StringUtil.notBlank(icdCodeNew)) { Diagnoses base = mzDao.selectDiseinfo(siPatInfo.getPatNo(), siPatInfo.getTimes()); if (null == base && null != mzptnt) { CodeName dor = mzDao.getDorCodeAndName(mzptnt.getDoctorCode()); base = new Diagnoses(); base.setDiagDept(mzptnt.getDeptCode()); base.setDiagTime(mzptnt.getVisitDate()); base.setDiseDorNo(dor.getCode()); base.setDiseDorName(dor.getName()); } String[] icds = icdCodeNew.split(","); for (int i = 0; i < icds.length; i++) { String icd = icds[i]; String icdTextNew = mzDao.selectIcdTextNew(icd); Diagnoses diag = new Diagnoses(); diag.setDiagCode(icd); diag.setDiagName(icdTextNew); diag.setDiagSrtNo(i + 1); diag.setDiagType("1"); diag.setValiFlag("1"); diag.setDiagDept(base.getDiagDept()); diag.setDiagTime(base.getDiagTime()); diag.setDiseDorNo(base.getDiseDorNo()); diag.setDiseDorName(base.getDiseDorName()); diagnosesList.add(diag); } } else { diagnosesList = mzDao.selectMzDiags(siPatInfo.getPatNo(), siPatInfo.getTimes()); if (null == diagnosesList || diagnosesList.isEmpty()) { log.info("【{}】 上传就诊信息失败,门诊诊断为空。", siPatInfo.getPatNo()); return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的门诊诊断为空,请联系医生填写。"); } } if (siPatInfo.getMedType().equals("14") || siPatInfo.getMedType().equals("51")) { if (StringUtil.isBlank(spcChrDiseAcct.getOpspDiseCode())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "生育门诊与慢特病门诊的病种不能为空 !"); } } mdtrtinfo.put("mdtrt_id", siPatInfo.getMdtrtId()); mdtrtinfo.put("psn_no", siPatInfo.getPsnNo()); mdtrtinfo.put("med_type", siPatInfo.getMedType()); mdtrtinfo.put("begntime", DateUtil.formatDatetime(siPatInfo.getVisitDatetime())); mdtrtinfo.put("main_cond_dscr", spcChrDiseAcct.getOpspDiseName()); mdtrtinfo.put("dise_codg", spcChrDiseAcct.getOpspDiseCode()); mdtrtinfo.put("dise_name", spcChrDiseAcct.getOpspDiseName()); mdtrtinfo.put("birctrl_type", ""); mdtrtinfo.put("birctrl_matn_date", ""); mdtrtinfo.put("exp_content", spcChrDiseAcct.getExpContent()); String ref = JSONObject.toJSONString(diagnosesList); input.getJSONObject("input").put("mdtrtinfo", mdtrtinfo); input.getJSONObject("input").put("diseinfo", JSONArray.parse(ref)); JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_OUTPATIENT_INFO); log.info("【操作员:{}】门诊就诊信息上传:\n参数:{},\n结果:{}", spcChrDiseAcct.getStaffId(), input, result); Integer infcode = result.getInteger(RESULT_CODE); logDao.insert(new SiLog(input, result, siPatInfo.getPatNo(), siPatInfo.getTimes(), infcode, siPatInfo.getPsnNo())); if (result.getIntValue(RESULT_CODE) == 0) { Diagnoses main = diagnosesList.get(0); mzDao.updatePatDiseinfo(siPatInfo.getPatNo(), siPatInfo.getTimes(), main.getDiagCode(), main.getDiagName()); return ResultVoUtil.success("门诊就诊信息上传成功。"); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo uploadOutpatientFeeDetails(SpcChrDiseAcct p) { String patNo = p.getPatNo(); if (null == p.getTimes()) { p.setTimes(mzDao.selectMaxTimes(patNo)); } SiPatInfo siPatInfo = mzDao.selectSiPatInfoForMz(patNo, p.getTimes()); if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patNo + "】未找到此患者的医保挂号信息,请核实。"); } if (!p.getFromDirectReg()) { ResultVo uplRes = uploadOutpatientInfo(null, p, siPatInfo); if (null != uplRes && uplRes.getCode() != ExceptionEnum.SUCCESS.getCode()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, uplRes.getMessage()); } } List feeDetails = mzDao.selectOutpatientFees(patNo, p.getTimes()); if (null == feeDetails || feeDetails.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有需要上传的费用。"); } MzVisit mzVisit = mzDao.selectMzVisitInfo(patNo, p.getTimes()); if (null == mzVisit || StringUtil.isBlank(mzVisit.getVisitDeptCode())) { log.info("【{},{}】就诊科室没有匹配医保码,无法使用门诊统筹。", patNo, p.getTimes()); return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "就诊科室没有匹配医保码,无法使用门诊统筹。"); } String batchNo = patNo + "_" + p.getTimes(); feeDetails.forEach(item -> { item.setMdtrtId(siPatInfo.getMdtrtId()); item.setPsnNo(siPatInfo.getPsnNo()); item.setChrgBchno(batchNo); item.setRxCircFlag(YesOrNo.NO.getCodeStr()); item.setBilgDeptCodg(mzVisit.getVisitDeptCode()); item.setBilgDeptName(mzVisit.getVisitDeptName()); if (siPatInfo.getMedType().equals("51")) { item.setMatnFeeFlag("1"); } }); JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_OUTPATIENT_FEE_DETAILS, siPatInfo.getInsuplcAdmdvs(), p.getStaffId()); String ref = JSONArray.toJSONStringWithDateFormat(feeDetails, "yyyy-MM-dd HH:mm:ss"); JSONArray feedetail = JSONArray.parseArray(ref); input.getJSONObject("input").put("feedetail", feedetail); JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_OUTPATIENT_FEE_DETAILS); log.info("【操作员:{}】门诊费用明细信息上传:\n参数:{},\n结果:{}", p.getStaffId(), input, result); Integer infcode = result.getInteger(RESULT_CODE); logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, siPatInfo.getPsnNo())); if (infcode == 0) { JSONArray feeRes = result.getJSONObject(OUTPUT).getJSONArray("result"); double fulamtOwnpayAmt = 0d; double overlmtAmt = 0d; double preselfpayAmt = 0d; double inscpScpAmt = 0d; for (int i = 0; i < feeRes.size(); i++) { JSONObject fee = feeRes.getJSONObject(i); fulamtOwnpayAmt += fee.getDoubleValue("fulamt_ownpay_amt"); overlmtAmt += fee.getDoubleValue("overlmt_amt"); preselfpayAmt += fee.getDoubleValue("preselfpay_amt"); inscpScpAmt += fee.getDoubleValue("inscp_scp_amt"); String detlSn = fee.getString("feedetl_sn"); String chrgLv = fee.getString("chrgitm_lv"); String chrgType = fee.getString("med_chrgitm_type"); String[] sns = detlSn.split("_"); int times = Integer.parseInt(sns[1]); int recNo = Integer.parseInt(sns[2]); int odrNo = Integer.parseInt(sns[3]); int itmNo = Integer.parseInt(sns[4]); mzDao.afterUploadFees(patNo, times, recNo, odrNo, itmNo, chrgLv, chrgType); } siPatInfo.setFulamtOwnpayAmt(fulamtOwnpayAmt); siPatInfo.setOverlmtAmt(overlmtAmt); siPatInfo.setPreselfpayAmt(preselfpayAmt); siPatInfo.setInscpScpAmt(inscpScpAmt); mzDao.updateSortOfAmt(siPatInfo); setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes()); return ResultVoUtil.success(siPatInfo); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo revokeOutpatientFeeDetails(MzPatientInfo p) { if (null == p.getTimes()) { p.setTimes(mzDao.selectMaxTimes(p.getPatNo())); } SiPatInfo siPatInfo = mzDao.selectSiPatInfoForMz(p.getPatNo(), p.getTimes()); if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有此患者的医保挂号信息!"); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_FEE_DETAILS, siPatInfo.getInsuplcAdmdvs(), p.getStaffId()); JSONObject data = new JSONObject(); data.put("mdtrt_id", siPatInfo.getMdtrtId()); data.put("psn_no", siPatInfo.getPsnNo()); data.put("chrg_bchno", "0000"); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_FEE_DETAILS); log.info("【操作员:{}】门诊费用明细信息撤销,参数:{},结果:{}", p.getStaffId(), input, result); Integer infcode = result.getInteger(RESULT_CODE); logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, siPatInfo.getPsnNo())); if (infcode == 0) { mzDao.afterRevokeFees(p.getPatNo(), p.getTimes()); setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes()); return ResultVoUtil.success("门诊费用明细信息撤销成功。"); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo outpatientPreSettlement(MzPatientInfo p) { if (null == p.getTimes()) { p.setTimes(mzDao.selectMaxTimes(p.getPatNo())); } ResultVo setlfund = getFundDetailByPatientInfo(p.getPatNo(), p.getTimes(), false); if (setlfund != null) { return setlfund; } MzPreSetlmt mzPreSetlmt = mzDao.selectPreSetlmt(p.getPatNo(), p.getTimes()); if (null == mzPreSetlmt || null == mzPreSetlmt.getMedfeeSumamt()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者没有已上传的费用。"); } ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType()); if (readCardBizType == ReadCardBizType.SETTLEMENT) { MdtrtCertType mdtrtCertType = MdtrtCertType.getByLabel(p.getMdtrtCertType()); mzPreSetlmt.setMdtrtCertType(mdtrtCertType.getCode()); if (mdtrtCertType.getCode().equals(MdtrtCertType.SOCIAL_SECURITY_CARD.getCode())) { String[] out = p.getReadCardResult().split("\\|"); mzPreSetlmt.setMdtrtCertNo(out[2]); mzPreSetlmt.setCardSn(out[3]); } else if (mdtrtCertType.getCode().equals(MdtrtCertType.ELECTRONIC_VOUCHER.getCode())) { String socialNo = mzDao.selectSocialNo(p.getPatNo()); JSONObject qrinfo = JSONObject.parseObject(p.getReadCardResult()); JSONObject qrdata = qrinfo.getJSONObject("data"); if (null != qrdata) { qrinfo = qrdata; } if (!Objects.equals(socialNo, qrinfo.getString("idNo").trim())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证身份证与HIS身份证不一致,请确认是否人证相符。"); } mzPreSetlmt.setMdtrtCertNo(qrinfo.getString("ecToken")); } } mzPreSetlmt.setMedfeeSumamt(mzPreSetlmt.getMedfeeSumamt().setScale(2, RoundingMode.HALF_UP)); JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_PRE_SETTLEMENT, mzPreSetlmt.getInsuplcAdmdvs(), p.getStaffId()); mzPreSetlmt.setPsnSetlway(PsnSetlWay.SETTLE_BY_ITEMS.getCode()); mzPreSetlmt.setAcctUsedFlag(p.getAcctUsedFlag()); mzPreSetlmt.setChrgBchno(p.getPatNo() + "_" + p.getTimes()); mzPreSetlmt.setExpContent(p.getExpContent()); String ref = JSONObject.toJSONString(mzPreSetlmt); input.getJSONObject("input").put("data", JSONObject.parseObject(ref)); JSONObject result = exec.executeTrade(input, SiFunction.OUTPATIENT_PRE_SETTLEMENT); log.info("【操作员:{}】门诊预结算:\n参数:{},\n结果:{}", p.getStaffId(), input, result); Integer infcode = result.getInteger(RESULT_CODE); logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, mzPreSetlmt.getPsnNo())); if (infcode == 0) { setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes()); JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo"); FundDetail fundDetail = new FundDetail(); fundDetail.setTotalCost(setlinfo.getString("medfee_sumamt")); fundDetail.setFundPay(setlinfo.getString("fund_pay_sumamt")); fundDetail.setCashPay(setlinfo.getString("psn_cash_pay")); fundDetail.setAcctPay(setlinfo.getString("acct_pay")); fundDetail.setSelfPay(setlinfo.getString("psn_part_amt")); fundDetail.setCardType(getCardType(mzPreSetlmt.getInsuplcAdmdvs())); SiSetlinfo setlEntity = JSONObject.parseObject(setlinfo.toJSONString(), SiSetlinfo.class); setlEntity.setPatNo(p.getPatNo()); setlEntity.setTimes(p.getTimes()); setlEntity.setLedgerSn(0); setlEntity.setStaffId(p.getStaffId()); setlEntity.setSetlType(ClrType.OUTPATIENT.getCode()); setlEntity.setInsuplcAdmdvs(mzPreSetlmt.getInsuplcAdmdvs()); log.info("开始插入预结算临时信息:{}_{}", p.getPatNo(), p.getTimes()); setlinfoDao.insertPreSettleInfo(setlEntity); log.info("插入预结算临时信息成功:{}_{}", p.getPatNo(), p.getTimes()); return ResultVoUtil.success(fundDetail); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } private ResultVo getFundDetailByPatientInfo(String patNo, int times, boolean realSettle) { SiSetlinfo sisetlinfo = mzDao.selectSettledInfo(patNo, times, 0); if (!realSettle && null == sisetlinfo) { sisetlinfo = setlinfoDao.selectPresettleInfo(patNo, times); } if (null != sisetlinfo) { return getFundDetailFromSetlinfo(sisetlinfo); } return null; } private ResultVo getFundDetailFromSetlinfo(SiSetlinfo setlinfo) { FundDetail fundDetail = new FundDetail(); fundDetail.setCardType(getCardType(setlinfo.getInsuplcAdmdvs())); fundDetail.setTotalCost(String.valueOf(setlinfo.getMedfeeSumamt())); fundDetail.setFundPay(String.valueOf(setlinfo.getFundPaySumamt())); fundDetail.setAcctPay(String.valueOf(setlinfo.getAcctPay())); fundDetail.setCashPay(String.valueOf(setlinfo.getPsnCashPay())); fundDetail.setSelfPay(String.valueOf(setlinfo.getPsnCashPay())); if (setlinfo.getRevoked() == 1) { fundDetail.reverseAll(); } fundDetail.setSetlinfo(setlinfo); return ResultVoUtil.success(fundDetail); } private Integer getCardType(String insplc) { if (insplc.startsWith("4301")) { return 1; } else if (insplc.equals("439900")) { return 2; } return 3; } public ResultVo outpatientSettlement(MzPatientInfo p) { ResultVo setlfund = getFundDetailByPatientInfo(p.getPatNo(), p.getTimes(), true); if (setlfund != null) { return setlfund; } Setlmt setlmt = mzDao.selectSetlmt(p.getPatNo(), p.getTimes()); if (null == setlmt) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有此患者的医保就诊信息。"); } p.setInsuplcAdmdvs(setlmt.getInsuplcAdmdvs()); p.setPsnNo(setlmt.getPsnNo()); p.setMdtrtId(setlmt.getMdtrtId()); JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_SETTLEMENT, setlmt.getInsuplcAdmdvs(), p.getStaffId()); ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType()); if (readCardBizType == ReadCardBizType.SETTLEMENT) { MdtrtCertType mdtrtCertType = MdtrtCertType.getByLabel(p.getMdtrtCertType()); setlmt.setMdtrtCertType(mdtrtCertType.getCode()); if (mdtrtCertType.getCode().equals(MdtrtCertType.SOCIAL_SECURITY_CARD.getCode())) { String[] out = p.getReadCardResult().split("\\|"); setlmt.setMdtrtCertNo(out[2]); setlmt.setCardSn(out[3]); } else if (mdtrtCertType.getCode().equals(MdtrtCertType.ELECTRONIC_VOUCHER.getCode())) { String socialNo = mzDao.selectSocialNo(p.getPatNo()); JSONObject qrinfo = JSONObject.parseObject(p.getReadCardResult()); if (!Objects.equals(socialNo, qrinfo.getString("idNo").trim())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证身份证与HIS身份证不一致,请确认是否人证相符。"); } setlmt.setMdtrtCertNo(qrinfo.getString("ecToken")); } } setlmt.setMedfeeSumamt(setlmt.getMedfeeSumamt().setScale(2, RoundingMode.HALF_UP)); setlmt.setPsnSetlway(PsnSetlWay.SETTLE_BY_ITEMS.getCode()); setlmt.setChrgBchno(p.getPatNo() + "_" + p.getTimes()); Integer acctUsedFlag = p.getRealAcctUsedFlag(); if (null == acctUsedFlag) { Double acctPay = mzDao.selectAcctPayInPreSettle(setlmt.getMdtrtId()); if (null != acctPay && acctPay > 0) { acctUsedFlag = 1; } else { acctUsedFlag = 0; } } setlmt.setAcctUsedFlag(String.valueOf(acctUsedFlag)); setlmt.setInvono(SnowFlakeId.getInstance().nextId()); setlmt.setExpContent(p.getExpContent()); String ref = JSONObject.toJSONString(setlmt); input.getJSONObject("input").put("data", JSONObject.parseObject(ref)); JSONObject result = exec.executeTrade(input, SiFunction.OUTPATIENT_SETTLEMENT); log.info("【操作员:{}】门诊结算:\n参数:{},\n结果:{}", p.getStaffId(), input, result); Integer infcode = result.getInteger(RESULT_CODE); logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, setlmt.getPsnNo())); if (infcode == 0) { JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo"); SiSetlinfo setlEntity = JSONObject.parseObject(setlinfo.toJSONString(), SiSetlinfo.class); List fundList = new ArrayList<>(); JSONArray setldetail = result.getJSONObject(OUTPUT).getJSONArray("setldetail"); for (int i = 0; i < setldetail.size(); i++) { SiSetldetail setldetailEntity = JSONObject.parseObject(setldetail.getJSONObject(i).toJSONString(), SiSetldetail.class); fundList.add(setldetailEntity); } setlEntity.setSetldetail(fundList); return dealSetlEntity(p, setlEntity); } String errMsg = result.getString(ERROR_MESSAGE); if (errMsg.contains("服务提供者后端服务响应超时")) { return timeoutSetl(p); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, errMsg); } public ResultVo timeoutSetl(MzPatientInfo p) { if (StringUtil.isBlank(p.getMdtrtId())) { p.setMdtrtId(mzDao.getMdtrtId(p.getPatNo(), p.getTimes())); } if (StringUtil.isBlank(p.getMdtrtId())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到患者的医保就诊信息!"); } ResultVo setlfund = getFundDetailByPatientInfo(p.getPatNo(), p.getTimes(), true); if (setlfund != null) { return setlfund; } SiSetlinfo setlEntity = querySettlementInfo(p); if (null != setlEntity) { return dealSetlEntity(p, setlEntity); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "超时结算失败。"); } private ResultVo dealSetlEntity(MzPatientInfo p, SiSetlinfo setlEntity) { saveSetlinfoToDatabase(setlEntity, p); if (!p.getStraitSettle() && BigDecimal.ZERO.compareTo(setlEntity.getPsnCashPay()) == 0) { ResultVo mzChargeResponse = mzHisChargeProcess(p.getPatNo(), p.getTimes(), String.valueOf(setlEntity.getMedfeeSumamt())); if (mzChargeResponse.getCode() != ExceptionEnum.SUCCESS.getCode()) { revokeOutpatientSettlementForTask(setlEntity); return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, mzChargeResponse.getMessage()); } } setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes()); return getFundDetailFromSetlinfo(setlEntity); } private SiSetlinfo querySettlementInfo(MzPatientInfo p) { String url = "http://172.16.32.167:8077/siQuery/querySettlementInfo"; JSONObject params = new JSONObject(); params.put("psnNo", p.getPsnNo()); params.put("mdtrtId", p.getMdtrtId()); ResultVo vo = new RestTemplate().postForObject(url, params, ResultVo.class); if (null == vo || vo.getCode() != ExceptionEnum.SUCCESS.getCode()) { return null; } LinkedHashMap resMap = vo.getData(); SiSetlinfo entity = JSONObject.parseObject(JSON.toJSONString(resMap), SiSetlinfo.class); entity.setInsuplcAdmdvs(resMap.get("insuOptins").toString()); if (null == entity.getPsnPartAmt()) { entity.setPsnPartAmt(new BigDecimal(resMap.get("psnPay").toString())); } if (null == entity.getPsnCashPay()) { entity.setPsnCashPay(new BigDecimal(resMap.get("cashPayamt").toString())); } return entity; } private void saveSetlinfoToDatabase(SiSetlinfo setlEntity, MzPatientInfo p) { setlEntity.setPatNo(p.getPatNo()); setlEntity.setTimes(p.getTimes()); setlEntity.setLedgerSn(0); setlEntity.setStaffId(p.getStaffId()); setlEntity.setRevoked(YesOrNo.NO.getCode()); setlEntity.setInsuplcAdmdvsName(mzDao.getInsuplcAdmdvsName(setlEntity.getMdtrtId())); setlEntity.setSetlType(ClrType.OUTPATIENT.getCode()); if (StringUtil.isBlank(setlEntity.getInsuplcAdmdvs())) { setlEntity.setInsuplcAdmdvs(p.getInsuplcAdmdvs()); } setlEntity.setBegntime(mzDao.selectBegntime(p.getPatNo(), p.getTimes())); setlEntity.setEndtime(setlEntity.getSetlTime()); setlEntity.setMzSaved(p.getSaved()); BigDecimal hospitalPart = BigDecimal.ZERO; List fundList = setlEntity.getSetldetail(); fundList = null == fundList ? new ArrayList<>() : fundList; for (int i = 0; i < fundList.size(); i++) { SiSetldetail detail = fundList.get(i); detail.setPatNo(p.getPatNo()); detail.setTimes(p.getTimes()); detail.setSetlId(setlEntity.getSetlId()); detail.setSortNo(i + 1); detail.setLedgerSn(0); if (detail.getFundPayType().equals("999996") || detail.getSetlProcInfo().equals("999996")) { hospitalPart = hospitalPart.add(BigDecimal.valueOf(detail.getFundPayamt())); } setldetailDao.insert(detail); } setlEntity.setHospPartAmt(hospitalPart); setlinfoDao.insert(setlEntity); setlinfoDao.updateSiZyInfoSetlId(p.getPatNo(), p.getTimes(), 0, setlEntity.getSetlId(), setlEntity.getMedinsSetlId(), setlEntity.getMedinsSetlId()); webHisService.saveCumInfo(webHisUrl, setlEntity); } public ResultVo revokeOutpatientSettlement(MzPatientInfo p) { log.info("请求撤销门诊医保结算:{}", JSONObject.toJSON(p)); if (null == p.getTimes()) { p.setTimes(mzDao.selectMaxTimes(p.getPatNo())); } SiSetlinfo setlinfo = mzDao.selectSettledInfo(p.getPatNo(), p.getTimes(), 0); if (null == setlinfo) { if (p.needRevokeRegistration()) { deletePresettleInfoAndRevokeYb(p); } setlinfo = mzDao.selectSettledInfo(p.getPatNo(), p.getTimes(), 1); if (null == setlinfo) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有此患者的已结算数据。"); } return getFundDetailFromSetlinfo(setlinfo); } String staffDept = mzDao.selectStaffDepartment(p.getStaffId()); if (!Objects.equals(staffDept, "3020100") && !Objects.equals(staffDept, "3060000") && !Objects.equals(staffDept, "3100000")) { if (!Objects.equals(p.getStaffId(), setlinfo.getStaffId())) { return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "您没有权限撤销本条医保业务,请到收费窗口退处方,或者联系医保科处理。"); } } if (BigDecimal.ZERO.compareTo(setlinfo.getPsnCashPay()) == 0 && !Objects.equals(staffDept, "3060000")) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "本次结算【个人现金支付为0】,请到收费窗口做退费操作。"); } JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_SETTLEMENT, mzDao.selectAdmdvs(setlinfo.getPatNo(), setlinfo.getTimes(), setlinfo.getLedgerSn()), p.getStaffId()); JSONObject data = new JSONObject(); data.put("setl_id", setlinfo.getSetlId()); data.put("mdtrt_id", setlinfo.getMdtrtId()); data.put("psn_no", setlinfo.getPsnNo()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_SETTLEMENT); log.info("【操作员:{}】门诊结算撤销:\n参数:{},\n结果:{}", p.getStaffId(), input, result); Integer infcode = result.getInteger(RESULT_CODE); logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, setlinfo.getPsnNo())); if (p.needRevokeRegistration()) { deletePresettleInfoAndRevokeYb(p); } if (infcode == 0) { afterRevokeSetl(p.getPatNo(), p.getTimes(), input.getString("msgid")); return getFundDetailFromSetlinfo(setlinfo); } return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public void revokeOutpatientSettlementForTask(SiSetlinfo setlinfo) { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_SETTLEMENT, mzDao.selectAdmdvs(setlinfo.getPatNo(), setlinfo.getTimes(), setlinfo.getLedgerSn()), "99999"); JSONObject data = new JSONObject(); data.put("setl_id", setlinfo.getSetlId()); data.put("mdtrt_id", setlinfo.getMdtrtId()); data.put("psn_no", setlinfo.getPsnNo()); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_SETTLEMENT); log.info("【操作员:99999】门诊结算撤销:\n参数:{},\n结果:{}", input, result); Integer infcode = result.getInteger(RESULT_CODE); logDao.insert(new SiLog(input, result, setlinfo.getPatNo(), setlinfo.getTimes(), infcode, setlinfo.getPsnNo())); if (null != infcode && infcode == 0) { afterRevokeSetl(setlinfo.getPatNo(), setlinfo.getTimes(), input.getString("msgid")); MzPatientInfo mzPatientInfo = new MzPatientInfo(); mzPatientInfo.setPatNo(setlinfo.getPatNo()); mzPatientInfo.setTimes(setlinfo.getTimes()); mzPatientInfo.setStaffId("99999"); revokeOutpatientFeeDetails(mzPatientInfo); revokeOutpatientRegistration(mzPatientInfo); } } public void afterRevokeSetl(String patNo, int times, String msgId) { MzgjUtil.finishProcessing(patNo); try { mzDao.deleteSetlInfo(patNo, times); mzDao.deleteSetlDetail(patNo, times); mzDao.updateRvkSetlMsgid(patNo, times, msgId); setlinfoDao.deletePreSettleInfo(patNo, times); } catch (Exception e) { String sql1 = String.format("update t_si_setlinfo set revoked=1,mz_saved=0 where pat_no='%s' and times=%d;\n", patNo, times); String sql2 = String.format("delete from t_si_setldetail where pat_no='%s' and times=%d;\n", patNo, times); String sql3 = String.format("update t_si_pat_info set rvk_setl_msgid='%s' where pat_no='%s' and times=%d;", msgId, patNo, times); String sql = sql1 + sql2 + sql3; mariadbService.insertNewRecord(sql); } } public ResultVo directRegistration(DirectionRegParam param) { log.info("门诊共济:{}", param); if (MzgjUtil.inProcessing(param.getPatientId())) { log.info("【{}】此患者上一次的共济流程尚未结束,请稍后再试。", param.getPatientId()); return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者上一次的共济流程尚未结束,请稍后再试。"); } ResultVo setlfund = getFundDetailByPatientInfo(param.getPatientId(), param.getTimes(), false); if (setlfund != null) { return setlfund; } MzgjUtil.addProcess(param.getPatientId()); ResultVo response; try { response = executeMzgj(param); } catch (Exception e) { response = ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, e.getMessage()); } finally { MzgjUtil.finishProcessing(param.getPatientId()); } return response; } private ResultVo executeMzgj(DirectionRegParam param) { if (mzDao.selectExistCount(param.getPatientId(), param.getTimes()) == 0) { if (mzDao.updateMzTimes(param.getPatientId(), param.getTimes()) == 0) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "[t_si_pat_info]不存在患者[" + param.getPatientId() + "]第[" + param.getTimes() + "]次的就诊信息,请重新查询。"); } } mzDao.deleteTempPatinfo(param.getPatientId(), param.getTimes()); MzPatientInfo mzptnt = new MzPatientInfo(); mzptnt.setStaffId(param.getStaffId()); mzptnt.setPatNo(param.getPatientId()); mzptnt.setTimes(param.getTimes()); mzptnt.setMedType(param.getMedType()); mzptnt.setAcctUsedFlag(param.getAcctUsedFlag()); mzptnt.setStraitSettle(param.getStraitSettle()); mzptnt.setAbortBeforeUploadFees(param.abortBeforeUploadFees()); mzptnt.setVisitDate(param.getVisitDate()); mzptnt.setDeptCode(param.getVisitDeptCode()); mzptnt.setDoctorCode(param.getDoctorCode()); mzptnt.setIcdCodeNew(param.getIcdCodeNew()); mzptnt.setIcdTextNew(param.getIcdTextNew()); if (!param.abortBeforeUploadFees()) { // 生成医保费用 String mzReceipts = generateSiMzFees(mzptnt); if (!mzReceipts.equals("SUCCESS")) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, mzReceipts); } } // 填充医保基本信息 SiPatInfo siPatInfo = mzDao.selectSiPatInfoForMz(mzptnt.getPatNo(), mzptnt.getTimes()); mzptnt.setInsuplcAdmdvs(siPatInfo.getInsuplcAdmdvs()); mzptnt.setInsutype(siPatInfo.getInsutype()); mzptnt.setPsnType(siPatInfo.getPsnType()); mzptnt.setName(siPatInfo.getPsnName()); mzptnt.setSocialNo(siPatInfo.getCertno()); // 解析读卡信息 if (StringUtil.notBlank(param.getReadCardResult())) { MdtrtCertType mdtrtCertType = MdtrtCertType.get(param.getReadCardType()); mzptnt.setMdtrtCertType(mdtrtCertType.getLabel()); mzptnt.setReadCardBizType(ReadCardBizType.REGISTRATION.getCode()); mzptnt.setReadCardResult(param.getReadCardResult()); if (mdtrtCertType.getCode().equals(MdtrtCertType.ELECTRONIC_VOUCHER.getCode())) { JSONObject obj = JSONObject.parseObject(param.getReadCardResult()); JSONObject qrdata = obj.getJSONObject("data"); if (null != qrdata) { obj = qrdata; } String admdvs = obj.getString("insuOrg"); if (StringUtil.isBlank(mzptnt.getInsuplcAdmdvs())) { mzptnt.setInsuplcAdmdvs(admdvs); } } } // 挂号登记 ResultVo regres = outpatientRegistration(mzptnt); if (regres.getCode() != ExceptionEnum.SUCCESS.getCode()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, regres.getMessage()); } // 上传就诊信息 siPatInfo = mzDao.selectSiPatInfoForMz(mzptnt.getPatNo(), mzptnt.getTimes()); siPatInfo.setFromDirectReg(true); SpcChrDiseAcct spcChrDiseAcct = new SpcChrDiseAcct(); spcChrDiseAcct.setStaffId(param.getStaffId()); spcChrDiseAcct.setOpspDiseCode(param.getOpspDiseCode()); spcChrDiseAcct.setOpspDiseName(param.getOpspDiseName()); spcChrDiseAcct.setExpContent(param.getExpContent()); ResultVo upldMdtrtRes = uploadOutpatientInfo(mzptnt, spcChrDiseAcct, siPatInfo); if (upldMdtrtRes.getCode() != ExceptionEnum.SUCCESS.getCode()) { revokeOutpatientRegistration(mzptnt); return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldMdtrtRes.getMessage()); } if (param.abortBeforeUploadFees()) { return ResultVoUtil.success(); } // 上传费用明细 spcChrDiseAcct.setStaffId(param.getStaffId()); spcChrDiseAcct.setPatNo(mzptnt.getPatNo()); spcChrDiseAcct.setTimes(mzptnt.getTimes()); spcChrDiseAcct.setFromDirectReg(true); ResultVo upldFeeRes = uploadOutpatientFeeDetails(spcChrDiseAcct); if (upldFeeRes.getCode() != ExceptionEnum.SUCCESS.getCode()) { revokeOutpatientRegistration(mzptnt); return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldFeeRes.getMessage()); } // 如果是退费重收,直接结算 if (param.getStraitSettle()) { return outpatientSettlement(mzptnt); } // 如果试算个人现金支付为0,直接结算 mzptnt.setReadCardBizType(ReadCardBizType.SETTLEMENT.getCode()); ResultVo presetlResponse = outpatientPreSettlement(mzptnt); if (presetlResponse.getCode() == ExceptionEnum.SUCCESS.getCode()) { FundDetail fundDetail = presetlResponse.getData(); BigDecimal cashpay = new BigDecimal(fundDetail.getCashPay()); if (cashpay.compareTo(BigDecimal.ZERO) == 0) { return outpatientSettlement(mzptnt); } } return presetlResponse; } public String generateSiMzFees(MzPatientInfo mzptnt) { ResultVo>> getMzRcptRes = webHisService.getMzReceipts(webHisUrl, mzptnt); if (null == getMzRcptRes) { return ExceptionEnum.NETWORK_ERROR.getMessage(); } if (getMzRcptRes.getCode() != ExceptionEnum.SUCCESS.getCode()) { return getMzRcptRes.getMessage(); } List mzReceipts = new ArrayList<>(); for (Map item : getMzRcptRes.getData()) { int times = (int) item.get("times"); if (times != mzptnt.getTimes()) { continue; } mzDao.deleteAllReceipts(mzptnt.getPatNo(), times); Map> orderReceiptsMap = FilterUtil.cast(item.get("mzReceipts")); for (Map.Entry> entry : orderReceiptsMap.entrySet()) { mzReceipts.addAll(entry.getValue()); } } if (mzReceipts.isEmpty()) { return "没有可以上传到医保的费用。"; } ResultVo insertSiMzFeeRes = webHisService.insertSiMzFees(webHisUrl, mzReceipts); if (insertSiMzFeeRes.getCode() != ExceptionEnum.SUCCESS.getCode()) { return insertSiMzFeeRes.getMessage(); } return "SUCCESS"; } private String queryDiscount(String patNo, int times, List mzReceipts) { JSONObject params = new JSONObject(); params.put("patientId", patNo); params.put("times", times); params.put("chargeCodes", mzReceipts); JSONObject response = webHisService.checkDiscount(thmzUrl, params); int code = response.getIntValue("code"); if (code == 0) { return "OK"; } if (code == -2) { return "患者本次就诊有折扣优惠,无法进行医保统筹。"; } return response.getString("message"); } private ResultVo mzHisChargeProcess(String patientId, int times, String totalFee) { JSONObject params = new JSONObject(); params.put("patientId", patientId); params.put("times", times); params.put("totalFee", totalFee); int tryTimes = 1; JSONObject response = webHisService.mzChargeFee(thmzUrl, params); log.info("第{}次保存处方:\n参数:{}\n结果:{}", tryTimes, params, response); while (0 != response.getInteger("code") && tryTimes < 5 && !response.getString("message").contains("已经收费")) { try { tryTimes += 1; response = webHisService.mzChargeFee(thmzUrl, params); log.info("第{}次保存处方:\n参数:{}\n结果:{}", tryTimes, params, response); TimeUnit.SECONDS.sleep(Math.min(tryTimes, 3)); } catch (Exception e) { log.error("TIMEUNIT SLEEP ERROR", e); } } if (0 != response.getInteger("code") && !response.getString("message").contains("已经收费")) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "自动保存处方失败,将为您撤销门诊医保业务。"); } return ResultVoUtil.success(); } public ResultVo isPatientDuringSiSettle(String patientId) { int result = MzgjUtil.inProcessing(patientId) ? 1 : 0; return ResultVoUtil.success(result); } public void deletePresettleInfoAndRevokeYb(MzPatientInfo p) { int res = setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes()); if (res == 1) { revokeOutpatientFeeDetails(p); revokeOutpatientRegistration(p); } } private boolean existSettledButNotPay(String patNo, int times) { List setlinfos = scheduledDao.selectSettleInfosByPatient(patNo, times); for (SiSetlinfo item : setlinfos) { if (null != item.getPayCount() && item.getPayCount() > 0) { scheduledDao.updateMzSaved(item.getSetlId()); } else { return true; } } return false; } public void test() { JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_SETTLEMENT, "430105", "01897"); JSONObject data = new JSONObject(); data.put("setl_id", "421253439"); data.put("mdtrt_id", "758032270"); data.put("psn_no", "43000020100034025147"); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_SETTLEMENT); log.info("【操作员:01897】门诊结算撤销:\n参数:{},\n结果:{}",input, result); } }