HL7 v2
hl7 parse <text>
Description
Parse a message or a batch into JSON: separators, message_type, trigger, control_id, version, sending_app, sending_facility, receiving_app, receiving_facility, datetime (ISO 8601 when valid), segments [{name, fields}]; batch and message_count when the input is a batch
Parse a message or a batch into JSON: separators, message_type, trigger, control_id, version, sending_app, sending_facility, receiving_app, receiving_facility, datetime (ISO 8601 when valid), segments [{name, fields}]; batch and message_count when the input is a batch
Parameters
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
admin
hl7 parse "MSH|^~\&|LAB|HOSP|EMR|FAC|202611041200||ADT^A01|MSG7|P|2.5 PID|1||900001^^^HOSP^MR~55512^^^NAT||TESTPATIENT^ALICE"
mentdb
{"separators": {"field": "|", "component": "^", "repetition": "~", "escape": "\\", "subcomponent": "&"}, "message_type": "ADT", "trigger": "A01", "control_id": "MSG7", "version": "2.5", "sending_app": "LAB", "sending_facility": "HOSP", "receiving_app": "EMR", "receiving_facility": "FAC", "datetime": "2026-11-04T12:00", "segments": [{"name": "MSH", "fields": ["|", "^~\\&", "LAB", "HOSP", "EMR", "FAC", "202611041200", "", ["ADT", "A01"], "MSG7", "P", "2.5"]}, {"name": "PID", "fields": ["1", "", {"repetitions": [["900001", "", "", "HOSP", "MR"], ["55512", "", "", "NAT"]]}, "", ["TESTPATIENT", "ALICE"]]}]}
Escape sequences are decoded
admin
hl7 parse "MSH|^~\&|A|B|C|D|2026||ORU^R01|M9|P|2.5 OBX|1|TX|NOTE||Fever \T\ cough\.br\Result \F\ see \S\ note"
mentdb
{"separators": {"field": "|", "component": "^", "repetition": "~", "escape": "\\", "subcomponent": "&"}, "message_type": "ORU", "trigger": "R01", "control_id": "M9", "version": "2.5", "sending_app": "A", "sending_facility": "B", "receiving_app": "C", "receiving_facility": "D", "datetime": "2026", "segments": [{"name": "MSH", "fields": ["|", "^~\\&", "A", "B", "C", "D", "2026", "", ["ORU", "R01"], "M9", "P", "2.5"]}, {"name": "OBX", "fields": ["1", "TX", "NOTE", "", "Fever & cough\ Result | see ^ note"]}]}
A batch file (FHS, BHS, several MSH)
admin
hl7 parse "FHS|^~\&|APP BHS|^~\&|APP MSH|^~\&|A|B|C|D|2026||ADT^A08|M1|P|2.4 PID|1||900001 MSH|^~\&|A|B|C|D|2026||ADT^A08|M2|P|2.4 PID|1||900002 BTS|2 FTS|1"
mentdb
{"separators": {"field": "|", "component": "^", "repetition": "~", "escape": "\\", "subcomponent": "&"}, "message_type": "ADT", "trigger": "A08", "control_id": "M1", "version": "2.4", "sending_app": "A", "sending_facility": "B", "receiving_app": "C", "receiving_facility": "D", "datetime": "2026", "batch": true, "message_count": 2, "segments": [{"name": "FHS", "fields": ["|", "^~\\&", "APP"]}, {"name": "BHS", "fields": ["|", "^~\\&", "APP"]}, {"name": "MSH", "fields": ["|", "^~\\&", "A", "B", "C", "D", "2026", "", ["ADT", "A08"], "M1", "P", "2.4"]}, {"name": "PID", "fields": ["1", "", "900001"]}, {"name": "MSH", "fields": ["|", "^~\\&", "A", "B", "C", "D", "2026", "", ["ADT", "A08"], "M2", "P", "2.4"]}, {"name": "PID", "fields": ["1", "", "900002"]}, {"name": "BTS", "fields": ["2"]}, {"name": "FTS", "fields": ["1"]}]}
hl7 parse <text> <json_params>
Description
Parse with parameters: decode (true; false keeps the escape sequences as written), charset (for a file; by default UTF-8 when the bytes are valid, else ISO-8859-1), max_bytes, max_segments, max_fields
Parse with parameters: decode (true; false keeps the escape sequences as written), charset (for a file; by default UTF-8 when the bytes are valid, else ISO-8859-1), max_bytes, max_segments, max_fields
Parameters
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
json_params: The parameters as a JSON object - String - required
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
json_params: The parameters as a JSON object - String - required
admin
hl7 parse "MSH|^~\&|A|B|C|D|2026||ORU^R01|M9|P|2.5 OBX|1|TX|NOTE||Fever \T\ cough\.br\Result \F\ see \S\ note" "{\"decode\": false}"
mentdb
{"separators": {"field": "|", "component": "^", "repetition": "~", "escape": "\\", "subcomponent": "&"}, "message_type": "ORU", "trigger": "R01", "control_id": "M9", "version": "2.5", "sending_app": "A", "sending_facility": "B", "receiving_app": "C", "receiving_facility": "D", "datetime": "2026", "segments": [{"name": "MSH", "fields": ["|", "^~\\&", "A", "B", "C", "D", "2026", "", ["ORU", "R01"], "M9", "P", "2.5"]}, {"name": "OBX", "fields": ["1", "TX", "NOTE", "", "Fever \\T\\ cough\\.br\\Result \\F\\ see \\S\\ note"]}]}
With a limit on the number of segments
admin
hl7 parse "MSH|^~\&|A PID|1" "{\"max_segments\": 10}"
mentdb
{"separators": {"field": "|", "component": "^", "repetition": "~", "escape": "\\", "subcomponent": "&"}, "message_type": null, "trigger": null, "control_id": null, "version": null, "sending_app": "A", "sending_facility": null, "receiving_app": null, "receiving_facility": null, "datetime": null, "segments": [{"name": "MSH", "fields": ["|", "^~\\&", "A"]}, {"name": "PID", "fields": ["1"]}]}
hl7 get <text> <path>
Description
Read one value by its path, all numbers from 1: SEG[(occurrence)]-field[(repetition)][.component[.subcomponent]]. Gives null for an absent or empty value. A leaf is decoded; an element that still has parts is given as written, with its separators
Read one value by its path, all numbers from 1: SEG[(occurrence)]-field[(repetition)][.component[.subcomponent]]. Gives null for an absent or empty value. A leaf is decoded; an element that still has parts is given as written, with its separators
Parameters
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
path: The path, ex: PID-5.1, OBX(2)-5, PID-3(1).1.2 - String - required
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
path: The path, ex: PID-5.1, OBX(2)-5, PID-3(1).1.2 - String - required
admin
hl7 get "MSH|^~\&|ADTAPP|HOSP|LAB|FAC|20261104101530+0400||ADT^A01^ADT_A01|MSG0001|P|2.5 EVN|A01|20261104101500 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE^MARIE||19800102|F|||1 FICTION ST^^FAKEVILLE^^97400^FRA PV1|1|I|WARD1^101^B^HOSP||||1234^DOCTOR^FAKE|||CARD||||||||INP|V9001" "PID-5.2"
mentdb
ALICE
The value of the second OBX
admin
hl7 get "MSH|^~\&|LAB|HOSP|EMR|FAC|202611041200||ORU^R01|MSG0002|P|2.5 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE||19800102|F OBR|1|ORD1|FIL1|CBC^Blood count^L|||202611041000|||||||||||||||202611041130|||F OBX|1|NM|WBC^Leukocytes^L||6.50|10*9/L|4.00-10.00|N|||F OBX|2|NM|HGB^Hemoglobin^L||9.8|g/dL|12.0-16.0|L|||F" "OBX(2)-5"
mentdb
9.8
A subcomponent of the first repetition
admin
hl7 get "MSH|^~\&|A PID|1||900001^^^HOSP&1.2.3&ISO^MR" "PID-3(1).4.2"
mentdb
1.2.3
MSH-1 is the separator
admin
hl7 get "MSH|^~\&|ADTAPP|HOSP|LAB|FAC|20261104101530+0400||ADT^A01^ADT_A01|MSG0001|P|2.5 EVN|A01|20261104101500 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE^MARIE||19800102|F|||1 FICTION ST^^FAKEVILLE^^97400^FRA PV1|1|I|WARD1^101^B^HOSP||||1234^DOCTOR^FAKE|||CARD||||||||INP|V9001" "MSH-1"
mentdb
|
An absent value
admin
hl7 get "MSH|^~\&|ADTAPP|HOSP|LAB|FAC|20261104101530+0400||ADT^A01^ADT_A01|MSG0001|P|2.5 EVN|A01|20261104101500 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE^MARIE||19800102|F|||1 FICTION ST^^FAKEVILLE^^97400^FRA PV1|1|I|WARD1^101^B^HOSP||||1234^DOCTOR^FAKE|||CARD||||||||INP|V9001" "PV2-1"
mentdb
null
The whole field, with its separators
admin
hl7 get "MSH|^~\&|ADTAPP|HOSP|LAB|FAC|20261104101530+0400||ADT^A01^ADT_A01|MSG0001|P|2.5 EVN|A01|20261104101500 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE^MARIE||19800102|F|||1 FICTION ST^^FAKEVILLE^^97400^FRA PV1|1|I|WARD1^101^B^HOSP||||1234^DOCTOR^FAKE|||CARD||||||||INP|V9001" "PID-5"
mentdb
TESTPATIENT^ALICE^MARIE
Used in use cases (1 recipe)
Integrator & ETL developer › Read a laboratory result in HL7 v2 and answer the sender
Integrator & ETL developer › Read a laboratory result in HL7 v2 and answer the sender
hl7 to_rows <text>
Description
Read a message as business JSON: a list with one object per message and per patient (a message with several PID gives several objects, so that a result is never attached to another patient): header, patient (id, family, given, birth_date, sex, identifiers, names, addresses, phones...), visit, event, results or orders with their observations, appointment, merges, next_of_kin, diagnoses, allergies; other_segments counts the segments that are not read. The type of the message is not checked against the segments
Read a message as business JSON: a list with one object per message and per patient (a message with several PID gives several objects, so that a result is never attached to another patient): header, patient (id, family, given, birth_date, sex, identifiers, names, addresses, phones...), visit, event, results or orders with their observations, appointment, merges, next_of_kin, diagnoses, allergies; other_segments counts the segments that are not read. The type of the message is not checked against the segments
Parameters
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
admin
hl7 to_rows "MSH|^~\&|ADTAPP|HOSP|LAB|FAC|20261104101530+0400||ADT^A01^ADT_A01|MSG0001|P|2.5 EVN|A01|20261104101500 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE^MARIE||19800102|F|||1 FICTION ST^^FAKEVILLE^^97400^FRA PV1|1|I|WARD1^101^B^HOSP||||1234^DOCTOR^FAKE|||CARD||||||||INP|V9001"
mentdb
[{"message_index": 1, "message_type": "ADT", "trigger": "A01", "control_id": "MSG0001", "version": "2.5", "sending_app": "ADTAPP", "sending_facility": "HOSP", "receiving_app": "LAB", "receiving_facility": "FAC", "datetime": "2026-11-04T10:15:30+04:00", "patient": {"id": "900001", "family": "TESTPATIENT", "given": "ALICE", "birth_date": "1980-01-02", "sex": "F", "identifiers": [{"id": "900001", "check_digit": null, "assigning_authority": "HOSP", "type": "MR", "assigning_facility": null}], "names": [{"family": "TESTPATIENT", "given": "ALICE", "middle": "MARIE", "suffix": null, "prefix": null, "type": null}], "addresses": [{"street": "1 FICTION ST", "other": null, "city": "FAKEVILLE", "state": null, "postal_code": "97400", "country": "FRA", "type": null}], "phones": [], "language": null, "marital_status": null, "account_number": null, "ssn": null, "death_datetime": null, "death_indicator": null}, "event": {"type": "A01", "recorded_datetime": "2026-11-04T10:15:00", "reason": null, "occurred_datetime": null}, "visit": {"class": "I", "location": {"point_of_care": "WARD1", "room": "101", "bed": "B", "facility": "HOSP"}, "admission_type": null, "prior_location": null, "attending": {"id": "1234", "family": "DOCTOR", "given": "FAKE"}, "referring": null, "hospital_service": "CARD", "admitting": null, "patient_type": "INP", "visit_number": "V9001", "discharge_disposition": null, "admit_datetime": null, "discharge_datetime": null}}]
ORU: results, values kept as text with units, ranges and flags
admin
hl7 to_rows "MSH|^~\&|LAB|HOSP|EMR|FAC|202611041200||ORU^R01|MSG0002|P|2.5 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE||19800102|F OBR|1|ORD1|FIL1|CBC^Blood count^L|||202611041000|||||||||||||||202611041130|||F OBX|1|NM|WBC^Leukocytes^L||6.50|10*9/L|4.00-10.00|N|||F OBX|2|NM|HGB^Hemoglobin^L||9.8|g/dL|12.0-16.0|L|||F"
mentdb
[{"message_index": 1, "message_type": "ORU", "trigger": "R01", "control_id": "MSG0002", "version": "2.5", "sending_app": "LAB", "sending_facility": "HOSP", "receiving_app": "EMR", "receiving_facility": "FAC", "datetime": "2026-11-04T12:00", "patient": {"id": "900001", "family": "TESTPATIENT", "given": "ALICE", "birth_date": "1980-01-02", "sex": "F", "identifiers": [{"id": "900001", "check_digit": null, "assigning_authority": "HOSP", "type": "MR", "assigning_facility": null}], "names": [{"family": "TESTPATIENT", "given": "ALICE", "middle": null, "suffix": null, "prefix": null, "type": null}], "addresses": [], "phones": [], "language": null, "marital_status": null, "account_number": null, "ssn": null, "death_datetime": null, "death_indicator": null}, "results": [{"placer_order": "ORD1", "filler_order": "FIL1", "service_code": "CBC", "service_text": "Blood count", "service_system": "L", "requested_datetime": null, "observation_datetime": "2026-11-04T10:00", "specimen_received_datetime": null, "ordering_provider": null, "result_datetime": "2026-11-04T11:30", "service_section": null, "result_status": "F", "observations": [{"set_id": "1", "value_type": "NM", "observation_code": "WBC", "observation_text": "Leukocytes", "observation_system": "L", "sub_id": null, "value": "6.50", "units": "10*9/L", "reference_range": "4.00-10.00", "flag": "N", "status": "F", "datetime": null, "producer": null}, {"set_id": "2", "value_type": "NM", "observation_code": "HGB", "observation_text": "Hemoglobin", "observation_system": "L", "sub_id": null, "value": "9.8", "units": "g/dL", "reference_range": "12.0-16.0", "flag": "L", "status": "F", "datetime": null, "producer": null}]}]}]
ORM: an order
admin
hl7 to_rows "MSH|^~\&|EMR|FAC|LAB|HOSP|20261104||ORM^O01|MSG0003|P|2.5 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE ORC|NW|P100||||||||||1234^DOCTOR^FAKE OBR|1|P100||GLU^Glucose^L"
mentdb
[{"message_index": 1, "message_type": "ORM", "trigger": "O01", "control_id": "MSG0003", "version": "2.5", "sending_app": "EMR", "sending_facility": "FAC", "receiving_app": "LAB", "receiving_facility": "HOSP", "datetime": "2026-11-04", "patient": {"id": "900001", "family": "TESTPATIENT", "given": "ALICE", "birth_date": null, "sex": null, "identifiers": [{"id": "900001", "check_digit": null, "assigning_authority": "HOSP", "type": "MR", "assigning_facility": null}], "names": [{"family": "TESTPATIENT", "given": "ALICE", "middle": null, "suffix": null, "prefix": null, "type": null}], "addresses": [], "phones": [], "language": null, "marital_status": null, "account_number": null, "ssn": null, "death_datetime": null, "death_indicator": null}, "orders": [{"order_control": "NW", "placer_order": "P100", "filler_order": null, "placer_group": null, "order_status": null, "transaction_datetime": null, "ordering_provider": {"id": "1234", "family": "DOCTOR", "given": "FAKE"}, "service_code": "GLU", "service_text": "Glucose", "service_system": "L", "requested_datetime": null, "observation_datetime": null, "specimen_received_datetime": null, "result_datetime": null, "service_section": null, "result_status": null}]}]
SIU: an appointment
admin
hl7 to_rows "MSH|^~\&|SCHED|FAC|EMR|HOSP|20261104||SIU^S12|MSG0005|P|2.5 SCH|PL1|FL1|||||CHK^Checkup^L|ROUT^Routine^L|30|min|^^^202611101000^202611101030||||||||||||||BOOKED PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE AIS|1||ECG^Electrocardiogram^L|202611101000|||30|min||BOOKED"
mentdb
[{"message_index": 1, "message_type": "SIU", "trigger": "S12", "control_id": "MSG0005", "version": "2.5", "sending_app": "SCHED", "sending_facility": "FAC", "receiving_app": "EMR", "receiving_facility": "HOSP", "datetime": "2026-11-04", "patient": {"id": "900001", "family": "TESTPATIENT", "given": "ALICE", "birth_date": null, "sex": null, "identifiers": [{"id": "900001", "check_digit": null, "assigning_authority": "HOSP", "type": "MR", "assigning_facility": null}], "names": [{"family": "TESTPATIENT", "given": "ALICE", "middle": null, "suffix": null, "prefix": null, "type": null}], "addresses": [], "phones": [], "language": null, "marital_status": null, "account_number": null, "ssn": null, "death_datetime": null, "death_indicator": null}, "appointment": {"placer_id": "PL1", "filler_id": "FL1", "event_reason_code": null, "event_reason_text": null, "event_reason_system": null, "reason_code": "CHK", "reason_text": "Checkup", "reason_system": "L", "type_code": "ROUT", "type_text": "Routine", "type_system": "L", "duration": "30", "duration_units": "min", "start": "2026-11-10T10:00", "end": "2026-11-10T10:30", "filler_status": "BOOKED", "resources": [{"kind": "service", "id": "ECG", "name": "Electrocardiogram", "start": "2026-11-10T10:00", "duration": "30", "duration_units": "min", "status": "BOOKED"}]}}]
hl7 to_rows <text> <json_params>
Description
Read with parameters: flat (true: one flat row per observation, or per order, appointment or message, with the common columns, to load in a table; a nested value is given as JSON text; next_of_kin, diagnoses, allergies, merges and the other identifiers are only in the default form), charset, max_bytes, max_segments, max_fields
Read with parameters: flat (true: one flat row per observation, or per order, appointment or message, with the common columns, to load in a table; a nested value is given as JSON text; next_of_kin, diagnoses, allergies, merges and the other identifiers are only in the default form), charset, max_bytes, max_segments, max_fields
Parameters
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
json_params: The parameters as a JSON object - String - required
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
json_params: The parameters as a JSON object - String - required
admin
hl7 to_rows "MSH|^~\&|LAB|HOSP|EMR|FAC|202611041200||ORU^R01|MSG0002|P|2.5 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE||19800102|F OBR|1|ORD1|FIL1|CBC^Blood count^L|||202611041000|||||||||||||||202611041130|||F OBX|1|NM|WBC^Leukocytes^L||6.50|10*9/L|4.00-10.00|N|||F OBX|2|NM|HGB^Hemoglobin^L||9.8|g/dL|12.0-16.0|L|||F" "{\"flat\": true}"
mentdb
[{"message_index": 1, "message_type": "ORU", "trigger": "R01", "control_id": "MSG0002", "datetime": "2026-11-04T12:00", "patient_id": "900001", "family": "TESTPATIENT", "given": "ALICE", "birth_date": "1980-01-02", "sex": "F", "visit_number": null, "visit_class": null, "placer_order": "ORD1", "filler_order": "FIL1", "service_code": "CBC", "service_text": "Blood count", "service_system": "L", "requested_datetime": null, "observation_datetime": "2026-11-04T10:00", "specimen_received_datetime": null, "ordering_provider": null, "result_datetime": "2026-11-04T11:30", "service_section": null, "result_status": "F", "set_id": "1", "value_type": "NM", "observation_code": "WBC", "observation_text": "Leukocytes", "observation_system": "L", "sub_id": null, "value": "6.50", "units": "10*9/L", "reference_range": "4.00-10.00", "flag": "N", "status": "F", "value_datetime": null, "producer": null}, {"message_index": 1, "message_type": "ORU", "trigger": "R01", "control_id": "MSG0002", "datetime": "2026-11-04T12:00", "patient_id": "900001", "family": "TESTPATIENT", "given": "ALICE", "birth_date": "1980-01-02", "sex": "F", "visit_number": null, "visit_class": null, "placer_order": "ORD1", "filler_order": "FIL1", "service_code": "CBC", "service_text": "Blood count", "service_system": "L", "requested_datetime": null, "observation_datetime": "2026-11-04T10:00", "specimen_received_datetime": null, "ordering_provider": null, "result_datetime": "2026-11-04T11:30", "service_section": null, "result_status": "F", "set_id": "2", "value_type": "NM", "observation_code": "HGB", "observation_text": "Hemoglobin", "observation_system": "L", "sub_id": null, "value": "9.8", "units": "g/dL", "reference_range": "12.0-16.0", "flag": "L", "status": "F", "value_datetime": null, "producer": null}]
hl7 write <json>
Description
Write a message from JSON (the result of hl7 parse, or a list of segments {name, fields}): values are escaped, segments end with CR. The first segment must be MSH, FHS or BHS; empty separators of a header take the default ones |^~\&
Write a message from JSON (the result of hl7 parse, or a list of segments {name, fields}): values are escaped, segments end with CR. The first segment must be MSH, FHS or BHS; empty separators of a header take the default ones |^~\&
Parameters
json: The message as JSON - String - required
json: The message as JSON - String - required
admin
hl7 write "[{\"name\": \"MSH\", \"fields\": [\"|\", \"^~\\&\", \"APP\", \"FAC\", \"LAB\", \"HOSP\", \"20261104101530\", null, [\"ADT\", \"A08\"], \"MSG1\", \"P\", \"2.5\"]}, {\"name\": \"PID\", \"fields\": [\"1\", null, {\"repetitions\": [\"900001\", [\"55512\", null, null, \"NAT\"]]}, null, [\"TESTPATIENT\", \"ALICE\"]]}, {\"name\": \"NTE\", \"fields\": [\"1\", null, \"Result 5|6, see A&B\"]}]"
mentdb
MSH|^~\&|APP|FAC|LAB|HOSP|20261104101530||ADT^A08|MSG1|P|2.5 PID|1||900001~55512^^^NAT||TESTPATIENT^ALICE NTE|1||Result 5\F\6, see A\T\B
A separator in a value is escaped: it cannot create a field
admin
hl7 write "[{\"name\": \"MSH\"}, {\"name\": \"NTE\", \"fields\": [\"a|b^c~d\"]}]"
mentdb
MSH|^~\& NTE|a\F\b\S\c\R\d
hl7 write <json> <json_params>
Description
Write with parameters: mllp (false; true adds 0x0B and 0x1C 0x0D), line_ending (cr, lf, crlf), line_break (br: \.br\, the default; hex: \X0A\, for a partner that refuses \.br\ outside text fields; a CR is always \X0D\), keep_formatting (true: \H\, \N\, \.sp\... in a value stay commands; false: they are escaped as data), escape (true; false: the values are already escaped, a separator or a control character in a value is refused), separators (an object field, component, repetition, escape, subcomponent)
Write with parameters: mllp (false; true adds 0x0B and 0x1C 0x0D), line_ending (cr, lf, crlf), line_break (br: \.br\, the default; hex: \X0A\, for a partner that refuses \.br\ outside text fields; a CR is always \X0D\), keep_formatting (true: \H\, \N\, \.sp\... in a value stay commands; false: they are escaped as data), escape (true; false: the values are already escaped, a separator or a control character in a value is refused), separators (an object field, component, repetition, escape, subcomponent)
Parameters
json: The message as JSON - String - required
json_params: The parameters as a JSON object - String - required
json: The message as JSON - String - required
json_params: The parameters as a JSON object - String - required
admin
hl7 write "[{\"name\": \"MSH\", \"fields\": [\"|\", \"^~\\&\", \"APP\", \"FAC\", \"LAB\", \"HOSP\", \"20261104101530\", null, [\"ADT\", \"A08\"], \"MSG1\", \"P\", \"2.5\"]}, {\"name\": \"PID\", \"fields\": [\"1\", null, {\"repetitions\": [\"900001\", [\"55512\", null, null, \"NAT\"]]}, null, [\"TESTPATIENT\", \"ALICE\"]]}, {\"name\": \"NTE\", \"fields\": [\"1\", null, \"Result 5|6, see A&B\"]}]" "{\"line_ending\": \"lf\"}"
mentdb
MSH|^~\&|APP|FAC|LAB|HOSP|20261104101530||ADT^A08|MSG1|P|2.5 PID|1||900001~55512^^^NAT||TESTPATIENT^ALICE NTE|1||Result 5\F\6, see A\T\B
Other delimiters
admin
hl7 write "[{\"name\": \"MSH\", \"fields\": [null, null, \"APP\"]}, {\"name\": \"NTE\", \"fields\": [\"a#b\"]}]" "{\"separators\": {\"field\": \"#\"}, \"line_ending\": \"lf\"}"
mentdb
MSH#^~\APP NTE#a\F\b
hl7 ack <text>
Description
Build the acknowledgment of a message, code AA: MSH with the applications swapped, the date of now, a generated control id, MSA with the control id of the message. A batch is refused
Build the acknowledgment of a message, code AA: MSH with the applications swapped, the date of now, a generated control id, MSA with the control id of the message. A batch is refused
Parameters
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
admin
-> "[res]" (hl7 get (hl7 ack "MSH|^~\&|ADTAPP|HOSP|LAB|FAC|20261104101530+0400||ADT^A01^ADT_A01|MSG0001|P|2.5 EVN|A01|20261104101500 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE^MARIE||19800102|F|||1 FICTION ST^^FAKEVILLE^^97400^FRA PV1|1|I|WARD1^101^B^HOSP||||1234^DOCTOR^FAKE|||CARD||||||||INP|V9001") "MSA-1"); [res]
mentdb
AA
hl7 ack <text> <json_params>
Description
Build an acknowledgment with parameters: code (AA, AE, AR, also CA, CE, CR), text (MSA-3), control_id (MSH-10), now (2026-11-04T10:15:00+04:00 or 20261104101500), and those of hl7 parse. Segments end with CR
Build an acknowledgment with parameters: code (AA, AE, AR, also CA, CE, CR), text (MSA-3), control_id (MSH-10), now (2026-11-04T10:15:00+04:00 or 20261104101500), and those of hl7 parse. Segments end with CR
Parameters
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
json_params: The parameters as a JSON object - String - required
text: The message as text, or the path of a file (a name that starts with MSH, FHS or BHS: write ./MSH_01.hl7) - String - required
json_params: The parameters as a JSON object - String - required
admin
-> "[res]" (hl7 get (hl7 ack "MSH|^~\&|ADTAPP|HOSP|LAB|FAC|20261104101530+0400||ADT^A01^ADT_A01|MSG0001|P|2.5 EVN|A01|20261104101500 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE^MARIE||19800102|F|||1 FICTION ST^^FAKEVILLE^^97400^FRA PV1|1|I|WARD1^101^B^HOSP||||1234^DOCTOR^FAKE|||CARD||||||||INP|V9001" "{\"code\": \"AE\", \"text\": \"Unknown ward\", \"control_id\": \"ACK1\", \"now\": \"20261104120000\"}") "MSA-3"); [res]
mentdb
Unknown ward
Used in use cases (1 recipe)
Integrator & ETL developer › Read a laboratory result in HL7 v2 and answer the sender
Integrator & ETL developer › Read a laboratory result in HL7 v2 and answer the sender
hl7 send <host> <port> <message>
Description
Send one message by MLLP (0x0B message 0x1C 0x0D, segments ended by CR) and read the framed answer: sent_bytes, sent_control_id, code, accepted (code AA or CA and the control id of the message in MSA-2), control_id, control_id_match, text, ack (parsed), raw. An AE or AR is a result, not an error. No retry: after a time-out the message may have been received. Timeout 10 s, 1 MB of answer. CLEAR TEXT by default: patient data needs tls true or a VPN
Send one message by MLLP (0x0B message 0x1C 0x0D, segments ended by CR) and read the framed answer: sent_bytes, sent_control_id, code, accepted (code AA or CA and the control id of the message in MSA-2), control_id, control_id_match, text, ack (parsed), raw. An AE or AR is a result, not an error. No retry: after a time-out the message may have been received. Timeout 10 s, 1 MB of answer. CLEAR TEXT by default: patient data needs tls true or a VPN
Parameters
host: The host name or IP address - String - required
port: The port - Number - required
message: One message that starts with MSH (or the path of a file); a batch is refused - String - required
host: The host name or IP address - String - required
port: The port - Number - required
message: One message that starts with MSH (or the path of a file); a batch is refused - String - required
admin
hl7 send "127.0.0.1" "22575" "MSH|^~\&|APP|FAC|LAB|HOSP|20261104||ADT^A01|M100|P|2.5 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE"
mentdb
{"sent_bytes": 101, "sent_control_id": "M100", "code": "AA", "accepted": true, "control_id": "M100", "control_id_match": true, "text": "OK", "ack": {"separators": {"field": "|", "component": "^", "repetition": "~", "escape": "\\", "subcomponent": "&"}, "message_type": "ACK", "trigger": "A01", "control_id": "ACK0001", "version": "2.5", "sending_app": "LAB", "sending_facility": "HOSP", "receiving_app": "APP", "receiving_facility": "FAC", "datetime": "2026-11-04T10:00:01", "segments": [{"name": "MSH", "fields": ["|", "^~\\&", "LAB", "HOSP", "APP", "FAC", "20261104100001", "", ["ACK", "A01", "ACK"], "ACK0001", "P", "2.5"]}, {"name": "MSA", "fields": ["AA", "M100", "OK"]}]}, "raw": "MSH|^~\\&|LAB|HOSP|APP|FAC|20261104100001||ACK^A01^ACK|ACK0001|P|2.5\rMSA|AA|M100|OK\r"}
hl7 send <host> <port> <message> <json_params>
Description
Send with parameters: tls (false; true verifies the certificate and the host name), ca_file (a PEM file of the trusted authorities when tls is true; by default the trust store of Java), timeout_ms (the whole call, 300000 at most), max_bytes (of the answer, 64 MB at most), charset (by default what MSH-18 declares: ASCII, 8859/n or UNICODE UTF-8, else UTF-8; a character that the charset cannot encode is refused before sending; HL7 assumes ASCII when MSH-18 is empty, so declare it for accented text: a receiver may read UTF-8 as garbage otherwise)
Send with parameters: tls (false; true verifies the certificate and the host name), ca_file (a PEM file of the trusted authorities when tls is true; by default the trust store of Java), timeout_ms (the whole call, 300000 at most), max_bytes (of the answer, 64 MB at most), charset (by default what MSH-18 declares: ASCII, 8859/n or UNICODE UTF-8, else UTF-8; a character that the charset cannot encode is refused before sending; HL7 assumes ASCII when MSH-18 is empty, so declare it for accented text: a receiver may read UTF-8 as garbage otherwise)
Parameters
host: The host name or IP address - String - required
port: The port - Number - required
message: One message that starts with MSH - String - required
json_params: The parameters as a JSON object - String - required
host: The host name or IP address - String - required
port: The port - Number - required
message: One message that starts with MSH - String - required
json_params: The parameters as a JSON object - String - required
admin
hl7 send "127.0.0.1" "22575" "MSH|^~\&|APP|FAC|LAB|HOSP|20261104||ADT^A01|CASE-AE|P|2.5 PID|1||900001^^^HOSP^MR||TESTPATIENT^ALICE" "{\"timeout_ms\": 2000, \"max_bytes\": 65536}"
mentdb
{"sent_bytes": 104, "sent_control_id": "CASE-AE", "code": "AE", "accepted": false, "control_id": "CASE-AE", "control_id_match": true, "text": "Field missing", "ack": {"separators": {"field": "|", "component": "^", "repetition": "~", "escape": "\\", "subcomponent": "&"}, "message_type": "ACK", "trigger": "A01", "control_id": "ACK0001", "version": "2.5", "sending_app": "LAB", "sending_facility": "HOSP", "receiving_app": "APP", "receiving_facility": "FAC", "datetime": "2026-11-04T10:00:01", "segments": [{"name": "MSH", "fields": ["|", "^~\\&", "LAB", "HOSP", "APP", "FAC", "20261104100001", "", ["ACK", "A01", "ACK"], "ACK0001", "P", "2.5"]}, {"name": "MSA", "fields": ["AE", "CASE-AE", "Field missing"]}]}, "raw": "MSH|^~\\&|LAB|HOSP|APP|FAC|20261104100001||ACK^A01^ACK|ACK0001|P|2.5\rMSA|AE|CASE-AE|Field missing\r"}
