-
Notifications
You must be signed in to change notification settings - Fork 27
Closed
Labels
Component: GatewayIssue/PR that handles connections, API gatewaysIssue/PR that handles connections, API gatewaysResolution: StaleStale or out of scope issueStale or out of scope issue
Description
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 testingGoal:
Create a @fhir.predict() decorator that wraps user prediction functions and automatically:
- Handles FHIR resource construction
- Manages patient references
- Formats prediction output correctly
- 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
Labels
Component: GatewayIssue/PR that handles connections, API gatewaysIssue/PR that handles connections, API gatewaysResolution: StaleStale or out of scope issueStale or out of scope issue
Type
Projects
Status
Done