Name | fhirpathpy JSON |
Version |
2.0.3
JSON |
| download |
home_page | None |
Summary | FHIRPath implementation in Python |
upload_time | 2025-07-28 07:09:12 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | None |
keywords |
fhir
fhirpath
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
fhirpath.py
===========
[](https://github.com/beda-software/fhirpath-py/actions)
[](https://codecov.io/gh/beda-software/fhirpath-py)
[](https://pypi.org/project/fhirpathpy/)
[](https://www.python.org/downloads/release/python-380/)
[FHIRPath](https://www.hl7.org/fhir/fhirpath.html) implementation in Python
Parser was generated with [antlr4](https://github.com/antlr/antlr4)
# Getting started
## Install
`pip install fhirpathpy`
## Usage
```Python
from fhirpathpy import evaluate
patient = {
"resourceType": "Patient",
"id": "example",
"name": [
{
"use": "official",
"given": [
"Peter",
"James"
],
"family": "Chalmers"
},
{
"use": "usual",
"given": [
"Jim"
]
},
{
"use": "maiden",
"given": [
"Peter",
"James"
],
"family": "Windsor",
"period": {
"end": "2002"
}
}
]
}
# Evaluating FHIRPath
result = evaluate(patient, "Patient.name.where(use='usual').given.first()", {})
# result: `['Jim']`
```
## evaluate
Evaluates the "path" FHIRPath expression on the given resource, using data from "context" for variables mentioned in the "path" expression.
**Parameters**
resource (dict|list): FHIR resource, bundle as js object or array of resources This resource will be modified by this function to add type information.
path (string): fhirpath expression, sample 'Patient.name.given'
context (dict): a hash of variable name/value pairs.
model (dict): The "model" data object specific to a domain, e.g. R4. See Using data models documentation below.
options (dict) - Custom options.
options.userInvocationTable - a user invocation table used to replace any existing functions or define new ones. See User-defined functions documentation below.
## compile
Returns a function that takes a resource and an optional context hash (see "evaluate"), and returns the result of evaluating the given FHIRPath expression on that resource. The advantage of this function over "evaluate" is that if you have multiple resources, the given FHIRPath expression will only be parsed once
**Parameters**
path (string) - the FHIRPath expression to be parsed.
model (dict) - The "model" data object specific to a domain, e.g. R4. See Using data models documentation below.
options (dict) - Custom options
options.userInvocationTable - a user invocation table used to replace any existing functions or define new ones. See User-defined functions documentation below.
## Using data models
The fhirpathpy library comes with pre-defined data models for FHIR versions DSTU2, STU3, R4, and R5. These models can be used within your project.
Example:
```python
from fhirpathpy.models import models
r4_model = models["r4"]
patient = {
"resourceType": "Patient",
"deceasedBoolean": false,
}
result = evaluate(patient, "Patient.deceased", {}, r4_model)
# result: `[False]`
```
## User-defined functions
The FHIRPath specification includes a set of built-in functions. However, if you need to extend the functionality by adding custom logic, you can define your own functions by providing a table of user-defined functions.
Example:
```python
user_invocation_table = {
"pow": {
"fn": lambda inputs, exp=2: [i**exp for i in inputs],
"arity": {0: [], 1: ["Integer"]},
}
}
result = evaluate(
{"a": [5, 6, 7]},
"a.pow()",
options={"userInvocationTable": user_invocation_table},
)
# result: `[25, 36, 49]`
```
It works similarly to [fhirpath.js](https://github.com/HL7/fhirpath.js/tree/master?tab=readme-ov-file#user-defined-functions)
## Development
To activate git pre-commit hook: `autohooks activate`
To run tests: `pytest`
Raw data
{
"_id": null,
"home_page": null,
"name": "fhirpathpy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "fhir, fhirpath",
"author": null,
"author_email": "\"beda.software\" <fhirpath@beda.software>",
"download_url": "https://files.pythonhosted.org/packages/9a/49/179df2e14fd84cd689c50f1115005cc008b9df926be3f89571c67167e312/fhirpathpy-2.0.3.tar.gz",
"platform": null,
"description": "fhirpath.py\n===========\n\n[](https://github.com/beda-software/fhirpath-py/actions)\n[](https://codecov.io/gh/beda-software/fhirpath-py)\n[](https://pypi.org/project/fhirpathpy/)\n[](https://www.python.org/downloads/release/python-380/)\n\n[FHIRPath](https://www.hl7.org/fhir/fhirpath.html) implementation in Python\n\nParser was generated with [antlr4](https://github.com/antlr/antlr4)\n\n# Getting started\n## Install\n`pip install fhirpathpy`\n\n## Usage\n```Python\nfrom fhirpathpy import evaluate\n\npatient = {\n \"resourceType\": \"Patient\",\n \"id\": \"example\",\n \"name\": [\n {\n \"use\": \"official\",\n \"given\": [\n \"Peter\",\n \"James\"\n ],\n \"family\": \"Chalmers\"\n },\n {\n \"use\": \"usual\",\n \"given\": [\n \"Jim\"\n ]\n },\n {\n \"use\": \"maiden\",\n \"given\": [\n \"Peter\",\n \"James\"\n ],\n \"family\": \"Windsor\",\n \"period\": {\n \"end\": \"2002\"\n }\n }\n ]\n}\n\n# Evaluating FHIRPath\nresult = evaluate(patient, \"Patient.name.where(use='usual').given.first()\", {})\n# result: `['Jim']`\n```\n\n## evaluate\nEvaluates the \"path\" FHIRPath expression on the given resource, using data from \"context\" for variables mentioned in the \"path\" expression.\n\n**Parameters**\n\nresource (dict|list): FHIR resource, bundle as js object or array of resources This resource will be modified by this function to add type information.\n\npath (string): fhirpath expression, sample 'Patient.name.given'\n\ncontext (dict): a hash of variable name/value pairs.\n\nmodel (dict): The \"model\" data object specific to a domain, e.g. R4. See Using data models documentation below.\n\noptions (dict) - Custom options.\n\noptions.userInvocationTable - a user invocation table used to replace any existing functions or define new ones. See User-defined functions documentation below.\n\n## compile\nReturns a function that takes a resource and an optional context hash (see \"evaluate\"), and returns the result of evaluating the given FHIRPath expression on that resource. The advantage of this function over \"evaluate\" is that if you have multiple resources, the given FHIRPath expression will only be parsed once\n\n**Parameters**\n\npath (string) - the FHIRPath expression to be parsed.\n\nmodel (dict) - The \"model\" data object specific to a domain, e.g. R4. See Using data models documentation below.\n\noptions (dict) - Custom options\n\noptions.userInvocationTable - a user invocation table used to replace any existing functions or define new ones. See User-defined functions documentation below.\n\n## Using data models\n\nThe fhirpathpy library comes with pre-defined data models for FHIR versions DSTU2, STU3, R4, and R5. These models can be used within your project.\n\nExample:\n```python\nfrom fhirpathpy.models import models\n\n\nr4_model = models[\"r4\"]\n\npatient = {\n \"resourceType\": \"Patient\",\n \"deceasedBoolean\": false,\n}\n\nresult = evaluate(patient, \"Patient.deceased\", {}, r4_model)\n\n# result: `[False]`\n```\n\n## User-defined functions\n\nThe FHIRPath specification includes a set of built-in functions. However, if you need to extend the functionality by adding custom logic, you can define your own functions by providing a table of user-defined functions.\n\nExample:\n```python\nuser_invocation_table = {\n \"pow\": {\n \"fn\": lambda inputs, exp=2: [i**exp for i in inputs],\n \"arity\": {0: [], 1: [\"Integer\"]},\n }\n}\n\nresult = evaluate(\n {\"a\": [5, 6, 7]},\n \"a.pow()\",\n options={\"userInvocationTable\": user_invocation_table},\n)\n\n# result: `[25, 36, 49]`\n```\n\nIt works similarly to [fhirpath.js](https://github.com/HL7/fhirpath.js/tree/master?tab=readme-ov-file#user-defined-functions)\n\n\n## Development\n\nTo activate git pre-commit hook: `autohooks activate`\n\nTo run tests: `pytest`\n\n",
"bugtrack_url": null,
"license": null,
"summary": "FHIRPath implementation in Python",
"version": "2.0.3",
"project_urls": {
"Changelog": "https://github.com/beda-software/fhirpath-py/blob/master/CHANGELOG.md",
"Documentation": "https://github.com/beda-software/fhirpath-py#readme",
"Homepage": "https://github.com/beda-software/fhirpath-py",
"Source": "https://github.com/beda-software/fhirpath-py.git"
},
"split_keywords": [
"fhir",
" fhirpath"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "19f995e2bcfc04d88ef07e982fd40815abf868006b1cf973dd2f6d15a671edf6",
"md5": "0963e33f9240b60021d2327867df6021",
"sha256": "f45220ef15977db29ca16251f9bf55be7cb6d123282b338634115f95cb948d5a"
},
"downloads": -1,
"filename": "fhirpathpy-2.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0963e33f9240b60021d2327867df6021",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 230620,
"upload_time": "2025-07-28T07:09:11",
"upload_time_iso_8601": "2025-07-28T07:09:11.069195Z",
"url": "https://files.pythonhosted.org/packages/19/f9/95e2bcfc04d88ef07e982fd40815abf868006b1cf973dd2f6d15a671edf6/fhirpathpy-2.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "9a49179df2e14fd84cd689c50f1115005cc008b9df926be3f89571c67167e312",
"md5": "405675400c110053f3ff3ee7b7fad70d",
"sha256": "58dbc950bfa538830dd40552f4732728674fbcd244039cba1fe5b883e0da9c1e"
},
"downloads": -1,
"filename": "fhirpathpy-2.0.3.tar.gz",
"has_sig": false,
"md5_digest": "405675400c110053f3ff3ee7b7fad70d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 216295,
"upload_time": "2025-07-28T07:09:12",
"upload_time_iso_8601": "2025-07-28T07:09:12.532020Z",
"url": "https://files.pythonhosted.org/packages/9a/49/179df2e14fd84cd689c50f1115005cc008b9df926be3f89571c67167e312/fhirpathpy-2.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-28 07:09:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "beda-software",
"github_project": "fhirpath-py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "fhirpathpy"
}