Overview
The Events API provides endpoints for managing clinical events, digital signatures, and event attachments. This includes integration with external devices and systems for importing clinical data.API Modules
The Events API is split across multiple modules:- Sign Module: Digital signature capture and validation
- Request Module: External data integration and queue management
- Attachment Module: Event attachment display and management
Event Model Reference
The Event model (protected/models/Event.php) represents clinical events:
Core Attributes
id- Event unique identifierepisode_id- Associated episode IDuser_id- User who created the eventevent_type_id- Type of clinical eventinfo- Additional event informationdeleted- Soft delete flagdelete_reason- Reason for deletionis_automated- Whether event was auto-generatedautomated_source- JSON structure describing automation sourceevent_date- Date of the clinical eventcreated_date- Record creation timestamplast_modified_date- Last modification timestampfirm_id- Associated firm/serviceparent_id- Parent event (for linked events)
Related Models
episode- Patient episodeeventType- Event type definitionuser- Creating usereventAttachmentGroups[]- Attached files/imagesparent- Parent eventchildren[]- Child events
protected/models/Event.php:1-100
Digital Signatures API
Add Signature
Import a digital signature for a clinical event.Request Body
Unique code identifying the event. Validated using
UniqueCodes::eventFromUniqueCode().JSON string containing element information:
e_id(integer, required) - Element IDe_t_id(integer, required) - Element type ID
{"e_id": 123, "e_t_id": 456}Base64-encoded signature image (PNG format recommended)
Base64-encoded original signature image before cropping
For manual crop operations, references the original import log ID
Response
Success Response:200 OK
Error Response:
200 OK (note: error returned with 200 status)
Bad Request:
400 Bad Request
Validation Errors
The endpoint validates:- Missing unique_identifier:
"Missing unique_identifier" - Missing extra_info:
"Missing element and element type ids" - Missing e_id in extra_info:
"Missing element id." - Missing e_t_id in extra_info:
"Missing element type id." - Event not found:
"Event not found" - Invalid unique code:
"Invalid UniqueCode or wrong event"
protected/modules/Api/controllers/SignController.php:52-95
Access Control
Source:SignController.php:37-49
CORS Support
The endpoint includes CORS headers:SignController.php:142
Implementation Details
The signature import process (lines 140-209):- Accepts POST request with JSON body
- Validates unique identifier and retrieves event
- Validates request data structure
- Saves signature image to protected file storage
- Creates signature element and associates with event
- Logs import attempt with status (success/failure)
- Updates CVI event information if applicable
- Returns success or error message
Signature File Storage
Signatures are stored using theProtectedFile model:
SignController.php:102-112
Signature Import Logging
All signature import attempts are logged:SignController.php:119-130
Event Attachments API
View Attachment
Retrieve an event attachment by ID.Query Parameters
Attachment data ID from the
attachment_data tableMIME type for Content-Type header (e.g.,
image/png, image/jpeg, application/pdf)Field name in the AttachmentData model containing the binary data
Response
Returns the raw attachment data with appropriate headers:Caching
The endpoint implements conditional GET with ETags:- Returns
304 Not Modifiedif client cache is current - Uses
If-Modified-Sinceheader for validation - Sets immutable cache for 1 year (attachments are versioned by ID)
AttachmentDisplayController.php:53-93
Authentication
Requires authenticated user:AttachmentDisplayController.php:38-50
Request Queue API
Add to Queue
Submit external device data to the processing queue.Request Body
Type of request being submitted (e.g., “diagnostic_data”, “imaging”, “form_data”)
Message from the external system describing the data
The actual data payload. Structure depends on content type and request handler.
Content Types Supported
The endpoint supports multiple content types:application/jsonmultipart/form-dataapplication/x-www-form-urlencoded
QueueController.php:26-30
Response
Success Response:200 OK
Validation Error Response:
422 Unprocessable Entity
System Error Response:
500 Internal Server Error
Source: QueueController.php:36-48
Request Processing Flow
- Determine content type from header or GET parameter
- Instantiate appropriate handler class dynamically
- Handler validates and processes request data
- Data saved to queue for async processing
- Return request ID or error details
QueueController.php:21-51
Event Attachment Groups
Event attachments are organized in groups associated with event elements.EventAttachmentGroup Model
Attributes:id- Group identifierevent_id- Associated event IDelement_type_id- Element type this group belongs to
event- Parent eventelementType- Element type definitioneventAttachmentItems[]- Individual attachment items in this group
protected/modules/Api/modules/Request/models/EventAttachmentGroup.php:17-79
Example: Retrieving Event Attachments
URL Routing
Main API Routes
protected/modules/Api/config/common.php:21
Request Module Routes
protected/modules/Api/modules/Request/config/common.php
Integration Examples
Python: Import Signature
JavaScript: Queue External Data
Best Practices
Signature Validation
Signature Validation
Always validate the
unique_identifier is correct before submitting signatures. Invalid codes cannot be corrected after submission.Image Encoding
Image Encoding
Ensure signature images are properly base64-encoded PNG format for best compatibility.
Error Handling
Error Handling
Check both HTTP status codes and response content. Some endpoints return error messages with 200 status.
Attachment Caching
Attachment Caching
Leverage the
If-Modified-Since header when repeatedly accessing the same attachment to reduce bandwidth.Queue Processing
Queue Processing
Data submitted to the queue is processed asynchronously. Implement polling or webhooks to check processing status.
Next Steps
Patient API
Search for patients to associate with events
Authentication
Secure your API requests