Skip to main content

fhir_parse_qs

PyPI version

A library to parse FHIR query strings.

  • Validates type and returns correct object
  • Built-in search parameters from FHIR standard
  • Supports modifiers, prefixes, and chains

Releases 0.7.x and below used FHIR R3. Releases 0.8.x and greater use FHIR R4.

The update_mappings.py script generates the mappings from the HL7 FHIR releases.

Development (uv)

This project uses uv for dependency management and packaging.

  • Install uv: curl -LsSf https://astral.sh/uv/install.sh | sh or pipx install uv
  • Create env and install deps: uv sync --group dev
  • Run tests: uv run pytest
  • Lint: uv run black --check fhir_parse_qs tests

Usage

Provide the endpoint and query_string arguments:

from fhir_parse_qs import Search
search = Search('Patient', 'name=bob') # Search(<endpoint>, <query_string>)

# supported endpoints
Search.supported ==> [...]

# endpoint
search.endpoint ==> 'Patient'

Each parameter/value pair is parsed into a FHIRSearchPair with attached FHIRParameter and FHIRValue namedtuples.

# all the namedtuples
search.parsed ==> [FHIRSearchPair(...)]

FHIRSearchPair.parameter ==> FHIRParameter
FHIRSearchPair.value ==> [FHIRValue, ...]

    FHIRParameter:
        value
        modifier
        chain
            [FHIRChain...]
        type_

        FHIRChain:
            endpoint
            target
            ttype

    FHIRValue:
        value
        prefix
        system
        code

Further features:

# index as key; each parameter/value pair parsed into a namedtuple
search[0] ==> FHIRSearchPair:
    parameter ==> FHIRParameter:
        value ==> 'name'
        modifier ==> None
        chain ==> None
        type_ ==> 'string'
    value ==> [FHIRValue(
        prefix ==> None
        value ==> 'bob'
        system ==> None
        code ==> None
        ]

# act like dict with parameter as key
search['name'] ==> FHIRSearchPair(...) #list if non-unique parameter

# iterate over the parameter/value pairs
for x in search:
     print(x) ==> FHIRSearchPair(...)

# supports comma-separated list of values
search = Search('Patient', 'name=peter,travis')
search["name"] ==> [FHIRValue(...), FHIRValue(...)]

# ignores and logs unrecognized parameters
search = Search('Patient', 'random=test')
search.error ==> [...]

# supports chaining
search = Search('Observation', 'patient.name=peter')
search[0].parameter.value ==> 'name' # last parameter in chain
search[0].value[0].value ==> 'peter'
search[0].parameter.chain ==> [FHIRChain(...), FHIRChain(...)]
search[0].parameter.chain[0].endpoint ==> 'Observation'
search[0].parameter.chain[0].target ==> 'patient'
search[0].parameter.chain[0].ttype ==> 'reference'
search[0].parameter.chain[1].endpoint ==> 'Patient'
search[0].parameter.chain[1].target ==> 'name'
search[0].parameter.chain[1].ttype ==> 'string'

# supports systems and codes
search = Search("Observation", "value-quantity=gt234|http://loinc.org|mg")
search["value-quantity"].value[0].value ==> 234
search["value-quantity"].value[0].prefix ==> "gt"
search["value-quantity"].value[0].system ==> "http://loinc.org"
search["value-quantity"].value[0].code ==> "mg"

# return control parameters (eg, _sort, _count, etc)
search.control ==> [...]

TODO

  • Narrow allowed chains (return error for ambiguous chains) (unreleased)
  • The _filter parameter
  • Reverse chains
  • Composite searches

Download files

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

Source Distribution

fhir_qs_parser-0.10.0.tar.gz (54.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fhir_qs_parser-0.10.0-py3-none-any.whl (123.0 kB view details)

Uploaded Python 3

File details

Details for the file fhir_qs_parser-0.10.0.tar.gz.

File metadata

  • Download URL: fhir_qs_parser-0.10.0.tar.gz
  • Upload date:
  • Size: 54.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for fhir_qs_parser-0.10.0.tar.gz
Algorithm Hash digest
SHA256 68438495e44f57f860266692ca0f3b39fd8ce40a3957ddffa2f19ea88ae0c8ea
MD5 cc96d64d4003711c01c45714328783ec
BLAKE2b-256 c8d47d9925112015407f9ccbfdaceb8c1dff05fe3a7983b2be81b9059c4360ae

See more details on using hashes here.

File details

Details for the file fhir_qs_parser-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: fhir_qs_parser-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 123.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for fhir_qs_parser-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1776bc9e0631cb0dd807f6c5dd164f4e7c6454ccafbe19b61c03d1fe234a183
MD5 2d2820b9a9842028e16dd3243c5b01d4
BLAKE2b-256 cac3f42efd0471797f363841479499a4912f47038bae637cfd934e5bd6e2e3d1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page