Product EngineeringFeaturesSample RerunBackend

API Reference

All six sample rerun API endpoints — fetch values, receive values, request rerun, confirm, cancel, and auto-check.

👤 Aakash Pawar📅 Updated: May 25, 2026🏷️ feature🏷️ backend🏷️ api

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_ENABLED must be True
  • lab_report_id must be provided

2. Receive rerun values (from instrument)

View: SampleRerunView.post() File: report/views/sample_rerun.py

POST /sample-rerun/<lab_report_id>/new

Receives 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

ConditionHandlerBehaviour
rerun_number == -1register_machine_triggered_rerun()Stores all values; auto-increments rerun number from existing records; marks fulfilled immediately (sampleRedrawFlag = 4)
rerun_number >= 1register_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>/request

Creates 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

  1. Validates payload against SampleRerun.create_allowed_fields
  2. Saves to DocumentDB with created_by, updated_by, timestamps
  3. Sets Redis cache: HSET sample_rerun_100 12345 1
  4. Updates lab_report.sampleRedrawFlag = 3
  5. Syncs to Elasticsearch
  6. 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>/confirm

Replaces 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

  1. Deletes existing ReportValue rows matching the confirmed indices
  2. Inserts the confirmed values as new ReportValue rows
  3. Calls SampleRerunValues.close_rerun():
    • Sets sampleRedrawFlag = 0
    • Syncs to Elasticsearch
    • Deletes all SampleRerunValues from DocumentDB
    • Deletes SampleRerun records from DocumentDB
    • Clears Redis cache
  4. 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>/abort

Cancels an in-progress rerun and resets the report to its normal state.

What it does

  1. Calls SampleRerunValues.close_rerun() (same cleanup as confirm)
  2. 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>/auto

Called 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

  1. Loads ReportFormat entries for the report
  2. Filters to only formats with auto_rerun_allowed = True
  3. Checks auto_rerun_record_exists() — returns early if already triggered
  4. Calls SampleRerun.get_auto_rerun_qualified_indices() which evaluates each value against its configured condition (abnormal, critical, custom) and age-aware ranges
  5. 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" }

On this page