Previous Page TOC Index Next Page

2.25.4 Query examples

2.25.4.1 Original mode query with display-oriented response

Query for all lab results on patient #12233. The query is made at 11:00 a.m., 9/11/87. The Query anticipates an immediate display-oriented response.

MSH|^~\&|ICU||LAB01|||QRY^Q01|MSG00001|P|2.1<CR>
QRD|198709111012|D|I|4387|||20^LI|12233|RES|ALL<CR>

The response to the above query might look like the following:

MSH|^~\&|LAB01||ICU|||DSR|ZXT23461|P|2.1<CR>
MSA|AA|MSG00001P<CR>
QRD|198709111012|D|I|4387|||20^LI|12233|RES|ALL<CR>
DSP|||RESULTS FOR PATIENT#12233   SMITH, JOHN H. 09/11/87<CR>
DSP|||SPECIMEN#H85 COLLECTED 09/11/87 /07/0/0<CR>
DSP<CR>
DSP|||ELECTROLYTES<CR>
DSP||| SODIUM   140 [135-148] MEQ/L STAT<CR>
DSP||| POTASSIUM  4.0 [3.5-5.0] MEQ/L STAT<CR>
DSP||| CHLORIDE   89 [95-111]  MEQ/L STAT<CR>
DSP||| CO2    20 [20-30]  MEQ/L STAT<CR>
DSP||||LB<CR>
DSP|||CBC<CR>
DSP||| HEMOGLOBIN   [13.5-18.0]<CR>
DSP||| HEMATOCRIT  45 [40-54]  %<CR> 
DSP||| RED CELL COUNT 5.0 [4.6-6.2]  M/MM3<CR>
DSP||| MCHC    32 [32-36]  G/DL<CR>
DSP||| MCH    28 [26-32]  PG<CR>
DSP||| MCV    85 [81-101]  FL<CR>
DSP||| WHITE CELL CNT 7.5 [5.0-10.0] K/MM3<CR>
DSP||||LB<CR> 
DSP|||SPECIMEN#B24   COLLECTED 9/10/87<CR>
DSC|12333H85;12<CR>

A continuation query would echo back the contents of DSC-1-continuation pointer as follows:

MSH|^~\&|ICU||LAB01|||QRY^Q01|MSG00003|P|2.1<CR>
QRD|198709111012|D|I|4387|||20^LI|12233|RES|ALL<CR>
DSC|12333H85;12<CR>

The following response shows that there is no further data by leaving DSC-1-continuation pointer not present. This could be done by sending the DSC segment with no data, but the example does the same thing by totally omitting the DSC segment.

MSH|^~\&|LAB01||ICU|||DSR|ZXT23469|P|2.1<CR>
MSA|AA|MSG00003|<CR>
QRD|198709111012|D|I|4387|||20^LI|12233|RES|ALL<CR>
DSP|||RESULTS FOR PATIENT#12233   SMITH, JOHN H. 09/11/87<CR>
DSP|||SPECIMEN#H85 COLLECTED 09/10/87 /07/0/0<CR>
DSP<CR>
DSP|||ELECTROLYTES<CR>
DSP||| SODIUM  136 [135-148] MEQ/L STAT<CR>
DSP||| POTASSIUM 4.2 [3.5-5.0] MEQ/L STAT<CR>
DSP||| CHLORIDE  91 [95-111]  MEQ/L STAT<CR>
DSP||| CO2   25 [20-30]  MEQ/L STAT<CR>
DSP||||LB<CR>

2.25.4.2 Enhanced mode query examples

Note: For illustration purposes, these examples assume that the following are defined in the ADT chapter:

• The VQQ (using SQL) and EQQ selection criteria

• The virtual table named PID

• The stored procedure named PID_QRY_01

2.25.4.2.1 Embedded query language (using SQL), virtual table and stored procedure queries with tabular response

The following example illustrates a query for the last and first names, address, social security number and date of birth of patients whose last name is "Evans." The fields comprising the query and response are identified by their HL7 item numbers. Where a field is composed of components, the particular component is identified with a ".n" suffix (e.g., the patient last name is the first component of the patient name field (HL7 item #00108), and therefore is identified as "@00108.1."

The following examples illustrate this query expressed as an SQL select statement, as a virtual table query and as a stored procedure call

2.25.4.2.2 Embedded query language query
MSH|^~\|CLINIC||CENTRAL-REG|||EQQ|MSG00001|P|2.3<CR>
EQL|TAG001|T|SQL_PID_QRY_01|SELECT @00108.1,@00108.2,@00114.1,@00114.2,
 @00114.3,@00114.4,@00114.5,@00122,@00110 
 FROM PID WHERE @00108.1=‘EVANS’<CR>
2.25.4.2.3 Virtual table query
MSH|^~\|CLINIC||CENTRAL-REG|||VQQ|MSG00001|P|2.3<CR>
VTQ| TAG001|T | VTQ_PID_QRY_01|PID|@00108.1^EQ^EVANS <CR>
RDF|9|@00108.1^ST^20~@00108.2^ST^20~@00114.1^ST^30~@00114.2^ST^30~
 @00114.3^ST^20~@00114.4^ST^2~@00114.5^ST^5~@00122^ST^11~
 @00110^TS^8<CR>
2.25.4.2.4 Stored procedure request
MSH|^~\|CLINIC||CENTRAL-REG|||SPQ|MSG00001|P|2.3<CR>
SPR|TAG0001|T|SPR_PID_QRY_01|@00108.1^EVANS<CR>
RDF|9|@00108.1^ST^20~@00108.2^ST^20~@00114.1^ST^30~@00114.2^ST^30~
 @00114.3^ST^20~@00114.4^ST^2~@00114.5^ST^5~@00122^ST^11~
 @00110^TS^8<CR>
2.25.4.2.5 The response to the above queries might look like the following:
MSH|^~\|CENTRAL-REG||CLINIC|||TBR|MSG99001|P|2.3<CR>
MSA|AA|MSG00001<CR>
QAK|TAG0001|OK<CR>
RDF|9|@00108.1^ST^20~@00108.2^ST^20~@00114.1^ST^30~@00114.2^ST^30~
 @00114.3^ST^20~@00114.4^ST^2~@00114.5^ST^5~@00122^ST^11~
 @00110^TS^8<CR>
RDT|Evans|Aaron|105 Maple St.||Lancaster|PA|19786|156-96-2542|19520809<cr>
RDT|Evans|Bart|166 Norwood Ln.||Hershey|PA|19987|765-58-4615|19701217<cr>
RDT|Evans|Beth|15 Elmwood Ct.|Apt. 15|Gap|PA|19724|58-96-7619|19401119<cr>
RDT|Evans|Carolyn|903 Diane Circle||Phoenixville|PA|19460|156-96-2542|19620324<cr>
DSC|00005<cr>

A continuation query would echo back the contents of DSC-1- continuation pointert.

2.25.4.2.6 Embedded query language continuation
MSH|^~\|CLINIC||CENTRAL-REG|||EQQ|MSG00002|P|2.3<CR>
EQL|TAG001|T|SQL_PID_QRY_01|SELECT @00108.1,@00108.2,@00114.1,@00114.2,
 @00114.3,@00114.4,@00114.5,@00122,@00110 
 FROM PID WHERE @00108.1=‘EVANS’<CR>
DSC|00005<cr>
2.25.4.2.7 Virtual table query continuation
MSH|^~\|CLINIC||CENTRAL-REG|||VQQ|MSG00002|P|2.3<CR>
VTQ| TAG001|T | VTQ_PID_QRY_01|PID|@00108.1^EQ^EVANS<CR>
RDF|9|@00108.1^ST^20~@00108.2^ST^20~@00114.1^ST^30~@00114.2^ST^30~
 @00114.3^ST^20~@00114.4^ST^2~@00114.5^ST^5~@00122^ST^11~
 @00110^TS^8<CR>
DSC|00005<cr>
2.25.4.2.8 Stored procedure request query continuation
MSH|^~\|CLINIC||CENTRAL-REG|||SPQ|MSG00002|P|2.3<CR>
SPR|TAG0001|T|SPR_PID_QRY_01|@00108.1^EVANS<CR>
RDF|9|@00108.1^ST^20~@00108.2^ST^20~@00114.1^ST^30~@00114.2^ST^30~
 @00114.3^ST^20~@00114.4^ST^2~@00114.5^ST^5~@00122^ST^11~
 @00110^TS^8<CR>
DSC|00005<cr>
2.25.4.2.9 This response shows that there is no further data by leaving the continuation pointer not present. This could be done by sending the DSC segment ID with no data, but the example does the same thing by totally omitting the DSC segment
MSH|^~\|CENTRAL-REG||CLINIC|||TBR|MSG00003|P|2.3<CR>
MSA|AA|MSG00002<CR>
QAK|TAG0001|OK<CR>
RDF|9|@00108.1^ST^20~@00108.2^ST^20~@00114.1^ST^30~@00114.2^ST^30~
 @00114.3^ST^20~@00114.4^ST^2~@00114.5^ST^5~@00122^ST^11~
 @00110^TS^8<CR>
RDT|Evans|William|609 N. 3rd St.||Manheim|PA|19898|169-03-9872|19290726<cr>
RDT|Evans|Zachary|111 North Ln.||Lancaster|PA|19987|539-43-8725|19340926<cr>
2.25.4.2.10 Suppose that from the table of "Evans," Carolyn Evans is selected and the querying application now needs detailed ADT information about her. It can issue another query for this information using the event replay query (EQQ).
MSH|^~\|CLINIC||CENTRAL-REG|||RQQ|MSG00004|P|2.3<CR>
ERQ|TAG0002|A04|@00122^156-96-2542<CR>
2.25.4.2.11 The response is returned as an Event Replay Response, which is the HL7 ADT patient registration message corresponding to event code A04, prefixed by the MSH, MSA and ERQ segments:
MSH|^~\|CLINIC||CENTRAL-REG|||ERP|MSG00005|P|2.3<CR>
MSA|AA|MSG00004<CR>
ERQ|TAG0002|A04|@00122^156-96-2542<CR>
QAK|TAG0002|OK<CR>
EVN|A04|199405151259||<cr>
PID|||2-68708-5|253763|EVANS^CAROLYN||19620324|F|||903
 Diane Circle^^PHOENIXVILLE^PA^19460|(610)555-1212|
 (610)555-1212||S|C||156-96-2542||<cr>
NK1||EVANS^RICHARD|SPOUSE|903Diane Circle^^PHOENIXVILLE^
 PA^19460|(610)555-1212|<cr>
PV1||E|EMERG||||0148^ADDISON^JAMES<cr>
..etc

Error responses to the above queries might look like the following:

2.25.4.2.12 Embedded query language (EQL) , virtual table, and stored procedure error response
MSH|^~\|CENTRAL-REG||CLINIC|||TBR|MSG99001|P|2.3<CR>
MSA|AE|MSG00001||||^REQUESTED TABLE "PID" IS UNKNOWN<CR>
QAK|TAG0001|AE<CR>
2.25.4.2.13 Event replay error response
MSH|^~\|CENTRAL-REG||CLINIC|||ERP|MSG00005|P|2.3<CR>
MSA|AE|MSG00004||||^REQUESTED EVENT TYPE "A04" NOT SUPPORTED ON THIS SYSTEM<CR>
QAK|TAG0002|AE<CR>

Previous Page TOC Index Next Page