一、前言
HL7协议相信医疗行业的IT人员都不陌生,笔者由于接触时间比较短,乍一听“协议”还是比较懵,不自觉就把它和“HTTP”、"SOAP”之类的网络协议挂上关联,可事实上这个HL7只是一种数据格式,传输方式也可以使用最简单的Socket。
二、正文
本文中用到的代码都做了部分敏感字删减,使用过程如遇到编译错误合理调整即可。
笔者调试中用到的工具及问题记录都会放到文末供大家参考。
1、环境配置
引入Maven依赖,笔者使用的hl7-2.6版本,所以只引入v26即可
<dependency>
<groupId>ca.uhn.hapi</groupId>
<artifactId>hapi-base</artifactId>
<version>2.3</version> <!-- 请根据实际情况选择最新版本 -->
</dependency>
<dependency>
<groupId>ca.uhn.hapi</groupId>
<artifactId>hapi-structures-v26</artifactId>
<version>2.3</version> <!-- 请根据实际情况选择最新版本 -->
</dependency>
增加配置文件作为hl7协议单独配置
#是否开启监听 0-关闭、1-开启
hl7socket.server.flag=0
#端口号
hl7socket.server.port=30000
2、数据接收:HL7Monitor
使用JDK自带注解@PostConstrust作为初始化启动监听,直接使用依赖中封装的API即可,需要注意的是,可以将一些数据校验关闭,否则在接受过程中直接阻断消息接收。
启动监听服务仅需要端口号即可,另外要将接收数据后的业务处理类对象作为参数传入registerApplication方法。
import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.app.HL7Service;
import ca.uhn.hl7v2.app.ServerConfiguration;
import ca.uhn.hl7v2.llp.MinLowerLayerProtocol;
import ca.uhn.hl7v2.parser.ParserConfiguration;
import ca.uhn.hl7v2.parser.PipeParser;
import ca.uhn.hl7v2.validation.ValidationContext;
import ca.uhn.hl7v2.validation.impl.DefaultValidation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* 使用HL7监听器,监控目标端口收到的协议
*/
@Component
@Slf4j(topic = "hl7message")
public class HL7Monitor {
@Autowired
private HL7Properties mHL7Properties;
@Autowired
private HL7Business mHL7Business;
private static HapiContext context = new DefaultHapiContext();
@PostConstruct
public void startWatchHL7(){
if (!"1".equals(mHL7Properties.getFlag())) {
return;
}
try {
ThreadPoolExecutor executor = new ThreadPoolExecutor(
10, 3100,
30, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(100));
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
MinLowerLayerProtocol mllp = new MinLowerLayerProtocol();
mllp.setCharset("UTF-8");
context.setLowerLayerProtocol(mllp);
context.setExecutorService(executor);
//设置hl7不校验字段值
ParserConfiguration tParserConfiguration = new ParserConfiguration();
tParserConfiguration.setValidating(false);
context.setParserConfiguration(tParserConfiguration);
//创建监听服务
boolean useSecureConnection = false;
HL7Service ourHl7Server = context.newServer(mHL7Properties.getPort(), useSecureConnection);
ourHl7Server.registerApplication(mHL7Business);
ourHl7Server.startAndWait();
} catch (Exception e) {
log.info("hl7协议监听失败:" + e.getMessage());
e.printStackTrace();
}
}
}
3、数据解析:HL7Business
数据解析和数据处理在一起,笔者这边的业务是将数据接收到后解析出来,直接使用websocket推送给前端,前端会将接收到的数据echart渲染到页面,例如:各个波形图、检测数值等都会实时展示。
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.model.ExtraComponents;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.Type;
import ca.uhn.hl7v2.model.Varies;
import ca.uhn.hl7v2.model.v26.datatype.CX;
import ca.uhn.hl7v2.model.v26.datatype.NA;
import ca.uhn.hl7v2.model.v26.datatype.XPN;
import ca.uhn.hl7v2.model.v26.group.ORU_R01_OBSERVATION;
import ca.uhn.hl7v2.model.v26.group.ORU_R01_ORDER_OBSERVATION;
import ca.uhn.hl7v2.model.v26.group.ORU_R01_PATIENT;
import ca.uhn.hl7v2.model.v26.group.ORU_R01_PATIENT_RESULT;
import ca.uhn.hl7v2.model.v26.segment.MSH;
import ca.uhn.hl7v2.model.v26.segment.OBR;
import ca.uhn.hl7v2.model.v26.segment.OBX;
import ca.uhn.hl7v2.model.v26.segment.PV1;
import ca.uhn.hl7v2.protocol.ReceivingApplication;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 接收到hl7消息,业务处理逻辑类
*/
@Component
@Slf4j(topic = "hl7message")
public class HL7Business implements ReceivingApplication {
@Autowired
private OutCarDao mOutCarDao;
@Autowired
private LifeSignService lifeSignService;
private Gson mGson = new GsonBuilder().serializeNulls().create();
public static List<JianHuYiListView> mJianHuYiListView = new ArrayList<>();
public static Map<String, Boolean> mLifeSignDoneMap = new HashMap<>();//标识监护仪体征信息是否采集过,true为采集过
@Override
public Message processMessage(Message theMessage, Map theMetadata) {
Message response = null;
try {
//判断进入何种解析模式
this.analysisModule_1(theMessage);
response = theMessage.generateACK();
} catch (Exception e) {
log.info("hl7协议数据解析失败!" + e.getMessage());
log.error(e.getMessage());
e.printStackTrace();
}
return response;
}
/**
* 利用messge转对象模式解析协议
* MSH|^~\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231024152606000||ORU^R01^ORU_R01|411|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO
* PID|||^^^Hospital^PI||^^^^^^L
* PV1||I
* OBR|1||411^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|CONTINUOUS WAVEFORM|||20231024152605710|20231024152606710
* OBX|1|NA|150452^MDC_PULS_OXIM_PLETH^MDC|1.3.1.150452|94^94^92^83^78^72^67^63^60^57^56^54^53^52^51^49^48^46^44^42^40^38^36^35^33^31^27^27^24^21^18^16^15^16^20^27^37^49^61^72^80^86^89^89^86^83^78^73^68^64^60^55^54^54^54^54^54^53^52^50|262656^MDC_DIM_DIMLESS^MDC
* OBX|2|NM|0^MDC_ATTR_SAMP_RATE^MDC|1.3.1.150452.1|60|264608^MDC_DIM_PER_SEC^MDC
* OBX|3|NM|2327^MDC_ATTR_NU_MSMT_RES^MDC|1.3.1.150452.2|1.000000|262656^MDC_DIM_DIMLESS^MDC
* OBX|4|NM|262196^MDC_EVT_INOP^MDC|1.3.1.150452.3|32767
*/
public void analysisModule_1(Message hapiMsg) throws HL7Exception, ParseException {
log.info(hapiMsg.toString());
JianHuYiView tJianHuYiView = new JianHuYiView();
//1、MSH
MSH msh = (MSH) hapiMsg.get("MSH");
String tSeries_no = msh.getMsh3_SendingApplication().getHd2_UniversalID().getValue();
if (StringUtils.isBlank(tSeries_no)) {
log.error("设备号获取为空!");
return;
}
String value7 = msh.getMsh7_DateTimeOfMessage().getValue();
if (StringUtils.isNotBlank(value7)) {
String tTime = (value7.length() > 17) ? value7.substring(0, 17) : value7;
Date tDate = new SimpleDateFormat("yyyyMMddHHmmssSSS").parse(tTime);
tJianHuYiView.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tDate));
}
//2、PATIENT_RESULT
ORU_R01_PATIENT_RESULT ORU_R01_PATIENT_RESULT = (ORU_R01_PATIENT_RESULT) hapiMsg.get("PATIENT_RESULT");
//2.1、PATIENT_RESULT——>PATIENT
ORU_R01_PATIENT patientResult = ORU_R01_PATIENT_RESULT.getPATIENT();
CX[] pid3PatientIdentifierList = patientResult.getPID().getPid3_PatientIdentifierList();
XPN[] pid5PatientName = patientResult.getPID().getPid5_PatientName();
PV1 pv1 = patientResult.getVISIT().getPV1();
//2.2、PATIENT_RESULT——>ORDER_OBSERVATION
ORU_R01_ORDER_OBSERVATION orderObservation = (ORU_R01_ORDER_OBSERVATION) ORU_R01_PATIENT_RESULT.get("ORDER_OBSERVATION");
//2.2.1、PATIENT_RESULT——>ORDER_OBSERVATION——>OBR
OBR obr = orderObservation.getOBR();
//2.2.2、PATIENT_RESULT——>PATIENT——>ORDER_OBSERVATION——>OBSERVATIONS
List<ORU_R01_OBSERVATION> observationAll = orderObservation.getOBSERVATIONAll();
List<Double> tMDC_PULS_OXIM_PLETHs = new ArrayList<>();
List<Double> tMDC_ECG_ELEC_POTL_IIs = new ArrayList<>();
List<Double> tMDC_IMPED_TTHORs = new ArrayList<>();
String tWaveType = "";
for (ORU_R01_OBSERVATION tORU_R01_OBSERVATION : observationAll) {
OBX obx = tORU_R01_OBSERVATION.getOBX();
String tType = obx.getObx3_ObservationIdentifier().getText().getValue();
if ("MDC_PULS_OXIM_PLETH".equals(tType)) {
tWaveType = "PLETH";
Varies[] obx5ObservationValue = obx.getObx5_ObservationValue();
NA data = (NA) obx5ObservationValue[0].getData();
//获取前四个
Type[] components = data.getComponents();
for (Type s : components) {
if (s != null) tMDC_PULS_OXIM_PLETHs.add(Double.parseDouble(s.toString()));
}
//获取剩余部分
ExtraComponents extraComponents = data.getExtraComponents();
int num = extraComponents.numComponents();
for (int i = 0; i < num; i++) {
tMDC_PULS_OXIM_PLETHs.add(Double.parseDouble(String.valueOf(extraComponents.getComponent(i).getData())));
}
}
if ("MDC_ECG_ELEC_POTL_II".equals(tType)) {
tWaveType = "ECG";
Varies[] obx5ObservationValue = obx.getObx5_ObservationValue();
NA data = (NA) obx5ObservationValue[0].getData();
//获取前四个
Type[] components = data.getComponents();
for (Type s : components) {
if (s != null) tMDC_ECG_ELEC_POTL_IIs.add(Double.parseDouble(s.toString()));
}
//获取剩余部分
ExtraComponents extraComponents = data.getExtraComponents();
int num = extraComponents.numComponents();
for (int i = 0; i < num; i++) {
tMDC_ECG_ELEC_POTL_IIs.add(Double.parseDouble(String.valueOf(extraComponents.getComponent(i).getData())));
}
}
if ("MDC_IMPED_TTHOR".equals(tType)) {
tWaveType = "RESP";
Varies[] obx5ObservationValue = obx.getObx5_ObservationValue();
NA data = (NA) obx5ObservationValue[0].getData();
//获取前四个
Type[] components = data.getComponents();
for (Type s : components) {
if (s != null) tMDC_IMPED_TTHORs.add(Double.parseDouble(s.toString()));
}
//获取剩余部分
ExtraComponents extraComponents = data.getExtraComponents();
int num = extraComponents.numComponents();
for (int i = 0; i < num; i++) {
tMDC_IMPED_TTHORs.add(Double.parseDouble(String.valueOf(extraComponents.getComponent(i).getData())));
}
}
if ("MDC_PULS_OXIM_SAT_O2".equals(tType)) {
Varies[] obx5ObservationValue = obx.getObx5_ObservationValue();
String dataV = obx5ObservationValue[0].getData().toString();
tJianHuYiView.setSpo2_value(dataV);
}
if ("MDC_PULS_OXIM_PULS_RATE".equals(tType)) {
Varies[] obx5ObservationValue = obx.getObx5_ObservationValue();
String dataV = obx5ObservationValue[0].getData().toString();
tJianHuYiView.setPr_value(dataV);
}
if ("MDC_TTHOR_RESP_RATE".equals(tType)) {
Varies[] obx5ObservationValue = obx.getObx5_ObservationValue();
String dataV = obx5ObservationValue[0].getData().toString();
tJianHuYiView.setResp_value(dataV);
}
if ("MDC_ECG_HEART_RATE".equals(tType)) {
Varies[] obx5ObservationValue = obx.getObx5_ObservationValue();
String dataV = obx5ObservationValue[0].getData().toString();
tJianHuYiView.setEcg_value(dataV);
}
if ("MDC_PRESS_CUFF_SYS".equals(tType)) {
Varies[] obx5ObservationValue = obx.getObx5_ObservationValue();
String dataV = obx5ObservationValue[0].getData().toString();
tJianHuYiView.setSbp_value(dataV);
}
if ("MDC_PRESS_CUFF_MEAN".equals(tType)) {
Varies[] obx5ObservationValue = obx.getObx5_ObservationValue();
String dataV = obx5ObservationValue[0].getData().toString();
tJianHuYiView.setMean_value(dataV);
}
if ("MDC_PRESS_CUFF_DIA".equals(tType)) {
Varies[] obx5ObservationValue = obx.getObx5_ObservationValue();
String dataV = obx5ObservationValue[0].getData().toString();
tJianHuYiView.setDbp_value(dataV);
}
}
tJianHuYiView.setMdc_puls_oxim_pleth(tMDC_PULS_OXIM_PLETHs);
tJianHuYiView.setMdc_ecg_elec_potl_ii(tMDC_ECG_ELEC_POTL_IIs);
tJianHuYiView.setMdc_imped_tthor(tMDC_IMPED_TTHORs);
this.pushMessage(tJianHuYiView, tSeries_no, tWaveType);
}
/**
* 推送消息逻辑处理
* @param tJianHuYiView
* @param tSeries_no
*/
private void pushMessage(JianHuYiView tJianHuYiView, String tSeries_no, String tWaveType) {
//判断全局对象是否包含本次监测设备信息
boolean tFlag = false;
for (JianHuYiListView tJianhuyilist : mJianHuYiListView) {
tJianhuyilist.setA(StringUtils.isBlank(tWaveType) ? "VALUE" : tWaveType);
if (tSeries_no.equals(tJianhuyilist.getSeries_no())) {
//保留上次数值,防止频闪
JianHuYiView tOldView = tJianhuyilist.getJianhuyi_info();
if (StringUtils.isBlank(tJianHuYiView.getPr_value())) {
tJianHuYiView.setPr_value(tOldView.getPr_value());
}
if (StringUtils.isBlank(tJianHuYiView.getSpo2_value())) {
tJianHuYiView.setSpo2_value(tOldView.getSpo2_value());
}
if (StringUtils.isBlank(tJianHuYiView.getSbp_value())) {
tJianHuYiView.setSbp_value(tOldView.getSbp_value());
}
if (StringUtils.isBlank(tJianHuYiView.getDbp_value())) {
tJianHuYiView.setDbp_value(tOldView.getDbp_value());
}
if (StringUtils.isBlank(tJianHuYiView.getMean_value())) {
tJianHuYiView.setMean_value(tOldView.getMean_value());
}
if (StringUtils.isBlank(tJianHuYiView.getResp_value())) {
tJianHuYiView.setResp_value(tOldView.getResp_value());
}
if (StringUtils.isBlank(tJianHuYiView.getEcg_value())) {
tJianHuYiView.setEcg_value(tOldView.getEcg_value());
}
tJianhuyilist.setJianhuyi_info(tJianHuYiView);
tFlag = true;
}
}
//判断上述循环是否拿到了设备信息,若没有则加载进去
if (!tFlag) {
JianHuYiListView tJianHuYiListView = new JianHuYiListView();
OutCarVO tOutCarVO = mOutCarDao.getOutCarVoByMonitorNo(tSeries_no);
if (tOutCarVO != null) {
tJianHuYiListView.setCar_code(tOutCarVO.getCar_code());
tJianHuYiListView.setSeries_no(tSeries_no);
tJianHuYiListView.setJianhuyi_info(tJianHuYiView);
mLifeSignDoneMap.put(tSeries_no, false);
//新增前判断当前集合是否有重复车牌
boolean subFlag = false;
for (JianHuYiListView tJianhuyilist : mJianHuYiListView) {
if (tOutCarVO.getCar_code().equals(tJianhuyilist.getCar_code())) {
BeanUtils.copyProperties(tJianHuYiListView, tJianhuyilist);
subFlag = true;
break;
}
}
//判断当前集合没有重复车牌,则添加到最后
if(!subFlag) mJianHuYiListView.add(tJianHuYiListView);
}
}
//获取监护仪信息更新到体征表
this.updateLifeSign(tJianHuYiView, tSeries_no);
//推送监护仪信息
HL7WebSocket.broadcast(mGson.toJson(mJianHuYiListView));
}
}
与前端交互的websocket逻辑如下:
package com.medex.mdap.hl7.ws;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.*;
@Controller
@ServerEndpoint(value = "/websocket/hl7message")
@Slf4j
public class HL7WebSocket {
private Gson mGson = new GsonBuilder().serializeNulls().create();
private static Set<Session> sessions = new HashSet<>();
@OnOpen
public void open(Session session) {
HL7WebSocket.sessions.add(session);
log.info("有新连接加入");
}
@OnMessage
public void receive(Session session, String msg) {
try {
log.info("收到新的消息请求:" + msg);
String[] split = msg.split(",");
//遍历当前推送的车辆信息,将缺失的车辆补充进来
for (String tCardCode : split) {
boolean tFlag = false;
for (JianHuYiListView tJianHuYiListView : HL7Business.mJianHuYiListView) {
if (tCardCode.equals(tJianHuYiListView.getCar_code())) {
tFlag = true;
break;
}
}
if (!tFlag) {
JianHuYiListView ttJianHuYiListView = new JianHuYiListView();
ttJianHuYiListView.init(tCardCode);
HL7Business.mJianHuYiListView.add(ttJianHuYiListView);
}
}
//遍历当前推送信息,将多余的车辆移除
Iterator<JianHuYiListView> iterator = HL7Business.mJianHuYiListView.iterator();
while(iterator.hasNext()){
JianHuYiListView tJianHuYiListView = iterator.next();
boolean tFlag = false;
for (String tCardCode : split) {
if (tCardCode.equals(tJianHuYiListView.getCar_code())) {
tFlag = true;
break;
}
}
if (!tFlag) {
iterator.remove();
}
}
this.sortCarcode(HL7Business.mJianHuYiListView, Arrays.asList(split));
this.broadcast(session, mGson.toJson(HL7Business.mJianHuYiListView));
} catch (Exception e) {
e.printStackTrace();
log.info("receive异常:" + e.getMessage());
}
}
public void broadcast(Session session, String msg) {
try {
if (session != null) {
session.getBasicRemote().sendText(msg);
}
} catch (Exception e) {
log.error("websocket推送失败");
e.printStackTrace();
}
}
public static void broadcast(String msg) {
log.info("推送HL7转义消息:" + msg);
for (Session ses : HL7WebSocket.sessions) {
try {
ses.getBasicRemote().sendText(msg);
} catch (Exception e) {
log.error("websocket推送失败");
e.printStackTrace();
HL7WebSocket.sessions.remove(ses);
}
}
}
/**
* 发生异常错误
*
* @param session
* @param error
* @throws IOException
*/
@OnError
public void onError(Session session, Throwable error) throws IOException {
log.error("websocket发生错误");
error.printStackTrace();
if (session.isOpen()) {
session.close();
}
}
/**
* 关闭网页时调用
*
* @param session
* @throws IOException
*/
@OnClose
public void close(Session session) {
try {
Iterator<Session> iterator = sessions.iterator();
while (iterator.hasNext()) {
if (iterator.next().equals(session)) {
iterator.remove();
}
}
} catch (Exception e) {
log.error("websocket连接关闭异常");
e.printStackTrace();
}
}
/**
* a集合参照b集合顺序进行排序
* @param a
* @param b
*/
public void sortCarcode(List<JianHuYiListView> a, List<String> b) {
Collections.sort(a, ((o1, o2) -> {
int io1 = b.indexOf(o1.getCar_code());
int io2 = b.indexOf(o2.getCar_code());
if (io1 != -1) {
io1 = a.size() - io1;
}
if (io2 != -1) {
io2 = a.size() - io2;
}
return io2 - io1;
}));
}
}
4、补充逻辑
在笔者前期调研过程中也写了一部分测试代码,现整理后发出记录下
import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.model.v26.datatype.CX;
import ca.uhn.hl7v2.model.v26.datatype.EI;
import ca.uhn.hl7v2.model.v26.datatype.XPN;
import ca.uhn.hl7v2.model.v26.group.ORU_R01_ORDER_OBSERVATION;
import ca.uhn.hl7v2.model.v26.group.ORU_R01_PATIENT;
import ca.uhn.hl7v2.model.v26.group.ORU_R01_PATIENT_RESULT;
import ca.uhn.hl7v2.model.v26.group.ORU_R01_VISIT;
import ca.uhn.hl7v2.model.v26.segment.MSH;
import ca.uhn.hl7v2.model.v26.segment.OBR;
import ca.uhn.hl7v2.model.v26.segment.PV1;
import ca.uhn.hl7v2.parser.Parser;
import ca.uhn.hl7v2.parser.PipeParser;
import ca.uhn.hl7v2.util.Terser;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* HL7解析Demo
*/
public class HL7MessageAnalysis {
public static void main(String[] args) throws HL7Exception {
String ss = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231024152606000||ORU^R01^ORU_R01|411|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1||411^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|CONTINUOUS WAVEFORM|||20231024152605710|20231024152606710\r" +
"OBX|1|NA|150452^MDC_PULS_OXIM_PLETH^MDC|1.3.1.150452|94^94^92^83^78^72^67^63^60^57^56^54^53^52^51^49^48^46^44^42^40^38^36^35^33^31^27^27^24^21^18^16^15^16^20^27^37^49^61^72^80^86^89^89^86^83^78^73^68^64^60^55^54^54^54^54^54^53^52^50|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|2|NM|0^MDC_ATTR_SAMP_RATE^MDC|1.3.1.150452.1|60|264608^MDC_DIM_PER_SEC^MDC\r" +
"OBX|3|NM|2327^MDC_ATTR_NU_MSMT_RES^MDC|1.3.1.150452.2|1.000000|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|4|NM|262196^MDC_EVT_INOP^MDC|1.3.1.150452.3|32767";
PipeParser p = PipeParser.getInstanceWithNoValidation();
Message hapiMsg;
try {
hapiMsg = p.parse(ss);
} catch (HL7Exception e) {
e.printStackTrace();
return;
}
new HL7MessageAnalysis().analysisTerser(hapiMsg);
new HL7MessageAnalysis().analysis(hapiMsg);
}
/**
* 转terser解析
* @param hapiMsg
* @throws HL7Exception
*/
public void analysisTerser(Message hapiMsg) throws HL7Exception {
Terser terser = new Terser(hapiMsg);
terser.get("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(1)/OBX-1");
String s = terser.get("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(1)/OBX-4");
String s1 = terser.get("/PATIENT_RESULT/ORDER_OBSERVATION/OBSERVATION(0)/OBX-5");
String observationValue = terser.get("/.OBSERVATION(0)/OBX-5");
// 将 Observation Value 字段中的数值部分拆分为数组
String[] values = observationValue.split("\\^");
System.out.println(values);
}
/**
* 转对象解析
* @param hapiMsg
* @throws HL7Exception
*/
public void analysis(Message hapiMsg) throws HL7Exception {
/**
* 2.6解析
* */
MSH msh = (MSH) hapiMsg.get("MSH");
String value1 = msh.getMsh3_SendingApplication().getHd1_NamespaceID().getValue();
String value2 = msh.getMsh3_SendingApplication().getHd2_UniversalID().getValue();
String value3 = msh.getMsh3_SendingApplication().getHd3_UniversalIDType().getValue();
ORU_R01_PATIENT_RESULT ORU_R01_PATIENT_RESULT = (ORU_R01_PATIENT_RESULT) hapiMsg.get("PATIENT_RESULT");
ORU_R01_PATIENT patientResult = ORU_R01_PATIENT_RESULT.getPATIENT();
//patient
CX[] pid3PatientIdentifierList = patientResult.getPID().getPid3_PatientIdentifierList();
XPN[] pid5PatientName = patientResult.getPID().getPid5_PatientName();
ORU_R01_VISIT visit = patientResult.getVISIT();
PV1 pv1 = visit.getPV1();
//obr
ORU_R01_ORDER_OBSERVATION orderObservation = (ORU_R01_ORDER_OBSERVATION) ORU_R01_PATIENT_RESULT.get("ORDER_OBSERVATION");
OBR obr = orderObservation.getOBR();
//obr节点2
String obr1value = obr.getObr1_SetIDOBR().getValue();
//obr节点3
EI obr3FillerOrderNumber = obr.getObr3_FillerOrderNumber();
String obr3_1value = obr3FillerOrderNumber.getEi1_EntityIdentifier().getValue();
String obr3_2value = obr3FillerOrderNumber.getEi2_NamespaceID().getValue();
String obr3_3value = obr3FillerOrderNumber.getEi3_UniversalID().getValue();
String obr3_4value = obr3FillerOrderNumber.getEi4_UniversalIDType().getValue();
//obr节点4
String obr4_1value = obr.getObr4_UniversalServiceIdentifier().getIdentifier().getValue();
//obr节点7 8
String obr7value = obr.getObr7_ObservationDateTime().getValue();
String obr8value = obr.getObr8_ObservationEndDateTime().getValue();
}
}
三、总结
1、工具分享
笔者使用的是:7Edit 可以模拟发送hl7协议数据用于Socket调试使用,具体用法可以参考其他博主的文章,本来想截几个工具的图片,但是试用期已过不让打开了......
调试过程中可以用上述工具观察解析结果,但是要大规模,大密度模拟报文就需要手动写几个测试类调用了,下述是笔者测试中用到的工具类,分享给大家。
访问路径为:aikes/hl7/20,具体访问频次可自行调整。
import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.parser.Parser;
import ca.uhn.hl7v2.parser.ParserConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.text.ParseException;
@RestController
@RequestMapping("aikes")
@Slf4j
public class AikesController {
@Autowired
private HL7Business mHL7Business;
@GetMapping("/hl7/{code}")
public String testx(@PathVariable(value = "code") String param1) throws IOException, HL7Exception, ParseException {
int param = Integer.parseInt(param1);
String s1 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231024152406000||ORU^R01^ORU_R01|49|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1||49^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|CONTINUOUS WAVEFORM|||20231024152405710|20231024152406710\r" +
"OBX|1|NA|131330^MDC_ECG_ELEC_POTL_II^MDC|1.7.6.131330|1840^1820^1740^1596^1412^1204^996^788^596^420^268^136^20^-72^-148^-212^-264^-304^-332^-356^-368^-376^-380^-384^-384^-380^-376^-376^-376^-368^-364^-356^-348^-340^-332^-324^-316^-312^-308^-308^-304^-300^-296^-288^-284^-276^-268^-260^-256^-252^-248^-240^-232^-224^-216^-212^-204^-200^-196^-192^-188^-184^-176^-168^-160^-156^-152^-148^-144^-140^-136^-128^-124^-116^-108^-100^-92^-84^-76^-72^-68^-64^-60^-56^-52^-48^-44^-32^-24^-16^-8^0^12^20^24^28^32^36^40^48^52^56^64^72^80^92^96^108^112^120^124^128^132^132^140^140^140^144^140^136^136^132^128^124^116^108^100^88^72^60^44^32^12^-4^-20^-36^-52^-68^-84^-100^-112^-124^-136^-148^-160^-168^-172^-176^-180^-184^-184^-184^-180^-176^-176^-172^-168^-164^-164^-168^-168^-168^-164^-164^-160^-152^-148^-144^-140^-136^-136^-132^-124^-120^-116^-112^-108^-108^-104^-104^-100^-100^-96^-96^-92^-92^-92^-92^-92^-88^-88^-84^-80^-76^-72^-68^-68^-68^-68^-68^-64^-64^-64^-64^-60^-60^-56^-56^-52^-52^-48^-44^-44^-44^-44^-44^-40^-44^-44^-48^-48^-48^-44^-44^-40^-40^-32^-32^-28^-28^-24^-20^-20^-16^-12^-12^-12^-12^-12^-12^-12^-12^-16^-16^-16^-16^-12^-12^-8^0^4^12^20^28^36^40^48^52^52^56^60^64^64^68^68^72^76^76^72^68^68^68^64^64^60^56^52^44^32^24^16^8^0^-8^-12^-20^-24^-24^-28^-32^-32^-32^-36^-36^-40^-44^-44^-44^-44^-40^-36^-32^-24^-20^-12^-8^0^0^0^0^0^-8^-20^-36^-56^-68^-80^-80^-68^-32^24^112^228^372^544^736^944^1160^1364^1548^1700^1796^1832^1800^1704^1552^1368^1164^956^756^572^412^268^144^44^-36^-104^-156^-200^-232^-256^-280^-296^-304^-312^-316^-320^-320^-320^-316^-312^-304^-296^-292^-280^-272^-268^-256^-252^-248^-244^-240^-236^-232^-228^-228^-224^-224^-220^-216^-208^-204^-196^-188^-180^-176^-168^-164^-160^-156^-152^-148^-144^-140^-132^-124^-116^-108^-100^-92^-88^-84^-76^-72^-64^-60^-56^-52^-48^-48^-44^-44^-40^-32^-24^-24^-16^-12^-8^0^4^8^16^24^32^40^48^56^64^68^76^80^84^92^100^104^112^116^120^128^132^136^144^148^156^164^172^176^180^180^180^180^180^176^172^168^164^160^148^136^124^108^88^68^52^32^12^-4^-24^-40^-60^-72^-84^-96^-108^-120^-128^-140^-148^-152^-164^-168^-172^-172^-176^-176^-176^-180^-180^-180^-180^-180^-176^-172^-164^-156^-148^-144^-140^-136|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|2|NM|0^MDC_ATTR_SAMP_RATE^MDC|1.7.6.131330.1|500|264608^MDC_DIM_PER_SEC^MDC\r" +
"OBX|3|NM|2327^MDC_ATTR_NU_MSMT_RES^MDC|1.7.6.131330.2|0.001221|266418^MDC_DIM_MILLI_VOLT^MDC\r" +
"OBX|4|NM|262196^MDC_EVT_INOP^MDC|1.7.6.131330.3|32767";
String s11 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231024152406000||ORU^R01^ORU_R01|49|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1||49^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|CONTINUOUS WAVEFORM|||20231024152405710|20231024152406710\r" +
"OBX|1|NA|131330^MDC_ECG_ELEC_POTL_II^MDC|1.7.6.131330|-132^-132^-132^-132^-132^-132^-132^-132^-132^-132^-132^-128^-128^-124^-120^-116^-108^-104^-100^-96^-92^-92^-88^-88^-84^-80^-80^-76^-76^-76^-76^-80^-80^-80^-80^-80^-76^-80^-80^-80^-80^-80^-80^-80^-80^-76^-72^-72^-68^-64^-64^-64^-64^-64^-64^-68^-68^-72^-72^-72^-72^-72^-68^-64^-64^-60^-60^-56^-56^-56^-56^-60^-60^-60^-64^-64^-64^-64^-64^-60^-60^-64^-60^-60^-56^-56^-52^-48^-44^-44^-44^-44^-48^-48^-52^-52^-56^-56^-56^-52^-52^-48^-44^-36^-32^-28^-24^-20^-16^-12^-8^-8^-4^-4^-4^0^0^0^4^8^12^20^24^28^36^36^36^36^36^36^32^28^20^16^8^4^-4^-8^-16^-28^-32^-40^-44^-52^-56^-60^-64^-68^-68^-68^-68^-68^-68^-64^-64^-60^-60^-60^-60^-60^-60^-64^-60^-60^-56^-56^-56^-60^-68^-76^-88^-96^-104^-104^-100^-76^-32^32^124^240^388^560^756^960^1172^1364^1532^1652^1716^1716^1652^1532^1372^1188^988^796^616^452^304^180^72^-16^-88^-148^-196^-236^-264^-288^-308^-320^-324^-328^-328^-324^-320^-316^-312^-304^-304^-296^-292^-284^-276^-272^-268^-260^-256^-252^-248^-244^-244^-240^-232^-228^-224^-224^-220^-212^-208^-200^-192^-188^-180^-172^-168^-164^-156^-156^-148^-144^-136^-132^-124^-116^-108^-104^-96^-92^-84^-80^-76^-68^-64^-56^-52^-44^-40^-36^-32^-24^-16^-8^0^4^16^20^28^32^36^44^48^52^60^68^76^80^84^88^88^92^100^104^112^116^124^132^136^144^148^152^156^160^164^164^168^168^172^172^172^172^172^168^164^156^152^144^136^124^112^100^84^64^48^28^12^-8^-24^-44^-56^-72^-88^-96^-112^-120^-132^-140^-148^-156^-160^-164^-168^-168^-168^-168^-168^-168^-168^-168^-168^-164^-164^-164^-160^-156^-152^-148^-144^-140^-136^-132^-128^-124^-124^-120^-120^-120^-120^-116^-116^-112^-108^-104^-100^-96^-92^-88^-84^-84^-80^-80^-80^-80^-80^-80^-84^-88^-84^-88^-84^-84^-84^-84^-84^-84^-88^-92^-92^-92^-88^-88^-88^-84^-84^-84^-80^-80^-80^-80^-76^-76^-76^-72^-72^-68^-64^-64^-60^-60^-60^-60^-60^-56^-60^-60^-60^-64^-68^-72^-72^-76^-76^-76^-76^-72^-72^-68^-64^-64^-64^-60^-56^-56^-56^-56^-52^-52^-52^-48^-44^-44^-44^-44^-44^-44^-44^-40^-40^-40^-36^-36^-32^-32^-28^-28^-28^-28^-32^-32^-32^-32^-28^-24^-24^-24^-24^-24^-24^-28^-28^-28^-28^-28^-28^-24^-24^-20^-16^-16^-12^-12^-12^-12^-8^-8^-4^0^4^8^12^16|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|2|NM|0^MDC_ATTR_SAMP_RATE^MDC|1.7.6.131330.1|500|264608^MDC_DIM_PER_SEC^MDC\r" +
"OBX|3|NM|2327^MDC_ATTR_NU_MSMT_RES^MDC|1.7.6.131330.2|0.001221|266418^MDC_DIM_MILLI_VOLT^MDC\r" +
"OBX|4|NM|262196^MDC_EVT_INOP^MDC|1.7.6.131330.3|32767";
String s12 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231024152406000||ORU^R01^ORU_R01|49|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1||49^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|CONTINUOUS WAVEFORM|||20231024152405710|20231024152406710\r" +
"OBX|1|NA|131330^MDC_ECG_ELEC_POTL_II^MDC|1.7.6.131330|24^28^32^40^44^48^48^48^48^52^48^56^64^68^76^84^88^92^92^92^92^92^88^84^80^76^68^60^56^48^44^36^32^28^24^20^16^8^4^4^0^0^0^0^0^0^-4^-4^-4^-4^-4^0^0^0^0^0^0^0^0^-8^-16^-28^-40^-52^-60^-64^-52^-28^20^92^196^324^476^652^844^1048^1248^1428^1576^1676^1720^1700^1624^1496^1332^1148^956^768^596^444^304^188^84^0^-68^-124^-168^-204^-232^-252^-268^-280^-288^-296^-296^-296^-296^-292^-288^-284^-280^-276^-268^-264^-260^-256^-256^-256^-256^-256^-252^-248^-248^-244^-240^-232^-224^-220^-212^-204^-196^-188^-180^-172^-164^-156^-152^-148^-144^-140^-136^-136^-132^-128^-124^-120^-116^-108^-104^-100^-92^-84^-76^-68^-64^-60^-56^-52^-48^-40^-36^-32^-24^-20^-12^-8^0^4^8^16^24^32^40^52^60^68^76^84^88^96^104^112^120^128^132^140^144^148^152^156^156^160^164^168^172^176^180^184^184^188^188^192^192^192^192^188^184^176^168^160^148^136^120^104^84^64^44^24^0^-16^-36^-52^-72^-84^-100^-108^-120^-132^-144^-156^-164^-168^-176^-180^-184^-184^-184^-184^-188^-188^-188^-188^-188^-184^-180^-180^-176^-172^-172^-168^-164^-160^-156^-156^-152^-144^-144^-144^-140^-140^-140^-136^-136^-136^-132^-128^-124^-124^-120^-116^-116^-112^-108^-108^-108^-104^-104^-104^-108^-104^-104^-104^-100^-100^-96^-96^-96^-96^-96^-96^-96^-96^-92^-92^-92^-88^-88^-84^-84^-84^-80^-80^-80^-80^-80^-76^-76^-76^-72^-72^-72^-68^-64^-64^-56^-56^-52^-52^-48^-48^-48^-48^-44^-44^-44^-44^-48^-44^-48^-48^-48^-44^-48^-48^-48^-44^-44^-44^-44^-44^-44^-40^-44^-44^-44^-48^-48^-48^-52^-52^-48^-48^-44^-40^-36^-32^-28^-28^-28^-24^-24^-24^-24^-20^-20^-20^-20^-20^-20^-16^-16^-16^-16^-16^-12^-12^-16^-16^-16^-16^-20^-20^-24^-24^-24^-24^-24^-28^-28^-28^-28^-28^-24^-20^-16^-12^-8^-4^0^0^4^8^12^16^20^24^32^36^36^40^44^44^48^52^52^52^52^52^52^48^48^44^44^44^44^44^40^36^32^24^16^8^4^-4^-8^-16^-24^-28^-32^-32^-36^-40^-44^-48^-44^-48^-44^-44^-40^-36^-36^-32^-32^-28^-28^-24^-24^-20^-24^-24^-32^-40^-52^-64^-76^-88^-92^-88^-68^-32^24^112^220^360^520^704^904^1104^1296^1464^1592^1668^1680^1632^1528^1384^1208^1024^840^660^500^356^228^116^24^-52^-116^-168^-208^-240|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|2|NM|0^MDC_ATTR_SAMP_RATE^MDC|1.7.6.131330.1|500|264608^MDC_DIM_PER_SEC^MDC\r" +
"OBX|3|NM|2327^MDC_ATTR_NU_MSMT_RES^MDC|1.7.6.131330.2|0.001221|266418^MDC_DIM_MILLI_VOLT^MDC\r" +
"OBX|4|NM|262196^MDC_EVT_INOP^MDC|1.7.6.131330.3|32767";
String s2 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231024152350000||ORU^R01^ORU_R01|2|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1||2^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|CONTINUOUS WAVEFORM|||20231024152349710|20231024152350710\r" +
"OBX|1|NA|151780^MDC_IMPED_TTHOR^MDC|1.7.1.151780|39^39^39^39^38^38^38^38^38^38^38^38^38^38^37^37^37^37^37^37^37^37^37^37^36^36^36^36^36^36^36^36^35^35^35^35^35^35^35^35^34^34^34^34^34^34^33^33^33^33^33^33^33^33^32^32^32^32^32^32^32^31^31^31^31^31^31^31^31^30^30^30^30^30^30^30^29^29^29^29^29^29^28^28^28^28^28^28^28^27^27^27^27^27^26^26^26^26^26^26^25^25^25^25^25^25^24^24^24^24^24^24^24^23^23^23^23^23^22^22^22^22^22^22^22^21^21^21^21^21^20^20^20^20^20^20^20^19^19^19^19^19^18^18^18^18^18^18^18^17^17^17^17^17^17^16^16^16^16^16^16^15^15^15^15^15^14^14^14^14^14^14^14^13^13^13^13^13^12^12^12^12^12^12^12^11^11^11^11^11^11^10^10^10^10^10^10^9^9^9^9^9^8^8^8^8^8^8^7^7^7^7^7^6^6^6^6^6^6^6^5^5^5^5^5^4^4^4^4^4^3^3^3^3^3^3^2^2^2^2^2^1^1^1^1^1^1^0^0^0^0^0^0^0^-1^-1^-1^-1^-1^-2^-2^-2^-2^-2^-3^-3^-3^-3^-3^-4^-4^-4^-4^-4^-5^-5^-5^-5^-5^-6^-6^-6^-6^-6^-7^-7^-7^-7^-7^-7^-8^-8^-8^-8^-8^-9^-9^-9^-9^-9^-10^-10^-10^-10^-11^-11^-11^-11^-11^-12^-12^-12^-12^-12^-13^-13^-13^-13^-13^-14^-14^-14^-14^-15^-15^-15^-15^-15^-16^-16^-16^-17^-17^-17^-17^-18^-18^-18^-19^-19^-19^-19^-20^-20^-20^-20^-21^-21^-21^-22^-22^-22^-23^-23^-23^-24^-24^-24^-25^-25^-25^-26^-26^-26^-27^-27^-28^-28^-28^-29^-29^-30^-30^-30^-31^-31^-32^-32^-32^-33^-33^-34^-34^-35^-35^-36^-36^-36^-37^-37^-38^-38^-39^-39^-40^-40^-41^-41^-42^-42^-43^-43^-44^-44^-44^-45^-45^-46^-46^-47^-48^-48^-49^-49^-50^-50^-50^-51^-52^-52^-53^-53^-54^-54^-55^-55^-56^-56^-57^-57^-58^-58^-59^-59^-60^-60^-61^-62^-62^-62^-63^-64^-64^-65^-65^-66^-66^-67^-67^-68^-69^-69^-70^-70^-71^-71^-72^-72^-73^-73^-74^-74^-75^-75^-76^-76^-77^-77^-78^-78^-79^-79^-80^-81^-81^-81^-82^-82^-83^-83^-84^-84^-85^-85^-86^-86^-87^-87^-88^-88^-89^-89^-90^-90^-91^-91^-92^-92^-93^-93|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|2|NM|0^MDC_ATTR_SAMP_RATE^MDC|1.7.1.151780.1|500|264608^MDC_DIM_PER_SEC^MDC\r" +
"OBX|3|NM|2327^MDC_ATTR_NU_MSMT_RES^MDC|1.7.1.151780.2|1.000000|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|4|NM|262196^MDC_EVT_INOP^MDC|1.7.1.151780.3|32767";
String s21 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231024152350000||ORU^R01^ORU_R01|2|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1||2^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|CONTINUOUS WAVEFORM|||20231024152349710|20231024152350710\r" +
"OBX|1|NA|151780^MDC_IMPED_TTHOR^MDC|1.7.1.151780|-93^-94^-94^-95^-95^-96^-96^-96^-97^-97^-98^-98^-99^-99^-99^-100^-100^-101^-101^-101^-102^-102^-103^-103^-103^-104^-104^-105^-105^-105^-106^-106^-106^-107^-107^-108^-108^-108^-109^-109^-109^-110^-110^-110^-111^-111^-112^-112^-112^-112^-113^-113^-113^-114^-114^-114^-115^-115^-115^-115^-116^-116^-116^-117^-117^-117^-117^-118^-118^-118^-118^-118^-119^-119^-119^-119^-120^-120^-120^-120^-120^-121^-121^-121^-121^-121^-122^-122^-122^-123^-123^-124^-124^-124^-124^-124^-124^-124^-124^-124^-125^-125^-125^-125^-125^-125^-125^-125^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-126^-125^-125^-125^-125^-125^-125^-124^-124^-124^-124^-124^-124^-123^-123^-123^-123^-123^-122^-122^-122^-122^-122^-121^-121^-121^-120^-120^-120^-119^-119^-119^-119^-118^-118^-118^-118^-117^-117^-117^-116^-116^-116^-115^-115^-115^-114^-114^-113^-113^-113^-112^-112^-112^-111^-111^-110^-110^-110^-109^-109^-108^-108^-107^-107^-106^-106^-106^-105^-105^-104^-104^-103^-103^-102^-102^-101^-101^-100^-100^-99^-98^-98^-97^-97^-96^-95^-95^-94^-94^-93^-92^-92^-91^-91^-90^-89^-89^-88^-87^-87^-86^-85^-85^-84^-83^-82^-82^-81^-80^-80^-79^-78^-78^-77^-76^-75^-75^-74^-73^-72^-72^-71^-70^-69^-69^-68^-67^-66^-65^-65^-64^-63^-62^-62^-61^-60^-59^-58^-57^-57^-56^-55^-54^-54^-53^-52^-51^-50^-50^-49^-48^-47^-46^-45^-44^-44^-43^-42^-41^-40^-39^-38^-38^-37^-36^-35^-34^-33^-32^-32^-31^-30^-29^-28^-27^-27^-26^-25^-24^-23^-22^-22^-21^-20^-19^-18^-17^-17^-16^-15^-14^-13^-13^-12^-11^-10^-9^-9^-8^-7^-6^-5^-5^-4^-3^-2^-1^-1^0^1^1^2^3^4^5^5^6^7^7^8^9^10^10^11^12^12^13^14^15^15^16^17^18^18^19^19^20^21^22^22^23^24^24^25^26^26^27^28^28^29^30^30^31^31^32^33^33^34^35^35^36^37^37^38^38^39^40^40^41^41^42^43^43^44^44^45^45^46^47^47^48^48^49^49^50^50^51^51^52^52^53^53^54^55^55^55^56^56^57^57^58^58^59^59^60^60^61^61^62^62^63^63^63^64^64^65^65^66^66^67^67^67^68^68^69^69^69^70^70^71^71^71^72^72^72^73^73^74^74^74^74^75^75^75^76^76^76^77^77^77^78^78^78^79^79|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|2|NM|0^MDC_ATTR_SAMP_RATE^MDC|1.7.1.151780.1|500|264608^MDC_DIM_PER_SEC^MDC\r" +
"OBX|3|NM|2327^MDC_ATTR_NU_MSMT_RES^MDC|1.7.1.151780.2|1.000000|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|4|NM|262196^MDC_EVT_INOP^MDC|1.7.1.151780.3|32767";
String s22 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231024152350000||ORU^R01^ORU_R01|2|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1||2^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|CONTINUOUS WAVEFORM|||20231024152349710|20231024152350710\r" +
"OBX|1|NA|151780^MDC_IMPED_TTHOR^MDC|1.7.1.151780|79^80^80^80^80^80^81^81^81^81^82^82^82^82^83^83^83^83^83^84^84^84^84^84^84^85^85^85^85^85^85^86^86^86^86^86^86^86^86^86^86^87^87^87^87^87^87^87^87^87^87^87^87^87^87^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^88^87^87^87^87^87^87^87^87^87^87^87^87^86^86^86^86^86^86^86^86^86^86^86^86^86^85^85^85^85^85^85^85^85^85^84^84^84^84^84^84^84^84^83^83^83^83^83^83^83^83^82^82^82^82^82^82^82^81^81^81^81^81^81^81^80^80^80^80^80^80^80^80^80^79^79^79^79^79^79^79^78^78^78^78^78^78^77^77^77^77^77^77^77^76^76^76^76^76^76^76^75^75^75^75^75^75^74^74^74^74^74^74^74^74^73^73^73^73^73^73^73^73^72^72^72^72^72^72^72^72^71^71^71^71^71^71^71^71^71^71^70^70^70^70^70^70^70^70^70^70^69^69^69^69^69^69^69^69^69^69^68^68^68^68^68^68^68^68^68^68^68^68^67^67^67^67^67^67^67^67^67^67^67^67^66^66^66^66^66^66^66^66^66^66^66^66^65^65^65^65^65^65^65^65^65^65^65^65^64^64^64^64^64^64^64^64^64^64^64^64^64^64^63^63^63^63^63^63^63^63^63^63^63^63^62^62^62^62^62^62^62^62^62^62^62^62^62^62^61^61^61^61^61^61^61^61^61^61^60^60^60^60^60^60^60^60^60^60^59^59^59^59^59^59^59^59^59^58^58^58^58^58^58^58^58^58^57^57^57^57^57^57^57^57^56^56^56^56^56^56^56^56^55^55^55^55^55^55^55^55^55^55^54^54^54^54^54^54^54^54^53^53^53^53^53^53^53^53^52^52^52^52^52^52^52^52^51^51^51^51^51^51^51^51^50^50^50^50^50^50^49^49^49^49^49^49^49^49^49^49^48^48^48^48^48^48^48^48^47^47^47^47^47^47^47^47^46^46^46^46^46^46^46^46^45^45^45^45^45^45^45^45^44^44^44^44^44^44^44^44|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|2|NM|0^MDC_ATTR_SAMP_RATE^MDC|1.7.1.151780.1|500|264608^MDC_DIM_PER_SEC^MDC\r" +
"OBX|3|NM|2327^MDC_ATTR_NU_MSMT_RES^MDC|1.7.1.151780.2|1.000000|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|4|NM|262196^MDC_EVT_INOP^MDC|1.7.1.151780.3|32767";
String s3 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231024152406000||ORU^R01^ORU_R01|6|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1||6^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|CONTINUOUS WAVEFORM|||20231024152350710|20231024152351710\r" +
"OBX|1|NA|150452^MDC_PULS_OXIM_PLETH^MDC|1.3.1.150452|67^66^64^61^58^55^51^48^44^41^38^36^33^31^29^22^19^15^12^10^10^12^17^24^33^43^53^61^68^72^75^75^73^72^71^69^69^68^68^68^68^68^68^67^66^65^62^59^56^52^48^45^42^39^37^35^34^32^30^27|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|2|NM|0^MDC_ATTR_SAMP_RATE^MDC|1.3.1.150452.1|60|264608^MDC_DIM_PER_SEC^MDC\r" +
"OBX|3|NM|2327^MDC_ATTR_NU_MSMT_RES^MDC|1.3.1.150452.2|1.000000|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|4|NM|262196^MDC_EVT_INOP^MDC|1.3.1.150452.3|32767";
String s31 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231024152406000||ORU^R01^ORU_R01|6|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1||6^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|CONTINUOUS WAVEFORM|||20231024152350710|20231024152351710\r" +
"OBX|1|NA|150452^MDC_PULS_OXIM_PLETH^MDC|1.3.1.150452|27^24^21^17^14^15^19^25^33^43^54^63^69^73^75^74^71^68^65^62^60^59^59^59^61^62^64^66^70^70^70^69^68^66^61^58^55^55^51^47^43^39^35^31^27^23^19^14^10^6^4^4^13^22^34^47^60^70^78^84|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|2|NM|0^MDC_ATTR_SAMP_RATE^MDC|1.3.1.150452.1|60|264608^MDC_DIM_PER_SEC^MDC\r" +
"OBX|3|NM|2327^MDC_ATTR_NU_MSMT_RES^MDC|1.3.1.150452.2|1.000000|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|4|NM|262196^MDC_EVT_INOP^MDC|1.3.1.150452.3|32767";
String s32 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231024152406000||ORU^R01^ORU_R01|6|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1||6^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|CONTINUOUS WAVEFORM|||20231024152350710|20231024152351710\r" +
"OBX|1|NA|150452^MDC_PULS_OXIM_PLETH^MDC|1.3.1.150452|87^87^87^86^86^86^86^86^85^85^84^83^81^80^78^73^71^68^65^62^59^56^53^50^47^44^40^37^33^30^27^24^21^18^12^10^9^10^10^17^24^33^41^49^55^60^63^64^64^64^64^63^63^63^63^63^64^63^63^63|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|2|NM|0^MDC_ATTR_SAMP_RATE^MDC|1.3.1.150452.1|60|264608^MDC_DIM_PER_SEC^MDC\r" +
"OBX|3|NM|2327^MDC_ATTR_NU_MSMT_RES^MDC|1.3.1.150452.2|1.000000|262656^MDC_DIM_DIMLESS^MDC\r" +
"OBX|4|NM|262196^MDC_EVT_INOP^MDC|1.3.1.150452.3|32767";
String s4 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231125150059000||ORU^R01^ORU_R01|161|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1|161^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|161^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|182777000^monitoring of patient^SCT|||20231125150059\r" +
"OBX|1|NM|147842^MDC_ECG_HEART_RATE^MDC|1.7.4.147842|70|264864^MDC_DIM_BEAT_PER_MIN^MDC|||||R|||20231125150059||||00A037009A00CB60^^00A037009A00CB60^EUI-64\r" +
"OBX|2|NM|151578^MDC_TTHOR_RESP_RATE^MDC|1.7.1.151578|15|264928^MDC_DIM_RESP_PER_MIN^MDC|||||R|||20231125150059\r" +
"OBX|3|NM|150456^MDC_PULS_OXIM_SAT_O2^MDC|1.3.1.150456|97|262688^MDC_DIM_PERCENT^MDC|||||R|||20231125150059\r" +
"OBX|4|NM|149530^MDC_PULS_OXIM_PULS_RATE^MDC|1.3.1.149530|69|264864^MDC_DIM_BEAT_PER_MIN^MDC|||||R|||20231125150059";
String s41 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231125150059000||ORU^R01^ORU_R01|161|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1|161^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|161^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|182777000^monitoring of patient^SCT|||20231125150059\r" +
"OBX|1|NM|147842^MDC_ECG_HEART_RATE^MDC|1.7.4.147842|71|264864^MDC_DIM_BEAT_PER_MIN^MDC|||||R|||20231125150059||||00A037009A00CB60^^00A037009A00CB60^EUI-64\r" +
"OBX|2|NM|151578^MDC_TTHOR_RESP_RATE^MDC|1.7.1.151578|14|264928^MDC_DIM_RESP_PER_MIN^MDC|||||R|||20231125150059\r" +
"OBX|3|NM|150456^MDC_PULS_OXIM_SAT_O2^MDC|1.3.1.150456|98|262688^MDC_DIM_PERCENT^MDC|||||R|||20231125150059\r" +
"OBX|4|NM|149530^MDC_PULS_OXIM_PULS_RATE^MDC|1.3.1.149530|69|264864^MDC_DIM_BEAT_PER_MIN^MDC|||||R|||20231125150059";
String s42 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231125150059000||ORU^R01^ORU_R01|161|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1|161^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|161^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|182777000^monitoring of patient^SCT|||20231125150059\r" +
"OBX|1|NM|147842^MDC_ECG_HEART_RATE^MDC|1.7.4.147842|1|264864^MDC_DIM_BEAT_PER_MIN^MDC|||||R|||20231125150059||||00A037009A00CB60^^00A037009A00CB60^EUI-64\r" +
"OBX|2|NM|151578^MDC_TTHOR_RESP_RATE^MDC|1.7.1.151578|1|264928^MDC_DIM_RESP_PER_MIN^MDC|||||R|||20231125150059\r" +
"OBX|3|NM|150456^MDC_PULS_OXIM_SAT_O2^MDC|1.3.1.150456|1|262688^MDC_DIM_PERCENT^MDC|||||R|||20231125150059\r" +
"OBX|4|NM|149530^MDC_PULS_OXIM_PULS_RATE^MDC|1.3.1.149530|1|264864^MDC_DIM_BEAT_PER_MIN^MDC|||||R|||20231125150059";
String s5 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231125150018000||ORU^R01^ORU_R01|120|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1|120^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|120^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|182777000^monitoring of patient^SCT|||20231125150018\r" +
"OBX|1|NM|150301^MDC_PRESS_CUFF_SYS^MDC|1.1.9.150301|121|266016^MDC_DIM_MMHG^MDC|||||R|||20231125150018|||^APERIODIC|00A037009A00CB60^^00A037009A00CB60^EUI-64\r" +
"OBX|2|NM|150303^MDC_PRESS_CUFF_MEAN^MDC|1.1.9.150303|86|266016^MDC_DIM_MMHG^MDC|||||R|||20231125150018|||^APERIODIC\r" +
"OBX|3|NM|150302^MDC_PRESS_CUFF_DIA^MDC|1.1.9.150302|80|266016^MDC_DIM_MMHG^MDC|||||R|||20231125150018|||^APERIODIC";
String s51 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231125150018000||ORU^R01^ORU_R01|120|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1|120^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|120^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|182777000^monitoring of patient^SCT|||20231125150018\r" +
"OBX|1|NM|150301^MDC_PRESS_CUFF_SYS^MDC|1.1.9.150301|123|266016^MDC_DIM_MMHG^MDC|||||R|||20231125150018|||^APERIODIC|00A037009A00CB60^^00A037009A00CB60^EUI-64\r" +
"OBX|2|NM|150303^MDC_PRESS_CUFF_MEAN^MDC|1.1.9.150303|85|266016^MDC_DIM_MMHG^MDC|||||R|||20231125150018|||^APERIODIC\r" +
"OBX|3|NM|150302^MDC_PRESS_CUFF_DIA^MDC|1.1.9.150302|85|266016^MDC_DIM_MMHG^MDC|||||R|||20231125150018|||^APERIODIC";
String s52 = "MSH|^~\\&|MINDRAY_D-SERIES^00A037009A00CB60^EUI-64||||20231125150018000||ORU^R01^ORU_R01|120|P|2.6|||AL|NE||UNICODE UTF-8|||IHE_PCD_001^IHE PCD^1.3.6.1.4.1.19376.1.6.1.1.1^ISO\r" +
"PID|||^^^Hospital^PI||^^^^^^L\r" +
"PV1||I\r" +
"OBR|1|120^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|120^MINDRAY_D-SERIES^00A037009A00CB60^EUI-64|182777000^monitoring of patient^SCT|||20231125150018\r" +
"OBX|1|NM|150301^MDC_PRESS_CUFF_SYS^MDC|1.1.9.150301|1|266016^MDC_DIM_MMHG^MDC|||||R|||20231125150018|||^APERIODIC|00A037009A00CB60^^00A037009A00CB60^EUI-64\r" +
"OBX|2|NM|150303^MDC_PRESS_CUFF_MEAN^MDC|1.1.9.150303|1|266016^MDC_DIM_MMHG^MDC|||||R|||20231125150018|||^APERIODIC\r" +
"OBX|3|NM|150302^MDC_PRESS_CUFF_DIA^MDC|1.1.9.150302|1|266016^MDC_DIM_MMHG^MDC|||||R|||20231125150018|||^APERIODIC";
HapiContext context = new DefaultHapiContext();
//设置hl7不校验字段值
ParserConfiguration tParserConfiguration = new ParserConfiguration();
tParserConfiguration.setValidating(false);
context.setParserConfiguration(tParserConfiguration);
Parser p = context.getGenericParser();
Message hapiMsg = null;
int x = 1;
while (true) {
try {
if (param >= 1) {
hapiMsg = p.parse(s1);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s2);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s3);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s4);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s5);
mHL7Business.analysisModule_1(hapiMsg);
Thread.sleep(1000);
}
if (param > 1) {
hapiMsg = p.parse(s11);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s21);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s31);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s41);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s51);
mHL7Business.analysisModule_1(hapiMsg);
Thread.sleep(1000);
hapiMsg = p.parse(s12);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s22);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s32);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s42);
mHL7Business.analysisModule_1(hapiMsg);
hapiMsg = p.parse(s52);
mHL7Business.analysisModule_1(hapiMsg);
Thread.sleep(1000);
}
if ((x++) == param) {
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
}
2、问题记录
笔者在开发中遇到的最坑的一个问题,也是耽误时间最长的:
从日志中抓取到hl7传输的数据,作为字符串复制到代码中开始调试,但是无论怎么运行都只能获取到第一行的部分数据,经过反反复复的调整环境仍然无果。
最后无意中看到了字符串末尾 \n 的字符,这才想到可能是换行导致了API识别有误,替换为 \r 后解析就正常啦。
以后也要注意粘贴进来的换行符可能会影响到解析逻辑。