Skip to main content

Crate octofhir_sof

Crate octofhir_sof 

Source
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 resource
  • SqlGenerator - Generates SQL from ViewDefinitions
  • ViewRunner - 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

See: https://build.fhir.org/ig/FHIR/sql-on-fhir-v2/

Modules§

output
Output format writers for view results.

Structs§

Column
A column definition in a ViewDefinition.
ColumnInfo
Information about a column in a view result.
CompiledView
A ViewDefinition compiled once for repeated, resource-at-a-time execution.
Constant
A constant value that can be referenced in FHIRPath expressions.
GeneratedColumn
A generated column with its SQL expression and metadata.
GeneratedSql
Generated SQL with column metadata.
SelectColumn
A select clause that defines columns or nested structures.
SqlGenerator
Generates SQL queries from ViewDefinitions.
ViewDefinition
A ViewDefinition resource that defines a tabular view over FHIR data.
ViewResult
Results from executing a ViewDefinition.
ViewRunner
Executes ViewDefinitions against a PostgreSQL database.
WhereClause
A where clause for filtering rows.

Enums§

ColumnType
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 TABLE statement for the given columns.
execute
Execute a ViewDefinition against in-memory FHIR resources.
execute_blocking
Blocking convenience wrapper around execute for non-async callers.
run_with
Execute a ViewDefinition by generating SQL and delegating row fetching to an external SqlExecutor. Produces the same ViewResult as ViewRunner::run, so callers can swap the database layer without changing downstream handling.

Type Aliases§

Result
Result type alias using the crate’s Error type.