|
@@ -0,0 +1,157 @@
|
|
|
+package thyyxxk.webserver.service.examinations;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.text.StringEscapeUtils;
|
|
|
+import org.dom4j.Document;
|
|
|
+import org.dom4j.DocumentException;
|
|
|
+import org.dom4j.DocumentHelper;
|
|
|
+import org.dom4j.Element;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import thyyxxk.webserver.config.exception.BizException;
|
|
|
+import thyyxxk.webserver.entity.examinations.adicon.AdiconInquiry;
|
|
|
+import thyyxxk.webserver.entity.examinations.adicon.BarcodeType;
|
|
|
+import thyyxxk.webserver.entity.examinations.adicon.ListTableItem;
|
|
|
+import thyyxxk.webserver.entity.examinations.adicon.ReportDetail;
|
|
|
+import thyyxxk.webserver.service.externalhttp.AdiconHttpSrvc;
|
|
|
+import thyyxxk.webserver.utils.FilterUtil;
|
|
|
+
|
|
|
+import javax.xml.bind.JAXBContext;
|
|
|
+import javax.xml.bind.Unmarshaller;
|
|
|
+import java.io.StringReader;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class AdiconService {
|
|
|
+ private final AdiconHttpSrvc adiconHttpSrvc;
|
|
|
+
|
|
|
+ private static final String URL = "http://222.240.235.22/CSWebService/ADReportWebService.asmx";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public AdiconService(AdiconHttpSrvc adiconHttpSrvc) {
|
|
|
+ this.adiconHttpSrvc = adiconHttpSrvc;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String login(String type) throws Exception {
|
|
|
+ String xml = type.equals("JYK") ? adiconHttpSrvc.jykLogin() : adiconHttpSrvc.blkLogin();
|
|
|
+ Document document = DocumentHelper.parseText(xml);
|
|
|
+ Element root = document.getRootElement();
|
|
|
+ return root.getText();
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ListTableItem> getReportList(AdiconInquiry inquiry) throws Exception {
|
|
|
+ String key = URLEncoder.encode(inquiry.getKey(), StandardCharsets.UTF_8.name());
|
|
|
+ String xmlString = adiconHttpSrvc.getReportList(key, inquiry.getBegin(), inquiry.getEnd());
|
|
|
+ List<ListTableItem> result = new ArrayList<>();
|
|
|
+ Element root = getRootElement(xmlString);
|
|
|
+ List<Element> listtable = FilterUtil.cast(root.elements("listtable"));
|
|
|
+ JAXBContext jaxbContext = JAXBContext.newInstance(ListTableItem.class);
|
|
|
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
|
|
+ for (Element element : listtable) {
|
|
|
+ StringReader reader = new StringReader(element.asXML());
|
|
|
+ ListTableItem listTable = (ListTableItem) unmarshaller.unmarshal(reader);
|
|
|
+ if (inquiry.getReportType().equals("全部") ||
|
|
|
+ inquiry.getReportType().equals(listTable.getReportType())) {
|
|
|
+ result.add(listTable);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ReportDetail> getReportItemListByCustomerBarcode(AdiconInquiry inquiry) throws Exception {
|
|
|
+ String key = URLEncoder.encode(inquiry.getKey(), StandardCharsets.UTF_8.name());
|
|
|
+ String xmlString;
|
|
|
+ if (inquiry.getBarcodeType() == BarcodeType.CUSTOMER) {
|
|
|
+ xmlString = adiconHttpSrvc.getReportItemListByCustomerBarcode(key, inquiry.getBarcode(), inquiry.getReportType());
|
|
|
+ } else {
|
|
|
+ xmlString = adiconHttpSrvc.getReportItemListByAdiconBarcode(key, inquiry.getBarcode(), inquiry.getReportType());
|
|
|
+ }
|
|
|
+ List<ReportDetail> result = new ArrayList<>();
|
|
|
+ Element root = getRootElement(xmlString);
|
|
|
+ List<Element> items = FilterUtil.cast(root.elements("item"));
|
|
|
+ JAXBContext jaxbContext = JAXBContext.newInstance(ReportDetail.class);
|
|
|
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
|
|
+ for (Element element : items) {
|
|
|
+ StringReader reader = new StringReader(element.asXML());
|
|
|
+ ReportDetail reportDetail = (ReportDetail) unmarshaller.unmarshal(reader);
|
|
|
+ result.add(reportDetail);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String setSampleDownFlagByCustomerBarcode(AdiconInquiry inquiry) throws Exception {
|
|
|
+ String key = URLEncoder.encode(inquiry.getKey(), StandardCharsets.UTF_8.name());
|
|
|
+ String xmlString;
|
|
|
+ if (inquiry.getBarcodeType() == BarcodeType.CUSTOMER) {
|
|
|
+ xmlString = adiconHttpSrvc.setSampleDownFlagByCustomerBarcode(key, inquiry.getBarcode(), inquiry.getReportType());
|
|
|
+ } else {
|
|
|
+ xmlString = adiconHttpSrvc.setSampleDownFlagByAdiconBarcode(key, inquiry.getBarcode(), inquiry.getReportType());
|
|
|
+ }
|
|
|
+ Document document = DocumentHelper.parseText(xmlString);
|
|
|
+ Element root = document.getRootElement();
|
|
|
+ return root.getText();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getByteReport(AdiconInquiry inquiry) throws Exception {
|
|
|
+ String key = URLEncoder.encode(inquiry.getKey(), StandardCharsets.UTF_8.name());
|
|
|
+ String xmlString = adiconHttpSrvc.getByteReport(inquiry.getId(), key);
|
|
|
+ Document document = DocumentHelper.parseText(xmlString);
|
|
|
+ Element root = document.getRootElement();
|
|
|
+ return root.getText();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Element getRootElement(String xmlString) throws DocumentException {
|
|
|
+ String xmlWithoutDeclaration = removeXmlDeclaration(xmlString);
|
|
|
+ String standardXml = StringEscapeUtils.unescapeXml(xmlWithoutDeclaration);
|
|
|
+ standardXml = standardXml.replaceAll("\r\n", "");
|
|
|
+ if (standardXml.startsWith("<string")) {
|
|
|
+ int startIndex = standardXml.indexOf(">");
|
|
|
+ int endIndex = standardXml.lastIndexOf("</string>");
|
|
|
+ standardXml = standardXml.substring(startIndex + 1, endIndex);
|
|
|
+ }
|
|
|
+ if (!standardXml.startsWith("<")) {
|
|
|
+ throw new BizException(standardXml);
|
|
|
+ }
|
|
|
+ Document document = DocumentHelper.parseText(standardXml);
|
|
|
+ return document.getRootElement();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String removeXmlDeclaration(String xmlString) {
|
|
|
+ // 去除XML声明
|
|
|
+ return xmlString.replaceAll("<\\?xml.*?\\?>", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void test() {
|
|
|
+// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
|
+// DocumentBuilder builder = factory.newDocumentBuilder();
|
|
|
+// ByteArrayInputStream input = new ByteArrayInputStream(standardXml.getBytes(StandardCharsets.UTF_8));
|
|
|
+// org.w3c.dom.Document document = builder.parse(input);
|
|
|
+//
|
|
|
+// NodeList listTableNodes = document.getElementsByTagName("listtable");
|
|
|
+//
|
|
|
+// for (int i = 0; i < listTableNodes.getLength(); i++) {
|
|
|
+// Node node = listTableNodes.item(i);
|
|
|
+// if (node.getNodeType() == Node.ELEMENT_NODE) {
|
|
|
+// org.w3c.dom.Element element = (org.w3c.dom.Element) node;
|
|
|
+// String id = element.getElementsByTagName("Id").item(0).getTextContent();
|
|
|
+// String reportType = element.getElementsByTagName("ReportType").item(0).getTextContent();
|
|
|
+// String adiconBarcode = element.getElementsByTagName("AdiconBarcode").item(0).getTextContent();
|
|
|
+// String patientName = element.getElementsByTagName("PatientName").item(0).getTextContent();
|
|
|
+//
|
|
|
+// System.out.println("Id: " + id);
|
|
|
+// System.out.println("Report Type: " + reportType);
|
|
|
+// System.out.println("Adicon Barcode: " + adiconBarcode);
|
|
|
+// System.out.println("Patient Name: " + patientName);
|
|
|
+// System.out.println("---------------");
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|