Skip to content

Commit

Permalink
Merge pull request #85 from S-Aishvarya/branch-UpdateUG
Browse files Browse the repository at this point in the history
Update UG
  • Loading branch information
jeong-jaeho authored Apr 4, 2024
2 parents f61ce65 + 7af01e3 commit 2b25031
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 18 deletions.
21 changes: 21 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,27 @@ Shows a list of all patients in the patient list.

Format: `list`

### Listing all patients in alphabetical order : `list-a`

Shows a list of all patients in the address book in alphabetical order.

Format: `list-a`

### Listing all patients in order of appointment date : `list-by-date`

Shows a list of all patients in the address book in order of appointment.

Format: `list-by-date`

### Listing all patients whose appointments fall or on before a certain date : `list-until-date`

Shows a list of all patients in the address book whose appointments fall on or before the given date.

Format: `list-until-date d/dd/mm/yyyy`

Examples:
* `list-until-date d/13/01/2024` Displays all patients with appointments on or before 13 January 2024.

### Editing a patient : `edit`

Edits an existing patient in the patient list.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PATIENTS;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import seedu.address.model.Model;
import seedu.address.model.patient.Patient;

/**
* Lists all patients in the patient list alphabetically to the user.
*/
public class ListAlphabeticalCommand extends Command {

public static final String COMMAND_WORD = "list-a";

public static final String MESSAGE_SUCCESS = "Listed all patients in alphabetical order";


@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS);
List<Patient> sortedList = new ArrayList<Patient>();
sortedList.addAll(model.getFilteredPatientList());
Comparator<Patient> comparator = (patient1, patient2) -> {
return patient1.getName().fullName.compareTo(patient2.getName().fullName);
};
sortedList.sort(comparator);
for (Patient patient : sortedList) {
model.deletePatient(patient);
}
for (Patient patient : sortedList) {
model.addPatient(patient);
}
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PATIENTS;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.PatientList;
import seedu.address.model.patient.Patient;

/**
* Lists patient by appointment dates
*/
public class ListByApptDateCommand extends Command {

public static final String COMMAND_WORD = "list-by-date";

public static final String MESSAGE_SUCCESS = "Listed all patients by ascending appointment date";

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS);
List<Patient> sortedList = new ArrayList<Patient>();
sortedList.addAll(model.getFilteredPatientList());
Comparator<Patient> comparator = (patient1, patient2) -> {
if (null != patient1.getAppointment().appointment && null != patient2.getAppointment().appointment) {
return patient1.getAppointment().appointment.compareTo((patient2.getAppointment().appointment));
} else if (null != patient1.getAppointment().appointment && null == patient2.getAppointment().appointment) {
return 1;
} else if (null == patient1.getAppointment().appointment && null != patient2.getAppointment().appointment) {
return -1;
} else if (null == patient1.getAppointment().appointment && null == patient2.getAppointment().appointment) {
return 0;
}
return 0;
};
sortedList.sort(comparator);

for (Patient patient : sortedList) {
model.setPatientList(new PatientList());
//model.deletePatient(patient);
}
for (Patient patient : sortedList) {
model.addPatient(patient);
}
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE_OF_VISIT;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PATIENTS;

import java.util.ArrayList;
import java.util.List;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.patient.ApptDateMatchesPredicate;
import seedu.address.model.patient.Patient;

/**
* Lists patient by appointment dates on or before given date
*/
public class ListByDateCriteriaCommand extends Command {

public static final String COMMAND_WORD = "list-until-date";

public static final String MESSAGE_SUCCESS = "Listed all patients with appointment date on or before date";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Finds all patients with appointment date on or before date "
+ "Parameters: "
+ "[" + PREFIX_DATE_OF_VISIT + "DATEOFVISIT] "
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_DATE_OF_VISIT + "25/2/2024";

private final ApptDateMatchesPredicate apptDatePredicate;

public ListByDateCriteriaCommand(ApptDateMatchesPredicate apptDatePredicate) {
this.apptDatePredicate = apptDatePredicate;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS);
List<Patient> sortedList = new ArrayList<Patient>();
model.updateFilteredPatientList(apptDatePredicate);

return new CommandResult(MESSAGE_SUCCESS);
}
}
19 changes: 1 addition & 18 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PATIENTS;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import seedu.address.model.Model;
import seedu.address.model.patient.Patient;

/**
* Lists all patients in the patient list to the user.
* Lists all patients in the patient list arbitrarily to the user.
*/
public class ListCommand extends Command {

Expand All @@ -24,18 +19,6 @@ public class ListCommand extends Command {
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredPatientList(PREDICATE_SHOW_ALL_PATIENTS);
List<Patient> sortedList = new ArrayList<Patient>();
sortedList.addAll(model.getFilteredPatientList());
Comparator<Patient> comparator = (patient1, patient2) -> {
return patient1.getName().fullName.compareTo(patient2.getName().fullName);
};
sortedList.sort(comparator);
for (Patient patient : sortedList) {
model.deletePatient(patient);
}
for (Patient patient : sortedList) {
model.addPatient(patient);
}
return new CommandResult(MESSAGE_SUCCESS);
}
}
12 changes: 12 additions & 0 deletions src/main/java/seedu/address/logic/parser/InputParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import seedu.address.logic.commands.ForceDeleteAllCommand;
import seedu.address.logic.commands.ForceExitCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListAlphabeticalCommand;
import seedu.address.logic.commands.ListByApptDateCommand;
import seedu.address.logic.commands.ListByDateCriteriaCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.NoCommand;
import seedu.address.logic.commands.YesCommand;
Expand Down Expand Up @@ -127,6 +130,9 @@ public Command parseCommand(String userInput) throws ParseException {
case ListCommand.COMMAND_WORD:
return new ListCommand();

case ListAlphabeticalCommand.COMMAND_WORD:
return new ListAlphabeticalCommand();

case ExitCommand.COMMAND_WORD:
isPreviousCommandExit = true;
return new ExitCommand();
Expand All @@ -137,6 +143,12 @@ public Command parseCommand(String userInput) throws ParseException {
case HelpCommand.COMMAND_WORD:
return new HelpCommand();

case ListByApptDateCommand.COMMAND_WORD:
return new ListByApptDateCommand();

case ListByDateCriteriaCommand.COMMAND_WORD:
return new ListByDateCriteriaCommandParser().parse(arguments);

default:
logger.finer("This user input caused a ParseException: " + userInput);
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE_OF_VISIT;

import java.time.LocalDate;

import seedu.address.logic.commands.ListByDateCriteriaCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.patient.ApptDateMatchesPredicate;

/**
* Lists patient by appointment dates parser
*/
public class ListByDateCriteriaCommandParser implements Parser<ListByDateCriteriaCommand> {

@Override
public ListByDateCriteriaCommand parse(String args) throws ParseException {

ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_DATE_OF_VISIT);

if (!argMultimap.getPreamble().equals("")) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
ListByDateCriteriaCommand.MESSAGE_USAGE));
}

LocalDate dateOfVisit =
ParserUtil.parseAppointment(argMultimap.getValue(PREFIX_DATE_OF_VISIT).get()).appointment;
ApptDateMatchesPredicate apptDatePredicate = new ApptDateMatchesPredicate(dateOfVisit);

return new ListByDateCriteriaCommand(apptDatePredicate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package seedu.address.model.patient;

import java.time.LocalDate;
import java.util.function.Predicate;

import seedu.address.commons.util.ToStringBuilder;

/**
* Predicate for appointment date.
*/
public class ApptDateMatchesPredicate implements Predicate<Patient> {
private final LocalDate apptDate;

public ApptDateMatchesPredicate(LocalDate apptDate) {
this.apptDate = apptDate;
}

@Override
public boolean test(Patient patient) {
LocalDate ptApptDate = patient.getAppointment().appointment;
if (ptApptDate == null) {
return false;
}
return ptApptDate.isBefore(this.apptDate) || ptApptDate.isEqual(this.apptDate);
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof ApptDateMatchesPredicate)) {
return false;
}

ApptDateMatchesPredicate otherApptMatchesPredicate = (ApptDateMatchesPredicate) other;
return apptDate.equals(otherApptMatchesPredicate.apptDate);
}

@Override
public String toString() {
return new ToStringBuilder(this).add("appointment", apptDate).toString();
}
}

0 comments on commit 2b25031

Please sign in to comment.