The Path
Module 3 · Message types·12 min
Queries: QBP and RSP
Asking for data instead of waiting for it: QPD, RCP, QAK and paging.
So far, your messages went out on their own. The patient record admits Marie Dubois and pushes an ADT, without anyone asking. But sometimes nothing will ever arrive unless you ask. Here is the sleep lab querying the patient index.
The sleep lab front desk looks for female patients named Dubois. It wants two results per response at most.
Three lines. QPD asks the question, RCP says how to answer. Click RCP-2: “two records at most”.
Wait or ask
HL7 v2 has two ways of exchanging data:
| Model | Who takes the first step | Example |
|---|---|---|
| Unsolicited | whoever has the data | ADT^A01, ORU^R01 |
| Query | whoever needs it | QBP^Q22, answered by RSP^K22 |
An unsolicited feed is perfect when you know in advance who wants what. A query fits when the need shows up in the moment. A nurse at the desk, an unknown patient, one precise question: “does this patient already exist?”.
The question: QPD
QPD-1 names the query: Q22, Find Candidates, a patient search in a central index. QPD-2 is the tag of this particular query (Q0042), chosen by the requester. From QPD-3 on come the parameters. For Q22 they are PID fields: @PID.5.1 for the family name, @PID.8 for sex. QPD-1 also has a 3rd component naming the coding system (the standard writes Q22^Find Candidates^HL7nnnn); in practice it is often left out, as here.
Which parameters a server accepts and which it ignores is written in its query profile (the standard calls it a conformance statement). Without that document, you are guessing.
How to answer: RCP
| Field | Role | Values |
|---|---|---|
RCP-1 |
priority | I immediate, D deferred (table 0091) |
RCP-2 |
maximum quantity | a number and a unit (table 0126) |
RCP-3 |
modality | R real time, T bolus, B batch (table 0394) |
For RCP-2, the unit matters. RD means “records”: in an RSP, a record is one hit, here one patient. LI (lines) is the default, and there a line is one segment. For RCP-3, B asks for the response as a batch file, the format covered in the “Batch files” lesson.
The response: QAK
The index finds three female patients named Dubois. It sends back only two, as asked.
The patient record returns two candidates out of three and says one is left.
Read QAK left to right. QAK-1 echoes the tag. QAK-2 gives the status. Then three counters: QAK-4 the total found (3), QAK-5 what this page holds (2), QAK-6 what is left (1).
| QAK-2 (table 0208) | Meaning |
|---|---|
OK |
data found, no errors |
NF |
no data found, no errors |
AE |
application error |
AR |
application reject |
In 2.5.1, the standard deprecates AE and AR in QAK-2: an error goes into MSA-1 and is described in an ERR segment. And “nothing found” is not an error: MSA|AA with QAK-2 set to NF, and no PID at all.
Paging: DSC
Marie Dubois is not on the first page. The last line, DSC, is the continuation pointer. DSC-1 is an opaque value that belongs to the server. DSC-2 set to I means “interactive continuation” (table 0398).
To get the rest, the lab sends the same query again, with a new MSH-10, and copies the pointer:
MSH|^~\&|SLEEPLAB|LELEUX|HIS|LELEUX|20260615090010||QBP^Q22^QBP_Q21|MSG00072|P|2.5.1
QPD|Q22^Find Candidates|Q0042|@PID.5.1^DUBOIS~@PID.8^F
RCP|I|2^RD
DSC|PG2-7F3A|I
The second response brings the last candidate. No DSC any more: the list is complete.
Compare the two responses. MSA-2 changes (MSG00070, then MSG00072): it follows each query message. QAK-1 stays Q0042: it follows the question. End of data means no DSC, or an empty DSC-1.
Sleep lab
requester
Patient record
patient index
- QBP^Q22 · RCP|I|2^RD
- RSP^K22 · QAK 3|2|1 + DSC
- QBP^Q22 + DSC|PG2-7F3A
- RSP^K22 · QAK 3|1|0
If the lab finds what it needs before the end, it can send a QCN^J01 (cancel query), with a QID segment carrying the tag. The server answers with a plain ACK^J01. It is a courtesy: the server drops the pages it was holding.
Immediate or deferred
With RCP-1 set to I, the server answers straight away and sends no ACK: the acknowledgement is the MSA inside the RSP. One exception: a query the server cannot parse gets a negative ACK straight away. With D, there are two round trips: an ACK right away, then the response later, which the requester acknowledges in turn. Deferred mode is for big reports built overnight.
What about the old QRY?
The first HL7 queries used the QRD and QRF segments, with message type QRY. For example, a request for demographics:
MSH|^~\&|SLEEPLAB|LELEUX|HIS|LELEUX|20260615090000||QRY^A19^QRY_A19|MSG00074|P|2.5.1
QRD|20260615090000|R|I|Q0043|||1^RD|1024^^^^^^^^LELEUX^^^^MR|DEM
Look at QRD-8, the patient the query is about. It is an XCN, a type built for people, not a CX: after the number come family name, given name, middle names, suffix. The assigning authority only shows up in component 9, the identifier type in 13. Hence the row of ^. One more detail that explains why QBP replaced it.
Version 2.5.1 keeps these “original mode queries” for backward compatibility, but lists them as superseded. HL7 recommends recasting them as QBP. You will meet them on older systems: do not build them into a new interface.
In the field, this search often arrives under the label of an IHE profile, PDQ, and its cousin PIX finds a patient’s identifiers across systems. The “Patient identity: PIX and PDQ” lesson covers both.
And in FHIR?
Same idea, over REST: GET /Patient?family=DUBOIS&gender=female&_count=2. The response is a Bundle of type searchset. Bundle.total plays the role of QAK-4, and a next link replaces the DSC.
Check your understanding
1 of 5The first RSP^K22 ends with DSC|PG2-7F3A|I. What does the sleep lab do to get the rest?
+50 XPPass the quiz (4 correct answers) to complete the lesson.
Reviewed and checked on 28 September 2026