AidboxTrigger
The AidboxTrigger resource is available starting from version 2505 and is currently in the alpha stage.
AidboxTrigger is a powerful feature that enables automatic execution of SQL statements in response to FHIR resource operations. It acts as a database-level hook system that can maintain data consistency, implement custom business logic, or integrate with external systems through database operations.
How AidboxTrigger works
AidboxTrigger works by registering SQL statements that are executed automatically after successful FHIR CRUD operations. The system:
Monitors
AidboxTrigger
resources in your Aidbox instanceExecutes the configured SQL statements when matching FHIR operations occur
Supports parameterized queries using
{{id}}
template substitutionEnsures transactional consistency with automatic rollback on errors
Configure AidboxTrigger
Creating triggers
To set up an AidboxTrigger, create an AidboxTrigger
resource with the following structure:
Only SQL statements that modify data (INSERT, UPDATE, DELETE) can be executed. Be cautious when designing your triggers, as this limitation prevents data retrieval operations and ensures that the triggers focus solely on data manipulation.
Required fields
action
(string array): Array of operations that trigger the SQL executionresource
(string): The FHIR resource type to monitorsql
(string): The SQL statement to execute
Supported actions
create
Executes when a new FHIR resource is created
POST operations, Bundle entries with POST
update
Executes when an existing FHIR resource is updated
PUT and PATCH operations, Bundle entries with PUT/PATCH
delete
Executes when a FHIR resource is deleted
DELETE operations, Bundle entries with DELETE
Examples
Basic audit logging
Set up a queue table and triggers to log all Patient operations:
Create triggers for all operations:
Multiple {{id}} usage
You can use multiple {{id}}
references in a single SQL statement:
SQL without parameters
Triggers don't require the {{id}}
parameter:
Error Handling and Rollback
Automatic Rollback
AidboxTrigger ensures data consistency through automatic rollback:
If any trigger SQL fails, the entire FHIR operation is rolled back
The original FHIR resource operation returns a 500 error
No partial state changes are persisted
Bundle Operations
AidboxTrigger respects Bundle transaction semantics:
Batch Bundles: Partial failure is allowed - successful operations have their triggers executed, failed operations are skipped.
Transaction Bundles: Complete rollback on any failure - if any operation or trigger fails, all changes are rolled back.
Best Practices
Keep trigger SQL statements lightweight and fast
Avoid complex queries that might slow down FHIR operations
Consider using background processing for heavy operations
Test your SQL statements thoroughly before deploying triggers
Ensure trigger SQL follows least-privilege principles
Validate that triggers don't expose sensitive data
Last updated
Was this helpful?