123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- package thyyxxk.webserver.service.medicalinsurance;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- 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.Capacity;
- import thyyxxk.webserver.constants.sidicts.MdtrtCertType;
- import thyyxxk.webserver.constants.sidicts.SiFunction;
- import thyyxxk.webserver.dao.his.medicalinsurance.SiMzDao;
- 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.service.externalhttp.SiMzSrvc;
- import thyyxxk.webserver.service.externalhttp.ThmzSystem;
- import thyyxxk.webserver.utils.*;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.util.*;
- /**
- * @description: 门诊医保交易
- * @author: DingJie
- * @create: 2021-05-28 16:11:19
- **/
- @Slf4j
- @Service
- public class SiMzService {
- private final SiMzDao dao;
- private final ExecService exec;
- private final ThmzSystem thmz;
- private final SiMzSrvc mzSrvc;
- private static final String RESULT_CODE = "infcode";
- private static final String ERROR_MESSAGE = "err_msg";
- private static final String OUTPUT = "output";
- @Autowired
- public SiMzService(SiMzDao dao, ExecService exec, ThmzSystem thmz, SiMzSrvc mzSrvc) {
- this.dao = dao;
- this.exec = exec;
- this.thmz = thmz;
- this.mzSrvc = mzSrvc;
- }
- public ResultVo<String> outpatientRegistration(MzPatientInfo p) {
- p.setStaffId(TokenUtil.getTokenUserId());
- return mzSrvc.outpatientRegistration(p);
- }
- public ResultVo<String> revokeOutpatientRegistration(MzPatientInfo p) {
- p.setStaffId(TokenUtil.getTokenUserId());
- return mzSrvc.revokeOutpatientRegistration(p);
- }
- public ResultVo<List<Map<String, Object>>> getMzReceipts(MzPatientInfo p) {
- String patNo = p.getPatNo();
- JSONObject queryMzChargeListParam = new JSONObject();
- queryMzChargeListParam.put("patCardType", 21);
- queryMzChargeListParam.put("patCardNo", patNo);
- queryMzChargeListParam.put("hisOrdNum", "");
- Map<String, Object> mzChargeListMap = thmz.getMzChargeDetailForUnPaid(queryMzChargeListParam);
- 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<Map<String, Object>> finalResult = new ArrayList<>();
- List<Map<String, String>> mzChargeList = FilterUtil.cast(mzChargeListMap.get("data"));
- for (Map<String, String> 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<String, Object> childResult = new HashMap<>(Capacity.FIVE);
- childResult.put("times", tempTimes);
- 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<String, Object> mzChargeDetailMap = thmz.unPaidToFullChargeDetail(queryMzChargeDetailParam);
- if (null != mzChargeDetailMap && 0 == (int) mzChargeDetailMap.get("resultCode")) {
- List<Map<String, Object>> 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<Integer, List<MzReceipt>> 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<MzReceipt> list = new ArrayList<>();
- list.add(receipt);
- orderReceiptsMap.put(receipt.getOrderNo(), list);
- } else {
- orderReceiptsMap.get(receipt.getOrderNo()).add(receipt);
- }
- });
- List<OrderNo> orderNos = getOrderNos(patNo, tempTimes, mzVisit.getReceiptNo(), orderReceiptsMap);
- childResult.put("orderNos", orderNos);
- childResult.put("mzReceipts", orderReceiptsMap);
- finalResult.add(childResult);
- }
- }
- }
- return ResultVoUtil.success(finalResult);
- }
- public ResultVo<List<MzDepositFile>> getHistoryMzReceipts(String patNo, String start, String end) {
- List<MzDepositFile> mzChargeList = dao.selectMzDepositFiles(patNo, start, end);
- if (null == mzChargeList || mzChargeList.isEmpty()) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到历史处方!");
- }
- return ResultVoUtil.success(mzChargeList);
- }
- public ResultVo<List<MzReceipt>> getHistoryReceiptDetail(MzDepositFile mzDepositFile) {
- List<MzReceipt> mzReceipts = dao.selectMzCharge(mzDepositFile.getPatNo(),
- mzDepositFile.getTimes(), mzDepositFile.getReceiptNo());
- mzReceipts.forEach(itm -> itm.setChecked(StringUtil.notBlank(itm.getNationalCode())));
- return ResultVoUtil.success(mzReceipts);
- }
- private MzReceipt fillMzReceipt(Map<String, Object> detail) {
- MzReceipt receipt = new MzReceipt();
- 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.valueOf(detail.get("quantity").toString()));
- 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());
- String table = receipt.getGroupNo().trim().equals("00") ? "zd_charge_item" : "yp_zd_dict";
- receipt.setNationalCode(dao.selectNationalCode(receipt.getChargeItemCode(), table));
- receipt.setChecked(StringUtil.notBlank(receipt.getNationalCode()));
- 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.valueOf(detail.get("drugQuan").toString()));
- }
- 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<OrderNo> getOrderNos(String patientId, int times, int receiptNo, Map<Integer, List<MzReceipt>> orderReceiptsMap) {
- List<OrderNo> orderNos = new ArrayList<>();
- for (Map.Entry<Integer, List<MzReceipt>> 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<String> insertSiMzFees(List<MzReceipt> receipts) {
- receipts.removeIf(itm -> !itm.getChecked());
- if (receipts.size() == 0) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "请选择至少一条处方明细!");
- }
- MzReceipt receipt = receipts.get(0);
- int count = dao.selectFeeCount(receipt.getPatientId(), receipt.getTimes(),
- receipt.getReceiptNo(), receipt.getOrderNo());
- if (count > 0) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该处方已生成过门特费用,请勿重复操作。");
- }
- receipts.forEach(item -> {
- if (item.getChecked()) {
- dao.insertBatchedMtFeeInfo(item);
- }
- });
- return ResultVoUtil.success();
- }
- public ResultVo<String> deleteMzReceipt(OrderNo param) {
- dao.deleteMzReceipt(param);
- return ResultVoUtil.success();
- }
- public ResultVo<String> 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("删除成功。");
- }
- public ResultVo<SiPatInfo> uploadOutpatientFeeDetails(SpcChrDiseAcct p) {
- p.setStaffId(TokenUtil.getTokenUserId());
- return mzSrvc.uploadOutpatientFeeDetails(p);
- }
- public ResultVo<String> revokeOutpatientFeeDetails(MzPatientInfo p) {
- p.setStaffId(TokenUtil.getTokenUserId());
- return mzSrvc.revokeOutpatientFeeDetails(p);
- }
- public ResultVo<FundDetail> outpatientPreSettlement(MzPatientInfo p) {
- if (null == p.getStaffId()) {
- p.setStaffId(TokenUtil.getTokenUserId());
- }
- return mzSrvc.outpatientPreSettlement(p);
- }
- public ResultVo<FundDetail> outpatientSettlement(MzPatientInfo p) {
- if (null == p.getStaffId()) {
- p.setStaffId(TokenUtil.getTokenUserId());
- }
- return mzSrvc.outpatientSettlement(p);
- }
- public ResultVo<FundDetail> revokeOutpatientSettlement(MzPatientInfo p) {
- if (null == p.getStaffId()) {
- p.setStaffId(TokenUtil.getTokenUserId());
- }
- return mzSrvc.revokeOutpatientSettlement(p);
- }
- public ResultVo<String> saveSiMzDiags(List<SiMzDiag> diags) {
- if (ListUtil.isBlank(diags)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有要保存的诊断!");
- }
- SiMzDiag diag = diags.get(0);
- dao.deleteMzDiags(diag.getPatNo(), diag.getTimes());
- String staffId = TokenUtil.getTokenUserId();
- for (SiMzDiag itm : diags) {
- itm.setRealOpter(staffId);
- dao.insertNewMzDiag(itm);
- }
- return ResultVoUtil.success("门诊诊断保存成功。");
- }
- public void updateMzSaved(String patientId, int times, int val) {
- dao.updateMzSaved(patientId, times, val);
- }
- public ResultVo<List<SpcChrDiseAcct>> fetchSpcSlwinfo(String socialNo) {
- if (StringUtil.isBlank(socialNo)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "患者身份证号不能为空,请补充!");
- }
- JSONObject input = exec.makeTradeHeader(SiFunction.OBTAIN_BASIC_PERSON_INFO);
- JSONObject data = new JSONObject();
- data.put("mdtrt_cert_type", MdtrtCertType.RESIDENT_IDENTITY_CARD.getCode());
- data.put("psn_cert_type", "01");
- data.put("mdtrt_cert_no", socialNo);
- data.put("certno", socialNo);
- input.getJSONObject("input").put("data", data);
- JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_BASIC_PERSON_INFO);
- if (null == result) {
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if (null == result.getInteger(RESULT_CODE)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的慢特病备案,或慢特病备案已过期!");
- }
- if (result.getIntValue(RESULT_CODE) == 0) {
- JSONObject output = result.getJSONObject(OUTPUT);
- JSONObject baseinfo = output.getJSONObject("baseinfo");
- String psnNo = baseinfo.getString("psn_no");
- JSONArray insuinfo = output.getJSONArray("insuinfo");
- Date now = new Date();
- List<SpcChrDiseAcct> list = new ArrayList<>();
- for (int i = 0; i < insuinfo.size(); i++) {
- JSONObject item = insuinfo.getJSONObject(i);
- String admdvs = item.getString("insuplc_admdvs");
- input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_ACCREDITATION, admdvs);
- data = new JSONObject();
- data.put("psn_no", psnNo);
- input.getJSONObject("input").put("data", data);
- result = exec.executeTrade(input, SiFunction.QUERY_SPECIAL_CHRONIC_DISEASES_ACCREDITATION);
- if (null == result) {
- continue;
- }
- if (null == result.getInteger(RESULT_CODE)) {
- continue;
- }
- if (result.getIntValue(RESULT_CODE) == 0) {
- output = result.getJSONObject(OUTPUT);
- JSONArray details = output.getJSONArray("feedetail");
- if (null == details || details.size() == 0) {
- continue;
- }
- for (int j = 0; j < details.size(); j++) {
- JSONObject detail = details.getJSONObject(j);
- SpcChrDiseAcct spcChrDiseAcct = JSONObject.parseObject(detail.toJSONString(), SpcChrDiseAcct.class);
- if (now.before(spcChrDiseAcct.getEnddate())) {
- list.add(spcChrDiseAcct);
- }
- }
- if (list.size() > 0) {
- return ResultVoUtil.success(list);
- }
- }
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的慢特病备案,或慢特病备案已过期!");
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "此患者没有有效的慢特病备案,或慢特病备案已过期!");
- }
- }
|