forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Prescription add/delete/list commands (#136)
* Added Prescription add/delete/list commands * Merge with master * Fix checkstyle errors * Updated to latest command format * Fix checkstyle error * Remove redundant prefix * Merge master, resolve naming recommendation * Fix checkstyle error
- Loading branch information
1 parent
2297f1c
commit f9deb2b
Showing
21 changed files
with
737 additions
and
23 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/main/java/seedu/address/logic/commands/prescription/AddPrescriptionCommand.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,83 @@ | ||
package seedu.address.logic.commands.prescription; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_DURATION; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_INDEX; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_VOLUME; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.AppointmentCommand; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.appointment.Appointment; | ||
import seedu.address.model.prescription.Prescription; | ||
|
||
|
||
/** | ||
* Adds a prescription to an appointment. | ||
*/ | ||
public class AddPrescriptionCommand extends AppointmentCommand { | ||
public static final String COMMAND_WORD = "pa"; | ||
|
||
public static final String MESSAGE_USAGE = | ||
"apmt " | ||
+ COMMAND_WORD + ": Adds a prescription to an appointment. " | ||
+ "Parameters: \n" | ||
+ PREFIX_INDEX + "ID OF APPOINTMENT \n" | ||
+ PREFIX_NAME + "MEDICINE \n" | ||
+ PREFIX_VOLUME + "VOLUME \n" | ||
+ PREFIX_DURATION + "DURATION \n" | ||
+ "Example: apmt " + COMMAND_WORD + " " | ||
+ PREFIX_INDEX + "1 " | ||
+ PREFIX_NAME + "Penicillin " | ||
+ PREFIX_VOLUME + "400 ml " | ||
+ PREFIX_DURATION + "2 times a week "; | ||
|
||
public static final String MESSAGE_SUCCESS = "New prescription added"; | ||
public static final String MESSAGE_DUPLICATE_MEDICINE = | ||
"This medicine already exists in the prescription for this appointment"; | ||
|
||
private final Index targetAppointmentIndex; | ||
private String medicine; | ||
private String volume; | ||
private String duration; | ||
|
||
/** | ||
* Creates an AddPrescriptionCommand to add the specified {@code Prescription} | ||
* @param targetAppointmentIndex appointment index to make prescription | ||
*/ | ||
public AddPrescriptionCommand(Index targetAppointmentIndex, String medicine, String volume, String duration) { | ||
requireNonNull(targetAppointmentIndex); | ||
requireNonNull(medicine); | ||
requireNonNull(volume); | ||
requireNonNull(duration); | ||
this.targetAppointmentIndex = targetAppointmentIndex; | ||
this.volume = volume; | ||
this.medicine = medicine; | ||
this.duration = duration; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Appointment> lastShownList = model.getFilteredAppointmentList(); | ||
|
||
if (targetAppointmentIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_APPOINTMENT_DISPLAYED_INDEX); | ||
} | ||
|
||
Appointment appointmentToMakePrescription = lastShownList.get(targetAppointmentIndex.getZeroBased()); | ||
Prescription toAdd = new Prescription(medicine, volume, duration, appointmentToMakePrescription); | ||
|
||
if (appointmentToMakePrescription.containsPrescription(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_MEDICINE); | ||
} | ||
appointmentToMakePrescription.addPrescription(toAdd); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/seedu/address/logic/commands/prescription/DeletePrescriptionCommand.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,84 @@ | ||
package seedu.address.logic.commands.prescription; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_INDEX; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.AppointmentCommand; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.appointment.Appointment; | ||
import seedu.address.model.prescription.exceptions.MedicineNotFoundException; | ||
|
||
|
||
|
||
public class DeletePrescriptionCommand extends AppointmentCommand { | ||
public static final String COMMAND_WORD = "pd"; | ||
|
||
public static final String MESSAGE_USAGE = "apmt " | ||
+ COMMAND_WORD + ": Deletes a prescription from an appointment based " | ||
+ "on appointment index and medicine name. \n" | ||
+ "Parameters: \n" | ||
+ PREFIX_INDEX + "ID OF APPOINTMENT \n" | ||
+ PREFIX_NAME + "MEDICINE \n" | ||
+ "Example: appt " + COMMAND_WORD + " " | ||
+ PREFIX_INDEX + "1 " | ||
+ PREFIX_NAME + "Penicillin "; | ||
|
||
public static final String MESSAGE_DELETE_PRESCRIPTION_SUCCESS = "Deleted prescription"; | ||
|
||
private final Index targetAppointmentIndex; | ||
private final String targetMedicineName; | ||
|
||
/** | ||
* Deletes a prescription from an appointment based on appointment index and medicine name | ||
* @param targetAppointmentIndex Index of targeted appointment | ||
* @param targetMedicineName Name of medicine associated with prescription to be deleted | ||
*/ | ||
public DeletePrescriptionCommand(Index targetAppointmentIndex, String targetMedicineName) { | ||
this.targetAppointmentIndex = targetAppointmentIndex; | ||
this.targetMedicineName = targetMedicineName; | ||
} | ||
|
||
@Override public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Appointment> lastShownList = model.getFilteredAppointmentList(); | ||
|
||
if (targetAppointmentIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_APPOINTMENT_DISPLAYED_INDEX); | ||
} | ||
|
||
Appointment appointmentToTarget = lastShownList.get(targetAppointmentIndex.getZeroBased()); | ||
try { | ||
appointmentToTarget.removePrescription(targetMedicineName); | ||
return new CommandResult(MESSAGE_DELETE_PRESCRIPTION_SUCCESS); | ||
} catch (MedicineNotFoundException e) { | ||
throw new CommandException(e.getMessage()); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
DeletePrescriptionCommand that = (DeletePrescriptionCommand) o; | ||
return Objects.equals(targetAppointmentIndex, that.targetAppointmentIndex) | ||
&& Objects.equals(targetMedicineName, that.targetMedicineName); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(targetAppointmentIndex, targetMedicineName); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/seedu/address/logic/commands/prescription/ListPrescriptionsCommand.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,50 @@ | ||
package seedu.address.logic.commands.prescription; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_INDEX; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PRESCRIPTIONS; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.AppointmentCommand; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.appointment.Appointment; | ||
|
||
|
||
|
||
public class ListPrescriptionsCommand extends AppointmentCommand { | ||
public static final String COMMAND_WORD = "pl"; | ||
|
||
public static final String MESSAGE_USAGE = "apmt " | ||
+ COMMAND_WORD + ": List all prescriptions of an appointment " | ||
+ "Parameters: \n" | ||
+ PREFIX_INDEX + "ID OF APPOINTMENT \n" | ||
+ "Example: appt " + COMMAND_WORD + " " | ||
+ PREFIX_INDEX + "1 "; | ||
|
||
public static final String MESSAGE_SUCCESS = "Listed all prescriptions of appointment"; | ||
|
||
private final Index targetAppointmentIndex; | ||
|
||
public ListPrescriptionsCommand(Index targetAppointmentIndex) { | ||
this.targetAppointmentIndex = targetAppointmentIndex; | ||
} | ||
|
||
@Override public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Appointment> lastShownList = model.getFilteredAppointmentList(); | ||
if (targetAppointmentIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_APPOINTMENT_DISPLAYED_INDEX); | ||
} | ||
|
||
Appointment appointmentToTarget = lastShownList.get(targetAppointmentIndex.getZeroBased()); | ||
|
||
appointmentToTarget.updateFilteredPrescriptions(PREDICATE_SHOW_ALL_PRESCRIPTIONS); | ||
|
||
return new CommandResult(MESSAGE_SUCCESS + appointmentToTarget.getFilteredPrescriptions()); | ||
} | ||
} |
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
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
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
Oops, something went wrong.