Mapping healthcare data to HL7 FHIR resources is crucial for achieving seamless communication and interoperability in the healthcare industry.
Many healthcare organizations operate independently, which creates challenges for data processing and exchange. FHIR specifications aim to solve this issue by standardizing the way data is stored in health systems, thus enabling seamless healthcare data exchange. In fact, with the 21st Century Cures Act going into effect, FHIR adoption has already become mandatory for healthcare organizations in the US.
However, given the complexity, diversity, and volume of the clinical data aggregated by healthcare organizations, FHIR implementation becomes a difficult and time-consuming process. One of the biggest issues is mapping healthcare data to an HL7 FHIR compliant format.
Having worked on multiple large-scale FHIR projects, our team has developed a custom FHIR resource mapper that transforms any clinical resource into a FHIR data mapping format. In this article, we want to share the issues we were able to solve for our clients and how we did it. We will also illustrate the FHIR mapper’s capabilities with JSON examples to provide a better understanding of its functions and how to map a resource in FHIR.
What is HL7 FHIR?
Fast Healthcare Interoperability Resources (FHIR) is an open standard developed by the HL7 International organization to facilitate seamless exchange of electronic health data between different healthcare systems and promote interoperability.
Read Also: FHIR vs. HL7: What to Choose
FHIR was built on modern web technologies such as REST API, JSON and XML, which makes it easier for developers to implement and use. It utilized a resource-based data model for representing healthcare data. Each HL7 FHIR resource corresponds to a specific element of healthcare data such as a patient, medication, or clinical observation. This modular approach enables flexible and granular exchange of data, and allows for easier EHR systems integration.
The standard has gained widespread adoption in the healthcare industry, and is supported by major EHR vendors, healthcare providers, and government agencies. It is seen as a key enabler of interoperability and data exchange in healthcare, and is expected to play a major role in advancing healthcare technology and improving patient care.
Read also: Introduction to FHIR Data Model
What is a FHIR mapper?
Are you wondering what is data mapping in healthcare? Whenever you need to match fields from one database to another, you “map” the data. In the case of FHIR specifications, you map the data you have to FHIR resources. For example, we have a Patient resource stored in a database in a particular format, but you need to have it in a FHIR format. You could hire a team of data analysts to do so manually, but that would be an immensely time- and cost-consuming task. Instead, you could automate the process of clinical data mapping to a FHIR resource by using a FHIR mapper.
How we built a FHIR mapper
We built a custom FHIR mapper that utilizes resource templates. Data analysts can easily customize these templates however is needed. For example, there’s a deleted_date field we deleted in one template; however, later on, we needed that field in another template. A data analyst can add said field by just writing a few lines in the JSON template.
The process of transforming a custom resource into a FHIR structure

The mapper utilizes various functions to map one resource onto another. Below we’ll take a look at these functions and provide some examples for better understanding.
_if mapping function
The keyword _if checks whether the field exists in the incoming JSON code. This validation is used for the cases when a JSON block has static fields along with data from the incoming JSON. For example, in the next block we check whether Patient in the incoming JSON code has ethnicity. If it doesn’t have the entire block, it will be absent in the outcoming JSON code.
{
"_if": "{Patient.ethnicity}",
"extension": [
{
"url": "ombCategory",
"valueCoding": "{Patient.ethnicity|ethnicity_code}"
},
{
"url": "text",
"valueString": "{Patient.ethnicity}"
}
],
"url": "http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity"
}
_ifnot mapping function
The keyword _ifnot is applied when data is absent in the incoming resource. For example, let’s take a look at the valueQuantity in the Observation resource. If data for Patient weight is present, the Observation resource will include valueQuantity data listed in the incoming resource; if not, an absence reason will be listed (e.g., “value was not set by Doctor”).
"valueQuantity": {
"_if": "{Patient.weight.value}",
"value": "{Patient.weight.value|float}",
"unit": "{Patient.weight.units}",
"system": "http://unitsofmeasure.org",
"code": "[lb_av]"
},
"dataAbsentReason": {
"_ifnot": "{Patient.weight.value}",
"text": "value was not set by Doctor"
}
_foreach mapping function
The keyword _foreach creates FHIR HL7 resources in the outcoming resource for each object or element in the array element from the incoming resource.
{
"phones": [
{
"phone": "4155555555",
"phone_type": "Home",
"created_date": "2016-10-10T23:31:49",
"deleted_date": null
},
{
"phone": "5155555555",
"phone_type": "Main",
"created_date": "2016-10-10T23:31:49",
"deleted_date": null
}
]
}
In this case, we’ll create a telecom element for each object in the phones array.
{
"telecom": [
{
"_foreach": "{Patient.phones}",
"use": "{array_element.phone_type|phone_type_to_use}",
"system": "{array_element.phone_type|phone_type_to_system}",
"rank": "{array_element.phone_type|phone_type_to_rank}",
"value": "{array_element.phone}",
"period": {
"start": "{array_element.created_date}",
"end": "{array_element.deleted_date}"
}
}
]
}
_flatten mapping function
Sometimes incoming FHIR resources could have arrays with arrays, and you need to map the data from the first array element to the second one.
For example, we have custom_report_income_resource.
{
"id": "123",
"patient": "456",
"report": [
{
"report_id": "number_1",
"resulted_date": "2022-10-13T09:37:00Z",
"collected_date": "2022-10-13T09:37:00Z",
"note": "this is a note",
"results": [
{
"status": "FINAL",
"value": "12",
"units": "%",
"observation_code": {
"name": "Hematocrit",
"loinc_code": "4544-3"
}
}
]
}
]
}
For each report element, we will create a Diagnostic report resource, and for each report.results, we will create an Observation resource. Data for each observation is in the report resource. For this case, we use _flatten, and we refer to the above element through report{array_element_above.#}.
Terminology mapping
The examples below show HL7 mapping between incoming codes and outcoming codes. The block is for the AllergyIntolerance resource. DrugIntolerance.status is incoming data and contains a list of codes.
{
"clinicalStatus": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical",
"code": "{DrugIntolerance.status|drug_intolerance_status}"
}
]
}
}
We save separate mappings for such lists. For example:
{
"drug_intolerance_status": {
"1": "active",
"2": "inactive"
}
}
As such, by using this type of HL7 mapping, we could use code from terminology.
Benefits of FHIR-Based Healthcare Interoperability
Below, we will explore some of the advantages the FHIR standard provides for healthcare interoperability.
Improved Data Exchange: FHIR’s standard format and protocol allow for efficient and standardized data exchange between healthcare organizations, reducing errors and improving patient outcomes.
Easier integration with third-party systems: FHIR’s use of RESTful APIs makes it easier to integrate with other healthcare IT systems, enabling better coordination of care across different providers and systems.
Better Clinical Care: Access to Electronic Health Records by medical personnel and hassle-free integration in software applications plays an important role in patient care, safety, effectiveness, timeliness and efficiency, and equity.
Enhancement in Data Management: Standardized data format simplifies and optimizes data management by providing solutions and choosing necessary FHIR tools to manage the significant volume of available data. Harmonized data ensures data integrity, accuracy, and consistency, and minimizes poor-quality data.
Holistic Patient Experience: The interoperability offered by the FHIR standard provides patients control over the use and monitoring of their data, thus empowering them and allowing for a more holistic patient experience. Patients can choose how and what information they share with healthcare providers, thus increasing faith in the industry and giving them power over the decisions of their treatment.
Compliance with Regulations: FHIR-based interoperability solutions can help healthcare organizations comply with regulatory requirements such as HIPAA and the ONC Interoperability Rule.
Simplified Development: FHIR uses modern web technologies and standards, making it easier for developers to create and implement healthcare applications and systems.
Conclusion
Non-standardized and legacy data formats are one of the biggest obstacles standing in the way of true healthcare interoperability. Understanding the nuances between HL7 and FHIR is crucial for modernizing these systems. However, data mapping in healthcare is not an impossible problem, as we have proved by developing an easy-to-use tool for data mapping to HL7 FHIR.
We hope this showcase of our FHIR HL7 mapping solution to the challenge healthcare organizations often face will make FHIR adoption less of a hassle for you. Our HL7 mapping software is one of many our team has created to help clinical data analysts make working with FHIR resources more efficient.
Check out our free low-code FHIR Profile Editor or request a demo of the Kodjin FHIR Server to discover more of the powerful features we offer for FHIR adoption.
FAQ
What is healthcare data mapping?
Healthcare data mapping is the process of converting data from one format to another to enable interoperability between healthcare systems, for example, converting data to UCUM, the Unified Code for Units of Measure.
Why is mapping healthcare data to HL7 FHIR resources important?
Mapping healthcare data to HL7 FHIR resources enables systems to communicate and exchange information in a standardized format, improving interoperability and allowing for better patient.
What are some challenges of mapping healthcare data to HL7 FHIR resources?
Some challenges of mapping healthcare data to HL7 FHIR resources include data mapping errors, inconsistent data formats, and lack of standardized data definitions.
