Radiology Triage (Urgent vs Normal)

Triage scans into **urgent** vs **normal** using pre-computed metadata. Route urgent first.

All recipes· ml· 7 minutesintermediatesql

Radiology Triage (Urgent vs Normal)

Objective

Triage scans into urgent vs normal using precomputed metadata. Route urgent first.

Step 1: Create tables and load data

CREATE TABLE radiology_metadata (
  scan_id BIGINT PRIMARY KEY,
  patient_id BIGINT,
  body_region VARCHAR(50),
  density_mean DOUBLE,
  density_variance DOUBLE,
  contrast_level DOUBLE,
  critical_label INT            -- 1 urgent, 0 normal (null = unlabeled)
);
INSERT INTO radiology_metadata VALUES
(9001, 501, 'chest', 42.3, 10.5, 0.8, 1),
(9002, 502, 'head',  38.7,  7.2, 0.4, 0),
(9003, 503, 'abd',   45.0, 11.1, 0.9, 1),
(9004, 504, 'chest', 37.2,  6.9, 0.3, 0),
(9005, 505, 'abd',   41.5,  9.0, 0.7, 1);

Step 2: Create experiment

CREATE EXPERIMENT radiology_rf AS
SELECT
  body_region,
  density_mean,
  density_variance,
  contrast_level,
  critical_label AS target
FROM radiology_metadata
WHERE critical_label IS NOT NULL
WITH (
  task_type = 'classification',
  target_column = 'target',
  algorithms = ['random_forest'],
  optimization_metric = 'recall',
  validation_strategy = 'kfold',
  n_folds = 5,
  class_weight = 'balanced',
  algorithm_params = {'n_estimators': 400, 'max_depth': 10, 'min_samples_leaf': 2}
);

Step 3: Deploy best model

DEPLOY MODEL radiology_model FROM EXPERIMENT radiology_rf;

Step 4: Live triage scoring

-- score today’s scans
PREDICT urgent_probability USING radiology_model AS
SELECT
  scan_id,
  body_region,
  density_mean,
  density_variance,
  contrast_level
FROM radiology_metadata
WHERE critical_label IS NULL;

Step 5: Worklist routing

-- send high-probability urgent cases to top of queue
SELECT scan_id, urgent_probability
FROM (
  PREDICT urgent_probability USING radiology_model AS
  SELECT scan_id, body_region, density_mean, density_variance, contrast_level
  FROM radiology_metadata
  WHERE critical_label IS NULL
) s
ORDER BY urgent_probability DESC;

Optional: QA and drift checks

-- monitor recall on labeled recent scans
WITH eval AS (
  SELECT
    p.scan_id,
    p.urgent_probability,
    r.critical_label
  FROM (
    PREDICT urgent_probability USING radiology_model AS
    SELECT scan_id, body_region, density_mean, density_variance, contrast_level
    FROM radiology_metadata
    WHERE critical_label IS NOT NULL
  ) p
  JOIN radiology_metadata r USING(scan_id)
)
SELECT
  AVG(CASE WHEN urgent_probability >= 0.5 AND critical_label = 1 THEN 1 ELSE 0 END) AS tp_rate,
  AVG(CASE WHEN urgent_probability <  0.5 AND critical_label = 1 THEN 1 ELSE 0 END) AS fn_rate
FROM eval;

Expected outcomes

  • Higher recall on urgent cases.
  • Faster time-to-read for critical patients.
  • Clear routing rules tied to probability bands.

Tags

mlsqlclassificationhealthcareimaging

Run this on your own machine

Install SynapCores Community Edition free, paste the SQL or Cypher above into the bundled web UI, and watch it run.

Download Free CE