Selaa lähdekoodia

新医保开发。

lighter 4 vuotta sitten
vanhempi
commit
9f47f77d49

+ 35 - 0
src/main/java/thyyxxk/webserver/dao/his/medicalinsurance/MedicalInsuranceDao.java

@@ -0,0 +1,35 @@
+package thyyxxk.webserver.dao.his.medicalinsurance;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import thyyxxk.webserver.entity.yibao.patient.ZyInYbDiag;
+
+import java.util.List;
+
+/**
+ * @description: 新医保mapper
+ * @author: DingJie
+ * @create: 2021-05-28 14:50:31
+ **/
+@Mapper
+public interface MedicalInsuranceDao {
+
+    /**
+     * 获取员工姓名
+     * @param staffId 员工5位长度唯一编码
+     * @return 员工姓名
+     * */
+    @Select("select rtrim(name) from a_employee_mi where code=#{staffId}")
+    String selectStaffName(@Param("staffId") String staffId);
+
+    /**
+     * 获取入院医保诊断
+     * @param zyh 住院号
+     * @param times 住院次数
+     * @return 入院医保诊断
+     * */
+    @Select("select *,operName=(select rtrim(name) from a_employee_mi where code=oper_id) " +
+            "from zy_in_diag_yb where inpatient_no=#{zyh} and admiss_times=#{times}")
+    List<ZyInYbDiag> selectZyInYbDiags(@Param("zyh") String zyh, @Param("times") int times);
+}

+ 4 - 0
src/main/java/thyyxxk/webserver/entity/yibao/patient/ZyInYbDiag.java

@@ -4,6 +4,9 @@ import lombok.Data;
 
 import java.util.Date;
 
+/**
+ * @author dj
+ */
 @Data
 public class ZyInYbDiag {
     private Integer pid;
@@ -13,5 +16,6 @@ public class ZyInYbDiag {
     private String icdCode;
     private String icdText;
     private String operId;
+    private String operName;
     private Date opDate;
 }

+ 117 - 0
src/main/java/thyyxxk/webserver/service/medicalinsurance/MedInsSignService.java

@@ -0,0 +1,117 @@
+package thyyxxk.webserver.service.medicalinsurance;
+
+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.constants.MedicalInsuranceFunction;
+import thyyxxk.webserver.dao.his.medicalinsurance.MedicalInsuranceDao;
+import thyyxxk.webserver.utils.DateUtil;
+import thyyxxk.webserver.utils.SiMsgIdUtil;
+import thyyxxk.webserver.utils.StringUtil;
+import thyyxxk.webserver.utils.TokenUtil;
+
+/**
+ * @description: 签到签退
+ * @author: DingJie
+ * @create: 2021-05-28 15:57:26
+ **/
+@Slf4j
+@Service
+public class MedInsSignService {
+    @Value("${si-api-url}")
+    private String siApiUrl;
+    private static final String RESULT_CODE = "infcode";
+    private static final String OUTPUT = "output";
+    private static final String MAC_ADDR = "FE-FC-FE-35-35-DE";
+    private static final String IP_ADDR = "218.104.151.243";
+    private final MedicalInsuranceDao dao;
+    private volatile String signNo;
+
+    @Autowired
+    public MedInsSignService(MedicalInsuranceDao dao) {
+        this.dao = dao;
+    }
+
+    private synchronized String getSignNo() {
+        if (StringUtil.isBlank(signNo)) {
+            signIn();
+        }
+        return signNo;
+    }
+
+    public synchronized void signIn() {
+        JSONObject header = makeSignHeader(MedicalInsuranceFunction.SIGN_IN);
+        JSONObject signIn = new JSONObject();
+        signIn.put("opter_no", "99999");
+        signIn.put("mac", MAC_ADDR);
+        signIn.put("ip", IP_ADDR);
+        header.getJSONObject("input").put("signIn", signIn);
+        RestTemplate template = new RestTemplate();
+        JSONObject result = template.postForObject(siApiUrl, header, JSONObject.class);
+        log.info("医保签到:{}", result);
+        if (null != result && result.getIntValue(RESULT_CODE) == 0) {
+            JSONObject output = result.getJSONObject(OUTPUT);
+            signNo = output.getString("sign_no");
+        }
+    }
+
+    public void signOut() {
+        if (StringUtil.notBlank(signNo)) {
+            JSONObject header = makeSignHeader(MedicalInsuranceFunction.SIGN_OUT);
+            JSONObject signOut = new JSONObject();
+            signOut.put("sign_no", signNo);
+            signOut.put("opter_no", "99999");
+            header.getJSONObject("input").put("signOut", signOut);
+            RestTemplate template = new RestTemplate();
+            JSONObject result = template.postForObject(siApiUrl, header, JSONObject.class);
+            log.info("医保签退:{}", result);
+            if (null != result && result.getIntValue(RESULT_CODE) == 0) {
+                signNo = null;
+            }
+        }
+    }
+
+    private JSONObject makeSignHeader(MedicalInsuranceFunction function) {
+        JSONObject header = makePublicHeader();
+        header.put("infno", function.getCode());
+        header.put("opter", "99999");
+        header.put("opter_name", "全院");
+        return header;
+    }
+
+    public JSONObject makeTradeHeader(MedicalInsuranceFunction function) {
+        String staffId = TokenUtil.getTokenUserId();
+        String staffName = dao.selectStaffName(staffId);
+        JSONObject header = makePublicHeader();
+        header.put("infno", function.getCode());
+        header.put("opter", staffId);
+        header.put("opter_name", staffName);
+        header.replace("sign_no", getSignNo());
+        return header;
+    }
+
+    public JSONObject makePublicHeader() {
+        JSONObject header = new JSONObject();
+        JSONObject input = new JSONObject();
+        header.put("msgid", SiMsgIdUtil.makeMsgId());
+        header.put("mdtrtarea_admvs", "430105");
+        header.put("insuplc_admdvs", "");
+        // TODO: 2021-05-28 替换下方值
+        header.put("recer_sys_code", "接收方系统代码,用于多套系统接入,区分不同系统使用");
+        header.put("dev_no", "");
+        header.put("dev_safe_info", "");
+        header.put("cainfo", "");
+        header.put("signtype", "");
+        header.put("infver", "V1.0");
+        header.put("opter_type", "1");
+        header.put("inf_time", DateUtil.now());
+        header.put("fixmedins_code", SiMsgIdUtil.INSTITUTION_ID);
+        header.put("fixmedins_name", "湖南泰和医院");
+        header.put("sign_no", "");
+        header.put("input", input);
+        return header;
+    }
+}

+ 0 - 64
src/main/java/thyyxxk/webserver/service/medicalinsurance/MedicalInsuranceService.java

@@ -1,64 +0,0 @@
-package thyyxxk.webserver.service.medicalinsurance;
-
-import com.alibaba.fastjson.JSONObject;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-import org.springframework.web.client.RestTemplate;
-import thyyxxk.webserver.constants.MedicalInsuranceFunction;
-import thyyxxk.webserver.entity.ResultVo;
-import thyyxxk.webserver.utils.DateUtil;
-import thyyxxk.webserver.utils.SiMsgIdUtil;
-
-/**
- * @description: 医保交易实现
- * @author: DingJie
- * @create: 2021-05-14 16:28:16
- **/
-@Slf4j
-@Service
-public class MedicalInsuranceService {
-    @Value("${si-api-url}")
-    private String siApiUrl;
-
-    public ResultVo<JSONObject> obtainBasicPersonInfo(String socialNo, String name) {
-        JSONObject header = makeParamHeader(MedicalInsuranceFunction.OBTAIN_BASIC_PERSON_INFO);
-        JSONObject param = new JSONObject();
-        param.put("mdtrt_cert_type", "02");
-        param.put("mdtrt_cert_no", socialNo);
-        param.put("card_sn", "");
-        param.put("begintime", "");
-        param.put("psn_cert_type", "1");
-        param.put("certno", socialNo);
-        param.put("psn_name", name);
-        header.getJSONObject("input").put("data", param);
-        RestTemplate template = new RestTemplate();
-        JSONObject result = template.postForObject(siApiUrl, param, JSONObject.class);
-        return null;
-    }
-
-    private JSONObject makeParamHeader(MedicalInsuranceFunction function) {
-        JSONObject header = new JSONObject();
-        JSONObject input = new JSONObject();
-        header.put("infno", function.getCode());
-        header.put("msgid", SiMsgIdUtil.makeMsgId());
-        header.put("mdtrtarea_admvs", "就医地医保区划");
-        header.put("insuplc_admdvs", "参保地医保区划");
-        header.put("recer_sys_code", "接收方系统代码");
-        header.put("dev_no", "");
-        header.put("dev_safe_info", "");
-        header.put("cainfo", "");
-        header.put("signtype", "");
-        header.put("infver", "V1.0");
-        header.put("opter_type", "1");
-        header.put("opter", "经办人");
-        header.put("opter_name", "经办人姓名");
-        header.put("inf_time", DateUtil.now());
-        header.put("fixmedins_code", SiMsgIdUtil.INSTITUTION_ID);
-        header.put("fixmedins_name", "湖南泰和医院");
-        header.put("sign_no", "交易签到流水号");
-        header.put("input", input);
-        return header;
-    }
-
-}

+ 30 - 0
src/main/java/thyyxxk/webserver/service/medicalinsurance/MzMedInsService.java

@@ -0,0 +1,30 @@
+package thyyxxk.webserver.service.medicalinsurance;
+
+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 thyyxxk.webserver.dao.his.medicalinsurance.MedicalInsuranceDao;
+
+/**
+ * @description: 门诊医保交易
+ * @author: DingJie
+ * @create: 2021-05-28 16:11:19
+ **/
+@Slf4j
+@Service
+public class MzMedInsService {
+    @Value("${si-api-url}")
+    private String siApiUrl;
+    private final MedicalInsuranceDao dao;
+    private final MedInsSignService signService;
+    private static final String RESULT_CODE = "infcode";
+    private static final String ERROR_MESSAGE = "err_msg";
+    private static final String OUTPUT = "output";
+
+    @Autowired
+    public MzMedInsService(MedicalInsuranceDao dao, MedInsSignService signService) {
+        this.dao = dao;
+        this.signService = signService;
+    }
+}

+ 156 - 0
src/main/java/thyyxxk/webserver/service/medicalinsurance/ZyMedInsService.java

@@ -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) {
+//
+//    }
+
+
+}

+ 1 - 1
src/main/java/thyyxxk/webserver/utils/SiMsgIdUtil.java

@@ -12,7 +12,7 @@ public class SiMsgIdUtil {
     private static int serial = 1000;
     private static final int MIN_VAL = 1000;
     private static final int MAX_VAL = 9999;
-    public static final String INSTITUTION_ID = "430195333";
+    public static final String INSTITUTION_ID = "43010150145";
 
     private static String timestamp() {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");