Work In Progress
Python scripts to download CareConnect FHIR profiles from the HL7 uk website and process them into code using a set of Jinja templates.
This project differs from existing FHIR code generation tools in that it is designed to work on the differential of a level 2 structure definition and subclass existing FHIR classes.
In theory it could also be run on a level 3 differential to subclass level 2 classes generated by this project - let me know how you get on :-)
Templates are included to produce nodeJS classes that are subclasses of the classes from the https://github.com/Asymmetrik/node-fhir-server-core project.
A build is attempted for all STU3 Codesets, Valuesets, Extensions and Profiles listed at:
are included except:
- Profiles/Extensions which use slices without a discriminator
- Profiles/Extensions which use slices with non-fixed value discriminators
The script will throw a RuntimeError if it encounters something known to be unsupported.
Codesets, Valuesets and Extensions have corresponding test suites built (see the templates) but the profile test suites are manually built.
Copy config.ini.sample to config.ini and adjust to point to your chosen output directory.
If you wish to use a different set of templates - adjust the template_dir too.
If you wish to change the Base Classes add your own to the BaseClasses directory under the templates directory Then ...
pip install -r requirements.txt
python buildall.py
The classes will automatically set the correct profile urls and provide helper functions to deal with CareConnect specific extensions and slices.
Classes provide named slice functions where possible. e.g The CareConnectPatient1 class provides two functions for adding and retrieving Identifiers:
nhsNumberIdentifier
which will return any identifer with the NHS Number system.otherIdentifier
which will return any identifer without the NHS Number system.
The profile classes can be constructed in two different ways:
-
With a FHIR JSON resource. When constructed with a FHIR resource the objects are by default in "read only" mode. Calling a getter for a Care Connect specific extension will only return an object if it was included in the FHIR JSON.
-
As an empty resource. When constructed empty the objects are a by default in "manufacture mode". Calling a getter for a Care Connect specific extension will create a new instance of the extension e.g.
patient.ethnicCategory
will create an instance of the ExtensionCareConnectEthnicCategory1 class and add it to the list of extensions in the patient object. A list is returned even when the maximum cardinality of the extension is 1 (because the getter filters the list of extensions to include only enthnic category extensions).
The classes will attempt to honour cardinality for extensions and replace an existing extension of the same type if it already exists and the maximum cardinality is one.
The Extension classes set the correct url and provide helper functions for CareConnect specific extentions and slices. For example the ExtensionCareConnectEncounterTrasport1 class provides:
- A reasonForTransport getter/setter to get/set the reasonForTransport extension
The classes also provide functions to set the relevant value property of an extension. For example the ExtensionCareConnectEthnicCategory1 provides:
- A getter\setter called
codeableConcept
to set the valueCodeableConcept value of the extension.
A named slice in an extension gets a specific getter/setter. For example ExtensionCareConnectNHSCommunication1 provides:
- A getter\setter called
preferred
to set the valueBoolean
N.B At this stage, unlike the Profile classes, Extension classes will not automatically build components of the right type. They must be expclitly created and set.
Where a valueset uses a single codesystem that is included in the classes then the display and system values are automatically added. e.g.
patient.ethnicCategory[0].codeableConcept = 'A'
Will also set the system and display value ('British, Mixed British' in this example)
Values from sets that use Snomed or multiple Codesystems must be specified fully. e.g.
patient.religiousAffiliation.codeableConcept = {
'system': 'http://snomed.info/sct', 'code': '428506007', 'display': 'Druid, follower of religion' }
Please read CONTRIBUTING.md for details of the process for submitting pull requests to us.
Python fhir models used in this project are from the SMART Health IT Python client
https://github.com/smart-on-fhir/client-py
This project is licensed under the MIT License - see the LICENSE.md file for details.
JSON representations of resources used in and by this project are Copyright © HL7.org 2011+
HL7® and FHIR® are the registered trademarks of Health Level Seven International