123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package thyyxxk.webserver.service.dictionary;
- 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.dao.his.dictionary.HisWjwMatchDao;
- import thyyxxk.webserver.entity.dictionary.HisWjwMatchEntity;
- import thyyxxk.webserver.utils.StringUtil;
- import thyyxxk.webserver.utils.TokenUtil;
- import java.util.*;
- @Slf4j
- @Service
- public class HisWjwMatchService {
- private final HisWjwMatchDao dao;
- @Autowired
- public HisWjwMatchService(HisWjwMatchDao dao) {
- this.dao = dao;
- }
- public Map<String, List<HisWjwMatchEntity>> selectMatchableDataByLabel(String label) {
- String histable, wjwtable;
- int type;
- switch (label) {
- case "department":
- histable = "zd_unit_code";
- wjwtable = "t_wjw_dept";
- type = 1;
- break;
- case "anaesthesia":
- histable = "zd_anaesthesia";
- wjwtable = "t_wjw_anaesthesia";
- type = 1;
- break;
- case "diagnose":
- histable = "zd_icd_code_new";
- wjwtable = "t_si_dl_dss_dns";
- type = 2;
- break;
- case "surgery":
- histable = "zd_icd9_cm3";
- wjwtable = "t_si_dl_oprtn";
- type = 3;
- break;
- case "surgery_chargeCode":
- default:
- histable = "zd_icd9_cm3";
- wjwtable = "zd_charge_item";
- type = 4;
- break;
- }
- List<HisWjwMatchEntity> hisList;
- List<HisWjwMatchEntity> wjwList;
- if (type == 1) {
- hisList = dao.selectHisData(histable);
- wjwList = dao.selectWjwData(wjwtable);
- } else if (type == 4) {
- hisList = dao.selectSurgeries();
- wjwList = dao.selectChargeCodes();
- for (HisWjwMatchEntity entity : hisList) {
- if (null != entity.getWjwCode()) {
- entity.setChargeCodeString(entity.getWjwCode());
- entity.setChargeCode(entity.getWjwCode().split("\\^"));
- entity.setWjwCode(null);
- }
- if (null != entity.getWjwName()) {
- entity.setChargeNameString(entity.getWjwName());
- entity.setChargeName(entity.getWjwName().split("\\^"));
- entity.setWjwName(null);
- }
- }
- } else {
- hisList = dao.selectNationTempData(histable);
- wjwList = new ArrayList<>();
- }
- Map<String, List<HisWjwMatchEntity>> result = new HashMap<>();
- result.put("hisList", hisList);
- result.put("wjwList", wjwList);
- return result;
- }
- public List<HisWjwMatchEntity> fetchSimilarities(String label, String name, String key) {
- String table,codeColumn,nameColumn;
- if (label.equals("diagnose")) {
- table = "t_si_dl_dss_dns";
- codeColumn = "diagnosis_code";
- nameColumn = "diagnosis_name";
- } else {
- table = "t_si_dl_oprtn";
- codeColumn = "surgical_operation_code";
- nameColumn = "operation_operation_name";
- }
- List<HisWjwMatchEntity> list = dao.selectMedInsData(table, codeColumn, nameColumn, key);
- list.forEach(item -> {
- item.setSimilarity(StringUtil.getSimilarDegree(name, item.getName()));
- });
- list.sort(Comparator.comparingDouble(HisWjwMatchEntity::getSimilarity).reversed());
- return list;
- }
- public String executeMatchAction(HisWjwMatchEntity entity) {
- log.info("【操作员:{}】匹配卫健委/国临字典:{}", TokenUtil.getTokenUserId(), JSONObject.toJSONString(entity));
- if (entity.getLabel().equals("surgery_chargeCode")) {
- if (null != entity.getChargeCode()) {
- StringBuilder codeBuilder = new StringBuilder();
- StringBuilder nameBuilder = new StringBuilder();
- for (String code : entity.getChargeCode()) {
- codeBuilder.append(code).append('^');
- }
- if (codeBuilder.length() > 1) {
- entity.setWjwCode(codeBuilder.substring(0, codeBuilder.length() - 1));
- }
- for (String name : entity.getChargeName()) {
- nameBuilder.append(name).append('^');
- }
- if (nameBuilder.length() > 1) {
- entity.setWjwName(nameBuilder.substring(0, nameBuilder.length() - 1));
- }
- }
- dao.updateDateAndOper(entity.getCode(), TokenUtil.getTokenUserId());
- }
- dao.executeMatchAction(entity);
- return StringUtil.isBlank(entity.getWjwCode()) ? "撤销匹配成功" : "匹配成功";
- }
- }
|