Skip to content

Commit

Permalink
Merge pull request #53 from gsmoon97/refactor-to-clinical
Browse files Browse the repository at this point in the history
Refactor AddressBook to CliniCal
  • Loading branch information
afroneth authored Sep 26, 2020
2 parents 036e3bf + ce782cc commit c645ca0
Show file tree
Hide file tree
Showing 54 changed files with 495 additions and 494 deletions.
2 changes: 1 addition & 1 deletion docs/diagrams/ArchitectureSequenceDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ activate model MODEL_COLOR
model -[MODEL_COLOR]-> logic
deactivate model

logic -[LOGIC_COLOR]> storage : saveAddressBook(addressBook)
logic -[LOGIC_COLOR]> storage : saveAddressBook(cliniCal)
activate storage STORAGE_COLOR

storage -[STORAGE_COLOR]> storage : Save to file
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.model.AddressBook;
import seedu.address.model.CliniCal;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyCliniCal;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.UserPrefs;
import seedu.address.model.util.SampleDataUtil;
import seedu.address.storage.AddressBookStorage;
import seedu.address.storage.JsonAddressBookStorage;
import seedu.address.storage.CliniCalStorage;
import seedu.address.storage.JsonCliniCalStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.Storage;
import seedu.address.storage.StorageManager;
Expand All @@ -48,16 +48,16 @@ public class MainApp extends Application {

@Override
public void init() throws Exception {
logger.info("=============================[ Initializing AddressBook ]===========================");
logger.info("=============================[ Initializing CliniCal ]===========================");
super.init();

AppParameters appParameters = AppParameters.parse(getParameters());
config = initConfig(appParameters.getConfigPath());

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

initLogging(config);

Expand All @@ -74,20 +74,20 @@ public void init() throws Exception {
* 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) {
Optional<ReadOnlyAddressBook> addressBookOptional;
ReadOnlyAddressBook initialData;
Optional<ReadOnlyCliniCal> cliniCalOptional;
ReadOnlyCliniCal initialData;
try {
addressBookOptional = storage.readAddressBook();
if (!addressBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample AddressBook");
cliniCalOptional = storage.readCliniCal();
if (!cliniCalOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample CliniCal");
}
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
initialData = cliniCalOptional.orElseGet(SampleDataUtil::getSampleCliniCal);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
initialData = new AddressBook();
logger.warning("Data file not in the correct format. Will be starting with an empty CliniCal");
initialData = new CliniCal();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
initialData = new AddressBook();
logger.warning("Problem while reading from the file. Will be starting with an empty CliniCal");
initialData = new CliniCal();
}

return new ModelManager(initialData, userPrefs);
Expand Down Expand Up @@ -151,7 +151,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {
+ "Using default user prefs");
initializedPrefs = new UserPrefs();
} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
logger.warning("Problem while reading from the file. Will be starting with an empty CliniCal");
initializedPrefs = new UserPrefs();
}

Expand All @@ -167,7 +167,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) {

@Override
public void start(Stage primaryStage) {
logger.info("Starting AddressBook " + MainApp.VERSION);
logger.info("Starting CliniCal " + MainApp.VERSION);
ui.start(primaryStage);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/LogsCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class LogsCenter {
private static final int MAX_FILE_COUNT = 5;
private static final int MAX_FILE_SIZE_IN_BYTES = (int) (Math.pow(2, 20) * 5); // 5MB
private static final String LOG_FILE = "addressbook.log";
private static final String LOG_FILE = "clinical.log";
private static Level currentLogLevel = Level.INFO;
private static final Logger logger = LogsCenter.getLogger(LogsCenter.class);
private static FileHandler fileHandler;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyCliniCal;
import seedu.address.model.patient.Patient;

/**
Expand All @@ -24,19 +24,19 @@ public interface Logic {
CommandResult execute(String commandText) throws CommandException, ParseException;

/**
* Returns the AddressBook.
* Returns the CliniCal.
*
* @see seedu.address.model.Model#getAddressBook()
* @see seedu.address.model.Model#getCliniCal()
*/
ReadOnlyAddressBook getAddressBook();
ReadOnlyCliniCal getCliniCal();

/** Returns an unmodifiable view of the filtered list of patients */
ObservableList<Patient> getFilteredPatientList();

/**
* Returns the user prefs' address book file path.
*/
Path getAddressBookFilePath();
Path getCliniCalFilePath();

/**
* Returns the user prefs' GUI settings.
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.AddressBookParser;
import seedu.address.logic.parser.CliniCalParser;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyCliniCal;
import seedu.address.model.patient.Patient;
import seedu.address.storage.Storage;

Expand All @@ -26,15 +26,15 @@ public class LogicManager implements Logic {

private final Model model;
private final Storage storage;
private final AddressBookParser addressBookParser;
private final CliniCalParser cliniCalParser;

/**
* Constructs a {@code LogicManager} with the given {@code Model} and {@code Storage}.
*/
public LogicManager(Model model, Storage storage) {
this.model = model;
this.storage = storage;
addressBookParser = new AddressBookParser();
cliniCalParser = new CliniCalParser();
}

@Override
Expand All @@ -44,14 +44,14 @@ public CommandResult execute(String commandText) throws CommandException, ParseE

CommandResult commandResult;
//Parse user input from String to a Command
Command command = addressBookParser.parseCommand(commandText);
Command command = cliniCalParser.parseCommand(commandText);
//Executes the Command and stores the result
commandResult = command.execute(model);

try {
//We can deduce that the previous line of code modifies model in some way
// since it's being stored here.
storage.saveAddressBook(model.getAddressBook());
storage.saveCliniCal(model.getCliniCal());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
Expand All @@ -60,8 +60,8 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
}

@Override
public ReadOnlyAddressBook getAddressBook() {
return model.getAddressBook();
public ReadOnlyCliniCal getCliniCal() {
return model.getCliniCal();
}

@Override
Expand All @@ -70,8 +70,8 @@ public ObservableList<Patient> getFilteredPatientList() {
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
public Path getCliniCalFilePath() {
return model.getCliniCalFilePath();
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static java.util.Objects.requireNonNull;

import seedu.address.model.AddressBook;
import seedu.address.model.CliniCal;
import seedu.address.model.Model;

/**
Expand All @@ -17,7 +17,7 @@ public class ClearCommand extends Command {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.setAddressBook(new AddressBook());
model.setCliniCal(new CliniCal());
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* Parses user input.
*/
public class AddressBookParser {
public class CliniCalParser {

/**
* Used for initial separation of command word and args.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Wraps all data at the address-book level
* Duplicates are not allowed (by .isSamePatient comparison)
*/
public class AddressBook implements ReadOnlyAddressBook {
public class CliniCal implements ReadOnlyCliniCal {

private final UniquePatientList patients;

Expand All @@ -27,12 +27,12 @@ public class AddressBook implements ReadOnlyAddressBook {
patients = new UniquePatientList();
}

public AddressBook() {}
public CliniCal() {}

/**
* Creates an AddressBook using the Patients in the {@code toBeCopied}
* Creates a CliniCal using the Patients in the {@code toBeCopied}
*/
public AddressBook(ReadOnlyAddressBook toBeCopied) {
public CliniCal(ReadOnlyCliniCal toBeCopied) {
this();
resetData(toBeCopied);
}
Expand All @@ -48,9 +48,9 @@ public void setPatients(List<Patient> patients) {
}

/**
* Resets the existing data of this {@code AddressBook} with {@code newData}.
* Resets the existing data of this {@code CliniCal} with {@code newData}.
*/
public void resetData(ReadOnlyAddressBook newData) {
public void resetData(ReadOnlyCliniCal newData) {
requireNonNull(newData);

setPatients(newData.getPatientList());
Expand Down Expand Up @@ -87,7 +87,7 @@ public void setPatient(Patient target, Patient editedPatient) {
}

/**
* Removes {@code key} from this {@code AddressBook}.
* Removes {@code key} from this {@code CliniCal}.
* {@code key} must exist in the address book.
*/
public void removePatient(Patient key) {
Expand All @@ -110,8 +110,8 @@ public ObservableList<Patient> getPatientList() {
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof AddressBook // instanceof handles nulls
&& patients.equals(((AddressBook) other).patients));
|| (other instanceof CliniCal // instanceof handles nulls
&& patients.equals(((CliniCal) other).patients));
}

@Override
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ public interface Model {
/**
* Returns the user prefs' address book file path.
*/
Path getAddressBookFilePath();
Path getCliniCalFilePath();

/**
* Sets the user prefs' address book file path.
*/
void setAddressBookFilePath(Path addressBookFilePath);
void setCliniCalFilePath(Path cliniCalFilePath);

/**
* Replaces address book data with the data in {@code addressBook}.
* Replaces address book data with the data in {@code cliniCal}.
*/
void setAddressBook(ReadOnlyAddressBook addressBook);
void setCliniCal(ReadOnlyCliniCal cliniCal);

/** Returns the AddressBook */
ReadOnlyAddressBook getAddressBook();
/** Returns the CliniCal */
ReadOnlyCliniCal getCliniCal();

/**
* Returns true if a patient with the same identity as {@code patient} exists in the address book.
Expand Down
Loading

0 comments on commit c645ca0

Please sign in to comment.