AY2425S1-CS2103T-T13-4 / tp

MIT License
0 stars 5 forks source link

Feature: Insert Patient and Caregivers to Address Book #72

Open pradyuprasad opened 2 days ago

pradyuprasad commented 2 days ago

Feature: Add Patient and Caregiver Details with Validation

TODO

Step 1: Add Patient Details

Command Format:

addpatient /fname /lname /nric /phone /address

/email

Example Commands:

addpatient /fname John /lname Doe /nric S1234567A /phone 91234567 /address 123 Clementi Ave /email john.doe@example.com addpatient /fname Sarah /lname Tan /nric T9876543Z /phone 98765432 /address 45 Upper Thomson /email sarah.tan@example.com

Parameters and Validation:

1. First Name (fname)

Acceptable Values:

  • Alphabetical characters only (A-Z, a-z), spaces allowed
  • Length: 1-50 characters

Error Message:
"First name must contain only alphabetical characters and cannot exceed 50 characters."

2. Last Name (lname)

Acceptable Values:

  • Alphabetical characters only (A-Z, a-z), spaces allowed
  • Length: 1-50 characters

Error Message:
"Last name must contain only alphabetical characters and cannot exceed 50 characters."

3. NRIC (nric)

Acceptable Values:

  • Valid Singapore NRIC format (e.g., S1234567A or T9876543Z)
  • Length: Exactly 9 characters

Error Message:
"NRIC must be in the valid Singapore NRIC format (e.g., S1234567A or T9876543Z)."

4. Phone (phone)

Acceptable Values:

  • Singapore phone number (8 digits, starting with 6, 8, or 9)

Error Message:
"Phone number must be 8 digits and start with 6, 8, or 9."

5. Address (address)

Acceptable Values:

  • Alphanumeric characters, spaces, and punctuation marks
  • Maximum length of 100 characters

Error Message:
"Address must not exceed 100 characters."

6. Email (email)

Acceptable Values:

  • Valid email format (e.g., example@example.com)

Error Message:
"Email must be in a valid email format (e.g., example@example.com)."

Outputs:

On Success:

  • Message: "Patient <First Name> <Last Name> has been successfully added."
  • UI Change: Patient details are saved to the CSV and the patient table.

On Failure:

  • Message: Appropriate error message depending on the invalid parameter (e.g., "NRIC must be in the valid Singapore NRIC format").
  • UI Change: Invalid data will not be saved.

Step 2: Add Caregiver Details and Link to Patient

Command Format:

addcaregiver /fname /lname /nric /phone /address

/email /patientid

Example Commands:

addcaregiver /fname Emma /lname Tan /nric S2345678B /phone 91234567 /address 456 Yishun Ave /email emma.tan@example.com /patientid 1 addcaregiver /fname Liam /lname Lee /nric T8765432Y /phone 87654321 /address 78 Serangoon Ave /email liam.lee@example.com /patientid 2

Parameters and Validation:

1. First Name (fname)

  • Same rules as the patient’s first name.

2. Last Name (lname)

  • Same rules as the patient’s last name.

3. NRIC (nric)

  • Same rules as the patient’s NRIC.

4. Phone (phone)

  • Same rules as the patient’s phone number.

5. Address (address)

  • Same rules as the patient’s address.

6. Email (email)

  • Same rules as the patient’s email.

7. Patient ID (patientid)

Acceptable Values:

  • Numeric values representing the patient’s ID from the patient table.

Error Message:
"Patient ID must refer to an existing patient."

Outputs:

On Success:

  • Message: "Caregiver <First Name> <Last Name> has been successfully added and linked to patient <Patient ID>."
  • UI Change: Caregiver’s details are saved to the caregiver table, and they are linked to the patient based on the patientid.

On Failure:

  • Message: Appropriate error message, e.g., "Patient ID must refer to an existing patient."
  • UI Change: Invalid data will not be saved.

Duplicate Handling:

For Patients:

  • Rule for Duplicates: Patients are considered duplicates if their NRICs are identical.
  • Behavior: If a duplicate NRIC is detected, the system rejects the new entry.
  • Error Message: "Patient with NRIC <NRIC> already exists in the system."

For Caregivers:

  • Rule for Duplicates: Caregivers are considered duplicates if their NRICs are identical.
  • Behavior: If a duplicate NRIC is detected, the system rejects the new entry.
  • Error Message: "Caregiver with NRIC <NRIC> already exists in the system."
pradyuprasad commented 15 hours ago

Proposal: Introduce Role Enum vs. Using Tags in Person Class

Current Setup

We planned to use the tags attribute (Set) in the Person class to mark someone as a patient or caregiver.

Proposed Change

Create a Role enum (with PATIENT and CAREGIVER) and add a Set<Role> to the Person class.

Why I Think This Might Be Better

  1. It's more specific - we'd have a dedicated way to handle roles.
  2. Less chance of typos - can't accidentally write "paitent" instead of "patient".
  3. Makes our code clearer - easier to understand at a glance what we're checking for.
  4. IDE Support: Enums provide better autocomplete and refactoring support in IDEs.
pradyuprasad commented 15 hours ago

We'll add two new fields to Person:

These will store the IC numbers of a person's dependents and caregivers.

I chose "dependent" instead of "patient" to avoid confusion with the PATIENT role we already have.

By storing just the IC numbers, we can:

  1. Save memory
  2. Avoid circular references
  3. Make it easier to add or remove relationships without loading whole Person objects

We'll need to add methods like:

And update equals(), hashCode(), and toString() to include these new fields.

Also, we'll need to update other parts of the code that work with Person objects