API Reference
All six sample rerun API endpoints — fetch values, receive values, request rerun, confirm, cancel, and auto-check.
API Reference
Six endpoints under the sample-rerun/ prefix power the sample rerun lifecycle. The base path is api-v3/sample-rerun/.
Overview
1. Fetch rerun values
View: SampleRerunView.get()
File: report/views/sample_rerun.py
GET /sample-rerun/<lab_report_id>Returns all SampleRerunValues records for a given lab report. Called when the Review Rerun Results tab opens to load original and rerun values for comparison.
Response
{
"reruns": [
{
"_id": "665abc...",
"lab_id": 100,
"sample_id": "S001",
"value": "12.5",
"order": 1,
"index": 3,
"rerun_type": "manual_rerun",
"rerun_number": 1,
"parameter_name": "WBC Count",
"device_id": "42",
"device_name": "Sysmex XN-1000",
"created_at": "2026-05-20T10:30:00Z"
}
]
}Guard
DOCUMENT_DB_ENABLEDmust beTruelab_report_idmust be provided
2. Receive rerun values (from instrument)
View: SampleRerunView.post()
File: report/views/sample_rerun.py
POST /sample-rerun/<lab_report_id>/newReceives rerun values from the interfacing app when the instrument re-tests a sample. Routes internally to register_machine_triggered_rerun() or register_manual_triggered_rerun() based on rerun_number.
Request body
{
"lab_id": 100,
"sample_id": "S001",
"device_id": "42",
"device_name": "Sysmex XN-1000",
"rerun_type": "manual_rerun",
"rerun_number": 1,
"lab_report_id": 12345,
"device_data": [
{ "index": 3, "value": "12.5", "parameter_name": "WBC Count" },
{ "index": 5, "value": "4.2", "parameter_name": "RBC Count" }
]
}Routing logic
| Condition | Handler | Behaviour |
|---|---|---|
rerun_number == -1 | register_machine_triggered_rerun() | Stores all values; auto-increments rerun number from existing records; marks fulfilled immediately (sampleRedrawFlag = 4) |
rerun_number >= 1 | register_manual_triggered_rerun() | Validates against requested_parameters; tracks partial fulfilment; marks fulfilled only when all requested parameters received |
Response
{ "message": "Rerun data updated", "type": "instrument triggered" }3. Request a rerun (manual or auto)
View: SampleRerunRequestView.post()
File: report/views/sample_rerun.py
POST /sample-rerun/<lab_report_id>/requestCreates a SampleRerun record in DocumentDB and sets sampleRedrawFlag = 3 on the report. Called directly from the frontend for manual reruns, or via Fusion webhook for auto reruns.
Request body
{
"type": "Manual",
"rerun_number": "1",
"requested_parameters": "[1, 3, 5]",
"parameter_names": ["WBC Count", "RBC Count", "Hemoglobin"],
"is_active": true,
"lab_id": 100
}What it does
- Validates payload against
SampleRerun.create_allowed_fields - Saves to DocumentDB with
created_by,updated_by, timestamps - Sets Redis cache:
HSET sample_rerun_100 12345 1 - Updates
lab_report.sampleRedrawFlag = 3 - Syncs to Elasticsearch
- Logs
RERUN_REQUESTED(981)
Response
{ "message": "Manual Sample rerun requested successfully" }Error response (save failure)
{ "message": "Something went wrong when saving sample rerun" }Logs RERUN_FAILED (984) on failure.
For auto reruns, the AutoSampleRerunCheck view calls this endpoint internally via a Fusion webhook with lab_id in the payload and x-is-internal-request: True header. The login_user is set to -1 for internal requests.
4. Confirm rerun values
View: SampleRerunConfirmView.post()
File: report/views/sample_rerun.py
POST /sample-rerun/<lab_report_id>/confirmReplaces the original ReportValue entries with the user-selected values (original or rerun) and closes the rerun lifecycle.
Request body
{
"rerun_confirmed_data": [
{
"profileTestId": 500,
"value": "12.5",
"order": 1,
"index": 3,
"highlight": 1,
"automatedValue": 0,
"reportForId_id": 12345,
"parameter_name": "WBC Count"
}
]
}What it does
- Deletes existing
ReportValuerows matching the confirmed indices - Inserts the confirmed values as new
ReportValuerows - Calls
SampleRerunValues.close_rerun():- Sets
sampleRedrawFlag = 0 - Syncs to Elasticsearch
- Deletes all
SampleRerunValuesfrom DocumentDB - Deletes
SampleRerunrecords from DocumentDB - Clears Redis cache
- Sets
- Logs
RERUN_VALUES_CONFIRMED(980)
Response
{ "message": "Rerun data updated" }5. Cancel / abort rerun
View: SampleRerunCancelView.post()
File: report/views/sample_rerun.py
POST /sample-rerun/<lab_report_id>/abortCancels an in-progress rerun and resets the report to its normal state.
What it does
- Calls
SampleRerunValues.close_rerun()(same cleanup as confirm) - Logs
RERUN_CANCELLED(985)
Response
{ "message": "Successfully aborted sample rerun" }6. Auto rerun qualification check
View: AutoSampleRerunCheck.post()
File: report/views/sample_rerun.py
POST /sample-rerun/<lab_report_id>/autoCalled by the interfacing app after device data is processed. Evaluates whether any parameters qualify for an automatic rerun based on configured conditions.
Request body
{
"device_data": [
{ "index": 3, "value": "1500" },
{ "index": 5, "value": "4.2" }
]
}Logic flow
- Loads
ReportFormatentries for the report - Filters to only formats with
auto_rerun_allowed = True - Checks
auto_rerun_record_exists()— returns early if already triggered - Calls
SampleRerun.get_auto_rerun_qualified_indices()which evaluates each value against its configured condition (abnormal, critical, custom) and age-aware ranges - If any indices qualify → sends a Fusion webhook to
POST /sample-rerun/{id}/request
Fusion webhook payload
{
"url": "{WEBHOOK_URL}/api-v3/sample-rerun/{lab_report_id}/request",
"body": {
"type": "auto",
"rerun_number": "1",
"requested_parameters": "[3, 5]",
"is_active": True,
"lab_id": 100,
},
}Response
{ "message": "Auto rerun queued successfully" }or
{ "message": "Auto rerun didn't qualify for these values" }