package thyyxxk.webserver.service.medicalinsurance; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import thyyxxk.webserver.config.exception.ExceptionEnum; import thyyxxk.webserver.constants.Capacity; import thyyxxk.webserver.dao.his.medicalinsurance.SiMzDao; import thyyxxk.webserver.dao.his.medicalinsurance.SiQueryDao; import thyyxxk.webserver.entity.ResultVo; import thyyxxk.webserver.entity.markmtfees.*; import thyyxxk.webserver.entity.medicalinsurance.outpatient.*; import thyyxxk.webserver.entity.medicalinsurance.query.SiPatInfo; import thyyxxk.webserver.entity.medicalinsurance.setlinfo.FundDetail; import thyyxxk.webserver.utils.*; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @description: 门诊医保交易 * @author: DingJie * @create: 2021-05-28 16:11:19 **/ @Slf4j @Service public class SiMzService { private final SiMzDao dao; private final SiQueryDao queryDao; @Value("${hrg-api-url}") private String hrgApiUrl; @Value("${si-fee-url}") private String siFeeUrl; @Autowired public SiMzService(SiMzDao dao, SiQueryDao queryDao) { this.dao = dao; this.queryDao = queryDao; } public ResultVo outpatientRegistration(MzPatientInfo p) { p.setStaffId(TokenUtil.getTokenUserId()); RestTemplate restTemplate = new RestTemplate(); return restTemplate.postForObject(siFeeUrl + "/mzFee/outpatientRegistration", p, ResultVo.class); // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_REGISTRATION, p.getInsuplcAdmdvs()); // Regstrtn regstrtn = dao.selectRegstrtn(p.getPatNo(), p.getTimes()); // if (null == regstrtn) { // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "mz_visit_table患者信息为空,请联系医生重开处方。"); // } // regstrtn.setInsutype(p.getInsutype()); // regstrtn.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode()); // 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结果:{}", 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).getJSONObject("data"); // p.setMdtrtId(output.getString("mdtrt_id")); // p.setVisitDate(regstrtn.getBegntime()); // dao.afterRegistrtn(p); // return ResultVoUtil.success("挂号成功。"); // } // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo revokeOutpatientRegistration(MzPatientInfo p) { p.setStaffId(TokenUtil.getTokenUserId()); RestTemplate restTemplate = new RestTemplate(); return restTemplate.postForObject(siFeeUrl + "/mzFee/revokeOutpatientRegistration", p, ResultVo.class); // if (null == p.getTimes()) { // p.setTimes(dao.selectMaxTimes(p.getPatNo())); // } // SiPatInfo siPatInfo = queryDao.selectSiPatInfoForMz(p.getPatNo(), p.getTimes()); // if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) { // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保挂号信息。"); // } // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_REGISTRATION, siPatInfo.getInsuplcAdmdvs()); // JSONObject data = new JSONObject(); // data.put("psn_no", siPatInfo.getPsnNo()); // data.put("mdtrt_id", siPatInfo.getMdtrtId()); // data.put("ipt_otp_no", p.getPatNo()); // input.getJSONObject("input").put("data", data); // JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_OUTPATIENT_REGISTRATION); // 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) { // queryDao.clearMdtrtIdForMz(p.getPatNo(), p.getTimes(), null); // return ResultVoUtil.success("取消门诊挂号成功。"); // } // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo>> getMzReceipts(MzPatientInfo p) { String patNo = p.getPatNo(); if (null == p.getTimes()) { p.setTimes(dao.selectMaxTimes(patNo)); } SiPatInfo siPatInfo = queryDao.selectSiPatInfoForMz(patNo, p.getTimes()); if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patNo + "】未找到此患者的医保挂号信息,请核实。"); } JSONObject queryMzChargeListParam = new JSONObject(); queryMzChargeListParam.put("patCardType", 21); queryMzChargeListParam.put("patCardNo", patNo); queryMzChargeListParam.put("hisOrdNum", ""); RestTemplate template = new RestTemplate(); Map mzChargeListMap = template.postForObject(hrgApiUrl + "/getMzChargeDetailForUnPaid", queryMzChargeListParam, Map.class); if (null == mzChargeListMap) { return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR); } if (0 != (int) mzChargeListMap.get("resultCode")) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, mzChargeListMap.get("resultMessage").toString()); } List> finalResult = new ArrayList<>(); List> mzChargeList = FilterUtil.cast(mzChargeListMap.get("data")); for (Map item : mzChargeList) { String hisOrdNum = item.get("hisOrdNum"); if (null != hisOrdNum) { String[] hisOrdNumParts = hisOrdNum.split("_"); int tempTimes = Integer.parseInt(hisOrdNumParts[1]); MzVisit mzVisit = dao.selectMzVisit(patNo, tempTimes); if (null == mzVisit) { continue; } Map childResult = new HashMap<>(Capacity.FIVE); childResult.put("times", tempTimes); childResult.put("mzPatient", siPatInfo); childResult.put("mzVisit", mzVisit); JSONObject queryMzChargeDetailParam = new JSONObject(); queryMzChargeDetailParam.put("patientId", patNo); queryMzChargeDetailParam.put("times", tempTimes); queryMzChargeDetailParam.put("receiptNo", hisOrdNumParts[2]); mzVisit.setReceiptNo(Integer.parseInt(hisOrdNumParts[2])); Map mzChargeDetailMap = template.postForObject(hrgApiUrl + "/unPaidToFullChargeDetail", queryMzChargeDetailParam, Map.class); if (null != mzChargeDetailMap && 0 == (int) mzChargeDetailMap.get("resultCode")) { List> mzChargeDetailList = FilterUtil.cast(mzChargeDetailMap.get("data")); mzChargeDetailList.removeIf(detail -> "TC".equals(detail.get("billItemCode")) || !"5".equals(detail.get("payMark")) || "BILL99".equals(detail.get("chargeItemCode")) || "四舍五入".equals(detail.get("tcName"))); if (mzChargeDetailList.isEmpty()) { continue; } Map> orderReceiptsMap = new HashMap<>(Capacity.DEFAULT); String doctorName = dao.selectDoctorName(mzChargeDetailList.get(0).get("doctorCode").toString()); mzChargeDetailList.forEach(detail -> { MzReceipt receipt = fillMzReceipt(detail); receipt.setPatientId(patNo); receipt.setTimes(tempTimes); receipt.setDoctorName(doctorName); if (!orderReceiptsMap.containsKey(receipt.getOrderNo())) { List list = new ArrayList<>(); list.add(receipt); orderReceiptsMap.put(receipt.getOrderNo(), list); } else { orderReceiptsMap.get(receipt.getOrderNo()).add(receipt); } }); List orderNos = getOrderNos(patNo, tempTimes, mzVisit.getReceiptNo(), orderReceiptsMap); childResult.put("orderNos", orderNos); childResult.put("mzReceipts", orderReceiptsMap); finalResult.add(childResult); } } } return ResultVoUtil.success(finalResult); } public ResultVo> getHistoryMzReceipts(String patNo) { List mzChargeList = dao.selectMzDepositFiles(patNo); if (null == mzChargeList || mzChargeList.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到历史处方!"); } return ResultVoUtil.success(mzChargeList); } public ResultVo> getHistoryReceiptDetail(MzDepositFile mzDepositFile) { List mzReceipts = dao.selectMzCharge(mzDepositFile.getPatNo(), mzDepositFile.getTimes(), mzDepositFile.getReceiptNo()); mzReceipts.forEach(itm -> itm.setChecked(true)); return ResultVoUtil.success(mzReceipts); } private MzReceipt fillMzReceipt(Map detail) { MzReceipt receipt = new MzReceipt(); receipt.setChecked(true); receipt.setReceiptNo((int) detail.get("receiptNo")); receipt.setOrderNo((int) detail.get("orderNo")); receipt.setItemNo((int) detail.get("itemNo")); receipt.setDrugName(detail.get("tcName").toString()); receipt.setChargeItemCode(detail.get("chargeItemCode").toString()); receipt.setPriceTime(DateUtil.formatPriceTime(detail.get("priceTime").toString())); receipt.setUnitPrice(new BigDecimal(detail.get("unitPrice").toString()).setScale(4, RoundingMode.HALF_UP)); receipt.setQuantity((double) detail.get("quantity")); receipt.setDrugWin((int) detail.get("drugWin")); receipt.setDoctorCode(detail.get("doctorCode").toString()); receipt.setSerialNo(detail.get("serialNo").toString()); receipt.setGroupNo(detail.get("groupNo").toString()); receipt.setBillItemCode(detail.get("billItemCode").toString()); receipt.setChargeBillCode(detail.get("chargeBillCode").toString()); if (null != detail.get("instructionText")) { receipt.setInstructionText(detail.get("instructionText").toString()); } if (null != detail.get("specification")) { receipt.setSpecification(detail.get("specification").toString()); } if (null != detail.get("frequency")) { receipt.setFrequency(detail.get("frequency").toString()); } if (null != detail.get("drugQuan")) { receipt.setDrugQuan((Double) detail.get("drugQuan")); } if (null != detail.get("orderDays")) { receipt.setOrderDays((Integer) detail.get("orderDays")); } // groupNo:00-项目;其他-药品 if ("00".equals(receipt.getGroupNo())) { receipt.setDrugUnit(dao.selectXmChargeUnit(receipt.getChargeItemCode())); } else { if (null != detail.get("serial")) { receipt.setSerial(detail.get("serial").toString()); receipt.setSpecification(dao.selectSpecification(receipt.getChargeItemCode(), receipt.getSerial())); } if (null != detail.get("supplyCode")) { receipt.setSupplyCode(dao.selectSupplyName(detail.get("supplyCode").toString())); } if (null != detail.get("drugUnit")) { receipt.setDrugUnit(dao.selectDrugUnit(detail.get("drugUnit").toString())); } } return receipt; } private List getOrderNos(String patientId, int times, int receiptNo, Map> orderReceiptsMap) { List orderNos = new ArrayList<>(); for (Map.Entry> entry : orderReceiptsMap.entrySet()) { OrderNo orderNo = new OrderNo(); orderNo.setPatientId(patientId); orderNo.setTimes(times); orderNo.setReceiptNo(entry.getValue().get(0).getReceiptNo()); orderNo.setOrderNo(entry.getKey()); BigDecimal total = new BigDecimal("0.00"); for (MzReceipt receipt : entry.getValue()) { total = total.add(receipt.getChargeFee()); } orderNo.setTotalFee(total); int count = dao.selectFeeCount(patientId, times, receiptNo, entry.getKey()); orderNo.setStatus(count > 0); orderNos.add(orderNo); } return orderNos; } public ResultVo insertSiMzFees(List receipts) { MzReceipt receipt = receipts.get(0); SiPatInfo siPatInfo = queryDao.selectSiPatInfoForMz(receipt.getPatientId(), receipt.getTimes()); if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + receipt.getPatientId() + "】未找到此患者的医保挂号信息,请核实。"); } int count = dao.selectFeeCount(receipt.getPatientId(), receipt.getTimes(), receipt.getReceiptNo(), receipt.getOrderNo()); if (count > 0) { return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该处方已生成过门特费用,请勿重复操作。"); } dao.insertMzChargeYb(receipt.getPatientId(), receipt.getTimes(), receipt.getReceiptNo(), receipt.getOrderNo(), siPatInfo.getInsutype(), siPatInfo.getMedType()); receipts.forEach(item -> { if (item.getChecked()) { dao.insertBatchedMtFeeInfo(item); } }); return ResultVoUtil.success(); } public ResultVo deleteMzReceipt(OrderNo param) { dao.deleteMzReceipt(param); return ResultVoUtil.success(); } public ResultVo deleteAllMzReceipts(MzPatientInfo p) { if (null == p.getTimes()) { p.setTimes(dao.selectMaxTimes(p.getPatNo())); } log.info("【操作员:{}】删除所有门特处方:门诊号:{},门诊次数:{}", TokenUtil.getTokenUserId(), p.getPatNo(), p.getTimes()); dao.deleteAllReceipts(p.getPatNo(), p.getTimes()); return ResultVoUtil.success("删除成功。"); } // private ResultVo uploadOutpatientInfo(SpcChrDiseAcct p, SiPatInfo siPatInfo) { // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_OUTPATIENT_INFO, siPatInfo.getInsuplcAdmdvs()); // JSONObject mdtrtinfo = new JSONObject(); // Diseinfo diag = dao.selectDiseinfo(p.getPatNo(), p.getTimes()); // if (StringUtil.notBlank(p.getOpspDiseCode())) { // diag.setDiagCode(p.getOpspDiseCode()); // diag.setDiagName(p.getOpspDiseName()); // } // if (StringUtil.isBlank(diag.getDiagCode())) { // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的门诊诊断为空,请联系医生填写!"); // } // dao.updatePatDiseinfo(siPatInfo.getPatNo(), siPatInfo.getTimes(), diag.getDiagCode(), diag.getDiagName()); // 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", p.getOpspDiseName()); // mdtrtinfo.put("dise_codg", p.getOpspDiseCode()); // mdtrtinfo.put("dise_name", p.getOpspDiseName()); // mdtrtinfo.put("birctrl_type", ""); // mdtrtinfo.put("birctrl_matn_date", ""); // List diseinfo = new ArrayList<>(); // diseinfo.add(diag); // String ref = JSONObject.toJSONString(diseinfo); // 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结果:{}", TokenUtil.getTokenUserId(), input, result); // return SiUtil.makeReturnWithoutOutput(result, "门诊就诊信息上传成功。"); // } public ResultVo uploadOutpatientFeeDetails(SpcChrDiseAcct p) { p.setStaffId(TokenUtil.getTokenUserId()); RestTemplate restTemplate = new RestTemplate(); return restTemplate.postForObject(siFeeUrl + "/mzFee/uploadOutpatientFeeDetails", p, ResultVo.class); // String patNo = p.getPatNo(); // if (null == p.getTimes()) { // p.setTimes(dao.selectMaxTimes(patNo)); // } // SiPatInfo siPatInfo = queryDao.selectSiPatInfoForMz(patNo, p.getTimes()); // if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) { // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patNo + // "】未找到此患者的医保挂号信息,请核实。"); // } // ResultVo uplRes = uploadOutpatientInfo(p, siPatInfo); // if (null != uplRes && uplRes.getCode() != ExceptionEnum.SUCCESS.getCode()) { // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, uplRes.getMessage()); // } // List feeDetails = dao.selectOutpatientFees(patNo, p.getTimes()); // if (null == feeDetails || feeDetails.isEmpty()) { // 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.setHospApprFlag(YesOrNo.YES.getCodeStr()); // }); // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_OUTPATIENT_FEE_DETAILS, siPatInfo.getInsuplcAdmdvs()); // String ref = JSONArray.toJSONString(feeDetails); // 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结果:{}", 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 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]); // dao.afterUploadFees(patNo, times, recNo, odrNo, itmNo, chrgLv, chrgType); // } // siPatInfo.setFulamtOwnpayAmt(fulamtOwnpayAmt); // siPatInfo.setOverlmtAmt(overlmtAmt); // siPatInfo.setPreselfpayAmt(preselfpayAmt); // siPatInfo.setInscpScpAmt(inscpScpAmt); // dao.updateSortOfAmt(siPatInfo); // return ResultVoUtil.success(siPatInfo); // } // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo revokeOutpatientFeeDetails(MzPatientInfo p) { p.setStaffId(TokenUtil.getTokenUserId()); RestTemplate restTemplate = new RestTemplate(); return restTemplate.postForObject(siFeeUrl + "/mzFee/revokeOutpatientFeeDetails", p, ResultVo.class); // if (null == p.getTimes()) { // p.setTimes(dao.selectMaxTimes(p.getPatNo())); // } // SiPatInfo siPatInfo = queryDao.selectSiPatInfoForMz(p.getPatNo(), p.getTimes()); // log.info("patNo: {}, times: {}, sipatinfo: {}", p.getPatNo(), p.getTimes(), siPatInfo); // if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) { // return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有此患者的医保挂号信息!"); // } // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_FEE_DETAILS, siPatInfo.getInsuplcAdmdvs()); // 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("【操作员:{}】门诊费用明细信息撤销,参数:{},结果:{}", 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) { // dao.afterRevokeFees(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.getStaffId()) { p.setStaffId(TokenUtil.getTokenUserId()); } RestTemplate restTemplate = new RestTemplate(); return restTemplate.postForObject(siFeeUrl + "/mzFee/outpatientPreSettlement", p, ResultVo.class); // if (null == p.getTimes()) { // p.setTimes(dao.selectMaxTimes(p.getPatNo())); // } // ResultVo fundDetail1 = getFundDetailResultVo(p); // if (fundDetail1 != null) return fundDetail1; // PreSetlmt preSetlmt = dao.selectPreSetlmt(p.getPatNo(), p.getTimes()); // preSetlmt.setMedfeeSumamt(preSetlmt.getMedfeeSumamt().setScale(2, RoundingMode.HALF_UP)); // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_PRE_SETTLEMENT, preSetlmt.getInsuplcAdmdvs()); // preSetlmt.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode()); // preSetlmt.setPsnSetlway(PsnSetlWay.SETTLE_BY_ITEMS.getCode()); // preSetlmt.setAcctUsedFlag(YesOrNo.NO.getCodeStr()); // preSetlmt.setChrgBchno(p.getPatNo() + "_" + p.getTimes()); // String ref = JSONObject.toJSONString(preSetlmt); // 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); // 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) { // int mtPartCount = dao.selectMtPartCount(p.getPatNo(), p.getTimes()); // if (mtPartCount == 0) { // CssybApplyInfo applyInfo = new CssybApplyInfo(); // applyInfo.setPatientId(p.getPatNo()); // applyInfo.setTimes(p.getTimes()); // applyInfo.setHicNo(preSetlmt.getPsnNo()); // applyInfo.setBizType(preSetlmt.getMedType()); // applyInfo.setIcdCode(""); // applyInfo.setIcdName(""); // applyInfo.setMzSerialNo(preSetlmt.getMdtrtId()); // dao.insertMtPartInfo(applyInfo); // } // 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")); // return ResultVoUtil.success(fundDetail); // } // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } // private ResultVo getFundDetailResultVo(MzPatientInfo p) { // SiSetlinfo sisetl = dao.selectSettledInfo(p.getPatNo(), p.getTimes()); // if (null != sisetl && null != sisetl.getSetlId()) { // FundDetail fundDetail = new FundDetail(); // fundDetail.setTotalCost(String.valueOf(sisetl.getMedfeeSumamt())); // fundDetail.setFundPay(String.valueOf(sisetl.getFundPaySumamt())); // fundDetail.setCashPay(String.valueOf(sisetl.getPsnCashPay())); // fundDetail.setAcctPay(String.valueOf(sisetl.getAcctPay())); // fundDetail.setSelfPay(String.valueOf(sisetl.getPsnPartAmt())); // return ResultVoUtil.success(fundDetail); // } // if (null == p.getStaffId()) { // p.setStaffId(TokenUtil.getTokenUserId()); // } // return null; // } public ResultVo outpatientSettlement(MzPatientInfo p) { if (null == p.getStaffId()) { p.setStaffId(TokenUtil.getTokenUserId()); } RestTemplate restTemplate = new RestTemplate(); return restTemplate.postForObject(siFeeUrl + "/mzFee/outpatientSettlement", p, ResultVo.class); // ResultVo fundDetail1 = getFundDetailResultVo(p); // if (fundDetail1 != null) return fundDetail1; // Setlmt setlmt = dao.selectSetlmt(p.getPatNo(), p.getTimes()); // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_SETTLEMENT, setlmt.getInsuplcAdmdvs()); // setlmt.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode()); // setlmt.setMedfeeSumamt(setlmt.getMedfeeSumamt().setScale(2, RoundingMode.HALF_UP)); // setlmt.setPsnSetlway(PsnSetlWay.SETTLE_BY_ITEMS.getCode()); // setlmt.setChrgBchno(p.getPatNo() + "_" + p.getTimes()); // setlmt.setAcctUsedFlag(YesOrNo.NO.getCodeStr()); // setlmt.setInvono(SnowFlakeId.instance().nextId()); // 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); // 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 setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo"); // SiSetlinfo setlEntity = JSONObject.parseObject(setlinfo.toJSONString(), SiSetlinfo.class); // setlEntity.setPatNo(p.getPatNo()); // setlEntity.setTimes(p.getTimes()); // setlEntity.setLedgerSn(0); // setlEntity.setStaffId(p.getStaffId()); // setlEntity.setRevoked(YesOrNo.NO.getCode()); // setlEntity.setSetlType(ClrType.OUTPATIENT.getCode()); // setlinfoDao.insert(setlEntity); // setlinfoDao.updateSiZyInfoSetlId(p.getPatNo(), p.getTimes(), 0, setlEntity.getSetlId(), // setlEntity.getMedinsSetlId(), input.getString("msgid")); // 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); // setldetailEntity.setPatNo(p.getPatNo()); // setldetailEntity.setTimes(p.getTimes()); // setldetailEntity.setLedgerSn(0); // setldetailDao.insert(setldetailEntity); // } // FundDetail fundDetail = new FundDetail(); // fundDetail.setTotalCost(String.valueOf(setlEntity.getMedfeeSumamt())); // fundDetail.setFundPay(String.valueOf(setlEntity.getFundPaySumamt())); // fundDetail.setCashPay(String.valueOf(setlEntity.getPsnCashPay())); // fundDetail.setAcctPay(String.valueOf(setlEntity.getAcctPay())); // fundDetail.setSelfPay(String.valueOf(setlEntity.getPsnPartAmt())); // return ResultVoUtil.success(fundDetail); // } // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } public ResultVo revokeOutpatientSettlement(MzPatientInfo p) { if (null == p.getStaffId()) { p.setStaffId(TokenUtil.getTokenUserId()); } RestTemplate restTemplate = new RestTemplate(); return restTemplate.postForObject(siFeeUrl + "/mzFee/revokeOutpatientSettlement", p, ResultVo.class); // if (null == p.getTimes()) { // p.setTimes(dao.selectMaxTimes(p.getPatNo())); // } // if (null == p.getStaffId()) { // p.setStaffId(TokenUtil.getTokenUserId()); // } // QueryWrapper wrapper = new QueryWrapper<>(); // wrapper.eq("pat_no", p.getPatNo()); // wrapper.eq("times", p.getTimes()); // wrapper.eq("revoked", 0); // SiSetlinfo setlinfo = setlinfoDao.selectOne(wrapper); // if (null == setlinfo) { // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的结算信息。"); // } // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_SETTLEMENT, // dao.selectAdmdvs(setlinfo.getPatNo(), setlinfo.getTimes(), setlinfo.getLedgerSn())); // 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); // 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) { // dao.deleteSetlInfo(p.getPatNo(), p.getTimes()); // dao.deleteSetlDetail(p.getPatNo(), p.getTimes()); // dao.updateRvkSetlMsgid(p.getPatNo(), p.getTimes(), input.getString("msgid")); // return ResultVoUtil.success("门诊结算撤销成功。"); // } // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE)); } }