• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    Python
  • License
    Other
  • Created about 10 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Python FHIR specification parser and class generator

Python FHIR Parser

Build Status

A Python FHIR specification parser for model class generation. If you've come here because you want Swift or Python classes for FHIR data models, look at our client libraries instead:

The master branch is currently capable of parsing STU 3, v3.0.0.
The develop branch should be capable of parsing the continuous integration build and will be merged into master on new major FHIR releases. There may be tags for specific freezes, see releases.

This work is licensed under the APACHE license. FHIR® is the registered trademark of HL7 and is used with the permission of HL7.

Tech

The generate.py script downloads FHIR specification files, parses the profiles (using fhirspec.py) and represents them as FHIRClass instances with FHIRClassProperty properties (found in fhirclass.py). Additionally, FHIRUnitTest (in fhirunittest.py) instances get created that can generate unit tests from provided FHIR examples. These representations are then used by Jinja templates to create classes in certain programming languages, mentioned below.

This script does its job for the most part, but it doesn't yet handle all FHIR peculiarities and there's no guarantee the output is correct or complete. This repository does not include the templates and base classes needed for class generation, you must do this yourself in your project. You will typically add this repo as a submodule to your framework project, create a directory that contains the necessary base classes and templates, create settings and mappings files and run the script. Examples on what you would need to do for Python classes can be found in Sample/settings.py, Sample/mappings.py and Sample/templates*.

Use

  1. Add fhir-parser as a submodule/subdirectory to the project that will use it

  2. Create the file mappings.py in your project, to be copied to fhir-parser root. First, import the default mappings using from Default.mappings import * (unless you will define all variables yourself anyway). Then adjust your mappings.py to your liking by overriding the mappings you wish to change.

  3. Similarly, create the file settings.py in your project. First, import the default settings using from Default.settings import * and override any settings you want to change. Then, import the mappings you have just created with from mappings import *. The default settings import the default mappings, so you may need to overwrite more keys from mappings than you'd first think. You most likely want to change the topmost settings found in the default file, which are determining where the templates can be found and generated classes will be copied to.

  4. Install the generator's requirements by running pip3 (or pip):

    pip3 install -r requirements.txt
  5. Create a script that copies your mappings.py and settings.py file to the root of fhir-parser, _cd_s into fhir-parser and then runs generate.py. The generate script by default wants to use Python 3, issue python generate.py if you don't have Python 3 yet.

    • Supply the -f flag to force a re-download of the spec.
    • Supply the --cache-only (-c) flag to deny the re-download of the spec and only use cached resources (incompatible with -f).

NOTE that the script currently overwrites existing files without asking and without regret.

Languages

This repo used to contain templates for Python and Swift classes, but these have been moved to the respective framework repositories. A very basic Python sample implementation is included in the Sample directory, complementing the default mapping and settings files in Default.

To get a sense of how to use fhir-parser, take a look at these libraries:

Tech Details

This parser still applies some tricks, stemming from the evolving nature of FHIR's profile definitions. Some tricks may have become obsolete and should be cleaned up.

How are property names determined?

Every “property” of a class, meaning every element in a profile snapshot, is represented as a FHIRStructureDefinitionElement instance. If an element itself defines a class, e.g. Patient.animal, calling the instance's as_properties() method returns a list of FHIRClassProperty instances – usually only one – that indicates a class was found in the profile. The class of this property is derived from element.type, which is expected to only contain one entry, in this matter:

  • If type is BackboneElement, a class name is constructed from the parent element (in this case Patient) and the property name (in this case animal), camel-cased (in this case PatientAnimal).
  • If type is *, a class for all classes found in settings star_expand_types` is created
  • Otherwise, the type is taken as-is (e.g. CodeableConcept) and mapped according to mappings' classmap, which is expected to be a valid FHIR class.

TODO: should http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name be respected?

More Repositories

1

client-py

Python SMART on FHIR client
Python
588
star
2

health-cards

Health Cards Framework: implementation guide and supporting material
TypeScript
259
star
3

Swift-FHIR

These are Swift classes for data models of FHIR elements and resources
Swift
159
star
4

Swift-SMART

Swift SMART on FHIR framework for iOS and OS X
Swift
125
star
5

smart-dev-sandbox

Docker based sandbox for smart apps
Smarty
116
star
6

api-server

Open-source FHIR Server to support patient- and clinician-facing apps
Groovy
104
star
7

patient-browser

JavaScript
83
star
8

smart-on-fhir.github.io

SMART on FHIR Docs
Jupyter Notebook
77
star
9

fhir-bulk-data-docs

Documentation and issue tracking for the emerging FHIR bulk data implementation guide
Jupyter Notebook
74
star
10

health-cards-dev-tools

Developer tools for validating SMART Health Cards
TypeScript
71
star
11

growth-chart-app

JavaScript
66
star
12

sample-apps-stu3

Collection of simple sample apps
JavaScript
46
star
13

fred

FRED - FHIR Resource Editor
JavaScript
44
star
14

health-cards-tests

Demo for health wallet with Verifiable Credentials and Decentralized Identifiers
TypeScript
43
star
15

bulk-data-server

JavaScript
42
star
16

fhir-server-dashboard

Presents a human-readable representation of the data in a FHIR server.
JavaScript
41
star
17

fhir-viewer

In-browser viewer for FHIR resources
JavaScript
39
star
18

installer

Shell
39
star
19

hapi

HAPI FHIR Server With Sample Patients
Dockerfile
37
star
20

SoF-Demo

Simple SMART on FHIR / Argonaut iOS sample app that fetches a couple of resources
Swift
36
star
21

smart-launcher

Launcher for SMART apps
JavaScript
33
star
22

smart-scheduling-links

Clinical Appointment Slot Discovery
TypeScript
28
star
23

sample-apps

HTML
25
star
24

cardiac-risk-app

JavaScript
25
star
25

generated-sample-data

Contains all the bundles that are loaded into the FHIR server
24
star
26

bulk-data-tools

HTML
23
star
27

smart-examples

Collection of public apps
JavaScript
14
star
28

client-node

SMART client for NodeJS
HTML
13
star
29

bulk-import

12
star
30

bulk-data-implementations

listing of bulk FHIR client implementations
12
star
31

bulk-data-client

JavaScript
11
star
32

tag-uploader

Adds tags to FHIR bundles and resources and uploads them to specified servers
JavaScript
9
star
33

sample-patients-stu3

Python
9
star
34

client-ts

FHIR Client Library
HTML
9
star
35

bp-centiles-app

JavaScript
8
star
36

cumulus-etl

Extract FHIR data, Transform with NLP and DEID tools, and then Load FHIR data into a SQL Database for analysis
Python
8
star
37

diabetes-monograph-app

JavaScript
7
star
38

fhir-starter

HTML
7
star
39

smart-launcher-v2

SMART Launcher
TypeScript
6
star
40

smart-local-sandbox

Docker based sandbox for smart apps
JavaScript
6
star
41

health-cards-designs

5
star
42

smart-hapi-stack

Experimental HAPI stack to support SMART on FHIR
Java
5
star
43

sample-bulk-fhir-datasets

Sample bulk export results of various sizes, for testing tools and workflows
Shell
5
star
44

bdt

Bulk Data Test Suite and Test Runner
TypeScript
5
star
45

sample-patients-prom

Provisional Quarterly Patient Reported Outcome Measures (PROMs) in England - April 2015 to March 2016, November 2016 release
JavaScript
5
star
46

smart-stub

Node / Express server to stub SMART Auth
JavaScript
4
star
47

mpr-monitor-app

JavaScript
4
star
48

dstu2-examples

Copy of official FHIR examples with an index page
HTML
4
star
49

synthea

Static build of Synthea with http interface
JavaScript
4
star
50

hca-fhir-importer

Import synthetic breast cancer sample data, courtesy of HCA/Bill Gregg
Python
4
star
51

fhir-demo-app

ApacheConf
3
star
52

smart-health-card-decoder

Sample code for a SMART Health Card validator
JavaScript
3
star
53

smart-health-links

Static documentation site for SMART Health Links
JavaScript
3
star
54

ehi-app

EHI Export API Client Reference Implementation
TypeScript
3
star
55

ehi-server

An EHI export server reference implementation of Argonaut's EHI Export API IG
TypeScript
3
star
56

bulk-import-client

CLI Client app for Bulk Data Import
JavaScript
2
star
57

confidential-client-example

JavaScript
2
star
58

fiery-sublime

Sublime Text 3 Plugin for FHIR data models
Python
2
star
59

disease-monograph-app

JavaScript
2
star
60

fhir-crawler

Utility to download resources from a FHIR server
TypeScript
1
star
61

fhir-server-tasks

Maintenance web-hooks for FHIR servers
JavaScript
1
star
62

timeshift

Shift dates in FHIR datasets
JavaScript
1
star
63

client-js-examples

Contains examples of how to use the client-js library
HTML
1
star
64

registry

Registry of FHIR Profiles for SMART Platforms
HTML
1
star
65

bulk-import-consumer

Bulk Data Import Server (Data Consumer)
JavaScript
1
star
66

reachnet

JavaScript
1
star
67

cumulus-library-hypertension

Hypertension case definition to support CDC chronic disease management and CMS measures
Python
1
star