Healthcare data with Jennifer

Jennifer

A lab result on its way from the analyzer to a FHIR server: ASTM, HL7 v2 and FHIR with the @deckyard/astm, @deckyard/hl7 and @deckyard/fhir decks.

November 2026, by @mplx.
Based on Jennifer 0.27.0

Powered by Jennifer's Cantrip - Markdown into slide decks, https://github.com/jennifer-language/cantrip
1 / 18

Three standards, one sample

analyzer --ASTM E1394 over LIS01 (TCP or serial)--> LIS
LIS      --HL7 v2 ORU^R01 over MLLP-------------->  bridge
bridge   --FHIR R4 transaction over HTTPS-------->  FHIR server
ProgramLinesDecks
analyzer.j, a stand-in for the instrument16astm
lis.j, the laboratory information system76astm, hl7
bridge.j, HL7 in, FHIR out86hl7, fhir
fhirfake.j, the server, for the demo only115none
2 / 18

ASTM: records from the analyzer

H|\^&|||Analyzer^A7^2.1|||||||P||20260312094500
P|1|PAT-1001|||Doe^Jane||19800214|F
O|1|S-2001||^^^GLU\^^^CREA|R||20260312080000||||X||||1||||||||||F
R|1|^^^GLU|5.4|mmol/l|3.9^6.1|N||F||auto||20260312094410|A7
R|2|^^^CREA|133|umol/l|45^90|H||F||auto||20260312094420|A7
L|1|N
3 / 18

Reading results

for (def m in astm.parse($text)) {
    io.printf("from %s\n", astm.component($m.records[0], 5, 1, 1));
    for (def r in astm.results($m)) {
        io.printf("  %s %s %s: %s %s %s\n", $r.patientId, $r.sampleId,
            $r.test, $r.value, $r.units, strings.join($r.flags, ","));
    }
}
from Analyzer
  PAT-1001 S-2001 GLU: 5.4 mmol/l N
  PAT-1001 S-2001 CREA: 133 umol/l H
astm: astm: record 1: no header before "P|1|X"
4 / 18

The link: LIS01 over TCP

# analyzer.j: the instrument side
def link as astm.Link init astm.connect("127.0.0.1:4001",
    astm.instrumentProfile());
astm.send($link, astm.parse($text));

# lis.j: the computer side
def link as astm.Link init astm.accept(astm.listen("127.0.0.1:4001"),
    astm.profile());
for (def m in astm.receive($link, 30000)) { ... }
5 / 18

HL7 v2 in one slide

MSH|^~\&|LIS||FHIRBRIDGE||20261118164607||ORU^R01|LIS00001|P|2.5.1
PID|1||PAT-1001||Doe^Jane||19800214|F
OBR|1||S-2001
OBX|1|NM|14749-6^Glucose [Moles/volume] in Serum or Plasma^LN||5.4|...
PathValue
MSH-9-1ORU, an observation result
PID-5-1, PID-5-2Doe, Jane
OBX(2)-5133, the second OBX's value
6 / 18

Reading with paths, strictly

def m as hl7.Message init hl7.parse($text);
io.printf("%s, %s\n", hl7.get($m, "PID-5-1"), hl7.get($m, "PID-5-2"));
io.printf("%s %s\n", hl7.get($m, "OBX(2)-3-1"), hl7.get($m, "OBX(2)-5"));
hl7.get($m, "PID-5");   # throws
Doe, Jane
14682-9 133
hl7: PID-5 has repetitions, components or subcomponents: "Doe^Jane"
7 / 18

Mapping ASTM to HL7

ASTMHL7 v2Note
P-3 patient IDPID-3the lab's ID, here an MRN
P-6 namePID-5family, given
P-8, P-9PID-7, PID-8birth date, sex
O-3 specimenOBR-3the filler's specimen number
R-3 GLUOBX-3 14749-6^...^LNinstrument code to LOINC
R-4, R-5OBX-5, OBX-6value; unit to UCUM: mmol/l to mmol/L
R-6, R-7OBX-7, OBX-8range, flag
R-13OBX-14time of the observation
8 / 18

Building the ORU^R01

def const TESTS as map of string to list of string init {
    "GLU": ["14749-6", "Glucose [Moles/volume] in Serum or Plasma", "mmol/L"],
    "CREA": ["14682-9", "Creatinine [Moles/volume] in S...", "umol/L"]
};
def oru as hl7.Message init hl7.newMessage("ORU", "R01", $id, "2.5.1");
def t as list of string init TESTS[$r.test];   # a missing key throws
def obx as hl7.Segment init hl7.segment("OBX", $oru.delimiters);
$obx = hl7.setComponent($obx, 3, 1, 1, $t[0]);   # and 3-2, 3-3 "LN"
$obx = hl7.setField($obx, 5, $r.value);
$oru = hl7.addSegment($oru, $obx);
9 / 18

Escapes are not optional

def nte as hl7.Segment init hl7.setField(
    hl7.segment("NTE", $m.delimiters), 3, "fasting & 8 h, see ^ note");
io.printf("%s\n%s\n", hl7.encodeSegment($nte), hl7.field($nte, 3));
NTE|||fasting \T\ 8 h, see \S\ note
fasting & 8 h, see ^ note
10 / 18

MLLP: send, acknowledge, refuse

# lis.j
def mllp as hl7.Connection init hl7.connect("127.0.0.1:2575", hl7.options());
def ack as hl7.Message init hl7.send($mllp, $oru);
io.printf("ack: %s %s\n", hl7.get($ack, "MSA-1"), hl7.get($ack, "MSA-3"));

# bridge.j
func onMessage(m as hl7.Message) {
    ...   # to FHIR, see the next slides
    return hl7.ack($m, "AA", "", "ACK" + hl7.get($m, "MSH-10"));
}
hl7.serve(hl7.listen("127.0.0.1:2575"), hl7.options(), onMessage);
11 / 18

FHIR: the Patient from PID

def p as json.Value init json.map({"resourceType": "Patient"});
$p = json.set($p, "/identifier",
    json.list([fhir.identifier(MRN, hl7.get($m, "PID-3-1"))]));
def name as json.Value init json.map({"family": hl7.get($m, "PID-5-1")});
$name = json.set($name, "/given", json.list([hl7.get($m, "PID-5-2")]));
$p = json.set($p, "/name", json.list([$name]));
$p = json.set($p, "/birthDate", fhirDate(hl7.get($m, "PID-7")));
$p = json.set($p, "/gender", $sex[hl7.get($m, "PID-8")]);   # F -> female
12 / 18

FHIR: an Observation per OBX

$o = json.set($o, "/code", fhir.concept(LOINC,
    hl7.component($obx, 3, 1, 1), hl7.component($obx, 3, 1, 2)));
$o = json.set($o, "/subject", json.map({"reference": $subject}));
def q as json.Value init json.map(
    {"unit": $unit, "system": UCUM, "code": $unit});
$q = json.set($q, "/value", convert.toFloat(hl7.field($obx, 5)));
$o = json.set($o, "/valueQuantity", $q);
"code": {"coding": [{"system": "http://loinc.org", "code": "14682-9", ...
"valueQuantity": {"unit": "umol/L", "system": "http://unitsofmeasure.org", ...
"interpretation": [{"coding": [{"system": ".../v3-ObservationInterpretation", ...
13 / 18

One transaction, all or nothing

def pid as string init "urn:uuid:" + uuid.v4();
def b as json.Value init fhir.bundle("transaction");
$b = fhir.entry($b, "PUT", "Patient?identifier={MRN}|{$mrn}",
    patientFrom($m), $pid);
for (def obx in hl7.segmentsOf($m, "OBX")) {
    $b = fhir.entry($b, "POST", "Observation", observationFrom($obx, $pid), "");
}
def result as json.Value init fhir.transaction($c, $b);
bridge: LIS00001 -> 3 FHIR entries
14 / 18

The first run said AE

ack: AE fhir: an entry URL is relative to the base, such as Patient/123,
got "Patient?identifier=http://example.org/fhir/mrn|PAT-1001"
def const MRN as string init "urn:oid:2.999.1.1";   # was http://example.org/...
15 / 18

Reading it back, and a 404

def c as fhir.Client init fhir.client("http://127.0.0.1:8090/fhir");
for (def o in fhir.search($c, "Observation", ["subject=Patient/1"])) { ... }
try {
    fhir.read($c, "Patient", "999");
} catch (e) {
    if ($e.kind == "fhir.http") {
        io.printf("%d %s: %s\n", $e.status, $e.issues[0].code,
            $e.issues[0].diagnostics);
    }
}
404 not-found: Resource Patient/999 is not known
16 / 18

Before this goes near a real patient

17 / 18

Read more

Based on Jennifer 0.27.0, November 2026.

18 / 18