tp

Developer Guide

Table of Contents

Acknowledgements

Parser class and its functions are adapted with inspiration from Ria’s IP and help from regex101.

Storage class and its functions are largely adapted from Dhanish’s IP on Duke.

Quick Start

  1. Ensure that you have Java 11 or above installed.
  2. Download the latest version of OneDoc from here.
  3. Move tp.jar into an empty folder.
  4. Open the command prompt / terminal and change working directory to the folder.
  5. Run the jar file by input java -jar tp.jar into the command line. The app should start running.

Design & implementation

Architecture

The architecture diagram above shows the high-level design of the application.

Below is a quick overview of the main components and how each component interacts with one another.

Main components of the architecture

OneDoc is the main class of the application. It is responsible for

The rest of the app consists of six components, with three of them having a similar nature.

The object diagram below shows how are the instances of the components are connected on initialization.

Interaction between the architecture components

The following two sequence diagrams shows how the main flow of the app is navigating between main menu and the three sub menus. OneDoc component mainly interacts with UI and Parser components. (Xyz is a placeholder for Patient, Visit or Prescription. For example for Patient, the main menu state enum is MainMenuState.PATIENT and the parser function is patientParser(input))

The sequence diagram below shows how the components interact with each other for the scenario where the user issues the command activate x/1 in the Prescription Sub Menu.

Each of the main components defines its API in a class with the same name as the component. The sections below give more details of each component.

PatientList Component

The PatientList Component,

The Patient and PatientList classes are used in conjunction to manage patients, and the list of patients. Each patient has a name, a unique ID, a date of birth and gender. The PatientList class holds an ArrayList of Patients and manipulates them accordingly, using a UI object to print output where necessary.

At the start of the program, a new PatientList object is instantiated. Through methods in the Storage class, invalid data is ignored while valid data is read from the relevant text files to create Patients that existed prior to the last closure of the program. The patients are then added to the ArrayList in PatientList. A final call to savePatientData rewrites the data files such that only valid data remain in them. This finishes the initial set-up.

The above is a summary of the aforementioned process, omitting some commands in the code that has to do with Visits, Prescriptions and UI classes and related methods.

Important methods in PatientList class

VisitList Component

The VisitList Component,

Important methods in VisitList class

Adding a new visit

  1. VisitList is first called to add a new visit with the required details. This calls the constructor class of Visit class to create an instance of Visit
  2. The new visit is then added to the ArrayList<Visit>
  3. Lastly, the ‘UI’ class is called, to print a confirmation message that the visit has been added, and prints out the details of this new visit.

PrescriptionList component

API: PrescriptionList.java

The PrescriptionList component,

Important Methods in PrescriptionList class

Members in Prescription class

Adding a new prescription

Users are allowed to add new prescriptions. The action works as follows:

  1. When PrescriptionList is called to add a new prescription with the given details, it calls the constructor of the Prescription class to create the Prescription instance.
  2. If the new prescription has no duplicates in the prescriptionList, then it is added to the list. And ui prints an acknowledgement message of what the new prescription has.
  3. Else, ui prints a message that the prescription is already existing, and print the details of the existing prescription.

Viewing prescriptions

There are 3 viewing methods that users can view a list of prescriptions in different filter. The filters are:

Here is an example of how viewing with a patient prescription filter works:

  1. When the function viewPatientPrescription(ui, patientId) is called, it first checks whether the list is empty and has no prescription associated with the given patientId. If either case is satisfied, ui prints a no matching prescription message and returns.
  2. If not, then prescriptionList is iterated. Whenever a prescription’s patientId matches the given patientId, ui prints the prescription details.

The other 2 filters work similarly with slightly different conditions checked.

Editing a prescription

Users are allowed to edit the medicine name, dosage and time interval of the prescription. However, it is only allowed if the updated prescription does not repeat other existing prescriptions. The action works as follow:

  1. When the edit function is called, it returns if the prescriptionNumber is invalid.
  2. If prescriptionNumber is valid, prescriptionEdited is retrieved from the ArrayList<>, and newPrescription object is created to represent the updated prescription.
  3. If newPrescription has a duplicate in the list, it returns with a prescription duplicated message from ui.
  4. If not, then prescriptionEdited is updated with a confirmation message from ui.

Activating / Deactivating a prescription

Users are allowed to activate or deactivate a prescription to track whether a prescription is currently being prescribed to patients or not. Both actions work in a similar manner. The action works as follows:

  1. When activate(ui, prescriptionNumber) initiates an action in the PrescriptionList, it converts the prescriptionNumber into the index in the array.
  2. If the index is null, i.e invalid, the function is returned.
  3. Else, it gets the prescriptionEdited from the ArrayList<> with the resolved index.
  4. Then, the prescriptionEdited is set active.
  5. Lastly, UI prints an acknowledgement message of the most updated details of the prescription.

Storage Component

The Storage component,

The class diagram summarises the functions of the Storage component at a glance. The Storage class has dependencies on the Scanner (used to read files) and FileWriter (used to write to files) classes. It also has a composition relationship with 3 File objects, that are used to store data.

Important methods in the Storage class

In particular, we can observe exactly how, for instance, savePatientData works.

  1. The method, once called, creates a new FileWriter object used to write data.
  2. It calls logPatients, passing in the list of Patients and the FileWriter object created.
  3. This method, process the list of Patients one by one, calling another method called logPatientIntoDataFile, passing the Patient and FileWriter objects.
  4. The most recently called method writes the data of this Patient attribute by attribute in a pre-specified format.
  5. After all iterations, control is returned to the class that called the savePatientData method.

UI Component

Important methods in the UI class

Parser Component

The Parser component,

The Parser class has dependencies on the Pattern (used to create regular expression patterns) and Matcher (used to find regular expressions in Strings) classes.

Important methods in the Parser class

In particular, we can observe exactly how, for instance, patientParser works.

  1. The method, once called, creates 3 new Matcher objects used to identify if there is a correctly-formatted command in the user’s input of type add, edit, or retrieve. Since viewAll is a single word command, there doesn’t need to be a Matcher for it.
  2. It checks for viewAll, and then checks for each Matcher.
  3. Based on the valid Matcher or viewAll, it calls the relevant method from PatientList
  4. The PatientList method performs the subsequent actions on Patient/s, and returns the result.
  5. The method then returns the result to the UI, which presents it to the user.
  6. If there is an error, the specific relevant command is identified in this method, and the format guide is returned to the user.

Appendix

Product scope

Target user profile

Our target user profile is a doctor in need of quick access to information about his/her patients, visits, and prescriptions. The doctor can quickly see all of the prescriptions that have been given, when a patient has visited, what their reasons were, etc. through this interface. The doctor can also quickly update this before, during, or after each visit and prescription to ensure that it stays up to date and easy-to-use.

Value proposition

Doctors tend to use sticky notes or quick pieces of paper to jot down notes such as prescriptions, reason for visit, etc. This platform allows a doctor to quickly reference basic information about a patient, find their previous prescriptions and visits, and look at the history to make a decision. A doctor can mark a prescription as active or inactive, allowing a consistent history. Moreover, the only part of these records that a doctor can delete is a reason, ensuring continuity of information.

User Stories

Version As a … I want to … So that I can …
v1.0 user exit the program leave the program without damage
v1.0 doctor/user add a new patient have the patient record saved to the list of patients
v1.0 doctor/user see all patients see all the patients that are saved in the program i.e. are treated by me
v1.0 doctor/user see all the information about a patient refer to them to see all the patients that are being treated by me
v1.0 doctor/user edit a patients record change his record to reflect changes in the patient
v1.0 doctor/user add a patient visitation record refer later on for future care for the patient
v1.0 doctor/user add a reason for visit to the existing record have on record the reason the patient came for treatment for future use
v1.0 doctor/user edit a patient visitation record change the visit information in case error was entered
v1.0 doctor/user add new prescription for a patient add a new prescription for treatment for the patient
v1.0 doctor/user edit a prescription changes a prescription in case of a change in treatment or error in the current one
v1.0 doctor/user view list of existing prescriptions for a patient refer to them for future patient treatments
v2.0 doctor/user view information for patient specific visit refer to the visit in case i want to reflect on the visit
v2.0 doctor/user view all patients visit see the patient and where treated and are on record
v2.0 doctor/user view list of all existing prescriptions for all of patients see which prescription the patient was ever prescribed
v2.0 doctor/user view list of all active prescriptions for all of patients see which prescription the patient is currently taking
v2.0 doctor/user change a prescription status to active have on record that the patient is currently taking the prescription
v2.0 doctor/user change a prescription status to inactive have on record that the patient is currently not taking the prescription

Non-Functional Requirements

Index Reference

We utilize both ID and index reference in this tP, which may look confusing at first. Indices for visit and prescription are unique when created, and can be found when adding, editing, or viewing a visit or prescription. If you want to find a visit, you can search for a patient’s visits through viewPatient in the visit menu, and then use the given index of the visit you find to edit it. The same workflow applies for prescription.

Glossary

Instructions for manual testing

Given below are instructions to test the app manually.

Launch and shutdown

  1. Initial launch
    1. Download the jar file and move it into an empty folder.
    2. Open the command prompt / terminal and change working directory to the folder.
    3. Run the jar file by input java -jar tp.jar into the command line. The app should start running.
  2. Exit program
    1. Input bye. The app should end with a greeting.
  1. Go to Patient menu and return to main
    1. Input 1. The patient menu should be shown.
    2. Input main. The main menu should be shown again.
  2. Go to Visit menu and return to main
    1. Input 2. The visit menu should be shown.
    2. Input main. The main menu should be shown again.
  3. Go to Prescription menu and exit the program
    1. Input 3. The prescription menu should be shown.
    2. Input bye. The app should end with a greeting.

Loading sample data

To load sample data, please reference the following formats:

patient.txt: Name | DOB | G | ID
Example: Jane Doe | 09-09-1978 | F | T1

visit.txt: ID | Reason | Date | Time
Example: T1 | checkup | 08-11-2022 | 08:00

prescription.txt: ID | Name | Dosage | Time Interval | Active Status (T or F)
Example: T1 | penicillin | 1 tablet | every 3 days | T

Patient menu tests

Please navigate to patient menu by inputting 1 in the main menu before testing the features below.

Adding a new patient

Please ensure that a patient with ID T1 doesn’t exist before testing this feature, and there is no patient with ID T2.

  1. Add a valid patient
    1. Input add n/Johnny Depp g/M d/08-09-1965 i/T1.
    2. The patient should be added successfully with the patient details printed
  2. Add repeated patient
    1. Input add n/Elizabeth Swann g/F d/09-11-1975 i/T1.
    2. This addition should be rejected, saying the patient ID is already taken
  3. Add patient with invalid format
    1. Input add n/Will Turner g/M d/11-12-1972 i/T2.
    2. The addition should be rejected with hints of the correct input format for adding patient.
Viewing all patients
  1. View patients when there are patients
    1. Input viewall.
    2. All patients that are saved in the patient.txt file should be listed.
  2. View patients when there are no patients
    1. Clear the patient.txt file manually if it is not empty.
    2. Input viewall.
    3. There should be a message stating that there is no patients in the system.
Retrieving a patient’s records
  1. Retrieve a patient with correct format
    1. Input retrieve i/T1.
    2. The patient should be retrieved successfully with the patient details printed
  2. Retrieve a patient that doesn’t exist
    1. Input retrieve i/T2.
    2. The addition should be rejected with an error message stating that the patient ID doesn’t exist
  3. Retrieve a patient with incorrect format
    1. Input retrieve T1.
    2. The addition should be rejected with an error message stating that the input is incorrectly formatted
Modifying the details of a patient
  1. Edit a patient that doesn’t exist
    1. Input edit i/T2 n/Will Turner.
    2. The addition should be rejected with an error message stating that the patient ID doesn’t exist
  2. Edit a patient with incorrect format
    1. Input edit i/T1 d/Will Turner.
    2. The addition should be rejected with an error message stating that the input for date of birth is wrong
Viewing the commands in Patient menu
  1. Input help
    1. All commands supported in the Prescription menu should be shown.
  2. Input a command that doesn’t exist, i.e. find
    1. All commands supported in the Prescription menu should be shown.

Visit menu tests

Please follow the same format as Patient & Prescription for add, edit, viewall, etc. For viewPatient and viewVisit please read below.

Viewing a patient’s visits

Please ensure that a patient with ID T1 and T2 exists before testing this feature, and there is no patient with ID 321. Please add visits for patient T1 and not for T2.

  1. View visits of a patient with existing visits
    1. Input viewPatient i/T1
    2. The visits corresponding to patient T1 should be listed.
  2. View visits of a patient with no existing visits
    1. Input viewPatient i/T2
    2. There should be a message stating that there is no visits from this patient in the system.
  3. View visits of non-existing patient
    1. Input viewPatient i/321
    2. There should be a message stating that there is the patient ID is not existing in the app.
Viewing a visit

Please ensure that a patient with ID T1 exists before testing this feature, and there is no patient with ID 321. Please add at least two visits for patient T1, and there are no other visits in the system.

  1. View visits of a patient with existing visits
    1. Input viewPatient i/T1
    2. The visits corresponding to patient T1 should be listed.
    3. Input viewVisit x/1
    4. The single visit should be displayed with an index of 1
  2. View visits that do not exist
    1. Input viewVisit x/5
    2. There should be a message stating that there is no visit with that index.

Prescription menu tests

Please navigate to prescription menu by inputting 3 in the main menu before testing the features below.

Adding new prescriptions

Please ensure that a patient with ID T1 exists before testing this feature, and there is no patient with ID 321.

  1. Add a valid prescription
    1. Input add i/T1 n/Problaxan d/10 mg t/take 15 minutes after every meal.
    2. The prescription should be added successfully with the prescription details printed
  2. Add repeated prescription
    1. Input add i/T1 n/Panadol d/5 mg t/Once a day.
    2. Input add i/T1 n/Panadol d/5 mg t/Once a day once again.
    3. The 2nd addition should be rejected, and the existing prescription with the same details should be shown.
  3. Add prescription for non-existing patient
    1. Input add i/321 n/Panadol d/5 mg t/Once a day.
    2. The addition should be rejected with an error message stating that the patient ID does not exist.
  4. Add prescription with invalid format
    1. Input add i/T1 n/Panadol d/A pill t/Once a day.
    2. The addition should be rejected with hints of the correct input format for adding prescription.
Modifying a patient’s prescription
  1. Edit an existing prescription’s medicine name
    1. Input add i/T1 n/Panadol d/5 mg t/Once a day if the record does not exist. Skip this if it is already there.
    2. Input edit x/<index> n/Problaxan with the index shown when adding the prescription. (Index is the number next to Prescription #)
    3. The prescription’s medicine name should be changed to Problaxan without changing all other attributes.
  2. Edit a non-existing prescription’s medicine dosage
    1. Input edit x/0 d/19 mg.
    2. The modification should be rejected with a message stating the index number is out of range.
  3. Edit an existing prescription which the new version is a duplicate of another existing prescription
    1. Input add i/T1 n/Panadol d/5 mg t/Once a day if the record does not exist. Skip this if it is already there.
    2. Input add i/T1 n/Panadol d/10 mg t/Once a day if the record does not exist. Skip this if it is already there.
    3. Input edit x/<index> d/5 mg with the index shown when adding the prescription with 10 mg dosage. (Index is the number next to Prescription #)
    4. The modification should be rejected, and the existing prescription with the same details should be shown.
Viewing list of all existing Prescriptions
  1. View prescriptions when there are prescriptions
    1. Input viewall.
    2. All prescriptions that are saved in the prescription.txt file should be listed.
  2. View prescriptions when there are no prescription
    1. Clear the prescription.txt file manually if it is not empty.
    2. Input viewall.
    3. There should be a message stating that there is no prescriptions in the system.
Viewing all prescriptions of a patient

Please ensure that a patient with ID T1 and T2 exists before testing this feature, and there is no patient with ID 321. Please add prescriptions for patient T1 and not for T2.

  1. View prescriptions of a patient with existing prescriptions
    1. Input viewPatientPres i/T1
    2. The prescriptions corresponding to patient T1 should be listed.
  2. View prescriptions of a patient with no existing prescriptions
    1. Input viewPatientPres i/T2
    2. There should be a message stating that there is no prescriptions from this patient in the system.
  3. View prescriptions of non-existing patient
    1. Input viewPatientPres i/321
    2. There should be a message stating that there is the patient ID is not existing in the app.
Viewing all active prescriptions of a patient

Please ensure that a patient with ID T1 and T2 exists before testing this feature, and there is no patient with ID 321. Please add prescriptions for patient T1 and not for T2.

  1. View prescriptions of a patient with existing prescriptions
    1. Input viewActPatientPres i/T1
    2. The active prescriptions corresponding to patient T1 should be listed.
  2. View prescriptions of a patient with no existing prescriptions
    1. Input viewActPatientPres i/T2
    2. There should be a message stating that there is no active prescriptions from this patient in the system.
  3. View prescriptions of non-existing patient
    1. Input viewActPatientPres i/321
    2. There should be a message stating that there is the patient ID is not existing in the app.
Changing prescription status
  1. Activate existing prescription
    1. Input viewall and check the index of the last prescription in the system. Please add 1 if there isn’t any.
    2. Input activate x/<index>, where the index is the one retrieved from Step 1.
    3. The status of the prescription should be updated to Active.
  2. Deactivate non-existing prescription
    1. Input deactivate x/0.
    2. There should be a message stating the index number is out of range shown.
Viewing the commands in the Prescription menu
  1. Input help
    1. All commands supported in the Prescription menu should be shown.
  2. Input a command that doesn’t exist, i.e. find
    1. All commands supported in the Prescription menu should be shown.