123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- package thyyxxk.webserver.service.medicalinsurance;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import thyyxxk.webserver.config.exception.ExceptionEnum;
- import thyyxxk.webserver.constants.sidicts.*;
- import thyyxxk.webserver.constants.YesOrNo;
- import thyyxxk.webserver.dao.his.medicalinsurance.*;
- import thyyxxk.webserver.entity.ResultVo;
- import thyyxxk.webserver.entity.dictionary.PureCodeName;
- import thyyxxk.webserver.entity.medicalinsurance.inpatient.*;
- import thyyxxk.webserver.entity.medicalinsurance.query.SiPatInfo;
- import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetldetail;
- import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetlinfo;
- import thyyxxk.webserver.entity.yibao.dismiss.YbSettleFee;
- import thyyxxk.webserver.entity.yibao.patient.Overview;
- import thyyxxk.webserver.service.externalhttp.SiZySrvc;
- import thyyxxk.webserver.service.yibao.DismissService;
- import thyyxxk.webserver.utils.*;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.List;
- /**
- * @description: 住院医保交易
- * @author: DingJie
- * @create: 2021-05-14 16:28:16
- * <p>
- * 联通云:
- * http://10.136.68.156:20005/isp-api/powercsb/1101
- * api_access_key=FqSRO1tkKe4PTsZS8mJkN3zs12U6Zkkwez6Qhy
- * api_secreKey=SKklCVOoGDag5ys4zkSE2qHYo8iU4FsG7DNyJQYI
- * <p>
- * 省政府二院:
- * http://10.90.0.11:8081/isp-api/powercsb/1101
- * api_access_key=sJAXxQd10aQLWZFAMH3PT9pHCGGqXPzz4Hv4Ei
- * api_secreKey=SK1BtAloxIaQUgv9m0gjqrQJ0NJikkPPUTlRGOzp
- **/
- @Slf4j
- @Service
- public class SiZyService {
- private static final String RESULT_CODE = "infcode";
- private static final String ERROR_MESSAGE = "err_msg";
- private static final String OUTPUT = "output";
- private final SiZyDao dao;
- private final SiQueryDao qrydao;
- private final SiSetlinfoDao setlinfodao;
- private final SiSetldetailDao setldetldao;
- private final SiChargeTempDao chrgtmpdao;
- private final ExecService exec;
- private final DismissService dismissService;
- private final SiZySrvc zySrvc;
- @Autowired
- public SiZyService(SiZyDao dao, SiQueryDao qrydao, SiSetlinfoDao setlinfoDao,
- SiSetldetailDao setldetldao, SiChargeTempDao chrgtmpdao, ExecService exec,
- DismissService dismissService, SiZySrvc zySrvc) {
- this.dao = dao;
- this.qrydao = qrydao;
- this.setlinfodao = setlinfoDao;
- this.setldetldao = setldetldao;
- this.chrgtmpdao = chrgtmpdao;
- this.exec = exec;
- this.dismissService = dismissService;
- this.zySrvc = zySrvc;
- }
- public ResultVo<String> admissRegister(ZyPatientInfo p) {
- if (p.getInsuplcAdmdvs().equals("430182")) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "宁乡患者无法在我院办理住院业务。");
- }
- AdmMdtrtinfo admMdtrtinfo = dao.selectAdmMdtrtinfo(p.getInpatientNo(), p.getLedgerSn());
- if (null == admMdtrtinfo) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的参保信息!");
- }
- if (StringUtil.isBlank(admMdtrtinfo.getChfpdrName())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "管床医生不能为空!");
- }
- List<AdmDiseinfo> admDiseinfos = dao.selectAdmDiags(p.getInpatientNo(), p.getAdmissTimes());
- if (null == admDiseinfos || admDiseinfos.isEmpty()) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请填写医保入院诊断!");
- }
- admMdtrtinfo.setInsutype(p.getInsutype());
- admMdtrtinfo.setAdmDiagDscr(admDiseinfos.get(0).getDiagName());
- admMdtrtinfo.setDscgMaindiagCode(admDiseinfos.get(0).getDiagCode());
- admMdtrtinfo.setDscgMaindiagName(admDiseinfos.get(0).getDiagName());
- admMdtrtinfo.setDiseCodg(admDiseinfos.get(0).getDiagCode());
- admMdtrtinfo.setDiseName(admDiseinfos.get(0).getDiagName());
- admMdtrtinfo.setMatnType(p.getMatnType());
- admMdtrtinfo.setLatechbFlag(p.getLatechbFlag());
- admMdtrtinfo.setPretFlag(p.getPretFlag());
- JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.ADMISSION_REGISTRATION, p.getInsuplcAdmdvs());
- String ref = JSONObject.toJSONStringWithDateFormat(admMdtrtinfo, "yyyy-MM-dd HH:mm:ss");
- input.getJSONObject("input").put("mdtrtinfo", JSONObject.parseObject(ref));
- String diseRef = JSONArray.toJSONStringWithDateFormat(admDiseinfos, "yyyy-MM-dd HH:mm:ss");
- input.getJSONObject("input").put("diseinfo", JSONArray.parse(diseRef));
- JSONObject result = exec.executeTrade(input, SiFunction.ADMISSION_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);
- String mdtrtId = output.getJSONObject("result").getString("mdtrt_id");
- p.setMdtrtId(mdtrtId);
- p.setAdmRegMsgid(input.getString("msgid"));
- dao.afterAdmissRegister(p);
- return ResultVoUtil.success("入院登记成功,就诊号为:" + mdtrtId);
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- public ResultVo<String> modifyAdmissionInfo(ZyPatientInfo p) {
- PureCodeName codeName = dao.selectMdtrtId(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- if (null == codeName || StringUtil.isBlank(codeName.getName())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者医保不在院!");
- }
- List<AdmDiseinfo> admDiseinfos = dao.selectAdmDiags(p.getInpatientNo(), p.getAdmissTimes());
- if (null == admDiseinfos || admDiseinfos.isEmpty()) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请填写医保入院诊断!");
- }
- admDiseinfos.forEach(item -> item.setMdtrtId(codeName.getName()));
- JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.MODIFY_ADMISSION_INFO, codeName.getCode());
- JSONObject adminfo = new JSONObject();
- adminfo.put("mdtrt_id", codeName.getName());
- adminfo.put("psn_no", p.getPsnNo());
- adminfo.put("begntime", DateUtil.formatDatetime(p.getAdmissDate()));
- adminfo.put("mdtrt_cert_type", MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
- adminfo.put("med_type", p.getMedType());
- adminfo.put("ipt_otp_no", p.getInpatientNo());
- adminfo.put("atddr_no", p.getReferPhysician());
- adminfo.put("chfpdr_name", p.getReferPhysicianName());
- adminfo.put("adm_diag_dscr", admDiseinfos.get(0).getDiagCode());
- adminfo.put("adm_dept_codg", p.getSmallDept());
- adminfo.put("adm_dept_name", p.getSmallDeptName());
- adminfo.put("adm_bed", p.getBedNo());
- adminfo.put("dscg_maindiag_code", admDiseinfos.get(0).getDiagCode());
- adminfo.put("dscg_maindiag_name", admDiseinfos.get(0).getDiagName());
- input.getJSONObject("input").put("adminfo", adminfo);
- String diseRef = JSONArray.toJSONStringWithDateFormat(admDiseinfos, "yyyy-MM-dd HH:mm:ss");
- input.getJSONObject("input").put("diseinfo", JSONArray.parse(diseRef));
- JSONObject result = exec.executeTrade(input, SiFunction.MODIFY_ADMISSION_INFO);
- log.info("【操作员:{}】,入院信息变更:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
- return SiUtil.makeReturnWithoutOutput(result, "变更住院信息成功。");
- }
- public ResultVo<String> revokeAdmission(ZyPatientInfo p) {
- SiPatInfo siPatInfo = qrydao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
- }
- revokeUploadFees(p);
- JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_ADMISSION, siPatInfo.getInsuplcAdmdvs());
- JSONObject data = new JSONObject();
- data.put("mdtrt_id", siPatInfo.getMdtrtId());
- data.put("psn_no", siPatInfo.getPsnNo());
- input.getJSONObject("input").put("data", data);
- JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_ADMISSION);
- 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) {
- qrydao.clearMdtrtIdForZy(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn(), null);
- return ResultVoUtil.success("取消入院登记成功。");
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- public ResultVo<String> uploadFeeDetail(Overview o) {
- o.setStaffId(TokenUtil.getTokenUserId());
- return zySrvc.uploadFeeDetail(o);
- }
- public ResultVo<String> hospitalizationPreSettlement(ZyPatientInfo p) {
- PreSetlmt preSetlmt = dao.selectPreSetlmt(p.getInpatientNo(), p.getAdmissTimes(),
- p.getLedgerSn(), DateUtil.getTodayEndTime());
- if (null == preSetlmt || StringUtil.isBlank(preSetlmt.getMdtrtId())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
- }
- preSetlmt.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
- preSetlmt.setPsnSetlway(p.getDbg() ? PsnSetlWay.SETTLE_BY_QUOTA.getCode() : PsnSetlWay.SETTLE_BY_ITEMS.getCode());
- preSetlmt.setAcctUsedFlag(YesOrNo.NO.getCodeStr());
- preSetlmt.setMidSetlFlag(YesOrNo.NO.getCodeStr());
- JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.HOSPITALIZATION_PRE_SETTLEMENT, preSetlmt.getInsuplcAdmdvs());
- String ref = JSONObject.toJSONString(preSetlmt);
- input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
- JSONObject result = exec.executeTrade(input, SiFunction.HOSPITALIZATION_PRE_SETTLEMENT);
- log.info("预结算:\n参数:{},\n结果:{}", 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");
- String fundPay = setlinfo.getString("fund_pay_sumamt");
- if (DecimalUtil.compare(fundPay, p.getTotalCharge()) == 1) {
- fundPay = p.getTotalCharge();
- }
- dao.updateFundPay(fundPay, p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- String message = "患者【" + p.getName() + "】院内总费用与医保中心总费用一致,医保报销金额为:¥ " + fundPay + "。";
- return ResultVoUtil.success(message);
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- public ResultVo<String> revokeUploadFees(ZyPatientInfo p) {
- SiPatInfo siPatInfo = qrydao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
- }
- JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_HOSPITALIZATION_FEE_DETAILS, siPatInfo.getInsuplcAdmdvs());
- JSONArray data = new JSONArray();
- if (null == p.getDetailSns() || p.getDetailSns().isEmpty()) {
- JSONObject item = new JSONObject();
- item.put("feedetl_sn", "0000");
- item.put("mdtrt_id", siPatInfo.getMdtrtId());
- item.put("psn_no", siPatInfo.getPsnNo());
- data.add(item);
- } else {
- p.getDetailSns().forEach(detailSn -> {
- JSONObject item = new JSONObject();
- item.put("feedetl_sn", detailSn);
- item.put("mdtrt_id", siPatInfo.getMdtrtId());
- item.put("psn_no", siPatInfo.getPsnNo());
- data.add(item);
- });
- }
- input.getJSONObject("input").put("data", data);
- JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_HOSPITALIZATION_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) {
- QueryWrapper<SiChargeTemp> wrapper = new QueryWrapper<>();
- wrapper.eq("pat_no", p.getInpatientNo());
- wrapper.eq("times", p.getAdmissTimes());
- wrapper.eq("ledger_sn", p.getLedgerSn());
- if (null == p.getDetailSns() || p.getDetailSns().isEmpty()) {
- dao.revokeAllUploadFee(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- chrgtmpdao.delete(wrapper);
- } else {
- wrapper.in("detail_sn", p.getDetailSns());
- chrgtmpdao.delete(wrapper);
- dao.revokePartUploadFee(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), p.getDetailSns());
- }
- return ResultVoUtil.success("撤销费用上传成功。");
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- public ResultVo<String> dischargeProcessing(ZyPatientInfo p) {
- List<Date> dscgDates = dao.selectDscgDate(p.getInpatientNo(), p.getAdmissTimes());
- if (null == dscgDates || dscgDates.isEmpty()) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有出院医嘱,请检查!");
- }
- if (dscgDates.size() > 1) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者的出院医嘱不止1条,请检查!");
- }
- if (null == p.getLedgerSn()) {
- p.setLedgerSn(dao.selectMaxLedgerSn(p.getInpatientNo(), p.getAdmissTimes()));
- }
- Dscginfo dscginfo = dao.selectDscginfo(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- if (null == dscginfo || StringUtil.isBlank(dscginfo.getMdtrtId())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
- }
- List<SetlDiseinfo> setlDises = dao.selectSetlDises(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- if (null == setlDises || setlDises.isEmpty()) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者医保出院诊断不能为空,请联系医生在病案首页填写。");
- }
- if (null == p.getStaffId()) {
- p.setStaffId(TokenUtil.getTokenUserId());
- }
- dscginfo.setDiseCodg(setlDises.get(0).getDiagCode());
- dscginfo.setDiseName(setlDises.get(0).getDiagName());
- dscginfo.setDscgWay(DscgWay.ORDER_TO_LEAVE_HOSPITAL.getCode());
- String ref = JSONObject.toJSONString(dscginfo);
- JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.DISCHARGE_PROCESSING,
- dao.selectAdmdvs(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn()));
- input.getJSONObject("input").put("dscginfo", JSONObject.parseObject(ref));
- String diseRef = JSONArray.toJSONString(setlDises);
- input.getJSONObject("input").put("diseinfo", JSONArray.parse(diseRef));
- JSONObject result = exec.executeTrade(input, SiFunction.DISCHARGE_PROCESSING);
- 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) {
- return inpatientSettlement(p);
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- public ResultVo<String> revokeDischarge(ZyPatientInfo p) {
- SiPatInfo siPatInfo = qrydao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- if (null == siPatInfo) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保出院信息,无法撤销出院!");
- }
- p.setMdtrtId(siPatInfo.getMdtrtId());
- JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_DISCHARGE, siPatInfo.getInsuplcAdmdvs());
- JSONObject data = new JSONObject();
- data.put("mdtrt_id", siPatInfo.getMdtrtId());
- data.put("psn_no", siPatInfo.getPsnNo());
- input.getJSONObject("input").put("data", data);
- JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_DISCHARGE);
- 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) {
- dao.deleteSetlInfo(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- dao.deleteSetlDetail(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- transbackTables(p);
- return ResultVoUtil.success("取消医保出院办理成功。");
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- private ResultVo<String> inpatientSettlement(ZyPatientInfo p) {
- PreSetlmt preSetlmt = dao.selectPreSetlmt(p.getInpatientNo(), p.getAdmissTimes(),
- p.getLedgerSn(), "2099-12-31 23:59:59.999");
- if (null == preSetlmt || StringUtil.isBlank(preSetlmt.getMdtrtId())) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保在院信息!");
- }
- preSetlmt.setMdtrtCertType(MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
- preSetlmt.setPsnSetlway(p.getDbg() ? PsnSetlWay.SETTLE_BY_QUOTA.getCode() : PsnSetlWay.SETTLE_BY_ITEMS.getCode());
- preSetlmt.setAcctUsedFlag(YesOrNo.NO.getCodeStr());
- preSetlmt.setMidSetlFlag(YesOrNo.NO.getCodeStr());
- preSetlmt.setInvono(SnowFlakeId.instance().nextId());
- JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.HOSPITALIZATION_SETTLEMENT, preSetlmt.getInsuplcAdmdvs());
- String ref = JSONObject.toJSONString(preSetlmt);
- input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
- JSONObject result = exec.executeTrade(input, SiFunction.HOSPITALIZATION_SETTLEMENT);
- log.info("【操作员:{}】,医保出院结算:\n参数:{},\n结果:{}", p.getStaffId(), input, result);
- if (null == result) {
- revokeDischarge(p);
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if (null == result.getInteger(RESULT_CODE)) {
- revokeDischarge(p);
- 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.getInpatientNo());
- setlEntity.setTimes(p.getAdmissTimes());
- setlEntity.setLedgerSn(p.getLedgerSn());
- setlEntity.setStaffId(TokenUtil.getTokenUserId());
- setlEntity.setRevoked(YesOrNo.NO.getCode());
- setlEntity.setSetlType(ClrType.INPATIENT.getCode());
- setlinfodao.insert(setlEntity);
- setlinfodao.updateSiZyInfoSetlId(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(),
- 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.getInpatientNo());
- setldetailEntity.setTimes(p.getAdmissTimes());
- setldetailEntity.setLedgerSn(p.getLedgerSn());
- setldetldao.insert(setldetailEntity);
- }
- // todo 结算,需要改造,慢慢删除responceType字段
- YbSettleFee settleFee = new YbSettleFee();
- if (p.getDismissFlag() == 2) {
- settleFee.setZjdzDatetime(p.getMidSetlDate());
- }
- settleFee.setResponceType("03");
- settleFee.setFlag(p.getDismissFlag());
- settleFee.setStaffId(TokenUtil.getTokenUserId());
- settleFee.setInpatientNo(p.getInpatientNo());
- settleFee.setAdmissTimes(p.getAdmissTimes());
- settleFee.setBedNo(p.getBedNo());
- settleFee.setWardCode(p.getAdmissWard());
- settleFee.setDeptCode(p.getAdmissDept());
- settleFee.setTotalCost(setlinfo.getString("medfee_sumamt"));
- settleFee.setTczf(setlinfo.getString("fund_pay_sumamt"));
- settleFee.setHospitalPay(setlinfo.getString("hosp_part_amt"));
- settleFee.setGrzhzf(setlinfo.getString("acct_pay"));
- settleFee.setDbzf(setlinfo.getString("hifmi_pay"));
- settleFee.setXjzf(setlinfo.getString("psn_part_amt"));
- settleFee.setTable(p.getTable());
- return dismissService.doDismiss(settleFee);
- }
- revokeDischarge(p);
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- public ResultVo<String> revokeSettlement(ZyPatientInfo p) {
- SiPatInfo siPatInfo = qrydao.selectSiPatInfoForZy(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- if (null == p.getStaffId()) {
- p.setStaffId(TokenUtil.getTokenUserId());
- }
- if (null == p.getLedgerSn()) {
- p.setLedgerSn(dao.selectMaxLedgerSn(p.getInpatientNo(), p.getAdmissTimes()));
- }
- if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getSetlId())) {
- return revokeDischarge(p);
- }
- p.setMdtrtId(siPatInfo.getMdtrtId());
- JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_HOSPITALIZATION_SETTLEMENT, siPatInfo.getInsuplcAdmdvs());
- JSONObject data = new JSONObject();
- data.put("mdtrt_id", siPatInfo.getMdtrtId());
- data.put("setl_id", siPatInfo.getSetlId());
- data.put("psn_no", siPatInfo.getPsnNo());
- input.getJSONObject("input").put("data", data);
- JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_HOSPITALIZATION_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 revokeDischarge(p);
- }
- if (result.getIntValue(RESULT_CODE) == 0) {
- dao.updateRvkSetlMsgid(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn(), input.getString("msgid"));
- transbackTables(p);
- }
- return revokeDischarge(p);
- }
- private void transbackTables(ZyPatientInfo p) {
- dao.deleteSiSetlFeeDetl(p.getMdtrtId());
- dao.deleteZyLedgerFileYb(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- dao.deleteZyReceipt(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- dao.updateSettleType(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- dao.updateChargeStatus(p.getInpatientNo(), p.getAdmissTimes(), p.getLedgerSn());
- }
- }
|