Changes between Initial Version and Version 1 of UseCase11


Ignore:
Timestamp:
06/12/26 18:20:14 (5 days ago)
Author:
236021
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UseCase11

    v1 v1  
     1= UseCase11 - Create Referral =
     2
     3== Initiating Actor - `Doctor` ==
     4
     5== Description ==
     6A doctor creates a referral for a patient to another doctor for specialist opinion or a consultation. The system creates the referral record and automatically schedules an appointment with the referred doctor.
     7
     8== Scenario ==
     9
     101. Doctor opens a patient's medical record.
     11
     12{{{
     13#!sql
     14SELECT
     15  mr.record_id,
     16  mr.patient_id
     17FROM medical_records mr
     18WHERE mr.patient_id = (
     19  SELECT patient_id FROM users WHERE username = 'maja.veljanova'
     20);
     21}}}
     22
     232. System retrieves the list of available specialist doctors.
     24
     25{{{
     26#!sql
     27SELECT
     28  d.doctor_id,
     29  u_d.first_name,
     30  u_d.last_name,
     31  ds.specialization_name,
     32  d.department_id
     33FROM doctors d
     34JOIN doctor_specialization ds ON d.specialization_id = ds.specialization_id
     35JOIN users u_d ON d.doctor_id = u_d.doctor_id
     36ORDER BY ds.specialization_name, u_d.last_name;
     37}}}
     38
     393. Doctor selects the receiving doctor, enters the referral reason, and specifies the appointment date and time.
     40
     41{{{
     42#!sql
     43INSERT INTO referrals (record_id, from_doctor_id, to_doctor_id, reason, referral_date, appointment_date, appointment_time)
     44VALUES (
     45  (SELECT record_id FROM medical_records WHERE patient_id = (SELECT patient_id FROM users WHERE username = 'maja.veljanova')),
     46  (SELECT doctor_id FROM users WHERE username = 'elena.kirova'),
     47  (SELECT doctor_id FROM users WHERE username = 'nikola.trajkov'),
     48  'Cardiology consultation for hypertension management',
     49  '2026-05-30',
     50  '2026-06-15',
     51  '14:00'
     52)
     53RETURNING referral_id;
     54}}}
     55
     564. System automatically creates an appointment with the receiving doctor.
     57
     58{{{
     59#!sql
     60INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status)
     61VALUES (
     62  (SELECT patient_id FROM users WHERE username = 'maja.veljanova'),
     63  (SELECT doctor_id FROM users WHERE username = 'nikola.trajkov'),
     64  '2026-06-15',
     65  '14:00',
     66  'SCHEDULED'
     67)
     68RETURNING appointment_id;
     69}}}
     70
     715. System displays the confirmation with full referral and appointment details.
     72
     73{{{
     74#!sql
     75SELECT
     76  r.referral_id,
     77  r.reason,
     78  r.referral_date,
     79  r.appointment_date,
     80  r.appointment_time,
     81  u_from.first_name AS from_doctor_first_name,
     82  u_from.last_name AS from_doctor_last_name,
     83  u_to.first_name AS to_doctor_first_name,
     84  u_to.last_name AS to_doctor_last_name
     85FROM referrals r
     86JOIN doctors d_from ON r.from_doctor_id = d_from.doctor_id
     87JOIN users u_from ON d_from.doctor_id = u_from.doctor_id
     88JOIN doctors d_to ON r.to_doctor_id = d_to.doctor_id
     89JOIN users u_to ON d_to.doctor_id = u_to.doctor_id
     90WHERE r.referral_id = (SELECT MAX(referral_id) FROM referrals);
     91}}}
     92
     936. System notifies the receiving doctor by displaying their incoming referrals.
     94
     95{{{
     96#!sql
     97SELECT
     98  r.referral_id,
     99  r.reason,
     100  r.referral_date,
     101  r.appointment_date,
     102  u_p.first_name AS patient_first_name,
     103  u_p.last_name AS patient_last_name
     104FROM referrals r
     105JOIN medical_records mr ON r.record_id = mr.record_id
     106JOIN patients p ON mr.patient_id = p.patient_id
     107JOIN users u_p ON p.patient_id = u_p.patient_id
     108WHERE r.to_doctor_id = (SELECT doctor_id FROM users WHERE username = 'nikola.trajkov')
     109ORDER BY r.referral_date DESC;
     110}}}