Bits & Flames bitsandflames/fyron

FHIR

fyron.fhir is the interoperability layer for FHIR extraction, SQL-backed FHIR warehouses, resource builders, bundle mapping, and lightweight JSON validation. The parent module keeps the decision simple: choose REST for live endpoints, SQL for warehouse tables, Builder for explicit resources, and Mapping for reviewed DataFrames.

FHIR servers vary by institution and implementation guide. Fyron keeps transport, extraction, table construction, and write-back separated so each step stays inspectable.

FHIR Submodules

ChapterUse it for
FHIR RESTLive endpoint searches, pagination, row-wise cohort lookups, and write-back.
FHIR SQLSQL-backed FHIR warehouses, joins, streaming, and parallel query jobs.
FHIR BuilderHand-building R4/R6 resources and evidence bundles.
FHIR MappingTurning reviewed DataFrames into FHIR bundles.

Choose The Right Path

NeedPrefer
Pull resources from a FHIR serverFHIR REST
Query a relational FHIR warehouseFHIR SQL
Build one resource or a small evidence bundle by handFHIR Builder
Convert an LLM/BOA/review CSV table into FHIR JSONFHIR Mapping
Extract specific nested fields from REST resourcesFHIR Paths & Custom Extraction
Reuse common FHIRPath extraction columnsget_fhir_path_preset(...) in FHIR REST

Imports

python
from fyron import Auth, FHIRRestClient, FHIRSQLClient
from fyron.fhir import FHIRObj, get_fhir_path_preset, safe_get
from fyron.fhir.builder import build_observation, build_bundle
from fyron.fhir.mapping import build_observations_from_dataframe

Minimal REST Example

python
from fyron import FHIRRestClient

client = FHIRRestClient("https://hapi.fhir.org/baseR4")
patients = client.search_df("Patient", params={"_count": 25}, max_pages=1)

Minimal SQL Example

python
from fyron import FHIRSQLClient

client = FHIRSQLClient(dsn="postgresql://user:password@localhost/fhir")
patients = client.query_df("select id as patient_id from patient limit 100")

Build Or Map FHIR JSON

python
from fyron.fhir.builder import build_bundle, build_observation

observation = build_observation(
    subject="Patient/123",
    code="L3 skeletal muscle area",
    value=123.4,
    unit="cm2",
)
bundle = build_bundle([observation], bundle_type="collection")

Use FHIR Mapping when the same information already exists as a reviewed DataFrame or CSV.

Common Pitfalls

  • FHIR references can be bare, relative, or absolute; normalize identifiers before cohort joins.
  • Search parameter support differs across FHIR servers.
  • Resource JSON may differ by implementation guide; keep local extraction assumptions visible.
  • Fyron validation is structural and lightweight, not a replacement for server/profile validation.
  • Core I/O for .env, local tables, Teable, and S3.
  • Cohort Tables for joining extracted features to outcomes.
  • Unified CLI for repeatable fyron fhir-rest and fyron fhir-build-bundle jobs.