| | |
| | | package cn.lihu.jh.module.ecg.service.appointment; |
| | | |
| | | import cn.lihu.jh.framework.common.pojo.PageResult; |
| | | import cn.lihu.jh.framework.common.util.date.DateUtils; |
| | | import cn.lihu.jh.framework.common.util.date.LocalDateTimeUtils; |
| | | import cn.lihu.jh.framework.common.util.object.BeanUtils; |
| | | import cn.lihu.jh.module.ecg.controller.admin.appointment.vo.AppointmentConfirmReqVO; |
| | | import cn.lihu.jh.module.ecg.controller.admin.appointment.vo.AppointmentPageReqVO; |
| | | import cn.lihu.jh.module.ecg.controller.admin.appointment.vo.AppointmentSaveReqVO; |
| | | import cn.lihu.jh.module.ecg.controller.admin.queue.vo.QueueSaveReqVO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.checktype.CheckTypeDO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.appointment.AppointmentDO; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.patient.PatDetails; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.queue.QueueDO; |
| | | import cn.lihu.jh.module.ecg.dal.mysql.appointment.AppointmentMapper; |
| | | import cn.lihu.jh.module.ecg.enums.HisCheckCodeEnum; |
| | | import cn.lihu.jh.module.ecg.feign.RemoteDataService; |
| | | import cn.lihu.jh.module.ecg.feign.RestApiReqBodyVo; |
| | | import cn.lihu.jh.module.ecg.feign.RestApiResult; |
| | | import cn.lihu.jh.module.ecg.feign.dto.AppointmentExternal; |
| | | import cn.lihu.jh.module.ecg.service.config.EcgConfigService; |
| | | import cn.lihu.jh.module.ecg.service.queue.QueueService; |
| | | import cn.lihu.jh.module.ecg.service.queue.QueueServiceTxFunctions; |
| | | import cn.lihu.jh.module.ecg.service.queuesequence.QueueSequenceService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.springframework.dao.DuplicateKeyException; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | |
| | | import cn.lihu.jh.module.ecg.controller.admin.appointment.vo.*; |
| | | import cn.lihu.jh.module.ecg.dal.dataobject.appointment.AppointmentDO; |
| | | import cn.lihu.jh.framework.common.pojo.PageResult; |
| | | import cn.lihu.jh.framework.common.util.object.BeanUtils; |
| | | |
| | | import cn.lihu.jh.module.ecg.dal.mysql.appointment.AppointmentMapper; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.xml.crypto.Data; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.lihu.jh.framework.common.pojo.CommonResult.error; |
| | | import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.*; |
| | | |
| | | /** |
| | |
| | | public Long createAppointment(AppointmentSaveReqVO createReqVO) { |
| | | // 插入 |
| | | AppointmentDO appointment = BeanUtils.toBean(createReqVO, AppointmentDO.class); |
| | | |
| | | appointment.setBookTime( LocalDateTime.now() ); |
| | | |
| | | try { |
| | | appointmentMapper.insert(appointment); |
| | |
| | | |
| | | @Override |
| | | public AppointmentDO getCurAppointmentByPatIdAndCheckType(String patId, Integer checkType) { |
| | | AppointmentDO appointmentDO = appointmentMapper.getByPatAndCheckTypeAndBookDate( patId, checkType, LocalDate.now() ); |
| | | AppointmentDO appointmentDO = appointmentMapper.getByPatAndCheckTypeAndBookDate(patId, checkType); |
| | | return appointmentDO; |
| | | } |
| | | |
| | |
| | | @Override |
| | | public List<AppointmentDO> queryAndCreateAppointmentByPatId(String patCode) { |
| | | // 从医院平台查询 |
| | | List<AppointmentDO> appointmentExtermalList = getAppointmentExtermal( patCode ); |
| | | List<AppointmentDO> appointmentExtermalList = getAppointmentExtermal(patCode); |
| | | |
| | | for ( int appointmentIndex = 0; appointmentIndex < appointmentExtermalList.size(); appointmentIndex++ ) { |
| | | for (int appointmentIndex = 0; appointmentIndex < appointmentExtermalList.size(); appointmentIndex++) { |
| | | AppointmentDO appointmentExtermal = appointmentExtermalList.get(appointmentIndex); |
| | | if (null == appointmentExtermal ) |
| | | continue; |
| | | if (null == appointmentExtermal) continue; |
| | | |
| | | // 从DB查询预约,是否已经存在 |
| | | AppointmentDO appointmentDO = appointmentMapper.getByEpisodeIdAndApplyNo(appointmentExtermal.getEpisodeId(), appointmentExtermal.getApplyNo()); |
| | | if (null == appointmentDO) { |
| | | appointmentMapper.insert(appointmentExtermal); |
| | | } else { |
| | | appointmentExtermal.setId( appointmentDO.getId() ); // 确保 返回值包含 appointment id |
| | | appointmentExtermal.setId(appointmentDO.getId()); // 确保 返回值包含 appointment id |
| | | |
| | | // 处理第一次确认时还没有预约时间,再来确认时已有预约时间的情况 |
| | | if (appointmentDO.getBookDate() != appointmentExtermal.getBookDate()) { |
| | | appointmentMapper.updateById( appointmentExtermal ); |
| | | appointmentMapper.updateById(appointmentExtermal); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public List<AppointmentDO> getAppointmentExtermal(String patId) { |
| | | List<AppointmentDO> curAppointDOList = new ArrayList<AppointmentDO>(); |
| | | |
| | | RestApiReqBodyVo reqBodyVo = new RestApiReqBodyVo(); |
| | | if (18 == patId.length()) { |
| | | reqBodyVo.setSfzh( patId ); |
| | | } else { |
| | | reqBodyVo.setMzzyh(patId); |
| | | } |
| | | |
| | | // QueryRisReportList queryEcgRequest |
| | | RestApiResult<AppointmentExternal> result = remoteDataService.httpApi("queryEcgRequest", "ECG", "ECG", reqBodyVo); |
| | | if (0 == result.getRow().size()) { |
| | | return curAppointDOList; |
| | | } |
| | | |
| | | for (int appointIndex=0; appointIndex < result.getRow().size(); appointIndex++ ) { |
| | | AppointmentExternal appointmentExternal = result.getRow().get( appointIndex ); |
| | | |
| | | AppointmentDO appointmentDO = BeanUtils.toBean(appointmentExternal, AppointmentDO.class); |
| | | appointmentDO.setApplyNo( appointmentExternal.getReqIdeApplyno() ); |
| | | appointmentDO.setEpisodeId( appointmentExternal.getEpisodeID() ); |
| | | appointmentDO.setPatSrc( getCorrespondingPatientSource(appointmentExternal.getAdmTypeCode()) ); |
| | | appointmentDO.setPatId(appointmentExternal.getPatientID()); // 内容为 身份证号 或 门诊住院号 |
| | | appointmentDO.setPatName(appointmentExternal.getPatName()); |
| | | appointmentDO.setPatGender(Byte.valueOf(appointmentExternal.getPatgender())); |
| | | appointmentDO.setPatBirthday(DateUtils.ofUTC(appointmentExternal.getEncPatBirthDate()).toLocalDate()); |
| | | appointmentDO.setPatIdentityId(appointmentExternal.getIdentityID()); |
| | | appointmentDO.setPatAddr(appointmentExternal.getAddress()); |
| | | appointmentDO.setPatDeptCode(appointmentExternal.getPatLocDeptCode()); |
| | | appointmentDO.setPatDeptDesc(appointmentExternal.getPatLocDeptDesc()); |
| | | appointmentDO.setPatWardCode(appointmentExternal.getPatLocWardCode()); |
| | | appointmentDO.setPatWardDesc(appointmentExternal.getPatLocWardDesc()); |
| | | appointmentDO.setPatMobile(appointmentExternal.getPhone()); |
| | | appointmentDO.setPatBedNo(appointmentExternal.getEnBedno()); |
| | | appointmentDO.setBookCheckType(getCorrespondingCheckType(appointmentExternal.getPlanDefItemList().getPlanDefItem().getPlanDefItemcode())); |
| | | appointmentDO.setBookTime(DateUtils.ofUTC(appointmentExternal.getReqAuthoredOn())); // 开单时间 |
| | | appointmentDO.setBookSrc( 0 ); |
| | | |
| | | // 光开单的情况,没有预约时间 |
| | | if (null != appointmentExternal.getReqExtBooktime() ) { |
| | | appointmentDO.setBookDate(DateUtils.ofUTC(appointmentExternal.getReqExtBooktime()).toLocalDate()); |
| | | LocalDateTime bookStartTime = DateUtils.ofUTC(appointmentExternal.getReqExtBooktime()); |
| | | LocalDateTime bookEndTime = bookStartTime.plusMinutes( ecgConfigService.getTimeslotLength()); |
| | | appointmentDO.setBookTimeslot((bookStartTime.getHour() * 100 + bookStartTime.getMinute()) * 10000 + bookEndTime.getHour() * 100 + bookEndTime.getMinute()); |
| | | } |
| | | |
| | | appointmentDO.setPaid( 0 ); |
| | | |
| | | curAppointDOList.add( appointmentDO ); |
| | | } |
| | | |
| | | return curAppointDOList; |
| | | return appointmentMapper.getCurrentPatId(patId); |
| | | } |
| | | |
| | | // @Override |
| | | // public List<AppointmentDO> getAppointmentExtermal(String patId) { |
| | | // List<AppointmentDO> curAppointDOList = new ArrayList<AppointmentDO>(); |
| | | // |
| | | // RestApiReqBodyVo reqBodyVo = new RestApiReqBodyVo(); |
| | | // if (18 == patId.length()) { |
| | | // reqBodyVo.setSfzh( patId ); |
| | | // } else { |
| | | // reqBodyVo.setMzzyh(patId); |
| | | // } |
| | | // |
| | | // // QueryRisReportList queryEcgRequest |
| | | // RestApiResult<AppointmentExternal> result = remoteDataService.httpApi("queryEcgRequest", "ECG", "ECG", reqBodyVo); |
| | | // if (0 == result.getRow().size()) { |
| | | // return curAppointDOList; |
| | | // } |
| | | // |
| | | // for (int appointIndex=0; appointIndex < result.getRow().size(); appointIndex++ ) { |
| | | // AppointmentExternal appointmentExternal = result.getRow().get( appointIndex ); |
| | | // |
| | | // AppointmentDO appointmentDO = BeanUtils.toBean(appointmentExternal, AppointmentDO.class); |
| | | // appointmentDO.setApplyNo( appointmentExternal.getReqIdeApplyno() ); |
| | | // appointmentDO.setEpisodeId( appointmentExternal.getEpisodeID() ); |
| | | // appointmentDO.setPatSrc( getCorrespondingPatientSource(appointmentExternal.getAdmTypeCode()) ); |
| | | // appointmentDO.setPatId(appointmentExternal.getPatientID()); // 内容为 身份证号 或 门诊住院号 |
| | | // appointmentDO.setPatName(appointmentExternal.getPatName()); |
| | | // appointmentDO.setPatGender(Byte.valueOf(appointmentExternal.getPatgender())); |
| | | // appointmentDO.setPatBirthday(DateUtils.ofUTC(appointmentExternal.getEncPatBirthDate()).toLocalDate()); |
| | | // appointmentDO.setPatIdentityId(appointmentExternal.getIdentityID()); |
| | | // appointmentDO.setPatAddr(appointmentExternal.getAddress()); |
| | | // appointmentDO.setPatDeptCode(appointmentExternal.getPatLocDeptCode()); |
| | | // appointmentDO.setPatDeptDesc(appointmentExternal.getPatLocDeptDesc()); |
| | | // appointmentDO.setPatWardCode(appointmentExternal.getPatLocWardCode()); |
| | | // appointmentDO.setPatWardDesc(appointmentExternal.getPatLocWardDesc()); |
| | | // appointmentDO.setPatMobile(appointmentExternal.getPhone()); |
| | | // appointmentDO.setPatBedNo(appointmentExternal.getEnBedno()); |
| | | // appointmentDO.setBookCheckType(getCorrespondingCheckType(appointmentExternal.getPlanDefItemList().getPlanDefItem().getPlanDefItemcode())); |
| | | // appointmentDO.setBookTime(DateUtils.ofUTC(appointmentExternal.getReqAuthoredOn())); // 开单时间 |
| | | // appointmentDO.setBookSrc( 0 ); |
| | | // |
| | | // // 光开单的情况,没有预约时间 |
| | | // if (null != appointmentExternal.getReqExtBooktime() ) { |
| | | // appointmentDO.setBookDate(DateUtils.ofUTC(appointmentExternal.getReqExtBooktime()).toLocalDate()); |
| | | // LocalDateTime bookStartTime = DateUtils.ofUTC(appointmentExternal.getReqExtBooktime()); |
| | | // LocalDateTime bookEndTime = bookStartTime.plusMinutes( ecgConfigService.getTimeslotLength()); |
| | | // appointmentDO.setBookTimeslot((bookStartTime.getHour() * 100 + bookStartTime.getMinute()) * 10000 + bookEndTime.getHour() * 100 + bookEndTime.getMinute()); |
| | | // } |
| | | // |
| | | // appointmentDO.setPaid( 0 ); |
| | | // |
| | | // curAppointDOList.add( appointmentDO ); |
| | | // } |
| | | // |
| | | // return curAppointDOList; |
| | | // } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Integer appoitmentConfirm(AppointmentConfirmReqVO confirmReqVO) { |
| | | AppointmentDO appointment = getAppointment(confirmReqVO.getId()); |
| | | if (null == appointment) |
| | | throw exception(PATIENT_NOT_EXISTS); |
| | | if (null == appointment) throw exception(PATIENT_NOT_EXISTS); |
| | | |
| | | // 手动预约,直接设置预约日期为当天 |
| | | if (confirmReqVO.getIsVip() == 1) { |
| | | appointment.setBookDate( LocalDate.now() ); |
| | | appointment.setBookDate(LocalDate.now()); |
| | | } |
| | | |
| | | if ( !DateUtils.isToday(appointment.getBookDate()) ) |
| | | throw exception( APPOINTMENT_NOT_TODAY); |
| | | if (!DateUtils.isToday(appointment.getBookDate())) throw exception(APPOINTMENT_NOT_TODAY); |
| | | |
| | | |
| | | Integer newSeqNo = null; |
| | |
| | | |
| | | try { |
| | | QueueSaveReqVO queueSaveReqVO = new QueueSaveReqVO(); |
| | | queueSaveReqVO.setApplyNo( appointment.getApplyNo() ); |
| | | queueSaveReqVO.setEpisodeId( appointment.getEpisodeId() ); |
| | | queueSaveReqVO.setApplyNo(appointment.getApplyNo()); |
| | | queueSaveReqVO.setEpisodeId(appointment.getEpisodeId()); |
| | | queueSaveReqVO.setAppointId(appointment.getId()); |
| | | queueSaveReqVO.setPatId(appointment.getPatId()); |
| | | queueSaveReqVO.setPatName(appointment.getPatName()); |
| | | queueSaveReqVO.setPatGender(appointment.getPatGender()); |
| | | queueSaveReqVO.setBookDate(appointment.getBookDate()); |
| | | queueSaveReqVO.setBookTimeslot( confirmReqVO.getBookTimeslot() ); /*appointment.getBookTimeslot()*/ |
| | | queueSaveReqVO.setBookTimeslot(confirmReqVO.getBookTimeslot()); /*appointment.getBookTimeslot()*/ |
| | | queueSaveReqVO.setBookCheckType(appointment.getBookCheckType()); |
| | | queueSaveReqVO.setBookSeqNum( newSeqNo ); |
| | | queueSaveReqVO.setIsVip( confirmReqVO.getIsVip() ); |
| | | queueSaveReqVO.setBookSeqNum(newSeqNo); |
| | | queueSaveReqVO.setIsVip(confirmReqVO.getIsVip()); |
| | | queueSaveReqVO.setPassed((byte) 0); |
| | | queueSaveReqVO.setExpired((byte) 0); |
| | | queueSaveReqVO.setPatDetails( getPatDetails(appointment) ); |
| | | queueSaveReqVO.setPatDetails(getPatDetails(appointment)); |
| | | queueService.queue(queueSaveReqVO); |
| | | } catch (DuplicateKeyException duplicateKeyException) { |
| | | throw exception(APPOINTMENT_HAVE_QUEUED); |
| | |
| | | return newSeqNo; |
| | | } |
| | | |
| | | private Integer getCorrespondingCheckType(String strPlanDefItemcode) { |
| | | if (strPlanDefItemcode.equals("691133607")) |
| | | return 100; |
| | | else if (strPlanDefItemcode.equals("201605")) |
| | | return 200; |
| | | else if (strPlanDefItemcode.equals("200327")) |
| | | return 300; |
| | | else if (strPlanDefItemcode.equals("201652")) |
| | | return 400; |
| | | else if (strPlanDefItemcode.equals("502490914")) |
| | | return 500; |
| | | else if (strPlanDefItemcode.equals("419562119")) |
| | | return 600; |
| | | else if (strPlanDefItemcode.equals("201604")) |
| | | return 700; |
| | | else if (strPlanDefItemcode.equals("1202042")) |
| | | return 800; |
| | | else if (strPlanDefItemcode.equals("1202058")) |
| | | return 900; |
| | | else if (strPlanDefItemcode.equals("1202065")) |
| | | return 1000; |
| | | else if (strPlanDefItemcode.equals("559542128")) |
| | | return 1100; |
| | | else if (strPlanDefItemcode.equals("590244511")) |
| | | return 1200; |
| | | else if (strPlanDefItemcode.equals("666454217")) |
| | | return 1300; |
| | | else if (strPlanDefItemcode.equals("720791490")) |
| | | return 1400; |
| | | else if (strPlanDefItemcode.equals("720792077")) |
| | | return 1500; |
| | | |
| | | return 100; |
| | | } |
| | | |
| | | private Integer getCorrespondingPatientSource(String admTypeCode) { |
| | | if (admTypeCode.equals("AMB")) |
| | | return 1; |
| | | else if (admTypeCode.equals("EMER")) |
| | | return 2; |
| | | else if (admTypeCode.equals("IMP")) |
| | | return 3; |
| | | else if (admTypeCode.equals("PHY")) |
| | | return 4; |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | private PatDetails getPatDetails(AppointmentDO appointment) { |
| | | PatDetails patDetails = new PatDetails(); |
| | | patDetails.setAppointmentId( appointment.getId() ); |
| | | patDetails.setId( appointment.getPatId() ); |
| | | patDetails.setName( appointment.getPatName() ); |
| | | patDetails.setMobile( appointment.getPatMobile() ); |
| | | patDetails.setDeptCode( appointment.getPatDeptCode() ); |
| | | patDetails.setDeptDesc( appointment.getPatDeptDesc() ); |
| | | patDetails.setWardCode( appointment.getPatWardCode() ); |
| | | patDetails.setWardDesc( appointment.getPatWardDesc() ); |
| | | patDetails.setBedNo( appointment.getPatBedNo() ); |
| | | patDetails.setSource( appointment.getPatSrc() ); |
| | | patDetails.setAppointmentId(appointment.getId()); |
| | | patDetails.setId(appointment.getPatId()); |
| | | patDetails.setName(appointment.getPatName()); |
| | | patDetails.setMobile(appointment.getPatMobile()); |
| | | patDetails.setDeptCode(appointment.getPatDeptCode()); |
| | | patDetails.setDeptDesc(appointment.getPatDeptDesc()); |
| | | patDetails.setWardCode(appointment.getPatWardCode()); |
| | | patDetails.setWardDesc(appointment.getPatWardDesc()); |
| | | patDetails.setBedNo(appointment.getPatBedNo()); |
| | | patDetails.setSource(appointment.getPatSrc()); |
| | | return patDetails; |
| | | } |
| | | |
| | | @Override |
| | | public Long handleAppointmentCreate(Map<String, Object> dataMap) { |
| | | if (dataMap == null) { |
| | | throw exception(APPOINTMENT_CREATE_FAIL); |
| | | } |
| | | |
| | | try { |
| | | // 创建AppointmentDO对象 |
| | | AppointmentDO appointment = new AppointmentDO(); |
| | | |
| | | // 从dataMap中提取数据 |
| | | Map<String, Object> encounter = extractEncounter(dataMap); |
| | | if (encounter == null) { |
| | | throw exception(APPOINTMENT_CREATE_FAIL); |
| | | } |
| | | |
| | | // 设置就诊流水号 |
| | | Optional.ofNullable(encounter.get("id")).map(id -> (Map<String, Object>) id).map(id -> (List<?>) id.get("item")).filter(items -> items.size() > 1).map(items -> (Map<String, Object>) items.get(1)).map(item -> (String) item.get("extension")).ifPresent(appointment::setEpisodeId); |
| | | |
| | | Optional.ofNullable(encounter.get("location")).map(location -> (Map<String, Object>) location).map(location -> (Map<String, Object>) location.get("serviceDeliveryLocation")).map(serviceDeliveryLocation -> (Map<String, Object>) serviceDeliveryLocation.get("location")).map(location -> (Map<String, Object>) location.get("id")).map(id -> (Map<String, Object>) id.get("item")).map(item -> (String) item.get("extension")).ifPresent(appointment::setPatBedNo); |
| | | |
| | | |
| | | // 设置患者来源类型 |
| | | Optional.ofNullable(encounter.get("code")).map(code -> (Map<String, Object>) code).map(code -> (String) code.get("code")).map(Integer::parseInt).ifPresent(appointment::setPatSrc); |
| | | |
| | | // 设置患者信息 |
| | | Optional.ofNullable(encounter.get("subject")).map(subject -> (Map<String, Object>) subject).map(subject -> (Map<String, Object>) subject.get("patient")).map(patient -> (Map<String, Object>) patient.get("patientPerson")).ifPresent(patientPerson -> { |
| | | // 设置患者ID |
| | | Optional.ofNullable(encounter.get("subject")).map(subject -> (Map<String, Object>) subject).map(subject -> (Map<String, Object>) subject.get("patient")).map(patient -> (Map<String, Object>) patient.get("id")).map(id -> (Map<String, Object>) id).map(id -> (List<?>) id.get("item")).filter(items -> items.size() > 1).map(items -> (Map<String, Object>) items.get(1)).map(item -> (String) item.get("extension")).ifPresent(appointment::setPatId); |
| | | |
| | | // 设置患者姓名 |
| | | Optional.ofNullable(patientPerson.get("name")).map(name -> (Map<String, Object>) name).map(name -> (Map<String, Object>) name.get("item")).map(item -> (Map<String, Object>) item.get("part")).map(part -> (String) part.get("value")).ifPresent(appointment::setPatName); |
| | | |
| | | // 设置患者手机和电话 |
| | | Optional.ofNullable(patientPerson.get("telecom")).map(telecom -> (Map<String, Object>) telecom).map(telecom -> (Map<String, Object>) telecom.get("item")).map(item -> (String) item.get("value")).ifPresent(phone -> { |
| | | appointment.setPatMobile(phone); |
| | | appointment.setPatPhone(phone); |
| | | }); |
| | | |
| | | // 设置患者性别 |
| | | Optional.ofNullable(patientPerson.get("administrativeGenderCode")).map(genderCode -> (Map<String, Object>) genderCode).map(genderCode -> (String) genderCode.get("code")).map(Byte::parseByte).ifPresent(appointment::setPatGender); |
| | | |
| | | // 设置患者生日 |
| | | Optional.ofNullable(patientPerson.get("birthTime")).map(birthTime -> (Map<String, Object>) birthTime).map(birthTime -> (String) birthTime.get("value")).map(birthdayStr -> LocalDate.parse(birthdayStr, DateTimeFormatter.ofPattern("yyyyMMdd"))).ifPresent(appointment::setPatBirthday); |
| | | |
| | | // 设置患者地址 |
| | | Optional.ofNullable(patientPerson.get("addr")).map(addr -> (Map<String, Object>) addr).map(addr -> (Map<String, Object>) addr.get("item")).map(item -> (Map<String, Object>) item.get("part")).map(part -> (String) part.get("value")).ifPresent(appointment::setPatAddr); |
| | | |
| | | // 设置患者身份证号 |
| | | Optional.ofNullable(patientPerson.get("id")).map(id -> (Map<String, Object>) id).map(id -> (List<?>) id.get("item")).filter(items -> !items.isEmpty()).map(items -> (Map<String, Object>) items.get(0)).map(item -> (String) item.get("extension")).ifPresent(appointment::setPatIdentityId); |
| | | }); |
| | | |
| | | // 设置科室和病区信息 |
| | | Optional.ofNullable(encounter.get("location")).map(location -> (Map<String, Object>) location).map(location -> (Map<String, Object>) location.get("serviceDeliveryLocation")).map(location -> (Map<String, Object>) location.get("serviceProviderOrganization")).ifPresent(org -> { |
| | | // 设置科室代码和名称 |
| | | Optional.ofNullable(org.get("id")).map(id -> (Map<String, Object>) id).map(id -> (Map<String, Object>) id.get("item")).map(item -> (String) item.get("extension")).ifPresent(appointment::setPatDeptCode); |
| | | |
| | | Optional.ofNullable(org.get("name")).map(name -> (Map<String, Object>) name).map(name -> (Map<String, Object>) name.get("item")).map(item -> (Map<String, Object>) item.get("part")).map(part -> (String) part.get("value")).ifPresent(appointment::setPatDeptDesc); |
| | | |
| | | // 设置病区代码和名称 |
| | | Optional.ofNullable(org.get("asOrganizationPartOf")).map(wardOrg -> (Map<String, Object>) wardOrg).map(wardOrg -> (Map<String, Object>) wardOrg.get("wholeOrganization")).ifPresent(wardOrg -> { |
| | | Optional.ofNullable(wardOrg.get("id")).map(id -> (Map<String, Object>) id).map(id -> (Map<String, Object>) id.get("item")).map(item -> (String) item.get("extension")).ifPresent(appointment::setPatWardCode); |
| | | |
| | | Optional.ofNullable(wardOrg.get("name")).map(name -> (Map<String, Object>) name).map(name -> (Map<String, Object>) name.get("item")).map(item -> (Map<String, Object>) item.get("part")).map(part -> (String) part.get("value")).ifPresent(appointment::setPatWardDesc); |
| | | }); |
| | | }); |
| | | |
| | | // 设置支付状态 |
| | | Optional.ofNullable(dataMap.get("controlActProcess")).map(controlActProcess -> (Map<String, Object>) controlActProcess).map(controlActProcess -> (Map<String, Object>) controlActProcess.get("subject")).map(subject -> (Map<String, Object>) subject.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("zdy")).map(zdy -> { |
| | | Object payStatus = zdy.get("PayStatus"); |
| | | if (payStatus != null) { |
| | | try { |
| | | return Integer.parseInt(payStatus.toString()); |
| | | } catch (NumberFormatException e) { |
| | | log.warn("PayStatus转换失败: {}", payStatus); |
| | | return null; |
| | | } |
| | | } |
| | | return null; |
| | | }).ifPresent(appointment::setPaid); |
| | | // 设置申请单号 |
| | | Optional.ofNullable(dataMap.get("controlActProcess")).map(controlActProcess -> (Map<String, Object>) controlActProcess).map(controlActProcess -> (Map<String, Object>) controlActProcess.get("subject")).map(subject -> (Map<String, Object>) subject.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("id")).map(id -> (Map<String, Object>) id.get("item")).map(item -> (String) item.get("extension")).ifPresent(appointment::setApplyNo); |
| | | |
| | | //设置检查类型 |
| | | // String checkType = Optional.ofNullable(dataMap.get("controlActProcess")).map(controlActProcess -> (Map<String, Object>) controlActProcess).map(controlActProcess -> (Map<String, Object>) controlActProcess.get("component2")).map(component2 -> (Map<String, Object>) component2.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("code")).map(code -> (String) code.get("code")).orElseThrow(() -> exception(APPOINTMENT_CREATE_FAIL)); |
| | | String checkType = Optional.ofNullable(dataMap.get("controlActProcess")).map(controlActProcess -> (Map<String, Object>) controlActProcess).map(controlActProcess -> (Map<String, Object>) controlActProcess.get("subject")).map(subject -> (Map<String, Object>) subject.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("component2")).map(component2 -> (Map<String, Object>) component2.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("code")).map(code -> (String) code.get("code")).orElseThrow(() -> exception(APPOINTMENT_CREATE_FAIL)); |
| | | if (checkType != null || checkType != "") |
| | | appointment.setBookCheckType(Integer.valueOf(HisCheckCodeEnum.getByCode(checkType.substring(1)))); |
| | | |
| | | // 将AppointmentDO转换为AppointmentSaveReqVO并保存 |
| | | AppointmentSaveReqVO saveReqVO = BeanUtils.toBean(appointment, AppointmentSaveReqVO.class); |
| | | return createAppointment(saveReqVO); |
| | | } catch (Exception e) { |
| | | log.error("[handleAppointmentCreate][处理预约创建失败 dataMap({})]", dataMap, e); |
| | | throw exception(APPOINTMENT_CREATE_FAIL); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void handleAppointmentUpdate(Map<String, Object> dataMap) { |
| | | if (dataMap == null) { |
| | | throw exception(APPOINTMENT_UPDATE_FAIL); |
| | | } |
| | | |
| | | try { |
| | | // 从dataMap中提取申请单号 |
| | | String applyNo = Optional.ofNullable(dataMap.get("controlActProcess")).map(controlActProcess -> (Map<String, Object>) controlActProcess).map(controlActProcess -> (Map<String, Object>) controlActProcess.get("subject")).map(subject -> (Map<String, Object>) subject.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("id")).map(id -> (Map<String, Object>) id.get("item")).map(item -> (String) item.get("extension")).orElseThrow(() -> exception(APPOINTMENT_CREATE_FAIL)); |
| | | |
| | | // 查询现有预约记录 |
| | | AppointmentDO existingAppointment = appointmentMapper.getByApplyNo(applyNo); |
| | | |
| | | // 如果记录不存在,则调用handleAppointmentCreate进行新增 |
| | | if (existingAppointment == null) { |
| | | handleAppointmentCreate(dataMap); |
| | | return; |
| | | } |
| | | |
| | | // 从dataMap中提取数据 |
| | | Map<String, Object> encounter = extractEncounter(dataMap); |
| | | if (encounter == null) { |
| | | throw exception(APPOINTMENT_CREATE_FAIL); |
| | | } |
| | | |
| | | // 更新就诊流水号 |
| | | Optional.ofNullable(encounter.get("id")).map(id -> (Map<String, Object>) id).map(id -> (List<?>) id.get("item")).filter(items -> items.size() > 1).map(items -> (Map<String, Object>) items.get(1)).map(item -> (String) item.get("extension")).ifPresent(existingAppointment::setEpisodeId); |
| | | |
| | | // 设置床位号 |
| | | Optional.ofNullable(encounter.get("location")).map(location -> (Map<String, Object>) location).map(location -> (Map<String, Object>) location.get("serviceDeliveryLocation")).map(serviceDeliveryLocation -> (Map<String, Object>) serviceDeliveryLocation.get("location")).map(location -> (Map<String, Object>) location.get("id")).map(id -> (Map<String, Object>) id.get("item")).map(item -> (String) item.get("extension")).ifPresent(existingAppointment::setPatBedNo); |
| | | |
| | | |
| | | // 更新患者来源类型 |
| | | Optional.ofNullable(encounter.get("code")).map(code -> (Map<String, Object>) code).map(code -> (String) code.get("code")).map(Integer::parseInt).ifPresent(existingAppointment::setPatSrc); |
| | | |
| | | // 更新患者信息 |
| | | Optional.ofNullable(encounter.get("subject")).map(subject -> (Map<String, Object>) subject).map(subject -> (Map<String, Object>) subject.get("patient")).map(patient -> (Map<String, Object>) patient.get("patientPerson")).ifPresent(patientPerson -> { |
| | | // 更新患者ID |
| | | Optional.ofNullable(encounter.get("subject")).map(subject -> (Map<String, Object>) subject).map(subject -> (Map<String, Object>) subject.get("patient")).map(patient -> (Map<String, Object>) patient.get("id")).map(id -> (Map<String, Object>) id).map(id -> (List<?>) id.get("item")).filter(items -> items.size() > 1).map(items -> (Map<String, Object>) items.get(1)).map(item -> (String) item.get("extension")).ifPresent(existingAppointment::setPatId); |
| | | |
| | | // 更新患者姓名 |
| | | Optional.ofNullable(patientPerson.get("name")).map(name -> (Map<String, Object>) name).map(name -> (Map<String, Object>) name.get("item")).map(item -> (Map<String, Object>) item.get("part")).map(part -> (String) part.get("value")).ifPresent(existingAppointment::setPatName); |
| | | |
| | | // 更新患者手机和电话 |
| | | Optional.ofNullable(patientPerson.get("telecom")).map(telecom -> (Map<String, Object>) telecom).map(telecom -> (Map<String, Object>) telecom.get("item")).map(item -> (String) item.get("value")).ifPresent(phone -> { |
| | | existingAppointment.setPatMobile(phone); |
| | | existingAppointment.setPatPhone(phone); |
| | | }); |
| | | |
| | | // 更新患者性别 |
| | | Optional.ofNullable(patientPerson.get("administrativeGenderCode")).map(genderCode -> (Map<String, Object>) genderCode).map(genderCode -> (String) genderCode.get("code")).map(Byte::parseByte).ifPresent(existingAppointment::setPatGender); |
| | | |
| | | // 更新患者生日 |
| | | Optional.ofNullable(patientPerson.get("birthTime")).map(birthTime -> (Map<String, Object>) birthTime).map(birthTime -> (String) birthTime.get("value")).map(birthdayStr -> LocalDate.parse(birthdayStr, DateTimeFormatter.ofPattern("yyyyMMdd"))).ifPresent(existingAppointment::setPatBirthday); |
| | | |
| | | // 更新患者地址 |
| | | Optional.ofNullable(patientPerson.get("addr")).map(addr -> (Map<String, Object>) addr).map(addr -> (Map<String, Object>) addr.get("item")).map(item -> (Map<String, Object>) item.get("part")).map(part -> (String) part.get("value")).ifPresent(existingAppointment::setPatAddr); |
| | | |
| | | // 更新患者身份证号 |
| | | Optional.ofNullable(patientPerson.get("id")).map(id -> (Map<String, Object>) id).map(id -> (List<?>) id.get("item")).filter(items -> !items.isEmpty()).map(items -> (Map<String, Object>) items.get(0)).map(item -> (String) item.get("extension")).ifPresent(existingAppointment::setPatIdentityId); |
| | | }); |
| | | |
| | | // 更新科室和病区信息 |
| | | Optional.ofNullable(encounter.get("location")).map(location -> (Map<String, Object>) location).map(location -> (Map<String, Object>) location.get("serviceDeliveryLocation")).map(location -> (Map<String, Object>) location.get("serviceProviderOrganization")).ifPresent(org -> { |
| | | // 更新科室代码和名称 |
| | | Optional.ofNullable(org.get("id")).map(id -> (Map<String, Object>) id).map(id -> (Map<String, Object>) id.get("item")).map(item -> (String) item.get("extension")).ifPresent(existingAppointment::setPatDeptCode); |
| | | |
| | | Optional.ofNullable(org.get("name")).map(name -> (Map<String, Object>) name).map(name -> (Map<String, Object>) name.get("item")).map(item -> (Map<String, Object>) item.get("part")).map(part -> (String) part.get("value")).ifPresent(existingAppointment::setPatDeptDesc); |
| | | |
| | | // 更新病区代码和名称 |
| | | Optional.ofNullable(org.get("asOrganizationPartOf")).map(wardOrg -> (Map<String, Object>) wardOrg).map(wardOrg -> (Map<String, Object>) wardOrg.get("wholeOrganization")).ifPresent(wardOrg -> { |
| | | Optional.ofNullable(wardOrg.get("id")).map(id -> (Map<String, Object>) id).map(id -> (Map<String, Object>) id.get("item")).map(item -> (String) item.get("extension")).ifPresent(existingAppointment::setPatWardCode); |
| | | |
| | | Optional.ofNullable(wardOrg.get("name")).map(name -> (Map<String, Object>) name).map(name -> (Map<String, Object>) name.get("item")).map(item -> (Map<String, Object>) item.get("part")).map(part -> (String) part.get("value")).ifPresent(existingAppointment::setPatWardDesc); |
| | | }); |
| | | }); |
| | | |
| | | // 更新支付状态 |
| | | Optional.ofNullable(dataMap.get("controlActProcess")).map(controlActProcess -> (Map<String, Object>) controlActProcess).map(controlActProcess -> (Map<String, Object>) controlActProcess.get("subject")).map(subject -> (Map<String, Object>) subject.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("zdy")).map(zdy -> { |
| | | Object payStatus = zdy.get("PayStatus"); |
| | | if (payStatus != null) { |
| | | try { |
| | | return Integer.parseInt(payStatus.toString()); |
| | | } catch (NumberFormatException e) { |
| | | log.warn("PayStatus转换失败: {}", payStatus); |
| | | return null; |
| | | } |
| | | } |
| | | return null; |
| | | }).ifPresent(existingAppointment::setPaid); |
| | | //设置检查类型 |
| | | String checkType = Optional.ofNullable(dataMap.get("controlActProcess")).map(controlActProcess -> (Map<String, Object>) controlActProcess).map(controlActProcess -> (Map<String, Object>) controlActProcess.get("subject")).map(subject -> (Map<String, Object>) subject.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("component2")).map(component2 -> (Map<String, Object>) component2.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("code")).map(code -> (String) code.get("code")).orElseThrow(() -> exception(APPOINTMENT_CREATE_FAIL)); |
| | | if (checkType != null || checkType != "") |
| | | existingAppointment.setBookCheckType(Integer.valueOf(HisCheckCodeEnum.getByCode(checkType.substring(1)))); |
| | | |
| | | // 将AppointmentDO转换为AppointmentSaveReqVO并更新 |
| | | AppointmentSaveReqVO updateReqVO = BeanUtils.toBean(existingAppointment, AppointmentSaveReqVO.class); |
| | | updateAppointment(updateReqVO); |
| | | } catch (Exception e) { |
| | | log.error("[handleAppointmentUpdate][申请单更新失败 dataMap({})]", dataMap, e); |
| | | throw exception(APPOINTMENT_UPDATE_FAIL); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void handleAppointmentStateUpdate(Map<String, Object> dataMap) { |
| | | if (dataMap == null) { |
| | | throw exception(APPOINTMENT_STATUS_UPDATE_FAIL); |
| | | } |
| | | // 从dataMap中提取申请单号 |
| | | String applyNo = Optional.ofNullable(dataMap.get("controlActProcess")).map(controlActProcess -> (Map<String, Object>) controlActProcess).map(controlActProcess -> (Map<String, Object>) controlActProcess.get("subject")).map(subject -> (Map<String, Object>) subject.get("placerGroup")).map(placerGroup -> (Map<String, Object>) placerGroup.get("component2")).map(component2 -> (Map<String, Object>) component2.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("id")).map(id -> (Map<String, Object>) id.get("item")).map(item -> (String) item.get("extension")).orElseThrow(() -> exception(APPOINTMENT_CREATE_FAIL)); |
| | | |
| | | // 查询现有预约记录 |
| | | AppointmentDO existingAppointment = appointmentMapper.getByApplyNo(applyNo); |
| | | |
| | | // 如果记录不存在,则调用handleAppointmentCreate进行新增 |
| | | if (existingAppointment == null) { |
| | | handleAppointmentCreate(dataMap); |
| | | return; |
| | | } |
| | | |
| | | |
| | | // 从dataMap中提取申请单号 |
| | | String status = Optional.ofNullable(dataMap.get("controlActProcess")).map(controlActProcess -> (Map<String, Object>) controlActProcess).map(controlActProcess -> (Map<String, Object>) controlActProcess.get("subject")).map(subject -> (Map<String, Object>) subject.get("placerGroup")).map(placerGroup -> (Map<String, Object>) placerGroup.get("component2")).map(component2 -> (Map<String, Object>) component2.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("component1")).map(component1 -> (Map<String, Object>) component1.get("processStep")).map(processStep -> (Map<String, Object>) processStep.get("code")).map(code -> (Map<String, Object>) code.get("displayName")).map(displayName -> (String) displayName.get("value")).orElseThrow(() -> exception(APPOINTMENT_CREATE_FAIL)); |
| | | |
| | | existingAppointment.setStatus(status); |
| | | // 将AppointmentDO转换为AppointmentSaveReqVO并更新 |
| | | AppointmentSaveReqVO updateReqVO = BeanUtils.toBean(existingAppointment, AppointmentSaveReqVO.class); |
| | | updateAppointment(updateReqVO); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 从dataMap中提取encounter数据 |
| | | */ |
| | | private Map<String, Object> extractEncounter(Map<String, Object> dataMap) { |
| | | return Optional.ofNullable(dataMap.get("controlActProcess")).map(controlActProcess -> (Map<String, Object>) controlActProcess).map(controlActProcess -> (Map<String, Object>) controlActProcess.get("subject")).map(subject -> (Map<String, Object>) subject.get("observationRequest")).map(observationRequest -> (Map<String, Object>) observationRequest.get("componentOf1")).map(componentOf1 -> (Map<String, Object>) componentOf1.get("encounter")).orElse(null); |
| | | } |
| | | |
| | | @Override |
| | | public void handleCheckAppointmentUpdate(Map<String, Object> dataMap) { |
| | | // 从dataMap中获取controlActProcess |
| | | Map<String, Object> controlActProcess = (Map<String, Object>) dataMap.get("controlActProcess"); |
| | | Map<String, Object> subject = (Map<String, Object>) controlActProcess.get("subject"); |
| | | Map<String, Object> actAppointment = (Map<String, Object>) subject.get("actAppointment"); |
| | | |
| | | // 获取申请编号 |
| | | List<Map<String, Object>> referencedOrders = (List<Map<String, Object>>) actAppointment.get("referencedOrder"); |
| | | String applyNo = null; |
| | | if (!CollectionUtils.isEmpty(referencedOrders)) { |
| | | Map<String, Object> actOrder = (Map<String, Object>) referencedOrders.get(0).get("actOrder"); |
| | | Map<String, Object> id = (Map<String, Object>) actOrder.get("id"); |
| | | applyNo = (String) id.get("extension"); |
| | | } |
| | | |
| | | if (applyNo == null) { |
| | | log.warn("[handleCheckAppointmentUpdate][未找到申请编号]"); |
| | | return; |
| | | } |
| | | |
| | | // 根据applyNo查询预约记录 |
| | | AppointmentDO appointment = appointmentMapper.getByApplyNo(applyNo); |
| | | if (appointment == null) { |
| | | log.warn("[handleCheckAppointmentUpdate][未找到预约记录 applyNo({})]", applyNo); |
| | | return; |
| | | } |
| | | |
| | | // 获取预约时间 |
| | | Map<String, Object> effectiveTime = (Map<String, Object>) actAppointment.get("effectiveTime"); |
| | | Map<String, Object> any = (Map<String, Object>) effectiveTime.get("any"); |
| | | String bookTimeStr = (String) any.get("value"); |
| | | |
| | | // 获取预约来源 |
| | | Map<String, Object> code = (Map<String, Object>) actAppointment.get("code"); |
| | | String bookSrc = (String) code.get("code"); |
| | | |
| | | // 解析预约时间 |
| | | LocalDateTime bookTime = LocalDateTime.parse(bookTimeStr, DateTimeFormatter.ofPattern("yyyyMMddHHmmss")); |
| | | LocalDate bookDate = bookTime.toLocalDate(); |
| | | |
| | | // 获取时间段 |
| | | String timeRange = (String) ((Map<String, Object>) actAppointment.get("ZDY")).get("time"); |
| | | String[] time1 = timeRange.split(" "); |
| | | String[] times = time1[1].split("-"); |
| | | String startTime = times[0].trim(); |
| | | String endTime = times[1].trim(); |
| | | |
| | | // 转换时间段格式为hhmmhhmm |
| | | int bookTimeslot = Integer.parseInt(startTime.replace(":", "")) * 10000 + Integer.parseInt(endTime.replace(":", "")); |
| | | |
| | | // 更新预约信息 |
| | | appointment.setBookDate(bookDate); |
| | | appointment.setBookTimeslot(bookTimeslot); |
| | | appointment.setBookTime(bookTime); |
| | | appointment.setBookSrc(Integer.parseInt(bookSrc)); |
| | | |
| | | // 保存更新 |
| | | appointmentMapper.updateById(appointment); |
| | | } |
| | | |
| | | public AppointmentDO getByApplyNo(String applyNo) { |
| | | return appointmentMapper.getByApplyNo(applyNo); |
| | | } |
| | | } |
| | | |