Most FHIR mapping guides start from HL7 v2, but many projects start somewhere messier: a practice database with its own tables, a nightly CSV export, or JSON from a home device vendor. None of these sources was designed with FHIR in mind, and each hides assumptions about identity, units and empty fields.
This post is for engineers and product teams turning that kind of data into FHIR resources that pass profile validation. It covers identifiers, cardinality, units, missing values, provenance, the choice between StructureMap and code, and testing.
What is FHIR data mapping?
Connecting a custom source to FHIR?
Our FHIR integration page covers how we connect databases, files and device feeds to FHIR servers and EHR APIs.
FHIR data mapping is the work of turning records from a source system into FHIR resources that conform to a chosen profile, with every field, code, unit and identifier accounted for. Agnotic Technologies treats each map as a versioned specification with tests, because a mapping that only lives inside a script cannot be reviewed or repeated.
The hard part is rarely the syntax. It is deciding what the source meant, for example whether an empty cell means unknown, not measured or zero, and writing that decision down.
Start from the target profile
Begin with the profile the receiving server or partner requires, not with the source columns. The profile tells you which elements are required, which must be supported and which code systems are expected.
Then write a mapping specification: one line per target element, naming the source field, the transform and the rule when the source is empty. Reviewers read the specification, and engineers build from it.
- Target element: the FHIR path, such as Observation.valueQuantity.value, with its cardinality.
- Source: the table and column, CSV header or JSON path that feeds it.
- Transform: the conversion, lookup or default, written in plain words.
- Empty rule: what happens when the source has no value, and who agreed it.
Run each source record through four stages: extract, map, validate against the profile and terminology, then load. Keep the specification version on every load so any resource can be traced to the rules that built it.
How should identifiers be mapped?
Map every source identifier to a FHIR Identifier with a system URI that names who issued it, plus the value. A medical record number without a system becomes ambiguous the moment a second clinic sends data.
Keep the business identifier separate from the server's resource id. Use conditional create or update keyed on the identifier, so a resent CSV row updates the existing Patient instead of creating a duplicate.
- Patient numbers: one system URI per issuing organization or source system.
- Device serials: held on a Device resource, so readings can reference the device that produced them.
- Row keys: kept as an identifier when the source has no stable business key.
- Merged records: a rule for how source merges reach FHIR, written before the first load.
What breaks on cardinality and data types?
Cardinality breaks when one source field holds several values, or several fields describe one repeating element. Data types break when the source stores dates, flags or numbers as loose text.
- Packed fields: "asthma; COPD" in one column must become two Condition resources, not one.
- Spread fields: phone_home, phone_work and phone_mobile become three telecom entries with use codes.
- Dates: a local timestamp without an offset needs a declared time zone before it becomes a FHIR dateTime.
- Flags: Y, N, 1, 0 and blank must map to true, false or absent by an agreed rule.
When the target element allows one value and the source has two, do not keep the first and drop the second silently. Send the record to a review queue, or apply a documented rule such as keeping the most recent value.
How do you handle units?
Convert source units to UCUM codes and keep the original unit text for display only. Device payloads often send "bpm", "lbs" or "mm Hg" as free strings, which a receiving system cannot compare reliably.
HL7 FHIR R4 says that when a Quantity's unit can be coded in UCUM and a code is provided, it should be a UCUM code, and a UCUM code lets a system generate a canonical value for comparing quantities.
Build a unit table for each source, with the source string, the UCUM code and any conversion factor. Reject a reading whose unit is not in the table instead of guessing, and add the unit once someone confirms it.
When the source has no value
A missing value needs a reason, not a made-up default. An empty cell can mean the question was not asked, the patient declined, the device failed or the field did not exist in older records.
HL7 FHIR R4 defines a core data-absent-reason extension that gives the reason why an expected value or element is missing.
Agree the empty rules with the clinical owner for each element. Never fill a required element with a placeholder such as 0 or the word unknown just to pass validation, because reports downstream will count it as real data.
How do you record where data came from?
Record the source on every resource, at two levels. Put a source marker and batch tag in the resource metadata, and write Provenance records when partners need to see who produced the data and how.
In HL7 FHIR R4, a Provenance resource is a record that describes the entities and processes involved in producing, delivering or otherwise influencing a resource, and it supports assessing authenticity and reproducing results.
In practice, one Provenance record per load batch that targets the resources it created is often enough. It names the source system, the specification version and the time of the run, which answers most audit questions without per-field records.
Should you use StructureMap or code?
Use ordinary code for most production maps, and consider StructureMap when maps must be shared, reviewed by analysts or run by a toolchain that executes them. FHIR defines StructureMap as a map of relationships between two structures that can be used to transform data.
- Code (TypeScript, Java, Python): easy to test, debug and deploy with the rest of the pipeline.
- StructureMap with the FHIR Mapping Language: portable and declarative, but fewer engineers know it.
- Hybrid: lookups and unit tables as data files, structure in code, all under version control.
Whatever the choice, keep lookup tables out of the transform logic. Unit tables, code maps and identifier systems change more often than the mapping structure, and they deserve their own review.
Mapping failure points
Most mapping failures pass validation and show up later as wrong numbers in a chart or a report. These are the ones to look for first.
- Silent defaults: blank values turned into zero, false or the load date.
- Lost precision: 98.60 stored as 98.6, or a decimal rounded to an integer by a CSV parser.
- Time zone drift: device times in UTC loaded as local time, so readings shift by hours.
- Duplicate patients: no identifier system, so every reload creates new records.
- Profile drift: the partner moves to a new profile version and the map is never updated.
Each of these is cheaper to block in the pipeline than to clean up later. Fail the record, write the reason to a reject queue, and report reject counts on every run.
A worked example: a blood pressure cuff vendor feed
A remote monitoring program receives JSON from a cuff vendor: a device serial, a patient number, systolic and diastolic values, a pulse, a unit string and a UTC timestamp. The target is a vital signs blood pressure profile on the program's FHIR server.
The map resolves the patient number through the program's identifier system, links the serial to a Device, and builds one Observation coded LOINC 85354-9 with components for systolic (8480-6) and diastolic (8462-4). The unit string "mmHg" maps to the UCUM code mm[Hg].
Pulse becomes a separate heart rate Observation. Readings missing a diastolic value are rejected with a reason rather than loaded half complete, and each nightly batch gets one Provenance record naming the vendor feed and the specification version.
Who owns each decision in a FHIR mapping project?
A mapping project needs a named owner for each decision, because the hardest questions are about meaning, not code.
- Source system owner: what each field means, how it is filled and when it changes.
- Clinical or product owner: empty rules, unit choices and anything that changes how data reads.
- Receiving partner: the profile version, required elements and terminology expectations.
- Engineering team: the specification, transforms, validation, reject queue and run reports.
How do you test a FHIR mapping?
Test a mapping with realistic fixtures for every rule in the specification, then validate every output against the target profile. Passing validation proves structure, so add value checks that prove meaning.
- Fixture per rule: one source record for each transform, empty rule and unit conversion.
- Profile validation: every generated resource run through a FHIR validator in CI.
- Value comparison: sample values compared between source and FHIR output, field by field.
- Run report: counts in, counts loaded, counts rejected and the top reject reasons.
Keep fixtures synthetic or de-identified. When a production record fails in a new way, turn it into a synthetic fixture so the case stays covered.
What are FHIR data mapping best practices?
Write the mapping specification before the code, name an identifier system for every source, and convert units to UCUM through a reviewed table. Give every missing value a reason and never use placeholder values to pass validation.
Tag each resource with its source and batch, version the specification, test every rule with a fixture and report rejects on every run.
How can Agnotic help map your data to FHIR profiles?
Agnotic maps custom databases, file exports and device feeds to FHIR profiles for health systems, digital health companies and device makers. We write the mapping specification with your owners, build the transforms and validation, and hand over tests and run reports your team can maintain.
Map your source data to FHIR with Agnotic
We build mapping pipelines that pass profile validation and keep a trail back to the source.
Related reading on Agnotic
FHIR mapping, profiles and testing.


