= UseCase06PrototypeImplementation - 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 == 1. Doctor opens a patient's medical record. {{{ #!sql SELECT mr.record_id, mr.patient_id FROM medical_records mr WHERE mr.patient_id = 4; }}} 2. Doctor navigates to "Request Lab Test" and system displays all available lab tests. [[Image(uc_06_1.png, width=100%)]] {{{ #!sql SELECT lt.test_id, lt.test_name, lt.description, lt.cost FROM lab_tests lt ORDER BY lt.test_name; }}} 3. Doctor selects a lab test, specifies the test date and notes, and submits the request. [[Image(uc_6_2.png, width=100%)]] {{{ #!sql INSERT INTO performed_lab_tests (patient_id, doctor_id, test_id, test_date, notes) VALUES ( 4, (SELECT doctor_id FROM doctors WHERE user_id = (SELECT user_id FROM users WHERE username = 'elena.kirova')), (SELECT test_id FROM lab_tests WHERE test_name = 'Complete Blood Count'), '2026-06-16', 'Blood work for hypertension monitoring' ) RETURNING performed_test_id; }}} 4. System calculates the total cost of lab tests performed on that date for this patient. {{{ #!sql 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 = 4 AND plt.test_date = '2026-06-16'; }}}