| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.smartor.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.ruoyi.common.core.domain.entity.PatArchive; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.outpatientvisit.domain.PatMedOuthosp; |
| | | import com.ruoyi.patarchive.domain.PatSpecificArchiveGenerateConfig; |
| | | import com.ruoyi.patarchive.mapper.PatArchiveMapper; |
| | | import com.ruoyi.patarchive.service.IPatSpecificArchiveGenerateConfigService; |
| | | import com.smartor.common.SpecificArchiveConstants; |
| | | import com.smartor.domain.PatChildArchiveDetail; |
| | | import com.smartor.domain.PatMaternityArchiveDetail; |
| | | import com.smartor.service.IPatChildArchiveService; |
| | | import com.smartor.service.IPatMaternityArchiveService; |
| | | import com.smartor.service.IPatSpecificArchiveGenerateService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * ä¸ç§æ¡£æ¡çæServiceä¸å¡å±å¤çã |
| | | * |
| | | * <p>åªå¤ç丽水å¸å¦å¹¼ä¿å¥é¢ï¼orgid = 47226079133110211G1001ï¼çé¨è¯æ¥è¯å®æè®°å½ï¼ |
| | | * æ {@code pat_specific_archive_generate_config} é
ç½®å¹é
ç§å®¤åè¯æåï¼ |
| | | * çæå¯¹åºç±»åçå¦ç§æ¡£æ¡æå¿ç§æ¡£æ¡ã</p> |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class PatSpecificArchiveGenerateServiceImpl implements IPatSpecificArchiveGenerateService { |
| | | |
| | | /** é¨é¨åç±»ï¼å¦ç§ */ |
| | | private static final String DEPT_CATEGORY_GYNECOLOGY = "1"; |
| | | /** é¨é¨åç±»ï¼å¿ç§ */ |
| | | private static final String DEPT_CATEGORY_PEDIATRICS = "2"; |
| | | /** é¨é¨ç±»åï¼ç§å®¤ */ |
| | | private static final String DEPT_TYPE_DEPARTMENT = "1"; |
| | | /** æ¥æºç±»åï¼é¨è¯è®°å½ */ |
| | | private static final String SOURCE_TYPE_OUTHOSP = "1"; |
| | | |
| | | @Autowired |
| | | private IPatSpecificArchiveGenerateConfigService patSpecificArchiveGenerateConfigService; |
| | | |
| | | @Autowired |
| | | private IPatMaternityArchiveService patMaternityArchiveService; |
| | | |
| | | @Autowired |
| | | private IPatChildArchiveService patChildArchiveService; |
| | | |
| | | @Autowired |
| | | private PatArchiveMapper patArchiveMapper; |
| | | |
| | | @Override |
| | | public int generateByOuthosp(PatMedOuthosp patMedOuthosp, PatArchive patArchive) { |
| | | if (patMedOuthosp == null) { |
| | | return 0; |
| | | } |
| | | // ä»
丽水å¸å¦å¹¼ä¿å¥é¢çæï¼é¿å
å½±åå
¶ä»æºæ |
| | | if (!SpecificArchiveConstants.LISHUI_MCH_ORG_ID.equals(patMedOuthosp.getOrgid())) { |
| | | return 0; |
| | | } |
| | | if (StringUtils.isBlank(patMedOuthosp.getOuthospno())) { |
| | | log.warn("çæä¸ç§æ¡£æ¡è·³è¿ï¼é¨è¯ç¼å·ä¸ºç©ºï¼serialnum={}", patMedOuthosp.getSerialnum()); |
| | | return 0; |
| | | } |
| | | |
| | | PatArchive targetArchive = resolvePatArchive(patMedOuthosp, patArchive); |
| | | if (targetArchive == null && patMedOuthosp.getPatid() != null) { |
| | | targetArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOuthosp.getPatid()); |
| | | } |
| | | Long patid = targetArchive != null ? targetArchive.getId() : patMedOuthosp.getPatid(); |
| | | if (patid == null) { |
| | | log.warn("çæä¸ç§æ¡£æ¡è·³è¿ï¼æªæ¾å°æ£è
æ¡£æ¡ï¼outhospno={}ï¼patno={}", |
| | | patMedOuthosp.getOuthospno(), patMedOuthosp.getPatno()); |
| | | return 0; |
| | | } |
| | | |
| | | String campusid = StringUtils.isNotBlank(patMedOuthosp.getCampusid()) |
| | | ? patMedOuthosp.getCampusid() : "1"; |
| | | List<PatSpecificArchiveGenerateConfig> configs = |
| | | patSpecificArchiveGenerateConfigService.selectEffectiveConfigList(patMedOuthosp.getOrgid(), campusid); |
| | | if (CollectionUtils.isEmpty(configs)) { |
| | | log.debug("çæä¸ç§æ¡£æ¡è·³è¿ï¼æºææªé
置档æ¡çæè§åï¼orgid={}ï¼campusid={}", |
| | | patMedOuthosp.getOrgid(), campusid); |
| | | return 0; |
| | | } |
| | | |
| | | // å䏿¡é¨è¯è®°å½ãåä¸é¨é¨åç±»ãå䏿¡£æ¡ç±»ååªçæä¸æ¬¡ |
| | | Set<String> generatedKeys = new HashSet<>(); |
| | | int generatedCount = 0; |
| | | for (PatSpecificArchiveGenerateConfig config : configs) { |
| | | if (!matchConfig(config, patMedOuthosp)) { |
| | | continue; |
| | | } |
| | | String archiveType = config.getArchiveType(); |
| | | String deptCategory = config.getDeptCategory(); |
| | | if (StringUtils.isBlank(archiveType) || StringUtils.isBlank(deptCategory)) { |
| | | log.warn("çæä¸ç§æ¡£æ¡è·³è¿ï¼é
ç½®ä¸å®æ´ï¼configId={}ï¼deptCategory={}ï¼archiveType={}", |
| | | config.getId(), deptCategory, archiveType); |
| | | continue; |
| | | } |
| | | |
| | | String generatedKey = deptCategory + "|" + archiveType; |
| | | if (!generatedKeys.add(generatedKey)) { |
| | | continue; |
| | | } |
| | | |
| | | try { |
| | | if (DEPT_CATEGORY_GYNECOLOGY.equals(deptCategory)) { |
| | | PatMaternityArchiveDetail detail = |
| | | buildMaternityDetail(patMedOuthosp, targetArchive, config, campusid); |
| | | patMaternityArchiveService.insertOrUpdateMaternityArchive(detail); |
| | | generatedCount++; |
| | | } else if (DEPT_CATEGORY_PEDIATRICS.equals(deptCategory)) { |
| | | PatChildArchiveDetail detail = |
| | | buildChildDetail(patMedOuthosp, targetArchive, config, campusid); |
| | | patChildArchiveService.insertOrUpdateChildArchive(detail); |
| | | generatedCount++; |
| | | } else { |
| | | log.warn("çæä¸ç§æ¡£æ¡è·³è¿ï¼æªç¥é¨é¨åç±»ï¼configId={}ï¼deptCategory={}", |
| | | config.getId(), deptCategory); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("çæä¸ç§æ¡£æ¡å¤±è´¥ï¼configId={}ï¼outhospno={}ï¼deptCategory={}ï¼archiveType={}", |
| | | config.getId(), patMedOuthosp.getOuthospno(), deptCategory, archiveType, e); |
| | | } |
| | | } |
| | | return generatedCount; |
| | | } |
| | | |
| | | /** |
| | | * 夿é¨è¯è®°å½æ¯å¦å½ä¸é
ç½®ã |
| | | * |
| | | * <p>é¨é¨æ¡ä»¶ä¸è¯ææ¡ä»¶ä¸º OR å
³ç³»ï¼ä»»ä¸æ¡ä»¶å½ä¸å³çæï¼ä¸¤ä¸ªéåé½ä¸ºç©ºæ¶é
ç½®æ æã</p> |
| | | */ |
| | | private boolean matchConfig(PatSpecificArchiveGenerateConfig config, PatMedOuthosp patMedOuthosp) { |
| | | List<String> deptCodes = parseCodes(config.getDeptCodes()); |
| | | List<String> icd10Codes = parseCodes(config.getIcd10Codes()); |
| | | if (CollectionUtils.isEmpty(deptCodes) && CollectionUtils.isEmpty(icd10Codes)) { |
| | | return false; |
| | | } |
| | | |
| | | boolean deptMatched = false; |
| | | if (CollectionUtils.isNotEmpty(deptCodes)) { |
| | | // é¨è¯è®°å½åªæç§å®¤ï¼æ²¡æç
åºï¼dept_type=2ï¼ç
åºï¼ä¸åä¸é¨è¯å¹é
|
| | | if (DEPT_TYPE_DEPARTMENT.equals(config.getDeptType())) { |
| | | deptMatched = containsIgnoreCase(deptCodes, patMedOuthosp.getDeptcode()); |
| | | } |
| | | } |
| | | |
| | | boolean diagnosisMatched = false; |
| | | if (CollectionUtils.isNotEmpty(icd10Codes)) { |
| | | String icd10code = patMedOuthosp.getIcd10code(); |
| | | String diagname = patMedOuthosp.getDiagname(); |
| | | diagnosisMatched = icd10Codes.stream().anyMatch(code -> { |
| | | if (equalsIgnoreCase(code, icd10code)) { |
| | | return true; |
| | | } |
| | | // é¨å HIS æ°æ®åªæè¯æå称没æè¯æç ï¼æ¤æ¶å
许æè¯æåç§°å
åºå¹é
|
| | | return StringUtils.isBlank(icd10code) && equalsIgnoreCase(code, diagname); |
| | | }); |
| | | } |
| | | |
| | | return deptMatched || diagnosisMatched; |
| | | } |
| | | |
| | | private PatMaternityArchiveDetail buildMaternityDetail(PatMedOuthosp patMedOuthosp, PatArchive patArchive, |
| | | PatSpecificArchiveGenerateConfig config, String campusid) { |
| | | PatMaternityArchiveDetail detail = new PatMaternityArchiveDetail(); |
| | | detail.setArchiveType(config.getArchiveType()); |
| | | detail.setSourceType(SOURCE_TYPE_OUTHOSP); |
| | | fillCommonDetail(detail, patMedOuthosp, patArchive, campusid); |
| | | if (patArchive != null) { |
| | | detail.setAddress(patArchive.getPlaceOfResidence()); |
| | | } |
| | | return detail; |
| | | } |
| | | |
| | | private PatChildArchiveDetail buildChildDetail(PatMedOuthosp patMedOuthosp, PatArchive patArchive, |
| | | PatSpecificArchiveGenerateConfig config, String campusid) { |
| | | PatChildArchiveDetail detail = new PatChildArchiveDetail(); |
| | | detail.setArchiveType(config.getArchiveType()); |
| | | detail.setSourceType(SOURCE_TYPE_OUTHOSP); |
| | | fillCommonChildDetail(detail, patMedOuthosp, patArchive, campusid); |
| | | detail.setParentPhone(patArchive != null |
| | | ? firstNotBlank(patArchive.getTelcode(), patMedOuthosp.getTelcode()) |
| | | : patMedOuthosp.getTelcode()); |
| | | if (patArchive != null) { |
| | | detail.setParentAddress(patArchive.getPlaceOfResidence()); |
| | | } |
| | | // è¥å
»æ§ç¾ç
æ¡£æ¡åæ¥è¯æä¿¡æ¯ï¼æ¹ä¾¿åè¡¨ç´æ¥å±ç¤º |
| | | if ("1".equals(config.getArchiveType())) { |
| | | detail.setNutritionIcd10Code(patMedOuthosp.getIcd10code()); |
| | | detail.setNutritionDiagName(patMedOuthosp.getDiagname()); |
| | | } |
| | | return detail; |
| | | } |
| | | |
| | | private void fillCommonDetail(PatMaternityArchiveDetail detail, PatMedOuthosp patMedOuthosp, |
| | | PatArchive patArchive, String campusid) { |
| | | detail.setOuthospno(patMedOuthosp.getOuthospno()); |
| | | detail.setSerialnum(patMedOuthosp.getSerialnum()); |
| | | detail.setPatid(patArchive != null ? patArchive.getId() : patMedOuthosp.getPatid()); |
| | | detail.setPatname(patArchive != null |
| | | ? firstNotBlank(patArchive.getName(), patMedOuthosp.getPatname()) : patMedOuthosp.getPatname()); |
| | | detail.setBirthdate(patArchive != null ? patArchive.getBirthdate() : null); |
| | | detail.setIdcardno(patArchive != null |
| | | ? firstNotBlank(patArchive.getIdcardno(), patMedOuthosp.getIdcardno()) : patMedOuthosp.getIdcardno()); |
| | | detail.setPhone(patArchive != null |
| | | ? firstNotBlank(patArchive.getTelcode(), patMedOuthosp.getTelcode()) : patMedOuthosp.getTelcode()); |
| | | detail.setSex(patArchive != null && patArchive.getSex() != null |
| | | ? patArchive.getSex() : patMedOuthosp.getSex()); |
| | | detail.setDiagTime(patMedOuthosp.getAdmitdate()); |
| | | detail.setArchiveTime(new Date()); |
| | | detail.setDoctorCode(patMedOuthosp.getDrcode()); |
| | | detail.setDoctorName(patMedOuthosp.getDrname()); |
| | | detail.setManagementDoctorCode(patMedOuthosp.getDrcode()); |
| | | detail.setManagementDoctorName(patMedOuthosp.getDrname()); |
| | | detail.setFirstDoctorCode(patMedOuthosp.getDrcode()); |
| | | detail.setFirstDoctorName(patMedOuthosp.getDrname()); |
| | | detail.setDeptcode(patMedOuthosp.getDeptcode()); |
| | | detail.setDeptname(patMedOuthosp.getDeptname()); |
| | | detail.setIcd10code(patMedOuthosp.getIcd10code()); |
| | | detail.setDiagname(patMedOuthosp.getDiagname()); |
| | | detail.setRegisterUser(patMedOuthosp.getDrname()); |
| | | detail.setOrgid(patMedOuthosp.getOrgid()); |
| | | detail.setCampusid(campusid); |
| | | detail.setDelFlag("0"); |
| | | } |
| | | |
| | | private void fillCommonChildDetail(PatChildArchiveDetail detail, PatMedOuthosp patMedOuthosp, |
| | | PatArchive patArchive, String campusid) { |
| | | detail.setOuthospno(patMedOuthosp.getOuthospno()); |
| | | detail.setSerialnum(patMedOuthosp.getSerialnum()); |
| | | detail.setPatid(patArchive != null ? patArchive.getId() : patMedOuthosp.getPatid()); |
| | | detail.setPatname(patArchive != null |
| | | ? firstNotBlank(patArchive.getName(), patMedOuthosp.getPatname()) : patMedOuthosp.getPatname()); |
| | | detail.setBirthdate(patArchive != null ? patArchive.getBirthdate() : null); |
| | | detail.setIdcardno(patArchive != null |
| | | ? firstNotBlank(patArchive.getIdcardno(), patMedOuthosp.getIdcardno()) : patMedOuthosp.getIdcardno()); |
| | | detail.setPhone(patArchive != null |
| | | ? firstNotBlank(patArchive.getTelcode(), patMedOuthosp.getTelcode()) : patMedOuthosp.getTelcode()); |
| | | detail.setSex(patArchive != null && patArchive.getSex() != null |
| | | ? patArchive.getSex() : patMedOuthosp.getSex()); |
| | | detail.setDiagTime(patMedOuthosp.getAdmitdate()); |
| | | detail.setArchiveTime(new Date()); |
| | | detail.setDoctorCode(patMedOuthosp.getDrcode()); |
| | | detail.setDoctorName(patMedOuthosp.getDrname()); |
| | | detail.setManagementDoctorCode(patMedOuthosp.getDrcode()); |
| | | detail.setManagementDoctorName(patMedOuthosp.getDrname()); |
| | | detail.setDeptcode(patMedOuthosp.getDeptcode()); |
| | | detail.setDeptname(patMedOuthosp.getDeptname()); |
| | | detail.setIcd10code(patMedOuthosp.getIcd10code()); |
| | | detail.setDiagname(patMedOuthosp.getDiagname()); |
| | | detail.setRegisterUser(patMedOuthosp.getDrname()); |
| | | detail.setOrgid(patMedOuthosp.getOrgid()); |
| | | detail.setCampusid(campusid); |
| | | detail.setDelFlag("0"); |
| | | } |
| | | |
| | | private PatArchive resolvePatArchive(PatMedOuthosp patMedOuthosp, PatArchive patArchive) { |
| | | if (patArchive != null && patArchive.getId() != null) { |
| | | return patArchive; |
| | | } |
| | | |
| | | PatArchive query = new PatArchive(); |
| | | if (StringUtils.isNotBlank(patMedOuthosp.getPatno())) { |
| | | query.setPatientno(patMedOuthosp.getPatno()); |
| | | } else if (StringUtils.isNotBlank(patMedOuthosp.getIdcardno())) { |
| | | query.setIdcardno(patMedOuthosp.getIdcardno()); |
| | | } else { |
| | | return null; |
| | | } |
| | | query.setOrgid(patMedOuthosp.getOrgid()); |
| | | |
| | | List<PatArchive> archives = patArchiveMapper.selectPatArchiveList(query); |
| | | return CollectionUtils.isNotEmpty(archives) ? archives.get(0) : null; |
| | | } |
| | | |
| | | private List<String> parseCodes(String raw) { |
| | | if (StringUtils.isBlank(raw)) { |
| | | return Collections.emptyList(); |
| | | } |
| | | String value = raw.trim(); |
| | | try { |
| | | JSONArray array = JSON.parseArray(value); |
| | | if (array != null) { |
| | | List<String> result = new ArrayList<>(); |
| | | for (Object item : array) { |
| | | if (item != null && StringUtils.isNotBlank(String.valueOf(item))) { |
| | | result.add(String.valueOf(item).trim()); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | } catch (Exception e) { |
| | | log.warn("è§£ææ¡£æ¡çæé
ç½®éåå¤±è´¥ï¼æéå·åéå¤çï¼{}", raw); |
| | | } |
| | | return Arrays.stream(value.split(",")) |
| | | .map(String::trim) |
| | | .filter(StringUtils::isNotBlank) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | private String firstNotBlank(String first, String second) { |
| | | return StringUtils.isNotBlank(first) ? first : second; |
| | | } |
| | | |
| | | private boolean containsIgnoreCase(List<String> source, String target) { |
| | | if (StringUtils.isBlank(target)) { |
| | | return false; |
| | | } |
| | | return source.stream().anyMatch(item -> equalsIgnoreCase(item, target)); |
| | | } |
| | | |
| | | private boolean equalsIgnoreCase(String first, String second) { |
| | | return first != null && second != null && first.trim().equalsIgnoreCase(second.trim()); |
| | | } |
| | | } |