CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-fhirpy

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%

Overview
Eval results
Files

task.mdevals/scenario-1/

Typed FHIR Gateway

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.

Capabilities

Custom serialization for typed patients

  • When saving a patient model, applies the provided serialization hook to produce the outbound JSON (e.g., uppercases the family name and excludes unset optional fields). @test

Save patient and return typed model

  • Saving a patient without an id sends it to the server and returns a typed model with the server-assigned id filled in. @test

Fetch patient as typed model

  • Fetching a patient by id returns a typed model with given and family names mapped from the FHIR response. @test

Query latest weight observations

  • Fetching the latest weight observations for a patient returns typed observation models sorted from newest to oldest, preserving value and unit from the response. @test

Implementation

@generates

API

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."""

Dependencies { .dependencies }

fhir-py { .dependency }

Python FHIR client used for typed resources, serialization hooks, and search/query helpers.

tile.json