| | |
| | | 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)) { |
| | | try { |
| | | int i = sysDeptMapper.insertDept(sysDept); |
| | | log.info("ServiceExternalServiceImpl---addDeptInfo是否新增成功:{}", i); |
| | | } catch (org.springframework.dao.DuplicateKeyException e) { |
| | | log.warn("【queryDeptWardAreaInfoList】科室已存在(并发插入),跳过:deptCode={}, orgid={}, campusid={}", sysDept.getDeptCode(), sysDept.getOrgid(), sysDept.getCampusid()); |
| | | } |
| | | } else { |
| | | sysDept.setDeptId(sysDept1.getDeptId()); |
| | | int i = sysDeptMapper.updateDept(sysDept); |
| | |
| | | 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)) { |
| | | //由人工维护的字段是不需要更新的 |
| | | //已存在:由人工维护的字段是不需要更新的,orgid/campusid保留原值不覆盖 |
| | | sysUser.setSearchscope(null); |
| | | sysUser.setPassword(null); |
| | | sysUser.setUserId(sysUser1.getUserId()); |
| | | sysUser.setOrgid(null); |
| | | sysUser.setCampusid(null); |
| | | sysUser2Mapper.updateUser(sysUser); |
| | | } else { |
| | | try { |
| | | sysUser2Mapper.insertUser(sysUser); |
| | | } catch (org.springframework.dao.DuplicateKeyException e) { |
| | | //并发插入场景:重新查询获取已存在记录,避免重复 |
| | | log.warn("【queryHospUserInfoList】用户已存在(并发插入),跳过:userName={}", sysUser.getUserName()); |
| | | SysUser existingUser = sysUser2Mapper.selectUserByUserName(sysUser.getUserName()); |
| | | if (ObjectUtils.isNotEmpty(existingUser)) { |
| | | sysUser.setUserId(existingUser.getUserId()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 处理用户与部门的关系 |
| | |
| | | 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(); |
| | |
| | | queryInhosp.setSerialnum(StringUtils.trim(patMedInhosp.getSerialnum())); |
| | | queryInhosp.setOrgid(StringUtils.trim(dto.getOrgId())); |
| | | queryInhosp.setInhospstate(cry); |
| | | queryInhosp.setSchemestatus(0L); |
| | | log.info("----------------这里的入参为:{},{}", queryInhosp.getPatno(), queryInhosp.getSerialnum()); |
| | | List<PatMedInhosp> existingInhosps = patMedInhospService.selectPatMedInhosp(queryInhosp); |
| | | |
| | |
| | | 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"); |
| | |
| | | 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 { |
| | |
| | | } |
| | | if ("1".equals(cry)) { |
| | | patMedInhosp.setInhospstate("1"); |
| | | if (CollectionUtils.isNotEmpty(dto.getDiagnosisList()) && dto.getDiagnosisList().size() > 0) { |
| | | for (ServiceSLTDDiagnosisResDTO diagnosis : dto.getDiagnosisList()) { |
| | | if (diagnosis.getIsMainDiagnosis() == 1) { |
| | | patMedInhosp.setLeavediagname(diagnosis.getDiagnosisDictName() == null ? "" : diagnosis.getDiagnosisDictName()); |
| | | patMedInhosp.setLeaveicd10code(diagnosis.getDiagnosisDictCode() == null ? "" : diagnosis.getDiagnosisDictCode()); |
| | | } |
| | | 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(), "")); |
| | | } |
| | | } |
| | | } |
| | |
| | | private PatArchive processPatientArchive(ServiceSLTDInhospResDTO dto) { |
| | | List<PatArchive> existingArchives = null; |
| | | |
| | | // 优先按 patientno 精确查重,查不到再按 idcardno 查重(AND条件会漏查同一人不同patientno的情况) |
| | | 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); |
| | | } |
| | | |
| | | // 第二步:按 patientno 查不到时,按 idcardno 查重(分步OR,避免AND条件漏查) |
| | | 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)) { |
| | | try { |
| | | patArchiveService.insertPatArchive(patArchive); |
| | | log.debug("【processPatientArchive】新增患者档案,患者编号:{}", patArchive.getPatientno()); |
| | | } catch (org.springframework.dao.DuplicateKeyException e) { |
| | | log.warn("【processPatientArchive】患者档案已存在(并发插入),跳过: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()); |
| | |
| | | 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)); |