From 28446c1489c8977d634e7a39dbbc96967e22c6f1 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期一, 11 五月 2026 11:32:31 +0800
Subject: [PATCH] 代码提交

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java |  136 ++++++++++++++++++++++++++++++++++++--------
 1 files changed, 110 insertions(+), 26 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
index 6df1fae..fe2ceb1 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
@@ -79,7 +79,8 @@
         try {
             Map<String, Object> requestParams = buildRequestParams(reqVO);
             Map<String, String> headers = buildRequestHeaders();
-            String result = HttpUtils.sendPostByHeader(sltdPubPath + "osj/hbos-thirdparty-integration/standard/common/healthcareRecord/dtcQueryHealthcareRecordList", new Gson().toJson(requestParams), headers);
+            log.info("璇锋眰鍙傛暟鍑洪櫌鏁版嵁鍦板潃锛歿},appKey:{}", sltdPubPath + "/osj/hbos-thirdparty-integration/standard/common/healthcareRecord/dtcQueryHealthcareRecordList", APP_KEY);
+            String result = HttpUtils.sendPostByHeader(sltdPubPath + "/osj/hbos-thirdparty-integration/standard/common/healthcareRecord/dtcQueryHealthcareRecordList", new Gson().toJson(requestParams), headers);
 
             String cry = determineCry(reqVO);
             log.info("cry鐨勫�间负锛歿}", cry);
@@ -88,7 +89,7 @@
             return serviceSLTDInhospResDTOS;
         } catch (Exception e) {
             log.error("銆恞ueryHealthcareRecordList銆戣皟鐢ㄧ渷绔嬪悓寰峰仴搴疯褰曟煡璇㈡帴鍙e紓甯革紝璇锋眰鍙傛暟锛歿}", reqVO, e);
-            throw new RuntimeException("璋冪敤鐪佺珛鍚屽痉鍋ュ悍璁板綍鏌ヨ鎺ュ彛澶辫触", e);
+            throw new RuntimeException("璋冪敤鐪佺珛鍚屽痉鍋ュ悍璁板綍鏌ヨ鎺ュ彛澶辫触:" + e.getMessage());
         }
     }
 
@@ -166,10 +167,15 @@
                 sysDept.setUpdateTime(new Date());
                 sysDept.setUpdateBy(null);
 
-                SysDept sysDept1 = sysDeptMapper.selectDeptByCode(sysDept.getDeptCode(), sysDept.getOrgid());
+                // 鎸� deptCode + orgid + campusid 鏌ラ噸锛岄伩鍏嶈法闄㈠尯绉戝閲嶅
+                SysDept sysDept1 = sysDeptMapper.selectDeptByCodeAndCampus(sysDept.getDeptCode(), sysDept.getOrgid(), sysDept.getCampusid());
                 if (Objects.isNull(sysDept1)) {
-                    int i = sysDeptMapper.insertDept(sysDept);
-                    log.info("ServiceExternalServiceImpl---addDeptInfo鏄惁鏂板鎴愬姛锛歿}", i);
+                    try {
+                        int i = sysDeptMapper.insertDept(sysDept);
+                        log.info("ServiceExternalServiceImpl---addDeptInfo鏄惁鏂板鎴愬姛锛歿}", i);
+                    } catch (org.springframework.dao.DuplicateKeyException e) {
+                        log.warn("銆恞ueryDeptWardAreaInfoList銆戠瀹ゅ凡瀛樺湪(骞跺彂鎻掑叆)锛岃烦杩囷細deptCode={}, orgid={}, campusid={}", sysDept.getDeptCode(), sysDept.getOrgid(), sysDept.getCampusid());
+                    }
                 } else {
                     sysDept.setDeptId(sysDept1.getDeptId());
                     int i = sysDeptMapper.updateDept(sysDept);
@@ -247,19 +253,29 @@
             sysUser.setUpdateTime(new Date());
             sysUser.setUpdateBy("admin");
             sysUser.setCreateBy("admin");
-            sysUser.setCreateBy("admin");
             sysUser.setOrgid("" + getLongValue(dataItem, "orgId"));
             BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
             sysUser.setPassword(passwordEncoder.encode(userPwd));
             SysUser sysUser1 = sysUser2Mapper.selectUserByUserName(sysUser.getUserName());
             if (ObjectUtils.isNotEmpty(sysUser1)) {
-                //鐢变汉宸ョ淮鎶ょ殑瀛楁鏄笉闇�瑕佹洿鏂扮殑
+                //宸插瓨鍦細鐢变汉宸ョ淮鎶ょ殑瀛楁鏄笉闇�瑕佹洿鏂扮殑锛宱rgid/campusid淇濈暀鍘熷�间笉瑕嗙洊
                 sysUser.setSearchscope(null);
                 sysUser.setPassword(null);
                 sysUser.setUserId(sysUser1.getUserId());
+                sysUser.setOrgid(null);
+                sysUser.setCampusid(null);
                 sysUser2Mapper.updateUser(sysUser);
             } else {
-                sysUser2Mapper.insertUser(sysUser);
+                try {
+                    sysUser2Mapper.insertUser(sysUser);
+                } catch (org.springframework.dao.DuplicateKeyException e) {
+                    //骞跺彂鎻掑叆鍦烘櫙锛氶噸鏂版煡璇㈣幏鍙栧凡瀛樺湪璁板綍锛岄伩鍏嶉噸澶�
+                    log.warn("銆恞ueryHospUserInfoList銆戠敤鎴峰凡瀛樺湪(骞跺彂鎻掑叆)锛岃烦杩囷細userName={}", sysUser.getUserName());
+                    SysUser existingUser = sysUser2Mapper.selectUserByUserName(sysUser.getUserName());
+                    if (ObjectUtils.isNotEmpty(existingUser)) {
+                        sysUser.setUserId(existingUser.getUserId());
+                    }
+                }
             }
 
             // 澶勭悊鐢ㄦ埛涓庨儴闂ㄧ殑鍏崇郴
@@ -274,8 +290,8 @@
                         log.info("------businessDeptMap鏄惁鏈夊�硷細{}", businessDeptMap);
                         String hisDeptId = getStringValue(businessDeptMap, "deptId");
                         log.info("------hisDeptId鏄惁鏈夊�硷細{}, reqVO.getOrgId()鐨勫�间负:{}", hisDeptId, reqVO.getCampusId());
-                        //鍦ㄨ繖閲岋紝hisDeptId灏辨槸deptCode
-                        SysDept sysDept = sysDeptMapper.selectDeptByCode(hisDeptId, reqVO.getOrgId());
+                        //鍦ㄨ繖閲岋紝hisDeptId灏辨槸deptCode锛屾寜闄㈠尯+鏈烘瀯鏌ョ瀹わ紝閬垮厤璺ㄩ櫌鍖烘煡閿�
+                        SysDept sysDept = sysDeptMapper.selectDeptByCodeAndCampus(hisDeptId, reqVO.getOrgId(), reqVO.getCampusId() != null ? reqVO.getCampusId().toString() : null);
                         log.info("------hisDeptId鏄惁鏈夊�硷細{}, reqVO.getCampusId()鐨勫�间负:{}", hisDeptId, reqVO.getCampusId());
                         if (Objects.isNull(sysDept)) continue;
                         SysUserDept sysUserDept = new SysUserDept();
@@ -594,8 +610,10 @@
                 queryInhosp.setInhospstate("3");
                 List<PatMedInhosp> patMedInhospList = patMedInhospService.selectPatMedInhosp(queryInhosp);
                 if (CollectionUtils.isNotEmpty(patMedInhospList)) {
-                    //濡傛灉棰勫叆闄笉涓虹┖锛屽垯杩涜淇敼
+                    //濡傛灉棰勫叆闄笉涓虹┖锛屽垯杩涜淇敼锛堥鍏ラ櫌鈫掑叆闄級
+                    patMedInhosp.setInhospid(patMedInhospList.get(0).getInhospid());
                     patMedInhospService.updatePatMedInhosp(patMedInhosp);
+                    log.info("鐢遍鍏ラ櫌鏇存柊涓哄叆闄細serialnum={}", patMedInhosp.getSerialnum());
                 } else {
                     //濡傛灉鍑洪櫌涓嶄负绌猴紝鍒欎笉杩涜澶勭悊
                     queryInhosp.setInhospstate("1");
@@ -672,6 +690,8 @@
             if (locked == null || Boolean.TRUE.equals(locked)) {
                 try {
                     queryInhosp.setInhospstate(null);
+                    queryInhosp.setSchemestatus(null);
+                    queryInhosp.setPatno(null);
                     List<PatMedInhosp> patMedInhospList3 = patMedInhospService.selectPatMedInhosp(queryInhosp);
                     if (CollectionUtils.isEmpty(patMedInhospList3)) {
                         try {
@@ -707,11 +727,43 @@
         patMedInhosp.setSerialnum(dto.getHealthcareRecordNo());
         patMedInhosp.setInhospno(dto.getHealthcareRecordNo());
         patMedInhosp.setFuflag("1");
+
+
         if (StringUtils.isNotEmpty(patArchive.getNotrequiredFlag()) && patArchive.getNotrequiredFlag().equals("1"))
             patMedInhosp.setFuflag("0");
-        if ("0".equals(cry)) patMedInhosp.setInhospstate("0");
-        if ("1".equals(cry)) patMedInhosp.setInhospstate("1");
-        if ("3".equals(cry)) patMedInhosp.setInhospstate("3");
+        if ("0".equals(cry)) {
+            patMedInhosp.setInhospstate("0");
+            if (CollectionUtils.isNotEmpty(dto.getDiagnosisList()) && dto.getDiagnosisList().size() > 0) {
+                for (ServiceSLTDDiagnosisResDTO diagnosis : dto.getDiagnosisList()) {
+                    if (diagnosis.getIsMainDiagnosis() == 1) {
+                        patMedInhosp.setDiagname(diagnosis.getDiagnosisDictName() == null ? "" : diagnosis.getDiagnosisDictName());
+                        patMedInhosp.setIcd10code(diagnosis.getDiagnosisDictCode() == null ? "" : diagnosis.getDiagnosisDictCode());
+                    }
+                }
+            }
+        }
+        if ("1".equals(cry)) {
+            patMedInhosp.setInhospstate("1");
+            ServiceSLTDDiagnosisResDTO mainDischargeDiagnosis = dto.getMainDischargeDiagnosis();
+            log.info("-----------mainDischargeDiagnosis鐨勫�兼湁浜嗗悧?{}", mainDischargeDiagnosis);
+            if (!Objects.isNull(mainDischargeDiagnosis)) {
+                if (mainDischargeDiagnosis.getIsMainDiagnosis() == 1) {
+                    patMedInhosp.setLeavediagname(StringUtils.defaultString(mainDischargeDiagnosis.getDiagnosisDictName(), ""));
+                    patMedInhosp.setLeaveicd10code(StringUtils.defaultString(mainDischargeDiagnosis.getDiagnosisDictCode(), ""));
+                }
+            }
+        }
+        if ("3".equals(cry)) {
+            patMedInhosp.setInhospstate("3");
+            if (CollectionUtils.isNotEmpty(dto.getDiagnosisList()) && dto.getDiagnosisList().size() > 0) {
+                for (ServiceSLTDDiagnosisResDTO diagnosis : dto.getDiagnosisList()) {
+                    if (diagnosis.getIsMainDiagnosis() == 1) {
+                        patMedInhosp.setDiagname(diagnosis.getDiagnosisDictName() == null ? "" : diagnosis.getDiagnosisDictName());
+                        patMedInhosp.setIcd10code(diagnosis.getDiagnosisDictCode() == null ? "" : diagnosis.getDiagnosisDictCode());
+                    }
+                }
+            }
+        }
         patMedInhosp.setHospitalcode(dto.getOrgId());
         patMedInhosp.setBedNo(dto.getBedNumber());
         patMedInhosp.setStarttime(parseDate(dto.getStartTime()));
@@ -758,24 +810,46 @@
     private PatArchive processPatientArchive(ServiceSLTDInhospResDTO dto) {
         List<PatArchive> existingArchives = null;
 
-        // 浼樺厛鎸� patientno 绮剧‘鏌ラ噸锛屾煡涓嶅埌鍐嶆寜 idcardno 鏌ラ噸锛圓ND鏉′欢浼氭紡鏌ュ悓涓�浜轰笉鍚宲atientno鐨勬儏鍐碉級
-        if (dto.getPatientId() != null) {
+        // 绗竴姝ワ細鎸� patientno 绮剧‘鏌ラ噸锛堜笌鎻掑叆鏃朵娇鐢ㄧ殑 medicalRecordNo 涓�鑷达級
+        String patientno = dto.getMedicalRecordNo() == null ? null : String.valueOf(dto.getMedicalRecordNo());
+        if (StringUtils.isNotEmpty(patientno)) {
             PatArchive queryByPatientNo = new PatArchive();
-            queryByPatientNo.setPatientno(String.valueOf(dto.getPatientId()));
-            queryByPatientNo.setIdcardno(StringUtils.isNotEmpty(dto.getIdCardNo()) ? dto.getIdCardNo().trim() : null);
+            queryByPatientNo.setPatientno(patientno);
             existingArchives = patArchiveService.selectPatArchiveList(queryByPatientNo);
         }
-//        if (CollectionUtils.isEmpty(existingArchives) && !StringUtils.isEmpty(dto.getIdCardNo())) {
-//            PatArchive queryByIdCard = new PatArchive();
-//            queryByIdCard.setIdcardno(dto.getIdCardNo().trim());
-//            existingArchives = patArchiveService.selectPatArchiveList(queryByIdCard);
-//        }
+
+        // 绗簩姝ワ細鎸� patientno 鏌ヤ笉鍒版椂锛屾寜 idcardno 鏌ラ噸锛堝垎姝R锛岄伩鍏岮ND鏉′欢婕忔煡锛�
+        if (CollectionUtils.isEmpty(existingArchives) && StringUtils.isNotEmpty(dto.getIdCardNo())) {
+            PatArchive queryByIdCard = new PatArchive();
+            queryByIdCard.setIdcardno(dto.getIdCardNo().trim());
+            existingArchives = patArchiveService.selectPatArchiveList(queryByIdCard);
+        }
+
+        // 绗笁姝ワ細鎸� patidHis 鏌ラ噸锛堝吋瀹规棫鏁版嵁锛屾棫鏁版嵁鍙兘浠� patientId 瀛樹负 patientno锛�
+        if (CollectionUtils.isEmpty(existingArchives) && dto.getPatientId() != null) {
+            PatArchive queryByPatidHis = new PatArchive();
+            queryByPatidHis.setPatientno(String.valueOf(dto.getPatientId()));
+            existingArchives = patArchiveService.selectPatArchiveList(queryByPatidHis);
+        }
 
         PatArchive patArchive = buildPatientArchive(dto);
 
         if (CollectionUtils.isEmpty(existingArchives)) {
-            patArchiveService.insertPatArchive(patArchive);
-            log.debug("銆恜rocessPatientArchive銆戞柊澧炴偅鑰呮。妗堬紝鎮h�呯紪鍙凤細{}", patArchive.getPatientno());
+            try {
+                patArchiveService.insertPatArchive(patArchive);
+                log.debug("銆恜rocessPatientArchive銆戞柊澧炴偅鑰呮。妗堬紝鎮h�呯紪鍙凤細{}", patArchive.getPatientno());
+            } catch (org.springframework.dao.DuplicateKeyException e) {
+                log.warn("銆恜rocessPatientArchive銆戞偅鑰呮。妗堝凡瀛樺湪(骞跺彂鎻掑叆)锛岃烦杩囷細patientno={}, idcardno={}", patArchive.getPatientno(), patArchive.getIdcardno());
+                // 骞跺彂鎻掑叆鍦烘櫙锛岄噸鏂版煡璇㈣幏鍙栧凡瀛樺湪鐨勮褰�
+                PatArchive queryRetry = new PatArchive();
+                queryRetry.setPatientno(patArchive.getPatientno());
+                existingArchives = patArchiveService.selectPatArchiveList(queryRetry);
+                if (CollectionUtils.isNotEmpty(existingArchives)) {
+                    patArchive.setId(existingArchives.get(0).getId());
+                    patArchive.setNotrequiredFlag(existingArchives.get(0).getNotrequiredFlag());
+                    patArchive.setNotrequiredreason(existingArchives.get(0).getNotrequiredreason());
+                }
+            }
         } else {
             patArchive.setId(existingArchives.get(0).getId());
             patArchive.setNotrequiredFlag(existingArchives.get(0).getNotrequiredFlag());
@@ -869,7 +943,17 @@
         dto.setCostNatureName(getStringValue(dataItem, "costNatureName"));
         dto.setCostNatureCode(getStringValue(dataItem, "costNatureCode"));
         dto.setFurtherConsultationStatus(getIntegerValue(dataItem, "furtherConsultationStatus"));
-
+        Object mainDiagObj = dataItem.get("mainDischargeDiagnosis");
+        if (mainDiagObj instanceof Map) {
+            Map<String, Object> mainDiagMap = (Map<String, Object>) mainDiagObj;
+            ServiceSLTDDiagnosisResDTO mainDiag = new ServiceSLTDDiagnosisResDTO();
+            mainDiag.setDiagnosisDictCode(getStringValue(mainDiagMap, "diagnosisDictCode"));
+            mainDiag.setDiagnosisDictName(getStringValue(mainDiagMap, "diagnosisDictName"));
+            mainDiag.setDiagnosisCategory(getStringValue(mainDiagMap, "diagnosisCategory"));
+            mainDiag.setRecordType(getIntegerValue(mainDiagMap, "recordType"));
+            mainDiag.setIsMainDiagnosis(getIntegerValue(mainDiagMap, "isMainDiagnosis"));
+            dto.setMainDischargeDiagnosis(mainDiag);
+        }
         Object contactsObj = dataItem.get("residentContactInfos");
         if (contactsObj instanceof List) {
             dto.setResidentContactInfos(parseContacts((List<?>) contactsObj));

--
Gitblit v1.9.3