UseCase06 - Doctor Requests Lab Test
Initiating Actor - Doctor
Description
A doctor requests a laboratory test for a patient. The system creates a performed lab test record linking the doctor, patient, and the specific test.
Scenario
- Doctor opens a patient's medical record.
SELECT mr.record_id, mr.patient_id FROM medical_records mr WHERE mr.patient_id = ( SELECT patient_id FROM users WHERE username = 'maja.veljanova' );
- System displays all available lab tests.
SELECT lt.test_id, lt.test_name, lt.description, lt.cost FROM lab_tests lt ORDER BY lt.test_name;
- Doctor selects a lab test, specifies the test date and notes, and submits the request.
INSERT INTO performed_lab_tests (patient_id, doctor_id, test_id, test_date, notes) VALUES ( (SELECT patient_id FROM users WHERE username = 'maja.veljanova'), (SELECT doctor_id FROM users WHERE username = 'elena.kirova'), (SELECT test_id FROM lab_tests WHERE test_name = 'Complete Blood Count'), '2026-06-05', 'Blood work for hypertension monitoring' ) RETURNING performed_test_id;
- System calculates the total cost of lab tests performed on that date for this patient.
SELECT SUM(lt.cost) AS total_cost FROM performed_lab_tests plt JOIN lab_tests lt ON plt.test_id = lt.test_id WHERE plt.patient_id = ( SELECT patient_id FROM users WHERE username = 'maja.veljanova') AND plt.test_date = '2026-06-05';
- System creates a billing record for the patient.
INSERT INTO billing (total_cost, payment_status, record_id, admin_id) VALUES ( 75.00, 'PENDING', (SELECT record_id FROM medical_records WHERE patient_id = (SELECT patient_id FROM users WHERE username = 'maja.veljanova')), (SELECT admin_id FROM admin LIMIT 1) ) RETURNING bill_id;
- System links the billing record to the performed lab test.
INSERT INTO billing_lab_tests (bill_id, test_id) VALUES ( (SELECT MAX(bill_id) FROM billing), (SELECT test_id FROM lab_tests WHERE test_name = 'Complete Blood Count') );
- System confirms the request and displays all pending lab tests for the patient.
SELECT plt.performed_test_id, lt.test_name, plt.test_date, plt.notes FROM performed_lab_tests plt JOIN lab_tests lt ON plt.test_id = lt.test_id WHERE plt.patient_id = ( SELECT patient_id FROM users WHERE username = 'maja.veljanova');
Last modified
7 days ago
Last modified on 06/12/26 18:00:39
Note:
See TracWiki
for help on using the wiki.
