123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- package thyyxxk.webserver.service.markmtfees;
- import com.alibaba.fastjson.JSONObject;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.web.client.RestTemplate;
- import thyyxxk.webserver.config.exception.ExceptionEnum;
- import thyyxxk.webserver.constants.Capacity;
- import thyyxxk.webserver.constants.ResponceType;
- import thyyxxk.webserver.dao.his.markmtfees.MarkMtFeesDao;
- import thyyxxk.webserver.pojo.ResultVo;
- import thyyxxk.webserver.pojo.markmtfees.*;
- import thyyxxk.webserver.utils.*;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * @author dj
- */
- @Slf4j
- @Service
- public class MarkMtFeesService {
- private final MarkMtFeesDao dao;
- @Autowired
- public MarkMtFeesService(MarkMtFeesDao dao) {
- this.dao = dao;
- }
- public ResultVo<Map<String, Object>> queryMtPersonInfo(QueryMtInfoParam param) {
- log.info("查询门特身份:{}", param);
- String patientId = param.getPatientId();
- if (StringUtil.isBlank(patientId)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请输入正确的门诊id号!");
- }
- patientId = patientId.trim();
- if (StringUtil.notBlank(param.getPhoneNo())) {
- dao.updatePhoneNo(patientId, param.getPhoneNo());
- }
- if (StringUtil.notBlank(param.getIdCard())) {
- dao.updateSocialNo(patientId, param.getIdCard());
- }
- Integer times = dao.selectMaxTimes(patientId);
- if (null == times || times == 0) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未查询到些患者的就诊信息,请检查!");
- }
- if (StringUtil.isBlank(param.getIdCard())) {
- param.setIdCard(dao.selectSocialNoByPatientId(patientId));
- }
- if (!IdCardUtil.isValidatedIdCard(param.getIdCard())) {
- return ResultVoUtil.fail(ExceptionEnum.SLIGHTLY_ERROR, "应医保局要求,门诊特殊病患者的身份证不能为空,请补充。");
- }
- if (StringUtil.isBlank(param.getPhoneNo())) {
- param.setPhoneNo(dao.selectPhoneNo(patientId));
- }
- if (StringUtil.isBlank(param.getPhoneNo())) {
- return ResultVoUtil.fail(ExceptionEnum.SLIGHTLY_ERROR, "应医保局要求,门诊特殊病患者的联系电话不能为空,请补充。");
- }
- Map<String, Object> data = new HashMap<>(Capacity.THREE);
- data.put("patientId", patientId);
- data.put("times", times);
- int mtCount;
- if (ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE.equals(param.getResponceType())) {
- mtCount = dao.selectCountMtPartInfo(patientId, times);
- } else {
- mtCount = dao.selectCountMtPartInfoForSyb(patientId, times, param.getBizType());
- }
- if (mtCount > 0) {
- return ResultVoUtil.success(data);
- }
- param.setStaffId(TokenUtil.getTokenUserId());
- RestTemplate template = new RestTemplate();
- Object mapRet;
- if (ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE.equals(param.getResponceType())) {
- param.setBizType("13");
- mapRet = template.postForObject(YbLinksUtil.normalLinks.get("hnsybMtInfo"), param, Object.class);
- } else {
- mapRet = template.postForObject(YbLinksUtil.normalLinks.get("cssybReadMzPatient"), param, Object.class);
- }
- if (null == mapRet) {
- return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "服务器内部错误,查询门特身份信息失败。");
- }
- Map<String, Object> map = FilterUtil.cast(mapRet);
- if (ExceptionEnum.SUCCESS.getCode() != (int) map.get("code")) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, map.get("message").toString());
- }
- if (ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE.equals(param.getResponceType())) {
- Map<String, Object> hnsybRet = FilterUtil.cast(map.get("data"));
- List<Map<String, String>> spinfos = FilterUtil.cast(hnsybRet.get("spinfo"));
- Map<String, String> spinfo = spinfos.get(0);
- String icd = spinfo.get("icd");
- String serialApply = spinfo.get("serial_apply");
- spinfos = FilterUtil.cast(hnsybRet.get("personinfo"));
- String balance = spinfos.get(0).get("last_balance");
- dao.insertHnsybMtPartInfo(patientId, times, icd, balance, serialApply);
- return ResultVoUtil.success(data);
- }
- data.put("list", map.get("data"));
- return ResultVoUtil.success(data);
- }
- public ResultVo<String> confirmCssybMtApplyInfo(CssybApplyInfo param) {
- int mtCount = dao.selectCountMtPartInfoForSyb(param.getPatientId(), param.getTimes(), param.getBizType());
- if (mtCount > 0) {
- return ResultVoUtil.success();
- }
- dao.clearMtPartInfo(param.getPatientId(), param.getTimes());
- param.setMzSerialNo(SnowFlakeId.instance().nextId());
- dao.insertCssybMtPartInfo(param);
- return ResultVoUtil.success();
- }
- public ResultVo<Map<String, Object>> getMtReceipts(String patientId, Integer times) {
- Map<String, Object> map = new HashMap<>(Capacity.FOUR);
- List<MzPatient> mzPatients = dao.selectMzPatient(patientId, times);
- if (null == mzPatients || mzPatients.isEmpty()) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patientId + ",就诊次数:" +
- times + "】未找到此患者的本次就诊信息,请核实。");
- }
- MzVisit mzVisit = dao.selectMzVisit(patientId, times);
- if (null == mzVisit) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "【门诊号:" + patientId + ",就诊次数:" +
- times + "】未找到此患者的本次就诊信息,请核实。");
- }
- map.put("mzPatient", mzPatients.get(0));
- map.put("mzVisit", mzVisit);
- List<MzReceipt> mzReceipts = dao.selectMzReceipts(patientId, times, mzVisit.getReceiptNo());
- mzReceipts.removeIf(item -> "TC".equals(item.getBillItemCode()) || item.getPayMark() != 5 || "BILL99".equals(item.getChargeItemCode()));
- Map<Integer, List<MzReceipt>> temp = new HashMap<>(Capacity.DEFAULT);
- mzReceipts.forEach(item -> {
- item.setChecked(true);
- if (!temp.containsKey(item.getOrderNo())) {
- List<MzReceipt> list = new ArrayList<>();
- list.add(item);
- temp.put(item.getOrderNo(), list);
- } else {
- temp.get(item.getOrderNo()).add(item);
- }
- });
- List<OrderNo> orderNos = new ArrayList<>();
- for (Map.Entry<Integer, List<MzReceipt>> entry : temp.entrySet()) {
- OrderNo orderNo = new OrderNo();
- orderNo.setPatientId(patientId);
- orderNo.setTimes(times);
- orderNo.setReceiptNo(mzVisit.getReceiptNo());
- orderNo.setOrderNo(entry.getKey());
- BigDecimal total = new BigDecimal("0.00");
- for (MzReceipt item : entry.getValue()) {
- total = total.add(item.getChargeFee());
- }
- orderNo.setTotalFee(total);
- int count = dao.selectFeeCount(patientId, times, mzVisit.getReceiptNo(), entry.getKey());
- orderNo.setStatus(count > 0);
- orderNos.add(orderNo);
- }
- map.put("orderNos", orderNos);
- map.put("mzReceipts", temp);
- return ResultVoUtil.success(map);
- }
- public ResultVo<String> insertMtFees(MarkMtFeeParam param) {
- if (param.getResponceType().equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) {
- param.setYbType("13");
- }
- MzReceipt receipt = param.getReceipts().get(0);
- int count = dao.selectFeeCount(receipt.getPatientId(), receipt.getTimes(),
- receipt.getReceiptNo(), receipt.getOrderNo());
- if (count > 0) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该处方已生成过门特费用,请勿重复操作。");
- }
- dao.insertMzChargeYb(receipt.getPatientId(), receipt.getTimes(), receipt.getReceiptNo(),
- receipt.getOrderNo(), param.getResponceType(), param.getYbType());
- param.getReceipts().forEach(item -> {
- if (item.getChecked()) {
- dao.insertBatchedMtFeeInfo(item);
- }
- });
- return ResultVoUtil.success();
- }
- public ResultVo<String> deleteMtFees(OrderNo param) {
- dao.deleteMtFees(param);
- return ResultVoUtil.success();
- }
- public ResultVo<Object> cssybMtPreCal(String patientId, Integer times) {
- JSONObject param = new JSONObject();
- param.put("patientId", patientId);
- param.put("times", times);
- param.put("staffId", TokenUtil.getTokenUserId());
- log.info("市门特试算:{}", param);
- RestTemplate template = new RestTemplate();
- Object mapRet = template.postForObject(YbLinksUtil.normalLinks.get("cssybMtPreCal"), param, Object.class);
- log.info("市门特试算结果:{}", mapRet);
- if (null == mapRet) {
- return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "服务器内部错误,门特费用试算失败。");
- }
- Map<String, Object> map = FilterUtil.cast(mapRet);
- if (ExceptionEnum.SUCCESS.getCode() != (int) map.get("code")) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, map.get("message").toString());
- }
- return ResultVoUtil.success(map.get("data"));
- }
- public Map<String, Object> uploadMtFees(UploadMtFeeParam param) {
- log.info("上传省门特费用:{}", param);
- Map<String, Object> resultMap = new HashMap<>(Capacity.TWO);
- String responceType = dao.selectResponceType(param.getPatientId(), param.getTimes());
- if (null == responceType) {
- resultMap.put("code", -1);
- resultMap.put("msg", "未查询到此人的门特身份记录。");
- return resultMap;
- }
- String urlHead = YbLinksUtil.normalLinks.get("mtBase");
- String urlEnd;
- if (responceType.equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) {
- urlEnd = ":2000/shengyb/mt/uploadFees";
- } else {
- urlEnd = ":1000/mzsyb/mzCalculate";
- }
- String url = urlHead + urlEnd;
- RestTemplate restTemplate = new RestTemplate();
- Object templateRet = restTemplate.postForObject(url, param, Object.class);
- log.info("上传省门特费用结果:{}", templateRet);
- return FilterUtil.cast(templateRet);
- }
- public Map<String, Object> retractMtFees(UploadMtFeeParam param) {
- log.info("撤销门特费用:{}", param);
- Map<String, Object> resultMap = new HashMap<>(Capacity.TWO);
- String responceType = dao.selectResponceType(param.getPatientId(), param.getTimes());
- if (null == responceType) {
- resultMap.put("code", -1);
- resultMap.put("msg", "未查询到此人的门特身份记录。");
- return resultMap;
- }
- String urlHead = YbLinksUtil.normalLinks.get("mtBase");
- String urlEnd;
- if (responceType.equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) {
- urlEnd = ":2000/shengyb/mt/retractFees";
- } else {
- urlEnd = ":1000/mzsyb/mzCancelCalculate";
- }
- String url = urlHead + urlEnd;
- RestTemplate restTemplate = new RestTemplate();
- Object templateRet = restTemplate.postForObject(url, param, Object.class);
- return FilterUtil.cast(templateRet);
- }
- public Map<String, Object> calculateMtFees(UploadMtFeeParam param) {
- log.info("结算门特费用:{}", param);
- Map<String, Object> resultMap = new HashMap<>(Capacity.TWO);
- String responceType = dao.selectResponceType(param.getPatientId(), param.getTimes());
- if (null == responceType) {
- resultMap.put("code", -1);
- resultMap.put("msg", "未查询到此人的门特身份记录。");
- return resultMap;
- }
- String urlHead = YbLinksUtil.normalLinks.get("mtBase");
- String urlEnd;
- if (responceType.equals(ResponceType.HUNAN_PROVINCIAL_MEDICAL_INSURANCE)) {
- urlEnd = ":2000/shengyb/mt/calculateCost";
- } else {
- urlEnd = ":1000/mzsyb/mzCalculate";
- }
- String url = urlHead + urlEnd;
- RestTemplate restTemplate = new RestTemplate();
- Object templateRet = restTemplate.postForObject(url, param, Object.class);
- log.info("结算门特费用结果:{}", templateRet);
- return FilterUtil.cast(templateRet);
- }
- }
|