ca.uhn.hl7v2.util
Class MessageQuery
java.lang.Object
ca.uhn.hl7v2.util.MessageQuery
public class MessageQuery
- extends java.lang.Object
Queries messages in an SQL-like style. We get repeated row-like
structures by looping over repetitions of groups, segments, or fields.
This is a very advanced class ... maybe too advanced even for you. If you
find it confusing, please note that there are simpler ways to get data
from a message (like calling its getters or using Terser).
LOOPING:
You specify the loop points as part of the query. For example you could
specify loop point x like this: x = /.MSH-18(*)
. The *
is replaced by numbers 0, 1, 2, etc. as you loop through the results,
so this example would loop through repetitions of MSH-18. If
there are multiple loop points, the loops are nested so that each possible
combination is returned. Looping stops when none of the fields under a
loop point are valued. The name of the loop point ('x' in the example
above) is arbitrary.
SELECTING FIELDS:
The syntax is similar to SQL, except that Terser paths are used in place
of table.field. You can use the "as" keyword to give a field a name, like
this: select /.MSH-7 as msg_date
. If your field is under
a loop point, replace the path up to the loop point with a loop point
reference, like this: select {foo}-1 loop foo = /.PID-3(*)
SELECTING ROWS:
A "row" is a combination of all selected fields at one iteration. You
can filter which rows are returned using a where clause similar to that
in SQL. Use exact values or regular expressions, for example:
where {1} like '.*blood.*'
or where {1}/PID-3-1 = '111'
Multiple filters can be separated with commas (which mean 'and'). Future
versions may support 'or', negation, brackets, etc., but this version doesn't.
FULL EXAMPLE:
select {pat-id}-1 as id loop pat-id = ./PID-3(*) where {pat-id}-2 = 'mrn'
SUBTLETIES OF LOOPING:
A loop point can be under another loop point. For example consider the message:
MSH|etc.|etc.
Z01|one~two|a
Z01|three~four|b
The query, "select {a}-2, {b} loop a = /Z01(*), b = {a}-1(*)" would return:
a one
a two
b three
b four
While the query "select {a}-2, {b} loop a = /Z01(*), b = /Z01(1)-1(*)" would return:
a one
a two
b one
b two
In the first case, one loop point refers to another. In the second case the loops
are treated as independent, just as if they referred to different branches of the
message.
TODO: could support distinct easily by keeping record of rows and comparing each
one to previous rows
- Version:
- $Revision: 1.1 $ updated on $Date: 2007/02/19 02:24:27 $ by $Author: jamesagnew $
- Author:
- Bryan Tripp
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MessageQuery
public MessageQuery()
query
public static MessageQuery.Result query(Message theMessage,
java.lang.String theQuery)
- Parameters:
theMessage
- an HL7 message from which data are to be queriedtheQuery
- the query (see class docs for syntax)
- Returns:
- data from the message that are selected by the query
Copyright © 2001-2011 University Health Network. All Rights Reserved.