Skip to content

Commit

Permalink
Merge pull request #356 from yentheng0110/master
Browse files Browse the repository at this point in the history
Fix bugs for BookBob
coraleaf0602 authored Nov 10, 2024
2 parents 9dddc78 + 7dd8d19 commit ef62847
Showing 8 changed files with 175 additions and 671 deletions.
1 change: 0 additions & 1 deletion data/bookbob_data.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Name: John Doe | NRIC: S1234567A | Phone Number: 98765432 | Date_Of_Birth: | Home Address: | Allergy: [] | Sex: | Medical History: [] | Visit: [01-10-2024 15:30, Diagnosis: [], Medications: [], 21-10-2024 15:48, Diagnosis: [], Medications: []];
Name: Patricia Chan | NRIC: S8907890J | Phone Number: | Date_Of_Birth: | Home Address: | Allergy: [] | Sex: | Medical History: [] | Visit: [21-11-2024 18:00, Diagnosis: [], Medications: []];
11 changes: 8 additions & 3 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
@@ -46,6 +46,9 @@ The following output would be shown :`Welcome to BookBob, Dr. Bob!`
---
# Features
<hr style="width: 15%; height: 2px; background-color: black; border: none; margin-top: 10px; margin-bottom: 20px;">
Note:
1. Extra Input: Additional input provided after expected inputs for commands like list and listAppointments will be ignored.
2. Case Sensitivity: Ensure correct lowercase input as commands are case-sensitive.

## Viewing Help
Shows the available list of commands and some guiding information.
@@ -149,7 +152,7 @@ number, diagnoses, medications, home address, date of birth, allergies, sex and
• 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>
• 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/01011995 v/21-10-2024 15:48 al/Pollen s/Female mh/Diabetes`
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`

Example Output:
```
@@ -498,13 +501,15 @@ Appointment on 20-11-2024 18:00 with Patient Hela, S9876543A.
## Saving/Retrieving Patient Records and Appointment Records Data
<br>
Saving and retrieving are performed automatically whenever changes are made, with no additional commands required.

---
## Exiting the Program
Exits the program.

## Exiting the Program
To exit the program, type `exit` exactly, with no extra spaces or characters following it.
Format: `exit`

---

## FAQ

### Data Management, Updates, & Migration
Empty file added logs/logs.log.1
Empty file.
Empty file added logs/logs.log.1.lck
Empty file.
204 changes: 132 additions & 72 deletions src/main/java/bookbob/functions/CommandHandler.java

Large diffs are not rendered by default.

62 changes: 24 additions & 38 deletions src/main/java/bookbob/parser/Parser.java
Original file line number Diff line number Diff line change
@@ -34,15 +34,13 @@ public static void handleCommand(String input, CommandHandler commandHandler, Re
break;

case "add":
if (validateParameters(input, "n/", "ic/", "v/")) {
logAndExecute("add", () -> {
try {
commandHandler.add(input, records);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
logAndExecute("add", () -> {
try {
commandHandler.add(input, records);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
break;

case "delete":
@@ -80,15 +78,13 @@ public static void handleCommand(String input, CommandHandler commandHandler, Re
break;

case "addVisit":
if (validateParameters(input, "ic/", "v/")) {
logAndExecute("addVisit", () -> {
try {
commandHandler.addVisit(input, records);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
logAndExecute("addVisit", () -> {
try {
commandHandler.addVisit(input, records);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
break;

case "editVisit":
@@ -102,15 +98,13 @@ public static void handleCommand(String input, CommandHandler commandHandler, Re
break;

case "appointment":
if (validateParameters(input, "n/", "ic/", "date/", "time/")) {
logAndExecute("appointment", () -> {
try {
commandHandler.appointment(input, appointmentRecord);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
logAndExecute("appointment", () -> {
try {
commandHandler.appointment(input, appointmentRecord);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
break;

case "listAppointments":
@@ -196,20 +190,12 @@ private static void logAndExecute(String commandName, Runnable action) {
} catch (DateTimeException e) {
logger.log(Level.WARNING, "Error in {0} command: incorrect time format", commandName);
System.out.println("Error: incorrect time format.");
} catch (NullPointerException e) {
logger.log(Level.WARNING, "Error in {0} command: No input is given for a mandatory field", commandName);
System.out.println("Error: No input is given for a mandatory field.");
} catch (Exception e) {
logger.log(Level.SEVERE, "Unexpected error processing {0} command", e);
System.out.println("An unexpected error occurred: " + e.getMessage());
}
}

private static boolean validateParameters(String input, String... requiredMarkers) {
for (String marker : requiredMarkers) {
if (!input.contains(marker)) {
System.out.println("Please provide the required parameter: " + marker);
logger.log(Level.INFO, "Missing required parameter: {0}", marker);
return false;
}
}
return true;
}
}
546 changes: 0 additions & 546 deletions src/test/java/bookbob/MainTest.java

This file was deleted.

22 changes: 11 additions & 11 deletions src/test/java/bookbob/functions/CommandHandlerTest.java
Original file line number Diff line number Diff line change
@@ -362,21 +362,21 @@ void testAddVisitNonExistentPatient() throws IOException {

//@@author kaboomzxc
@Test
void testAddVisitMissingNRIC() throws IOException {
command.addVisit("addVisit v/21-10-2024 15:48 d/Fever m/Paracetamol", records);

assertEquals("Please provide the patient's NRIC.", outputStreamCaptor.toString().trim());
void testAddVisit_missingNRIC_expectAssertionError() throws IOException {
String input = "addVisit v/21-10-2024 15:48 d/Fever m/Paracetamol";
assertThrows(AssertionError.class, () -> {
command.addVisit(input, records);
});
}

//@@author kaboomzxc
@Test
void testAddVisitMissingVisitDate() throws IOException {
command.add("add n/John Doe ic/S1234567A p/98765432 v/01-10-2024 15:30", records);
outputStreamCaptor.reset();

command.addVisit("addVisit ic/S1234567A d/Fever m/Paracetamol", records);

assertEquals("Please provide the visit date and time.", outputStreamCaptor.toString().trim());
assertThrows(AssertionError.class, () -> {
command.addVisit("addVisit ic/S1234567A d/Fever m/Paracetamol", records);
});
}

//@@author kaboomzxc
@@ -569,15 +569,15 @@ public void addCommand_inputWithoutName_expectAssertionError() {
//@@author yentheng0110
@Test
void addCommand_inputWithoutNRIC_expectAssertionError() {
assertThrows(NullPointerException.class, () -> {
assertThrows(AssertionError.class, () -> {
command.add("add n/Jane Tan", records);
});
}

//@@author yentheng0110
@Test
void addCommand_inputWithoutVisitDate_expectAssertionError() {
assertThrows(NullPointerException.class, () -> {
assertThrows(AssertionError.class, () -> {
command.add("add n/Jane Tan ic/S9087689B p/90876543", records);
});
}
@@ -900,7 +900,7 @@ void editVisitCommand_inputWithoutNRIC_expectAssertionError() throws IOException
void editVisitCommand_nricInputtedNotInRecord_noPatientFoundMessageGetsPrinted() throws IOException {
String input = "editVisit ic/T0267890J date/06-11-2024 10:00 d/Asthma";
command.editVisit(input, records);
String expectedOutput = "No patient found with the given NRIC.";
String expectedOutput = "No patient found with the given NRIC";
assertEquals(expectedOutput,
outputStreamCaptor.toString().trim().replace(System.lineSeparator(), "\n"));
}

0 comments on commit ef62847

Please sign in to comment.