123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
- package thyyxxk.simzfeeoprnsystm.service;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import org.springframework.beans.factory.annotation.Value;
- import thyyxxk.simzfeeoprnsystm.dao.SiLogDao;
- import thyyxxk.simzfeeoprnsystm.dao.SiMzDao;
- import thyyxxk.simzfeeoprnsystm.dao.SiSetldetailDao;
- import thyyxxk.simzfeeoprnsystm.dao.SiSetlinfoDao;
- import thyyxxk.simzfeeoprnsystm.dicts.*;
- import thyyxxk.simzfeeoprnsystm.external.WebHisSrvc;
- import thyyxxk.simzfeeoprnsystm.pojo.*;
- import thyyxxk.simzfeeoprnsystm.pojo.ResultVo;
- import thyyxxk.simzfeeoprnsystm.pojo.SiPatInfo;
- import thyyxxk.simzfeeoprnsystm.pojo.onlinepayment.EcTokenParams;
- import thyyxxk.simzfeeoprnsystm.pojo.registration.InsuInfo;
- import thyyxxk.simzfeeoprnsystm.pojo.registration.PsnBaseInfo;
- 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;
- import java.util.Map;
- @Slf4j
- @Service
- public class SiMzFeeService {
- private final SiMzDao mzDao;
- private final SiSetlinfoDao setlinfoDao;
- private final SiSetldetailDao setldetailDao;
- private final ExecService exec;
- private final WebHisSrvc webHisSrvc;
- 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;
- @Autowired
- public SiMzFeeService(SiMzDao mzDao, SiSetlinfoDao setlinfoDao,
- SiSetldetailDao setldetailDao, ExecService exec, WebHisSrvc webHisSrvc, SiLogDao logDao) {
- this.mzDao = mzDao;
- this.setlinfoDao = setlinfoDao;
- this.setldetailDao = setldetailDao;
- this.exec = exec;
- this.webHisSrvc = webHisSrvc;
- this.logDao = logDao;
- }
- public ResultVo<String> outpatientRegistration(MzPatientInfo p) {
- Regstrtn regstrtn = mzDao.selectRegstrtn(p.getPatNo(), p.getTimes());
- if (null == regstrtn) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "mz_visit_table患者信息为空,请联系医生重开处方。");
- }
- ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType());
- if (readCardBizType != ReadCardBizType.REGISTRATION && !p.getInsuplcAdmdvs().startsWith("43")) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "省外异地的患者请读社保卡或医保电子凭证登记!");
- }
- if (readCardBizType == ReadCardBizType.REGISTRATION) {
- MdtrtCertType mdtrtCertType = MdtrtCertType.getByLabel(p.getMdtrtCertType());
- regstrtn.setMdtrtCertType(mdtrtCertType.getCode());
- if (mdtrtCertType == MdtrtCertType.SOCIAL_SECURITY_CARD) {
- String[] out = p.getReadCardResult().split("\\|");
- if (!p.getName().trim().equals(out[4].trim())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "社保卡姓名与HIS姓名不一致,请确认是否人证相符。");
- }
- regstrtn.setMdtrtCertNo(out[2]);
- regstrtn.setCardSn(out[3]);
- } else if (mdtrtCertType == MdtrtCertType.MEDICAL_INSURANCE_ELECTRONIC_VOUCHER) {
- JSONObject qrinfo = JSONObject.parseObject(p.getReadCardResult());
- if (!p.getName().trim().equals(qrinfo.getString("userName").trim())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证姓名与HIS姓名不一致,请确认是否人证相符。");
- }
- if (!p.getSocialNo().trim().equals(qrinfo.getString("idNo").trim())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证身份证与HIS身份证不一致,请确认是否人证相符。");
- }
- 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);
- if (null == result) {
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- Integer infcode = result.getInteger(RESULT_CODE);
- logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, regstrtn.getPsnNo()));
- if (null == infcode) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
- }
- if (infcode == 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);
- }
- Integer infcode = result.getInteger(RESULT_CODE);
- logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, siPatInfo.getPsnNo()));
- if (null == infcode) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
- }
- if (infcode == 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 indise, 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(indise.getOpspDiseCode())) {
- diseinfo = new ArrayList<>();
- Diseinfo diag = mzDao.selectDiseinfo(siPatInfo.getPatNo(), siPatInfo.getTimes());
- diag.setDiagCode(indise.getOpspDiseCode());
- diag.setDiagName(indise.getOpspDiseName());
- diseinfo.add(diag);
- mzDao.updatePatDiseinfo(siPatInfo.getPatNo(), siPatInfo.getTimes(), diag.getDiagCode(), diag.getDiagName());
- } else {
- if (siPatInfo.getFromDirectReg()) {
- String icdCodeNew = mzDao.selectIcdCodeNew(siPatInfo.getPatNo(), siPatInfo.getTimes());
- if (StringUtil.isBlank(icdCodeNew)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者的门诊诊断为空,请联系医生填写。");
- }
- diseinfo = new ArrayList<>();
- Diseinfo base = mzDao.selectDiseinfo(siPatInfo.getPatNo(), siPatInfo.getTimes());
- String[] icds = icdCodeNew.split(",");
- for (int i = 0; i < icds.length; i++) {
- String icd = icds[i];
- String icdTextNew = mzDao.selectIcdTextNew(icd);
- Diseinfo diag = new Diseinfo();
- 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());
- diseinfo.add(diag);
- }
- indise.setOpspDiseCode(diseinfo.get(0).getDiagCode());
- indise.setOpspDiseName(diseinfo.get(0).getDiagName());
- } else {
- diseinfo = mzDao.selectMzDiags(siPatInfo.getPatNo(), siPatInfo.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", indise.getOpspDiseName());
- mdtrtinfo.put("dise_codg", indise.getOpspDiseCode());
- mdtrtinfo.put("dise_name", indise.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);
- 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) {
- return ResultVoUtil.success("门诊就诊信息上传成功。");
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- 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 +
- "】未找到此患者的医保挂号信息,请核实。");
- }
- if (!p.getFromDirectReg()) {
- 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);
- }
- Integer infcode = result.getInteger(RESULT_CODE);
- logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, siPatInfo.getPsnNo()));
- if (null == infcode) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
- }
- 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);
- 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());
- 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);
- }
- Integer infcode = result.getInteger(RESULT_CODE);
- logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, siPatInfo.getPsnNo()));
- if (null == infcode) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
- }
- if (infcode == 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());
- ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType());
- if (readCardBizType == ReadCardBizType.SETTLEMENT) {
- MdtrtCertType mdtrtCertType = MdtrtCertType.getByLabel(p.getMdtrtCertType());
- mzPreSetlmt.setMdtrtCertType(mdtrtCertType.getCode());
- if (mdtrtCertType == MdtrtCertType.SOCIAL_SECURITY_CARD) {
- String[] out = p.getReadCardResult().split("\\|");
- if (!p.getName().trim().equals(out[4].trim())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "社保卡姓名与HIS姓名不一致,请确认是否人证相符。");
- }
- mzPreSetlmt.setMdtrtCertNo(out[2]);
- mzPreSetlmt.setCardSn(out[3]);
- } else if (mdtrtCertType == MdtrtCertType.MEDICAL_INSURANCE_ELECTRONIC_VOUCHER) {
- JSONObject qrinfo = JSONObject.parseObject(p.getReadCardResult());
- if (!p.getName().trim().equals(qrinfo.getString("userName").trim())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证姓名与HIS姓名不一致,请确认是否人证相符。");
- }
- if (!p.getSocialNo().trim().equals(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());
- 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);
- }
- Integer infcode = result.getInteger(RESULT_CODE);
- logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, mzPreSetlmt.getPsnNo()));
- if (null == infcode) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
- }
- if (infcode == 0) {
- 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(), 0);
- 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()));
- if (sisetl.getRevoked() == 1) {
- fundDetail.reverseAll();
- }
- 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());
- ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType());
- if (readCardBizType == ReadCardBizType.SETTLEMENT) {
- MdtrtCertType mdtrtCertType = MdtrtCertType.getByLabel(p.getMdtrtCertType());
- setlmt.setMdtrtCertType(mdtrtCertType.getCode());
- if (mdtrtCertType == MdtrtCertType.SOCIAL_SECURITY_CARD) {
- String[] out = p.getReadCardResult().split("\\|");
- if (!p.getName().trim().equals(out[4].trim())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "社保卡姓名与HIS姓名不一致,请确认是否人证相符。");
- }
- setlmt.setMdtrtCertNo(out[2]);
- setlmt.setCardSn(out[3]);
- } else if (mdtrtCertType == MdtrtCertType.MEDICAL_INSURANCE_ELECTRONIC_VOUCHER) {
- JSONObject qrinfo = JSONObject.parseObject(p.getReadCardResult());
- if (!p.getName().trim().equals(qrinfo.getString("userName").trim())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "电子医保凭证姓名与HIS姓名不一致,请确认是否人证相符。");
- }
- if (!p.getSocialNo().trim().equals(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());
- setlmt.setAcctUsedFlag(p.getAcctUsedFlag());
- 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, "与医保中心的连接出现网络异常!");
- }
- Integer infcode = result.getInteger(RESULT_CODE);
- logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, setlmt.getPsnNo()));
- if (null == infcode) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
- }
- if (infcode == 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());
- setlEntity.setInsuplcAdmdvs(setlmt.getInsuplcAdmdvs());
- setlEntity.setBegntime(mzDao.selectBegntime(p.getPatNo(), p.getTimes()));
- setlEntity.setEndtime(setlEntity.getSetlTime());
- setlEntity.setMzSaved(p.getSaved());
- 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<FundDetail> revokeOutpatientSettlement(MzPatientInfo p) {
- if (null == p.getTimes()) {
- p.setTimes(mzDao.selectMaxTimes(p.getPatNo()));
- }
- SiSetlinfo setlinfo = mzDao.selectSettledInfo(p.getPatNo(), p.getTimes(), 0);
- if (null == setlinfo) {
- setlinfo = mzDao.selectSettledInfo(p.getPatNo(), p.getTimes(), 1);
- return getFundDetailResultVo(setlinfo);
- }
- 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);
- }
- Integer infcode = result.getInteger(RESULT_CODE);
- logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, setlinfo.getPsnNo()));
- if (null == infcode) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
- }
- if (infcode == 0) {
- mzDao.deleteSetlInfo(p.getPatNo(), p.getTimes());
- mzDao.deleteSetlDetail(p.getPatNo(), p.getTimes());
- mzDao.updateRvkSetlMsgid(p.getPatNo(), p.getTimes(), input.getString("msgid"));
- return getFundDetailResultVo(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);
- Integer infcode = result.getInteger(RESULT_CODE);
- logDao.insert(new SiLog(input, result, setlinfo.getPatNo(), setlinfo.getTimes(), infcode, setlinfo.getPsnNo()));
- if (null != infcode && infcode == 0) {
- mzDao.deleteSetlInfo(setlinfo.getPatNo(), setlinfo.getTimes());
- mzDao.deleteSetlDetail(setlinfo.getPatNo(), setlinfo.getTimes());
- mzDao.updateRvkSetlMsgid(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 ResultVo<FundDetail> directRegistration(EcTokenParams ecpms) {
- // 查询参保信息
- MzPatientInfo mzptnt = new MzPatientInfo();
- mzptnt.setStaffId(ecpms.getStaffId());
- mzptnt.setPatNo(ecpms.getPatientId());
- mzptnt.setTimes(ecpms.getTimes());
- mzptnt.setAcctUsedFlag(String.valueOf(ecpms.getAcctUsedFlag()));
- int hasSiPatInfo = mzDao.updateMzTimes(mzptnt.getPatNo(), mzptnt.getTimes());
- if (hasSiPatInfo == 0) {
- Map<String, Object> map = webHisSrvc.queryInsuinfo(webHisUrl, ecpms);
- if (null == map) {
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if ((int) map.get("code") == -1) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, map.get("msg").toString());
- }
- }
- // 查询到职工参保信息后挂号登记(执行到这一步,siPatInfo必不为空,所以无需作非空判断)
- 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(ecpms.getEcIndexNo())) {
- mzptnt.setMdtrtCertType(MdtrtCertType.MEDICAL_INSURANCE_ELECTRONIC_VOUCHER.getLabel());
- mzptnt.setReadCardBizType(ReadCardBizType.REGISTRATION.getCode());
- mzptnt.setReadCardResult(JSONObject.toJSONString(ecpms));
- }
- ResultVo<String> regres = outpatientRegistration(mzptnt);
- if (null == regres) {
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- 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();
- ResultVo<String> upldMdtrtRes = uploadOutpatientInfo(spcChrDiseAcct, siPatInfo, ecpms.getStaffId());
- if (null == upldMdtrtRes) {
- revokeOutpatientRegistration(mzptnt);
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if (upldMdtrtRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
- revokeOutpatientRegistration(mzptnt);
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldMdtrtRes.getMessage());
- }
- // 上传就诊信息成功后生成门诊医保费用
- ResultVo<List<Map<String, Object>>> getMzRcptRes = webHisSrvc.getMzReceipts(webHisUrl, mzptnt);
- if (null == getMzRcptRes) {
- revokeOutpatientRegistration(mzptnt);
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if (getMzRcptRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
- revokeOutpatientRegistration(mzptnt);
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, getMzRcptRes.getMessage());
- }
- List<MzReceipt> mzReceipts = new ArrayList<>();
- for (Map<String, Object> item : getMzRcptRes.getData()) {
- Map<Integer, List<MzReceipt>> orderReceiptsMap = FilterUtil.cast(item.get("mzReceipts"));
- for (Map.Entry<Integer, List<MzReceipt>> entry : orderReceiptsMap.entrySet()) {
- mzReceipts.addAll(entry.getValue());
- }
- }
- ResultVo<String> insertSiMzFeeRes = webHisSrvc.insertSiMzFees(webHisUrl, mzReceipts);
- if (null == insertSiMzFeeRes) {
- revokeOutpatientRegistration(mzptnt);
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if (insertSiMzFeeRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
- revokeOutpatientRegistration(mzptnt);
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, insertSiMzFeeRes.getMessage());
- }
- // 生成费用成功后上传到医保
- spcChrDiseAcct.setStaffId(ecpms.getStaffId());
- spcChrDiseAcct.setPatNo(mzptnt.getPatNo());
- spcChrDiseAcct.setTimes(mzptnt.getTimes());
- spcChrDiseAcct.setFromDirectReg(true);
- ResultVo<SiPatInfo> upldFeeRes = uploadOutpatientFeeDetails(spcChrDiseAcct);
- if (null == upldFeeRes) {
- revokeOutpatientRegistration(mzptnt);
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if (upldFeeRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
- revokeOutpatientRegistration(mzptnt);
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldFeeRes.getMessage());
- }
- // 上传完成之后结算并返回结算结果
- return outpatientSettlement(mzptnt);
- }
- private InsuInfo getEmployeeInsuInfo(List<InsuInfo> list) {
- for (InsuInfo info : list) {
- if (info.getInsutype().equals("310")) {
- return info;
- }
- }
- return null;
- }
- // public ResultVo<String> payOnline(EcTokenParams params) {
- //
- //
- // }
- // private ResultVo<EcTokenUpldRslt> ecTokenUploadFees(EcTokenParams params) {
- // EcTokenUpldDetl upldDetl = mzDao.selectEcTokenUpldDetl(params.getPatientId(), params.getTimes());
- // if (null == upldDetl || StringUtil.isBlank(upldDetl.getMdtrtId())) {
- // return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者有没有效的医保登记信息,请核实。");
- // }
- // upldDetl.setIdNo(params.getIdNo());
- // upldDetl.setUserName(params.getUserName());
- // upldDetl.setIdType(params.getIdType());
- // upldDetl.setEcToken(params.getEcToken());
- // upldDetl.setInsuCode(params.getInsuOrg());
- // upldDetl.setIptOtpNo(params.getPatientId());
- //
- // upldDetl.setDiseinfoList(null);
- // upldDetl.setFeedetailList(null);
- //
- // JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.ECTOKEN_UPLOAD_FEE_DETAIL,
- // params.getInsuOrg(), params.getStaffId());
- // }
- }
|