Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

FHIRPath implementation in Python.

Project description

Introduction Documentation Status Test Coverage Python Versions Language grade: Python License HL7® FHIR®

FHIRPath (STU1) implementation in Python. This library is built in ORM like approach. Our goal is to make 100% (as much as possible) FHIRPath (STU1) specification compliance product.


This library is kind of abstract type, where all specifications from FHIRPath (STU1) are implemented rather than completed solution (ready to go). The main reason behind this design pattern, to support multiple database systems as well as well as any framework, there is no dependency.

fhirpath never taking care of creating indexes, mappings (elasticsearch) and storing data, if you want to use this library, you have to go through any of existing providers (see list bellow) or make your own provider (should not too hard work).

Simple example


  1. Elasticsearch server 7.x.x Installed.
  2. Mappings and indexes are handled manually.
  3. Data (document) also are stored manually.

Create Connection and Engine:

>>> from fhirpath.connectors import create_connection
>>> from import ElasticsearchEngine
>>> from fhirpath.engine import dialect_factory
>>> from fhirpath.enums import FHIR_VERSION

>>> host, port = "", 9200
>>> conn_str = "es://@{0}:{1}/".format(host, port)
>>> connection = create_connection(conn_str, "elasticsearch.Elasticsearch")
>>> engine = ElasticsearchEngine(FHIR_VERSION.R4, lambda x: connection, dialect_factory)

Basic Search:

>>> from import Search
>>> from import SearchContext

>>> search_context = SearchContext(engine, "Organization")
>>> params = (
....    ("active", "true"),
....    ("_lastUpdated", "2010-05-28T05:35:56+00:00"),
....    ("_profile", ""),
....    ("identifier", "urn:oid:2.16.528.1|91654"),
....    ("type", "|prov"),
....    ("address-postalcode", "9100 AA"),
....    ("address", "Den Burg"),
.... )
>>> fhir_search = Search(search_context, params=params)
>>> bundle = fhir_search()
>>> len(bundle.entry) == 0

Basic Query:

>>> from fhirpath.enums import SortOrderType
>>> from fhirpath.query import Q_
>>> from fhirpath.fql import T_
>>> from fhirpath.fql import V_
>>> from fhirpath.fql import exists_
>>> query_builder = Q_(resource="Organization", engine=engine)
>>>  query_builder = (
....    query_builder.where(T_("") == V_("true"))
....    .where(T_("Organization.meta.lastUpdated", "2010-05-28T05:35:56+00:00"))
....    .sort(sort_("Organization.meta.lastUpdated", SortOrderType.DESC))
.... )
>>> query_result = query_builder(async_result=False)
>>> for resource in query_result:
....    assert resource.__class__.__name__ == "OrganizationModel"
>>> # test fetch all
>>> result = query_result.fetchall()
>>> result.__class__.__name__ == "EngineResult"

>>> query_builder = Q_(resource="ChargeItem", engine=engine)
>>> query_builder = query_builder.where(exists_("ChargeItem.enteredDate"))
>>> result = query_builder(async_result=False).single()
>>> result is not None
>>> isinstance(result, builder._from[0][1])

>>> query_builder = Q_(resource="ChargeItem", engine=engine)
>>> query_builder = query_builder.where(exists_("ChargeItem.enteredDate"))
>>> result = query_builder(async_result=False).first()
>>> result is not None
>>> isinstance(result, builder._from[0][1])

Available Provider (known)

Currently very few numbers of providers available, however more will coming soon.


A Plone powered provider, like fhirpath-guillotina every thing is included. ready to go, although has a dependency on

  1. Engine: Elasticsearch
  2. PyPi:
  3. Source:


Why are you waiting for? You are welcome to list your provider here! Developing provider should not be so hard, as fhirpath is giving you convenient APIs.


This package skeleton was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

© Copyright HL7® logo, FHIR® logo and the flaming fire are registered trademarks owned by Health Level Seven International

“FHIR® is the registered trademark of HL7 and is used with the permission of HL7. Use of the FHIR trademark does not constitute endorsement of this product by HL7”


0.4.0 (2019-10-24)


  • Now full select features are accepted, meaning that you can provide multiple path in select section. for example select(, Patient.gender).
  • FHIRPath count() and empty() functions are supported.
  • Supports path navigation with index and functions inside select. Example [index], last(), first(), Skip(), Take(), count().


  • QueryResult.first and QueryResult.single are no longer return FHIR Model instance instead returning fhirpath.engine.EngineResultRow.
  • QueryResult.fetchall returning list of fhirpath.engine.EngineResultRow instead of FHIR JSON.
  • QueryResult iteration returning list of FHIR Model instance on condition (if select is *), other than returning list of fhirpath.engine.EngineResultRow.

0.3.1 (2019-10-08)


  • Add support for search parameter expression that contains with space+as (MedicationRequest.medication as CodeableConcept)


0.3.0 (2019-09-30)


  • Supports multiple AND values for same search parameter!.
  • Add support FHIR version STU3 compability for Money type search.[nazrulworld]
  • IN Query support added.[nazrulworld]
  • Support PathElement that contains string path with .as(), thus suports for Search also.
  • Supports Duration type in Search.
  • Add support composite type search param.


  • Multiple search values (IN search)
  • Missing text for HumanName and Address search.

0.2.0 (2019-09-15)


  • Built-in providers ( guillotina_app and plone_app ) have been wiped as both becoming separate pypi project.
  • queries module has been moved from fql sub-package to fhirpath package and also renamed as query.


  • There are so many improvements made for almost all most modules.
  • FhirSearch coverages are increased.
  • Sort, Limit facilities added in Query as well in FhirSearch.


  • numbers of bugs fixed.

0.1.1 (2019-08-15)

  • First working version has been released. Of-course not full featured.

0.1.0 (2018-12-15)

  • First release on PyPI.(Just register purpose, not usable at all, next release coming soon)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for fhirpath, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size fhirpath-0.4.0-py2.py3-none-any.whl (76.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size fhirpath-0.4.0.tar.gz (68.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page