From: Tripp, B. <Bry...@uh...> - 2004-11-11 00:02:52
|
There is a new class called ca.uhn.hl7v2.util.MessageQuery (in CVS now = and to be included in next release). It's like Terser but with much better support for repetitions. =20 It could use a few more features but works great for lots of cases. See unit tests for examples. For your convenience the docs are included = below. Bryan =20 * Queries messages in an SQL-like style. We get repeated row-like=20 * structures by looping over repetitions of groups, segments, or = fields.=20 *=20 * LOOPING: =20 * You specify the loop points as part of the query. For example you = could=20 * specify loop point x like this: <code>x =3D /.MSH-18(*)</code>. The = *=20 * 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=20 * there are multiple loop points, the loops are nested so that each possible=20 * combination is returned. Looping stops when none of the fields under = a=20 * loop point are valued. The name of the loop point ('x' in the = example=20 * above) is arbitrary. =20 *=20 * SELECTING FIELDS:=20 * 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=20 * this: <code>select /.MSH-7 as msg_date</code>. If your field is = under=20 * a loop point, replace the path up to the loop point with a loop point = * reference, like this: <code>select {foo}-1 loop foo =3D = /.PID-3(*)</code> *=20 * SELECTING ROWS: * A "row" is a combination of all selected fields at one iteration. = You=20 * can filter which rows are returned using a where clause similar to = that * in SQL. Use exact values or regular expressions, for example:=20 * <code>where {1} like '.*blood.*'</code> or <code>where {1}/PID-3-1 = =3D '111'</code> * Multiple filters can be separated with commas (which mean 'and'). = Future * versions may support 'or', negation, brackets, etc., but this version doesn't. =20 *=20 * FULL EXAMPLE:=20 * select {pat-id}-1 as id loop pat-id =3D ./PID-3(*) where {pat-id}-2 = =3D 'mrn' *=20 * SUBTLETIES OF LOOPING:=20 * A loop point can be under another loop point. For example consider = the message: =20 *=20 * MSH|etc.|etc. * Z01|one~two|a * Z01|three~four|b *=20 * The query, "select {a}-2, {b} loop a =3D /Z01(*), b =3D {a}-1(*)" = would return:=20 * a one * a two=20 * b three * b four *=20 * While the query "select {a}-2, {b} loop a =3D /Z01(*), b =3D = /Z01(1)-1(*)" would return: * a one * a two=20 * b one * b two *=20 * In the first case, one loop point refers to another. In the second = case the loops=20 * are treated as independent, just as if they referred to different branches of the=20 * message. =20 |