Skip to content

Commit

Permalink
Merge pull request AY2324S2-CS2103T-T15-1#214 from officialchengyud/b…
Browse files Browse the repository at this point in the history
…ranch-update-DG

Update DG with add and delete commands
  • Loading branch information
alfaloo authored Apr 12, 2024
2 parents 734cf39 + 46cf565 commit 8326529
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 136 deletions.
62 changes: 26 additions & 36 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,31 +155,35 @@ Classes used by multiple components are in the `seedu.addressbook.commons` packa

This section describes some noteworthy details on how certain features are implemented.

### Add a `Patient`
### Add a `Patient` or `Doctor`
<i><b>Note</b>: Add `patient` and `doctor` has been grouped together as they are very similar in implementation.
This reduces repetition of information and increases clarity.</i>

Adds a new `Patient` entry by indicating their `NRIC`, `Name`, `DoB`, and `Phone`.
This command is implemented through the `AddPatientCommand` class which extend the `Command` class.
Adds a new `Patient` or `Doctor` entry by indicating their `NRIC`, `Name`, `DoB`, and `Phone`.
This command is implemented through the `AddPatientCommand` for patient and `AddDoctorCommand` for doctor class which both extend the `Command` class.

* Step 1. User enters an `addpatient` command.
* Step 2. The `AddressBookParser` will call `parseCommand` on the user's input string and return an instance of `addPatientCommandParser`.
* Step 3. The `parse` command in `addPatientCommandParser` calls `ParserUtil` to create instances of objects for each of the fields.
* If there are any missing fields, a `CommandException` is thrown.
* If input arguments does not match contraints for the fields, a `IllegalArgumentException` is thrown.
* If the patient to added already exists in the system, a `DuplicatePersonException` is thrown`.
* Step 1. User enters an `addpatient` or `adddoctor` command.
* Step 2. The `AddressBookParser` will call `parseCommand` on the user's input string and return an instance of `addPatientCommandParser` or `addDoctorCommandParser`.
* Step 3. The `parse` command in `addPatientCommandParser` or `addDoctorCommandParser` calls `ParserUtil` to create instances of objects for each of the fields.
* If there are any missing fields, a `CommandException` is thrown.
* If input arguments does not match contraints for the fields, a `IllegalArgumentException` is thrown.
* If the patient to added already exists in the system, a `DuplicatePersonException` is thrown`.

The activity diagram below demonstrates this error handling process in more detail.

<img src="images/AddPatientActivityDiagram.png" width="800" />
<img src="images/AddPersonActivityDiagram.png" width="800" />

* Step 4. The `parse` command in `addPatientCommandParser` return an instance of `addPatientCommand`.
* Step 5. The `LogicManager` calls the `execute` method in `addPatientCommand`.
* Step 6. The `execute` method in `addPatientCommand` executes and calls `addPerson` in model to add the new patient into the system.
* Step 4. The `parse` command in `addPatientCommandParser` or `addDoctorCommandParser` return an instance of either `addPatientCommand` or `addDoctorCommand`.
* Step 5. The `LogicManager` calls the `execute` method in `addPatientCommand` or `addDoctorCommand`.
* Step 6. The `execute` method in `addPatientCommand` or `addDoctorCommand` executes and calls `addPerson` in model to add the new patient into the system.
* Step 7. Success message gets printed onto the results display to notify user.

The sequence diagram below closely describes the interaction between the various components during the execution of the `AddPatientCommand`.

<img src="images/AddPatientSequenceDiagram.png" width="800" />

<i>Note: Sequence diagram above is the same for `AddDoctorCommand`, but instead of `AddPatientCommandParser` it is `AddDoctorCommandParser` etc.</i>

#### Design considerations:

**Aspect: How editing a Person works:**
Expand All @@ -192,27 +196,6 @@ The sequence diagram below closely describes the interaction between the various
* Pros: Better performance, since this only requires searching through the person list once.
* Cons: The order of person list will be lost, since `Name` of a `Person` may be edited.

### Add a `doctor`

Adds a new `doctor` entry by indicating their `NRIC`, `Name`, `DoB`, and `Phone`.
This command is implemented through the `AddDoctorCommand` class which extend the `Command` class.

* Step 1. User enters an `adddoctor` command.
* Step 2. The `AddressBookParser` will call `parseCommand` on the user's input string and return an instance of `addDoctorCommandParser`.
* Step 3. The `parse` command in `addDoctorCommandParser` calls `ParserUtil` to create instances of objects for each of the fields.
* If there are any missing fields, a `CommandException` is thrown.
* If input arguments does not match contraints for the fields, a `IllegalArgumentException` is thrown.
* If the doctor to added already exists in the system, a `DuplicatePersonException` is thrown`.

The activity diagram below demonstrates this error handling process in more detail.

<img src="images/AddDoctorActivityDiagram.png" width="800" />

* Step 4. The `parse` command in `addDoctorCommandParser` return an instance of `addDoctorCommand`.
* Step 5. The `LogicManager` calls the `execute` method in `addDoctorCommand`.
* Step 6. The `execute` method in `addDoctorCommand` executes and calls `addDoctor` in model to add the new doctor into the system.
* Step 7. Success message gets printed onto the results display to notify user.

### Delete `doctor` or `patient`

Deletes a `doctor` or `patient` entry by indicating their `Index`.
Expand All @@ -235,6 +218,11 @@ The activity diagram below demonstrates this error handling process in more deta
* Step 7. The `execute` method in `deleteCommand` also iterates through the `ObservableList<Appointments>` and retrieves all appointments that have the person to be deleted, and calls the `deleteAppointmentCommand` as well.
* Step 8. Success message gets printed onto the results display to notify user.

The sequence diagram below closely describes the interaction between the various components during the execution of the `DeleteCommand`.

<img src="images/DeletePersonSequenceDiagram.png" width="800" />


Why is this implemented this way?
1. Making both `Doctor` and `Patient` class extend the `Person` class makes it easier to execute delete operations.
2. `Doctor` and `Patient` all exhibit similar qualities, and thus can inherit from the `Person` superclass.
Expand All @@ -261,8 +249,6 @@ This command is implemented through the `AddAppointmentCommand` class which exte
The activity diagram below demonstrates this error handling process in more detail.
<img src="images/AddAppointmentActivityDiagram.png" width="800" />

<img src="images/AddPatientActivityDiagram.png" width="800" />

* Step 4. The `parse` command in `addAppointmentCommandParser` return an instance of `addAppointmentCommand`.
* Step 5. The `LogicManager` calls the `execute` method in `addAppointmentCommand`.
* Step 6. The `execute` method in `addAppointmentCommand` executes and calls `addAppointment` in model to add the new appointment into the system.
Expand Down Expand Up @@ -318,6 +304,10 @@ The activity diagram below demonstrates this error handling process in more deta
* Step 6. The `execute` method in `deleteAppointmentCommand` executes and calls `deleteAppointment` in model to remove appointment from the system.
* Step 7. Success message gets printed onto the results display to notify user.

The sequence diagram below closely describes the interaction between the various components during the execution of the `DeleteAppointmentCommand`.

<img src="images/DeleteAppointmentSequenceDiagram.png" width="800" />

Why is this implemented this way?
1. The `Appointment` class has very similar functionalities to that of the `Person` class, in which both classes deal with deletion operations.
2. Furthermore on the UI, the `Appointment` column runs parallel to the `Person` column, as such, the behaviours (UX) of operating on the `Person` panel should have a similar feel and experience when dealing with `Appointment` objects.
Expand Down
30 changes: 0 additions & 30 deletions docs/diagrams/AddDoctorActivityDiagram.puml

This file was deleted.

65 changes: 0 additions & 65 deletions docs/diagrams/AddPatientSequenceDiagram.puml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ skinparam ActivityFontSize 15
skinparam ArrowFontSize 12

start
:User enters command to add a patient;
:User enters command to add a patient/doctor;

if () then ([command is invalid])
:Show error message\nfor invalid command;
Expand All @@ -15,12 +15,12 @@ else ([else])
if () then ([invalid field arguments])
:Show error message\nindicating invalid field\narguments provided;
else ([else])
if () then ([Duplicate patient detected])
:Show error message\nindicating duplicate patient;
if () then ([Duplicate patient/doctor detected])
:Show error message\nindicating duplicate patient/doctor;
else ([else])
:Add the patient\ninto the persons list;
:Add the patient/doctor\ninto the persons list;
:Update the 'person' panel\nin the GUI;
:Show success message\nwith patient's information;
:Show success message\nwith patient/doctor's information;
endif;
endif
endif
Expand Down
65 changes: 65 additions & 0 deletions docs/diagrams/DeleteAppointmentSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
@startuml
!include style.puml
skinparam ArrowFontStyle plain

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
participant ":DeleteAppointmentCommandParser" as DeleteAppointmentCommandParser LOGIC_COLOR
participant "e:DeleteAppointmentCommand" as DeleteAppointmentCommand LOGIC_COLOR
participant ":CommandResult" as CommandResult LOGIC_COLOR
end box

box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
end box

[-> LogicManager : execute("deleteappt i/...")
activate LogicManager

LogicManager -> AddressBookParser : parseCommand("deleteappt i/...")
activate AddressBookParser

create DeleteAppointmentCommandParser
AddressBookParser -> DeleteAppointmentCommandParser
activate DeleteAppointmentCommandParser

create DeleteAppointmentCommand
DeleteAppointmentCommandParser -> DeleteAppointmentCommand : : parse("deleteappt i/...")
activate DeleteAppointmentCommand

DeleteAppointmentCommand --> DeleteAppointmentCommandParser
deactivate DeleteAppointmentCommand

DeleteAppointmentCommandParser --> AddressBookParser
deactivate DeleteAppointmentCommandParser

'Hidden arrow to position the destroy marker below the end of the activation bar.
DeleteAppointmentCommandParser -[hidden]-> AddressBookParser
destroy DeleteAppointmentCommandParser

AddressBookParser --> LogicManager
deactivate AddressBookParser

LogicManager -> DeleteAppointmentCommand : execute()
activate DeleteAppointmentCommand

DeleteAppointmentCommand -> Model : deleteAppointment(toRemove)
activate Model

Model --> DeleteAppointmentCommand
deactivate Model

create CommandResult
DeleteAppointmentCommand -> CommandResult
activate CommandResult

CommandResult --> DeleteAppointmentCommand : result
deactivate CommandResult

DeleteAppointmentCommand --> LogicManager : result
deactivate DeleteAppointmentCommand

[<--LogicManager
deactivate LogicManager
@enduml
65 changes: 65 additions & 0 deletions docs/diagrams/DeletePersonSequenceDiagram.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
@startuml
!include style.puml
skinparam ArrowFontStyle plain

box Logic LOGIC_COLOR_T1
participant ":LogicManager" as LogicManager LOGIC_COLOR
participant ":AddressBookParser" as AddressBookParser LOGIC_COLOR
participant ":DeleteCommandParser" as DeleteCommandParser LOGIC_COLOR
participant "e:DeleteCommand" as DeleteCommand LOGIC_COLOR
participant ":CommandResult" as CommandResult LOGIC_COLOR
end box

box Model MODEL_COLOR_T1
participant ":Model" as Model MODEL_COLOR
end box

[-> LogicManager : execute("delete i/...")
activate LogicManager

LogicManager -> AddressBookParser : parseCommand("delete i/...")
activate AddressBookParser

create DeleteCommandParser
AddressBookParser -> DeleteCommandParser
activate DeleteCommandParser

create DeleteCommand
DeleteCommandParser -> DeleteCommand : : parse("delete i/...")
activate DeleteCommand

DeleteCommand --> DeleteCommandParser
deactivate DeleteCommand

DeleteCommandParser --> AddressBookParser
deactivate DeleteCommandParser

'Hidden arrow to position the destroy marker below the end of the activation bar.
DeleteCommandParser -[hidden]-> AddressBookParser
destroy DeleteCommandParser

AddressBookParser --> LogicManager
deactivate AddressBookParser

LogicManager -> DeleteCommand : execute()
activate DeleteCommand

DeleteCommand -> Model : removePerson(toRemove)
activate Model

Model --> DeleteCommand
deactivate Model

create CommandResult
DeleteCommand -> CommandResult
activate CommandResult

CommandResult --> DeleteCommand : result
deactivate CommandResult

DeleteCommand --> LogicManager : result
deactivate DeleteCommand

[<--LogicManager
deactivate LogicManager
@enduml
Binary file removed docs/images/AddDoctorActivityDiagram.png
Binary file not shown.
Binary file removed docs/images/AddPatientActivityDiagram.png
Binary file not shown.
Binary file added docs/images/AddPersonActivityDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/DeleteAppointmentSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/DeletePersonSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8326529

Please sign in to comment.