diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 8c246a2669..803ac339d5 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -157,7 +157,8 @@ Note :
• 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.
• Single diagnosis, medication, allergy and medical history can be added; Multiple diagnoses, medications, allergies and/or medical histories are also allowed, by separating them with commas.
-• Date and Time format must be in : dd-MM-yyyy HH:mm
+• Date and Time format must be in : dd-MM-yyyy HH:mm
+• "add" command does not allow for adding future Dates&Time. Consider scheduling an Appointment instead.
• Parameters entered in the input can be of any order or you may also choose to stick to the format above.
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` diff --git a/src/main/java/bookbob/functions/CommandHandler.java b/src/main/java/bookbob/functions/CommandHandler.java index 2e6b82c898..07aed316b6 100644 --- a/src/main/java/bookbob/functions/CommandHandler.java +++ b/src/main/java/bookbob/functions/CommandHandler.java @@ -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()); diff --git a/src/test/java/bookbob/functions/CommandHandlerTest.java b/src/test/java/bookbob/functions/CommandHandlerTest.java index b3b409d4ce..a145d4a89e 100644 --- a/src/test/java/bookbob/functions/CommandHandlerTest.java +++ b/src/test/java/bookbob/functions/CommandHandlerTest.java @@ -722,7 +722,7 @@ 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()); } @@ -730,7 +730,7 @@ void add_onePatient_onePatientInRecord() throws IOException{ @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" + @@ -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); @@ -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]"; @@ -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); @@ -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" + @@ -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" +