| Crates.io | octofhir-canonical-manager |
| lib.rs | octofhir-canonical-manager |
| version | 0.1.26 |
| created_at | 2025-08-05 09:47:21.164233+00 |
| updated_at | 2026-01-02 22:42:34.335644+00 |
| description | FHIR Canonical Manager - Library-first FHIR package management |
| homepage | |
| repository | https://github.com/octofhir/canonical-manager-rs |
| max_upload_size | |
| id | 1781776 |
| size | 849,162 |
A library-first solution for managing FHIR Implementation Guide packages, providing fast canonical URL resolution and resource search capabilities.
This crate supports several optional features:
sqlite (included in default): Enables SQLite storage backend
SqliteStorage implementationCanonicalManager::new() and UnifiedStorage::new()cli (included in default): Enables the command-line interface
sqlite featureoctofhir-fcm binaryfuzzy-search: Enables fuzzy matching for canonical URL resolution
metrics: Enables performance metrics collection
By default, both sqlite and cli features are enabled. To use the library without SQLite:
[dependencies]
octofhir-canonical-manager = { version = "0.1", default-features = false }
To use with only the SQLite storage (no CLI):
[dependencies]
octofhir-canonical-manager = { version = "0.1", default-features = false, features = ["sqlite"] }
Add to your Cargo.toml:
[dependencies]
octofhir-canonical-manager = "0.1"
tokio = { version = "1.0", features = ["full"] }
Basic usage:
use octofhir_canonical_manager::{CanonicalManager, FcmConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Load configuration
let config = FcmConfig::load()?;
let manager = CanonicalManager::new(config).await?;
// Install a FHIR package
manager.install_package("hl7.fhir.us.core", "6.1.0").await?;
// Resolve a canonical URL
let resource = manager.resolve(
"http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
).await?;
println!("Found resource: {}", resource.id);
// Search for resources
let results = manager.search()
.resource_type("StructureDefinition")
.package("hl7.fhir.us.core")
.execute().await?;
println!("Found {} structure definitions", results.len());
// Get search parameters for a resource type
let search_params = manager.get_search_parameters("Patient").await?;
println!("Found {} search parameters for Patient", search_params.len());
Ok(())
}
If you want to use a different storage backend (PostgreSQL, MongoDB, etc.), you can implement the PackageStore and SearchStorage traits:
use octofhir_canonical_manager::{
CanonicalManager, FcmConfig,
PackageStore, SearchStorage,
};
use std::sync::Arc;
// Implement the PackageStore trait for your storage
struct MyPostgresStorage {
// Your storage fields
}
#[async_trait::async_trait]
impl PackageStore for MyPostgresStorage {
// Implement required methods
async fn add_package(&self, package: &ExtractedPackage) -> Result<()> {
// Your implementation
}
async fn remove_package(&self, name: &str, version: &str) -> Result<bool> {
// Your implementation
}
async fn find_resource(&self, canonical_url: &str) -> Result<Option<ResourceIndex>> {
// Your implementation
}
async fn list_packages(&self) -> Result<Vec<PackageInfo>> {
// Your implementation
}
}
#[async_trait::async_trait]
impl SearchStorage for MyPostgresStorage {
// Implement required methods
// See trait definition for all required methods
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = FcmConfig::default();
let storage = Arc::new(MyPostgresStorage::new());
let registry = Arc::new(MyCustomRegistry::new());
let manager = CanonicalManager::new_with_components(
config,
storage.clone(), // PackageStore
registry, // AsyncRegistry
storage, // SearchStorage
).await?;
// Use manager as normal
Ok(())
}
Install the CLI tool:
cargo install octofhir-canonical-manager --features cli
Initialize and use:
# Initialize configuration
octofhir-fcm init
# Install packages
octofhir-fcm install hl7.fhir.us.core@6.1.0
# Search resources
octofhir-fcm search "Patient" --resource-type StructureDefinition
# Get search parameters for a resource type
octofhir-fcm search-params Patient
octofhir-fcm search-params Patient --format json
octofhir-fcm search-params Patient --format csv
# Resolve canonical URLs
octofhir-fcm resolve "http://hl7.org/fhir/us/core/StructureDefinition/us-core-patient"
# List installed packages
octofhir-fcm list
Create a fcm.toml configuration file:
[registry]
url = "https://fs.get-ig.org/pkgs/"
timeout = 60
retry_attempts = 5
[[packages]]
name = "hl7.fhir.r4.core"
version = "4.0.1"
priority = 1
[storage]
cache_dir = ".fcm/cache"
packages_dir = ".fcm/packages"
max_cache_size = "2GB"
# Optimization settings (SQLite handles indexing automatically)
[optimization]
# Parallel processing
parallel_workers = 8
batch_size = 100
# Change detection
enable_checksums = true
checksum_algorithm = "blake3"
checksum_cache_size = 10000
# Performance monitoring
enable_metrics = true
metrics_interval = "30s"
url: FHIR package registry URLtimeout: Network timeout in secondsretry_attempts: Number of retry attempts for failed requestscache_dir: Directory for package downloads cachepackages_dir: Directory for extracted packagesmax_cache_size: Maximum cache size (e.g., "2GB", "500MB")parallel_workers: Number of workers for parallel package processingbatch_size: Batch size for parallel operationsenable_checksums: Enable package checksum validation for change detectionchecksum_algorithm: Algorithm to use (blake3, sha256, sha1)checksum_cache_size: Size of checksum cacheenable_metrics: Enable performance metrics collectionmetrics_interval: Metrics collection intervalNote: SQLite handles indexing, compression, and memory mapping automatically - no manual configuration needed!
CanonicalManager: Main entry point for all operationsFcmConfig: Configuration managementCanonicalResolver: Fast URL resolution engineSearchEngine: Advanced resource search capabilitiesSqliteStorage: SQLite-based storage with automatic indexing// Package management
manager.install_package("package-name", "version").await?;
manager.remove_package("package-name", "version").await?;
manager.list_packages().await?;
// Batch installation (optimized for multiple packages)
manager.install_packages_batch(&packages).await?;
// Resource resolution
let resource = manager.resolve("canonical-url").await?;
let resources = manager.batch_resolve(&urls).await?;
// Resolution with FHIR version
let resource = manager.resolve_with_fhir_version(
"http://hl7.org/fhir/StructureDefinition/Patient",
"4.0.1"
).await?;
// Search functionality
let results = manager.search()
.resource_type("StructureDefinition")
.package("hl7.fhir.us.core")
.canonical_pattern("Patient")
.execute().await?;
// Search parameter retrieval
let search_params = manager.get_search_parameters("Patient").await?;
for param in search_params {
println!("{}: {} ({})", param.code, param.name, param.type_field);
}
// Load local packages
manager.load_from_directory("/path/to/package", Some("my.package@1.0.0")).await?;
manager.load_resources_from_directory("/path/to/resources").await?;
| Command | Description |
|---|---|
init |
Initialize FCM configuration |
install <package>[@version] |
Install FHIR package |
remove <package>[@version] |
Remove FHIR package |
list |
List installed packages |
search <query> |
Search for resources |
search-params <resource-type> |
Get search parameters for a resource type |
resolve <url> |
Resolve canonical URL |
update |
Update package indexes |
The canonical manager is optimized for speed and reliability:
# Run tests
just test
# Check code quality
just check
# Fix formatting and linting
just fix-all
# Prepare for publishing
just prepare-publish
# Generate documentation
just docs
# Run examples
cargo run --example search_parameters
cargo run --example configuration
See the examples directory for more usage examples:
basic_usage.rs: Basic package management and resolutionsearch_parameters.rs: Working with FHIR SearchParametersconfiguration.rs: Configuration managementLicensed under either of:
at your option.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Made with ❤️ by OctoFHIR Team 🐙🦀