Medical Instrument Middleware, Prolab LIS Cloud

Interfacing the Biobase Biochemistry Analyzer with a LIS via HL7 over TCP/IP

1. Overview

The Biobase biochemistry analyzer communicates results over a local TCP/IP connection. The middleware listens on a fixed socket, receives a one-shot HL7 v2.3.1 ORU^R01 message encoded in hexadecimal, decodes and parses it, then writes structured result records into the Prolab LIS database — matching results to orders via barcode when present.

Stack:

  • Transport: TCP socket — middleware listens on 192.168.1.96:502
  • Protocol: HL7 v2.3.1 ORU^R01
  • Encoding: Raw hex over TCP (single transmission per result set)
  • Target LIS: Prolab

2. Message Flow

Biobase Analyzer
     │
     │  TCP connect → 192.168.1.96:502
     │  Sends: hex-encoded HL7 ORU^R01 (one shot)
     ▼
Linux Middleware (proline)
     │
     ├─ 1. Receive raw hex bytes
     ├─ 2. Decode hex → UTF-8 HL7 string
     ├─ 3. Parse HL7 segments (MSH / PID / OBR / OBX)
     ├─ 4. Extract barcode from PID-4 or OBR-3
     ├─ 5. Map OBX lines → Prolab result records
     └─ 6. Write to Prolab LIS

3. HL7 Message Structure

A typical transmission contains one MSH block per result set. The segments of interest are:

SegmentKey Fields Used
MSHSending app (BIOBASE), equipment ID (BK-400), message timestamp
PIDPatient ID, patient name, barcode (field 4), sex
OBROrder ID, sample barcode (field 3), collection timestamp
OBXSequence, value type (NM), LOINC-like code, test name, value, units, reference range, flag (H/L/N)

Example OBX line:

OBX|0|NM|246|AST BB|46.73|U/L|0~40|H|||||46.73|20260308160336||1000||

Fields: sequence | valueType | code | name | value | units | range | flag | ... | timestamp

4. Hex Decoding

The analyzer transmits the HL7 payload as a hex string. The first middleware step is decoding:

raw_hex = receive_from_socket()           # e.g. "4d53487c5e7e5c26..."
hl7_string = bytes.fromhex(raw_hex).decode("utf-8")
segments = hl7_string.strip().split("r")  # HL7 segment delimiter is CR

Note: HL7 v2 uses carriage return (r, 0x0D) as the segment terminator, not newline.

5. Barcode Extraction

When a barcode is present, it appears in two locations:

  • PID-4 — patient/sample barcode (e.g. 142 for patient Fatou BA)
  • OBR-3 — filler order number / sample ID (e.g. 21346159068142)

Anonymous samples (bench QC, calibrators) have no barcode; the middleware falls back to the internal messageControlId for record matching.

pid_fields = segments["PID"].split("|")
barcode = pid_fields[3] if len(pid_fields) > 3 and pid_fields[3] else None

obr_fields = segments["OBR"].split("|")
sample_id = obr_fields[2]  # OBR-3: filler order number

6. OBX → Prolab Record Mapping

Each OBX segment maps to one result line in Prolab:

HL7 OBX FieldProlab Field
OBX-3 (code)Test code
OBX-4 (name)Test label
OBX-5 (value)Result value
OBX-6 (units)Unit
OBX-7 (range)Reference interval
OBX-8 (flag)Abnormality flag (H / L / N)
OBX-14 (timestamp)Result datetime

Flags are normalized before insertion: HHigh, LLow, NNormal (or absent).

7. Two Message Patterns

The Biobase emits two distinct PID patterns depending on context:

Anonymous sample (no patient, bench test):

PID|17||||BS1|||O|...

Barcode absent — middleware assigns a synthetic ID from the message control number.

Named patient sample (with barcode):

PID|20|||142|Fatou BA|||F|...
OBR|2|21346159068142|2|...

Barcode 142 links the result set to the Prolab worklist order for that patient.

8. Reference Unit Considerations

Biobase transmits values in conventional units (g/L, mg/L, U/L). Prolab may store in SI units depending on laboratory configuration. The middleware applies conversion factors where needed — for example:

TestBiobase UnitSI Conversion
Creatinine (CREA)mg/L× 8.84 → µmol/L
Urea (URES)g/L× 16.65 → mmol/L
Uric acid (ACUR)mg/L× 5.95 → µmol/L
Glucose (GAJ)g/L× 5.55 → mmol/L

9. Error Handling

ConditionBehaviour
Malformed hex stringLog error, discard message, keep socket open
Missing barcodeInsert with null order reference, flag for manual matching
Unknown test codeLog unmapped OBX, insert raw with warning
Duplicate messageControlIdSkip insertion, log duplicate

10. Deployment Notes

  • Middleware runs as a Linux service on the proline host
  • Socket must bind before the analyzer is powered on (Biobase connects at boot/result-ready)
  • The connection is one-shot per result set — the analyzer connects, sends, disconnects
  • No ACK is required by the analyzer; the middleware operates in receive-only mode on this port