Skip to content

Create @fhir.predict() decorator for simplified ML model deployment #143

@jenniferjiangkells

Description

@jenniferjiangkells

Add a convenience decorator that simplifies deploying ML models as FHIR endpoints by abstracting away the FHIR resource boilerplate.

Current approach (verbose):

from fhir.resources.reference import Reference
from fhir.resources.riskassessment import RiskAssessment

from healthchain.gateway import HealthChainAPI, FHIRGateway


app = HealthChainAPI(title="Sepsis Risk Assessment")

fhir = FHIRGateway()
fhir.add_source("epic", "fhir://epic.org/api/FHIR/R4/test")

@fhir.transform(RiskAssessment)
def sepsis_risk_transform(id: str, source: str | None = None) -> RiskAssessment:
    predicted_score = round(random(), 3)
    return RiskAssessment(
        status="completed",
        subject=Reference(reference=f"Patient/{id}"),
        prediction=[{"probabilityDecimal": predicted_score}],
    )

Proposed approach (cleaner):

@fhir.predict(resource=RiskAssessment)
def sepsis_risk(patient_id: str) -> float:
    """Just return the prediction score, decorator handles FHIR formatting."""
    # Load your model and make prediction
    return model.predict(patient_data)  # Or round(random(), 3) for testing

Goal:
Create a @fhir.predict() decorator that wraps user prediction functions and automatically:

  1. Handles FHIR resource construction
  2. Manages patient references
  3. Formats prediction output correctly
  4. Supports both sync and async functions

Implementation Location:
Add to healthchain/gateway/fhir/base.py or create healthchain/gateway/fhir/decorators.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: GatewayIssue/PR that handles connections, API gatewaysResolution: StaleStale or out of scope issue

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions