From 971bd30b611531464d7a878352e453ab4511f93f Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期四, 19 六月 2025 19:36:24 +0800
Subject: [PATCH] 代码提交

---
 jh-module-ecg/jh-module-ecg-biz/src/main/java/cn/lihu/jh/module/ecg/service/appointment/AppointmentServiceImpl.java |   87 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 76 insertions(+), 11 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 13e68f3..4badfac 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
@@ -11,13 +11,17 @@
 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.feign.RemoteDataService;
 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.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;
@@ -61,6 +65,9 @@
     @Resource
     private AppointmentMapper appointmentMapper;
 
+    @Autowired
+    private WebServiceClient webServiceClient;
+
     @Override
     public Long createAppointment(AppointmentSaveReqVO createReqVO) {
         // 鎻掑叆
@@ -83,6 +90,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
@@ -117,7 +160,7 @@
     @Override
     public List<AppointmentDO> queryAndCreateAppointmentByPatId(String patCode) {
         // 浠庡尰闄㈠钩鍙版煡璇�
-        List<AppointmentDO> appointmentExtermalList = getAppointmentExtermal(patCode);
+        List<AppointmentDO> appointmentExtermalList = appointmentMapper.getCurrentCode(patCode);
 
         for (int appointmentIndex = 0; appointmentIndex < appointmentExtermalList.size(); appointmentIndex++) {
             AppointmentDO appointmentExtermal = appointmentExtermalList.get(appointmentIndex);
@@ -301,6 +344,13 @@
 
             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);
 
             // 璁剧疆鎮h�呮潵婧愮被鍨�
             Optional.ofNullable(encounter.get("code")).map(code -> (Map<String, Object>) code).map(code -> (String) code.get("code")).map(Integer::parseInt).ifPresent(appointment::setPatSrc);
@@ -309,6 +359,12 @@
             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);
@@ -330,6 +386,9 @@
 
                 // 璁剧疆鎮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);
             });
 
             // 璁剧疆绉戝鍜岀梾鍖轰俊鎭�
@@ -501,7 +560,8 @@
 
 
         // 浠巇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 -> (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);
         // 灏咥ppointmentDO杞崲涓篈ppointmentSaveReqVO骞舵洿鏂�
@@ -557,22 +617,27 @@
         // 瑙f瀽棰勭害鏃堕棿
         LocalDateTime bookTime = LocalDateTime.parse(bookTimeStr, DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
         LocalDate bookDate = bookTime.toLocalDate();
+        Integer bookTimeslot = null;
 
         // 鑾峰彇鏃堕棿娈�
-        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(":", ""));
-
+        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);

--
Gitblit v1.9.3