Changes between Initial Version and Version 1 of UseCase06


Ignore:
Timestamp:
06/12/26 18:00:39 (7 days ago)
Author:
236021
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UseCase06

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