From efaa2a7a5b7d9d1a36f4d6a7e275d2b76f6cd9d3 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期四, 06 八月 2026 18:06:09 +0800
Subject: [PATCH] 【景宁】查询随访任务组科室关联列表、查询随访任务组疾病关联列表

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java |  206 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 192 insertions(+), 14 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 82c4094..1ad6fc5 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
@@ -111,28 +111,57 @@
     }
 
     @Override
-    public Boolean queryMedicationItemList(ServiceSLTDInhospReqVO reqVO) {
+    /**
+     * 鏌ヨ鑽搧淇℃伅鍒楄〃
+     * @return 杩斿洖瀹為檯鑾峰彇鍒扮殑鑽搧鏁版嵁鏉℃暟锛屽鏋滃嚭閿欏垯杩斿洖 null
+     */ public Integer queryMedicationItemList(ServiceSLTDInhospReqVO reqVO) {
         try {
             Map<String, Object> requestParams = buildRequestParams(reqVO);
             Map<String, String> headers = buildRequestHeaders();
             log.info("璇锋眰鍙傝嵂鍝佷俊鎭湴鍧�锛歿},appKey:{}", sltdPubPath + "/hbos-thirdparty-integration/standard/base/mc/service/medication/queryMedicationInfoPage", APP_KEY);
             String result = HttpUtils.sendPostByHeader(sltdPubPath + "/hbos-thirdparty-integration/standard/base/mc/service/medication/queryMedicationInfoPage", new Gson().toJson(requestParams), headers);
             List<Map<String, Object>> dataList = getDataList(result, 2);
+            log.info("銆恞ueryMedicationItemList銆戝叡鑾峰彇鍒皗}鏉¤嵂鍝佹暟鎹�", dataList.size());
+            int successCount = 0;
+            int failCount = 0;
             for (Map<String, Object> dataItem : dataList) {
-                MedicationItem medicationItem = convertToMedication(dataItem);
-                log.info("medicationItem鐨勫�间负锛歿}", medicationItem);
-                medicationItemMapper.insertMedicationItem(medicationItem);
-                List<MedicationDoseInfo> doseInfoList = medicationItem.getDoseInfoList();
-                for (MedicationDoseInfo doseInfo : doseInfoList) {
-                    doseInfo.setMedicationItemId(medicationItem.getId());
-                    medicationDoseInfoMapper.insertMedicationDoseInfo(doseInfo);
+                try {
+                    MedicationItem medicationItem = convertToMedication(dataItem);
+                    log.info("鍑嗗鎻掑叆鑽搧鏁版嵁锛歩temName={}, itemCode={}", medicationItem.getItemName(), medicationItem.getItemCode());
+                    medicationItem.setCreateTime(new Date());
+                    medicationItemMapper.insertMedicationItem(medicationItem);
+
+                    // 濡傛灉鎻掑叆鎴愬姛涓旇繑鍥炰簡鑷 ID锛屽垯鎻掑叆瀛愯〃
+                    if (medicationItem.getId() != null) {
+                        List<MedicationDoseInfo> doseInfoList = medicationItem.getDoseInfoList();
+                        if (CollectionUtils.isNotEmpty(doseInfoList)) {
+                            for (MedicationDoseInfo doseInfo : doseInfoList) {
+                                try {
+                                    doseInfo.setMedicationItemId(medicationItem.getId());
+                                    medicationDoseInfoMapper.insertMedicationDoseInfo(doseInfo);
+                                    log.debug("鎻掑叆鍓傞噺淇℃伅鎴愬姛锛歩temId={}, doseUnit={}", medicationItem.getId(), doseInfo.getDoseUnit());
+                                } catch (Exception e) {
+                                    log.warn("鎻掑叆鍓傞噺淇℃伅澶辫触锛歩temId={}, doseUnit={}, 閿欒:{}", medicationItem.getId(), doseInfo.getDoseUnit(), e.getMessage(), e);
+                                    failCount++;
+                                }
+                            }
+                        }
+                    }
+                    successCount++;
+                    log.info("鉁� 鑽搧鏁版嵁鎻掑叆鎴愬姛锛歿}", medicationItem.getItemName());
+                } catch (Exception e) {
+                    log.warn("銆恞ueryMedicationItemList銆戝崟鏉¤嵂鍝佹暟鎹彃鍏ュけ璐ワ細itemName={}, itemCode={}, 閿欒:{}", dataItem.get("itemName"), dataItem.get("itemCode"), e.getMessage(), e);
+                    failCount++;
+                    // 缁х画澶勭悊涓嬩竴鏉℃暟鎹紝涓嶄腑鏂暣涓惊鐜�
                 }
             }
+            log.info("銆恞ueryMedicationItemList銆戞壒閲忔彃鍏ュ畬鎴愶紝鎬绘暟:{}, 鎴愬姛:{}, 澶辫触:{}", dataList.size(), successCount, failCount);
+            // 杩斿洖瀹為檯鑾峰彇鍒扮殑鑽搧鏁版嵁鏉℃暟锛岀敤浜庡垎椤靛垽鏂槸鍚﹁繕鏈夋洿澶氭暟鎹�
+            return dataList.size();
         } catch (Exception e) {
             log.error("銆恞ueryMedicationItemList銆戣皟鐢ㄧ渷绔嬪悓寰疯嵂鍝佷俊鎭煡璇㈡帴鍙e紓甯革紝璇锋眰鍙傛暟锛歿}", reqVO, e);
             throw new RuntimeException(e);
         }
-        return true;
     }
 
 
@@ -868,7 +897,160 @@
             }
         }
 
+        if (active.equals("nhfy") || active.equals("sltd")) {
+            Map<String, String> drugInfoMap = queryMedicalOrders(dto);
+            if (drugInfoMap != null && !drugInfoMap.isEmpty()) {
+                patMedInhosp.setMedicalName(drugInfoMap.get("drugItemNames"));
+                patMedInhosp.setMedicalCode(drugInfoMap.get("drugItemIds"));
+                patMedInhosp.setMedicalCompany(drugInfoMap.get("drugManufacturerNames"));
+
+                log.info("鑾峰彇鑽搧淇℃伅鎴愬姛锛氬悕绉�={}, 缂栫爜={}, 鍘傚={}", drugInfoMap.get("drugItemNames"), drugInfoMap.get("drugItemIds"), drugInfoMap.get("drugManufacturerNames"));
+            }
+        }
         return patMedInhosp;
+    }
+
+    /**
+     * 鏌ヨ鍖诲槺淇℃伅骞舵嫾鎺ヨ嵂鍝佷俊鎭�
+     *
+     * @param dto 鍋ュ悍璁板綍璇锋眰瀵硅薄
+     * @return 杩斿洖鍖呭惈涓変釜瀛楁 Map锛�
+     * - drugItemNames: 鑽搧鍚嶇О鍒楄〃锛堥�楀彿鍒嗛殧锛�
+     * - drugItemIds: 鑽搧缂栫爜鍒楄〃锛堥�楀彿鍒嗛殧锛�
+     * - drugManufacturerNames: 鑽搧鍘傚鍒楄〃锛堥�楀彿鍒嗛殧锛�
+     * <p>
+     * 瑙勫垯锛�
+     * 1. 涓変釜瀛楁椤哄簭浣嶇疆淇濇寔涓�鑷�
+     * 2. 濡傛灉涓変釜瀛楁閮戒负绌猴紝鍒欒烦杩囪璁板綍
+     * 3. 濡傛灉鑷冲皯鏈変竴涓瓧娈垫湁鍊硷紝鍒欏叾浠栦袱涓负绌虹敤绌哄瓧绗︿覆浠f浛
+     */
+    private Map<String, String> queryMedicalOrders(ServiceSLTDInhospResDTO dto) {
+        Map<String, String> result = new HashMap<>();
+        List<String> itemNames = new ArrayList<>();
+        List<String> itemIds = new ArrayList<>();
+        List<String> manufacturerNames = new ArrayList<>();
+
+        try {
+            // 鑾峰彇鎮h�呯殑鍖诲槺淇℃伅
+            Map<String, Object> medicineInfoReq = new HashMap<>();
+            medicineInfoReq.put("orgId", dto.getOrgId());
+            medicineInfoReq.put("patientId", dto.getPatientId());
+            medicineInfoReq.put("campusId", dto.getCampusId());
+            medicineInfoReq.put("medicalRecordNo", dto.getMedicalRecordNo());
+            log.info("銆恞ueryMedicalOrders銆戣姹傚弬鏁帮細{}", medicineInfoReq);
+            Map<String, String> headers = buildRequestHeaders();
+            String resultStr = HttpUtils.sendPostByHeader(sltdPubPath + "/osj/hbos-thirdparty-integration/standard/common/doctorOrder/queryDoctorOrderList", new Gson().toJson(medicineInfoReq), headers);
+
+            if (StringUtils.isEmpty(resultStr)) {
+                log.warn("銆恞ueryMedicalOrders銆戞帴鍙h繑鍥炰负绌猴紝patientId={}", dto.getPatientId());
+                return result;
+            }
+
+            // 瑙f瀽杩斿洖鏁版嵁
+            Gson gson = new Gson();
+            Type mapType = new TypeToken<Map<String, Object>>() {
+            }.getType();
+            Map<String, Object> responseMap = gson.fromJson(resultStr, mapType);
+
+            // 妫�鏌ヨ繑鍥炵爜
+            Object codeObj = responseMap.get("code");
+            if (codeObj != null) {
+                String code = BigDecimal.valueOf(((Number) codeObj).longValue()).toPlainString();
+                if (!"200".equals(code)) {
+                    log.error("銆恞ueryMedicalOrders銆戞帴鍙h繑鍥炲け璐ワ紝code={}, message={}", code, responseMap.get("message"));
+                    return result;
+                }
+            }
+
+            // 鑾峰彇 data 鏁扮粍
+            Object dataObj = responseMap.get("data");
+            if (dataObj instanceof List) {
+                List<?> dataList = (List<?>) dataObj;
+
+                // 閬嶅巻鍖诲槺鍒楄〃锛屾彁鍙栬嵂鍝佷俊鎭�
+                Set<String> processedItemIds = new HashSet<>(); // 鐢ㄤ簬鍘婚噸锛堝彧鏍规嵁 itemId 鍘婚噸锛�
+                
+                for (Object item : dataList) {
+                    if (item instanceof Map) {
+                        Map<String, Object> itemMap = (Map<String, Object>) item;
+
+                        // 鍙鐞嗚嵂鍝佺浉鍏崇殑鍖诲槺锛坕temDomain 涓� FH0134.01 琛ㄧず鑽搧锛�
+                        Object itemDomainObj = itemMap.get("itemDomain");
+                        if (itemDomainObj == null || !"FH0134.01".equals(itemDomainObj.toString())) {
+                            continue;
+                        }
+
+                        // 鑾峰彇涓変釜瀛楁
+                        Object itemNameObj = itemMap.get("itemName");
+                        Object itemIdObj = itemMap.get("itemId");
+                        Object manufacturerNameObj = itemMap.get("manufacturerName");
+
+                        // 鍒ゆ柇鏄惁閮戒负绌�
+                        boolean allEmpty = (itemNameObj == null || StringUtils.isEmpty(itemNameObj.toString())) && (itemIdObj == null || StringUtils.isEmpty(itemIdObj.toString())) && (manufacturerNameObj == null || StringUtils.isEmpty(manufacturerNameObj.toString()));
+
+                        // 濡傛灉涓変釜閮戒负绌猴紝鍒欒烦杩�
+                        if (allEmpty) {
+                            continue;
+                        }
+
+                        // 鑷冲皯鏈変竴涓湁鍊硷紝澶勭悊姣忎釜瀛楁
+                        String itemName = (itemNameObj != null && StringUtils.isNotEmpty(itemNameObj.toString())) ? itemNameObj.toString() : "";
+                        
+                        // itemId 鐗规畩澶勭悊锛氶伩鍏嶇瀛﹁鏁版硶锛圙son 鍙兘灏嗘暟瀛楄В鏋愪负 Double锛�
+                        String itemId = "";
+                        if (itemIdObj != null && StringUtils.isNotEmpty(itemIdObj.toString())) {
+                            if (itemIdObj instanceof Number) {
+                                // 濡傛灉鏄暟鍊肩被鍨嬶紝杞崲涓烘暣鏁板瓧绗︿覆锛岄伩鍏嶇瀛﹁鏁版硶
+                                itemId = String.valueOf(((Number) itemIdObj).longValue());
+                            } else {
+                                itemId = itemIdObj.toString();
+                            }
+                        }
+                        
+                        String manufacturerName = (manufacturerNameObj != null && StringUtils.isNotEmpty(manufacturerNameObj.toString())) ? manufacturerNameObj.toString() : "";
+
+                        // 鍙牴鎹� itemId 鍘婚噸锛堝悓涓�缂栫爜鐨勮嵂鍝佸彧淇濈暀涓�涓級
+                        if (StringUtils.isNotEmpty(itemId)) {
+                            if (processedItemIds.contains(itemId)) {
+                                log.info("銆恞ueryMedicalOrders銆戣烦杩囬噸澶嶈嵂鍝侊紙鐩稿悓缂栫爜锛夛細鍚嶇О={}, 缂栫爜={}", itemName, itemId);
+                                continue;
+                            }
+                            processedItemIds.add(itemId);
+                        } else {
+                            // itemId 涓虹┖鏃讹紝浣跨敤 itemName 浣滀负鍘婚噸渚濇嵁
+                            if (processedItemIds.contains(itemName)) {
+                                log.info("銆恞ueryMedicalOrders銆戣烦杩囬噸澶嶈嵂鍝侊紙鐩稿悓鍚嶇О锛夛細鍚嶇О={}", itemName);
+                                continue;
+                            }
+                            processedItemIds.add(itemName);
+                        }
+
+                        // 娣诲姞鍒板垪琛�
+                        itemNames.add(itemName);
+                        itemIds.add(itemId);
+                        manufacturerNames.add(manufacturerName);
+
+                        log.info("銆恞ueryMedicalOrders銆戞彁鍙栬嵂鍝佷俊鎭細鍚嶇О={}, 缂栫爜={}, 鍘傚={}", itemName, itemId, manufacturerName);
+                    }
+                }
+            } else {
+                log.info("銆恞ueryMedicalOrders銆慸ata 涓嶆槸鏁扮粍绫诲瀷锛宲atientId={}", dto.getPatientId());
+            }
+
+            // 灏嗗垪琛ㄦ嫾鎺ユ垚閫楀彿鍒嗛殧鐨勫瓧绗︿覆
+            if (!itemNames.isEmpty()) {
+                result.put("drugItemNames", String.join(",", itemNames));
+                result.put("drugItemIds", String.join(",", itemIds));
+                result.put("drugManufacturerNames", String.join(",", manufacturerNames));
+            }
+
+            log.info("銆恞ueryMedicalOrders銆戞垚鍔熸彁鍙杮}鏉¤嵂鍝佷俊鎭紝patientId={}", itemNames.size(), dto.getPatientId());
+
+        } catch (Exception e) {
+            log.error("銆恞ueryMedicalOrders銆戞煡璇㈠尰鍢变俊鎭け璐ワ紝patientId={}", dto.getPatientId(), e);
+        }
+
+        return result;
     }
 
     private void setDischargeInfo(PatMedInhosp patMedInhosp, ServiceSLTDInhospResDTO dto) {
@@ -928,11 +1110,7 @@
                 if (importanceFlagCodeListObj instanceof List) {
                     List<?> importanceFlagCodeList = (List<?>) importanceFlagCodeListObj;
                     // 杩囨护鎺� null 鍊�
-                    List<String> nonNullList = importanceFlagCodeList.stream()
-                            .filter(Objects::nonNull)
-                            .map(Object::toString)
-                            .filter(StringUtils::isNotEmpty)
-                            .collect(Collectors.toList());
+                    List<String> nonNullList = importanceFlagCodeList.stream().filter(Objects::nonNull).map(Object::toString).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
 
                     if (!nonNullList.isEmpty()) {
                         String importanceFlagLabel;

--
Gitblit v1.9.3