|
@ -1,33 +1,154 @@
|
|
|
package com.yihu.hos.gateway.control.rpc.impl;
|
|
|
|
|
|
import com.coreframework.remoting.Url;
|
|
|
import com.coreframework.remoting.reflect.InvokeRequest;
|
|
|
import com.coreframework.remoting.reflect.Rpc;
|
|
|
import com.yihu.hos.config.Config;
|
|
|
import com.yihu.hos.gateway.control.rpc.IResourceRpc;
|
|
|
import com.yihu.hos.gateway.exception.EHRException;
|
|
|
import com.yihu.hos.gateway.model.RsResourceRpcGateway;
|
|
|
import com.yihu.hos.gateway.model.rpc.RPCRequestResult;
|
|
|
import com.yihu.hos.gateway.model.rpc.RPCResponseResult;
|
|
|
import com.yihu.hos.gateway.util.Constant;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.dom4j.Document;
|
|
|
import org.dom4j.Element;
|
|
|
import org.dom4j.io.SAXReader;
|
|
|
|
|
|
import javax.xml.bind.JAXBContext;
|
|
|
import javax.xml.bind.Unmarshaller;
|
|
|
import java.io.StringReader;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Created by Administrator on 2016/4/12.
|
|
|
*/
|
|
|
public class ResourceRpcImpl implements IResourceRpc {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public String transport(String RPCRequestXml) {
|
|
|
try {
|
|
|
|
|
|
//解析xml
|
|
|
SAXReader saxReader = new SAXReader();
|
|
|
Document document = saxReader.read(RPCRequestXml);
|
|
|
Element root = document.getRootElement();
|
|
|
|
|
|
//xml转对象
|
|
|
JAXBContext context = JAXBContext.newInstance(RPCRequestResult.class);
|
|
|
Unmarshaller unmarshaller = context.createUnmarshaller();
|
|
|
RPCRequestResult rpcRequestResult = (RPCRequestResult) unmarshaller.unmarshal(new StringReader(RPCRequestXml));
|
|
|
// JAXBContext context = JAXBContext.newInstance(RPCRequestResult.class);
|
|
|
//Unmarshaller unmarshaller = context.createUnmarshaller();
|
|
|
// RPCRequestResult rpcRequestResult = (RPCRequestResult) unmarshaller.unmarshal(new StringReader(RPCRequestXml));
|
|
|
//得到业务code
|
|
|
String trancode = rpcRequestResult.getTransactionCode();
|
|
|
String trancode = root.element("TransactionCode").toString();
|
|
|
if (trancode.equals(Constant.PATIENT_INFORMATION)) {
|
|
|
String cardNo = root.element("Data").element("CardNo").toString();
|
|
|
;
|
|
|
String cardType = root.element("Data").element("CardType").toString();
|
|
|
;
|
|
|
String patientId = root.element("Data").element("PatientId").toString();
|
|
|
;
|
|
|
//查询病人基本信息
|
|
|
patientInformation(cardNo, cardType, patientId);
|
|
|
} else if (trancode.equals(Constant.PUSHREPORT)) {
|
|
|
//检查检验报告
|
|
|
String reportType = root.element("Data").element("ReportType").toString();
|
|
|
String reportId = root.element("Data").element("ReportId").toString();
|
|
|
pushreport(reportType, reportId);
|
|
|
}
|
|
|
|
|
|
RPCResponseResult r = RPCResponseResult.success();
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
}
|
|
|
System.out.println(RPCRequestXml);
|
|
|
return "你也好";
|
|
|
}
|
|
|
|
|
|
|
|
|
//查询病人基本信息
|
|
|
private void patientInformation(String cardNo, String cardType, String patientId) throws Exception {
|
|
|
String data =
|
|
|
"<Req>" +
|
|
|
"<TransactionCode></TransactionCode>" +
|
|
|
"<Data>" +
|
|
|
"<CardType>" + cardType + "</CardType>" +
|
|
|
"<CardNo>" + cardNo + "</CardNo>" +
|
|
|
"<PatientId>" + patientId + "</PatientId>" +
|
|
|
"</Data>" +
|
|
|
"</Req>";
|
|
|
InvokeRequest r = new InvokeRequest(new Url(Config.ip, Integer.valueOf(Config.port)), Config.clazz, Config.method, String.class);
|
|
|
r.setSyncMode();//设置调用模式为同步模式
|
|
|
Object s = Rpc.invoke(r);
|
|
|
//解析xml
|
|
|
SAXReader saxReader = new SAXReader();
|
|
|
Document document = saxReader.read(s.toString());
|
|
|
Element root = document.getRootElement();
|
|
|
if ("10000".equals(root.element("RespCode"))) {
|
|
|
//xml轉json
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put(root.getName(), iterateElement(root));
|
|
|
String jsonString = obj.toString();
|
|
|
//調用接口存入mongo
|
|
|
|
|
|
//出發採集上傳
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//检查检验报告
|
|
|
private void pushreport(String reportType, String reportId) throws Exception {
|
|
|
String data =
|
|
|
"<Req>" +
|
|
|
"<TransactionCode></TransactionCode>" +
|
|
|
"<Data>" +
|
|
|
"<ReportId>" + reportId + "</ReportId>" +
|
|
|
"<ReportType>" + reportType + "</ReportType>" +
|
|
|
"</Data>" +
|
|
|
"</Req>";
|
|
|
InvokeRequest r = new InvokeRequest(new Url(Config.ip, Integer.valueOf(Config.port)), Config.clazz, Config.method, String.class);
|
|
|
r.setSyncMode();//设置调用模式为同步模式
|
|
|
Object s = Rpc.invoke(r);
|
|
|
//解析xml
|
|
|
SAXReader saxReader = new SAXReader();
|
|
|
Document document = saxReader.read(s.toString());
|
|
|
Element root = document.getRootElement();
|
|
|
if ("10000".equals(root.element("RespCode"))) {
|
|
|
//xml轉json
|
|
|
JSONObject obj = new JSONObject();
|
|
|
obj.put(root.getName(), iterateElement(root));
|
|
|
String jsonString = obj.toString();
|
|
|
//調用接口存入mongo
|
|
|
|
|
|
//出發採集上傳
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private static Map iterateElement(Element element) {
|
|
|
List jiedian = element.elements();
|
|
|
Element et = null;
|
|
|
Map obj = new HashMap();
|
|
|
List list = null;
|
|
|
for (int i = 0; i < jiedian.size(); i++) {
|
|
|
list = new LinkedList();
|
|
|
et = (Element) jiedian.get(i);
|
|
|
if (et.getTextTrim().equals("")) {
|
|
|
if (et.elements().size() == 0)
|
|
|
continue;
|
|
|
if (obj.containsKey(et.getName())) {
|
|
|
list = (List) obj.get(et.getName());
|
|
|
}
|
|
|
list.add(iterateElement(et));
|
|
|
obj.put(et.getName(), list);
|
|
|
} else {
|
|
|
if (obj.containsKey(et.getName())) {
|
|
|
list = (List) obj.get(et.getName());
|
|
|
}
|
|
|
list.add(et.getTextTrim());
|
|
|
obj.put(et.getName(), list);
|
|
|
}
|
|
|
}
|
|
|
return obj;
|
|
|
}
|
|
|
}
|