Reputation: 69
I have a HL7 message that contains one MSH segment and multiple PIV segments.
Using Java REGEX, I need to do these:
1) extract the entire MSH segment
2) find each occurence of PV1 segment.
3) extract the entire content/segments that exists between each PV1 segment - including the PV1 segment.
How do I accomplish the above?
Below is the sample HL7 msg:
MSH|^~\&|OADD|${FACILITY}|HELIX||201012010910||ORU^R01|20101720000042|T|2.2
PID|||PX65^^^MRENTR||Mayer^Ronny
PV1||I||2|||9898^Jackson^Burt^T|||||||||||IP||||||||||||||||||||||||||201012010840
OBX|1|NM|NA^Sodium^0|1.1|140^3|mmol/L|137-146||||F|||201012010905|IM^|8035^COX^CATHERINE(IM)
OBX|2|NM|K^Potassium^0|1.1|4.5|mmol/L|3.5-5.0||||F|||201012010905|IM^|8035^COX^CATHERINE
(IM)
OBX|3|CE|CL^Chloride^0|1.1|100|mmol/L|98-109||||F|||201012010905|IM^|8035^COX^CATHERINE(IM)
PV1||I||2|||9898^Jackson^Burt^T|||||||||||IP||||||||||||||||||||||||||201012010840
OBX|1|NM|NA^Sodium^0|1.1|140^3|mmol/L|137-146||||F|||201012010905|IM^|8035^COX^CATHERINE(IM)
PV1||I||2|||9898^Jackson^Burt^T|||||||||||IP||||||||||||||||||||||||||201012010840
OBX|1|NM|NA^Sodium^0|1.1|140^3|mmol/L|137-146||||F|||201012010905|IM^|8035^COX^CATHERINE(IM)
So the final goal is to have a msg like this - to have the extracted MSH segment before each PV1 segment. Then create a new HL7 message object that contains each of such HL7 message. In my example, 3 hl7 message will be created - each ofthem will be passed to HAPI parser.
MSH|^~\&|OADD|${FACILITY}|HELIX||201012010910||ORU^R01|20101720000042|T|2.2
PID|||PX65^^^MRENTR||Mayer^Ronny
PV1||I||2|||9898^Jackson^Burt^T|||||||||||IP||||||||||||||||||||||||||201012010840
OBX|1|NM|NA^Sodium^0|1.1|140^3|mmol/L|137-146||||F|||201012010905|IM^|8035^COX^CATHERINE(IM)
OBX|2|NM|K^Potassium^0|1.1|4.5|mmol/L|3.5-5.0||||F|||201012010905|IM^|8035^COX^CATHERINE
(IM)
OBX|3|CE|CL^Chloride^0|1.1|100|mmol/L|98-109||||F|||201012010905|IM^|8035^COX^CATHERINE(IM)
MSH|^~\&|OADD|${FACILITY}|HELIX||201012010910||ORU^R01|20101720000042|T|2.2
PV1||I||2|||9898^Jackson^Burt^T|||||||||||IP||||||||||||||||||||||||||201012010840
OBX|1|NM|NA^Sodium^0|1.1|140^3|mmol/L|137-146||||F|||201012010905|IM^|8035^COX^CATHERINE(IM)
MSH|^~\&|OADD|${FACILITY}|HELIX||201012010910||ORU^R01|20101720000042|T|2.2
PV1||I||2|||9898^Jackson^Burt^T|||||||||||IP||||||||||||||||||||||||||201012010840
OBX|1|NM|NA^Sodium^0|1.1|140^3|mmol/L|137-146||||F|||201012010905|IM^|8035^COX^CATHERINE(IM)
Upvotes: 2
Views: 1541
Reputation: 1077
You can use the library jar: hapi-base.2.0.jar
With the class ca.uhn.hl7v2.util.Terser you can get the segments that you want of the report.
public Message processMessage(Message theIn) throws ApplicationException,
HL7Exception {
theIn = (ORU_R01) new PipeParser(new CanonicalModelClassFactory("2.3"))
.parse(theIn.encode());
System.out.println(theIn.printStructure());//for debug better
Terser menssageParsed = new Terser(theIn);
String sResp = menssageParsed.get("/.RESPONSE/ORDER_OBSERVATION/OBR-3-1");
}
But if you like to create new segments in the report or edit. You can use this classes
ca.uhn.hl7v2.model.Message; ca.uhn.hl7v2.model.Structure;
Upvotes: 0