Backend Workflow Guide
Step-by-step execution sequences for configuration, outbound triggers, bulk dispatch, inbound capture, retries, and Mirth handoff.
Backend Workflow Guide
This page maps standard integration executions as step-by-step sequences — from configuration through delivery, retry states, and Mirth handoff. For the UI-level walkthrough of how these workflows appear in the Support Dashboard, see the Workflow Guide at the feature root.
Workflow 1: Integration Configuration
Goal: Create or update an integration rule for a lab or organization.
- Support dashboard queries
get_developer_authenticationandget_actioncategory_listto populate the configuration UI. - UI fetches available
labIntegrationinstances for the resolved auth context. - User confirms endpoint, headers, and action mapping, then submits via
add_update_webhook_integration. - Backend writes
developerAuthenticationkeys andlabIntegrationrows keyed byactionCategoryListId.
Workflow 2: Outbound Event Trigger
Goal: Dispatch a payload to a third-party system when a LiveHealth business event fires.
- A business action completes normally (e.g., bill generated, sample received).
- The domain controller calls the corresponding trigger function (e.g.,
commomFunctionForIntegrationBillCategory,common_integration_sample_receive). - The trigger function fetches active
labIntegrationrows matching theactionCategoryListId. - For each matching integration, it calls
get_integration_payload()to build the structured payload. save_log_instance()pre-creates a log document in DocumentDB, returning alog_id.- The trigger enqueues a Fusion task via
commonFunctionForIntegrationWebhookCall, injecting thelog_idinto the payload. - The Fusion worker calls the internal webhook handler, which dispatches to the third-party endpoint.
WebhookIntegrationDirectoryLoggerupdates the DocumentDB log with the finalSUCCESSorFAILstatus.
Example: Billing API Trigger Flow
When a new bill is created:
- The endpoint
url(r'^billing/$', BillingView.as_view())is hit. BillingViewinvokes thebill_patientcore function.- After processing,
bill_patientcallscommomFunctionForIntegrationBillCategory. - The trigger function invokes
get_integration_payloadto prepare the exact integration payload, which pre-creates a log with alog_idand includes theintegration_callback_url. commonFunctionForIntegrationWebhookCallis called to dispatch the payload to Fusion.- Finally, the Fusion worker makes the HTTP call and hits the
integration_callback_urlto log the finalSUCCESSorFAILoutcome in the Integration Dashboard.
Workflow 3: Bulk Outbound Dispatch
Goal: Enqueue many integration tasks efficiently (e.g., consolidated report submissions).
- The trigger calls
commonIntegrationWebhookFunctionForBulk(...)with a list of records. - For each record, a payload is built and a Fusion task is constructed.
- All tasks are submitted in a single batch via
Fusion().bulk(...). - The
/integrationWebhookBulkAPI/endpoint processes each task asynchronously and independently.
Workflow 4: Inbound API Capture
Goal: Record that a third-party system called a LiveHealth API endpoint.
- The third party makes an authenticated request to a LiveHealth API (e.g.,
appointmentConfirmAPI). IntegrationDirectoryLoggercaptures the pre-call context: token, headers, body, IP, and origin.- The API view function executes normally — business logic runs without any modification.
- After the function returns, the decorator assembles and persists the full request/response payload to
IntegrationDirectory.
If the current DB transaction is in a broken state (needs_rollback=True), the decorator falls back to a Fusion webhook to persist the log out-of-band, ensuring the record is not lost.
Workflow 5: Fusion Worker Status Callback (integration_callback_url)
Goal: Report the final SUCCESS or FAIL outcome of a Fusion-dispatched HTTP call back to the Integration Dashboard.
This is the standard status-reporting mechanism for all outbound integrations dispatched via Fusion. It is baked into fusion_worker/tasks/webhooks.py and fires automatically after every third-party HTTP call.
- When
get_integration_payload()builds the dispatch payload, it includes anintegration_callback_url— pointing to the internal LiveHealth webhook handler decorated with@WebhookIntegrationDirectoryLogger. - The Fusion worker (
webhooks.py) picks up the queued task and makes the actual HTTP call to the third-party endpoint (viaGET(...),POST(...),PUT(...), orDELETE(...)). - After the response is received, the worker calls
send_integration_payload(), which:- Extracts
integration_payloadfrom the task args (checking bothargs.integration_payloadandargs.payload.integration_payload). - Checks the response for suppression signals — if the response code is
209or the response body contains"message": "#NOTFORDASHBOARD", the callback is skipped entirely and no status is written to the dashboard. - If not suppressed, enriches the payload with
end_point,request_headers,request_body,response_body,response_status_code,response_time,activity_date, and derivedstatus(SUCCESSfor HTTP 2xx,FAILotherwise). - POSTs the enriched payload to
integration_callback_urlwith an internal auth header (x-internal-token).
- Extracts
- The internal handler at
integration_callback_urlis wrapped by@WebhookIntegrationDirectoryLogger, which updates theIntegrationDirectorydocument with the final status.
Status suppression
Responses with code 209 or message #NOTFORDASHBOARD are intentionally excluded from the dashboard. Trigger functions use this to suppress noisy or expected non-errors (e.g., skipped records in a bulk run) without polluting the failure view.
Legacy callback pattern
Older integrations may still use integration_status_callback(...) or jio_integration_status_callback(...), which write human-readable notes to ActivityLog instead of updating IntegrationDirectory. These are not used for new integrations.
Workflow 6: Retry
Goal: Re-execute a failed or stalled integration with fresh domain context.
- A retry is triggered manually via the dashboard UI (routed through
RetryIntegrationView) or automatically by the auto-retry scheduler. - The system reads
action_category_list_idfrom the originalIntegrationDirectorylog to identify the correct trigger function. retry_context(serialized at first-time execution) is used by the appropriate_prepare_kwargs_*function to re-fetch live domain objects from the database.- The original trigger function is called with the freshly rebuilt arguments.
WebhookIntegrationDirectoryLogger(withis_retry_enabled=True) captures the outcome and callsIntegrationRetryLog.update_existing_record_and_push_update().- The parent
IntegrationDirectorydocument'sretry_countis incremented andstatusupdated. - A Pusher notification via
UpdateRetryIntegrationStatusrefreshes the dashboard in real time.
Workflow 7: Mirth / HL7 Handoff
Goal: Send an HL7 message to Mirth via TCP socket.
- The trigger calls
send_hl7_manual_sample_update()or an equivalent HL7 handler. - The handler reads host, port, and transport settings from
labIntegration.integrationExtraDetails. update_message_with_ids()injectsLABIDandLOGIDinto the HL7 message body for downstream traceability and stamps the log withstage="LIVEHEALTHAPI".- The handler opens a TCP socket and sends the HL7 message to Mirth.
WebhookIntegrationDirectoryLoggerwraps the handler and records the outcome asSUCCESS,FAIL, orQUEUED.
Mirth handoffs often remain in QUEUED until downstream socket confirmation is received. This is expected behavior, not a failure.
Troubleshooting Checklist
When investigating an integration failure, work through these steps in order:
- Verify config — confirm the
labIntegrationrow is active and not soft-disabled for the lab and action ID. - Check the trigger — confirm the business event actually fired and the trigger function was called.
- Read the log — find the
IntegrationDirectorydocument. Checkstatus,error_message,response_body, andretry_count. - Trace the
log_id— the DocumentDB_idis the thread connecting the pre-created log, the Fusion payload, the handler, and any retry records. Start here if anything is missing. - Evaluate the response — was the payload valid? Was the auth token correct? Did the third-party return an error body?
Fusion task failures
If no IntegrationDirectory record exists at all, the Fusion task may have failed before the handler ran. Check failed_task_handler queues — they log system-level exceptions like Timeout before the logging decorator is reached.