在段重复的情况下如何使用 Terser.get() 方法从特定段获取值?
How to get the value from specific segment using Terser.get() method in case of segment repetition?
我正在尝试阅读具有多个 ORC
段的 HL7 消息。 terser.get()
方法仅获取第一个 ORC
段的值。当尝试从 /ORDER(2)/ORC-X-X
读取时,该方法没有 return 任何值。
Terser mesg = new Terser(next);
System.out.println(mesg.get("/ORDER(2)/ORC-2-1"));
该方法将 return mesg.get("/ORDER/ORC-2-1")
的值。我希望它也 return for "/ORDER(2)/ORC-2-1"
.
更简洁的完整路径:
我不是 Terser 专家,但是...
根据documentation,以下是String get(String spec)
方法的描述:
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).
其中 spec 是字段规范。
有了这个,正如here所解释的那样,您可以使用以下代码获取特定段中的特定组件:
@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"));
}
输入的HL7消息是:
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.
同样,对于您的情况,以下代码应该有效:
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
更新您的编辑和评论:
关于ORDER
的东西,看来很有必要。在这种情况下,请使用以下代码:
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
解决方案是使用 OMS_O05
中的 getOrderReps()
方法,该方法会给出 ORDERS 的重复次数。也使用 OMS_O05
作为消息类型。
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"));
}
我正在尝试阅读具有多个 ORC
段的 HL7 消息。 terser.get()
方法仅获取第一个 ORC
段的值。当尝试从 /ORDER(2)/ORC-X-X
读取时,该方法没有 return 任何值。
Terser mesg = new Terser(next);
System.out.println(mesg.get("/ORDER(2)/ORC-2-1"));
该方法将 return mesg.get("/ORDER/ORC-2-1")
的值。我希望它也 return for "/ORDER(2)/ORC-2-1"
.
更简洁的完整路径:
我不是 Terser 专家,但是...
根据documentation,以下是String get(String spec)
方法的描述:
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).
其中 spec 是字段规范。
有了这个,正如here所解释的那样,您可以使用以下代码获取特定段中的特定组件:
@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"));
}
输入的HL7消息是:
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.
同样,对于您的情况,以下代码应该有效:
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
更新您的编辑和评论:
关于ORDER
的东西,看来很有必要。在这种情况下,请使用以下代码:
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
解决方案是使用 OMS_O05
中的 getOrderReps()
方法,该方法会给出 ORDERS 的重复次数。也使用 OMS_O05
作为消息类型。
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"));
}