| | 1 | = UseCase06 - Doctor Requests Lab Test = |
| | 2 | |
| | 3 | == Initiating Actor - `Doctor` == |
| | 4 | |
| | 5 | |
| | 6 | == Description == |
| | 7 | 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. |
| | 8 | |
| | 9 | == Scenario == |
| | 10 | |
| | 11 | 1. Doctor opens a patient's medical record. |
| | 12 | |
| | 13 | {{{ |
| | 14 | #!sql |
| | 15 | SELECT |
| | 16 | mr.record_id, |
| | 17 | mr.patient_id |
| | 18 | FROM medical_records mr |
| | 19 | WHERE mr.patient_id = ( |
| | 20 | SELECT patient_id FROM users WHERE username = 'maja.veljanova' |
| | 21 | ); |
| | 22 | }}} |
| | 23 | |
| | 24 | 2. System displays all available lab tests. |
| | 25 | |
| | 26 | {{{ |
| | 27 | #!sql |
| | 28 | SELECT |
| | 29 | lt.test_id, |
| | 30 | lt.test_name, |
| | 31 | lt.description, |
| | 32 | lt.cost |
| | 33 | FROM lab_tests lt |
| | 34 | ORDER BY lt.test_name; |
| | 35 | }}} |
| | 36 | |
| | 37 | 3. Doctor selects a lab test, specifies the test date and notes, and submits the request. |
| | 38 | |
| | 39 | {{{ |
| | 40 | #!sql |
| | 41 | INSERT INTO performed_lab_tests (patient_id, doctor_id, test_id, test_date, notes) |
| | 42 | VALUES ( |
| | 43 | (SELECT patient_id FROM users WHERE username = 'maja.veljanova'), |
| | 44 | (SELECT doctor_id FROM users WHERE username = 'elena.kirova'), |
| | 45 | (SELECT test_id FROM lab_tests WHERE test_name = 'Complete Blood Count'), |
| | 46 | '2026-06-05', |
| | 47 | 'Blood work for hypertension monitoring' |
| | 48 | ) |
| | 49 | RETURNING performed_test_id; |
| | 50 | }}} |
| | 51 | |
| | 52 | 4. System calculates the total cost of lab tests performed on that date for this patient. |
| | 53 | |
| | 54 | {{{ |
| | 55 | #!sql |
| | 56 | SELECT SUM(lt.cost) AS total_cost |
| | 57 | FROM performed_lab_tests plt |
| | 58 | JOIN lab_tests lt ON plt.test_id = lt.test_id |
| | 59 | WHERE plt.patient_id = ( |
| | 60 | SELECT patient_id |
| | 61 | FROM users |
| | 62 | WHERE username = 'maja.veljanova') |
| | 63 | AND plt.test_date = '2026-06-05'; |
| | 64 | }}} |
| | 65 | |
| | 66 | 5. System creates a billing record for the patient. |
| | 67 | |
| | 68 | {{{ |
| | 69 | #!sql |
| | 70 | INSERT INTO billing (total_cost, payment_status, record_id, admin_id) |
| | 71 | VALUES ( |
| | 72 | 75.00, |
| | 73 | 'PENDING', |
| | 74 | (SELECT record_id FROM medical_records WHERE patient_id = (SELECT patient_id FROM users WHERE username = 'maja.veljanova')), |
| | 75 | (SELECT admin_id FROM admin LIMIT 1) |
| | 76 | ) |
| | 77 | RETURNING bill_id; |
| | 78 | }}} |
| | 79 | |
| | 80 | 6. System links the billing record to the performed lab test. |
| | 81 | |
| | 82 | {{{ |
| | 83 | #!sql |
| | 84 | INSERT INTO billing_lab_tests (bill_id, test_id) |
| | 85 | VALUES ( |
| | 86 | (SELECT MAX(bill_id) FROM billing), |
| | 87 | (SELECT test_id FROM lab_tests WHERE test_name = 'Complete Blood Count') |
| | 88 | ); |
| | 89 | }}} |
| | 90 | |
| | 91 | 7. System confirms the request and displays all pending lab tests for the patient. |
| | 92 | |
| | 93 | {{{ |
| | 94 | #!sql |
| | 95 | SELECT |
| | 96 | plt.performed_test_id, |
| | 97 | lt.test_name, |
| | 98 | plt.test_date, |
| | 99 | plt.notes |
| | 100 | FROM performed_lab_tests plt |
| | 101 | JOIN lab_tests lt ON plt.test_id = lt.test_id |
| | 102 | WHERE plt.patient_id = ( |
| | 103 | SELECT patient_id |
| | 104 | FROM users |
| | 105 | WHERE username = 'maja.veljanova'); |
| | 106 | }}} |