From 045dc3a1be1c2980458c6cf20de9e2f2efe7e15d Mon Sep 17 00:00:00 2001
From: zhaowenxuan <chacca165@163.com>
Date: 星期四, 26 十二月 2024 18:06:13 +0800
Subject: [PATCH] 20241226

---
 ltkj-admin/src/main/java/com/ltkj/web/controller/pacs/PacsApiMethodService.java |  145 ++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 110 insertions(+), 35 deletions(-)

diff --git a/ltkj-admin/src/main/java/com/ltkj/web/controller/pacs/PacsApiMethodService.java b/ltkj-admin/src/main/java/com/ltkj/web/controller/pacs/PacsApiMethodService.java
index cdf9b24..fc7d4a7 100644
--- a/ltkj-admin/src/main/java/com/ltkj/web/controller/pacs/PacsApiMethodService.java
+++ b/ltkj-admin/src/main/java/com/ltkj/web/controller/pacs/PacsApiMethodService.java
@@ -27,10 +27,13 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
+import javax.xml.soap.*;
 
 /**
  * @Company: 瑗垮畨璺嘲绉戞妧鏈夐檺鍏徃
@@ -239,6 +242,8 @@
      * xml浼犻��
      */
     public boolean OrderAdd(TjCustomer customer,TjOrder tjOrder){
+        String hospbm = configService.selectConfigByKey("common_api_service_hospbm");
+
         List<TbTransition> detailList = transitionService.getTbTransitionListByCusId(customer.getCusIdcard(), tjOrder.getCardId());
         LambdaQueryWrapper<TjProject> wq = new LambdaQueryWrapper<>();
         wq.in(TjProject::getProId, detailList.stream().map(TbTransition::getParentProId).collect(Collectors.toList()));
@@ -247,43 +252,113 @@
         HashMap<String, Object> root = new HashMap<>();
         HashMap<String, Object> hashMap = new HashMap<>();
 
-        HashMap<String, Object> patientInfo = new HashMap<>();
-        patientInfo.put("PatientId",customer.getCusId());
-        patientInfo.put("VisitNo",tjOrder.getTjNumber());
-        patientInfo.put("PatType","P");
-        patientInfo.put("PatientName",customer.getCusName());
-        if (customer.getCusSex() == 0) patientInfo.put("PatientSex","M");
-        else if (customer.getCusSex() == 1) patientInfo.put("PatientSex","F");
-        else patientInfo.put("PatientSex","O");
-        patientInfo.put("PatBirthday",customer.getCusBrithday());
-        patientInfo.put("IdCard",customer.getCusIdcard());
+        String xmlRequest = "";
 
-        String examItems = "";
-        String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
-        for (TjProject project : projects) {
-            HashMap<String, Object> examItem = new HashMap<>();
-            // 鐢宠鍗曞彿瑙勫垯锛氫綋妫�鍙穇project.getProId()鍚庡洓浣�
-            examItem.put("HisID", tjOrder.getTjNumber() + String.valueOf(project.getProId()).substring(String.valueOf(project.getProId()).length() - 4));
-            examItem.put("EmergencyFlag", "0");
-            examItem.put("ExamItemID", project.getHisXmbm());
-            examItem.put("ExamItemName", project.getHisXmmc());
-            examItem.put("OrderDT", date);
-            SysDept dept = deptService.getById(project.getDeptId());
-            examItem.put("Modality", dept.getModality());
-            // TODO 鏀惰垂鏍囪瘑 1鏄敹璐� 鍜� 0鏈敹璐�
-            examItem.put("ChargeFlag","");
-            examItems += "<ExamItem>"+
-                    XmlUtil.mapToXmlStr(examItem)
-                            .replaceAll("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>","")
-                            .replaceAll("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>","")
-                            .replaceAll("<xml>","")
-                            .replaceAll("</xml>","")
-                    +"</ExamItem>";
+        MessageFactory messageFactory = null;
+        try {
+            // 鍒涘缓SOAP娑堟伅
+            messageFactory = MessageFactory.newInstance();
+            SOAPMessage soapMessage = messageFactory.createMessage();
+            // 鍒涘缓SOAP Envelope
+            SOAPPart soapPart = soapMessage.getSOAPPart();
+            SOAPEnvelope envelope = soapPart.getEnvelope();
+            envelope.addNamespaceDeclaration("xmlns", "http://tempuri.org/");
+
+            // 鍒涘缓SOAP Body
+            SOAPBody soapBody = envelope.getBody();
+            SOAPElement rootElement = soapBody.addChildElement("OrderAdd", "xmlns");
+            rootElement.addChildElement("dataSourceName").addTextNode("hisDataSource");
+
+            // PatientInfor 閮ㄥ垎
+            SOAPElement patientInfor = rootElement.addChildElement("PatientInfor");
+            if (customer.getCusSex() == 0) patientInfor.addChildElement("PatientSex").addTextNode("M");
+            else if (customer.getCusSex() == 1) patientInfor.addChildElement("PatientSex").addTextNode("F");
+            else patientInfor.addChildElement("PatientSex").addTextNode("O");
+            patientInfor.addChildElement("PatBirthday").addTextNode(new SimpleDateFormat("yyyy-MM-dd").format(customer.getCusBrithday()));
+            patientInfor.addChildElement("VisitNo").addTextNode(tjOrder.getTjNumber());
+            patientInfor.addChildElement("PatientId").addTextNode(String.valueOf(customer.getCusId()));
+            patientInfor.addChildElement("HospitalID").addTextNode("shanxiqinxamjyy");
+            patientInfor.addChildElement("IdCard").addTextNode(customer.getCusIdcard());
+            patientInfor.addChildElement("PatientName").addTextNode(customer.getCusName());
+            patientInfor.addChildElement("PatType").addTextNode("P");
+
+            // ExamItemList 閮ㄥ垎
+            SOAPElement examItemList = rootElement.addChildElement("ExamItemList");
+
+            String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
+            for (TjProject project : projects) {
+                SOAPElement examItem = examItemList.addChildElement("ExamItem");
+                examItem.addChildElement("HisID").addTextNode(tjOrder.getTjNumber() + String.valueOf(project.getProId()).substring(String.valueOf(project.getProId()).length() - 4));
+                examItem.addChildElement("EmergencyFlag").addTextNode("0");
+                examItem.addChildElement("ExamItemID").addTextNode(project.getHisXmbm());
+                examItem.addChildElement("ExamItemName").addTextNode(project.getHisXmmc());
+                examItem.addChildElement("OrderDT").addTextNode(date);
+                SysDept dept = deptService.getById(project.getDeptId());
+                examItem.addChildElement("Modality").addTextNode(dept.getModality());
+                examItem.addChildElement("ChargeFlag").addTextNode("1");
+            }
+
+            // 淇濆瓨SOAP娑堟伅
+            soapMessage.saveChanges();
+
+            // 鎵撳嵃鐢熸垚鐨凷OAP璇锋眰
+            System.out.println("鐢熸垚鐨凷OAP璇锋眰鍐呭锛�");
+            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+            soapMessage.writeTo(byteArrayOutputStream);
+            xmlRequest = byteArrayOutputStream.toString("UTF-8");
+        } catch (SOAPException | IOException e) {
+            log.error("SOAP寮傚父 ->{}",String.valueOf(e));
         }
-        hashMap.put("PatientInfor",patientInfo);
-        hashMap.put("ExamItemList",examItems);
-        root.put("Root",hashMap);
-        String result = HttpRequest.post("").body(XmlUtil.mapToXmlStr(root)).contentType("application/xml;charset:utf-8;").execute().body();
+
+
+//        HashMap<String, Object> patientInfo = new HashMap<>();
+//        patientInfo.put("PatientId",customer.getCusId());
+//        patientInfo.put("VisitNo",tjOrder.getTjNumber());
+//        patientInfo.put("PatType","P");
+//        patientInfo.put("PatientName",customer.getCusName());
+//        if (customer.getCusSex() == 0) patientInfo.put("PatientSex","M");
+//        else if (customer.getCusSex() == 1) patientInfo.put("PatientSex","F");
+//        else patientInfo.put("PatientSex","O");
+//        patientInfo.put("PatBirthday",new SimpleDateFormat("yyyy-MM-dd").format(customer.getCusBrithday()));
+//        patientInfo.put("IdCard",customer.getCusIdcard());
+//        patientInfo.put("hospitalid","chkwyy");
+//        patientInfo.put("HospitalID",hospbm);
+//
+//        HashMap<String, Object> examItemList = new HashMap<>();
+//        List<Map<String, Object>> examItemsList = new ArrayList<>();
+        String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
+//
+//        for (TjProject project : projects) {
+//            HashMap<String, Object> examItem = new HashMap<>();
+//            // 鐢宠鍗曞彿瑙勫垯锛氫綋妫�鍙穇project.getProId()鍚庡洓浣�
+//            examItem.put("HisID", tjOrder.getTjNumber() + String.valueOf(project.getProId()).substring(String.valueOf(project.getProId()).length() - 4));
+//            examItem.put("EmergencyFlag", "0");
+//            examItem.put("ExamItemID", project.getHisXmbm());
+//            examItem.put("ExamItemName", project.getHisXmmc());
+//            examItem.put("OrderDT", date);
+//
+//            SysDept dept = deptService.getById(project.getDeptId());
+//            examItem.put("Modality", dept.getModality());
+//            // 鏀惰垂鏍囪瘑锛�1 鏄敹璐癸紝0 鏈敹璐�
+//            examItem.put("ChargeFlag", "1");
+//
+//            examItemsList.add(examItem); // 灏嗘瘡涓狤xamItem娣诲姞鍒伴泦鍚�
+//        }
+//
+//        // 鏋勯�犳渶缁堢殑ExamItemList
+//        examItemList.put("ExamItem", examItemsList);
+//        hashMap.put("ExamItemList", examItemList);
+//
+//        hashMap.put("PatientInfor", patientInfo);
+//
+//        // 灏嗘暟鎹皝瑁呭埌鏍硅妭鐐�
+//        root.put("Root", hashMap);
+//
+//        // 浣跨敤Hutool灏哅ap杞崲涓篨ML瀛楃涓�
+//        String xmlRequest = XmlUtil.mapToXmlStr(root);
+
+        String result = "1";
+        log.info("璋冪敤pacs浼犻�掑弬鏁扮殑鍊间负: "+xmlRequest);
         Map<String, Object> map = XmlUtil.xmlToMap(result);
         if (map.get("Code").toString().equals("1")){
             for (TjProject project : projects) {

--
Gitblit v1.8.0