Class PatientMenu

java.lang.Object
cz.cuni.kubinja.hospitalsystem.UI.PatientMenu
All Implemented Interfaces:
Page, PersonnelMenu

public class PatientMenu extends Object implements PersonnelMenu
Menu page containing options connected with patients.
  • Field Details

    • api

      protected Hospital api
      Connection to the hospital system
    • scanner

      protected Scanner scanner
      Scanner pointing to the input data
    • options

      protected List<cz.cuni.kubinja.hospitalsystem.UI.MenuEntry> options
      Options of the menu page
    • state

      protected UIState state
      State in which menu page is
    • exitSequence

      protected static final String exitSequence
      Sequence that forcefully stop entering data
      See Also:
  • Constructor Details

    • PatientMenu

      public PatientMenu(Hospital api, Scanner scanner)
      Creates patient menu page.
      Parameters:
      api - HospitalAPI giving the menu options how to interact with hospital system.
      scanner - Scanner pointing to the input data.
    • PatientMenu

      public PatientMenu(Hospital api, Scanner scanner, boolean dummy)
      Creates dummy patient menu page.

      This way how to create menu is only used for testing, because we want to have option how to call directly menu options and not only via prepared input data.

      Parameters:
      api - Hospital gives menu options how to interact with hospital system.
      scanner - Scanner pointing to the input data.
      dummy - Decides whether the menu page will be dummy (do not show menu, but only processes direct method calls)
  • Method Details

    • defineMenu

      public void defineMenu()
      Description copied from interface: Page
      Defines which options should menu provide and how will be mapped options to the functions.
      Specified by:
      defineMenu in interface Page
    • add

      public void add()
      Processes input data and calls for creating of new patient in hospital system.
      Specified by:
      add in interface PersonnelMenu
    • edit

      public void edit()
      Processes input about patient and updates data for the patient with the provided id.
      Specified by:
      edit in interface PersonnelMenu
    • delete

      public void delete()
      Delete patient based on provided ID.
      Specified by:
      delete in interface PersonnelMenu
    • findById

      public void findById()
      Prints information about patient with provided ID.

      ID is provided via input data in class scanner.

      Specified by:
      findById in interface PersonnelMenu
    • all

      public void all()
      Prints all patients in the hospital system.
      Specified by:
      all in interface PersonnelMenu
    • printMenu

      public void printMenu()
      Description copied from interface: Page
      Shows menu options in terminal.
      Specified by:
      printMenu in interface Page
    • processMenu

      public void processMenu()
      Description copied from interface: Page
      Processes the user option based on page menu.
      Specified by:
      processMenu in interface Page
    • addOption

      protected void addOption(String text, Runnable action)
      Adds new option into the menu.
      Parameters:
      text - Text of the option.
      action - Action that will be called every time the option is selected.
    • end

      protected void end()
      Sets state of the menu to the end.
    • getOption

      public int getOption(int range)
      Processes input and returns extracted option.
      Parameters:
      range - Upper bound for not zero positive range of options, thus (0, range]
      Returns:
      First valid option in the input stream.
    • getPersonData

      public PersonData getPersonData(Person person)
      Processes input and extracts valid information into Person data wrapper.
      Parameters:
      person - Person whose data will be user as the default values.
      Returns:
      Wrapper containing data for Person creating (without id)
    • getPersonData

      public PersonData getPersonData()
      Processes input and extracts valid information into Person data wrapper.
      Returns:
      Person data wrapper containing data for person creation.
    • getPatientDetails

      public PatientsDetails getPatientDetails(Patient patient)
      Processes input and extracts valid information into patient details data wrapper.
      Parameters:
      patient - Patient object that will be used as default values.
      Returns:
      Patient details data wrapper.
    • getPatientDetails

      public PatientsDetails getPatientDetails()
      Processes input and extracts valid information into patient details data wrapper.
      Returns:
      Patient details data wrapper.
    • getDoctorDetails

      public DoctorDetails getDoctorDetails(Doctor doctor)
      Processes input and extracts valid information into doctors details data wrapper.
      Parameters:
      doctor - Doctor object that will be used as default values.
      Returns:
      Doctors details data wrapper.
    • getDoctorDetails

      public DoctorDetails getDoctorDetails()
      Processes input and extracts valid information into doctors details data wrapper.
      Returns:
      Doctor details data wrapper.
    • getQuestion

      public String getQuestion(String question)
      Returns question, where the default value is not present.
      Parameters:
      question - Text of the question.
      Returns:
      question, where the default value is not present.
    • getQuestion

      public String getQuestion(String question, String defaultValue)
      Returns question, where will be displayed default value.
      Parameters:
      question - Text of the question.
      defaultValue - Default value for the question.
      Returns:
      Question, where will be displayed default value.
    • clearConsole

      public void clearConsole()
      Clears console with appropriate command based on OS
    • getInteger

      public int getInteger(String question)
      Processes input and extracts first valid integer.
      Parameters:
      question - Question with which will be user prompted.
      Returns:
      Valid integer.
    • getString

      public String getString(String question, String defaultValue)
      Processes input and extracts first not empty line.
      Parameters:
      question - Question with which will be user prompted.
      defaultValue - Default value that will be suggested to the user.
      Returns:
      Not empty string.
    • getString

      public String getString(String question)
      Processes input and extracts first not empty line.
      Parameters:
      question - Question with which will be user prompted.
      Returns:
      First not empty line.
    • getDate

      public LocalDate getDate(String question, LocalDate defaultValue)
      Processes input and extracts first line containing valid date (in format YYYY-MM-DD)
      Parameters:
      question - Question with which will be user prompted.
      defaultValue - Default value that will be suggested to the user.
      Returns:
      LocalDate object containing valid date.
    • getDate

      public LocalDate getDate(String question)
      Processes input and extracts first line containing valid date (int format YYYY-MM-DD)
      Parameters:
      question - Question with which will be user prompted.
      Returns:
      LocalDate object containing valid date.
    • getDateTime

      public LocalDateTime getDateTime(String question)
      Processes input and extracts first line containing valid date and time.

      (in format YYYY-MM-DDTHH:MM or YYYY-MM-DD HH:MM)

      Parameters:
      question - Question with which will be user prompted.
      Returns:
      LocalDateTime object containing valid date and time.
    • createNew

      public boolean createNew(String what)
      Checks whether the user wants to create new object.
      Parameters:
      what - The object in question.
      Returns:
      Whether the user wants to create new object.
    • getBool

      public boolean getBool(String question)
      Processes input from scanner and returns value after processing first line that contains some text that can be converted to bool value.
      Parameters:
      question - Question with which will be user prompted.
      Returns:
      Value after processing first line that contains some text that can be converted to bool value.
    • waitForEnter

      public void waitForEnter()
      Show waiting text and prompts user into pressing any key.
    • printAndWait

      public void printAndWait(String text)
      Prints text and wait for the confirmation action from the user.
      Parameters:
      text - Text that will be displayed.
    • processPacketStatus

      public boolean processPacketStatus(GeneralPacket packet)
      Processes packet status and prints the resolved status.
      Parameters:
      packet - Packet that will be processed.
      Returns:
      Whether the packet came from successful API request.
    • processPacketStatusInSilence

      public boolean processPacketStatusInSilence(GeneralPacket packet)
      Processes packet status and prints the status if the API request was not successful.
      Parameters:
      packet - Packet that will be processed.
      Returns:
      Whether the packet came from successful API request.