Async/sync FHIR client for Python providing comprehensive API for CRUD operations over FHIR resources
Agent Success
Agent success rate when using this tile
68%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.08x
Baseline
Agent success rate without this tile
63%
Implement a typed gateway around a FHIR server that uses the dependency's typed model support and customizable serialization hook to send and receive resources as strongly typed objects.
@generates
from dataclasses import dataclass
from datetime import datetime
from typing import Callable, List, Optional, Union
@dataclass
class PatientModel:
id: Optional[str]
given_name: str
family_name: str
birth_date: str
@dataclass
class ObservationModel:
id: Optional[str]
patient_id: str
weight_value: float
weight_unit: str
issued_at: datetime
TypedModel = Union[PatientModel, ObservationModel]
class TypedFHIRGateway:
def __init__(
self,
base_url: str,
*,
auth_token: Optional[str] = None,
serialization_hook: Optional[Callable[[TypedModel], dict]] = None,
):
"""
Initialize a gateway that uses the dependency's client in typed mode.
serialization_hook transforms typed models into request payloads.
"""
def save_patient(self, patient: PatientModel) -> PatientModel:
"""Create or update a patient using typed integration, returning a typed model with id set."""
def fetch_patient(self, patient_id: str) -> PatientModel:
"""Retrieve a patient by id and map the response into a typed patient model."""
def fetch_latest_weight(self, patient_id: str, limit: int = 3) -> List[ObservationModel]:
"""Return the newest weight observations for a patient as typed models, newest first."""Python FHIR client used for typed resources, serialization hooks, and search/query helpers.
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10