Migrate custom resources defined with Zen to FHIR Schema
Last updated
Last updated
The materials in this section describe what to do next with the resulting FHIR Schema resource or set of resources. They explain how to load them into Aidbox, either one by one or via IG. Additionally, they outline the requirements for FHIR Schema to define a Custom Resource and provide a detailed FHIR Schema specification.
In the following sections, we will describe how to obtain the FHIR Schema from a Zen resource definition.
You can use a special REST API endpoint to migrate specific Zen definitions to the FHIR schema. The endpoint requires a Zen namespace
and symbol
under which the custom resource definition is described. Internally, it attempts to compile the Zen definition to the FHIR schema.
If the compilation succeeds, the endpoint returns the resulting FHIR Schema. If it fails, it provides a list of errors detailing what went wrong. Most errors occur because you've used keys on your Zen definition that are not recognized by our compiler. In this case, you can contact us to potentially extend the compiler. Alternatively, you can manually rewrite your custom resource using FHIR Schema.
Please double-check the compilation results, as they may contain transformation errors. This tool is intended to reduce manual effort during the migration process and is not meant for fully automated resource migration.
Here's an example of migrating a custom resource EmailSchedule
that describes the schedule for email notifications about appointments. Let's imagine it is described in main
namespace of our Aidbox configuration project.
Convert this Zen definition
to FHIRSchema
using API:
If the compiler doesn't support certain instructions for your Zen definitions, if you want full control during the migration process, or if you want to extend your custom resources using unique FHIR Schema features, you can manually rewrite your custom resource definitions from scratch using the FHIR Schema.
In the following steps, we will use the same custom resource example, EmailSchedule
. Although it is just an example, it covers most aspects of resource definition with Zen. If this guide misses any features of Zen resource definition, please contact us.
Get Zen definition
Open your Aidbox configuration project and find custom resource definitions. It should look similar to EmailSchedule
definition example.
:keys
to FHIRSchema element entryThe FHIRSchema elements
is similar to :keys
field in Zen definition, serving the same purpose: defining properties for a resource.
For example, we have name
key in EmailSchedule
custom resource:
It states that the name
property must be a string
. This property is located on the top level, indicating it is the root field in the resource.
To describe it as a FHIRSchema element, do the following:
For nested keys like reports.enabled
in the EmailSchedule
resource, nest the "elements" statements accordingly. Note that "elements" repeats each time you nest a property:
Handling Enums
Enums (:enum
) were a handy tool for limiting possible values directly within the Zen definition model. However, this approach conflicts with FHIR, which has its own well-defined methods for limiting value sets.
Using FHIRPath Constraints
Enums can be described using FHIRPath constraints. Here's an example of days
property in EmailSchedule
resource:
Constraint id must be unique across one resource definition. While this method allows for defining possible values in place, it has downsides. It makes it difficult to reuse or implement lookups for these values. Here is the FHIRSchema reference specification describing the constraints property.
Using ValueSets
Alternatively, you can create a ValueSet and bind it to the coded value. FHIR resources extensively utilize this approach. This involves creating a ValueSet as a resource and delivering it to an external terminology server. However, this is beyond the scope of this guide.
In FHIR, terminology bindings occur in four gradations: required, extensible, preferred, and example. The FHIRSchema validator checks bindings only with the strength of "required"; all other binding strengths are ignored.
This approach leverages FHIR's capabilities for managing value sets, ensuring consistency and reusability across different resources.
:validation-type :open
The :validation-type :open
with :type zen/map
instruction for a Zen definition indicates that value is an arbitrary map with arbitrary key/value pairs.
Example: parameters
property in EmailSchedule
resource
FHIRSchema Equivalent
With FHIRSchema, you can express identical semantics using additionalProperties
and any: true
. However, note that resource definitions using these instructions are not compatible with FHIR. This means you cannot convert FHIRSchema with these instructions back to StructureDefinition, as FHIR doesn't naturally describe arbitrary key/value nodes.
To express :validation-type :open
with :type zen/map
in FHIRSchema:
additionalProperties
indicates that any property not described in elements
will be validated against the schema provided in additionalProperties
.
any: true
indicates that the value is arbitrary and may be of any type.
You can also include more complex schemas within additionalProperties
. For example:
This means any keys not described in elements
must have a string value and pass the defined constraints. For more details about these FHIRSchema instructions, please refer to the reference specification section.
zen/any
The zen/any
type for a Zen definition indicates that the value is arbitrary and may be of any type.
Example: data
property in EmailSchedule
resource
FHIRSchema Equivalent
To describe zen/any
use any
without additionalProperties
.
:require
The :require
instruction indicates that the described property is required and must be present in a resource instance.
Example: reports
property in EmailSchedule
resource
FHIRSchema Equivalent
To express :require
in FHIRSchema, use the required
property at the same level as elements
. It is an array of fields that must be present in the data instance.
For more information about this instruction, please refer to the relevant section in the FHIRSchema specification.
zen/vector
The zen/vector
type indicates that the described property represents a collection of items.
Example: recipients
property in EmailSchedule
resource
This definition specifies that recipients
is a property within the EmailSchedule
resource, where each item in the collection is of type string.
FHIRSchema Equivalent
To express zen/vector
in FHIRSchema, use array: true
.