依赖项:
1 2 3 4 5 6 7 8 9 10 11 |
<dependency> <groupId>ca.uhn.hapi</groupId> <artifactId>hapi-base</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>ca.uhn.hapi</groupId> <artifactId>hapi-structures-v24</artifactId> <version>2.3</version> </dependency> |
服务端:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
package org.longsheng.hl7.server; import ca.uhn.hl7v2.DefaultHapiContext; import ca.uhn.hl7v2.HapiContext; import ca.uhn.hl7v2.app.HL7Service; import ca.uhn.hl7v2.llp.MinLowerLayerProtocol; import ca.uhn.hl7v2.validation.ValidationContext; import ca.uhn.hl7v2.validation.impl.ValidationContextFactory; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.nio.charset.StandardCharsets; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @Component @Slf4j public class Hl7Server { /** * 核心线程数 */ private static final int CORE_POOL_SIZE = 50; /** * 最大线程数 */ private static final int MAX_POOL_SIZE = 200; /** * 设置缓冲队列大小 */ private static final int QUEUE_CAPACITY = 100; /** * 设置线程的最大空闲时间,超过了核心线程数之外的线程,在空闲时间到达之后会被销毁 */ private static final int KEEP_ALIVE_SECONDS = 60; /** * 接收端口 */ private static final int PORT_NUMBER = 30000; /** * 使用安全连接 */ public static final boolean USE_SECURE_CONNECTION = false; /** * HL7上下文 */ private static HapiContext context = new DefaultHapiContext(); @PostConstruct public static void start() { try { context.setValidationContext((ValidationContext) ValidationContextFactory.noValidation()); ThreadPoolExecutor hl7Executor = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, new ArrayBlockingQueue<>(QUEUE_CAPACITY)); hl7Executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); MinLowerLayerProtocol hl7MinLowerLayerProtocol = new MinLowerLayerProtocol(); hl7MinLowerLayerProtocol.setCharset(StandardCharsets.UTF_8); context.setLowerLayerProtocol(hl7MinLowerLayerProtocol); context.setExecutorService(hl7Executor); HL7Service hl7Service = context.newServer(PORT_NUMBER, USE_SECURE_CONNECTION); hl7Service.registerConnectionListener(new Hl7ConnectionListener()); hl7Service.registerApplication(new Hl7ReceivingApplication()); hl7Service.setExceptionHandler(new Hl7ExceptionHandler()); hl7Service.startAndWait(); log.info("HL7服务端===>启动成功。 端口:{}", PORT_NUMBER); } catch (Exception e) { log.error("HL7服务端===>启动失败。{} | {}", e.getMessage(), e.getStackTrace()); } } } |
连接监听:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
package org.longsheng.hl7.server; import ca.uhn.hl7v2.app.Connection; import ca.uhn.hl7v2.app.ConnectionListener; import lombok.extern.slf4j.Slf4j; @Slf4j public class Hl7ConnectionListener implements ConnectionListener { @Override public void connectionReceived(Connection c) { log.info("HL7服务端===>新连接:{}:{}", c.getRemoteAddress(), c.getRemotePort()); } @Override public void connectionDiscarded(Connection c) { log.info("HL7服务端===>断开连接:{}:{}", c.getRemoteAddress(), c.getRemotePort()); } } |
业务处理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
package org.longsheng.hl7.server; import ca.uhn.hl7v2.AcknowledgmentCode; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.model.Type; import ca.uhn.hl7v2.model.v24.datatype.CX; import ca.uhn.hl7v2.model.v24.datatype.SI; import ca.uhn.hl7v2.model.v24.datatype.XPN; import ca.uhn.hl7v2.model.v24.message.ACK; import ca.uhn.hl7v2.model.v24.message.DSR_Q03; import ca.uhn.hl7v2.model.v24.message.QCK_Q02; import ca.uhn.hl7v2.model.v24.message.QRY_Q02; import ca.uhn.hl7v2.model.v24.segment.MSH; import ca.uhn.hl7v2.model.v24.segment.OBR; import ca.uhn.hl7v2.model.v24.segment.OBX; import ca.uhn.hl7v2.model.v24.segment.PID; import ca.uhn.hl7v2.protocol.ReceivingApplication; import lombok.extern.slf4j.Slf4j; import org.longsheng.hl7.parser.Hl7StringConverter; import org.longsheng.hl7.parser.MY_ORU_R01; import org.longsheng.hl7.parser.MY_OUL_R21; import org.longsheng.hl7.parser.OrmO01; import java.io.IOException; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; @Slf4j public class Hl7ReceivingApplication implements ReceivingApplication { private String MSHId = ""; private String SetIdPid = "1"; private String SetIdObr = "1"; public Hl7ReceivingApplication() throws SQLException { } @Override public Message processMessage(Message message, Map map) throws HL7Exception { Message convert = Hl7StringConverter.convert(map.get("raw-message").toString()); OrmO01 ormO01 = (OrmO01) convert; PID pid = ormO01.getPID(); SI si = pid.getSetIDPID(); CX[] test = pid.getPid3_PatientIdentifierList(); CX cx = test[0]; String id = cx.getCx1_ID().getValue(); for (String name : message.getNames()) { message.getAll(name); } String messageID = map.get("/MSH-10").toString(); String messageType = message.getName(); String SendIP = map.get("SENDING_IP").toString(); String SendPort = map.get("SENDING_PORT").toString(); String rawMessage = map.get("raw-message").toString(); log.info("messageID: {}, messageType: {}, SendIP: {}, SendPort: {}", messageID, messageType, SendIP, SendPort); System.out.println("message ===> " + rawMessage.replaceAll("\r", "\r\n")); Message message1 = null; try { message1 = message.generateACK(); } catch (Exception e) { e.printStackTrace(); try { message1 = returnMSG(e.getMessage(), message); } catch (Exception ex) { ex.printStackTrace(); message1 = returnMSG(ex.getMessage(), message); } } finally { return message1; } } @Override public boolean canProcess(Message message) { return true; } private Message returnMSG(String exceptionMSG, Message message) { Message message1 = null; try { message1 = message.generateACK(AcknowledgmentCode.AE, new HL7Exception(exceptionMSG)); } catch (HL7Exception e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return message1; } private List<String> saveMessage(Message message) { if (message instanceof MY_ORU_R01) { // todo 不存在相同,已经重写 MY_ORU_R01 oru_r01 = (MY_ORU_R01) message; return dealORU_R01Message(oru_r01); } if (message instanceof MY_OUL_R21) { // todo 不存在相同,已经重写 MY_OUL_R21 MY_OUL_R21 = (MY_OUL_R21) message; return dealOUL_R21Message(MY_OUL_R21); } if (message instanceof QCK_Q02) { QCK_Q02 qck_q02 = (QCK_Q02) message; } // todo 存在相同的,不需要重写 // TODO: 2020-08-17 剩余的就不一个一个写了, if (message instanceof DSR_Q03) { DSR_Q03 dsr_q03 = (DSR_Q03) message; } // todo 未知数据字段 if (message instanceof QRY_Q02) { QRY_Q02 qry_q02 = (QRY_Q02) message; } // todo 未知数据字段 if (message instanceof ACK) { ACK ack = (ACK) message; } // todo 未知数据字段 return null; } private String getObxParams(OBX obx) throws HL7Exception { StringBuffer sqlColumnStr = new StringBuffer(); sqlColumnStr.append(" insert into T4("); StringBuffer sqlParamStr = new StringBuffer(); sqlParamStr.append(" values("); String[] names = obx.getNames(); for (int i = 1; i <= names.length; i++) { Type[] field = obx.getField(i); for (Type type : field) { String name = NamingRules(names[i - 1]); sqlColumnStr.append(name); sqlParamStr.append("'" + type.encode() + "'"); } if (i != names.length && field.length != 0) { sqlColumnStr.append(","); sqlParamStr.append(","); } } if (sqlColumnStr.lastIndexOf(",") == sqlColumnStr.length() - 1) { sqlColumnStr.deleteCharAt(sqlColumnStr.length() - 1); } if (sqlParamStr.lastIndexOf(",") == sqlParamStr.length() - 1) { sqlParamStr.deleteCharAt(sqlParamStr.length() - 1); } sqlColumnStr.append(")"); sqlParamStr.append(")"); return sqlColumnStr.append(sqlParamStr).toString(); } private List<String> dealOUL_R21Message(MY_OUL_R21 ro1) { List<String> sqlList = new ArrayList<String>(); try { System.out.println("deal 解析开始"); OBR obr = ro1.getOBR(); OBX obx = ro1.getOBX(); String[] namesArr = ro1.getNamesArr(); int obrNum = Hl7StringConverter.getConNum("OBR", namesArr); for (String name : namesArr) { if (name.contains("MSH")) { sqlList.add(getMSHParams(ro1.getMSH(name))); } else if (name.contains("PID")) { sqlList.add(getPIDParams(ro1.getPID(name))); } else if (name.contains("PV1")) { } else if (name.contains("OBR")) { sqlList.add(getOBRParams(ro1.getOBR(name))); } else if (name.contains("OBX")) { List<OBX> obxList = ro1.getOBXList(name); for (OBX obx1 : obxList) { sqlList.add(getOBXParams(obx1)); } } } } catch (Exception e) { e.printStackTrace(); } return sqlList; } private List<String> dealORU_R01Message(MY_ORU_R01 ro1) { List<String> sqlList = new ArrayList<String>(); try { System.out.println("deal 解析开始"); OBR obr = ro1.getOBR(); OBX obx = ro1.getOBX(); String[] namesArr = ro1.getNamesArr(); int obrNum = Hl7StringConverter.getConNum("OBR", namesArr); for (String name : namesArr) { if (name.contains("MSH")) { sqlList.add(getMSHParams(ro1.getMSH(name))); } else if (name.contains("PID")) { sqlList.add(getPIDParams(ro1.getPID(name))); } else if (name.contains("PV1")) { } else if (name.contains("OBR")) { sqlList.add(getOBRParams(ro1.getOBR(name))); } else if (name.contains("OBX")) { List<OBX> obxList = ro1.getOBXList(name); for (OBX obx1 : obxList) { sqlList.add(getOBXParams(obx1)); } } } } catch (Exception e) { e.printStackTrace(); } return sqlList; } private String getPIDParams(PID pid) throws HL7Exception { StringBuffer sqlColumnStr = new StringBuffer(); sqlColumnStr.append(" insert into hl7_message_pid(MessageControlID,"); StringBuffer sqlParamStr = new StringBuffer(); sqlParamStr.append(" values('" + MSHId + "',"); String[] names = pid.getNames(); for (int i = 1; i <= names.length; i++) { Type[] field = pid.getField(i); if (i == 1 && field.length != 0) { SetIdPid = field[0].encode(); } for (Type type : field) { String name = NamingRules(names[i - 1]); sqlColumnStr.append(name); sqlParamStr.append("'" + type.encode() + "'"); } if (i != names.length && field.length != 0) { sqlColumnStr.append(","); sqlParamStr.append(","); } } if (sqlColumnStr.lastIndexOf(",") == sqlColumnStr.length() - 1) { sqlColumnStr.deleteCharAt(sqlColumnStr.length() - 1); } if (sqlParamStr.lastIndexOf(",") == sqlParamStr.length() - 1) { sqlParamStr.deleteCharAt(sqlParamStr.length() - 1); } sqlColumnStr.append(")"); sqlParamStr.append(")"); return sqlColumnStr.append(sqlParamStr).toString(); } private String getMSHParams(MSH msh) throws HL7Exception { MSHId = msh.getMsh10_MessageControlID().toString(); StringBuffer sqlColumnStr = new StringBuffer(); sqlColumnStr.append(" insert into hl7_message_msh("); StringBuffer sqlParamStr = new StringBuffer(); sqlParamStr.append(" values("); String[] names = msh.getNames(); for (int i = 1; i <= names.length; i++) { Type[] field = msh.getField(i); for (Type type : field) { String name = NamingRules(names[i - 1]); sqlColumnStr.append(name); sqlParamStr.append("'" + type.encode().replaceAll("\\\\", "") + "'"); } if (i != names.length && field.length != 0) { sqlColumnStr.append(","); sqlParamStr.append(","); } } if (sqlColumnStr.lastIndexOf(",") == sqlColumnStr.length() - 1) { sqlColumnStr.deleteCharAt(sqlColumnStr.length() - 1); } if (sqlParamStr.lastIndexOf(",") == sqlParamStr.length() - 1) { sqlParamStr.deleteCharAt(sqlParamStr.length() - 1); } sqlColumnStr.append(")"); sqlParamStr.append(")"); return sqlColumnStr.append(sqlParamStr).toString(); } private String getOBRParams(OBR obr) throws HL7Exception { StringBuffer sqlColumnStr = new StringBuffer(); sqlColumnStr.append(" insert into hl7_message_obr(MessageControlID,SetIDPID,"); StringBuffer sqlParamStr = new StringBuffer(); sqlParamStr.append(" values('" + MSHId + "','" + SetIdPid + "',"); String[] names = obr.getNames(); for (int i = 1; i <= names.length; i++) { Type[] field = obr.getField(i); for (Type type : field) { if (i == 1 && field.length != 0) SetIdObr = field[0].encode(); String name = NamingRules(names[i - 1]); sqlColumnStr.append(name); sqlParamStr.append("'" + type.encode().replaceAll("\\\\", "") + "'"); } if (i != names.length && field.length != 0) { sqlColumnStr.append(","); sqlParamStr.append(","); } } if (sqlColumnStr.lastIndexOf(",") == sqlColumnStr.length() - 1){ sqlColumnStr.deleteCharAt(sqlColumnStr.length() - 1);} if (sqlParamStr.lastIndexOf(",") == sqlParamStr.length() - 1){ sqlParamStr.deleteCharAt(sqlParamStr.length() - 1);} sqlColumnStr.append(")"); sqlParamStr.append(")"); return sqlColumnStr.append(sqlParamStr).toString(); } private String getOBXParams(OBX obx) throws HL7Exception { StringBuffer sqlColumnStr = new StringBuffer(); sqlColumnStr.append(" insert into hl7_message_obx(MessageControlID,SetIDPID,SetIDOBR,"); StringBuffer sqlParamStr = new StringBuffer(); sqlParamStr.append(" values('" + MSHId + "','" + SetIdPid + "','" + SetIdObr + "',"); String[] names = obx.getNames(); for (int i = 1; i <= names.length; i++) { Type[] field = obx.getField(i); for (Type type : field) { String name = NamingRules(names[i - 1]); // System.out.println(name); sqlColumnStr.append(name); sqlParamStr.append("'" + type.encode().replaceAll("\\\\", "") + "'"); } if (i != names.length && field.length != 0) { sqlColumnStr.append(","); sqlParamStr.append(","); } } if (sqlColumnStr.lastIndexOf(",") == sqlColumnStr.length() - 1){ sqlColumnStr.deleteCharAt(sqlColumnStr.length() - 1);} if (sqlParamStr.lastIndexOf(",") == sqlParamStr.length() - 1){ sqlParamStr.deleteCharAt(sqlParamStr.length() - 1);} sqlColumnStr.append(")"); sqlParamStr.append(")"); return sqlColumnStr.append(sqlParamStr).toString(); } //简单更改命名规则 private String NamingRules(String name) { String str = name.replaceAll(" ", "") .replaceAll("-", "").replaceAll("/", ""). replaceAll("'s", "").replaceAll("#", ""). replaceAll("\\+", ""); return str; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
package org.longsheng.hl7.parser; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.model.v24.message.ACK; import ca.uhn.hl7v2.model.v24.message.DSR_Q03; import ca.uhn.hl7v2.model.v24.message.QCK_Q02; import ca.uhn.hl7v2.model.v24.message.QRY_Q02; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Hl7StringConverter { public static Message convert(String hl7Str) throws HL7Exception { QCK_Q02 msg = new QCK_Q02(); try { msg.parse(hl7Str); String type = ""; type = match(msg.getMSH().getMessageType() + ""); type = type == "" ? "QCK^Q02" : type; switch (type) { // 申请单新增 case "ORM^O01": OrmO01 ormO01 = new OrmO01(); ormO01.parse(hl7Str); return ormO01; case "OUL^R21": MY_OUL_R21 oul_r21 = new MY_OUL_R21(); oul_r21.parse(hl7Str); return oul_r21; case "QCK^Q02": QCK_Q02 qck_q02 = new QCK_Q02(); qck_q02.parse(hl7Str); return qck_q02; case "ORU^R01": MY_ORU_R01 oru_r01 = new MY_ORU_R01(); oru_r01.parse(hl7Str); return oru_r01; case "DSR^Q03": DSR_Q03 dsr_q03 = new DSR_Q03(); dsr_q03.parse(hl7Str); return dsr_q03; case "QRY^Q02": QRY_Q02 qry_q02 = new QRY_Q02(); qry_q02.parse(hl7Str); return qry_q02; case "ACK^Q03": ACK ack = new ACK(); ack.parse(hl7Str); return ack; } } catch (HL7Exception e) { e.printStackTrace(); } throw new HL7Exception("未知错误,Message Type 为正确设置"); } private static String match(String string) { String regex = "\\[(.*?)]"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(string); StringBuffer buffer = new StringBuffer(); while (matcher.find()) { buffer.append(matcher.group(1)); } return buffer.toString(); } //从名称数组中查找包含元素的名称个数 public static int getConNum(String str, String[] names) { int flag = 0; for (String name : names) { if (name.contains(str)) { flag++; } } return flag; } //返回传入消息段字符串的索引 public static int getConIndex(String str, String[] names) { for (int i = 0; i < names.length; i++) { if (names[i].equals(str)) { return i; } } return -1; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
package org.longsheng.hl7.parser; import ca.uhn.hl7v2.HL7Exception; import ca.uhn.hl7v2.model.AbstractMessage; import ca.uhn.hl7v2.model.v24.segment.*; import ca.uhn.hl7v2.parser.DefaultModelClassFactory; import ca.uhn.hl7v2.parser.ModelClassFactory; import ca.uhn.hl7v2.parser.PipeParser; /** * 申请单新增 */ public class OrmO01 extends AbstractMessage { public OrmO01() { this(new DefaultModelClassFactory()); } public OrmO01(ModelClassFactory theFactory) { super(theFactory); init(theFactory); setParser(new PipeParser()); } private void init(ModelClassFactory factory) { try { this.add(MSH.class, true, false); this.add(PID.class, true, true); this.add(PV1.class, true, true); this.add(ORC.class, true, true); this.add(OBR.class, false, true); this.add(FT1.class, false, true); } catch (HL7Exception e) { log.error("init异常:", e); } } public String getVersion() { return "2.4"; } public MSH getMSH() { return getTyped("MSH", MSH.class); } public PID getPID() { return getTyped("PID", PID.class); } public PV1 getPV1() { return getTyped("PV1", PV1.class); } public ORC getORC() { return getTyped("ORC", ORC.class); } public OBR getOBR() { return getTyped("OBR", OBR.class); } public FT1 getFT1() { return getTyped("FT1", FT1.class); } } |
异常处理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
package org.longsheng.hl7.server; import ca.uhn.hl7v2.protocol.ReceivingApplicationExceptionHandler; import lombok.extern.slf4j.Slf4j; import java.util.Map; @Slf4j public class Hl7ExceptionHandler implements ReceivingApplicationExceptionHandler { @Override public String processException(String incomingMessage, Map<String, Object> incomingMetadata, String outgoingMessage, Exception e) { log.error("HL7服务端===>异常:{}", e); return "接收消息异常"; } } |
客户端:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
package org.longsheng.hl7.client; import ca.uhn.hl7v2.DefaultHapiContext; import ca.uhn.hl7v2.HapiContext; import ca.uhn.hl7v2.app.Connection; import ca.uhn.hl7v2.app.Initiator; import ca.uhn.hl7v2.llp.MinLowerLayerProtocol; import ca.uhn.hl7v2.model.Message; import ca.uhn.hl7v2.parser.PipeParser; import ca.uhn.hl7v2.validation.ValidationContext; import ca.uhn.hl7v2.validation.impl.ValidationContextFactory; import java.nio.charset.StandardCharsets; public class Hl7Client { private static HapiContext context = new DefaultHapiContext(); public static void main(String[] args) throws Exception { try { context.setValidationContext((ValidationContext) ValidationContextFactory.noValidation()); MinLowerLayerProtocol minLowerLayerProtocol = new MinLowerLayerProtocol(); minLowerLayerProtocol.setCharset(StandardCharsets.UTF_8); context.setLowerLayerProtocol(minLowerLayerProtocol); Connection connection = context.newClient("localhost", 30000, false); PipeParser pipeParser = context.getPipeParser(); Initiator initiator = connection.getInitiator(); // String msg = "MSH|^~\\&|LIS||HTCIS||20201207101411||OUL^R21|U6680658|P|2.4|||AL|AL\r" // + "PID||0001042069|0001042069||谢继韬|||M\r" // + "PV1||O|^^^0305^肾内科门诊||||||001287||||||||||5407031|||||||||||||||||||||||||20201207093847\r" // + "OBR|1|16032220|4237929723|F00000092055^电解质七项^Ordinary||20201207084203|||||||||2&血清|||肾内科门诊|0305|4861273||20201207101340||||||||||0179&肖晓蔚|0178&郭伟权\r" // + "NTE|1\r" // + "OBX|1|NM|12081^钾(K)||3.98|mmol/L|3.50-5.30||||F|||20201207093847\r" // + "OBX|2|NM|12071^钠(Na)||143.00|mmol/L|137-147||||F|||20201207093847\r" // + "OBX|3|NM|12063^氯(Cl)||104|mmol/L|99-110||||F|||20201207093847\r" // + "OBX|4|NM|12062^钙(Ca)||2.50|mmol/L|2.11-2.52||||F|||20201207093847\r" // + "OBX|5|NM|12057^磷(P)||0.87|mmol/L|0.85-1.51||||F|||20201207093847\r" // + "OBX|6|NM|12054^镁(Mg)||0.76|mmol/L|0.75-1.02||||F|||20201207093847\r" // + "OBX|7|NM|12053^总二氧化碳(CO2)||24.00|mmoll/L|21-31||||F|||20201207093847\r"; // String msg = "MSH|^~\\&|HIS|01|RIS|01|20240420164543+0800||ORM^O01|nw240420084543800038|P|2.4|||NE|AL||utf-8\r" + // "PID|1|00703661|00703661~00703661||张亦斐^ZHANG YI FEI^9岁||20140702000000+0800|男||^|关公东街馥园小区^^^^||13453974285^^^^^^^^|^^^^^^^^|||||140823201407020135|||^\r" + // "PV1|1|O|儿科门诊^^^^^^^||||^|^|||||||||^|自费病员|20240420000175|自费||||||||[是否发热门诊]否||||||||||||||||2024-04-20 00:00:00|||||\r" + // "ORC|NW|2024042000076691^HIS|^US^200801^|103^0^0||0|^^^^^1||20240420164532+0800|||00211001^裴竹英|儿科门诊|||^否|10450107^儿科门诊^01|^\r" + // "OBR|1|2024042000076691|^|2312311136351749^双肾、肾上腺彩超^泌尿系彩超^^US|||||||||0|||||||01|200801||||||||||6^泌尿系统\r" + // "DG1|1||| [现病史]患儿近2月无诱因有间断低声,来诊 [既往史]无特殊 [个人史]G1P1,足月顺产,出生体重,混合喂养 [家族史]否认家族遗传病史,父亲身高170cm,母亲身高158cm,遗传身高169cm [过敏史]无\r" + // "DG1|2|||青春期发育状态\r" + // "DG1|3|||-\r" + // "DG1|4|||身高145cm(0~+1SD),体重38kg,BMI,呼吸平,精神可,咽红,双肺呼吸音粗,未闻及水泡音,心腹无异,神经系统检查未见异常。睾丸6-8ml,\r" + // "DG1|5|||[主诉]变声2月来诊\r"; String msg = "MSH|^~\\&|HIS_OutPatient|WinningSoft|RIS|WinningSoft|20190912161834||ORM^O01|8E51A455-C3BC-461B-B907-A3DD44B802FD|P|2.4|||||CHN\r" + "PID|1||10544231^^^&PATID|||||U||||||||S\r" + "PV1|1|O|||||||||||||||||1428814|||||||||||||||||||||||||||||||10544231\r" + "ORC|NW|1672006||4319016|0|||||^^^^^^^0||0309^^张月|||||||^^^^^^^^^P~^^^^^^^^^D\r" + "OBR||||145^子宫附件(经阴道)^^0|0|20190912161728|||1^&&&次||||月经不规则|||||1029|妇科门诊|3003|超声科||&60.0000^&&&1||||||||||||||||普通超声^^0^\\E\\2019\\E\\09MZ191551700.html^年龄#34 岁$$性别#女$$检查类型#US$$检查部位:#妇产科彩超$$患者姓名#曹芳$$申请单名称#普通超声$$检查目的#明确诊断$$项目预约标识#1$$检查部位 1#计算机图文报告$$检查项目#子宫附件(经阴道)();$$执行科室代码#3003$$护送方式#无需护送$$申请单序号#1672006$$科室#妇科门诊$$病历号#190907878$$条形码#B191551700$$执行科室#超声科$$诊断#月经不规则$$检查部位 0#子宫附件(经阴道)()$$临床信息#主诉内容停经 36 天,少量出血 4 天现病史平素月经规则,,末次月经 2019.8.6。少量出血 4 天。周期 27 天 0-0-1-0。$$项目预约标识#0$$^0||||||4319016^^^sf12843494|^588682^^1\r" + "FT1||sf0"; Message parse = pipeParser.parse(msg); Message message = initiator.sendAndReceive(parse); System.out.println(message.encode()); } catch (Exception e) { e.printStackTrace(); } } } |