Implementation Features
Endpoints
Ferrum supports the standard FHIR compartment search endpoints:
Examples:
The literal
* in the URL path means “all resource types in this
compartment”. For POST searches, use the /_search endpoint without the *.How Compartments Work
Compartment Membership
Resources belong to a compartment when they reference the compartment resource through specific search parameters. For example:- Patient Compartment: Resources with
patient,subject, orperformerparameters pointing to a Patient - Encounter Compartment: Resources with
encounterorcontextparameters pointing to an Encounter - Device Compartment: Resources with
deviceorsubjectparameters pointing to a Device
CompartmentDefinition Resources
Ferrum usesCompartmentDefinition resources to define compartment membership rules. When you create or update a CompartmentDefinition, the server automatically:
- Parses the compartment type (e.g., “Patient”, “Encounter”)
- Extracts resource membership rules from the
resource[]array - Updates the
compartment_membershipsdatabase table - Enables compartment searches for that compartment type
Special Parameter Values
{def}: The compartment resource itself (e.g., Patient in Patient compartment)- Multiple parameters: OR logic - resource is in compartment if ANY parameter matches
- Empty param array: Resource type is NOT in this compartment
Temporal Boundaries
Some resources have time-based membership usingstartParam and endParam:
period date range.
Database Schema
Ferrum stores compartment membership rules in thecompartment_memberships table:
Search Examples
Basic Compartment Search
Advanced Search Features
All standard FHIR search features work within compartments:Type Filtering in All-Types Search
Managing CompartmentDefinitions
Creating a CompartmentDefinition
Updating Compartment Rules
When you update a CompartmentDefinition, Ferrum automatically:- Clears existing membership rules for that compartment type
- Rebuilds the rules from the updated definition
- Applies changes immediately to new searches
Deleting CompartmentDefinitions
Per FHIR spec, servers may continue using compartment definitions even after deletion. Ferrum keeps the membership rules unless explicitly replaced:resource array.
Configuration
Compartment search can be disabled in the server configuration:Performance Considerations
- Indexing: Ferrum uses GIN indexes on
parameter_namesfor efficient membership queries - Caching: Compartment membership rules are loaded once per search and cached
- Query Optimization: The search engine builds optimized SQL queries with proper JOINs
- Resource Types: Searching specific resource types is more efficient than all-types searches
Limitations
- Compartment Instance Validation: Ferrum does not validate that the compartment resource (e.g., Patient/123) exists
- Empty Results: Non-existent compartment instances return empty search results rather than errors
- Temporal Boundaries: Currently stored but not yet fully implemented in search logic