|
@@ -0,0 +1,156 @@
|
|
|
+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.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import thyyxxk.webserver.config.exception.ExceptionEnum;
|
|
|
+import thyyxxk.webserver.constants.MedicalInsuranceFunction;
|
|
|
+import thyyxxk.webserver.dao.his.medicalinsurance.MedicalInsuranceDao;
|
|
|
+import thyyxxk.webserver.entity.ResultVo;
|
|
|
+import thyyxxk.webserver.entity.yibao.patient.Patient;
|
|
|
+import thyyxxk.webserver.entity.yibao.patient.ZyInYbDiag;
|
|
|
+import thyyxxk.webserver.utils.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @description: 住院医保交易
|
|
|
+ * @author: DingJie
|
|
|
+ * @create: 2021-05-14 16:28:16
|
|
|
+ **/
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class ZyMedInsService {
|
|
|
+ private static final String RESULT_CODE = "infcode";
|
|
|
+ private static final String ERROR_MESSAGE = "err_msg";
|
|
|
+ private static final String OUTPUT = "output";
|
|
|
+ private final MedicalInsuranceDao dao;
|
|
|
+ private final MedInsSignService signService;
|
|
|
+ @Value("${si-api-url}")
|
|
|
+ private String siApiUrl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public ZyMedInsService(MedicalInsuranceDao dao, MedInsSignService signService) {
|
|
|
+ this.dao = dao;
|
|
|
+ this.signService = signService;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<JSONObject> obtainBasicPersonInfo(String socialNo, String name) {
|
|
|
+ JSONObject header = signService.makeTradeHeader(MedicalInsuranceFunction.OBTAIN_BASIC_PERSON_INFO);
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("mdtrt_cert_type", "02");
|
|
|
+ data.put("mdtrt_cert_no", socialNo);
|
|
|
+ data.put("psn_cert_type", "1");
|
|
|
+ data.put("certno", socialNo);
|
|
|
+ data.put("psn_name", name);
|
|
|
+ header.getJSONObject("input").put("data", data);
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ JSONObject result = template.postForObject(siApiUrl, header, JSONObject.class);
|
|
|
+ if (null == result) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (result.getIntValue(RESULT_CODE) == 0) {
|
|
|
+ return ResultVoUtil.success(result.getJSONObject(OUTPUT));
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<JSONObject> admissRegister(Patient p) {
|
|
|
+ JSONObject header = signService.makeTradeHeader(MedicalInsuranceFunction.ADMISSION_REGISTRATION);
|
|
|
+ JSONObject mdtrtinfo = new JSONObject();
|
|
|
+ mdtrtinfo.put("psn_no", p.getHicNo());
|
|
|
+ mdtrtinfo.put("insutype", "险种类型");
|
|
|
+ mdtrtinfo.put("begntime", DateUtil.formatDatetime(p.getAdmissDate()));
|
|
|
+ mdtrtinfo.put("mdtrt_cert_type", "02");
|
|
|
+ mdtrtinfo.put("mdtrt_cert_no", p.getSocialNo());
|
|
|
+ mdtrtinfo.put("cert_type", "1");
|
|
|
+ mdtrtinfo.put("certno", p.getSocialNo());
|
|
|
+ mdtrtinfo.put("med_type", p.getYbType());
|
|
|
+ mdtrtinfo.put("ipt_no", p.getInpatientNo());
|
|
|
+ mdtrtinfo.put("atddr_no", p.getReferPhysician());
|
|
|
+ mdtrtinfo.put("chfpdr_name", p.getReferPhysicianName());
|
|
|
+ mdtrtinfo.put("adm_diag_dscr", p.getIcdText());
|
|
|
+ mdtrtinfo.put("adm_dept_codg", p.getSmallDept());
|
|
|
+ mdtrtinfo.put("adm_dept_name", p.getSmallDeptName());
|
|
|
+ mdtrtinfo.put("adm_bed", p.getBedNo());
|
|
|
+ mdtrtinfo.put("dscg_maindiag_code", p.getIcdCode());
|
|
|
+ mdtrtinfo.put("dscg_maindiag_name", p.getIcdText());
|
|
|
+ // 手术操作代码,日间手术病种时必填
|
|
|
+ mdtrtinfo.put("oprn_oprt_code", "");
|
|
|
+ header.getJSONObject("input").put("mdtrtinfo", mdtrtinfo);
|
|
|
+
|
|
|
+ JSONArray diseinfo = new JSONArray();
|
|
|
+ List<ZyInYbDiag> zyInYbDiags = dao.selectZyInYbDiags(p.getInpatientNo(), p.getAdmissTimes());
|
|
|
+ if (null == zyInYbDiags || zyInYbDiags.isEmpty()) {
|
|
|
+ JSONObject diag = new JSONObject();
|
|
|
+ diag.put("psn_no", p.getHicNo());
|
|
|
+ diag.put("diag_type", "诊断类别");
|
|
|
+ diag.put("maindiag_flag", "主诊断标志");
|
|
|
+ diag.put("diag_srt_no", 1);
|
|
|
+ diag.put("diag_code", p.getIcdCode());
|
|
|
+ diag.put("diag_name", p.getIcdText());
|
|
|
+ diag.put("diag_dept", p.getSmallDeptName());
|
|
|
+ diag.put("dise_dor_no", p.getReferPhysician());
|
|
|
+ diag.put("dise_dor_name", p.getReferPhysicianName());
|
|
|
+ diag.put("diag_time", DateUtil.formatDatetime(p.getAdmissDate()));
|
|
|
+ diseinfo.add(diag);
|
|
|
+ } else {
|
|
|
+ zyInYbDiags.forEach(item -> {
|
|
|
+ JSONObject diag = new JSONObject();
|
|
|
+ diag.put("psn_no", p.getHicNo());
|
|
|
+ diag.put("diag_type", "诊断类别");
|
|
|
+ diag.put("maindiag_flag", item.getDiagNo() == 1 ? 1 : 0);
|
|
|
+ diag.put("diag_srt_no", item.getDiagNo());
|
|
|
+ diag.put("diag_code", item.getIcdCode());
|
|
|
+ diag.put("diag_name", item.getIcdText());
|
|
|
+ diag.put("diag_dept", p.getSmallDeptName());
|
|
|
+ diag.put("dise_dor_no", item.getOperId());
|
|
|
+ diag.put("dise_dor_name", item.getOperName());
|
|
|
+ diag.put("diag_time", DateUtil.formatDatetime(item.getOpDate()));
|
|
|
+ diseinfo.add(diag);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ header.getJSONObject("input").put("diseinfo", diseinfo);
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ JSONObject result = template.postForObject(siApiUrl, header, JSONObject.class);
|
|
|
+ log.info("【操作员:{}】,医保入院登记:参数:{},结果:{}", TokenUtil.getTokenUserId(), header, result);
|
|
|
+ if (null == result) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (result.getIntValue(RESULT_CODE) == 0) {
|
|
|
+ JSONObject output = result.getJSONObject(OUTPUT);
|
|
|
+ // 就诊ID,医保返回唯一流水(可能就是yb_jlh)
|
|
|
+ String mdtrtId = output.getString("mdtrt_id");
|
|
|
+ return ResultVoUtil.success(output);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultVo<String> revokeAdmission(String mdtrtId, String psnNo) {
|
|
|
+ JSONObject header = signService.makeTradeHeader(MedicalInsuranceFunction.REVOKE_ADMISSION);
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("mdtrt_id", mdtrtId);
|
|
|
+ data.put("psn_no", psnNo);
|
|
|
+ header.getJSONObject("input").put("data", data);
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ JSONObject result = template.postForObject(siApiUrl, header, JSONObject.class);
|
|
|
+ log.info("【操作员:{}】,取消入院登记:参数:{},结果:{}", TokenUtil.getTokenUserId(), header, result);
|
|
|
+ if (null == result) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (result.getIntValue(RESULT_CODE) == 0) {
|
|
|
+ return ResultVoUtil.success("取消入院登记成功。");
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
|
|
|
+ }
|
|
|
+
|
|
|
+// public ResultVo<String> uploadFeeDetail(Overview o) {
|
|
|
+//
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+}
|