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.

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

Release files for fhir-parse-qs 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fhir-parse-qs 0.9.0
File Size Uploaded
fhir_parse_qs-0.9.0.tar.gz 51.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fhir-parse-qs 0.9.0
File Interpreter ABI Platform
fhir_parse_qs-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 174.6 kB

Release files / fhir_parse_qs-0.9.0.tar.gz

Download URL fhir_parse_qs-0.9.0.tar.gz
Size 51.8 kB
Tags Source
SHA-256 checksum
How to use checksums
73e3ef2c46437ff851f8fdc5f009dab141b1c0380edad278a04c8136a25ca912
BLAKE2b-256 checksum
How to use checksums
c216b48476ea16f0a507c27df5610fe4032d3785ef86132553aa6b04537f7601
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Release files / fhir_parse_qs-0.9.0-py3-none-any.whl

Download URL fhir_parse_qs-0.9.0-py3-none-any.whl
Size 122.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a5fd6a97e8aa32801072740035755d6302ac18eff06a7f3c809015602d626d3
BLAKE2b-256 checksum
How to use checksums
50d77c3444d95c6bd3cebcfc9227b31b39afbee115e1deae1585c7ea9a9b445b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.1

1 release file

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page