prepare(
"SELECT
ot.order_id,
ot.ordered_at,
ot.test_type,
ot.status,
p.patient_name,
p.id as patient_id,
CASE
WHEN ot.test_type = 'lab' THEN lt.test_name
WHEN ot.test_type = 'imaging' THEN it.test_name
END as test_name,
u.username as doctor_name
FROM ordered_tests ot
JOIN patient_visits pv ON ot.visit_id = pv.visit_id
JOIN patients p ON pv.patient_id = p.id
JOIN users u ON pv.doctor_id = u.id
LEFT JOIN lab_tests lt ON ot.test_type = 'lab' AND ot.test_id = lt.test_id
LEFT JOIN imaging_tests it ON ot.test_type = 'imaging' AND ot.test_id = it.test_id
WHERE ot.status = 'Ordered'
ORDER BY ot.ordered_at ASC"
);
$pending_tests_stmt->execute();
$pending_tests = $pending_tests_stmt->fetchAll(PDO::FETCH_ASSOC);
?>
Lab & Imaging Reports
Pending Lab & Imaging Reports
Date Ordered
Patient
Test Name
Type
Ordered By
Status
Action
No pending tests found.
= date("d M, Y", strtotime($test['ordered_at'])) ?>