| | |
| | | import com.ruoyi.common.core.domain.entity.SysUserDept; |
| | | import com.ruoyi.common.core.domain.entity.SysUserRole; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.smartor.common.enums.EmergencyLevelEnum; |
| | | import com.smartor.common.enums.ImportFlagEnum; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.smartor.common.DistinctByProperty; |
| | | import com.smartor.domain.*; |
| | |
| | | } |
| | | |
| | | @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("【queryMedicationItemList】共获取到{}条药品数据", 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("准备插入药品数据:itemName={}, 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("插入剂量信息成功:itemId={}, doseUnit={}", medicationItem.getId(), doseInfo.getDoseUnit()); |
| | | } catch (Exception e) { |
| | | log.warn("插入剂量信息失败:itemId={}, doseUnit={}, 错误:{}", medicationItem.getId(), doseInfo.getDoseUnit(), e.getMessage(), e); |
| | | failCount++; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | successCount++; |
| | | log.info("✓ 药品数据插入成功:{}", medicationItem.getItemName()); |
| | | } catch (Exception e) { |
| | | log.warn("【queryMedicationItemList】单条药品数据插入失败:itemName={}, itemCode={}, 错误:{}", dataItem.get("itemName"), dataItem.get("itemCode"), e.getMessage(), e); |
| | | failCount++; |
| | | // 继续处理下一条数据,不中断整个循环 |
| | | } |
| | | } |
| | | log.info("【queryMedicationItemList】批量插入完成,总数:{}, 成功:{}, 失败:{}", dataList.size(), successCount, failCount); |
| | | // 返回实际获取到的药品数据条数,用于分页判断是否还有更多数据 |
| | | return dataList.size(); |
| | | } catch (Exception e) { |
| | | log.error("【queryMedicationItemList】调用省立同德药品信息查询接口异常,请求参数:{}", reqVO, e); |
| | | throw new RuntimeException(e); |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | |
| | | patMedInhosp.setInhospno(dto.getHealthcareRecordNo()); |
| | | patMedInhosp.setFuflag("1"); |
| | | |
| | | |
| | | if (StringUtils.isNotEmpty(patArchive.getNotrequiredFlag()) && patArchive.getNotrequiredFlag().equals("1")) |
| | | patMedInhosp.setFuflag("0"); |
| | | if ("0".equals(cry)) { |
| | |
| | | setDischargeInfo(patMedInhosp, dto); |
| | | } else { |
| | | setAdmissionInfo(patMedInhosp, dto); |
| | | patMedInhosp.setEncounterSourceId(dto.getEncounterSourceId() == null ? "" : dto.getEncounterSourceId()); |
| | | if (StringUtils.isNotEmpty(dto.getEncounterSourceId())) { |
| | | //根据 encounterSourceId 获取 importanceFlagCode emergencyLevelCode |
| | | Map<String, String> applyInfo = hospitalizedApply(dto.getEncounterSourceId(), dto.getOrgId()); |
| | | patMedInhosp.setImportanceFlagCode(applyInfo.get("importanceFlagCode")); |
| | | patMedInhosp.setEmergencyLevelCode(applyInfo.get("emergencyLevelCode")); |
| | | } |
| | | } |
| | | |
| | | patMedInhosp.setDrname(dto.getDoctorName()); |
| | |
| | | } |
| | | } |
| | | |
| | | 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. 如果至少有一个字段有值,则其他两个为空用空字符串代替 |
| | | */ |
| | | 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 { |
| | | // 获取患者的医嘱信息 |
| | | 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("【queryMedicalOrders】请求参数:{}", 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("【queryMedicalOrders】接口返回为空,patientId={}", dto.getPatientId()); |
| | | return result; |
| | | } |
| | | |
| | | // 解析返回数据 |
| | | 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("【queryMedicalOrders】接口返回失败,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; |
| | | |
| | | // 只处理药品相关的医嘱(itemDomain 为 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 特殊处理:避免科学计数法(Gson 可能将数字解析为 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("【queryMedicalOrders】跳过重复药品(相同编码):名称={}, 编码={}", itemName, itemId); |
| | | continue; |
| | | } |
| | | processedItemIds.add(itemId); |
| | | } else { |
| | | // itemId 为空时,使用 itemName 作为去重依据 |
| | | if (processedItemIds.contains(itemName)) { |
| | | log.info("【queryMedicalOrders】跳过重复药品(相同名称):名称={}", itemName); |
| | | continue; |
| | | } |
| | | processedItemIds.add(itemName); |
| | | } |
| | | |
| | | // 添加到列表 |
| | | itemNames.add(itemName); |
| | | itemIds.add(itemId); |
| | | manufacturerNames.add(manufacturerName); |
| | | |
| | | log.info("【queryMedicalOrders】提取药品信息:名称={}, 编码={}, 厂家={}", itemName, itemId, manufacturerName); |
| | | } |
| | | } |
| | | } else { |
| | | log.info("【queryMedicalOrders】data 不是数组类型,patientId={}", 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("【queryMedicalOrders】成功提取{}条药品信息,patientId={}", itemNames.size(), dto.getPatientId()); |
| | | |
| | | } catch (Exception e) { |
| | | log.error("【queryMedicalOrders】查询医嘱信息失败,patientId={}", dto.getPatientId(), e); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private void setDischargeInfo(PatMedInhosp patMedInhosp, ServiceSLTDInhospResDTO dto) { |
| | |
| | | patMedInhosp.setHospitaldistrictid("" + dto.getAreaId()); |
| | | patMedInhosp.setHospitaldistrictcode("" + dto.getAreaId()); |
| | | patMedInhosp.setHospitaldistrictname(dto.getAreaName()); |
| | | } |
| | | |
| | | /** |
| | | * 根据入院申请单ID查询入院申请单详情 |
| | | * 只提取 importanceFlagCode(importanceFlagCodeList逗号拼接)和 emergencyLevelCode 两个值 |
| | | */ |
| | | private Map<String, String> hospitalizedApply(String encounterSourceId, String orgid) { |
| | | Map<String, String> applyInfo = new HashMap<>(); |
| | | Map<String, String> headers = buildRequestHeaders(); |
| | | log.info("院申请单ID查询入院申请单:{},appKey:{}", sltdPubPath + "/sf/hospitalizedApply/query", APP_KEY); |
| | | //设置入参 |
| | | Map<String, Object> requestParams = new HashMap<>(); |
| | | requestParams.put("applyId", encounterSourceId); |
| | | requestParams.put("orgId", orgid); |
| | | |
| | | String result = null; |
| | | if (StringUtils.isNotEmpty(encounterSourceId) && StringUtils.isNotEmpty(orgid)) |
| | | result = HttpUtils.sendPostByHeader(sltdPubPath + "/sf/hospitalizedApply/query", new Gson().toJson(requestParams), headers); |
| | | |
| | | if (StringUtils.isEmpty(result)) { |
| | | log.error("【hospitalizedApply】接口返回为空,applyId={}", encounterSourceId); |
| | | return applyInfo; |
| | | } |
| | | try { |
| | | Gson gson = new Gson(); |
| | | Type mapType = new TypeToken<Map<String, Object>>() { |
| | | }.getType(); |
| | | Map<String, Object> responseMap = gson.fromJson(result, mapType); |
| | | Object dataObj = responseMap == null ? null : responseMap.get("data"); |
| | | if (dataObj instanceof Map) { |
| | | Map<String, Object> data = (Map<String, Object>) dataObj; |
| | | //重要性标记编码,接口返回是数组,需要转换为字典名称 |
| | | Object importanceFlagCodeListObj = data.get("importanceFlagCodeList"); |
| | | 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()); |
| | | |
| | | if (!nonNullList.isEmpty()) { |
| | | String importanceFlagLabel; |
| | | if (nonNullList.size() == 1) { |
| | | // 只有一个值,直接通过枚举获取描述 |
| | | importanceFlagLabel = ImportFlagEnum.getDescByCode(nonNullList.get(0)); |
| | | } else { |
| | | // 多个值,用逗号拼接枚举描述 |
| | | StringBuilder labelBuilder = new StringBuilder(); |
| | | for (String code : nonNullList) { |
| | | String label = ImportFlagEnum.getDescByCode(code); |
| | | if (StringUtils.isNotEmpty(label)) { |
| | | labelBuilder.append(label).append(","); |
| | | } |
| | | } |
| | | importanceFlagLabel = StringUtils.stripEnd(labelBuilder.toString(), ","); |
| | | } |
| | | |
| | | if (StringUtils.isNotEmpty(importanceFlagLabel)) { |
| | | applyInfo.put("importanceFlagCode", importanceFlagLabel); |
| | | } |
| | | } |
| | | } |
| | | //紧急程度编码,通过枚举转换描述 |
| | | Object emergencyLevelCodeObj = data.get("emergencyLevelCode"); |
| | | if (emergencyLevelCodeObj != null) { |
| | | String emergencyLevelLabel = EmergencyLevelEnum.getDescByCode(emergencyLevelCodeObj.toString()); |
| | | if (StringUtils.isNotEmpty(emergencyLevelLabel)) { |
| | | applyInfo.put("emergencyLevelCode", emergencyLevelLabel); |
| | | } |
| | | } |
| | | } else { |
| | | log.error("【hospitalizedApply】接口返回data不是对象,applyId={},result:{}", encounterSourceId, result); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("【hospitalizedApply】解析入院申请单详情失败,applyId={}", encounterSourceId, e); |
| | | } |
| | | log.info("【hospitalizedApply】applyId={},importanceFlagCode={},emergencyLevelCode={}", encounterSourceId, applyInfo.get("importanceFlagCode"), applyInfo.get("emergencyLevelCode")); |
| | | return applyInfo; |
| | | } |
| | | |
| | | /** |
| | |
| | | dto.setCostCategoryCode(getStringValue(dataItem, "costCategoryCode")); |
| | | dto.setCostNatureName(getStringValue(dataItem, "costNatureName")); |
| | | dto.setCostNatureCode(getStringValue(dataItem, "costNatureCode")); |
| | | dto.setEncounterSourceId(getStringValue(dataItem, "encounterSourceId")); |
| | | dto.setFurtherConsultationStatus(getIntegerValue(dataItem, "furtherConsultationStatus")); |
| | | Object mainDiagObj = dataItem.get("mainDischargeDiagnosis"); |
| | | if (mainDiagObj instanceof Map) { |