Expand description
SQL on FHIR implementation for OctoFHIR.
This crate provides support for the SQL on FHIR specification, which enables transformation of FHIR resources into tabular data using ViewDefinition resources.
§Overview
SQL on FHIR allows you to define views over FHIR resources that can be materialized as relational tables. This is useful for analytics, reporting, and integration with SQL-based tools.
§Components
ViewDefinition- Parsed representation of a FHIR ViewDefinition resourceSqlGenerator- Generates SQL from ViewDefinitionsViewRunner- Executes views against a PostgreSQL database
§Example
ⓘ
use octofhir_sof::{ViewDefinition, SqlGenerator, ViewRunner};
// Parse a ViewDefinition
let view_def = ViewDefinition::from_json(&json)?;
// Generate SQL
let generator = SqlGenerator::new();
let sql = generator.generate(&view_def)?;
// Execute the view
let runner = ViewRunner::new(pool, generator);
let result = runner.run(&view_def).await?;§SQL on FHIR Specification
Modules§
- output
- Output format writers for view results.
Structs§
- Column
- A column definition in a ViewDefinition.
- Column
Info - Information about a column in a view result.
- Compiled
View - A ViewDefinition compiled once for repeated, resource-at-a-time execution.
- Constant
- A constant value that can be referenced in FHIRPath expressions.
- Generated
Column - A generated column with its SQL expression and metadata.
- Generated
Sql - Generated SQL with column metadata.
- Select
Column - A select clause that defines columns or nested structures.
- SqlGenerator
- Generates SQL queries from ViewDefinitions.
- View
Definition - A ViewDefinition resource that defines a tabular view over FHIR data.
- View
Result - Results from executing a ViewDefinition.
- View
Runner - Executes ViewDefinitions against a PostgreSQL database.
- Where
Clause - A where clause for filtering rows.
Enums§
- Column
Type - Data types supported by SQL on FHIR columns.
- Dialect
- SQL dialect for DDL type names.
- Error
- Errors that can occur during SQL on FHIR operations.
Traits§
- SqlExecutor
- Fetches rows for SoF-generated SQL through an external database layer.
Functions§
- create_
table - Render a
CREATE TABLEstatement for the given columns. - execute
- Execute a ViewDefinition against in-memory FHIR resources.
- execute_
blocking - Blocking convenience wrapper around
executefor non-async callers. - run_
with - Execute a ViewDefinition by generating SQL and delegating row fetching to an
external
SqlExecutor. Produces the sameViewResultasViewRunner::run, so callers can swap the database layer without changing downstream handling.
Type Aliases§
- Result
- Result type alias using the crate’s Error type.