How to create a FHIR Resource
In this tutorial, we’re looking at how to create our first FHIR resource. Here is a quick recap of some basic concepts before we get started.
What is FHIR?
FHIR, or Fast Health Interoperability Resources is a standard that governs healthcare interoperability that is maintained by HL7 (Health Level 7), an international, non-profit organization. Resources are the smallest unit of exchange in FHIR, and are used to define healthcare concepts like Patient, Encounter, Observation and so on.
We recommend checking out our previous blog for a detailed, beginner friendly explanation of FHIR and its core concepts.
Creating your first FHIR resource
Download and use FHIR schema
The first thing we will do is to download the FHIR JSON Schema so that we can validate the resource we create. We’ll do that by accessing the FHIR Specification Documentation, and finding the Downloadable JSON schema file. Extract it, and keep it ready for use.
Here are the details that we will be entering into our Patient resource.
- Name: John Doe
- Gender: Female
- Date of Birth: 8 May 2000
- Phone: 9876543210
- Email: abc@example.com
- Address: 123, House and Street, State
- Pincode: 98765
Next, create a new folder for your patient resource, and copy it into your project folder. Open this folder in any code editor, we recommend VSCode or Cursor. Copy and paste the JSON Schema file you extracted into this folder structure.
We will then configure the code editor to recognize this file as a schema. For this, you navigate to ‘Preferences: Open Workspace Settings (JSON)’ which will open a settings.json
file. In it, add the following code,
{
"json.schemas": [
{
"fileMatch": [
"*.fhir.json"
],
"url": "./fhir.schema.json"
}
]
}
Now create a new file, patient.fhir.json
in your working folder, and you will be able to get autocomplete suggestions according to the schema we just added.
Referring to FHIR documentation for Patient
Before we dive into creating, let’s take a look at the documentation for the Patient resource. You can refer to the Resource Content during the next steps, while we translate our patient details into a FHIR resource. This is helpful for understanding the data types and formats to be used.
From the ‘What is FHIR? A Beginner’s Guide’ article,
The
Card.
field stands for Cardinality and represents the minimum and maximum times a particular data element can appear using the notationminimum..maximum
. A maximum value of*
means “as many times as needed” or ∞.
Coding your first FHIR resource
In the video, we do a detailed walkthrough of how to understand data elements and represent each field in a resource.
Here is a sample FHIR resource created from the details we listed above. Since we’ve included the JSON schema as part of our code editor’s settings, the resource has also been validated during its creation.
{
"resourceType": "Patient",
"name": [
{
"use": "official",
"given": ["John"],
"family": "Doe"
}
],
"gender": "female",
"birthDate": "2000-05-08",
"telecom": [
{
"system": "phone",
"value": "9876543210",
"use": "mobile"
},
{
"system": "email",
"value": "abc@example.com",
"use": "home"
}
],
"address": [
{
"line": ["123, House and Street"],
"city": "City",
"state": "State",
"postalCode": "98765",
"country": "USA"
}
]
}