forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from S-Aishvarya/branch-UpdateUG
Update UG
- Loading branch information
Showing
8 changed files
with
253 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/seedu/address/logic/commands/ListAlphabeticalCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/seedu/address/logic/commands/ListByApptDateCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/seedu/address/logic/commands/ListByDateCriteriaCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/seedu/address/logic/parser/ListByDateCriteriaCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/seedu/address/model/patient/ApptDateMatchesPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |