1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//! Helios FHIR Server Persistence Layer
//!
//! This crate provides a polyglot persistence layer for storing and retrieving FHIR resources.
//! It supports multiple database backends via feature flags and provides configurable
//! multitenancy with full FHIR search capabilities.
//!
//! # Features
//!
//! - **Multiple Backends**: SQLite, PostgreSQL, Cassandra, MongoDB, Neo4j, Elasticsearch, S3
//! - **Multitenancy**: Three isolation strategies (shared schema, schema-per-tenant, database-per-tenant)
//! - **Full FHIR Search**: All parameter types, modifiers, chaining, _include/_revinclude
//! - **Versioning**: Full resource history with optimistic locking
//! - **Transactions**: ACID transactions with bundle support
//!
//! # Backend Features
//!
//! Enable backends with feature flags in `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! helios-persistence = { version = "0.1", features = ["postgres", "R4"] }
//! ```
//!
//! Available backend features:
//! - `sqlite` (default) - SQLite with in-memory and file modes
//! - `postgres` - PostgreSQL with JSONB storage
//! - `cassandra` - Apache Cassandra via cdrs-tokio
//! - `mongodb` - MongoDB document storage
//! - `neo4j` - Neo4j graph database
//! - `elasticsearch` - Elasticsearch for full-text search
//! - `s3` - AWS S3 object storage
//!
//! FHIR version features:
//! - `R4`, `R4B`, `R5`, `R6`
//!
//! # Architecture
//!
//! The persistence layer is organized into several modules:
//!
//! - [`tenant`] - Multi-tenant support with mandatory tenant context
//! - [`types`] - Core types for stored resources and search
//! - [`error`] - Error types for all operations
//! - [`core`] - Storage traits and abstractions
//! - [`strategy`] - Tenancy isolation strategies (shared schema, schema-per-tenant, database-per-tenant)
//! - [`backends`] - Backend implementations (SQLite, PostgreSQL, etc.)
//!
//! # Quick Start
//!
//! ```no_run
//! use helios_persistence::tenant::{TenantContext, TenantId, TenantPermissions};
//! use helios_persistence::types::StoredResource;
//! use helios_fhir::FhirVersion;
//! use serde_json::json;
//!
//! // Create a tenant context (required for all operations)
//! let tenant = TenantContext::new(
//! TenantId::new("my-organization"),
//! TenantPermissions::full_access(),
//! );
//!
//! // Create a stored resource
//! let resource = StoredResource::new(
//! "Patient",
//! "patient-123",
//! tenant.tenant_id().clone(),
//! json!({
//! "resourceType": "Patient",
//! "id": "patient-123",
//! "name": [{"family": "Smith", "given": ["John"]}]
//! }),
//! FhirVersion::default(),
//! );
//!
//! // The resource includes persistence metadata
//! assert_eq!(resource.version_id(), "1");
//! assert_eq!(resource.url(), "Patient/patient-123");
//! ```
//!
//! # Multitenancy
//!
//! All storage operations require a [`TenantContext`](tenant::TenantContext), ensuring
//! tenant isolation at the type level. There is no way to bypass this requirement.
//!
//! ```
//! use helios_persistence::tenant::{TenantContext, TenantId, TenantPermissions, Operation};
//!
//! // Full access tenant
//! let admin_ctx = TenantContext::new(
//! TenantId::new("acme"),
//! TenantPermissions::full_access(),
//! );
//!
//! // Read-only tenant
//! let reader_ctx = TenantContext::new(
//! TenantId::new("acme"),
//! TenantPermissions::read_only(),
//! );
//!
//! // Check permissions
//! assert!(admin_ctx.check_permission(Operation::Create, "Patient").is_ok());
//! assert!(reader_ctx.check_permission(Operation::Create, "Patient").is_err());
//! ```
//!
//! # Search
//!
//! Build search queries with full FHIR search support:
//!
//! ```
//! use helios_persistence::types::{
//! SearchQuery, SearchParameter, SearchParamType, SearchValue,
//! SearchModifier, SortDirective, IncludeDirective, IncludeType,
//! };
//!
//! // Simple search
//! let query = SearchQuery::new("Patient")
//! .with_parameter(SearchParameter {
//! name: "name".to_string(),
//! param_type: SearchParamType::String,
//! modifier: Some(SearchModifier::Contains),
//! values: vec![SearchValue::eq("smith")],
//! chain: vec![],
//! components: vec![],
//! })
//! .with_sort(SortDirective::parse("-_lastUpdated"))
//! .with_count(20);
//!
//! // With _include
//! let query_with_include = SearchQuery::new("Observation")
//! .with_include(IncludeDirective {
//! include_type: IncludeType::Include,
//! source_type: "Observation".to_string(),
//! search_param: "patient".to_string(),
//! target_type: Some("Patient".to_string()),
//! iterate: false,
//! });
//! ```
// Re-export commonly used types at crate root
pub use ;
pub use ;
pub use ;
// Re-export core traits
pub use ;
// Re-export tenancy strategies
pub use ;
/// Crate version.
pub const VERSION: &str = env!;
/// Crate name.
pub const NAME: &str = env!;