HL7 RSP_K31 Dispense History Response

HL7 message structure RSP_K31 groups and segments from HL7 v2.5.1 Hide structure

These are the generated groups and segments for the version selected at the top of the page. The article explains the workflow, and this panel follows the chosen HL7 version.

Message Structure

SegmentNameRequiredRepeatable
Message Header Yes No
Message Acknowledgment Yes No
Error No Yes
Software Segment No Yes
Query Acknowledgment Yes No
Query Parameter Definition Yes No
Response Control Parameter Yes No
RSP_K31.RESPONSE
Response group Yes Yes
RSP_K31.PATIENT
Patient group No No
Patient Identification Yes No
Patient Additional Demographic No No
Notes and Comments No Yes
Patient Allergy Information No Yes
RSP_K31.PATIENT_VISIT
Patient Visit group No No
Patient Visit Yes No
Patient Visit - Additional Information No No
RSP_K31.ORDER
Order group Yes Yes
Common Order Yes No
RSP_K31.TIMING
Timing group No Yes
Timing/Quantity Yes No
Timing/Quantity Relationship No Yes
RSP_K31.ORDER_DETAIL
Order Detail group No No
Pharmacy/Treatment Order Yes No
Notes and Comments No Yes
Pharmacy/Treatment Route Yes Yes
RSP_K31.COMPONENTS
Components group No Yes
Pharmacy/Treatment Component Order Yes No
Notes and Comments No Yes
RSP_K31.ENCODING
Encoding group No No
Pharmacy/Treatment Encoded Order Yes No
RSP_K31.TIMING_ENCODED
Timing Encoded group Yes Yes
Timing/Quantity Yes No
Timing/Quantity Relationship No Yes
Pharmacy/Treatment Route Yes Yes
Pharmacy/Treatment Component Order No Yes
Pharmacy/Treatment Dispense Yes No
Pharmacy/Treatment Route Yes Yes
Pharmacy/Treatment Component Order No Yes
RSP_K31.OBSERVATION
Observation group Yes Yes
Observation/Result No No
Notes and Comments No Yes
Continuation Pointer No No

RSP_K31 is a dispense history response. It is the answer side of a pharmacy query where the requester needs historical dispense details for a patient, medication, or pharmacy workflow. Compared with simple query responses, it carries a full patient/order/pharmacy shape.

The message can be dense because dispense history has to connect patient identity, order identifiers, timing, medication details, route, actual dispense information, components, and optional observations. That is exactly why it deserves a careful implementation guide rather than a quick "response with RXD" note.

A small RSP K31 example

MSH|^~\&|PHARMACY|CITYHOSP|MEDREC|CITYHOSP|20260717113000||RSP^K31^RSP_K31|RSP310001|P|2.5.1 MSA|AA|QBP310001 QAK|Q310001|OK|Q31^Dispense history^HL7nnn|1 QPD|Q31^Dispense history^HL7nnn|Q310001|123456^^^CITYHOSP^MR RCP|I|10^RD PID|1||123456^^^CITYHOSP^MR||Smith^Jane^Anne^^Ms^^L||19800314|F ORC|RE|RXO1001^CITYHOSP|RXD9001^PHARM TQ1|1||||||20260715080000|20260722080000 RXD|1|8756^Amoxicillin 500mg capsule^RXNORM|20260715103000|21|CAP|RXD9001^PHARM|Take one capsule three times daily RXR|PO^Oral^HL70162 OBX|1|CWE|RXHISTSTAT^Dispense status^L||CM^Completed^HL70322

What workflow it represents

A requester asks for pharmacy dispense history and the pharmacy or medication record system returns one or more response groups. The requester may use it for medication reconciliation, clinical review, refill support, audit, or a downstream medication history display.

This is not the same as an order message. An order says what was requested or authorized. RSP_K31 is about the response to a query for dispense history, so the important question is what the pharmacy says actually happened.

How to read the structure

The top of the message combines response control and query correlation: MSH, MSA, optional ERR, QAK, QPD, and RCP. Those segments tell the requester what query was answered and whether the answer is complete or limited.

Each response contains an optional patient group with PID, optional PD1, notes, allergies, and visit details. The required order group starts with ORC and can include timing, order detail, encoded order, dispense, route, component, and observation information.

Pharmacy detail that receivers care about

RXD is the practical center of dispense history. It carries the dispensed drug, dispense date/time, quantity, units, dispense number, and related dispense details. RXR gives route, which matters when a medication name alone is not enough. RXC can describe components when the product is compound or needs component-level detail.

Optional OBX segments are useful for status, clinical notes, adherence indicators, or local facts that do not fit cleanly in the RX segments. Use them carefully and code OBX-3 well, because pharmacy history quickly becomes hard to reconcile when every site invents different observation names.

Implementation traps

Do not collapse order identifiers and dispense identifiers into one local field. ORC placer and filler IDs, RXD dispense numbers, and pharmacy transaction IDs answer different questions during reconciliation and support calls.

Also be clear about what counts as "history." Some responders return only completed dispenses. Others include partial fills, canceled fills, transferred prescriptions, or administrations. QAK may say the query worked while the business meaning still differs from what the requester expected.

Reference notes

The HL7 v2+ refactored RSP_K31 structure shows a required repeating response group with optional patient details and required pharmacy order detail, including ORC, timing, RXO/RXE/RXD, RXR, RXC, OBX, and DSC for continuation.