From 27df1079c1d230fab29f565f5209f2a02e0def8a Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期一, 20 七月 2026 16:56:51 +0800
Subject: [PATCH] 省立同德的功能

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java |  194 +++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 158 insertions(+), 36 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 fa8c0f0..2ada147 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSLTDHealthcareRecordServiceImpl.java
@@ -63,6 +63,12 @@
     private SysUserRole2Mapper sysUserRoleMapper;
 
     @Autowired
+    private MedicationItemMapper medicationItemMapper;
+
+    @Autowired
+    private MedicationDoseInfoMapper medicationDoseInfoMapper;
+
+    @Autowired
     private RedisTemplate<String, String> redisTemplate;
 
     @Value("${sltd_pub_path}")
@@ -84,7 +90,12 @@
             Map<String, Object> requestParams = buildRequestParams(reqVO);
             Map<String, String> headers = buildRequestHeaders();
             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 result = null;
+            if (reqVO.getSize() == null && reqVO.getCurrent() == null)
+                result = HttpUtils.sendPostByHeader(sltdPubPath + "/osj/hbos-thirdparty-integration/standard/common/healthcareRecord/dtcQueryHealthcareRecordList", new Gson().toJson(requestParams), headers);
+            else
+                result = HttpUtils.sendPostByHeader(sltdPubPath + "/osj/hbos-thirdparty-integration/standard/common/healthcareRecord/dtcPageHealthcareRecordList", new Gson().toJson(requestParams), headers);
+            log.info("queryHealthcareRecordList--result杩斿洖鐨勭粨鏋滃�硷細{}", result == null ? "绌哄��" : "鏈夊��");
 
             String cry = determineCry(reqVO);
             log.info("cry鐨勫�间负锛歿}", cry);
@@ -95,6 +106,31 @@
             log.error("銆恞ueryHealthcareRecordList銆戣皟鐢ㄧ渷绔嬪悓寰峰仴搴疯褰曟煡璇㈡帴鍙e紓甯革紝璇锋眰鍙傛暟锛歿}", reqVO, e);
             throw new RuntimeException("璋冪敤鐪佺珛鍚屽痉鍋ュ悍璁板綍鏌ヨ鎺ュ彛澶辫触:" + e.getMessage());
         }
+    }
+
+    @Override
+    public Boolean 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);
+            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);
+                }
+            }
+        } catch (Exception e) {
+            log.error("銆恞ueryMedicationItemList銆戣皟鐢ㄧ渷绔嬪悓寰疯嵂鍝佷俊鎭煡璇㈡帴鍙e紓甯革紝璇锋眰鍙傛暟锛歿}", reqVO, e);
+            throw new RuntimeException(e);
+        }
+        return true;
     }
 
 
@@ -136,7 +172,7 @@
             Map<String, String> headers = buildRequestHeaders();
             String result = HttpUtils.sendPostByHeader(sltdPubPath + "/osj/hbos-thirdparty-integration/standard/common/dept/queryDeptList", new Gson().toJson(params), headers);
             log.info("銆恞ueryDeptWardAreaInfoList銆戞帴鍙e搷搴旂粨鏋滐細{}", StringUtils.isEmpty(result) ? "绌虹殑" : "涓嶇┖");
-            List<Map<String, Object>> dataList = getDataList(result);
+            List<Map<String, Object>> dataList = getDataList(result, 1);
             log.info("-----------dataList鎺ュ彛鍝嶅簲缁撴灉锛歿}", dataList.size());
             for (Map<String, Object> dataItem : dataList) {
                 SysDept sysDept = new SysDept();
@@ -192,20 +228,6 @@
         return true;
     }
 
-    @Override
-    public void aa(Map<String, Object> map) {
-        List<String> types = new ArrayList<>();
-        types.add("FH0109.27");
-        ObjectMapper objectMapper = new ObjectMapper();
-        try {
-            String jsonString = objectMapper.writeValueAsString(map);
-            parseResponseData(jsonString, types, "1", "20001001");
-        } catch (JsonProcessingException e) {
-            e.printStackTrace();
-        }
-
-    }
-
 
     /**
      * 閲囬泦鍖婚櫌鐢ㄦ埛淇℃伅
@@ -219,7 +241,7 @@
         Map<String, String> headers = buildRequestHeaders();
         String result = HttpUtils.sendPostByHeader(sltdPubPath + "/osj/hbos-thirdparty-integration/standard/common/staff/queryStaffList", new Gson().toJson(requestParams), headers);
         log.info("銆恞ueryHealthcareRecordList銆戞帴鍙e搷搴旂粨鏋滄槸鍚︽湁鍊硷細{}", StringUtils.isEmpty(result) ? "娌″��" : "鏈夊��");
-        List<Map<String, Object>> dataList = getDataList(result);
+        List<Map<String, Object>> dataList = getDataList(result, 1);
         for (Map<String, Object> dataItem : dataList) {
             SysUser sysUser = new SysUser();
             if (StringUtils.isEmpty(getStringValue(dataItem, "accountNo"))) {
@@ -355,17 +377,25 @@
     }
 
     private String determineCry(ServiceSLTDInhospReqVO reqVO) {
-        if (CollectionUtils.isEmpty(reqVO.getStatusList())) return null;
-
-        if (reqVO.getStatusList().contains("FH0109.24")) {
-            //鍏ラ櫌
-            return "0";
-        } else if (reqVO.getStatusList().contains("FH0109.27")) {
-            //鍑洪櫌
-            return "1";
-        } else if (reqVO.getStatusList().contains("FH0109.22") || reqVO.getStatusList().contains("FH0109.23") || reqVO.getStatusList().contains("FH0109.53")) {
-            //棰勫叆闄�
-            return "3";
+        if (CollectionUtils.isEmpty(reqVO.getStatusList()) && CollectionUtils.isEmpty(reqVO.getHealthcareRecordTypeList()))
+            return null;
+        if (reqVO.getStatusList() != null) {
+            if (reqVO.getStatusList().contains("FH0109.24")) {
+                //鍏ラ櫌
+                return "0";
+            } else if (reqVO.getStatusList().contains("FH0109.27")) {
+                //鍑洪櫌
+                return "1";
+            } else if (reqVO.getStatusList().contains("FH0109.22") || reqVO.getStatusList().contains("FH0109.23") || reqVO.getStatusList().contains("FH0109.53")) {
+                //棰勫叆闄�
+                return "3";
+            }
+        }
+        if (reqVO.getHealthcareRecordTypeList() != null) {
+            if (reqVO.getHealthcareRecordTypeList().contains("FH0108.03") || reqVO.getHealthcareRecordTypeList().contains("FH0108.01")) {
+                //闂ㄦ�ヨ瘖
+                return "4";
+            }
         }
         return null;
     }
@@ -376,7 +406,7 @@
             params.put("orgId", Long.parseLong(reqVO.getOrgId()));
         }
         if (reqVO.getCampusId() != null) {
-            params.put("campusId", reqVO.getCampusId());
+            params.put("campusIds", reqVO.getCampusId());
         }
         if (reqVO.getStartHeadTime() != null) {
             params.put("startHeadTime", reqVO.getStartHeadTime());
@@ -431,12 +461,13 @@
 
     private List<ServiceSLTDInhospResDTO> parseResponseData(String result, List<String> types, String cry, String campusId) {
         try {
-            List<Map<String, Object>> dataList = getDataList(result);
+            List<Map<String, Object>> dataList = getDataList(result, cry.equals("4") ? 2 : 1);
+            log.info("銆恜arseResponseData銆戞垚鍔熻В鏋恉ataList:{}鏉″仴搴疯褰曟暟鎹�", dataList.size());
             List<ServiceSLTDInhospResDTO> resultList = new ArrayList<>();
             for (Map<String, Object> dataItem : dataList) {
                 resultList.add(convertToDTO(dataItem));
             }
-            log.info("銆恜arseResponseData銆戞垚鍔熻В鏋恵}鏉″仴搴疯褰曟暟鎹�", resultList.size());
+            log.info("銆恜arseResponseData銆戞垚鍔熻В鏋恟esultList:{}鏉″仴搴疯褰曟暟鎹�", resultList.size());
 
             processResultList(resultList, types, cry, campusId);
             return resultList;
@@ -446,11 +477,20 @@
         }
     }
 
-    public List<Map<String, Object>> getDataList(String result) {
+    /**
+     * 瑙f瀽鎺ュ彛杩斿洖鏁版嵁
+     *
+     * @param result 鎺ュ彛杩斿洖鏁版嵁
+     * @param flag   1浠h〃锛屾暟缁勫湪data閲岋紝2浠h〃鏁扮粍鍦╠ata/records閲�
+     * @return 瑙f瀽鍚庣殑鏁版嵁鍒楄〃
+     */
+
+    public List<Map<String, Object>> getDataList(String result, Integer flag) {
         Gson gson = new Gson();
         Type mapType = new TypeToken<Map<String, Object>>() {
         }.getType();
         Map<String, Object> responseMap = gson.fromJson(result, mapType);
+        log.info("銆恜arseResponseData銆戞帴鍙h繑鍥炴暟鎹殑responseMap锛歿}", Objects.isNull(responseMap) ? "绌虹殑" : "鏈夊��");
         Number codeNum = (Number) responseMap.get("code");
         String code = BigDecimal.valueOf(codeNum.longValue()).toPlainString();
         if (StringUtils.isEmpty(code) || !code.equals("200")) {
@@ -459,15 +499,30 @@
         }
 
         Object dataObj = responseMap.get("data");
+        if (flag == 1) {
+            dataObj = responseMap.get("data");
+        } else if (flag == 2) {
+            //闂ㄦ�ヨ瘖鐨勫垎椤垫暟鎹槸鍦╮ecords涓�
+            dataObj = ((Map<String, Object>) responseMap.get("data")).get("records");
+            log.info("銆恜arseResponseData銆戞帴鍙h繑鍥炴暟鎹殑dataObj锛歿}", Objects.isNull(dataObj) ? "绌虹殑" : "鏈夊��");
+        }
         if (dataObj == null) {
             log.info("銆恜arseResponseData銆戞帴鍙h繑鍥炴暟鎹负绌�");
             return new ArrayList<>();
         }
 
-        String dataJson = gson.toJson(dataObj);
-        Type listType = new TypeToken<List<Map<String, Object>>>() {
-        }.getType();
-        List<Map<String, Object>> dataList = gson.fromJson(dataJson, listType);
+        // 鍏煎data涓烘暟缁勬垨瀵硅薄涓ょ鎯呭喌锛氭帴鍙f甯告椂data涓篬{...}]鏁扮粍锛�
+        // 寮傚父鎴栫┖鏁版嵁鏃跺彲鑳借繑鍥瀧}瀵硅薄锛岀洿鎺ユ寜List瑙f瀽浼氭姏JsonSyntaxException
+        List<Map<String, Object>> dataList;
+        if (dataObj instanceof List) {
+            String dataJson = gson.toJson(dataObj);
+            Type listType = new TypeToken<List<Map<String, Object>>>() {
+            }.getType();
+            dataList = gson.fromJson(dataJson, listType);
+        } else {
+            log.info("銆恜arseResponseData銆戞帴鍙h繑鍥瀌ata涓嶆槸鏁扮粍锛岃�屾槸瀵硅薄绫诲瀷锛宒ata鍐呭锛歿}", gson.toJson(dataObj));
+            return new ArrayList<>();
+        }
 
         // 浣跨敤 Set 鍘婚噸锛岀‘淇濇病鏈夐噸澶嶇殑鏁版嵁
         Set<Map<String, Object>> uniqueDataSet = new HashSet<>(dataList);
@@ -699,6 +754,14 @@
                     List<PatMedInhosp> patMedInhospList3 = patMedInhospService.selectPatMedInhosp(queryInhosp);
                     if (CollectionUtils.isEmpty(patMedInhospList3)) {
                         try {
+                            //鑾峰彇涓�涓嬪叆闄㈢敵璇峰崟
+                            Map<String, String> headers = buildRequestHeaders();
+                            Map<String, Object> requestParams = new HashMap<>();
+                            requestParams.put("orgId", "20001001");
+                            requestParams.put("20001001", patArchive.getPatidHis());
+                            String result = HttpUtils.sendPostByHeader(sltdPubPath + "/hospitalizedApply/query", new Gson().toJson(requestParams), headers);
+
+
                             patMedInhospService.insertPatMedInhosp(patMedInhosp);
                             log.debug("鎴愬姛鎻掑叆棰勫叆闄㈣褰曪細serialnum={}", patMedInhosp.getSerialnum());
                         } catch (Exception e) {
@@ -1038,6 +1101,55 @@
         return dto;
     }
 
+    private MedicationItem convertToMedication(Map<String, Object> dataItem) {
+        MedicationItem dto = new MedicationItem();
+        dto.setOrgId(getLongValue(dataItem, "orgId"));
+        dto.setIdentificationCode(getStringValue(dataItem, "identificationCode"));
+        dto.setWbm(getStringValue(dataItem, "wbm"));
+        dto.setMedicationCommonName(getStringValue(dataItem, "medicationCommonName"));
+        dto.setManufacturerName(getStringValue(dataItem, "manufacturerName"));
+        dto.setItemCode(getStringValue(dataItem, "itemCode"));
+        dto.setSmallLargePackageRatio(getLongValue(dataItem, "smallLargePackageRatio"));
+        dto.setRemark(getStringValue(dataItem, "remark"));
+        dto.setItemName(getStringValue(dataItem, "itemName"));
+        dto.setMedicationType(getStringValue(dataItem, "medicationType"));
+        Object mainDiagObj = dataItem.get("doseInfoList");
+        List<MedicationDoseInfo> doseInfoList = new ArrayList<>();
+        if (mainDiagObj instanceof List) {
+            List<Map<String, Object>> mainDiagList = (List<Map<String, Object>>) mainDiagObj;
+            for (Map<String, Object> mainDiagMap : mainDiagList) {
+                MedicationDoseInfo medicationDoseInfo = new MedicationDoseInfo();
+                medicationDoseInfo.setDoseSmallPackageRation(getBigDecimalValue(mainDiagMap, "doseSmallPackageRation"));
+                medicationDoseInfo.setDose(getLongValue(mainDiagMap, "dose"));
+                medicationDoseInfo.setDoseSmallPackageNum(getLongValue(mainDiagMap, "doseSmallPackageNum"));
+                medicationDoseInfo.setDoseUnit(getStringValue(mainDiagMap, "doseUnit"));
+                medicationDoseInfo.setDoseUnitType(getLongValue(mainDiagMap, "doseUnitType"));
+                doseInfoList.add(medicationDoseInfo);
+            }
+        }
+        dto.setDoseInfoList(doseInfoList);
+        dto.setAntimicrobialGradeCode(getStringValue(dataItem, "antimicrobialGradeCode"));
+        dto.setLicenseNumber(getStringValue(dataItem, "licenseNumber"));
+        dto.setDefaultUsageName(getStringValue(dataItem, "defaultUsageName"));
+        dto.setSpecialDrugsName(getStringValue(dataItem, "specialDrugsName"));
+        dto.setAntimicrobialGradeName(getStringValue(dataItem, "antimicrobialGradeName"));
+        dto.setCommonPinyin(getStringValue(dataItem, "commonPinyin"));
+        dto.setCommonWbm(getStringValue(dataItem, "commonWbm"));
+        dto.setManufacturerId(getLongValue(dataItem, "manufacturerId"));
+        dto.setDefaultUsageId(getLongValue(dataItem, "defaultUsageId"));
+        dto.setSpecification(getStringValue(dataItem, "specification"));
+        dto.setSmallPackageUnit(getStringValue(dataItem, "smallPackageUnit"));
+        dto.setItemId(getLongValue(dataItem, "itemId"));
+        dto.setSpecialDrugsCode(getStringValue(dataItem, "specialDrugsCode"));
+        dto.setPinyin(getStringValue(dataItem, "pinyin"));
+        dto.setDoseFormName(getStringValue(dataItem, "doseFormName"));
+        dto.setLargePackageUnit(getStringValue(dataItem, "largePackageUnit"));
+        dto.setRetailPrice(getBigDecimalValue(dataItem, "retailPrice"));
+        dto.setStatus(getLongValue(dataItem, "status"));
+        return dto;
+    }
+
+
     private List<ServiceSLTDContactsResDTO> parseContacts(List<?> contactsList) {
         List<ServiceSLTDContactsResDTO> contacts = new ArrayList<>();
         for (Object contactObj : contactsList) {
@@ -1082,6 +1194,16 @@
         return value instanceof Number ? new BigDecimal(value.toString()).toPlainString() : value.toString();
     }
 
+    private BigDecimal getBigDecimalValue(Map<String, Object> map, String key) {
+        Object value = map.get(key);
+        if (value == null) {
+            return null;
+        }
+
+        // 鍙鐞嗘暟瀛楃被鍨嬶紝閬垮厤绉戝璁℃暟娉�
+        return new BigDecimal(value.toString());
+    }
+
     private Long getLongValue(Map<String, Object> map, String key) {
         Object value = map.get(key);
         if (value == null) return null;

--
Gitblit v1.9.3