fhir_sqlite_gen/lib.rs
1//! fhir-sqlite-gen: generates the fhir-sqlite relational map from the official FHIR
2//! specification packages (profiles-resources.json, profiles-types.json).
3// Nothing here has any business dereferencing a raw pointer: this code
4// parses and reshapes untrusted clinical data, and memory safety is the
5// property that keeps a malformed resource from becoming a vulnerability.
6#![forbid(unsafe_code)]
7
8pub mod assets;
9pub mod build;
10pub mod names;
11pub mod search;
12pub mod spec;
13
14use std::path::Path;
15
16use fhir_sqlite_map::RelMap;
17use thiserror::Error;
18
19#[derive(Debug, Error)]
20pub enum GenError {
21 #[error("spec: {0}")]
22 Spec(String),
23 #[error("build: {0}")]
24 Build(String),
25}
26
27/// Generate the relational map for one FHIR version from a definitions
28/// directory containing profiles-resources.json and profiles-types.json.
29pub fn generate(definitions_dir: &Path, schema: &str) -> Result<RelMap, GenError> {
30 let spec = spec::load_spec(definitions_dir)?;
31 let mut map = build::build_map(&spec, schema)?;
32 search::compile_search(&mut map, definitions_dir)?;
33 search::add_norm_columns(&mut map);
34 // U1/U9: after the fold columns, and only where the dialect needs them.
35 search::add_adjunct_columns(&mut map);
36 // G2.6a: after every column is placed, so the bound is a fact of the
37 // finished map (F-90).
38 build::assert_row_budget(&map)?;
39 // U12a: last, so the bound is a fact of the finished map.
40 build::record_path_bound(&mut map);
41 Ok(map)
42}