| | |
| | | } |
| | | |
| | | //检查详情添加 |
| | | @SuppressWarnings("unchecked") |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean addInspectBGService(Map dataMap) { |
| | | log.info("ServiceExternalServiceImpl---addInspectBGService的新增的值为:{}", dataMap); |
| | | Map xiaoXiTou = (Map) dataMap.get("XiaoXiTou"); |
| | | Map yeWuXX = (Map) dataMap.get("YeWuXX"); |
| | | Map<String, Object> BingRenXX = ObjectUtils.isNotEmpty(yeWuXX) ? (Map<String, Object>) yeWuXX.get("BingRenXX") : null; |
| | | Map<String, Object> JianChaBG = ObjectUtils.isNotEmpty(yeWuXX) ? (Map<String, Object>) yeWuXX.get("JianChaBG") : null; |
| | | List<HashMap<String, Object>> JianChaBWList = ObjectUtils.isNotEmpty(JianChaBG) ? (List<HashMap<String, Object>>) JianChaBG.get("JianChaBWList") : null; |
| | | if (ObjectUtils.isEmpty(BingRenXX)) { |
| | | throw new BaseException("检查报告同步失败:BingRenXX不能为空"); |
| | | } |
| | | if (ObjectUtils.isEmpty(JianChaBG)) { |
| | | throw new BaseException("检查报告同步失败:JianChaBG不能为空"); |
| | | } |
| | | |
| | | // 机构优先取消息头,其次取患者信息,和检查申请补建逻辑保持一致 |
| | | String orgid = ObjectUtils.isNotEmpty(xiaoXiTou) ? getMapValue(xiaoXiTou, "FaSongJGID") : null; |
| | | if (StringUtils.isBlank(orgid)) { |
| | | orgid = getMapValue(BingRenXX, "ZuZhiJGID"); |
| | | } |
| | | String bingAnHao = getMapValue(BingRenXX, "BingAnHao"); |
| | | String bingRenID = getMapValue(BingRenXX, "BingRenID"); |
| | | String xingMing = getMapValue(BingRenXX, "XingMing"); |
| | | String shenQingDID = getMapValue(JianChaBG, "ShenQingDID"); |
| | | if (StringUtils.isBlank(orgid) || StringUtils.isBlank(bingAnHao) || StringUtils.isBlank(bingRenID) |
| | | || StringUtils.isBlank(xingMing) || StringUtils.isBlank(shenQingDID)) { |
| | | throw new BaseException("检查报告同步失败:BingRenXX.ZuZhiJGID/BingAnHao/BingRenID/XingMing、JianChaBG.ShenQingDID不能为空"); |
| | | } |
| | | |
| | | PatMedInspection patMedInspection = new PatMedInspection(); |
| | | PatMedInspectionItem patMedInspectionItem = new PatMedInspectionItem(); |
| | | patMedInspection.setOrgid(BingRenXX.get("ZuZhiJGID").toString()); |
| | | patMedInspection.setOrgid(orgid); |
| | | //丽水无院区,默认值是 1 |
| | | patMedInspection.setCampusid("1"); |
| | | patMedInspection.setInhospno(BingRenXX.get("BingAnHao").toString()); |
| | | patMedInspection.setPatidHis(BingRenXX.get("BingRenID").toString()); |
| | | patMedInspection.setPatname(BingRenXX.get("XingMing").toString()); |
| | | patMedInspection.setAppliyid(JianChaBG.get("ShenQingDID").toString()); |
| | | patMedInspection.setInhospno(bingAnHao); |
| | | patMedInspection.setPatidHis(bingRenID); |
| | | patMedInspection.setPatname(xingMing); |
| | | patMedInspection.setAppliyid(shenQingDID); |
| | | //查找患者检查检验信息,如果无,进行新加 |
| | | List<PatMedInspection> patMedInspections = patMedInspectionMapper.selectPatMedInspectionList(patMedInspection); |
| | | if (CollectionUtils.isNotEmpty(patMedInspections)) { |
| | | patMedInspectionItem.setInspectionid(patMedInspections.get(0).getId().intValue()); |
| | | } else { |
| | | if (CollectionUtils.isEmpty(patMedInspections)) { |
| | | addInspectService(dataMap); |
| | | List<PatMedInspection> patMedInspections2 = patMedInspectionMapper.selectPatMedInspectionList(patMedInspection); |
| | | patMedInspectionItem.setInspectionid(patMedInspections2.get(0).getId().intValue()); |
| | | patMedInspections = patMedInspectionMapper.selectPatMedInspectionList(patMedInspection); |
| | | if (CollectionUtils.isEmpty(patMedInspections)) { |
| | | throw new BaseException("检查报告同步失败:未找到或创建检查主记录,ShenQingDID=" + shenQingDID); |
| | | } |
| | | } |
| | | patMedInspectionItem.setInspectionid(patMedInspections.get(0).getId().intValue()); |
| | | //检查检验报告数据处理 |
| | | patMedInspectionItem.setOrgid(BingRenXX.get("ZuZhiJGID").toString()); |
| | | patMedInspectionItem.setOrgid(orgid); |
| | | //丽水无院区,默认值是 1 |
| | | patMedInspectionItem.setCampusid("1"); |
| | | List<PatMedInspectionItem> patMedInspectionItems = patMedInspectionItemMapper.selectPatMedInspectionItemList(patMedInspectionItem); |
| | | if (ObjectUtils.isNotEmpty(JianChaBG)) { |
| | | patMedInspectionItem.setInspectionName(JianChaBG.get("JianChaHao").toString()); |
| | | patMedInspectionItem.setReportid(JianChaBG.get("JianChaHao").toString()); |
| | | patMedInspectionItem.setStatuscode(JianChaBG.get("DangQianZTDM").toString()); |
| | | patMedInspectionItem.setStatusname(JianChaBG.get("DangQianZTMC").toString()); |
| | | patMedInspectionItem.setReportid(JianChaBG.get("BaoGaoRID").toString()); |
| | | patMedInspectionItem.setReportername(JianChaBG.get("BaoGaoRXM").toString()); |
| | | patMedInspectionItem.setDiagimpression(JianChaBG.get("ZhenDuanYX").toString()); |
| | | patMedInspectionItem.setDiagfindings(JianChaBG.get("ZhenDuanSJ").toString()); |
| | | patMedInspectionItem.setDiagsuggestion(JianChaBG.get("ZhenDuanJY").toString()); |
| | | patMedInspectionItem.setReporturl(JianChaBG.get("BaoGaoYXDZ").toString()); |
| | | patMedInspectionItem.setCriticalFlag(Integer.valueOf(JianChaBG.get("WeiJiZBZ").toString())); |
| | | patMedInspectionItem.setCriticalContent(JianChaBG.get("WeiJiZNR").toString()); |
| | | patMedInspectionItem.setReportdeptid(JianChaBG.get("BaoGaoKSID").toString()); |
| | | patMedInspectionItem.setReportdeptname(JianChaBG.get("BaoGaoKSMC").toString()); |
| | | patMedInspectionItem.setResultcode(JianChaBG.get("JianChaJGDM").toString()); |
| | | patMedInspectionItem.setResultname(JianChaBG.get("JianChaJGMC").toString()); |
| | | if (ObjectUtils.isNotEmpty(JianChaBG.get("BaoGaoSJ"))) { |
| | | try { |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | patMedInspection.setOpendate(simpleDateFormat.parse(JianChaBG.get("BaoGaoSJ").toString())); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | |
| | | // 兼容 PACS 实际报文:报告人、报告时间、报告地址等字段名与标准报文存在差异 |
| | | String jianChaHao = getMapValue(JianChaBG, "JianChaHao"); |
| | | String reportId = getMapValue(JianChaBG, "BaoGaoID"); |
| | | if (StringUtils.isBlank(reportId)) { |
| | | reportId = getMapValue(JianChaBG, "BaoGaoRID"); |
| | | } |
| | | if (StringUtils.isBlank(reportId)) { |
| | | reportId = jianChaHao; |
| | | } |
| | | String inspectionName = StringUtils.isNotBlank(jianChaHao) ? jianChaHao : reportId; |
| | | if (StringUtils.isBlank(inspectionName)) { |
| | | inspectionName = shenQingDID; |
| | | } |
| | | String reporterId = getMapValue(JianChaBG, "BaoGaoRID", "ZhiXingRID", "KaiDanRID"); |
| | | String reporterName = getMapValue(JianChaBG, "BaoGaoRXM", "ZhiXingRXM", "KaiDanRXM"); |
| | | String reportUrl = getMapValue(JianChaBG, "BaoGaoYXDZ", "TuWenBGXZDZ", "PDFurl"); |
| | | String reportDateStr = getMapValue(JianChaBG, "BaoGaoSJ", "ZhiXingSJ"); |
| | | |
| | | patMedInspectionItem.setInspectionName(inspectionName); |
| | | patMedInspectionItem.setReportid(reportId); |
| | | patMedInspectionItem.setStatuscode(getMapValue(JianChaBG, "DangQianZTDM")); |
| | | patMedInspectionItem.setStatusname(getMapValue(JianChaBG, "DangQianZTMC")); |
| | | patMedInspectionItem.setReporterid(reporterId); |
| | | patMedInspectionItem.setReportername(reporterName); |
| | | patMedInspectionItem.setDiagimpression(getMapValue(JianChaBG, "ZhenDuanYX")); |
| | | patMedInspectionItem.setDiagfindings(getMapValue(JianChaBG, "ZhenDuanSJ")); |
| | | patMedInspectionItem.setDiagsuggestion(getMapValue(JianChaBG, "ZhenDuanJY")); |
| | | patMedInspectionItem.setReporturl(reportUrl); |
| | | patMedInspectionItem.setCriticalFlag(parseInteger(getMapValue(JianChaBG, "WeiJiZBZ"))); |
| | | patMedInspectionItem.setCriticalContent(getMapValue(JianChaBG, "WeiJiZNR")); |
| | | patMedInspectionItem.setReportdeptid(getMapValue(JianChaBG, "BaoGaoKSID")); |
| | | patMedInspectionItem.setReportdeptname(getMapValue(JianChaBG, "BaoGaoKSMC")); |
| | | patMedInspectionItem.setResultcode(getMapValue(JianChaBG, "JianChaJGDM")); |
| | | patMedInspectionItem.setResultname(getMapValue(JianChaBG, "JianChaJGMC")); |
| | | Date reportDate = parseDateTime(reportDateStr); |
| | | if (reportDate != null) { |
| | | patMedInspectionItem.setReportdate(reportDate); |
| | | } |
| | | |
| | | // 同一检查下可能存在多条报告明细,优先按报告ID、检查号匹配,避免更新错行 |
| | | PatMedInspectionItem existingItem = null; |
| | | if (CollectionUtils.isNotEmpty(patMedInspectionItems)) { |
| | | for (PatMedInspectionItem item : patMedInspectionItems) { |
| | | if (StringUtils.isNotBlank(reportId) && reportId.equals(item.getReportid())) { |
| | | existingItem = item; |
| | | break; |
| | | } |
| | | } |
| | | if (existingItem == null) { |
| | | for (PatMedInspectionItem item : patMedInspectionItems) { |
| | | if (StringUtils.isNotBlank(inspectionName) && inspectionName.equals(item.getInspectionName())) { |
| | | existingItem = item; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (ObjectUtils.isNotEmpty(patMedInspectionItems)) { |
| | | if (existingItem == null) { |
| | | existingItem = patMedInspectionItems.get(0); |
| | | } |
| | | } |
| | | |
| | | if (existingItem != null) { |
| | | // 更新必须带上主键,否则 update ... where id = null 会影响 0 行,接口返回失败 |
| | | patMedInspectionItem.setId(existingItem.getId()); |
| | | patMedInspectionItem.setUpdateTime(new Date()); |
| | | int i = patMedInspectionItemMapper.updatePatMedInspectionItem(patMedInspectionItem); |
| | | if (i != 1) return false; |
| | | if (i < 1) { |
| | | throw new BaseException("检查报告明细更新失败,id=" + existingItem.getId()); |
| | | } |
| | | } else { |
| | | patMedInspectionItem.setDelFlag("0"); |
| | | patMedInspectionItem.setCreateTime(new Date()); |
| | | int i = patMedInspectionItemMapper.insertPatMedInspectionItem(patMedInspectionItem); |
| | | if (i != 1) return false; |
| | | if (i != 1) { |
| | | throw new BaseException("检查报告明细新增失败,ShenQingDID=" + shenQingDID); |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 从报文中按顺序获取第一个非空字段,兼容不同厂商的字段命名 |
| | | */ |
| | | private String getMapValue(Map<String, Object> source, String... keys) { |
| | | if (source == null || keys == null) { |
| | | return null; |
| | | } |
| | | for (String key : keys) { |
| | | Object value = source.get(key); |
| | | if (value != null && StringUtils.isNotBlank(String.valueOf(value))) { |
| | | return String.valueOf(value); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 解析检查报告时间,兼容常见日期时间格式 |
| | | */ |
| | | private Date parseDateTime(String dateTime) { |
| | | if (StringUtils.isBlank(dateTime)) { |
| | | return null; |
| | | } |
| | | String[] patterns = {"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd"}; |
| | | for (String pattern : patterns) { |
| | | try { |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); |
| | | simpleDateFormat.setLenient(false); |
| | | return simpleDateFormat.parse(dateTime); |
| | | } catch (ParseException ignored) { |
| | | // 尝试下一种格式 |
| | | } |
| | | } |
| | | log.warn("检查报告时间格式无法解析:{}", dateTime); |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 解析检查报告数字字段,避免非数字内容导致接口报错 |
| | | */ |
| | | private Integer parseInteger(String value) { |
| | | if (StringUtils.isBlank(value)) { |
| | | return null; |
| | | } |
| | | try { |
| | | return Integer.valueOf(value.trim()); |
| | | } catch (NumberFormatException e) { |
| | | log.warn("检查报告数字字段无法转换:{}", value); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> query360PatInfolwl(Long patid, SysUser sysUser) { |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patid); |