Skip to content

Commit

Permalink
Merge pull request #2 from AY2324S1-CS2103T-T12-4/master
Browse files Browse the repository at this point in the history
pull to local device
  • Loading branch information
adammangzijun authored Oct 24, 2023
2 parents 2634f5e + b9df459 commit 4dcdfa0
Show file tree
Hide file tree
Showing 70 changed files with 2,190 additions and 217 deletions.
2 changes: 2 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "src/main/java/seedu/address/ui"
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ shadowJar {
archiveFileName = 'medbook.jar'
}

run {
enableAssertions = true
}

defaultTasks 'clean', 'test'
217 changes: 133 additions & 84 deletions docs/UserGuide.md

Large diffs are not rendered by default.

Binary file added docs/images/MedBookUi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 15 additions & 7 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.commons.core.Version;
import seedu.address.commons.exceptions.DataLoadingException;
import seedu.address.commons.util.ConfigUtil;
import seedu.address.commons.util.JsonUtil;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
Expand Down Expand Up @@ -57,7 +58,8 @@ public void init() throws Exception {

UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath());
UserPrefs userPrefs = initPrefs(userPrefsStorage);
AddressBookStorage addressBookStorage = new JsonAddressBookStorage(userPrefs.getAddressBookFilePath());
AddressBookStorage addressBookStorage = new JsonAddressBookStorage(userPrefs.getAddressBookFilePath(),
new JsonUtil());
storage = new StorageManager(addressBookStorage, userPrefsStorage);

model = initModelManager(storage, userPrefs);
Expand All @@ -68,9 +70,12 @@ public void init() throws Exception {
}

/**
* Returns a {@code ModelManager} with the data from {@code storage}'s address book and {@code userPrefs}. <br>
* The data from the sample address book will be used instead if {@code storage}'s address book is not found,
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
* Returns a {@code ModelManager} with the data from {@code storage}'s address
* book and {@code userPrefs}. <br>
* The data from the sample address book will be used instead if
* {@code storage}'s address book is not found,
* or an empty address book will be used instead if errors occur when reading
* {@code storage}'s address book.
*/
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
logger.info("Using data file : " + storage.getAddressBookFilePath());
Expand Down Expand Up @@ -127,7 +132,8 @@ protected Config initConfig(Path configFilePath) {
initializedConfig = new Config();
}

//Update config file in case it was missing to begin with or there are new/unused fields
// Update config file in case it was missing to begin with or there are
// new/unused fields
try {
ConfigUtil.saveConfig(initializedConfig, configFilePathUsed);
} catch (IOException e) {
Expand All @@ -137,7 +143,8 @@ protected Config initConfig(Path configFilePath) {
}

/**
* Returns a {@code UserPrefs} using the file at {@code storage}'s user prefs file path,
* Returns a {@code UserPrefs} using the file at {@code storage}'s user prefs
* file path,
* or a new {@code UserPrefs} with default configuration if errors occur when
* reading from the file.
*/
Expand All @@ -158,7 +165,8 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
initializedPrefs = new UserPrefs();
}

//Update prefs file in case it was missing to begin with or there are new/unused fields
// Update prefs file in case it was missing to begin with or there are
// new/unused fields
try {
storage.saveUserPrefs(initializedPrefs);
} catch (IOException e) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/commons/core/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
public class GuiSettings implements Serializable {

private static final double DEFAULT_HEIGHT = 600;
private static final double DEFAULT_WIDTH = 740;
private static final double DEFAULT_HEIGHT = 720;
private static final double DEFAULT_WIDTH = 1280;

private final double windowWidth;
private final double windowHeight;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.record.Record;

/**
* API of the Logic component
Expand Down Expand Up @@ -50,4 +51,8 @@ public interface Logic {
* Set the user prefs' GUI settings.
*/
void setGuiSettings(GuiSettings guiSettings);

ObservableList<Record> getRecordList();

ObservableList<Person> getPersonBeingViewed();
}
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Person;
import seedu.address.model.record.Record;
import seedu.address.storage.Storage;

/**
Expand Down Expand Up @@ -76,6 +77,16 @@ public ObservableList<Person> getPinnedPersonList() {
return model.getPinnedPersonList();
}

@Override
public ObservableList<Record> getRecordList() {
return model.getRecordList();
}

@Override
public ObservableList<Person> getPersonBeingViewed() {
return model.getPersonBeingViewed();
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Messages {
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_RECORD_DISPLAYED_INDEX = "The record index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";
Expand Down Expand Up @@ -69,7 +70,7 @@ public static String format(Appointment appointment, Person person) {
}

/**
* Formats the {@code person} for display to the user.
* Formats the {@code record} for display to the user.
*/
public static String format(Record record, Person person) {
final StringBuilder builder = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import seedu.address.model.person.BloodType;
import seedu.address.model.person.Email;
import seedu.address.model.person.Gender;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.record.UniqueRecordList;
import seedu.address.model.shared.Name;


/**
Expand Down
232 changes: 232 additions & 0 deletions src/main/java/seedu/address/logic/commands/EditRecordCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CONDITION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.CollectionUtil;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.person.Person;
import seedu.address.model.record.Condition;
import seedu.address.model.record.Record;
import seedu.address.model.record.UniqueRecordList;
import seedu.address.model.shared.DateTime;

/**
* Edits the details of an existing record of a Person in the address book.
*/
public class EditRecordCommand extends Command {

public static final String COMMAND_WORD = "editrecord";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits a patient's record in the address book "
+ "by the patient's index number and the record's index number.\n"
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: PATIENT'S INDEX/RECORD INDEX (both must be a positive integer) "
+ "[" + PREFIX_DATE + "DATE] "
+ "[" + PREFIX_CONDITION + "CONDITION] " + "\n"
+ "Example: " + COMMAND_WORD + " 1/2 "
+ PREFIX_DATE + "21092023 1800 "
+ PREFIX_CONDITION + "Cold";

public static final String MESSAGE_EDIT_RECORD_SUCCESS = "Edited record: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_RECORD = "This record already exists in the record of the patient.";

private final Index patientIndex;
private final Index recordIndex;
private final EditRecordCommand.EditRecordDescriptor editRecordDescriptor;

/**
* @param patientIndex index of the person in the filtered person list to edit
* @param recordIndex index of the record of the targeted patient
* @param editRecordDescriptor details to edit the record with
*/
public EditRecordCommand(Index patientIndex, Index recordIndex,
EditRecordCommand.EditRecordDescriptor editRecordDescriptor) {
requireNonNull(patientIndex);
requireNonNull(recordIndex);
requireNonNull(editRecordDescriptor);

this.patientIndex = patientIndex;
this.recordIndex = recordIndex;
this.editRecordDescriptor = new EditRecordCommand.EditRecordDescriptor(editRecordDescriptor);
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Person> lastShownPersonList = model.getFilteredPersonList();

if (patientIndex.getZeroBased() >= lastShownPersonList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}

Person personToEdit = lastShownPersonList.get(patientIndex.getZeroBased());

UniqueRecordList uniqueRecordList = personToEdit.getRecords();
List<Record> lastShownRecordList = uniqueRecordList.getRecordList();

if (recordIndex.getZeroBased() >= lastShownRecordList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_RECORD_DISPLAYED_INDEX);
}

Record recordToEdit = lastShownRecordList.get(recordIndex.getZeroBased());
Record editedRecord = createEditedRecord(recordToEdit, editRecordDescriptor);

if (!recordToEdit.equals(editedRecord) && uniqueRecordList.contains(editedRecord)) {
throw new CommandException(MESSAGE_DUPLICATE_RECORD);
}

uniqueRecordList.setRecord(recordToEdit, editedRecord);
Person editedPerson = createdEditedPerson(personToEdit, uniqueRecordList);

if (!personToEdit.isSamePerson(editedPerson) && model.hasPerson(editedPerson)) {
throw new CommandException(EditCommand.MESSAGE_DUPLICATE_PERSON);
}

model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult(String.format(MESSAGE_EDIT_RECORD_SUCCESS,
Messages.format(editedRecord, personToEdit)));
}

/**
* Creates and returns a {@code Record} with the details of {@code recordToEdit}
* edited with {@code editRecordDescriptor}.
*/
private static Record createEditedRecord(Record recordToEdit,
EditRecordCommand.EditRecordDescriptor editRecordDescriptor) {
assert recordToEdit != null;

DateTime updatedDateTime = editRecordDescriptor.getDateTime().orElse(recordToEdit.getDateTime());
List<Condition> updatedConditions = editRecordDescriptor.getConditions().orElse(recordToEdit.getConditions());

return new Record(updatedDateTime, updatedConditions);
}

private static Person createdEditedPerson(Person personToEdit, UniqueRecordList records) {
assert personToEdit != null;
Person editedPerson = new Person(personToEdit.getName(), personToEdit.getEmail(),
personToEdit.getPhone(), personToEdit.getGender(),
personToEdit.getAge(), personToEdit.getBloodType(),
personToEdit.getAllergies(), records,
personToEdit.getAppointments(), personToEdit.isPinned());

return editedPerson;
}

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

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

EditRecordCommand otherEditRecordCommand = (EditRecordCommand) other;
return patientIndex.equals(otherEditRecordCommand.patientIndex)
&& recordIndex.equals(otherEditRecordCommand.recordIndex)
&& editRecordDescriptor.equals(otherEditRecordCommand.editRecordDescriptor);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("patientIndex", patientIndex)
.add("recordIndex", recordIndex)
.add("editRecordDescriptor", editRecordDescriptor)
.toString();
}

/**
* Stores the details to edit the record with. Each non-empty field value will replace the
* corresponding field value of the record.
*/
public static class EditRecordDescriptor {
private DateTime dateTime;
private List<Condition> conditions;

public EditRecordDescriptor() {}

/**
* Copy constructor.
* A defensive copy of {@code conditionss} is used internally.
*/
public EditRecordDescriptor(EditRecordCommand.EditRecordDescriptor toCopy) {
setDateTime(toCopy.dateTime);
setConditions(toCopy.conditions);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(dateTime, conditions);
}

public void setDateTime(DateTime dateTime) {
this.dateTime = dateTime;
}

public Optional<DateTime> getDateTime() {
return Optional.ofNullable(dateTime);
}

/**
* Sets {@code conditions} to this record's {@code conditions}.
* A defensive copy of {@code condtions} is used internally.
*/
public void setConditions(List<Condition> conditions) {
this.conditions = (conditions != null) ? new ArrayList<>(conditions) : null;
}

/**
* Returns an unmodifiable condition list, which throws {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code conditions} is null.
*/
public Optional<List<Condition>> getConditions() {
return (conditions != null) ? Optional.of(Collections.unmodifiableList(conditions)) : Optional.empty();
}

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

// instanceof handles nulls
if (!(other instanceof EditRecordCommand.EditRecordDescriptor)) {
return false;
}

EditRecordCommand.EditRecordDescriptor otherEditRecordDescriptor =
(EditRecordCommand.EditRecordDescriptor) other;
return Objects.equals(dateTime, otherEditRecordDescriptor.dateTime)
&& Objects.equals(conditions, otherEditRecordDescriptor.conditions);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("dateTime", dateTime)
.add("conditions", conditions)
.toString();
}
}
}
Loading

0 comments on commit 4dcdfa0

Please sign in to comment.