Class Database

java.lang.Object
cz.cuni.kubinja.hospitalsystem.database.Database

public class Database extends Object
Interface for communication with SQLite database from Hospital system request.
  • Constructor Details

    • Database

      public Database(String url) throws DatabaseException
      Connects to the databased located on provided url and check whether the database has correct structure. If not then creates missing tables.
      Parameters:
      url - Location of the database.
      Throws:
      DatabaseException - Errors connected to the unability to open/create database.
  • Method Details

    • getPerson

      public List<Person> getPerson(String fistName, String lastName, String expectedType) throws DatabaseException
      Returns list of people with provided first name and last name.
      Parameters:
      fistName - First name of the person.
      lastName - Last name of the person.
      expectedType - Kind of the person which will help filter out invalid combinations.
      Returns:
      List of people with provided first name and last name.
      Throws:
      DatabaseException - Error connected with the failure of retrieving people from database.
    • addPatient

      public Patient addPatient(PatientData patientData) throws DatabaseException
      Adds patients into the database.
      Parameters:
      patientData - Patients data which will be used for entry creation.
      Returns:
      Patient object matching with the patient that was stored in database.
      Throws:
      DatabaseException - Errors connected with the unability of storing new patient.
    • updatePatient

      public void updatePatient(Patient patient) throws DatabaseException
      Updates patient data inside the database.
      Parameters:
      patient - Patient that will be updated.
      Throws:
      DatabaseException - Errors connected with the inability of update patient's data.
    • deletePatient

      public void deletePatient(int id) throws DatabaseException
      Deletes patient from the database.
      Parameters:
      id - Identification number of patient.
      Throws:
      DatabaseException - Error connected with the inability of deleting patient from database. Such as ID does not exist or connection errors.
    • getPatient

      public Patient getPatient(int id) throws DatabaseException
      Returns patient based on provided id.
      Parameters:
      id - Id of the patient we want to retrieve from database.
      Returns:
      patient based on provided id.
      Throws:
      DatabaseException - Error connected with the unability to successfully retrieve patients data from database.
    • getPatient

      public Patient getPatient(Connection connection, int id) throws DatabaseException
      Returns patient based on provided id.
      Parameters:
      connection - Connection to the database.
      id - Id of the patient we want to retrieve from database.
      Returns:
      patient based on provided id.
      Throws:
      DatabaseException - Error connected with the unability to successfully retrieve patients data from database.
    • getAllPatients

      public List<Patient> getAllPatients() throws DatabaseException
      Returns all patients in the database.
      Returns:
      list of all patients in the database.
      Throws:
      DatabaseException - Error connected to the failure of retrieving all patients from the database.
    • addDoctor

      public Doctor addDoctor(DoctorData doctorData) throws DatabaseException
      Adds doctor into the database.
      Parameters:
      doctorData - Doctor data that will be stored in the database.
      Returns:
      Doctor matching with the doctor entry stored in database.
      Throws:
      DatabaseException - Error connected to the failure of storing new doctor in database.
    • updateDoctor

      public void updateDoctor(Doctor doctor) throws DatabaseException
      Updates doctor information inside the database.
      Parameters:
      doctor - Doctor that will be updated.
      Throws:
      DatabaseException - Errors connected with the failure of updating doctor's data. Such as doctor was not present inside the database or connection errors.
    • deleteDoctor

      public void deleteDoctor(int id) throws DatabaseException
      Deletes doctor from the database.
      Parameters:
      id - Identification number of the doctor.
      Throws:
      DatabaseException - Error connected with the failure of deleting doctor from database. Such as doctor was not present inside the database or connection errors.
    • getAllDoctors

      public List<Doctor> getAllDoctors() throws DatabaseException
      Returns list of all doctors in the database.
      Returns:
      List of all doctors in the database.
      Throws:
      DatabaseException - Error connected with the failure of retrieving all doctors from the database - connection errors.
    • getDoctor

      public Doctor getDoctor(int id) throws DatabaseException
      Returns Doctor with corresponding id.
      Parameters:
      id - Id of the doctor.
      Returns:
      Doctor with corresponding id.
      Throws:
      DatabaseException - Error connected with failure of retrieving doctor from database.
    • getDoctor

      public Doctor getDoctor(Connection connection, int id) throws DatabaseException
      Returns Doctor with corresponding id.
      Parameters:
      connection - Connection to the database.
      id - Id of the doctor.
      Returns:
      Doctor with corresponding id.
      Throws:
      DatabaseException - Error connected with failure of retrieving doctor from database.
    • checkAndAddAppointment

      public void checkAndAddAppointment(AppointmentData appointmentData) throws DatabaseException, CalendarException
      Checks the provided appointment data and adds the new appointments into the database.
      Parameters:
      appointmentData - Information about the appointment.
      Throws:
      DatabaseException - Error connected to the failure of storing appointment into the database.
      CalendarException - Error connected to the invalid time intervals of appointment.
    • getAppointment

      public Appointment getAppointment(int id) throws DatabaseException
      Returns the appointment based on provided id.
      Parameters:
      id - Identification number of the appointment.
      Returns:
      Appointment based on provided id.
      Throws:
      DatabaseException - Error connected to the failure of retrieving appointment from the database. No such appointment with id is present in the database or connection errors.
    • deleteAppointment

      public void deleteAppointment(int id) throws DatabaseException
      Deletes appointment from the database based on provided id.
      Parameters:
      id - Identification number of the appointment.
      Throws:
      DatabaseException - Error connected to the failure of deleting appointment from the database. No such appointment with id is present in the database or connection errors.
    • updateAppointment

      public void updateAppointment(Appointment appointment) throws DatabaseException
      Updates information about existing appointment.
      Parameters:
      appointment - Appointment data that will be used for updating.
      Throws:
      DatabaseException - Failure of updating data inside database. Invalid identifiers or connection errors.
    • getAppointmentsForPatient

      public List<Appointment> getAppointmentsForPatient(int id) throws DatabaseException
      Returns list of appointments for patient with provided id.
      Parameters:
      id - Identification number of the patient.
      Returns:
      List of appointments for patient.
      Throws:
      DatabaseException - Error connected with the connection to the database.
    • getAppointmentsForPatient

      public List<Appointment> getAppointmentsForPatient(Connection connection, int id) throws DatabaseException
      Returns list of appointments for patient with provided id.
      Parameters:
      connection - Connection to the database.
      id - Identification number of the patient.
      Returns:
      List of appointments for patient.
      Throws:
      DatabaseException - Error connected with the connection to the database.
    • getAppointmentsForDoctor

      public List<Appointment> getAppointmentsForDoctor(int id) throws DatabaseException
      Returns list of appointments for doctor with provided id.
      Parameters:
      id - Identification number of the doctor.
      Returns:
      List of appointments for doctor with provided id.
      Throws:
      DatabaseException - Error connected with the connection to the database.
    • getAppointmentsForDoctor

      public List<Appointment> getAppointmentsForDoctor(Connection connection, int id) throws DatabaseException
      Returns list of appointments for doctor with provided id.
      Parameters:
      connection - Connection to the database.
      id - Identification number of the doctor.
      Returns:
      List of appointments for doctor with provided id.
      Throws:
      DatabaseException - Error connected with the connection to the database.
    • getCalendar

      public Calendar getCalendar() throws DatabaseException
      Returns calendar object representing all appointments in the database.
      Returns:
      Calendar object representing all appointments.
      Throws:
      DatabaseException - Error connected to the failure of retrieving data from database or connection errors.
    • deleteAllData

      public void deleteAllData() throws DatabaseException
      Deletes all data from database.

      Created for the purpose of unit tests to ensure same starting point for all tests.

      Throws:
      DatabaseException - Error connected to the failure of deletion of data from database.