From 9ad12f4a3cbf1fc5bb2ef5a76a371064afac62fc Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期五, 24 十月 2025 11:48:37 +0800
Subject: [PATCH] 新增日志
---
jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java | 740 +++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 637 insertions(+), 103 deletions(-)
diff --git a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java
index 577b98c..745b77d 100644
--- a/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java
+++ b/jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java
@@ -1,30 +1,45 @@
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.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.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.AppointmentTypeEnum;
+import cn.lihu.jh.module.ecg.enums.HisCheckCodeEnum;
+import cn.lihu.jh.module.ecg.enums.HisCheckNameEnum;
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.devrent.ApplicationTemplate;
import cn.lihu.jh.module.ecg.service.queue.QueueService;
+import cn.lihu.jh.module.ecg.service.queuesequence.QueueSequenceService;
+import cn.lihu.jh.module.ecg.webservice.WebServiceClient;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.beans.factory.annotation.Autowired;
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 java.text.SimpleDateFormat;
+import java.time.LocalDate;
import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+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.*;
/**
@@ -34,10 +49,17 @@
*/
@Service
@Validated
+@Slf4j
public class AppointmentServiceImpl implements AppointmentService {
@Resource
+ private EcgConfigService ecgConfigService;
+
+ @Resource
private RemoteDataService remoteDataService;
+
+ @Resource
+ private QueueSequenceService queueSequenceService;
@Resource
private QueueService queueService;
@@ -45,15 +67,20 @@
@Resource
private AppointmentMapper appointmentMapper;
+ @Autowired
+ private WebServiceClient webServiceClient;
+
@Override
public Long createAppointment(AppointmentSaveReqVO createReqVO) {
// 鎻掑叆
AppointmentDO appointment = BeanUtils.toBean(createReqVO, AppointmentDO.class);
- appointment.setBookTime( LocalDateTime.now() );
- appointment.setBookSrc( 1 );
+ try {
+ appointmentMapper.insert(appointment);
+ } catch (DuplicateKeyException e) {
+ throw exception(APPOINTMENT_EXIST_TODAY);
+ }
- appointmentMapper.insert(appointment);
// 杩斿洖
return appointment.getId();
}
@@ -65,6 +92,42 @@
// 鏇存柊
AppointmentDO updateObj = BeanUtils.toBean(updateReqVO, AppointmentDO.class);
appointmentMapper.updateById(updateObj);
+ }
+
+ @Override
+ public void updateAppointmentStatus(AppointmentSaveReqVO updateReqVO) {
+ // 鏍¢獙瀛樺湪
+ validateAppointmentExists(updateReqVO.getId());
+
+ // 鑾峰彇瀹屾暣鐨勯绾︿俊鎭�
+ AppointmentDO appointment = appointmentMapper.selectById(updateReqVO.getId());
+ if (appointment == null) {
+ throw exception(APPOINTMENT_NOT_EXISTS);
+ }
+
+ // 鏇存柊鐘舵��
+ appointment.setStatus(updateReqVO.getStatus());
+
+ // 璋冪敤HIS绯荤粺鏇存柊鐘舵��
+ String action = "S0405";
+ ApplicationTemplate app = new ApplicationTemplate();
+ String statusName = AppointmentTypeEnum.getByType(appointment.getStatus());
+ String message = app.getXML(appointment.getApplyNo(), appointment.getStatus(), statusName, null, appointment.getPatDeptCode(), appointment.getPatDeptDesc(), appointment.getPatWardCode(), appointment.getPatWardDesc(), appointment.getPatBedNo(), appointment.getEpisodeId(), String.valueOf(appointment.getBookSrc()), appointment.getPatId(), appointment.getPatName());
+
+ try {
+ String response = webServiceClient.callJHFWTYRK(action, "", message);
+ if (response.contains("鏇存柊鎴愬姛")) {
+ // 鏇存柊鏈湴鏁版嵁搴�
+ appointmentMapper.updateById(appointment);
+
+
+ } else {
+ throw exception(APPOINTMENT_UPDATE_FAIL);
+ }
+ } catch (Exception e) {
+ log.error("[updateAppointmentStatus][鏇存柊棰勭害鐘舵�佸け璐� appointment({})]", appointment, e);
+ throw exception(APPOINTMENT_UPDATE_FAIL);
+ }
}
@Override
@@ -87,126 +150,597 @@
}
@Override
- public AppointmentDO getAppointmentByPatId(String patId) {
- // 鍏堜粠鍖婚櫌骞冲彴鏌ヨ
- AppointmentDO appointmentExtermal = getAppointmentExtermal( patId );
- if (null != appointmentExtermal && null != appointmentExtermal.getBookDate()) {
- // 鏌ヨDB涓� 鏄惁宸茬粡瀛樺湪
- AppointmentDO appointmentDO = appointmentMapper.getCurrentPatId( patId );
- if (null == appointmentDO ) {
- appointmentMapper.insert( appointmentExtermal );
- return appointmentExtermal;
+ public AppointmentDO getCurAppointmentByPatIdAndCheckType(String patId, Integer checkType) {
+ AppointmentDO appointmentDO = appointmentMapper.getByPatAndCheckTypeAndBookDate(patId, checkType);
+ return appointmentDO;
+ }
+
+ /**
+ * @param patCode 缂栧彿 : !!! 涓嶄竴瀹氬氨鏄湰绯荤粺鐨� 鎮h�呯紪鍙�(patID), 鏍规簮鍦ㄤ簬 妫�鏌ュ崟鎵弿鍑烘潵鐨勭紪鍙� 涓嶄竴瀹氭槸 鏈郴缁熺殑 鎮h�呯紪鍙�(patID)
+ * @return
+ */
+ @Override
+ public List<AppointmentDO> queryAndCreateAppointmentByPatId(String patCode) {
+ // 浠庡尰闄㈠钩鍙版煡璇�
+ List<AppointmentDO> appointmentExtermalList = appointmentMapper.getCurrentCode(patCode);
+
+ for (int appointmentIndex = 0; appointmentIndex < appointmentExtermalList.size(); appointmentIndex++) {
+ AppointmentDO appointmentExtermal = appointmentExtermalList.get(appointmentIndex);
+ if (null == appointmentExtermal) continue;
+
+ // 浠嶥B鏌ヨ棰勭害锛屾槸鍚﹀凡缁忓瓨鍦�
+ AppointmentDO appointmentDO = appointmentMapper.getByEpisodeIdAndApplyNo(appointmentExtermal.getEpisodeId(), appointmentExtermal.getApplyNo());
+ if (null == appointmentDO) {
+ appointmentMapper.insert(appointmentExtermal);
+ } else {
+ appointmentExtermal.setId(appointmentDO.getId()); // 纭繚 杩斿洖鍊煎寘鍚� appointment id
+
+ // 澶勭悊绗竴娆$‘璁ゆ椂杩樻病鏈夐绾︽椂闂达紝鍐嶆潵纭鏃跺凡鏈夐绾︽椂闂寸殑鎯呭喌
+ if (appointmentDO.getBookDate() != appointmentExtermal.getBookDate()) {
+ appointmentMapper.updateById(appointmentExtermal);
+ }
}
- return appointmentDO;
}
- return appointmentMapper.getCurrentPatId( patId );
+ // 鏌ヨ[queue琛╙琛ュ厖 book_seq_num 鍒拌繑鍥炲�间腑
+ if (!appointmentExtermalList.isEmpty()) {
+ List<Long> appointIdlist = appointmentExtermalList.stream().map(appointmentDO -> appointmentDO.getId()).toList();
+ List<QueueDO> simpleQueueDOList = queueService.selectBookSeqNumByAppointIdList(appointIdlist);
+ if (!simpleQueueDOList.isEmpty()) {
+ Map<Long, Integer> mapAppointIdVsBookSeqNo = simpleQueueDOList.stream().collect(Collectors.toMap(QueueDO::getAppointId, QueueDO::getBookSeqNum));
+ appointmentExtermalList.forEach(appointmentExterma -> appointmentExterma.setBookSeqNum(mapAppointIdVsBookSeqNo.get(appointmentExterma.getId())));
+ }
+ }
+
+ // 涓嶄粠DB鏌ヨ
+ //List<AppointmentDO> appointmentDOList = appointmentMapper.getCurrentPatId( patCode );
+ //return 0 == appointmentDOList.size() ? null : appointmentDOList.get(0);
+
+ return appointmentExtermalList;
}
@Override
public PageResult<AppointmentDO> getAppointmentPage(AppointmentPageReqVO pageReqVO) {
+ //1. 鍏堟牴鎹畃atId鍘绘煡
+ PageResult<AppointmentDO> result = appointmentMapper.selectPage(pageReqVO);
+ log.info("--------------PATID result鐨勫�间负锛歿}", result);
+ if (!result.getList().isEmpty()) {
+ return result;
+ }
+
+ if (StringUtils.isNotEmpty(pageReqVO.getPatId())) {
+ // 2. 鐢� applyNo 鏌ヨ
+ pageReqVO.setApplyNo(pageReqVO.getPatId());
+ pageReqVO.setPatId(null);
+ log.info("------------------ApplyNo pageReqVO鐨勫�间负锛歿}", pageReqVO);
+ result = appointmentMapper.selectPage(pageReqVO);
+ if (!result.getList().isEmpty()) {
+ return result;
+ }
+
+ // 3. 鐢� episodeId 鏌ヨ
+ pageReqVO.setEpisodeId(pageReqVO.getApplyNo());
+ pageReqVO.setPatId(null);
+ pageReqVO.setApplyNo(null);
+ log.info("-----------EpisodeId pageReqVO鐨勫�间负锛歿}", pageReqVO);
+ }
return appointmentMapper.selectPage(pageReqVO);
}
@Override
- public AppointmentDO getAppointmentExtermal(String mzzyh) {
- RestApiReqBodyVo reqBodyVo = new RestApiReqBodyVo();
- //reqBodyVo.setSfzh(confirmReqVO.getPatId());
- reqBodyVo.setMzzyh( mzzyh );
-
- // QueryRisReportList queryEcgRequest
- RestApiResult<AppointmentExternal> result = remoteDataService.httpApi("queryEcgRequest", "ECG", "ECG", reqBodyVo);
- result.getCode();
-
- AppointmentExternal appointmentExternal = result.getRow().get(0);
-
- AppointmentDO appointmentDO = BeanUtils.toBean( appointmentExternal, AppointmentDO.class );
-
- appointmentDO.setPatId( appointmentExternal.getPatientID() ); // 鍐呭涓� 韬唤璇佸彿 鎴� 闂ㄨ瘖浣忛櫌鍙�
- appointmentDO.setPatName( appointmentExternal.getPatName() );
- appointmentDO.setPatGender( Byte.valueOf(appointmentExternal.getPatgender()) );
- appointmentDO.setPatBirthday( appointmentExternal.getEncPatBirthDate() );
- 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.setBookId( appointmentExternal.getReqIdeApplyno() );
- appointmentDO.setBookDate( appointmentExternal.getReqExtBooktime().toLocalDate() );
- appointmentDO.setBookCheckType( getCorrespondingCheckType(appointmentExternal.getPlanDefItemList().getPlanDefItem().getPlanDefItemcode()) );
- appointmentDO.setBookTime( appointmentExternal.getReqAuthoredOn() );
- LocalDateTime bookStartTime = appointmentExternal.getReqExtBooktime();
- LocalDateTime bookEndTime = bookStartTime.plusMinutes(30);
- appointmentDO.setBookTimeslot( (bookStartTime.getHour()*100 + bookStartTime.getMinute())*10000 + bookEndTime.getHour()*100 + bookEndTime.getMinute() );
- appointmentDO.setBookSrc( 0 );
- appointmentDO.setPaid( 1 );
- return appointmentDO;
+ public List<AppointmentDO> getAppointmentExtermal(String patId) {
+ 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 String appoitmentConfirm(AppointmentConfirmReqVO confirmReqVO) {
+ 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 ( !DateUtils.isToday(appointment.getBookDate()) )
- throw exception( APPOINTMENT_NOT_TODAY);
+ // 鎵嬪姩棰勭害锛岀洿鎺ヨ缃绾︽棩鏈熶负褰撳ぉ
+ if (confirmReqVO.getIsVip() == 1) {
+ appointment.setBookDate(LocalDate.now());
+ }
+
+ if (!DateUtils.isToday(appointment.getBookDate())) throw exception(APPOINTMENT_NOT_TODAY);
+
+
+ Integer newSeqNo = null;
+ if (confirmReqVO.getIsVip() == 0) {
+ newSeqNo = queueSequenceService.distributeSeqNo(confirmReqVO.getBookCheckType(), confirmReqVO.getBookTimeslot());
+ } else {
+ newSeqNo = queueSequenceService.distributeVipSeqNo(confirmReqVO.getBookCheckType(), confirmReqVO.getBookTimeslot());
+ }
try {
QueueSaveReqVO queueSaveReqVO = new QueueSaveReqVO();
+ 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(appointment.getBookTimeslot());
+ queueSaveReqVO.setBookTimeslot(confirmReqVO.getBookTimeslot()); /*appointment.getBookTimeslot()*/
queueSaveReqVO.setBookCheckType(appointment.getBookCheckType());
+ queueSaveReqVO.setBookSeqNum(newSeqNo);
+ queueSaveReqVO.setIsVip(confirmReqVO.getIsVip());
queueSaveReqVO.setPassed((byte) 0);
queueSaveReqVO.setExpired((byte) 0);
- queueSaveReqVO.setPatDetails( appointment.getPatDeptDesc() + "-" + appointment.getPatWardDesc() + "-" + appointment.getPatBedNo());
+ queueSaveReqVO.setPatDetails(getPatDetails(appointment));
queueService.queue(queueSaveReqVO);
} catch (DuplicateKeyException duplicateKeyException) {
throw exception(APPOINTMENT_HAVE_QUEUED);
}
- return "纭鎴愬姛";
+ 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 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());
+ return patDetails;
}
-}
\ No newline at end of file
+
+ @Override
+ public Long handleAppointmentCreate(Map<String, Object> dataMap) {
+ if (dataMap == null) {
+ throw exception(APPOINTMENT_CREATE_FAIL);
+ }
+
+ try {
+ // 鍒涘缓AppointmentDO瀵硅薄
+ AppointmentDO appointment = new AppointmentDO();
+
+ // 浠巇ataMap涓彁鍙栨暟鎹�
+ 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(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 ISDN = zdy.get("ISDN");
+ if (ISDN != null) {
+ return ISDN.toString();
+ }
+ return null;
+ }).ifPresent(appointment::setTolerance);
+
+ // 鍖荤敓寮�鍗曟椂闂�
+ 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("author")).map(author -> (Map<String, Object>) author.get("time")).map(time -> (String) time.get("value")).map(str -> {
+ try {
+ return new SimpleDateFormat("yyyyMMddHHmmss").parse(str);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }).filter(Objects::nonNull).ifPresent(appointment::setDoctorTime);
+
+ //璁剧疆寮�鍗曞尰鐢熷鍚�
+ 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("author")).map(author -> (Map<String, Object>) author.get("assignedEntity")).map(assignedEntity -> (Map<String, Object>) assignedEntity.get("assignedPerson")).map(assignedPerson -> (Map<String, Object>) assignedPerson.get("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::setDoctor);
+
+ //璁剧疆寮�鍗曞尰鐢熺紪鐮�
+ 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("author")).map(author -> (Map<String, Object>) author.get("assignedEntity")).map(assignedEntity -> (Map<String, Object>) assignedEntity.get("id")).map(id -> (Map<String, Object>) id.get("item")).map(item -> (String) item.get("extension")).ifPresent(appointment::setDoctorCode);
+
+
+ // 璁剧疆鎮h�呮潵婧愮被鍨�
+ Optional.ofNullable(encounter.get("code")).map(code -> (Map<String, Object>) code).map(code -> (String) code.get("code")).map(Integer::parseInt).ifPresent(appointment::setPatSrc);
+
+ // 璁剧疆鎮h�呬俊鎭�
+ 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 -> {
+ // 璁剧疆鎮h�匢D
+ 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);
+
+ // 璁剧疆鎮h�呴棬璇婂彿
+ 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(2)).map(item -> (String) item.get("extension")).ifPresent(appointment::setOutpatientNo);
+
+ // 璁剧疆鎮h�呬綇闄㈠彿
+ 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(2)).map(item -> (String) item.get("extension")).ifPresent(appointment::setHospitalNo);
+
+ // 璁剧疆鎮h�呭鍚�
+ 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);
+
+ // 璁剧疆鎮h�呮墜鏈哄拰鐢佃瘽
+ 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);
+ });
+
+ // 璁剧疆鎮h�呮�у埆
+ Optional.ofNullable(patientPerson.get("administrativeGenderCode")).map(genderCode -> (Map<String, Object>) genderCode).map(genderCode -> (String) genderCode.get("code")).map(Byte::parseByte).ifPresent(appointment::setPatGender);
+
+ // 璁剧疆鎮h�呯敓鏃�
+ 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);
+
+ // 璁剧疆鎮h�呭湴鍧�
+ 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);
+
+ // 璁剧疆鎮h�呰韩浠借瘉鍙�
+ 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);
+
+ //鎮h�呭尰淇濆崱
+ 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(1)).map(item -> (String) item.get("extension")).ifPresent(appointment::setMedicalCard);
+ });
+
+ // 璁剧疆鏀粯鐘舵��
+ 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));
+ String checkName = 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 -> (Map<String, Object>) code.get("displayName")).map(displayName -> (String) displayName.get("value")).orElseThrow(() -> exception(APPOINTMENT_CREATE_FAIL));
+ if (appointment.getPatSrc() != null && appointment.getPatSrc() != 4) {
+ if (checkType != null || checkType != "")
+ appointment.setBookCheckType(Integer.valueOf(HisCheckCodeEnum.getByCode(checkType.substring(1))));
+ } else if (appointment.getPatSrc() != null && appointment.getPatSrc() == 4) {
+ if (StringUtils.isNotEmpty(checkName)) {
+ checkName = checkName.replaceAll("\\s+", "");
+ appointment.setBookCheckType(Integer.valueOf(HisCheckNameEnum.getByName(checkName)));
+ }
+ }
+
+
+ // 璁剧疆绉戝鍜岀梾鍖轰俊鎭�
+ 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 -> {
+ // 璁剧疆绉戝浠g爜鍜屽悕绉�
+ 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);
+
+ // 璁剧疆鐥呭尯浠g爜鍜屽悕绉�
+ 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);
+ if (appointment.getPatSrc() != null && appointment.getPatSrc() == 4) {
+ //浣撴灏辫繖涓�涓瀹�
+ appointment.setPatDeptDesc("鍋ュ悍绠$悊涓績");
+ } else {
+ 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);
+ }
+ });
+ });
+
+
+ // 灏咥ppointmentDO杞崲涓篈ppointmentSaveReqVO骞朵繚瀛�
+ AppointmentSaveReqVO saveReqVO = BeanUtils.toBean(appointment, AppointmentSaveReqVO.class);
+
+ //鏍规嵁鐢宠缂栧彿鍏堟煡璇竴涓嬫槸鍚﹀瓨鍦紝濡傛灉瀛樺湪锛屽氨涓嶆柊澧炰簡
+ AppointmentDO appointmentDO = appointmentMapper.getByApplyNo(saveReqVO.getApplyNo());
+ log.info("=======鏄惁鏂板杩囦簡锛歿}", ObjectUtils.isNotEmpty(appointmentDO) ? appointmentDO.getId() : null);
+ if (ObjectUtils.isNotEmpty(appointmentDO)) return appointmentDO.getId();
+
+ 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 {
+ // 浠巇ataMap涓彁鍙栫敵璇峰崟鍙�
+ 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);
+
+ // 濡傛灉璁板綍涓嶅瓨鍦紝鍒欒皟鐢╤andleAppointmentCreate杩涜鏂板
+ if (existingAppointment == null) {
+ handleAppointmentCreate(dataMap);
+ return;
+ }
+
+ // 浠巇ataMap涓彁鍙栨暟鎹�
+ 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);
+
+
+ // 鏇存柊鎮h�呮潵婧愮被鍨�
+ Optional.ofNullable(encounter.get("code")).map(code -> (Map<String, Object>) code).map(code -> (String) code.get("code")).map(Integer::parseInt).ifPresent(existingAppointment::setPatSrc);
+
+ // 鏇存柊鎮h�呬俊鎭�
+ 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 -> {
+ // 鏇存柊鎮h�匢D
+ 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);
+
+ // 鏇存柊鎮h�呭鍚�
+ 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);
+
+ // 鏇存柊鎮h�呮墜鏈哄拰鐢佃瘽
+ 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);
+ });
+
+ // 鏇存柊鎮h�呮�у埆
+ Optional.ofNullable(patientPerson.get("administrativeGenderCode")).map(genderCode -> (Map<String, Object>) genderCode).map(genderCode -> (String) genderCode.get("code")).map(Byte::parseByte).ifPresent(existingAppointment::setPatGender);
+
+ // 鏇存柊鎮h�呯敓鏃�
+ 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);
+
+ // 鏇存柊鎮h�呭湴鍧�
+ 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);
+
+ // 鏇存柊鎮h�呰韩浠借瘉鍙�
+ 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 -> {
+ // 鏇存柊绉戝浠g爜鍜屽悕绉�
+ 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);
+
+ // 鏇存柊鐥呭尯浠g爜鍜屽悕绉�
+ 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))));
+
+ // 灏咥ppointmentDO杞崲涓篈ppointmentSaveReqVO骞舵洿鏂�
+ 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);
+ }
+ // 浠巇ataMap涓彁鍙栫敵璇峰崟鍙�
+ 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);
+
+ // 濡傛灉璁板綍涓嶅瓨鍦紝鍒欒皟鐢╤andleAppointmentCreate杩涜鏂板
+ if (existingAppointment == null) {
+ handleAppointmentCreate(dataMap);
+ return;
+ }
+
+
+ // 浠巇ataMap涓彁鍙栫敵璇峰崟鍙�
+// 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));
+ 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 -> (String) code.get("code")).orElseThrow(() -> exception(APPOINTMENT_CREATE_FAIL));
+
+ existingAppointment.setStatus(status);
+ if ("3".equals(status)) {
+ existingAppointment.setRegisterDate(new Date());
+ }
+ // 灏咥ppointmentDO杞崲涓篈ppointmentSaveReqVO骞舵洿鏂�
+ AppointmentSaveReqVO updateReqVO = BeanUtils.toBean(existingAppointment, AppointmentSaveReqVO.class);
+ updateAppointment(updateReqVO);
+ }
+
+
+ /**
+ * 浠巇ataMap涓彁鍙杄ncounter鏁版嵁
+ */
+ 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) {
+ // 浠巇ataMap涓幏鍙朿ontrolActProcess
+ 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");
+
+ // 瑙f瀽棰勭害鏃堕棿
+ LocalDateTime bookTime = LocalDateTime.parse(bookTimeStr, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
+ LocalDate bookDate = bookTime.toLocalDate();
+ Integer bookTimeslot = null;
+
+ // 鑾峰彇鏃堕棿娈�
+ try {
+// String timeRange = (String) ((Map<String, Object>) actAppointment.get("ZDY")).get("time");杩欒濡傛灉鏄洿鏂版搷浣滅殑鏃跺�欙紝鏈夊彲鑳芥姤绌烘寚閽�(浣嗕笉褰卞搷锛屽彲浠ヤ笉鐢ㄧ)
+ 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
+ bookTimeslot = Integer.parseInt(startTime.replace(":", "")) * 10000 + Integer.parseInt(endTime.replace(":", ""));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ // 鏇存柊棰勭害淇℃伅
+ appointment.setBookDate(bookDate);
+ appointment.setBookTimeslot(bookTimeslot);
+ appointment.setBookTime(bookTime);
+ appointment.setBookSrc(Integer.parseInt(bookSrc));
+ appointment.setStatus((String) ((Map<String, Object>) actAppointment.get("ZDY")).get("statusCode"));
+
+ // 淇濆瓨鏇存柊
+ appointmentMapper.updateById(appointment);
+ }
+
+ @Override
+ public void handleAppointmentStatusUpdate(Map<String, Object> dataMap) {
+ if (dataMap == null) {
+ throw exception(APPOINTMENT_STATUS_REGISTER_UPDATE_FAIL);
+ }
+ //鑾峰彇applyNo
+ Map<String, Object> controlActProcess = (Map<String, Object>) dataMap.get("controlActProcess");
+ Map<String, Object> subject = (Map<String, Object>) controlActProcess.get("subject");
+ Map<String, Object> placerGroup = (Map<String, Object>) subject.get("placerGroup");
+ Map<String, Object> component2 = (Map<String, Object>) placerGroup.get("component2");
+ Map<String, Object> observationRequest = (Map<String, Object>) component2.get("observationRequest");
+ Map<String, Object> id = (Map<String, Object>) observationRequest.get("id");
+ Map<String, Object> item = (Map<String, Object>) id.get("item");
+ String applyNo = (String) item.get("extension");
+
+ //鑾峰彇status
+ Map<String, Object> component1 = (Map<String, Object>) observationRequest.get("component1");
+ Map<String, Object> processStep = (Map<String, Object>) component1.get("processStep");
+ Map<String, Object> codeMap = (Map<String, Object>) processStep.get("code");
+ String status = String.valueOf(codeMap.get("code"));
+ Date date = null;
+ if (status.equals("3")) {
+ //璁板綍鐧昏鏃堕棿
+ date = new Date();
+ }
+ //鐘舵�佹洿鏂�
+ Integer i = appointmentMapper.updateStatusByApplyNo(applyNo, status, date);
+ log.info("鐢宠鍗曠櫥璁癮pplyNo:{},鐘舵�乻tatus:{},鏇存柊缁撴灉锛歿}", applyNo, status, i);
+
+ }
+
+ public AppointmentDO getByApplyNo(String applyNo) {
+ return appointmentMapper.getByApplyNo(applyNo);
+ }
+}
+
--
Gitblit v1.9.3