| | |
| | | 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: 西安路泰科技有限公司 |
| | |
| | | * 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())); |
| | |
| | | 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(); |
| | | |
| | | // 打印生成的SOAP请求 |
| | | System.out.println("生成的SOAP请求内容:"); |
| | | 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); // 将每个ExamItem添加到集合 |
| | | // } |
| | | // |
| | | // // 构造最终的ExamItemList |
| | | // examItemList.put("ExamItem", examItemsList); |
| | | // hashMap.put("ExamItemList", examItemList); |
| | | // |
| | | // hashMap.put("PatientInfor", patientInfo); |
| | | // |
| | | // // 将数据封装到根节点 |
| | | // root.put("Root", hashMap); |
| | | // |
| | | // // 使用Hutool将Map转换为XML字符串 |
| | | // 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) { |