Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"add" command prevents addition of future dates. #379

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ Note : <br>
• The mandatory fields are name, NRIC and visit date. Optional fields (denoted by square brackets above) include phone
number, diagnoses, medications, home address, date of birth, allergies, sex and medical histories. <br>
• Single diagnosis, medication, allergy and medical history can be added; <u>Multiple diagnoses, medications, allergies and/or medical histories are also allowed</u>, by separating them with commas. <br>
• Date and Time format must be in : dd-MM-yyyy HH:mm <br>
• Date and Time format must be in : dd-MM-yyyy HH:mm <br>
• "add" command does <u>not allow</u> for adding <u>future Dates&Time</u>. Consider scheduling an Appointment instead. <br>
• Parameters entered in the input can be of <u>any order</u> or you may also choose to stick to the format above. <br>
Example: `add n/James Ho ic/S9534567A p/91234567 d/Asthma m/Albuterol ha/NUS-PGPR dob/01-01-1995 v/21-10-2024 15:48 al/Pollen s/Female mh/Diabetes`

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/bookbob/functions/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ public void add(String input, Records records) throws IOException {
errorMessages.append("Please provide the patient's visit date and time");
}

// Only validate future dates if we have a valid visit date
if (visitDate != null) {
LocalDateTime currentDateTime = LocalDateTime.now();
if (visitDate.isAfter(currentDateTime)) {
System.out.println("Error: Cannot add patient records for future dates. Please consider " +
"scheduling an appointment instead.");
logger.log(Level.WARNING, "Attempted to add patient record with future visit date: " +
visitDate.format(DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm")));
return;
}
}

// If there are error messages, print them and return
if (errorMessages.length() > 0) {
System.out.println(errorMessages.toString());
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/bookbob/functions/CommandHandlerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,15 +722,15 @@ void editCommand_validFormatInputtedToEditAllergies_editSuccessfully() throws IO
@Test
void add_onePatient_onePatientInRecord() throws IOException{
command.add("add n/John Doe ic/S1234567A p/98765432 d/COVID-19 m/Paracetamol ha/RC4 dob/13-04-2000" +
"v/23-11-2024 12:29", records);
"v/01-11-2024 12:29", records);
assertEquals(1, records.getPatients().size());
}

// @@author G13nd0n
@Test
void delete_onePatient_twoPatientInRecord() throws IOException{
command.add("add n/John Doe ic/S1234567A p/98765432 d/COVID-19 m/Paracetamol ha/RC4 dob/13-04-2000" +
"v/23-11-2024 12:29", records);
"v/06-11-2024 12:29", records);
command.add("add n/Will Smith ic/S7654321B p/91234567 d/AIDS m/Paracetamol ha/CAPT dob/18-06-2003" +
"v/15-10-2024 11:53", records);
command.add("add n/Shawn Knowles ic/S2468013C p/87654321 d/Fever m/Aspirin ha/Tembusu dob/23-11-1998" +
Expand All @@ -743,7 +743,7 @@ void delete_onePatient_twoPatientInRecord() throws IOException{
@Test
void testList_twoInputs_twoPatientsInRecord() throws IOException {
command.add("add n/John Doe ic/S1234567A p/98765432 d/COVID-19 m/Paracetamol ha/RC4 dob/13-04-2000" +
"v/23-11-2024 12:29", records);
"v/03-11-2024 12:29", records);
command.add("add n/Will Smith ic/S7654321B p/91234567 d/AIDS m/Paracetamol ha/CAPT dob/18-06-2003" +
"v/15-10-2024 11:53", records);
command.list(records);
Expand All @@ -752,7 +752,7 @@ void testList_twoInputs_twoPatientsInRecord() throws IOException {
"Patient Will Smith with NRIC S7654321B added.\n" +
"Name: John Doe, NRIC: S1234567A, Phone: 98765432, Home Address: RC4, " +
"DOB: 13-04-2000, Allergies: [], Sex: , Medical Histories: []\n" +
" Visit Date: 23-11-2024 12:29, Diagnosis: [COVID-19], Medications: [Paracetamol]\n" +
" Visit Date: 03-11-2024 12:29, Diagnosis: [COVID-19], Medications: [Paracetamol]\n" +
"Name: Will Smith, NRIC: S7654321B, Phone: 91234567, Home Address: CAPT, " +
"DOB: 18-06-2003, Allergies: [], Sex: , Medical Histories: []\n" +
" Visit Date: 15-10-2024 11:53, Diagnosis: [AIDS], Medications: [Paracetamol]";
Expand All @@ -766,7 +766,7 @@ void testList_twoInputs_twoPatientsInRecord() throws IOException {
@Test
void testFind_nric_oneOutput() throws IOException{
command.add("add n/John Doe ic/S1234567A p/98765432 d/COVID-19 m/Paracetamol ha/RC4 dob/13-04-2000" +
"v/23-11-2024 12:29", records);
"v/02-11-2024 12:29", records);
command.add("add n/Will Smith ic/S7654321B p/91234567 d/AIDS m/Paracetamol ha/CAPT dob/18-06-2003" +
"v/21-10-2024 15:30 al/peanuts s/male mh/diabetes", records);
command.find("ic/S7654321B", records);
Expand Down Expand Up @@ -795,7 +795,7 @@ void editCommand_validFormatInputtedToEditMedicalHistories_editSuccessfully() th
@Test
void testFind_name_multipleOutputs() throws IOException {
command.add("add n/John Doe ic/S1234567A p/98765432 d/COVID-19 m/Paracetamol ha/RC4 dob/13-04-2000" +
"v/23-11-2024 12:29", records);
"v/01-11-2024 12:29", records);
command.add("add n/Will Smith ic/S7654321B p/91234567 d/AIDS m/Paracetamol ha/CAPT dob/18-06-2003" +
"v/21-10-2024 15:30", records);
command.add("add n/John Smith ic/S2468024A p/87654321 d/Diabetes m/Insulin ha/CAPT dob/13-04-2002" +
Expand Down Expand Up @@ -826,7 +826,7 @@ void editCommand_invalidFormatInputtedWithoutTo_editFailsWithErrorMessage() thro
@Test
void testFind_address_multipleOutputs() throws IOException {
command.add("add n/John Doe ic/S1234567A p/98765432 d/COVID-19 m/Paracetamol ha/RC4 dob/13-04-2000" +
"v/23-11-2024 12:29", records);
"v/10-11-2024 12:29", records);
command.add("add n/Will Smith ic/S7654321B p/91234567 d/AIDS m/Paracetamol ha/CAPT dob/18-06-2003" +
"v/21-10-2024 15:30", records);
command.add("add n/John Smith ic/S2468024A p/87654321 d/Diabetes m/Insulin ha/CAPT dob/13-04-2002" +
Expand Down
Loading