Skip to content

trostalski/fhir-query

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fhir-query

A simple Python client library for querying FHIR servers. Sync and async support.

Features

  • Synchronous and asynchronous FHIR server querying
  • Multiple authentication methods (Basic Auth, Token Auth, Login Auth)
  • Support for GET and POST search requests
  • Pagination handling
  • Bundle response handling with DataFrame conversion
  • Type hints and resource type validation

Installation

pip install fhir-query

Quick Start

Synchronous Client

from fhir_query import FhirQueryClient

# Initialize the client
client = FhirQueryClient(
    base_url="https://hapi.fhir.org/baseR4/",
)

# Query patients
response = client.get(resource_type="Patient", params={"family": "Smith"})

# Access the raw bundle
bundle = response.data
print(bundle)

# Access the resources
resources = response.resources
print(resources)

Asynchronous Client

from fhir_query import AsyncFhirQueryClient
import asyncio

async def main():
    # Initialize the async client
    client = AsyncFhirQueryClient(
        base_url="https://hapi.fhir.org/baseR4/",
    )

    # Query patients
    response = await client.get(
        resource_type="Patient",
        params={"gender": "female"}
    )

    # Convert to DataFrame
    df = response.to_df()
    print(df)

asyncio.run(main())

Authentication Methods

The client supports three authentication methods:

  • basic: Basic HTTP authentication with username and password
  • token: Bearer token authentication
  • login: Login-based authentication that obtains a token from a login endpoint

Bundle Handling

The FhirQueryBundle class provides convenient methods to work with FHIR Bundle responses:

# Get total count
total_count = bundle.total

# Access resources
resources = bundle.resources

# Convert to DataFrame
df = bundle.to_df()

# Pagination
next_link = bundle.next_link
previous_link = bundle.previous_link

About

A simple client to query FHIR servers

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published