Skip to content

Commit

Permalink
Merge pull request #34 from daviddl9/create_JsonAdaptedRequest_and_Js…
Browse files Browse the repository at this point in the history
…onAdaptedHealthWorker

Create json adapted request and json adapted health worker
  • Loading branch information
Lookuz authored Mar 5, 2019
2 parents 23a1ca1 + 91c68de commit f5c0f64
Show file tree
Hide file tree
Showing 21 changed files with 1,137 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package seedu.address.logic.commands.request;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CONDITION;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.request.Request;

/**
* Creates a new request to the request book.
*/
public class CreateCommand extends RequestCommand {

public static final String COMMAND_WORD = "create";

public static final String MESSAGE_USAGE = RequestCommand.COMMAND_WORD + " " + COMMAND_WORD
+ ": Creates a new request in the request book. " + "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_PHONE + "PHONE "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_DATE + "DATETIME"
+ PREFIX_CONDITION + "CONDITION...\n"
+ "Example: " + RequestCommand.COMMAND_WORD + " " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "81234567 "
+ PREFIX_ADDRESS + "123, Sengkang Ave 3, #04-12, 214632 "
+ PREFIX_DATE + "01-01-2019 08:00:00 "
+ PREFIX_CONDITION + "Physiotherapy";

public static final String MESSAGE_SUCCESS = "Created new request successfully: %1$s";
public static final String MESSAGE_DUPLICATE_REQUEST = "This request already exists.";

private final Request newRequest;

public CreateCommand(Request newRequest) {
requireNonNull(newRequest);
this.newRequest = newRequest;
}

/**
* Executes the command and returns the result message.
*
* @param model {@code Model} which the command should operate on.
* @param history {@code CommandHistory} which the command should operate on.
* @return feedback message of the operation result for display
* @throws CommandException If an error occurs during command execution.
*/
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
// TODO write created request into the JSON file
// if (model.hasRequest(this.newRequest)) {
// throw new CommandException(MESSAGE_DUPLICATE_REQUEST);
// }
// model.addRequest(newRequest);
// model.commitRequestBook();
return new CommandResult(String.format(MESSAGE_SUCCESS, newRequest));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package seedu.address.logic.commands.request;

import seedu.address.logic.commands.Command;

/**
* Base command for all request commands
*/
public abstract class RequestCommand extends Command {
public static final String COMMAND_WORD = "/request";
}
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_DATE = new Prefix("dt/");
public static final Prefix PREFIX_HEALTHWORKER = new Prefix("hw/");
public static final Prefix PREFIX_STATUS = new Prefix("st/");
public static final Prefix PREFIX_CONDITION = new Prefix("o/");

// Additional prefixes for HealthWorker and Patient class
public static final Prefix PREFIX_ORGANIZATION = new Prefix("o/");
public static final Prefix PREFIX_CONDITION = new Prefix("c/");
public static final Prefix PREFIX_SKILLS = new Prefix("s/");

// Prefixes for Add/Edit/Delete Command modes
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public interface Model {
/** {@code Predicate} that always evaluate to true */
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;

// /** {@code Predicate} that always evaluate to true */
// Predicate<HealthWorker> PREDICATE_SHOW_ALL_HEALTHWORKERS = unused -> true;
//
// /** {@code Predicate} that always evaluate to true */
// Predicate<Request> PREDICATE_SHOW_ALL_REQUESTS = unused -> true;

/**
* Replaces user prefs data with the data in {@code userPrefs}.
*/
Expand Down Expand Up @@ -159,4 +165,22 @@ public interface Model {
* Sets the selected person in the filtered person list.
*/
void setSelectedPerson(Person person);
//
// /**
// * Adds a given request.
// * {@code newRequest} cannot already be present in the request book.
// * @param newRequestthe request to be added.
// */
// void addRequest(Request newRequest);
//
// /**
// * Replaces the given request {@code target} with {@code request}.
// * {@code target} must be present in the address book.
// * {@code request} must not be the same request as any other request in the request book.
// * @param target The target to update
// * @param request The request to update with
// */
// void updateRequest(Request target, Request request);
//
// ObservableList<Request> get
}
15 changes: 15 additions & 0 deletions src/main/java/seedu/address/model/ReadOnlyRequestBook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package seedu.address.model;

import javafx.beans.Observable;
import javafx.collections.ObservableList;
import seedu.address.model.request.Request;

/**
* Unmodifiable view of a request book.
*/
public interface ReadOnlyRequestBook extends Observable {
/**
* @return an unmodifiable view of the request list. This list will not contain any duplicate requests.
*/
ObservableList<Request> getRequestList();
}
136 changes: 136 additions & 0 deletions src/main/java/seedu/address/model/RequestBook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package seedu.address.model;

import static java.util.Objects.requireNonNull;

import java.util.List;

import javafx.beans.InvalidationListener;
import javafx.collections.ObservableList;
import seedu.address.commons.util.InvalidationListenerManager;
import seedu.address.model.request.Request;
import seedu.address.model.request.UniqueRequestList;

/**
* Wraps all data at the request-book level
* Duplicates are not allowed (by .isSameRequest comparison)
*/
public class RequestBook implements ReadOnlyRequestBook {

private final UniqueRequestList requests = new UniqueRequestList();
private final InvalidationListenerManager invalidationListenerManager = new InvalidationListenerManager();

public RequestBook() {}

/**
* Creates a RequestBook using the Requests in the {@code toBeCopied}
*/
public RequestBook(ReadOnlyRequestBook toBeCopied) {
this();
resetData(toBeCopied);
}

//// list overwrite operations

/**
* Replaces the contents of the request list with {@code requests}.
* {@code requests} must not contain duplicate requests.
*/
public void setRequests(List<Request> requests) {
this.requests.setRequests(requests);
indicateModified();
}

/**
* Resets the existing data of this {@code RequestBook} with {@code newData}.
*/
public void resetData(ReadOnlyRequestBook newData) {
requireNonNull(newData);
setRequests(newData.getRequestList());
}

//// request-level operations

/**
* Returns true if a request with the same identity as {@code req} exists in the request book.
*/
public boolean hasRequest(Request req) {
requireNonNull(req);
return requests.contains(req);
}

/**
* Adds a request to the request book.
* The request must not already exist in the request book.
*/
public void addRequest(Request r) {
requests.add(r);
indicateModified();
}

/**
* Replaces the given person {@code target} in the list with {@code editedPerson}.
* {@code target} must exist in the request book.
* The request identity of {@code editedPerson} must not be the same as another existing request in the request
* book.
*/
public void setRequest(Request target, Request editedRequest) {
requireNonNull(editedRequest);

requests.setRequest(target, editedRequest);
indicateModified();
}

/**
* Removes {@code key} from this {@code RequestBook}.
* {@code key} must exist in the request book.
*/
public void removeRequest(Request key) {
requests.remove(key);
indicateModified();
}

/**
* @return an unmodifiable view of the request list. This list will not contain any duplicate requests.
*/
@Override
public ObservableList<Request> getRequestList() {
return requests.asUnmodifiableObservableList();
}

@Override
public void addListener(InvalidationListener listener) {
invalidationListenerManager.addListener(listener);
}

@Override
public void removeListener(InvalidationListener listener) {
invalidationListenerManager.removeListener(listener);
}

/**
* Notifies listeners that the request book has been modified.
*/
protected void indicateModified() {
invalidationListenerManager.callListeners(this);
}

//// util methods

@Override
public String toString() {
return requests.asUnmodifiableObservableList().size() + " persons";
}


@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof RequestBook // instanceof handles nulls
&& requests.equals(((RequestBook) other).requests));
}

@Override
public int hashCode() {
return requests.hashCode();
}
}
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/model/request/Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,13 @@ public boolean equals(Object other) {
}

Request otherRequest = (Request) other;

return otherRequest.getId().equals(this.id)
&& otherRequest.getPatient().equals(this.patient)
&& (otherRequest.getRequestDate().equals(this.requestDate))
&& (otherRequest.getConditions().equals(this.conditions))
&& otherRequest.getHealthStaff().equals(this.healthWorker)
&& (otherRequest.getRequestStatus() == this.requestStatus);
&& (otherRequest.getRequestStatus().equals(this.requestStatus));
}

public Set<Tag> getConditions() {
Expand Down
Loading

0 comments on commit f5c0f64

Please sign in to comment.