| | |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.core.service.IConfigService; |
| | | import com.ruoyi.common.core.service.dto.PatMedReq; |
| | | import com.ruoyi.common.core.service.dto.PatMedRes; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.DtoConversionUtils; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.smartor.domain.*; |
| | | import com.ruoyi.inhospvisit.domain.PatMedInhospDTO; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.io.IOException; |
| | | import java.time.Instant; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.ruoyi.othervisit.domain.PatMedOperationItem; |
| | | import com.ruoyi.inhospvisit.domain.PatMedInhospVO; |
| | | import com.ruoyi.inhospvisit.domain.PatMedInhosp; |
| | |
| | | import com.ruoyi.task.domain.ServiceTask; |
| | | import com.ruoyi.task.domain.ServiceTaskdept; |
| | | import com.ruoyi.task.domain.ServiceTaskdiag; |
| | | import com.ruoyi.task.domain.ServiceTaskmedical; |
| | | import com.ruoyi.task.domain.ServiceTaskoper; |
| | | import com.ruoyi.task.domain.ServiceTaskRule; |
| | | import com.ruoyi.task.domain.ServiceTaskSchedule; |
| | |
| | | import com.ruoyi.task.mapper.ServiceTaskdeptMapper; |
| | | import com.ruoyi.task.mapper.ServiceTaskdiagMapper; |
| | | import com.ruoyi.task.mapper.ServiceTaskMapper; |
| | | import com.ruoyi.task.mapper.ServiceTaskmedicalMapper; |
| | | import com.ruoyi.task.mapper.ServiceTaskoperMapper; |
| | | import com.ruoyi.task.mapper.ServiceTaskRuleMapper; |
| | | import com.ruoyi.task.mapper.ServiceTaskScheduleDetailMapper; |
| | | import com.ruoyi.task.mapper.ServiceTaskScheduleMapper; |
| | | import com.ruoyi.task.domain.ServiceSubtaskPreachform; |
| | | import com.ruoyi.task.common.ScheduleSubtaskBuilder; |
| | | import com.ruoyi.task.mapper.ServiceSubtaskPreachformMapper; |
| | | import com.ruoyi.patarchive.domain.PatArchiveImport; |
| | | import com.ruoyi.patarchive.mapper.PatArchiveImportMapper; |
| | | import com.ruoyi.patarchive.mapper.PatArchiveMapper; |
| | | /** |
| | | * 患者住院记录Service业务层处理 |
| | | * |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class PatMedInhospServiceImpl implements IPatMedInhospService { |
| | | |
| | | @Autowired |
| | | private InhospVisitFacade inhospVisitFacade; |
| | | |
| | |
| | | @Autowired |
| | | private ServiceSubtaskPreachformMapper serviceSubtaskPreachformMapper; |
| | | @Autowired |
| | | private ServiceTaskmedicalMapper serviceTaskmedicalMapper; |
| | | @Autowired |
| | | private ServiceTaskRuleMapper serviceTaskRuleMapper; |
| | | |
| | | @Value("${spring.profiles.active}") |
| | | private String active; |
| | | @Autowired |
| | | private IConfigService iSysConfigService; |
| | | @Autowired |
| | | private ServiceTaskScheduleMapper serviceTaskScheduleMapper; |
| | | |
| | |
| | | private ScheduleSubtaskBuilder scheduleSubtaskBuilder; |
| | | @Autowired |
| | | private ServiceTaskScheduleDetailMapper serviceTaskScheduleDetailMapper; |
| | | |
| | | |
| | | /** |
| | | * 查询患者住院记录 |
| | | * |
| | | * @param inhospid 患者住院记录主键 |
| | | * @return 患者住院记录 |
| | | */ |
| | | @Override |
| | | public PatMedInhosp selectPatMedInhospByInhospid(Long inhospid) { |
| | | return inhospVisitFacade.selectPatMedInhospByInhospid(inhospid); |
| | | } |
| | | |
| | | @Override |
| | | public List<PatMedInhosp> selectPatMedInhosp(PatMedInhosp patMedInhosp) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 查询出入院人次 |
| | | * |
| | | * @param patMedReq |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PatMedRes selectPatMedInhospListCount(PatMedReq patMedReq) { |
| | | PatMedRes patMedRes = null; |
| | | // 获取当前登陆人的部门权限 |
| | | patMedRes = inhospVisitFacade.selectPatMedInhospCount(patMedReq); |
| | | return patMedRes; |
| | | } |
| | | |
| | | /** |
| | | * 新增患者住院记录 |
| | | * |
| | | * @param patMedInhosp 患者住院记录 |
| | |
| | | patMedInhosp.setUpdateTime(DateUtils.getNowDate()); |
| | | return inhospVisitFacade.updatePatMedInhosp(patMedInhosp); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除患者住院记录 |
| | | * |
| | | * @param inhospids 需要删除的患者住院记录主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deletePatMedInhospByInhospids(Long[] inhospids) { |
| | | return inhospVisitFacade.deletePatMedInhospByInhospids(inhospids); |
| | | } |
| | | |
| | | /** |
| | | * 删除患者住院记录信息 |
| | | * |
| | | * @param inhospid 患者住院记录主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deletePatMedInhospByInhospid(Long inhospid) { |
| | | return inhospVisitFacade.deletePatMedInhospByInhospid(inhospid); |
| | | } |
| | | |
| | | /** |
| | | * 删除患者住院记录信息 |
| | | * |
| | | * @param inhospno 患者住院编码 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deletePatMedInhospByInhospno(String inhospno) { |
| | | return inhospVisitFacade.deletePatMedInhospByInhospno(inhospno); |
| | | } |
| | | |
| | | @Override |
| | | public int dealOutHospInfo(String config) { |
| | | PatMedInhosp pmks = new PatMedInhosp(); |
| | | pmks.setDeptcheckFlag("0"); |
| | | pmks.setInhospstate("1"); |
| | | pmks.setFuflag("1"); |
| | | List<PatMedInhosp> patMedInhosps = inhospVisitFacade.selectPatMedInhospList(pmks); |
| | | |
| | | //1.入院宣教 |
| | | String helibrarySwitch = iSysConfigService.selectConfigByKey("in.helibrary.switch"); |
| | | if (StringUtils.isNotEmpty(helibrarySwitch) && "2".equals(helibrarySwitch)) { |
| | | |
| | | //1.1 科室 |
| | | for (PatMedInhosp patMedInhosp1 : patMedInhosps) { |
| | | //获取患者信息 |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedInhosp1.getPatid()); |
| | | if (Objects.isNull(patArchive)) { |
| | | patMedInhosp1.setInDeptcheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason("患者基本信息为空"); |
| | | inhospVisitFacade.updatePatMedInhosp(patMedInhosp1); |
| | | continue; |
| | | } |
| | | try { |
| | | //根据患者所在科室,获取该科室的入院长期宣教任务 |
| | | ServiceTaskdept serviceTaskdept = new ServiceTaskdept(); |
| | | serviceTaskdept.setLongtask(1L); |
| | | serviceTaskdept.setDeptCode(patMedInhosp1.getDeptcode()); |
| | | serviceTaskdept.setDeptType("1"); |
| | | serviceTaskdept.setServiceType("17"); |
| | | serviceTaskdept.setOrgid(patMedInhosp1.getOrgid()); |
| | | List<ServiceTaskdept> serviceTaskdepts = serviceTaskdeptMapper.selectServiceTaskdeptList(serviceTaskdept); |
| | | //如果部门模板为空(将deptIsNull设置为true) |
| | | if (CollectionUtils.isEmpty(serviceTaskdepts) || serviceTaskdepts.size() == 0) { |
| | | PatMedInhosp patMedInhosp = inhospVisitFacade.selectPatMedInhospByInhospid(patMedInhosp1.getInhospid()); |
| | | patMedInhosp1.setInDeptcheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason(StringUtils.isNotEmpty(patMedInhosp.getLongTaskReason()) ? patMedInhosp.getLongTaskReason() + "该患者所在科室未配置入院长期宣教任务;" : "该患者所在科室未配置入院长期宣教任务;"); |
| | | inhospVisitFacade.updatePatMedInhosp(patMedInhosp1); |
| | | } else { |
| | | for (ServiceTaskdept serviceTaskdept1 : serviceTaskdepts) { |
| | | writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedInhosp1, patArchive, 4, config); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | log.error("人员入院科室处理出异常了:{}", e.getMessage()); |
| | | patMedInhosp1.setInDeptcheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason("人员入院科室处理出异常了"); |
| | | inhospVisitFacade.updatePatMedInhosp(patMedInhosp1); |
| | | } |
| | | } |
| | | |
| | | |
| | | //1.2 病区 |
| | | pmks.setInDeptcheckFlag(null); |
| | | pmks.setInWardcheckFlag("0"); |
| | | pmks.setDeptcheckFlag(null); |
| | | List<PatMedInhosp> inPatMedInhospsWard = inhospVisitFacade.selectPatMedInhospList(pmks); |
| | | for (PatMedInhosp patMedInhosp1 : inPatMedInhospsWard) { |
| | | //获取患者信息 |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedInhosp1.getPatid()); |
| | | if (Objects.isNull(patArchive)) { |
| | | patMedInhosp1.setInDeptcheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason("患者基本信息为空"); |
| | | inhospVisitFacade.updatePatMedInhosp(patMedInhosp1); |
| | | continue; |
| | | } |
| | | //根据患者所在病区,获取该病区的入院长期宣教任务(会出现一个问题,科室和病区发的同一个模板) |
| | | ServiceTaskdept serviceTaskWard = new ServiceTaskdept(); |
| | | serviceTaskWard.setLongtask(1L); |
| | | serviceTaskWard.setDeptCode(patMedInhosp1.getHospitaldistrictcode()); |
| | | serviceTaskWard.setDeptType("2"); |
| | | serviceTaskWard.setServiceType("17"); |
| | | serviceTaskWard.setOrgid(patMedInhosp1.getOrgid()); |
| | | List<ServiceTaskdept> serviceTaskWardList = serviceTaskdeptMapper.selectServiceTaskdeptList(serviceTaskWard); |
| | | //如果部门模板为空(将deptIsNull设置为true) |
| | | if (CollectionUtils.isEmpty(serviceTaskWardList) || serviceTaskWardList.size() == 0) { |
| | | PatMedInhosp patMedInhosp = inhospVisitFacade.selectPatMedInhospByInhospid(patMedInhosp1.getInhospid()); |
| | | patMedInhosp1.setInDeptcheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason(patMedInhosp.getLongTaskReason() + "该患者所在病区未配置入院长期宣教任务;"); |
| | | inhospVisitFacade.updatePatMedInhosp(patMedInhosp1); |
| | | } else { |
| | | for (ServiceTaskdept serviceTaskdept1 : serviceTaskWardList) { |
| | | writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedInhosp1, patArchive, 5, config); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //2.药品宣教(省立同德的需求,其它地方没提) |
| | | if (active.equals("sltd")) { |
| | | for (PatMedInhosp patMedInhosp : patMedInhosps) { |
| | | String medicalCode = patMedInhosp.getMedicalCode(); |
| | | if (StringUtils.isNotEmpty(medicalCode)) { |
| | | String[] split = medicalCode.split(","); |
| | | // 防御性编程:确保 medicalCompany 和 medicalName 不为 null |
| | | String medicalCompanyStr = patMedInhosp.getMedicalCompany() != null ? patMedInhosp.getMedicalCompany() : ""; |
| | | String medicalNameStr = patMedInhosp.getMedicalName() != null ? patMedInhosp.getMedicalName() : ""; |
| | | String[] medicalCompanyArray = medicalCompanyStr.split(","); |
| | | String[] medicalNameArray = medicalNameStr.split(","); |
| | | |
| | | for (int i = 0; i < split.length; i++) { |
| | | ServiceTaskmedical serviceTaskmedical = new ServiceTaskmedical(); |
| | | //拿药品编码和公司去查 |
| | | serviceTaskmedical.setMedicalCode(split[i]); |
| | | // 防止下标越界:如果数组长度不一致,取最小长度 |
| | | if (i < medicalCompanyArray.length) { |
| | | serviceTaskmedical.setMedicalCompany(medicalCompanyArray[i]); |
| | | } else { |
| | | log.warn("【药品宣教】药品编码{}对应的公司信息下标越界,medicalCompany 数组长度={}, 当前索引={}", split[i], medicalCompanyArray.length, i); |
| | | serviceTaskmedical.setMedicalName(""); // 越界时设置为空 |
| | | } |
| | | List<ServiceTaskmedical> serviceTaskmedicals = serviceTaskmedicalMapper.selectServiceTaskmedicalList(serviceTaskmedical); |
| | | if (CollectionUtils.isNotEmpty(serviceTaskmedicals)) { |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedInhosp.getPatid()); |
| | | // check=true,让 writeInSubTask 内部做去重校验 |
| | | writeInSubTask(serviceTaskmedicals.get(0).getTaskId(), true, patMedInhosp, patArchive, 0, config); |
| | | } |
| | | //查不到的药品就是不需要宣教的,就不管了 |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //3.出院随访 - 基于规则的任务生成 |
| | | // 获取所有需要处理的出院患者(科室维度未处理) |
| | | |
| | | addSubTaskByRule(config, patMedInhosps); |
| | | if (!active.equals("xh")) { |
| | | addOperationSubTask(config); |
| | | } |
| | | |
| | | |
| | | //获取未处理在院的数据(如果刚刚出院的患者数据的出院时间,在下面查询出的入院时间之前,那之前的出院患者的数据,也得停掉,因为又入院了) |
| | | PatMedInhosp patMedInhosp = new PatMedInhosp(); |
| | | patMedInhosp.setDeptcheckFlag("0"); |
| | | patMedInhosp.setInhospstate("0"); |
| | | List<PatMedInhosp> patMedInhospList = inhospVisitFacade.selectPatMedInhospList(patMedInhosp); |
| | | if (CollectionUtils.isNotEmpty(patMedInhospList) && patMedInhospList.size() > 0) { |
| | | dealInHospInfo(patMedInhospList); |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | /** |
| | | * 任务组随访 |
| | | * |
| | | * @param config |
| | | * @return |
| | | */ |
| | | public int dealOutHospInfoBySchedule(String config) { |
| | | |
| | | ServiceTask serviceTaskVo = new ServiceTask(); |
| | | serviceTaskVo.setLongTask(1); |
| | | serviceTaskVo.setAppltype("5"); |
| | | List<ServiceTask> serviceTasks = serviceTaskMapper.selectServiceTaskList(serviceTaskVo); |
| | | |
| | | if (CollectionUtils.isNotEmpty(serviceTasks)) { |
| | | for (ServiceTask serviceTask : serviceTasks) { |
| | | if (!ObjectUtils.isEmpty(serviceTask.getTaskid())) { |
| | | ServiceTaskSchedule serviceTaskSchedule = new ServiceTaskSchedule(); |
| | | ServiceTaskSchedule taskSchedule = new ServiceTaskSchedule(); |
| | | taskSchedule.setTaskid(serviceTask.getTaskid()); |
| | | List<ServiceTaskSchedule> serviceTaskSchedules = serviceTaskScheduleMapper.selectServiceTaskScheduleList(taskSchedule); |
| | | if (CollectionUtils.isNotEmpty(serviceTaskSchedules)) { |
| | | serviceTaskSchedule = serviceTaskSchedules.get(0); |
| | | String deptCodes = serviceTaskSchedule.getDeptCodes(); |
| | | String wardCodes = serviceTaskSchedule.getWardCodes(); |
| | | String icd10Codes = serviceTaskSchedule.getIcd10Codes(); |
| | | String opLevelCodes = serviceTaskSchedule.getOplevelCodes(); |
| | | |
| | | List<String> icd10CodeList = new ArrayList<>(); |
| | | List<String> opLevelCodeList = new ArrayList<>(); |
| | | List<String> deptCodeList = new ArrayList<>(); |
| | | List<String> wardCodeList = new ArrayList<>(); |
| | | |
| | | /** |
| | | * 随访类型(1-科室,2-病区,3-疾病 4-入院科室 5-入院病区 6-手术) |
| | | */ |
| | | Integer type = 1; |
| | | if (StringUtils.isNotEmpty(deptCodes)) { |
| | | type = 1; |
| | | deptCodeList = new ArrayList<>(Arrays.asList(deptCodes.split(","))); |
| | | } |
| | | if (StringUtils.isNotEmpty(wardCodes)) { |
| | | type = 2; |
| | | wardCodeList = new ArrayList<>(Arrays.asList(wardCodes.split(","))); |
| | | } |
| | | if (StringUtils.isNotEmpty(icd10Codes)) { |
| | | type = 3; |
| | | icd10CodeList = new ArrayList<>(Arrays.asList(icd10Codes.split(","))); |
| | | } |
| | | if (StringUtils.isNotEmpty(opLevelCodes)) { |
| | | type = 6; |
| | | opLevelCodeList = new ArrayList<>(Arrays.asList(opLevelCodes.split(","))); |
| | | } |
| | | //非手术处理方式 |
| | | if (type != 6) { |
| | | PatMedInhosp patMedInhospVo = new PatMedInhosp(); |
| | | patMedInhospVo.setScheduleCheckFlag("0"); |
| | | patMedInhospVo.setInhospstate("1"); |
| | | patMedInhospVo.setFuflag("1"); |
| | | // patMedInhospVo.setDeptcodeList(deptCodeList); |
| | | patMedInhospVo.setLeaveldeptcodes(deptCodeList); |
| | | patMedInhospVo.setLeavehospitaldistrictcodes(wardCodeList); |
| | | patMedInhospVo.setIcd10codeList(icd10CodeList); |
| | | List<PatMedInhosp> patList = inhospVisitFacade.selectPatMedInhospList(patMedInhospVo); |
| | | log.info("dealOutHospInfoBySchedule 任务组随访, taskid = {}, 扫描患者人数 {}", serviceTask.getTaskid(), patList.size()); |
| | | |
| | | for (PatMedInhosp patMedInhosp : patList) { |
| | | ServiceTaskScheduleDetail scheduleDetailVo = new ServiceTaskScheduleDetail(); |
| | | scheduleDetailVo.setTaskid(serviceTask.getTaskid()); |
| | | scheduleDetailVo.setScheduleid(serviceTaskSchedule.getId()); |
| | | List<ServiceTaskScheduleDetail> serviceTaskScheduleDetails = serviceTaskScheduleDetailMapper.selectServiceTaskScheduleDetailList(scheduleDetailVo); |
| | | |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedInhosp.getPatid()); |
| | | if (Objects.isNull(patArchive)) { |
| | | continue; |
| | | } |
| | | //封装serviceSubtask |
| | | |
| | | ServiceSubtask serviceSubtask = boxedServiceSubtask(serviceTask, patMedInhosp, patArchive, config, type); |
| | | List<Map<String, Object>> preachformList = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(serviceTask.getPreachformDesc())) { |
| | | try { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | preachformList = objectMapper.readValue(serviceTask.getPreachformDesc(), List.class); |
| | | } catch (Exception e) { |
| | | log.error("任务组preachformDesc解析失败,taskid={},inhospid={}", serviceTask.getTaskid(), patMedInhosp.getInhospid()); |
| | | } |
| | | } |
| | | scheduleSubtaskBuilder.buildSubtasksForPatient(serviceTask, serviceTaskSchedule, serviceTaskScheduleDetails, serviceSubtask, preachformList); |
| | | //置首轮纳入标记,避免下次扫描重复生成(后续轮次由 rollTaskGroupCycle 负责) |
| | | PatMedInhosp flagUpd = new PatMedInhosp(); |
| | | flagUpd.setInhospid(patMedInhosp.getInhospid()); |
| | | flagUpd.setScheduleCheckFlag("1"); |
| | | inhospVisitFacade.updatePatMedInhosp(flagUpd); |
| | | } |
| | | } else { |
| | | //任务组 - 手术随访 |
| | | if (CollectionUtils.isNotEmpty(opLevelCodeList)) { |
| | | PatMedOperationItem pmoi = new PatMedOperationItem(); |
| | | //获取需要出院疾病随访,未处理的数据 |
| | | pmoi.setOpercheckFlag("0"); |
| | | pmoi.setMainFlag("1"); |
| | | pmoi.setDeptCodes(deptCodeList); |
| | | pmoi.setWardCodes(wardCodeList); |
| | | pmoi.setOpLevelCodes(opLevelCodeList); |
| | | |
| | | //每次查询只查最大的手术等级记录 |
| | | List<PatMedOperationItem> patMedOperationItems = otherVisitFacade.selectOperationItemListMaxLevel(pmoi); |
| | | for (PatMedOperationItem patMedOperationItem : patMedOperationItems) { |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedOperationItem.getPatid()); |
| | | if (Objects.isNull(patArchive)) { |
| | | continue; |
| | | } |
| | | PatMedInhosp patMedInhospVo = new PatMedInhosp(); |
| | | patMedInhospVo.setPatid((patMedOperationItem.getPatid())); |
| | | patMedInhospVo.setScheduleCheckFlag("0"); |
| | | patMedInhospVo.setInhospstate("1"); |
| | | patMedInhospVo.setFuflag("1"); |
| | | List<PatMedInhosp> patMedInhospList = inhospVisitFacade.selectPatMedInhospList(patMedInhospVo); |
| | | if (CollectionUtils.isNotEmpty(patMedInhospList)) { |
| | | ServiceTaskScheduleDetail scheduleDetailVo = new ServiceTaskScheduleDetail(); |
| | | scheduleDetailVo.setTaskid(serviceTask.getTaskid()); |
| | | scheduleDetailVo.setScheduleid(serviceTaskSchedule.getId()); |
| | | List<ServiceTaskScheduleDetail> serviceTaskScheduleDetails = serviceTaskScheduleDetailMapper.selectServiceTaskScheduleDetailList(scheduleDetailVo); |
| | | //封装serviceSubtask |
| | | ServiceSubtask serviceSubtask = boxedServiceSubtaskForOp(serviceTask, patMedInhospList.get(0), patMedOperationItem, patArchive, config); |
| | | List<Map<String, Object>> preachformList = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(serviceTask.getPreachformDesc())) { |
| | | try { |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | preachformList = objectMapper.readValue(serviceTask.getPreachformDesc(), List.class); |
| | | } catch (Exception e) { |
| | | log.error("任务组(手术)preachformDesc解析失败,taskid={}", serviceTask.getTaskid()); |
| | | } |
| | | } |
| | | scheduleSubtaskBuilder.buildSubtasksForPatient(serviceTask, serviceTaskSchedule, serviceTaskScheduleDetails, serviceSubtask, preachformList); |
| | | //置首轮纳入标记,避免重复生成 |
| | | PatMedInhosp flagUpd = new PatMedInhosp(); |
| | | flagUpd.setInhospid(patMedInhospList.get(0).getInhospid()); |
| | | flagUpd.setScheduleCheckFlag("1"); |
| | | inhospVisitFacade.updatePatMedInhosp(flagUpd); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return 1; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取出院,住院,门诊服务人次 |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void addOperationSubTask(String config) { |
| | | // 手术随访 |
| | | PatMedOperationItem pmoi = new PatMedOperationItem(); |
| | | //获取需要出院手术随访,未处理的数据 |
| | | if(!active.equals("hzszlyy")){ |
| | | pmoi.setInhospstate("1"); |
| | | } |
| | | pmoi.setOpercheckFlag("0"); |
| | | pmoi.setMainFlag("1"); |
| | | |
| | | //每次查询只查最大的手术等级记录 |
| | | List<PatMedOperationItem> patMedOperationItems = otherVisitFacade.selectOperationItemListMaxLevel(pmoi); |
| | | log.info("dealOutHospInfo需要处理的出院手术患者信息:{}", CollectionUtils.isNotEmpty(patMedOperationItems) ? patMedOperationItems.size() : null); |
| | | |
| | | for (PatMedOperationItem opItem : patMedOperationItems) { |
| | | |
| | | try { |
| | | if (StringUtils.isEmpty(opItem.getOplevelcode())) { |
| | | continue; |
| | | } |
| | | // 根据患者的疾病,获取该疾病的长期任务 |
| | | List<ServiceTaskoper> serviceTaskopersDept = new ArrayList<>(); |
| | | if(StringUtils.isNotEmpty(opItem.getLeaveldeptcode())){ |
| | | ServiceTaskoper serviceTaskoper1 = new ServiceTaskoper(); |
| | | serviceTaskoper1.setLongtask(1L); |
| | | serviceTaskoper1.setOrgid(opItem.getOrgid()); |
| | | serviceTaskoper1.setOplevelcode(opItem.getOplevelcode()); |
| | | serviceTaskoper1.setDeptCode(opItem.getLeaveldeptcode()); |
| | | serviceTaskopersDept = serviceTaskoperMapper.selectServiceTaskoperList(serviceTaskoper1); |
| | | } |
| | | |
| | | |
| | | List<ServiceTaskoper> serviceTaskopersWard = new ArrayList<>(); |
| | | if(StringUtils.isNotEmpty(opItem.getLeavehospitaldistrictcode())){ |
| | | ServiceTaskoper serviceTaskoper2 = new ServiceTaskoper(); |
| | | serviceTaskoper2.setLongtask(1L); |
| | | serviceTaskoper2.setOrgid(opItem.getOrgid()); |
| | | serviceTaskoper2.setOplevelcode(opItem.getOplevelcode()); |
| | | serviceTaskoper2.setWardCode(opItem.getLeavehospitaldistrictcode()); |
| | | serviceTaskopersWard = serviceTaskoperMapper.selectServiceTaskoperList(serviceTaskoper2); |
| | | } |
| | | |
| | | |
| | | List<ServiceTaskoper> serviceTaskopers = new ArrayList<>(); |
| | | serviceTaskopers.addAll(serviceTaskopersDept); |
| | | serviceTaskopers.addAll(serviceTaskopersWard); |
| | | //如果部门模板为空(将deptIsNull设置为true) |
| | | if (CollectionUtils.isEmpty(serviceTaskopers) || serviceTaskopers.size() == 0) { |
| | | PatMedOperationItem patMedOperationItem = otherVisitFacade.selectOperationItemById(opItem.getId()); |
| | | patMedOperationItem.setOpercheckFlag("2"); |
| | | patMedOperationItem.setLongTaskReason("所患的手术未配置长期任务;"); |
| | | patMedOperationItem.setUpdateTime(new Date()); |
| | | otherVisitFacade.updateOperationItem(patMedOperationItem); |
| | | } else { |
| | | for (ServiceTaskoper serviceTaskoper : serviceTaskopers) { |
| | | writeInSubTaskForOp(serviceTaskoper.getTaskId(), true, opItem, config); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("人员手术处理出异常了:{}", e.getMessage()); |
| | | opItem.setUpdateTime(new Date()); |
| | | opItem.setOpercheckFlag("2"); |
| | | opItem.setLongTaskReason("人员手术处理异常"); |
| | | otherVisitFacade.updateOperationItem(opItem); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void addIcd10SubTask(String config) { |
| | | PatMedInhosp pmjb = new PatMedInhosp(); |
| | | //获取需要出院疾病随访,未处理的数据 |
| | | pmjb.setDiagcheckFlag("0"); |
| | | pmjb.setInhospstate("1"); |
| | | pmjb.setFuflag("1"); |
| | | List<PatMedInhosp> patMedInhospJBs = inhospVisitFacade.selectPatMedInhospList(pmjb); |
| | | log.info("dealOutHospInfo需要处理的出院疾病患者信息:{}", CollectionUtils.isNotEmpty(patMedInhospJBs) ? patMedInhospJBs.size() : null); |
| | | for (PatMedInhosp patMedInhosp1 : patMedInhospJBs) { |
| | | String tagname = inhospVisitFacade.getTagnameBypatid(patMedInhosp1.getPatid()); |
| | | patMedInhosp1.setTagname(tagname); |
| | | } |
| | | |
| | | for (PatMedInhosp pmiJB : patMedInhospJBs) { |
| | | //获取患者信息 |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(pmiJB.getPatid()); |
| | | if (Objects.isNull(patArchive)) { |
| | | pmiJB.setDiagcheckFlag("2"); |
| | | pmiJB.setLongTaskReason("患者基本信息为空"); |
| | | inhospVisitFacade.updatePatMedInhosp(pmiJB); |
| | | continue; |
| | | } |
| | | try { |
| | | String errorIcd = null; |
| | | if (StringUtils.isEmpty(pmiJB.getLeaveicd10code())) { |
| | | continue; |
| | | } |
| | | // 根据患者的疾病,获取该疾病的长期任务 |
| | | ServiceTaskdiag serviceTaskdiag = new ServiceTaskdiag(); |
| | | serviceTaskdiag.setLongtask(1L); |
| | | // serviceTaskdiag.setServiceType("2"); |
| | | if (active.equals("nhfy")) { |
| | | //南华附一的icd10code有重复,所以用主诊断名称去查询 |
| | | serviceTaskdiag.setIcd10name(pmiJB.getLeavediagname()); |
| | | if (StringUtils.isEmpty(pmiJB.getLeavediagname())) { |
| | | errorIcd = "该患者主诊断名称为空;"; |
| | | } |
| | | } else { |
| | | serviceTaskdiag.setIcd10code(pmiJB.getLeaveicd10code()); |
| | | if (StringUtils.isEmpty(pmiJB.getLeaveicd10code())) { |
| | | errorIcd = "该患者主诊断ICD10码为空;"; |
| | | } |
| | | } |
| | | serviceTaskdiag.setOrgid(pmiJB.getOrgid()); |
| | | List<ServiceTaskdiag> serviceTaskdiags = serviceTaskdiagMapper.selectServiceTaskdiagListByIcdName(serviceTaskdiag); |
| | | |
| | | //如果部门模板为空(将deptIsNull设置为true) |
| | | if (StringUtils.isNotEmpty(errorIcd)) { |
| | | PatMedInhosp patMedInhosp = inhospVisitFacade.selectPatMedInhospByInhospid(pmiJB.getInhospid()); |
| | | pmiJB.setDiagcheckFlag("2"); |
| | | pmiJB.setLongTaskReason(StringUtils.isNotEmpty(patMedInhosp.getLongTaskReason()) ? patMedInhosp.getLongTaskReason() + errorIcd : errorIcd); |
| | | inhospVisitFacade.updatePatMedInhosp(pmiJB); |
| | | } else if (CollectionUtils.isEmpty(serviceTaskdiags)) { |
| | | errorIcd = "该患者所患疾病未配置长期任务;"; |
| | | PatMedInhosp patMedInhosp = inhospVisitFacade.selectPatMedInhospByInhospid(pmiJB.getInhospid()); |
| | | pmiJB.setDiagcheckFlag("2"); |
| | | pmiJB.setLongTaskReason(StringUtils.isNotEmpty(patMedInhosp.getLongTaskReason()) ? patMedInhosp.getLongTaskReason() + errorIcd : errorIcd); |
| | | inhospVisitFacade.updatePatMedInhosp(pmiJB); |
| | | } else { |
| | | int flag = 0; |
| | | for (ServiceTaskdiag serviceTaskdept1 : serviceTaskdiags) { |
| | | //必须科室或病区能匹配上,才可以用这个疾病创建子任务(主要处理一个疾病在多个病区或科室出现) |
| | | if (StringUtils.isNotEmpty(serviceTaskdept1.getDeptCode()) && serviceTaskdept1.getDeptCode().equals(pmiJB.getLeaveldeptcode())) { |
| | | writeInSubTask(serviceTaskdept1.getTaskId(), true, pmiJB, patArchive, 3, config); |
| | | flag = 1; |
| | | } else if (StringUtils.isNotEmpty(serviceTaskdept1.getWardCode()) && serviceTaskdept1.getWardCode().equals(pmiJB.getLeavehospitaldistrictcode())) { |
| | | writeInSubTask(serviceTaskdept1.getTaskId(), true, pmiJB, patArchive, 3, config); |
| | | flag = 1; |
| | | } |
| | | } |
| | | if (flag == 0) { |
| | | log.error("该科室或病区对于患者所患疾病未配置长期任务,患者:{}", pmiJB.getInhospid()); |
| | | errorIcd = "该科室或病区对于患者所患疾病未配置长期任务;"; |
| | | PatMedInhosp patMedInhosp = inhospVisitFacade.selectPatMedInhospByInhospid(pmiJB.getInhospid()); |
| | | pmiJB.setDiagcheckFlag("2"); |
| | | pmiJB.setLongTaskReason(StringUtils.isNotEmpty(patMedInhosp.getLongTaskReason()) ? patMedInhosp.getLongTaskReason() + errorIcd : errorIcd); |
| | | inhospVisitFacade.updatePatMedInhosp(pmiJB); |
| | | } |
| | | |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("人员疾病处理出异常了:{}", e.getMessage()); |
| | | pmiJB.setDiagcheckFlag("2"); |
| | | pmiJB.setLongTaskReason("人员疾病处理异常"); |
| | | inhospVisitFacade.updatePatMedInhosp(pmiJB); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void addWardSubTask(String config) { |
| | | PatMedInhosp pmbq = new PatMedInhosp(); |
| | | //获取需要出院部门随访,未处理的数据 |
| | | pmbq.setWardcheckFlag("0"); |
| | | pmbq.setInhospstate("1"); |
| | | pmbq.setFuflag("1"); |
| | | List<PatMedInhosp> patMedInhospBQs = inhospVisitFacade.selectPatMedInhospList(pmbq); |
| | | log.info("dealOutHospInfo需要处理的出院病区患者信息:{}", CollectionUtils.isNotEmpty(patMedInhospBQs) ? patMedInhospBQs.size() : null); |
| | | for (PatMedInhosp patMedInhosp1 : patMedInhospBQs) { |
| | | String tagname = inhospVisitFacade.getTagnameBypatid(patMedInhosp1.getPatid()); |
| | | patMedInhosp1.setTagname(tagname); |
| | | } |
| | | |
| | | //病区数据处理 |
| | | for (PatMedInhosp pmiBQ1 : patMedInhospBQs) { |
| | | if ("1".equals(pmiBQ1.getLeavehospitaldistrictcode()) && pmiBQ1.getDiagcheckFlag().equals("1")) { |
| | | pmiBQ1.setWardcheckFlag("2"); |
| | | pmiBQ1.setLongTaskReason("根据交叉生成随访任务规则,病区任务可以不用生成"); |
| | | inhospVisitFacade.updatePatMedInhosp(pmiBQ1); |
| | | continue; |
| | | } |
| | | |
| | | //获取患者信息 |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(pmiBQ1.getPatid()); |
| | | if (Objects.isNull(patArchive)) { |
| | | pmiBQ1.setWardcheckFlag("2"); |
| | | pmiBQ1.setLongTaskReason("患者基本信息为空"); |
| | | inhospVisitFacade.updatePatMedInhosp(pmiBQ1); |
| | | continue; |
| | | } |
| | | try { |
| | | String errorreason = null; |
| | | List<ServiceTaskdept> serviceTaskdeptList = null; |
| | | if (!StringUtils.isEmpty(pmiBQ1.getLeavehospitaldistrictcode())) { |
| | | ServiceTaskdept serviceTaskdept = new ServiceTaskdept(); |
| | | serviceTaskdept.setLongtask(1L); |
| | | serviceTaskdept.setDeptCode(pmiBQ1.getLeavehospitaldistrictcode()); |
| | | serviceTaskdept.setDeptType("2"); |
| | | serviceTaskdept.setServiceType("2"); |
| | | serviceTaskdept.setOrgid(pmiBQ1.getOrgid()); |
| | | serviceTaskdeptList = serviceTaskdeptMapper.selectServiceTaskdeptList(serviceTaskdept); |
| | | if (CollectionUtils.isEmpty(serviceTaskdeptList)) { |
| | | errorreason = "该患者所在病区未配置长期任务;"; |
| | | } |
| | | } else { |
| | | errorreason = "离院病区为空;"; |
| | | } |
| | | //如果部门模板为空(将deptIsNull设置为true) |
| | | if (StringUtils.isNotEmpty(errorreason)) { |
| | | PatMedInhosp patMedInhosp = inhospVisitFacade.selectPatMedInhospByInhospid(pmiBQ1.getInhospid()); |
| | | pmiBQ1.setWardcheckFlag("2"); |
| | | pmiBQ1.setLongTaskReason(StringUtils.isNotEmpty(patMedInhosp.getLongTaskReason()) ? patMedInhosp.getLongTaskReason() + errorreason : errorreason); |
| | | inhospVisitFacade.updatePatMedInhosp(pmiBQ1); |
| | | } else { |
| | | for (ServiceTaskdept serviceTaskdept1 : serviceTaskdeptList) { |
| | | writeInSubTask(serviceTaskdept1.getTaskId(), true, pmiBQ1, patArchive, 2, config); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("人员病区处理出异常了:{}", e.getMessage()); |
| | | pmiBQ1.setWardcheckFlag("2"); |
| | | pmiBQ1.setLongTaskReason("人员病区处理异常"); |
| | | inhospVisitFacade.updatePatMedInhosp(pmiBQ1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void addDeptSubTask(String config) { |
| | | //获取需要出院部门随访,未处理的数据 |
| | | PatMedInhosp pmks = new PatMedInhosp(); |
| | | pmks.setDeptcheckFlag("0"); |
| | | pmks.setInhospstate("1"); |
| | | pmks.setFuflag("1"); |
| | | List<PatMedInhosp> patMedInhosps = inhospVisitFacade.selectPatMedInhospList(pmks); |
| | | log.info("dealOutHospInfo需要处理的出院部门患者信息:{}", CollectionUtils.isNotEmpty(patMedInhosps) ? patMedInhosps.size() : null); |
| | | for (PatMedInhosp patMedInhosp1 : patMedInhosps) { |
| | | String tagname = inhospVisitFacade.getTagnameBypatid(patMedInhosp1.getPatid()); |
| | | patMedInhosp1.setTagname(tagname); |
| | | } |
| | | |
| | | //科室 |
| | | for (PatMedInhosp patMedInhosp1 : patMedInhosps) { |
| | | if ("1".equals(patMedInhosp1.getLeavehospitaldistrictcode()) && patMedInhosp1.getDiagcheckFlag().equals("1")) { |
| | | patMedInhosp1.setDeptcheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason("根据交叉生成随访任务规则,部门任务可以不用生成"); |
| | | inhospVisitFacade.updatePatMedInhosp(patMedInhosp1); |
| | | continue; |
| | | } |
| | | //获取患者信息 |
| | | PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedInhosp1.getPatid()); |
| | | if (Objects.isNull(patArchive)) { |
| | | patMedInhosp1.setDeptcheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason("患者基本信息为空"); |
| | | inhospVisitFacade.updatePatMedInhosp(patMedInhosp1); |
| | | continue; |
| | | } |
| | | try { |
| | | //根据患者所在科室,获取该科室的长期任务 |
| | | ServiceTaskdept serviceTaskdept = new ServiceTaskdept(); |
| | | serviceTaskdept.setLongtask(1L); |
| | | serviceTaskdept.setDeptCode(patMedInhosp1.getLeaveldeptcode()); |
| | | serviceTaskdept.setDeptType("1"); |
| | | serviceTaskdept.setServiceType("2"); |
| | | serviceTaskdept.setOrgid(patMedInhosp1.getOrgid()); |
| | | List<ServiceTaskdept> serviceTaskdepts = serviceTaskdeptMapper.selectServiceTaskdeptList(serviceTaskdept); |
| | | //如果部门模板为空(将deptIsNull设置为true) |
| | | if (CollectionUtils.isEmpty(serviceTaskdepts) || serviceTaskdepts.size() == 0) { |
| | | PatMedInhosp patMedInhosp = inhospVisitFacade.selectPatMedInhospByInhospid(patMedInhosp1.getInhospid()); |
| | | patMedInhosp1.setDeptcheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason(patMedInhosp.getLongTaskReason() + "该患者所在科室未配置离院长期任务;"); |
| | | inhospVisitFacade.updatePatMedInhosp(patMedInhosp1); |
| | | } else { |
| | | for (ServiceTaskdept serviceTaskdept1 : serviceTaskdepts) { |
| | | writeInSubTask(serviceTaskdept1.getTaskId(), true, patMedInhosp1, patArchive, 1, config); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("人员科室处理出异常了:{}", e.getMessage()); |
| | | patMedInhosp1.setDeptcheckFlag("2"); |
| | | patMedInhosp1.setLongTaskReason("人员科室处理异常"); |
| | | inhospVisitFacade.updatePatMedInhosp(patMedInhosp1); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 统一更新pat_med_inhosp的check_flag |
| | | * |
| | |
| | | inhospVisitFacade.updatePatMedInhosp(patMedInhosp1); |
| | | } |
| | | return generatedCount; |
| | | } |
| | | |
| | | // ========================================================================== |
| | | // 出入院随访模块化(第一批)—— 3 个过渡期入口(纯转发,零业务逻辑) |
| | | // |
| | | // ⚠️ 这 3 个方法是刻意新增的,不是误加: |
| | | // 见 IPatMedInhospService 里同名的接口声明注释,以及 |
| | | // sql/_probe/verify_step16_service_restore.py 的 expected_added 断言。 |
| | | // ========================================================================== |
| | | |
| | | /** |
| | | * 【过渡期用】手术随访扫描 —— 与 {@link #addOperationSubTask(String)} 完全等价。 |
| | | * <p> |
| | | * ⚠️ {@code addOperationSubTask} 原实现返回 {@code void},所以这里按"处理了 1 轮"返回 1, |
| | | * 仅用于日志;<b>调用方不得依赖该返回值的业务含义</b>。 |
| | | */ |
| | | @Override |
| | | public int runOperationVisit(String config) { |
| | | addOperationSubTask(config); |
| | | return 1; |
| | | } |
| | | |
| | | /** |
| | | * 【过渡期用】科室维度未处理的在院患者。 |
| | | * <p> |
| | | * 条件与原 {@code dealOutHospInfo} 第一段查询逐字一致: |
| | | * {@code deptcheckFlag="0"} + {@code inhospstate="1"} + {@code fuflag="1"}。 |
| | | */ |
| | | @Override |
| | | public List<PatMedInhosp> selectPendingDeptPatientsForVisit() { |
| | | PatMedInhosp pmks = new PatMedInhosp(); |
| | | pmks.setDeptcheckFlag("0"); |
| | | pmks.setInhospstate("1"); |
| | | pmks.setFuflag("1"); |
| | | return inhospVisitFacade.selectPatMedInhospList(pmks); |
| | | } |
| | | |
| | | /** |
| | | * 【过渡期用】把一条已组装好的子任务落库(原 {@code serviceSubtaskMapper.insertServiceSubtask})。 |
| | | */ |
| | | @Override |
| | | public boolean persistSubtask(ServiceSubtask serviceSubtask) { |
| | | return serviceSubtaskMapper.insertServiceSubtask(serviceSubtask) == 1; |
| | | } |
| | | |
| | | } |