Changes between Initial Version and Version 1 of UseCase10


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

--

Legend:

Unmodified
Added
Removed
Modified
  • UseCase10

    v1 v1  
     1= UseCase10 - Schedule Appointment =
     2
     3== Initiating Actor - `Doctor or System Administrator` ==
     4
     5== Description ==
     6An appointment is scheduled for a patient with a specific doctor on a specific date and time. The system checks for conflicts, creates the appointment record, and makes it visible to both the patient and doctor.
     7
     8== Scenario ==
     9
     101. User selects a patient and a doctor to schedule an appointment for.
     11
     12{{{
     13#!sql
     14SELECT
     15  p.patient_id,
     16  u_p.first_name,
     17  u_p.last_name,
     18  p.embg
     19FROM patients p
     20JOIN users u_p ON p.patient_id = u_p.patient_id
     21WHERE u_p.username = 'maja.veljanova';
     22}}}
     23
     242. System retrieves the selected doctor details.
     25
     26{{{
     27#!sql
     28SELECT
     29  d.doctor_id,
     30  u_d.first_name,
     31  u_d.last_name,
     32  ds.specialization_name,
     33  d.department_id
     34FROM doctors d
     35JOIN doctor_specialization ds
     36ON d.specialization_id = ds.specialization_id
     37JOIN users u_d
     38ON d.doctor_id = u_d.doctor_id
     39WHERE u_d.username = 'elena.kirova';
     40}}}
     41
     423. System checks which time slots are already taken for the doctor on the selected date.
     43
     44{{{
     45#!sql
     46SELECT a.appointment_time
     47FROM appointments a
     48WHERE a.doctor_id = (
     49SELECT doctor_id
     50FROM users
     51WHERE username = 'elena.kirova')
     52  AND a.appointment_date = '2026-06-12'
     53  AND a.status != 'CANCELLED';
     54}}}
     55
     564. System verifies the patient does not already have an appointment with this doctor at the chosen time.
     57
     58{{{
     59#!sql
     60SELECT 1
     61FROM appointments a
     62WHERE a.patient_id = (SELECT patient_id FROM users WHERE username = 'maja.veljanova')
     63  AND a.doctor_id = (SELECT doctor_id FROM users WHERE username = 'elena.kirova')
     64  AND a.appointment_date = '2026-06-12'
     65  AND a.appointment_time = '10:00'
     66  AND a.status != 'CANCELLED';
     67}}}
     68
     695. System creates the appointment record.
     70
     71{{{
     72#!sql
     73INSERT INTO appointments (patient_id, doctor_id, appointment_date, appointment_time, status)
     74VALUES (
     75  (SELECT patient_id FROM users WHERE username = 'maja.veljanova'),
     76  (SELECT doctor_id FROM users WHERE username = 'elena.kirova'),
     77  '2026-06-12',
     78  '10:00',
     79  'SCHEDULED'
     80)
     81RETURNING appointment_id;
     82}}}
     83
     846. System displays the confirmation with full appointment details.
     85
     86{{{
     87#!sql
     88SELECT
     89  a.appointment_id,
     90  a.appointment_date,
     91  a.appointment_time,
     92  a.status,
     93  u_d.first_name AS doctor_first_name,
     94  u_d.last_name AS doctor_last_name,
     95  u_p.first_name AS patient_first_name,
     96  u_p.last_name AS patient_last_name
     97FROM appointments a
     98JOIN doctors d ON a.doctor_id = d.doctor_id
     99JOIN users u_d ON d.doctor_id = u_d.doctor_id
     100JOIN patients p ON a.patient_id = p.patient_id
     101JOIN users u_p ON p.patient_id = u_p.patient_id
     102WHERE a.appointment_id = (SELECT MAX(appointment_id) FROM appointments);
     103}}}
     104
     1057. System displays all upcoming appointments for the patient.
     106
     107{{{
     108#!sql
     109SELECT
     110  a.appointment_id,
     111  a.appointment_date,
     112  a.appointment_time,
     113  a.status,
     114  u_d.first_name AS doctor_first_name,
     115  u_d.last_name AS doctor_last_name
     116FROM appointments a
     117JOIN doctors d ON a.doctor_id = d.doctor_id
     118JOIN users u_d ON d.doctor_id = u_d.doctor_id
     119WHERE a.patient_id = (
     120SELECT patient_id
     121FROM users
     122WHERE username = 'maja.veljanova')
     123  AND a.appointment_date >= CURRENT_DATE
     124ORDER BY a.appointment_date ASC, a.appointment_time ASC;
     125}}}