fhir-sqlite-gen 0.5.2

Generates the fhir-sqlite relational map from FHIR® specification packages. HL7®, and FHIR® are the registered trademarks of Health Level Seven International and their use of these trademarks does not constitute an endorsement by HL7. This project is an independent work.
Documentation
//! fhir-sqlite-gen: generates the fhir-sqlite relational map from the official FHIR
//! specification packages (profiles-resources.json, profiles-types.json).
// Nothing here has any business dereferencing a raw pointer: this code
// parses and reshapes untrusted clinical data, and memory safety is the
// property that keeps a malformed resource from becoming a vulnerability.
#![forbid(unsafe_code)]

pub mod assets;
pub mod build;
pub mod names;
pub mod search;
pub mod spec;

use std::path::Path;

use fhir_sqlite_map::RelMap;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum GenError {
    #[error("spec: {0}")]
    Spec(String),
    #[error("build: {0}")]
    Build(String),
}

/// Generate the relational map for one FHIR version from a definitions
/// directory containing profiles-resources.json and profiles-types.json.
pub fn generate(definitions_dir: &Path, schema: &str) -> Result<RelMap, GenError> {
    let spec = spec::load_spec(definitions_dir)?;
    let mut map = build::build_map(&spec, schema)?;
    search::compile_search(&mut map, definitions_dir)?;
    search::add_norm_columns(&mut map);
    // U1/U9: after the fold columns, and only where the dialect needs them.
    search::add_adjunct_columns(&mut map);
    // G2.6a: after every column is placed, so the bound is a fact of the
    // finished map (F-90).
    build::assert_row_budget(&map)?;
    // U12a: last, so the bound is a fact of the finished map.
    build::record_path_bound(&mut map);
    Ok(map)
}