|
@@ -62,6 +62,18 @@ public class SiMzFeeService {
|
|
|
if (null == regstrtn) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "mz_visit_table患者信息为空,请联系医生重开处方。");
|
|
|
}
|
|
|
+
|
|
|
+ List<String> chargeCodeList = mzDao.selectHisChargeCodes(p.getPatNo(), p.getTimes());
|
|
|
+ if (chargeCodeList.isEmpty()) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未找到收费明细,请先生成医保处方。");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询处方是否有折扣
|
|
|
+ String discount = queryDiscount(p.getPatNo(), p.getTimes(), chargeCodeList);
|
|
|
+ if (!discount.equals("OK")) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, discount);
|
|
|
+ }
|
|
|
+
|
|
|
ReadCardBizType readCardBizType = ReadCardBizType.get(p.getReadCardBizType());
|
|
|
if (readCardBizType != ReadCardBizType.REGISTRATION && !p.getInsuplcAdmdvs().startsWith("43")) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "省外异地的患者请读社保卡或医保电子凭证登记!");
|
|
@@ -111,6 +123,7 @@ public class SiMzFeeService {
|
|
|
if (null == siPatInfo || StringUtil.isBlank(siPatInfo.getMdtrtId())) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的医保挂号信息。");
|
|
|
}
|
|
|
+ MzgjUtil.finishProcessing(p.getPatNo());
|
|
|
RevokeRegRequest request = new RevokeRegRequest();
|
|
|
request.setInsuplcAdmdvs(siPatInfo.getInsuplcAdmdvs()); ;
|
|
|
request.setStaffId(p.getStaffId());
|
|
@@ -135,6 +148,7 @@ public class SiMzFeeService {
|
|
|
logDao.insert(new SiLog(input, result, request.getPatNo(), request.getTimes(), infcode, request.getPsnNo()));
|
|
|
if (infcode == 0) {
|
|
|
mzDao.clearMdtrtIdForMz(request.getPatNo(), request.getTimes(), null);
|
|
|
+
|
|
|
return ResultVoUtil.success("取消门诊挂号成功。");
|
|
|
}
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
@@ -211,7 +225,6 @@ public class SiMzFeeService {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patNo +
|
|
|
"】未找到此患者的医保挂号信息,请核实。");
|
|
|
}
|
|
|
- setlinfoDao.deletePreSettleInfo(patNo, p.getTimes());
|
|
|
if (!p.getFromDirectReg()) {
|
|
|
ResultVo<String> uplRes = uploadOutpatientInfo(p, siPatInfo);
|
|
|
if (null != uplRes && uplRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
@@ -309,13 +322,6 @@ public class SiMzFeeService {
|
|
|
}
|
|
|
|
|
|
public ResultVo<FundDetail> outpatientPreSettlement(MzPatientInfo p) {
|
|
|
- while (MzgjUtil.inProcessing(p.getPatNo())) {
|
|
|
- try {
|
|
|
- TimeUnit.SECONDS.sleep(1);
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- }
|
|
|
if (null == p.getTimes()) {
|
|
|
p.setTimes(mzDao.selectMaxTimes(p.getPatNo()));
|
|
|
}
|
|
@@ -357,6 +363,7 @@ public class SiMzFeeService {
|
|
|
Integer infcode = result.getInteger(RESULT_CODE);
|
|
|
logDao.insert(new SiLog(input, result, p.getPatNo(), p.getTimes(), infcode, mzPreSetlmt.getPsnNo()));
|
|
|
if (infcode == 0) {
|
|
|
+ setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes());
|
|
|
JSONObject setlinfo = result.getJSONObject(OUTPUT).getJSONObject("setlinfo");
|
|
|
FundDetail fundDetail = new FundDetail();
|
|
|
fundDetail.setTotalCost(setlinfo.getString("medfee_sumamt"));
|
|
@@ -365,19 +372,16 @@ public class SiMzFeeService {
|
|
|
fundDetail.setAcctPay(setlinfo.getString("acct_pay"));
|
|
|
fundDetail.setSelfPay(setlinfo.getString("psn_part_amt"));
|
|
|
fundDetail.setCardType(getCardType(mzPreSetlmt.getInsuplcAdmdvs()));
|
|
|
-
|
|
|
- if (p.needSavePreSettleResult()) {
|
|
|
- setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes());
|
|
|
- SiSetlinfo setlEntity = JSONObject.parseObject(setlinfo.toJSONString(), SiSetlinfo.class);
|
|
|
- setlEntity.setPatNo(p.getPatNo());
|
|
|
- setlEntity.setTimes(p.getTimes());
|
|
|
- setlEntity.setLedgerSn(0);
|
|
|
- setlEntity.setStaffId(p.getStaffId());
|
|
|
- setlEntity.setSetlType(ClrType.OUTPATIENT.getCode());
|
|
|
- setlEntity.setInsuplcAdmdvs(mzPreSetlmt.getInsuplcAdmdvs());
|
|
|
- setlinfoDao.insertPreSettleInfo(setlEntity);
|
|
|
- }
|
|
|
-
|
|
|
+ SiSetlinfo setlEntity = JSONObject.parseObject(setlinfo.toJSONString(), SiSetlinfo.class);
|
|
|
+ setlEntity.setPatNo(p.getPatNo());
|
|
|
+ setlEntity.setTimes(p.getTimes());
|
|
|
+ setlEntity.setLedgerSn(0);
|
|
|
+ setlEntity.setStaffId(p.getStaffId());
|
|
|
+ setlEntity.setSetlType(ClrType.OUTPATIENT.getCode());
|
|
|
+ setlEntity.setInsuplcAdmdvs(mzPreSetlmt.getInsuplcAdmdvs());
|
|
|
+ log.info("开始插入预结算临时信息:{}_{}", p.getPatNo(), p.getTimes());
|
|
|
+ setlinfoDao.insertPreSettleInfo(setlEntity);
|
|
|
+ log.info("插入预结算临时信息成功:{}_{}", p.getPatNo(), p.getTimes());
|
|
|
return ResultVoUtil.success(fundDetail);
|
|
|
}
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
@@ -385,11 +389,9 @@ public class SiMzFeeService {
|
|
|
|
|
|
private ResultVo<FundDetail> getFundDetailByPatientInfo(String patientId, int times, boolean realSettle) {
|
|
|
SiSetlinfo sisetlinfo = mzDao.selectSettledInfo(patientId, times, 0);
|
|
|
-
|
|
|
if (!realSettle && null == sisetlinfo) {
|
|
|
sisetlinfo = setlinfoDao.selectPresettleInfo(patientId, times);
|
|
|
}
|
|
|
-
|
|
|
if (null != sisetlinfo) {
|
|
|
return getFundDetailFromSetlinfo(sisetlinfo);
|
|
|
}
|
|
@@ -489,16 +491,14 @@ public class SiMzFeeService {
|
|
|
webHisService.saveCumInfo(webHisUrl, setlEntity);
|
|
|
|
|
|
if (BigDecimal.ZERO.compareTo(BigDecimal.valueOf(setlEntity.getPsnCashPay())) == 0) {
|
|
|
- ResultVo<String> mzChargeResponse = mzChargeFee(p.getPatNo(), p.getTimes(),
|
|
|
+ ResultVo<String> mzChargeResponse = mzHisChargeProcess(p.getPatNo(), p.getTimes(),
|
|
|
String.valueOf(setlEntity.getMedfeeSumamt()));
|
|
|
if (mzChargeResponse.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
revokeOutpatientSettlementForTask(setlEntity);
|
|
|
return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, mzChargeResponse.getMessage());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes());
|
|
|
-
|
|
|
return getFundDetailFromSetlinfo(setlEntity);
|
|
|
}
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
@@ -512,7 +512,7 @@ public class SiMzFeeService {
|
|
|
SiSetlinfo setlinfo = mzDao.selectSettledInfo(p.getPatNo(), p.getTimes(), 0);
|
|
|
if (null == setlinfo) {
|
|
|
if (p.needRevokeRegistration()) {
|
|
|
- deletePresettleInfo(p);
|
|
|
+ deletePresettleInfoAndRevokeYb(p);
|
|
|
}
|
|
|
setlinfo = mzDao.selectSettledInfo(p.getPatNo(), p.getTimes(), 1);
|
|
|
if (null == setlinfo) {
|
|
@@ -549,12 +549,12 @@ public class SiMzFeeService {
|
|
|
if (infcode == 0) {
|
|
|
afterRevokeSetl(p.getPatNo(), p.getTimes(), input.getString("msgid"));
|
|
|
if (p.needRevokeRegistration()) {
|
|
|
- deletePresettleInfo(p);
|
|
|
+ deletePresettleInfoAndRevokeYb(p);
|
|
|
}
|
|
|
return getFundDetailFromSetlinfo(setlinfo);
|
|
|
}
|
|
|
if (p.needRevokeRegistration()) {
|
|
|
- deletePresettleInfo(p);
|
|
|
+ deletePresettleInfoAndRevokeYb(p);
|
|
|
}
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
|
}
|
|
@@ -583,6 +583,7 @@ public class SiMzFeeService {
|
|
|
}
|
|
|
|
|
|
public void afterRevokeSetl(String patNo, int times, String msgId) {
|
|
|
+ MzgjUtil.finishProcessing(patNo);
|
|
|
try {
|
|
|
mzDao.deleteSetlInfo(patNo, times);
|
|
|
mzDao.deleteSetlDetail(patNo, times);
|
|
@@ -609,20 +610,20 @@ public class SiMzFeeService {
|
|
|
return setlfund;
|
|
|
}
|
|
|
MzgjUtil.addProcess(param.getPatientId());
|
|
|
+ ResultVo<FundDetail> response;
|
|
|
try {
|
|
|
- return executeMzgj(param);
|
|
|
+ response = executeMzgj(param);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("门诊共济出错:", e);
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, e.getMessage());
|
|
|
+ response = ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, e.getMessage());
|
|
|
} finally {
|
|
|
MzgjUtil.finishProcessing(param.getPatientId());
|
|
|
}
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
private ResultVo<FundDetail> executeMzgj(DirectionRegParam param) {
|
|
|
if (mzDao.selectExistCount(param.getPatientId(), param.getTimes()) == 0) {
|
|
|
- int update = mzDao.updateMzTimes(param.getPatientId(), param.getTimes());
|
|
|
- if (update == 0) {
|
|
|
+ if (mzDao.updateMzTimes(param.getPatientId(), param.getTimes()) == 0) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR,
|
|
|
"[t_si_pat_info]不存在患者[" + param.getPatientId()
|
|
|
+ "]第[" + param.getTimes() + "]次的就诊信息,请重新查询。");
|
|
@@ -635,18 +636,27 @@ public class SiMzFeeService {
|
|
|
mzptnt.setTimes(param.getTimes());
|
|
|
mzptnt.setMedType("11");
|
|
|
mzptnt.setAcctUsedFlag(String.valueOf(param.getAcctUsedFlag()));
|
|
|
+
|
|
|
+ // 生成医保费用
|
|
|
+ String mzReceipts = generateSiMzFees(mzptnt);
|
|
|
+ if (!mzReceipts.equals("SUCCESS")) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, mzReceipts);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 填充医保基本信息
|
|
|
SiPatInfo siPatInfo = mzDao.selectSiPatInfoForMz(mzptnt.getPatNo(), mzptnt.getTimes());
|
|
|
mzptnt.setInsuplcAdmdvs(siPatInfo.getInsuplcAdmdvs());
|
|
|
mzptnt.setInsutype(siPatInfo.getInsutype());
|
|
|
mzptnt.setPsnType(siPatInfo.getPsnType());
|
|
|
mzptnt.setName(siPatInfo.getPsnName());
|
|
|
mzptnt.setSocialNo(siPatInfo.getCertno());
|
|
|
+
|
|
|
+ // 解析读卡信息
|
|
|
if (StringUtil.notBlank(param.getReadCardResult())) {
|
|
|
MdtrtCertType mdtrtCertType = MdtrtCertType.get(param.getReadCardType());
|
|
|
mzptnt.setMdtrtCertType(mdtrtCertType.getLabel());
|
|
|
mzptnt.setReadCardBizType(ReadCardBizType.REGISTRATION.getCode());
|
|
|
mzptnt.setReadCardResult(param.getReadCardResult());
|
|
|
-
|
|
|
if (mdtrtCertType.getCode().equals(MdtrtCertType.ELECTRONIC_VOUCHER.getCode())) {
|
|
|
JSONObject obj = JSONObject.parseObject(param.getReadCardResult());
|
|
|
String admdvs = obj.getString("insuOrg");
|
|
@@ -656,12 +666,13 @@ public class SiMzFeeService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 挂号登记
|
|
|
ResultVo<String> regres = outpatientRegistration(mzptnt);
|
|
|
if (regres.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, regres.getMessage());
|
|
|
}
|
|
|
|
|
|
- // 挂号登记成功后上传就诊信息
|
|
|
+ // 上传就诊信息
|
|
|
siPatInfo = mzDao.selectSiPatInfoForMz(mzptnt.getPatNo(), mzptnt.getTimes());
|
|
|
siPatInfo.setFromDirectReg(true);
|
|
|
SpcChrDiseAcct spcChrDiseAcct = new SpcChrDiseAcct();
|
|
@@ -673,15 +684,28 @@ public class SiMzFeeService {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldMdtrtRes.getMessage());
|
|
|
}
|
|
|
|
|
|
- // 上传就诊信息成功后生成门诊医保费用
|
|
|
+ // 上传费用明细
|
|
|
+ spcChrDiseAcct.setStaffId(param.getStaffId());
|
|
|
+ spcChrDiseAcct.setPatNo(mzptnt.getPatNo());
|
|
|
+ spcChrDiseAcct.setTimes(mzptnt.getTimes());
|
|
|
+ spcChrDiseAcct.setFromDirectReg(true);
|
|
|
+ ResultVo<SiPatInfo> upldFeeRes = uploadOutpatientFeeDetails(spcChrDiseAcct);
|
|
|
+ if (upldFeeRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
+ revokeOutpatientRegistration(mzptnt);
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldFeeRes.getMessage());
|
|
|
+ }
|
|
|
+ // 试算并返回试算结果
|
|
|
+ mzptnt.setReadCardBizType(ReadCardBizType.SETTLEMENT.getCode());
|
|
|
+ return outpatientPreSettlement(mzptnt);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String generateSiMzFees(MzPatientInfo mzptnt) {
|
|
|
ResultVo<List<Map<String, Object>>> getMzRcptRes = webHisService.getMzReceipts(webHisUrl, mzptnt);
|
|
|
if (null == getMzRcptRes) {
|
|
|
- revokeOutpatientRegistration(mzptnt);
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ return ExceptionEnum.NETWORK_ERROR.getMessage();
|
|
|
}
|
|
|
if (getMzRcptRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
- revokeOutpatientRegistration(mzptnt);
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, getMzRcptRes.getMessage());
|
|
|
+ return getMzRcptRes.getMessage();
|
|
|
}
|
|
|
List<MzReceipt> mzReceipts = new ArrayList<>();
|
|
|
for (Map<String, Object> item : getMzRcptRes.getData()) {
|
|
@@ -689,39 +713,39 @@ public class SiMzFeeService {
|
|
|
if (times != mzptnt.getTimes()) {
|
|
|
continue;
|
|
|
}
|
|
|
- mzDao.deleteAllReceipts(param.getPatientId(), times);
|
|
|
+ mzDao.deleteAllReceipts(mzptnt.getPatNo(), times);
|
|
|
Map<Integer, List<MzReceipt>> orderReceiptsMap = FilterUtil.cast(item.get("mzReceipts"));
|
|
|
for (Map.Entry<Integer, List<MzReceipt>> entry : orderReceiptsMap.entrySet()) {
|
|
|
mzReceipts.addAll(entry.getValue());
|
|
|
}
|
|
|
}
|
|
|
if (mzReceipts.isEmpty()) {
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有可以上传到医保的费用。");
|
|
|
+ return "没有可以上传到医保的费用。";
|
|
|
}
|
|
|
ResultVo<String> insertSiMzFeeRes = webHisService.insertSiMzFees(webHisUrl, mzReceipts);
|
|
|
if (insertSiMzFeeRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
- revokeOutpatientRegistration(mzptnt);
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, insertSiMzFeeRes.getMessage());
|
|
|
+ return insertSiMzFeeRes.getMessage();
|
|
|
}
|
|
|
+ return "SUCCESS";
|
|
|
+ }
|
|
|
|
|
|
- // 生成费用成功后上传到医保
|
|
|
- spcChrDiseAcct.setStaffId(param.getStaffId());
|
|
|
- spcChrDiseAcct.setPatNo(mzptnt.getPatNo());
|
|
|
- spcChrDiseAcct.setTimes(mzptnt.getTimes());
|
|
|
- spcChrDiseAcct.setFromDirectReg(true);
|
|
|
- ResultVo<SiPatInfo> upldFeeRes = uploadOutpatientFeeDetails(spcChrDiseAcct);
|
|
|
- if (upldFeeRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
- revokeOutpatientRegistration(mzptnt);
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldFeeRes.getMessage());
|
|
|
+ private String queryDiscount(String patNo, int times, List<String> mzReceipts) {
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("patientId", patNo);
|
|
|
+ params.put("times", times);
|
|
|
+ params.put("chargeCodes", mzReceipts);
|
|
|
+ JSONObject response = webHisService.checkDiscount(thmzUrl, params);
|
|
|
+ int code = response.getIntValue("code");
|
|
|
+ if (code == 0) {
|
|
|
+ return "OK";
|
|
|
}
|
|
|
- // 上传完成之后试算并返回试算结果
|
|
|
- mzptnt.setReadCardBizType(ReadCardBizType.SETTLEMENT.getCode());
|
|
|
-// mzptnt.setSavePreSettleResult(true);
|
|
|
-// return outpatientPreSettlement(mzptnt);
|
|
|
- return outpatientSettlement(mzptnt);
|
|
|
+ if (code == -2) {
|
|
|
+ return "患者本次就诊有折扣优惠,无法进行医保统筹。";
|
|
|
+ }
|
|
|
+ return response.getString("message");
|
|
|
}
|
|
|
|
|
|
- private ResultVo<String> mzChargeFee(String patientId, int times, String totalFee) {
|
|
|
+ private ResultVo<String> mzHisChargeProcess(String patientId, int times, String totalFee) {
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("patientId", patientId);
|
|
|
params.put("times", times);
|
|
@@ -751,7 +775,7 @@ public class SiMzFeeService {
|
|
|
return ResultVoUtil.success(result);
|
|
|
}
|
|
|
|
|
|
- public void deletePresettleInfo(MzPatientInfo p) {
|
|
|
+ public void deletePresettleInfoAndRevokeYb(MzPatientInfo p) {
|
|
|
int res = setlinfoDao.deletePreSettleInfo(p.getPatNo(), p.getTimes());
|
|
|
if (res == 1) {
|
|
|
revokeOutpatientFeeDetails(p);
|