|
@@ -0,0 +1,81 @@
|
|
|
+package com.diagbot.web;
|
|
|
+
|
|
|
+import ca.uhn.hl7v2.model.Message;
|
|
|
+import ca.uhn.hl7v2.parser.PipeParser;
|
|
|
+import ca.uhn.hl7v2.util.Terser;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.diagbot.annotation.SysLogger;
|
|
|
+import com.diagbot.util.YWAnalysis;
|
|
|
+import com.diagbot.util.YWDateUtils;
|
|
|
+import com.diagbot.vo.hl7.Hl7VO;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/qc/hl7")
|
|
|
+@Api(value = "HL7协议-对接接口API", tags = { "HL7协议-对接接口API" })
|
|
|
+public class DataHl7Controller {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private YWAnalysis ywAnalysis;
|
|
|
+
|
|
|
+ @ApiOperation(value = "HL7协议-对接接口API")
|
|
|
+ @PostMapping("/Run")
|
|
|
+ @SysLogger("Run")
|
|
|
+ public String receviceHl7(@RequestParam String hisMessage){
|
|
|
+
|
|
|
+ Hl7VO hl7VO=new Hl7VO();
|
|
|
+ hl7VO=JSON.parseObject(hisMessage,Hl7VO.class);
|
|
|
+
|
|
|
+ try {
|
|
|
+ byte[] bytes = new byte[5120];
|
|
|
+ InputStream is = new ByteArrayInputStream(hl7VO.getMessage().getBytes("UTF-8"));
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ sb.append(new String(bytes, 0, is.read(bytes), "UTF-8"));
|
|
|
+
|
|
|
+ //sb= sb.replaceAll("\n", "\r").replace("\u000B", "").replace("\u001C", "").replace("\\\r","");
|
|
|
+ hisMessage.getBytes("UTF-8");
|
|
|
+ ywAnalysis.executeAnalysis(hisMessage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return getResponseMsg(hisMessage,e.getMessage()).toString();
|
|
|
+ }
|
|
|
+ return getResponseMsg(hisMessage,"成功").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private StringBuilder getResponseMsg(String receiveMsg,String msg) {
|
|
|
+ StringBuilder responseMsg = new StringBuilder();
|
|
|
+ try {
|
|
|
+ PipeParser pipeParser = PipeParser.getInstanceWithNoValidation();
|
|
|
+ Message message = pipeParser.parse(receiveMsg);
|
|
|
+ Terser terser = new Terser(message);
|
|
|
+ String sUid = UUID.randomUUID().toString();
|
|
|
+ responseMsg.append("\u000B").append("MSH|")
|
|
|
+ .append(terser.get("/." + "MSH-2") + "|")
|
|
|
+ .append(terser.get("/." + "MSH-3") + "|")
|
|
|
+ .append(terser.get("/." + "MSH-4") + "|")
|
|
|
+ .append(terser.get("/." + "MSH-5") + "|")
|
|
|
+ .append(terser.get("/." + "MSH-6") + "|")
|
|
|
+ .append(YWDateUtils.getCurrentTime() + "||")
|
|
|
+ .append("ACK|" + sUid + "|")
|
|
|
+ .append(terser.get("/." + "MSH-11") + "|")
|
|
|
+ .append(terser.get("/." + "MSH-12"))
|
|
|
+ .append("\r\n")
|
|
|
+ .append("MSA|AA|")
|
|
|
+ .append(terser.get("/." + "MSH-10")+ "|").append(msg)
|
|
|
+ .append("\u001C");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return responseMsg;
|
|
|
+ }
|
|
|
+}
|