Map fields, look up codes and run JavaScript
Reshape an HL7v2 lab result into JSON with a Data Map, translate local test codes with a code table, and add a JavaScript step, testing the output after each step.
On this page
This guide reshapes a lab result before the engine sends it on. A lab sends an HL7v2 ORU^R01 message, and the receiving registry wants flat JSON with LOINC codes and a high, low or normal flag. You use three tools: a code table, a Data Map with value ops, and a JavaScript step. You test the output with a sample message after each one.
Here is the flow.
flowchart LR
A[ORU^R01 over MLLP] --> B[Data Map]
B --> C[JavaScript]
C --> D[POST JSON to the registry]
T[(lab-codes code table)] -.-> BThe Data Map picks fields out of the message and writes them to JSON paths. On the way, a row can change its value with ops and translate it with a code table. The JavaScript step receives the Data Map's output and returns what the registry gets.
Before you start
- A running engine and a user with the
operatorrole or above. See the Quick start. - A workflow with an MLLP listener source, and a saved sample message. See Test with sample messages.
- A Generic REST API adapter profile for the registry, for example with the base URL
https://registry.example.test/results. See HL7v2 over MLLP to a JSON webhook.
If the assistant is on (off by default), you can ask it for the workflow on the Agent screen, for example "Draft a workflow that takes ORU^R01 over MLLP and posts JSON to a registry". It drafts a disabled workflow; choose Save as draft, then continue from step 1 here.
This guide uses this synthetic sample, one glucose result for TESTPATIENT:
MSH|^~\&|LAB|DEMOHEALTH|MEDHOOK|EXAMPLE|20261019140000||ORU^R01^ORU_R01|DOCS0002|T|2.5.1
PID|1||TEST000123^^^EXAMPLE^MR||TESTPATIENT^ALPHA^A||19800101|F
OBR|1||LAB0001|GLU^Glucose^L|||20261019133000
OBX|1|NM|GLU^Glucose^L||182|mg/dL|70-99|H|||F|||20261019133000Steps
1. Create a code table
The lab uses its own test codes, such as GLU for glucose. The registry wants LOINC codes. A code table translates one into the other.
Open Code Tables at /code-tables on your engine. Under New code table, set Table name to lab-codes and paste two columns into CSV, the lab's code and then the LOINC code:
source,target
GLU,2345-7
K,2823-3
NA,2951-2The page checks the CSV before it saves anything and shows how many entries are ready. Choose Create table. The table appears under Tables with its entry count.
History and restore
Every save of a code table is kept as a version: when you create it, each edit, each restore and each import. Choose History on a table's row to see them, newest first, with who saved each one, when, the note they left and how many codes it added, removed and changed. When you edit a table, What changed next to Save table takes an optional note for that version.
- Changes shows the rows a version changed against the one before it: added and removed codes, and each changed code's old row above its new one.
- Restore puts an older version's rows and columns back. Before anything changes, it shows what the restore changes in the table now and asks you to confirm. The restore is saved as a new version, so you can undo it the same way. The table keeps its current name, and running workflows use the restored rows within about a second.
The engine keeps the newest 200 versions of each table and deletes older ones. Set CODE_TABLE_HISTORY_MAX_VERSIONS on the engine to keep more or fewer (2 to 10,000). A configuration bundle or workflow bundle carries each table's current rows only, not its history: importing one saves a new version on the receiving engine.
2. Add a destination and load the sample
Open the workflow from Workflows. In the Sample message panel, choose Load sample. Choose + Add destination in the Steps list and set Destination name, for example Results registry.
3. Map the fields with a Data Map
Under Output, choose + Add output step and set the output to Data map → JSON. The Data Map lists every field of the sample with its value. Next to Show, choose All to see all of them, or Mapped to see only the fields you have mapped. Build new (the default) builds a new object from your rows.
Type a path in a field's Target path and press Enter to map it. A field with components, such as PID-3, holds all of them, separated by ^. Mapping the whole field sends them all. Open the field to show its components, and map only the one you need.
| Field | Sample value | Target path |
|---|---|---|
PID.3.1 | TEST000123 | mrn |
PID.7 | 19800101 | birthDate |
OBX.3.1 | GLU | code |
OBX.5 | 182 | value |
OBX.6 | mg/dL | unit |
OBX.7 | 70-99 | range |
4. Add value rules
The cog at the end of a row opens its rules: Transform, Code table, Value ops and Default value. Choose Apply to keep them. The row then shows its rules under the target path.
- On
PID.7, choose + Add op and pick Date format. With from set toautoand to set toYYYY-MM-DD,19800101becomes1980-01-01. - On
OBX.3.1, set Code table tolab-codes.GLUbecomes2345-7. - On
OBX.5, add the op Type, set tonumber, so the registry gets182, not"182".
When the code table has no entry decides what happens to a code the table does not hold. The default, Fail the row, fails the message, so an unmapped clinical code stops instead of slipping through. Keep the value passes it through unchanged, and Use the default value writes the row's Default value.
5. Test the Data Map
Under Send, pick the registry's Adapter profile and the Action post. Choose Run test. The engine runs the sample through every step, unsaved edits included, and delivers nothing. Under the destination, Would send shows the body:
{
"mrn": "TEST000123",
"birthDate": "1980-01-01",
"code": "2345-7",
"value": 182,
"unit": "mg/dL",
"range": "70-99"
}6. Add a JavaScript step
The registry wants a flag, high, low or normal, instead of the range. Choose + Add output step again. The new step, Output 2, is a JavaScript step that runs after the Data Map. Your code is the body of a function: input is the Data Map's output, and the step sends what you return.
const [low, high] = input.range.split("-").map(Number);
const { range, ...result } = input;
const flag = input.value > high ? "high" : input.value < low ? "low" : "normal";
return { ...result, flag };7. Test again and save
Choose Run test. Would send now ends with "flag": "high", because 182 is above 99, and the range is gone. The Test run panel shows one line per step: the Data Map, the JavaScript step, and the post the destination would make.
Choose Save. From here, deploy the workflow like any other. See Save and deploy.
🎉 The registry now gets clean JSON with LOINC codes and a flag for every lab result. To let AI suggest the mappings for you, read AI-assisted mapping and conditions.