Skip to content
The Path

Module 5 · The integrator’s job·12 min

Mapping two systems

Mapping table, patient identifiers, code conversion.

Two systems never store things in the same place. The hospital record puts the medical record number in PID-3, the sleep lab software expects it in its own “Patient No.” field. Building that bridge is mapping: a table that says, for each piece of data, where it comes from, where it goes and how it changes on the way.

Here is an admission sent by the Leleux Clinic hospital record. Click PID-3: two identifiers for a single patient.

The hospital record announces Marie Dubois to the sleep lab. PID-3 holds her medical record number and the lab’s internal identifier.

ADT^A01^ADT_A01· Patient admit
||||||||||
||
||||||||
|||||||

The mapping table

This is the core document of the project. One row per piece of data. Here is an excerpt for the interface between the hospital record (HIS) and the sleep lab (SLEEPLAB):

Source (HIS) Target (SLEEPLAB) Rule
PID-3, repetition where CX-4 = LELEUX and CX-5 = MR Record No. Copy CX-1
PID-5.1 Last name Upper case
PID-5.2 First name Copy
PID-7 Date of birth YYYYMMDD to DD/MM/YYYY
PID-8 Sex F to 2, M to 1, anything else to 9
PV1-2 Stay type I to INPT, O to OUTP
PV1-7 Attending doctor Look up in the lab’s doctor list

Each row answers three questions: from where, to where, which transformation. Add a fourth column, “if missing”: what does the interface do when the source is empty? Ignore it, use a default, or block the message? And a fifth, “if ""”, covered below.

The target codes 1, 2, 9, INPT and OUTP belong to an imaginary system. That is the point: every receiver has its own codes, and the table is what links them.

Empty or "": do not mix them up

This is the most common mapping trap. In an update message, two cases look alike but say the opposite:

  • an empty field means “I am telling you nothing about this”: the receiver keeps its value;
  • a field set to "" (two straight double quotes) means “delete the value on your side”.

Marie Dubois no longer has a landline. The hospital record sends an A08 update that clears that number at the sleep lab.

ADT^A08^ADT_A01· Patient update
||||||||||
||
|||||||||||||
|||

Click PID-13: it is "". The lab must delete the phone number it had. If the field were simply empty, it should keep it. A transformation rule that turns "" into empty, or the reverse, either keeps stale data or wipes good data. So add an “if ""” column to the mapping table next to “if missing”, and ask the vendor whether they can send "".

Lengths and truncation

The target system has limited fields: a name on 30 characters, a comment on 255. Check the maximum length on the target side and write down what happens to a value that is too long: truncate, refuse, alert. Silently truncating a double-barrelled name or a medical conclusion is a real risk.

Patient identifiers: CX, authority and type

PID-3 has the CX data type (extended composite ID). Three components really matter:

Component Name In the example
CX-1 ID Number 1024
CX-4 Assigning Authority LELEUX: who issued this number
CX-5 Identifier Type Code MR: what kind of number

A number on its own means nothing. 1024 in the hospital record and 1024 at the lab can be two different people. The authority + type pair is what gives the number its meaning.

Types come from HL7 table 0203. The most common ones:

Code Meaning
MR Medical record number
PI Patient internal identifier
PT Patient external identifier
PN Person number
SS Social Security number
AN Account number
VN Visit number

PID-3 can repeat: finding several identifiers there is normal. So a mapping rule never says “the first repetition”. It says “the repetition whose authority and type are this”.

The MPI: one patient, many numbers

In a hospital, each system often has its own patient number. The MPI (Master Patient Index) keeps the links between all those numbers and one reference identity. When there is one, it is the source of truth. The interface asks it for the right number instead of guessing.

Without an MPI, the hospital record often plays that role, and the other systems receive its MR number alongside their own. The lesson on patient identity shows how a master index links these numbers.

Merges: the A40 event

Sometimes a patient gets registered twice. The day the two records are merged, the other systems must follow. That is the job of the A40 event (merge patient, patient identifier list):

Record 2099 was a duplicate. It is merged into record 1024, the correct one.

ADT^A40^ADT_A39· Merge patient
||||||||||
||
||||||||
|

PID-3 carries the correct identifier, MRG-1 the one to retire. The receiver must move everything filed under 2099 to record 1024. If your interface ignores A40 messages, duplicates live on in the target system. Put merges in the mapping table from day one.

Two facts from the field. Many receiving systems do not handle A40: check it in their specification. And a merge is very hard to undo: there is no simple message to cancel it. A wrong merge mixes up the records of two people, and that is a clinical incident.

Converting codes: from local to LOINC

Tests and results often carry a local code. The Leleux Clinic lab codes blood glucose as GLU. The receiver expects LOINC. The conversion table:

Local code Local label LOINC code LOINC name
GLU Glucose 2345-7 Glucose [Mass/volume] in Serum or Plasma

In OBX-3, the result goes from GLU^Glucose^L to 2345-7^Glucose [Mass/volume] in Serum or Plasma^LN. The third component says which code system is used: L for local, LN for LOINC.

A code mapping is validated with the lab. A LOINC code pins down what is measured, in which specimen, with which unit. Picking “the closest one” casually distorts the result.

A code conversion goes with a unit conversion (OBX-6, in UCUM if possible, for example mg/dL versus mmol/L) and a reference range conversion (OBX-7). The terminologies lesson covers UCUM. And in v2, the decimal separator of a number (NM) is always the point: 28,5 is not a valid value, even if the software screen shows it that way.

Dates, times and time zones

HL7 v2.5.1 dates use the YYYYMMDDHHMMSS format, followed by an optional offset from universal time: 20260627031500+0200. With no offset, the standard says the time is in the sender’s local time zone.

In Belgium, the offset is +0100 in winter and +0200 in summer. On the night of 25 October 2026, the hour between 2 and 3 am happens twice. For a sleep lab recording all night long, that is not a detail. State in the specification whether times are sent with an offset, and test a night with a clock change.

And in FHIR?

The CX becomes an Identifier, with a system (the authority, as a URI) and a value:

{ "system": "urn:oid:1.2.3.4.5", "value": "1024",
  "type": { "coding": [{ "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR" }] } }

The OID is made up. A merge maps to Patient.link, with type replaced-by or replaces.

Check your understanding

1 of 4

The hospital record sends PID-3 = 1024^^^LELEUX^MR~P-55821^^^SLEEPLAB^PI. The sleep lab result must be filed under the right record in the clinic’s hospital record. Which identifier should your rule pick?

+50 XPPass the quiz (3 correct answers) to complete the lesson.

Reviewed and checked on 27 September 2026