Skip to main content

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, or performer parameters pointing to a Patient
  • Encounter Compartment: Resources with encounter or context parameters pointing to an Encounter
  • Device Compartment: Resources with device or subject parameters pointing to a Device

CompartmentDefinition Resources

Ferrum uses CompartmentDefinition resources to define compartment membership rules. When you create or update a CompartmentDefinition, the server automatically:
  1. Parses the compartment type (e.g., “Patient”, “Encounter”)
  2. Extracts resource membership rules from the resource[] array
  3. Updates the compartment_memberships database table
  4. Enables compartment searches for that compartment type
Example CompartmentDefinition:

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 using startParam and endParam:
This means an Account is only in the Patient compartment during its period date range.

Database Schema

Ferrum stores compartment membership rules in the compartment_memberships table:

Search Examples

Advanced Search Features

All standard FHIR search features work within compartments:

Managing CompartmentDefinitions

Creating a CompartmentDefinition

Updating Compartment Rules

When you update a CompartmentDefinition, Ferrum automatically:
  1. Clears existing membership rules for that compartment type
  2. Rebuilds the rules from the updated definition
  3. 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:
To fully disable a compartment, create a CompartmentDefinition with an empty resource array.

Configuration

Compartment search can be disabled in the server configuration:

Performance Considerations

  • Indexing: Ferrum uses GIN indexes on parameter_names for 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

Error Handling