|
|
@@ -0,0 +1,394 @@
|
|
|
+package thyyxxk.simzfeeoprnsystm.service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import thyyxxk.simzfeeoprnsystm.dao.SiMzDao;
|
|
|
+import thyyxxk.simzfeeoprnsystm.dao.SiSetldetailDao;
|
|
|
+import thyyxxk.simzfeeoprnsystm.dao.SiSetlinfoDao;
|
|
|
+import thyyxxk.simzfeeoprnsystm.dicts.*;
|
|
|
+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.RoundingMode;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class SiMzFeeService {
|
|
|
+ private final SiMzDao mzDao;
|
|
|
+ private final SiSetlinfoDao setlinfoDao;
|
|
|
+ private final SiSetldetailDao setldetailDao;
|
|
|
+ private final ExecService exec;
|
|
|
+ private static final String RESULT_CODE = "infcode";
|
|
|
+ private static final String ERROR_MESSAGE = "err_msg";
|
|
|
+ private static final String OUTPUT = "output";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public SiMzFeeService(SiMzDao mzDao, SiSetlinfoDao setlinfoDao, SiSetldetailDao setldetailDao, ExecService exec) {
|
|
|
+ this.mzDao = mzDao;
|
|
|
+ this.setlinfoDao = setlinfoDao;
|
|
|
+ this.setldetailDao = setldetailDao;
|
|
|
+ this.exec = exec;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<String> outpatientRegistration(MzPatientInfo p) {
|
|
|
+ JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_REGISTRATION,
|
|
|
+ p.getInsuplcAdmdvs(), p.getStaffId());
|
|
|
+ Regstrtn regstrtn = mzDao.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结果:{}", 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 output = result.getJSONObject(OUTPUT).getJSONObject("data");
|
|
|
+ p.setMdtrtId(output.getString("mdtrt_id"));
|
|
|
+ p.setVisitDate(regstrtn.getBegntime());
|
|
|
+ mzDao.afterRegistrtn(p);
|
|
|
+ return ResultVoUtil.success("挂号成功。");
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<String> 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, "此患者没有有效的医保挂号信息。");
|
|
|
+ }
|
|
|
+ JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_REGISTRATION,
|
|
|
+ siPatInfo.getInsuplcAdmdvs(), p.getStaffId());
|
|
|
+ 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结果:{}", 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) {
|
|
|
+ mzDao.clearMdtrtIdForMz(p.getPatNo(), p.getTimes(), null);
|
|
|
+ return ResultVoUtil.success("取消门诊挂号成功。");
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResultVo<String> uploadOutpatientInfo(SpcChrDiseAcct p, SiPatInfo siPatInfo, String staffId) {
|
|
|
+ JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_OUTPATIENT_INFO,
|
|
|
+ siPatInfo.getInsuplcAdmdvs(), staffId);
|
|
|
+ JSONObject mdtrtinfo = new JSONObject();
|
|
|
+ List<Diseinfo> diseinfo;
|
|
|
+ if (StringUtil.notBlank(p.getOpspDiseCode())) {
|
|
|
+ diseinfo = new ArrayList<>();
|
|
|
+ Diseinfo diag = mzDao.selectDiseinfo(p.getPatNo(), p.getTimes());
|
|
|
+ diag.setDiagCode(p.getOpspDiseCode());
|
|
|
+ diag.setDiagName(p.getOpspDiseName());
|
|
|
+ diseinfo.add(diag);
|
|
|
+ mzDao.updatePatDiseinfo(siPatInfo.getPatNo(), siPatInfo.getTimes(), diag.getDiagCode(), diag.getDiagName());
|
|
|
+ } else {
|
|
|
+ diseinfo = mzDao.selectMzDiags(p.getPatNo(), p.getTimes());
|
|
|
+ if (null == diseinfo || diseinfo.isEmpty()) {
|
|
|
+ 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", p.getOpspDiseName());
|
|
|
+ mdtrtinfo.put("dise_codg", p.getOpspDiseCode());
|
|
|
+ mdtrtinfo.put("dise_name", p.getOpspDiseName());
|
|
|
+ mdtrtinfo.put("birctrl_type", "");
|
|
|
+ mdtrtinfo.put("birctrl_matn_date", "");
|
|
|
+
|
|
|
+ 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结果:{}", staffId, input, result);
|
|
|
+ return SiUtil.makeReturnWithoutOutput(result, "门诊就诊信息上传成功。");
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<SiPatInfo> 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 +
|
|
|
+ "】未找到此患者的医保挂号信息,请核实。");
|
|
|
+ }
|
|
|
+ ResultVo<String> uplRes = uploadOutpatientInfo(p, siPatInfo, p.getStaffId());
|
|
|
+ if (null != uplRes && uplRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, uplRes.getMessage());
|
|
|
+ }
|
|
|
+ List<FeeDetail> feeDetails = mzDao.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());
|
|
|
+ if (siPatInfo.getMedType().equals("51")) {
|
|
|
+ item.setMatnFeeFlag("1");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_OUTPATIENT_FEE_DETAILS,
|
|
|
+ siPatInfo.getInsuplcAdmdvs(), p.getStaffId());
|
|
|
+ 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结果:{}", 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) {
|
|
|
+ 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);
|
|
|
+ return ResultVoUtil.success(siPatInfo);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<String> revokeOutpatientFeeDetails(MzPatientInfo p) {
|
|
|
+ if (null == p.getTimes()) {
|
|
|
+ p.setTimes(mzDao.selectMaxTimes(p.getPatNo()));
|
|
|
+ }
|
|
|
+ SiPatInfo siPatInfo = mzDao.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(), 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);
|
|
|
+ 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) {
|
|
|
+ mzDao.afterRevokeFees(p.getPatNo(), p.getTimes());
|
|
|
+ return ResultVoUtil.success("门诊费用明细信息撤销成功。");
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<FundDetail> outpatientPreSettlement(MzPatientInfo p) {
|
|
|
+ if (null == p.getTimes()) {
|
|
|
+ p.setTimes(mzDao.selectMaxTimes(p.getPatNo()));
|
|
|
+ }
|
|
|
+ ResultVo<FundDetail> fundDetail1 = getFundDetailResultVo(p);
|
|
|
+ if (fundDetail1 != null) return fundDetail1;
|
|
|
+ MzPreSetlmt mzPreSetlmt = mzDao.selectPreSetlmt(p.getPatNo(), p.getTimes());
|
|
|
+ mzPreSetlmt.setMedfeeSumamt(mzPreSetlmt.getMedfeeSumamt().setScale(2, RoundingMode.HALF_UP));
|
|
|
+ JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_PRE_SETTLEMENT,
|
|
|
+ mzPreSetlmt.getInsuplcAdmdvs(), p.getStaffId());
|
|
|
+ mzPreSetlmt.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
|
|
|
+ mzPreSetlmt.setPsnSetlway(PsnSetlWay.SETTLE_BY_ITEMS.getCode());
|
|
|
+ mzPreSetlmt.setAcctUsedFlag(YesOrNo.NO.getCodeStr());
|
|
|
+ mzPreSetlmt.setChrgBchno(p.getPatNo() + "_" + p.getTimes());
|
|
|
+ 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);
|
|
|
+ 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 = mzDao.selectMtPartCount(p.getPatNo(), p.getTimes());
|
|
|
+ if (mtPartCount == 0) {
|
|
|
+ MtPartInfo mtinfo = new MtPartInfo();
|
|
|
+ mtinfo.setPatientId(p.getPatNo());
|
|
|
+ mtinfo.setTimes(p.getTimes());
|
|
|
+ mtinfo.setHicNo(mzPreSetlmt.getPsnNo());
|
|
|
+ mtinfo.setBizType(mzPreSetlmt.getMedType());
|
|
|
+ mtinfo.setIcdCode("");
|
|
|
+ mtinfo.setIcdName("");
|
|
|
+ mtinfo.setMzSerialNo(mzPreSetlmt.getMdtrtId());
|
|
|
+ mzDao.insertMtPartInfo(mtinfo);
|
|
|
+ }
|
|
|
+ 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<FundDetail> getFundDetailResultVo(MzPatientInfo p) {
|
|
|
+ SiSetlinfo sisetl = mzDao.selectSettledInfo(p.getPatNo(), p.getTimes());
|
|
|
+ if (null != sisetl && null != sisetl.getSetlId()) {
|
|
|
+ return getFundDetailResultVo(sisetl);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResultVo<FundDetail> getFundDetailResultVo(SiSetlinfo sisetl) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<FundDetail> outpatientSettlement(MzPatientInfo p) {
|
|
|
+ ResultVo<FundDetail> fundDetail1 = getFundDetailResultVo(p);
|
|
|
+ if (fundDetail1 != null) return fundDetail1;
|
|
|
+ Setlmt setlmt = mzDao.selectSetlmt(p.getPatNo(), p.getTimes());
|
|
|
+ JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.OUTPATIENT_SETTLEMENT,
|
|
|
+ setlmt.getInsuplcAdmdvs(), p.getStaffId());
|
|
|
+ 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.getInstance().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);
|
|
|
+ }
|
|
|
+ return getFundDetailResultVo(setlEntity);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<String> revokeOutpatientSettlement(MzPatientInfo p) {
|
|
|
+ if (null == p.getTimes()) {
|
|
|
+ p.setTimes(mzDao.selectMaxTimes(p.getPatNo()));
|
|
|
+ }
|
|
|
+ QueryWrapper<SiSetlinfo> 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,
|
|
|
+ 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);
|
|
|
+ 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) {
|
|
|
+ mzDao.deleteSetlInfo(p.getPatNo(), p.getTimes());
|
|
|
+ mzDao.deleteSetlDetail(p.getPatNo(), p.getTimes());
|
|
|
+ mzDao.updateRvkSetlMsgid(p.getPatNo(), p.getTimes(), input.getString("msgid"));
|
|
|
+ return ResultVoUtil.success("门诊结算撤销成功。");
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
|
+ }
|
|
|
+}
|