Objective
Create a system for tracking patient imaging history over time, enabling longitudinal analysis, comparison studies, and comprehensive imaging timelines.
Step 1: Create Patients Table
Store patient demographics.
CREATE TABLE imaging_patients (
id INTEGER PRIMARY KEY,
patient_id VARCHAR(50) NOT NULL UNIQUE,
first_name VARCHAR(100),
last_name VARCHAR(100),
date_of_birth DATE,
gender VARCHAR(20),
primary_physician VARCHAR(200),
total_studies INTEGER DEFAULT 0,
last_study_date DATE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Step 2: Create Patient Studies Table
Store all imaging studies.
CREATE TABLE patient_studies (
id INTEGER PRIMARY KEY,
patient_id INTEGER NOT NULL,
study_uid VARCHAR(100) UNIQUE,
study_date DATE NOT NULL,
study_time TIME,
modality VARCHAR(20),
body_region VARCHAR(100),
study_description VARCHAR(255),
institution VARCHAR(200),
referring_physician VARCHAR(200),
radiologist VARCHAR(200),
image_count INTEGER DEFAULT 0,
has_report BOOLEAN DEFAULT FALSE,
report_date DATE,
study_status VARCHAR(50) DEFAULT 'completed',
FOREIGN KEY (patient_id) REFERENCES imaging_patients(id)
);
Step 3: Create Study Comparisons Table
Link related studies for comparison.
CREATE TABLE study_comparisons (
id INTEGER PRIMARY KEY,
current_study_id INTEGER NOT NULL,
prior_study_id INTEGER NOT NULL,
comparison_type VARCHAR(50),
time_interval_days INTEGER,
compared_by VARCHAR(100),
comparison_notes TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (current_study_id) REFERENCES patient_studies(id),
FOREIGN KEY (prior_study_id) REFERENCES patient_studies(id)
);
Step 4: Create Key Images Table
Store significant images from studies.
CREATE TABLE key_images (
id INTEGER PRIMARY KEY,
study_id INTEGER NOT NULL,
image_data IMAGE(JPEG),
thumbnail IMAGE(JPEG),
image_description VARCHAR(255),
finding_summary TEXT,
marked_by VARCHAR(100),
marked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (study_id) REFERENCES patient_studies(id)
);
Step 5: Create Imaging Alerts Table
Track follow-up recommendations.
CREATE TABLE imaging_alerts (
id INTEGER PRIMARY KEY,
patient_id INTEGER NOT NULL,
study_id INTEGER NOT NULL,
alert_type VARCHAR(50),
finding VARCHAR(255),
recommended_followup VARCHAR(255),
followup_interval VARCHAR(50),
due_date DATE,
alert_status VARCHAR(50) DEFAULT 'active',
resolved_date DATE,
resolved_by VARCHAR(100),
FOREIGN KEY (patient_id) REFERENCES imaging_patients(id),
FOREIGN KEY (study_id) REFERENCES patient_studies(id)
);
Step 6: Insert Sample Patients
Add patient records.
INSERT INTO imaging_patients (id, patient_id, first_name, last_name, date_of_birth, gender, primary_physician, total_studies, last_study_date) VALUES
(1, 'PAT-10001', 'John', 'Smith', '1955-03-15', 'Male', 'Dr. Anderson', 8, '2024-01-15'),
(2, 'PAT-10002', 'Mary', 'Johnson', '1968-07-22', 'Female', 'Dr. Thompson', 5, '2024-01-10'),
(3, 'PAT-10003', 'Robert', 'Williams', '1972-11-08', 'Male', 'Dr. Garcia', 12, '2024-01-18'),
(4, 'PAT-10004', 'Sarah', 'Brown', '1980-04-30', 'Female', 'Dr. Miller', 3, '2024-01-05'),
(5, 'PAT-10005', 'Michael', 'Davis', '1960-09-12', 'Male', 'Dr. Anderson', 15, '2024-01-20');
Step 7: Insert Patient Studies
Add imaging history.
INSERT INTO patient_studies (id, patient_id, study_uid, study_date, study_time, modality, body_region, study_description, institution, referring_physician, radiologist, image_count, has_report, report_date, study_status) VALUES
-- Patient 1 history
(1, 1, '1.2.840.10001.1.1', '2022-06-15', '09:00:00', 'CT', 'CHEST', 'CT Chest Low Dose Lung Screening', 'City General', 'Dr. Anderson', 'Dr. Miller', 200, TRUE, '2022-06-15', 'completed'),
(2, 1, '1.2.840.10001.1.2', '2023-06-20', '10:30:00', 'CT', 'CHEST', 'CT Chest Low Dose Lung Screening', 'City General', 'Dr. Anderson', 'Dr. Miller', 210, TRUE, '2023-06-20', 'completed'),
(3, 1, '1.2.840.10001.1.3', '2024-01-15', '09:15:00', 'CT', 'CHEST', 'CT Chest Low Dose Lung Screening', 'City General', 'Dr. Anderson', 'Dr. Miller', 205, TRUE, '2024-01-15', 'completed'),
(4, 1, '1.2.840.10001.1.4', '2023-03-10', '14:00:00', 'XR', 'CHEST', 'Chest X-Ray PA Lateral', 'City General', 'Dr. Anderson', 'Dr. Chen', 2, TRUE, '2023-03-10', 'completed'),
-- Patient 2 history
(5, 2, '1.2.840.10002.1.1', '2023-01-05', '11:00:00', 'MR', 'BRAIN', 'MRI Brain with Contrast', 'City General', 'Dr. Thompson', 'Dr. Garcia', 300, TRUE, '2023-01-05', 'completed'),
(6, 2, '1.2.840.10002.1.2', '2024-01-10', '10:00:00', 'MR', 'BRAIN', 'MRI Brain with Contrast', 'City General', 'Dr. Thompson', 'Dr. Garcia', 320, TRUE, '2024-01-10', 'completed'),
-- Patient 3 history
(7, 3, '1.2.840.10003.1.1', '2022-05-01', '08:30:00', 'CT', 'ABDOMEN', 'CT Abdomen Pelvis with Contrast', 'City General', 'Dr. Garcia', 'Dr. Miller', 400, TRUE, '2022-05-01', 'completed'),
(8, 3, '1.2.840.10003.1.2', '2022-11-15', '09:00:00', 'CT', 'ABDOMEN', 'CT Abdomen Pelvis with Contrast', 'City General', 'Dr. Garcia', 'Dr. Miller', 420, TRUE, '2022-11-15', 'completed'),
(9, 3, '1.2.840.10003.1.3', '2023-05-20', '10:00:00', 'CT', 'ABDOMEN', 'CT Abdomen Pelvis with Contrast', 'City General', 'Dr. Garcia', 'Dr. Miller', 415, TRUE, '2023-05-20', 'completed'),
(10, 3, '1.2.840.10003.1.4', '2024-01-18', '09:30:00', 'CT', 'ABDOMEN', 'CT Abdomen Pelvis with Contrast', 'City General', 'Dr. Garcia', 'Dr. Miller', 430, TRUE, '2024-01-18', 'completed'),
-- Patient 5 history
(11, 5, '1.2.840.10005.1.1', '2023-06-01', '11:00:00', 'CT', 'CHEST', 'CT Chest with Contrast', 'City General', 'Dr. Anderson', 'Dr. Miller', 350, TRUE, '2023-06-01', 'completed'),
(12, 5, '1.2.840.10005.1.2', '2023-09-15', '10:00:00', 'PET', 'WHOLEBODY', 'PET-CT Whole Body', 'Cancer Center', 'Dr. Lee', 'Dr. Wilson', 800, TRUE, '2023-09-15', 'completed'),
(13, 5, '1.2.840.10005.1.3', '2024-01-20', '09:00:00', 'CT', 'CHEST', 'CT Chest with Contrast', 'City General', 'Dr. Anderson', 'Dr. Miller', 360, TRUE, '2024-01-20', 'completed');