Skip to content

FHIR R4 integration — ingest patient medication lists for richer drug safety checks #4

Description

@sarvanithin

Overview

Clinical systems expose patient data via FHIR R4 APIs (Epic, Cerner, etc.). If medguard can pull a patient's current medication list from a FHIR server, it can check the LLM query against the full medication profile — not just drugs mentioned in the message.

What to build

  • medguard/integrations/fhir.py — FHIRMedicationLoader
    • get_medications(patient_id, fhir_base_url, token) → list[str] drug names
    • Parses MedicationRequest and MedicationStatement FHIR resources
    • Uses httpx (already a dependency)
  • MedGuard.achat(message, fhir_context=None) — optional FHIR context
  • When fhir_context provided, drug safety checks include FHIR medications + message drugs

FHIR endpoint example

GET {base}/MedicationRequest?patient={id}&status=active
Authorization: Bearer {token}

Files to create/modify

  • medguard/integrations/fhir.py — new file
  • medguard/core.py — accept optional fhir_context in achat
  • medguard/guardrails/drug_safety.py — merge FHIR drugs with extracted drugs

Acceptance criteria

  • FHIRMedicationLoader.get_medications(...) parses FHIR MedicationRequest JSON
  • Medications from FHIR are included in drug safety check
  • Works with public FHIR test server (https://hapi.fhir.org/baseR4)
  • Tests use mocked FHIR responses

Resources

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions