| | 1 | = UseCase07 - Create an Appointment |
| | 2 | ** Initiating actor: Owner ** |
| | 3 | == Description |
| | 4 | An owner schedules an appointment for one of their pets at a vet clinic they choose. The owner selects one of their animals, selects a clinic and submits the appointment request. The system then confirms the appointment has been created. |
| | 5 | == Scenario |
| | 6 | 1. Owner opens a specific vet clinic. |
| | 7 | {{{ |
| | 8 | SELECT |
| | 9 | clinic_id, |
| | 10 | name, |
| | 11 | city, |
| | 12 | address, |
| | 13 | email, |
| | 14 | phone, |
| | 15 | open_time, |
| | 16 | close_time, |
| | 17 | not_working_isodow |
| | 18 | FROM vet_clinics |
| | 19 | WHERE clinic_id = $1; |
| | 20 | }}} |
| | 21 | 2. Owner clicks "Create an appointment". |
| | 22 | {{{ |
| | 23 | SELECT |
| | 24 | a.animal_id, |
| | 25 | a.name, |
| | 26 | a.species, |
| | 27 | a.breed |
| | 28 | FROM animals a |
| | 29 | WHERE a.owner_id = $1 |
| | 30 | ORDER BY a.name; |
| | 31 | }}} |
| | 32 | 3. Owner fills in the form. |
| | 33 | {{{ |
| | 34 | BEGIN; |
| | 35 | |
| | 36 | SELECT 1 |
| | 37 | FROM appointments ap |
| | 38 | WHERE ap.clinic_id = $1 |
| | 39 | AND ap.date_time = $2 |
| | 40 | AND ap.status = 'CONFIRMED' |
| | 41 | FOR UPDATE; |
| | 42 | |
| | 43 | INSERT INTO appointments ( |
| | 44 | clinic_id, |
| | 45 | animal_id, |
| | 46 | responsible_owner_id, |
| | 47 | status, |
| | 48 | date_time, |
| | 49 | notes |
| | 50 | ) |
| | 51 | VALUES ( |
| | 52 | $1, |
| | 53 | $3, |
| | 54 | $4, |
| | 55 | 'CONFIRMED', |
| | 56 | $2, |
| | 57 | $5 |
| | 58 | ) |
| | 59 | RETURNING appointment_id; |
| | 60 | |
| | 61 | COMMIT; |
| | 62 | }}} |