问题
I'm trying to read HL7 messages where I have multiple ORC
segments. The terser.get()
method is only getting values for the first ORC
segment. When trying to read from /ORDER(2)/ORC-X-X
, the method does not return any value.
Terser mesg = new Terser(next);
System.out.println(mesg.get("/ORDER(2)/ORC-2-1"));
The method would return the value for mesg.get("/ORDER/ORC-2-1")
. I expect it also to return for "/ORDER(2)/ORC-2-1"
.
Terser Full Path:
回答1:
The solution was to use getOrderReps()
method from OMS_O05
that would give the repetition number of ORDERS. Also use OMS_O05
as message type.
OMS_O05 omsMsg = (OMS_O05) next;
Terser t = new Terser(omsMsg);
for (int i = 0; i < omsMsg.getORDERReps(); i++)
{
System.out.println(t.get("/ORDER("+i+")/ORC-2-1"));
}
回答2:
I am not expert in Terser, but...
According to documentation, following is the description for String get(String spec)
method:
Gets the string value of the field specified. See the class docs for syntax of the location spec.
If a repetition is omitted for a repeating segment or field, the first rep is used. If the component or subcomponent is not specified for a composite field, the first component is used (this allows one to write code that will work with later versions of the HL7 standard).
where spec is field specification.
With this, as explained here, you can get the specific component in specific segment with following code:
@Test
public void testAccessSegmentRepetitions() throws Exception{
//First Next of Kin Id
assertEquals("1", terser.get("NK1(0)-1"));
//Second Next of Kin Id
assertEquals("2", terser.get("NK1(1)-1"));
}
The input HL7 message is:
MSH|^~\\&|hl7Integration|hl7Integration|||||ADT^A01|||2.3|
EVN|A01|20130617154644
PID|1|465 306 5961||407623|Wood^Patrick^^^MR||19700101|1|||High Street^^Oxford^^Ox1 4DP~George St^^Oxford^^Ox1 5AP|||||||
NK1|1|Wood^John^^^MR|Father||999-9999
NK1|2|Jones^Georgie^^^MSS|MOTHER||999-9999
PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|||||||||
We can get particular repetitions using the brackets. Depending where we put the brackets we will be retrieving a segment repetition, a field repetition or a component repetition.
Similarly, in your case, following code should work:
mesg.get("/ORC(0)-2-1") //This will return value from first occurrence of segment
mesg.get("/ORC(1)-2-1") //This will return value from second occurrence of segment
Update for your edit and your comment:
About the ORDER
stuff, it looks that it is necessary. In that case, use following code:
mesg.get("/ORDER(2)/ORC(0)-2-1") //This will return value from first occurrence of segment
mesg.get("/ORDER(2)/ORC(1)-2-1") //This will return value from second occurrence of segment
来源:https://stackoverflow.com/questions/56137962/how-to-get-the-value-from-specific-segment-using-terser-get-method-in-case-of