Custom resources using FHIR Schema
Custom resources are defined by individual organizations or projects to meet specific needs not covered by the FHIR standard. While these resources can be useful within a particular ecosystem, they may not be interoperable with other systems that do not recognize or support those custom resources.
FHIR Schema is a community project that aims to simplify the implementation and validation of FHIR (Fast Healthcare Interoperability Resources) resources across different programming languages. It also provides the ability to define custom resources. You can read more about the syntax and validation algorithms in the FHIR Schema documentation.
Configure Aidbox
To begin using custom FHIR resources, enable the FHIRSchema validator engine in Aidbox.
Setup Aidbox with FHIR Schema validation engineFHIR Schema endpoint
Aidbox provides the /fhir/FHIRSchema
POST endpoint for creating FHIRSchema instances. Examples of usage are given in this article below.
FHIR Schema top level properties
To understand the meaning of the schemas described below, it is important to know the meaning of some basic FHIR Schema properties:
base
This property contains the canonical URL to the FHIR Schema/StructureDefinition whose elements and constraints will be inherited.
It shares the same meaning as FHIR StructureDefinition.baseDefinition
Usually, you want to set this property to DomainResource
. This provides all the resource infrastructure, such as top-level extension
collection and meta
, which allows you to populate meta in the FHIR manner and add profile references.
If you omit this field, only the elements defined in the elements
section of FHIR Schema will be validated. Aidbox does not perform any automatic inference of the base
if it is omitted.
url
*
This field contains the unique canonical URL for your FHIRSchema.
In the context of custom resources, this field is not important. However, it becomes crucial when defining profiles, as you use the profile's canonical URL to reference it in the meta.profile
of a resource instance.
It shares the same meaning as FHIR StructureDefinition.url
name
*
This field provides the computer-readable name for your custom resource or profile.
It shares the same meaning as FHIR StructureDefinition.name
When defining a new resource type, the current implementation requires that this field must be equal to both the type
and id
.
type
This property provides reource type name for a new resource definition or in case of profiling the type of resource that is being constrained.
It shares the same meaning as FHIR StructureDefinition.type
When defining a new resource type, the current implementation requires that this field must be equal to both the name
and id
.
kind
*
This property is used to define the kind of structure that FHIRSchema is describing.
It shares the same meaning as FHIR StructureDefinition.kind
To define custom resources, you should use kind
: resource
or kind: logical
derivation
*
This property represents how the type relates to the base
property. If it is set to specialization
- Aidbox will create a new resource type with tables in the database and other resource infrastructure. If it is set to constraint
- Aidbox will create a new profile that can be referenced on resource instances
id
It shares the same meaning as FHIR Resource.id
When defining a new resource type, the current implementation requires that this field must be equal to both the type
and name
.
FHIR Schema may contain additional fields at the top level, but they share the same meaning as properties defined in the elements
instruction.
For more information about these fields, please refer to the FHIR Schema reference specification.
Limitations of FHIR Logical Models
Logical models (StructureDefinition/FHIRSchema with kind: logical) have two limitations as guided by the FHIR specification:
Base Value:
The base value is limited to two possible values:
Element
orbase
.
Type Value:
The type value must be a fully specified URL and may share the same value as the URL property. This requirement is enforced by FHIR to avoid clashes with core resources.
Since FHIR Schema shares the same semantic meaning and purpose as StructureDefinition, it inherits all these limitations of the original StructureDefinition resource.
Due to the second limitation, resource definitions based on logical models are not intended for instantiation and are provided to an end FHIR server only as data structure examples.
Create customs resources using FHIR Schemas
This guide will walk you through the process of creating custom resources for a notification system, demonstrating the typical workflow of creating, managing, and sending template-based notifications from a healthcare system to patients using custom resources defined through FHIRSchema.
Additionally, there is a JavaScript application that showcases the implementation of notification handling. This includes requesting notifications, locking them for processing, and completing the sending process.
To implement a notification flow, you may need a notification resource and a template resource to store your notification messages.
Let's start with shaping a TutorNotificationTemplate resource.
This resource contains one property defined under FHIRSchema.elements
:
template
: this property is for notification template text and is of the FHIRstring
data type. Also, it is a required property.
Also FHIRSchema.derivation
: specialization
is a property that tells the Aidbox to create a new resource instead of constraining an existing one with a new profile.
Now, when a resource to store notification templates is available, a more complex resource can be shaped: the TutorNotification
. This resource will include several key properties:
type
: property that containsbinding
value set URL invalueSet
property andstrength
:required
, that is used to force binding validation.status
: property withbinding
tovalueSet: http://hl7.org/fhir/ValueSet/task-status
with additional constraint torequested
,in-progress
orcompleted
values.template
: reference toTutorNotificationTemplate
resource that we created above.message
: message text and is of the FHIRstring
data type.sendAfter
: property that specifies thedateTime
after which this notification should be sent.subject
: reference to thePatient
resource to whom this notification will be sent.
Define search parameters
With defined resources, most of the work is done, but there is one missing aspect of any FHIR resource. You definitely want to check your requested notifications or include related subjects to the search bundle. Aidbox allows you to define SearchParameter resources in addition to custom resources.
Let's create the search parameters mentioned above.
This one defines the expression
to achieve resource status, which allows you to search for TutorNotification resources by status like this:
The other one is used to include related Patient resources to the search bundle.
It allows you to make following requests:
Interact with a resource
Now you can interact with created resources just like with any other FHIR resources.
Let's create an instance of TutorNotificationTemplate
resource with welcome message based on related patient's given name.
Then we probably want to create some patient:
So request that creates welcome sms notification for James Morgan at 12:00 should look like this:
How Aidbox Deals with FHIR Limitations for Custom Resources
FHIR Type ValueSet Bindings
FHIR defines certain ValueSets that list all resource types and binds them with required strength to some properties. For example, the SearchParameter.base
property points to the resource this SearchParameter
is intended for and has this exact binding. Obviously, your custom resource type is not mentioned in this ValueSet. However, you still want to create and use search parameters for your custom resources.
During validation, Aidbox checks whether the resource type is in the given ValueSet or if it is a known custom resource for Aidbox. This allows you to use custom resources in resources like CapabilityStatement
or SearchParameter
, or in the type
property of references.
References to Unknown FHIR Types
FHIR allows references to point only to FHIR resources. Aidbox, however, allows you to specify custom resources in reference targets as well.
Bundle Entries Must Inherit from Resource FHIR Type
FHIR explicitly states that Bundle.entry.resource
must be a type that inherits from the Resource FHIR type. Aidbox relaxes this constraint and checks that the referenced resource inherits from at least one StructureDefinition
/FHIRSchema
with kind: resource
and derivation: specialization
.
Last updated