示例#1
0
 def search_departments_having_patients_with_a_certain_age(self):
     repo1 = DepartmentsRepository()
     department1 = Departments(1, "flu", 4)
     department2 = Departments(2, "Zika", 3)
     department3 = Departments(3, "coma", 1)
     repo1.add_department(department1)
     repo1.add_department(department2)
     repo1.add_department(department3)
     repo2 = PatientRepository()
     patient1 = Patients("A", "E", 1991115, "flu")
     patient2 = Patients("B", "C", 2344509, "flu")
     patient3 = Patients("A", "A", 2000001, "flu")
     patient4 = Patients("E", "G", 3099809, "Zika")
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     repo2.add_patient(patient3)
     repo2.add_patient(patient4)
     repo1.add_patients_to_department(repo2, department1)
     repo1.add_patients_to_department(repo2, department2)
     repo1.add_patients_to_department(repo2, department3)
     l = repo1.search_departments_having_patients_with_a_certain_age(30)
     try:
         if l[0] == department1 and l[1] == department2:
             assert True
     except Exception as ex:
         assert False
示例#2
0
 def test_sort_departments_and_patients_alphabetically(self):
     repo1 = DepartmentsRepository()
     department1 = Departments(1, "flu", 4)
     department2 = Departments(2, "Zika", 3)
     department3 = Departments(3, "coma", 1)
     repo1.add_department(department1)
     repo1.add_department(department2)
     repo1.add_department(department3)
     repo2 = PatientRepository()
     patient1 = Patients("A", "E", 1991115, "flu")
     patient2 = Patients("B", "C", 2344509, "flu")
     patient3 = Patients("A", "A", 2000001, "flu")
     patient4 = Patients("E", "G", 3099809, "Zika")
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     repo2.add_patient(patient3)
     repo2.add_patient(patient4)
     repo1.add_patients_to_department(repo2, department1)
     repo1.add_patients_to_department(repo2, department2)
     repo1.add_patients_to_department(repo2, department3)
     repo1.sort_patients_from_department_by_age(15)
     try:
         l = department1.get_patients().get_all()
         if l[0] == patient3 and l[1] == patient1 and l[2] == patient2:
             assert True
     except Exception as ex:
         assert False
示例#3
0
 def test_search_departments_having_patients_with_a_given_name(self):
     repo1 = DepartmentsRepository()
     department1 = Departments(1, "flu", 4)
     department2 = Departments(2, "Zika", 3)
     department3 = Departments(3, "coma", 1)
     repo1.add_department(department1)
     repo1.add_department(department2)
     repo1.add_department(department3)
     repo2 = PatientRepository()
     patient1 = Patients("Alexandru", "Elena", 1991115, "flu")
     patient2 = Patients("Bexan", "Cmm", 2344509, "flu")
     patient3 = Patients("A", "A", 2000001, "flu")
     patient4 = Patients("Alexandru", "G", 3099809, "Zika")
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     repo2.add_patient(patient3)
     repo2.add_patient(patient4)
     repo1.add_patients_to_department(repo2, department1)
     repo1.add_patients_to_department(repo2, department2)
     repo1.add_patients_to_department(repo2, department3)
     l = repo1.search_departments_having_patients_with_a_given_name(
         "Alexandru")
     try:
         if l[0] == department1 and l[1] == department2:
             assert True
     except Exception:
         assert False
示例#4
0
 def test_sort_departments_by_number_of_patients(self):
     repo1 = DepartmentsRepository()
     department1 = Departments(1, "flu", 4)
     department2 = Departments(2, "Zika", 3)
     department3 = Departments(3, "coma", 1)
     repo1.add_department(department1)
     repo1.add_department(department2)
     repo1.add_department(department3)
     repo2 = PatientRepository()
     patient1 = Patients("A", "B", 111, "flu")
     patient2 = Patients("B", "C", 234, "flu")
     patient3 = Patients("C", "D", 2, "flu")
     patient4 = Patients("E", "G", 3, "Zika")
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     repo2.add_patient(patient3)
     repo2.add_patient(patient4)
     repo1.add_patients_to_department(repo2, department1)
     repo1.add_patients_to_department(repo2, department2)
     repo1.add_patients_to_department(repo2, department3)
     repo1.sort_departments_by_number_of_patients()
     try:
         l = repo1.get_all_departments()
         if l[0] == department3 and l[1] == department2 and l[
                 2] == department1:
             assert True
     except Exception as ex:
         assert False
示例#5
0
 def test_get_index_by_PNC(self):
     repo = PatientRepository()
     patient1 = Patients("K", "J", 324, "flu")
     patient2 = Patients("L", "R", 2221, "Zika")
     patient3 = Patients("L", "P", 1209, "Yellow fever")
     repo.add_patient(patient1)
     repo.add_patient(patient2)
     repo.add_patient(patient3)
     self.assertEqual(repo.get_index_by_PNC(patient1.get_PNC()), 0)
示例#6
0
 def test_delete_all_patients(self):
     repo = PatientRepository()
     patient1 = Patients("A", "AA", 111, "flu")
     patient2 = Patients("B", "BB", 124, "flu")
     patient3 = Patients("C", "L", 90, "Zika")
     repo.add_patient(patient1)
     repo.add_patient(patient2)
     repo.add_patient(patient3)
     repo.delete_all_patients()
     self.assertEqual(repo.get_size(), 0)
示例#7
0
 def test_delete_a_patient(self):
     repo = PatientRepository()
     patient1 = Patients("K", "J", 324, "flu")
     patient2 = Patients("L", "R", 2221, "Zika")
     patient3 = Patients("L", "P", 1209, "Yellow fever")
     repo.add_patient(patient1)
     repo.add_patient(patient2)
     repo.add_patient(patient3)
     repo.delete_a_patient_by_index(0)
     self.assertEqual(repo.get_size(), 2)
示例#8
0
 def test_get_size(self):
     repo1 = DepartmentsRepository()
     repo2 = PatientRepository()
     patient1 = Patients("G", "K", 111, "flu")
     patient2 = Patients("R", "R", 112, "coma")
     department1 = Departments(1, "flue", 4)
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     department1.set_patients(repo2)
     repo1.add_department(department1)
     self.assertEqual(repo1.get_size_department(), 1)
示例#9
0
 def test_add_patients_to_department(self):
     repo1 = PatientRepository()
     patient1 = Patients("G", "K", 111, "flu")
     patient2 = Patients("R", "R", 112, "coma")
     patient3 = Patients("A", "B", 1344, "flu")
     repo1.add_patient(patient1)
     repo1.add_patient(patient2)
     repo1.add_patient(patient3)
     department = Departments(1, "flu", 4)
     repo2 = DepartmentsRepository()
     repo2.add_department(department)
     repo2.add_patients_to_department(repo1, department)
     self.assertEqual(department.get_patients().get_size(), 2)
示例#10
0
 def test_get_patients_with_same_disease(self):
     repo = PatientRepository()
     patient1 = Patients("K", "J", 324, "flu")
     patient2 = Patients("L", "R", 2221, "Zika")
     patient3 = Patients("L", "P", 1209, "Yellow fever")
     patient4 = Patients("A", "B", 10101, "flu")
     repo.add_patient(patient1)
     repo.add_patient(patient2)
     repo.add_patient(patient3)
     repo.add_patient(patient4)
     l = []
     l.append(patient1)
     l.append(patient4)
     self.assertEqual(repo.get_patients_with_the_same_disease("flu"), l)
    def add_patients_to_department(self, patients, department):
        """

        :param patients: a parameter of type PatientsRepository
        :param department: a parameter of type department read by the user
        """
        i = self.get_index(department)
        if 0 > i > self.get_size_department():
            raise ValueError("The department does not exist")
        p = PatientRepository()
        p.delete_all_patients()
        for el in patients.get_all():
            p.add_patient(el)
        self.__department[i].set_patients(p)
示例#12
0
 def test_get_patients_from_department(self):
     repo1 = DepartmentsRepository()
     department1 = Departments(1, "flu", 4)
     repo1.add_department(department1)
     repo2 = PatientRepository()
     patient1 = Patients("A", "B", 111, "flu")
     patient2 = Patients("B", "C", 234, "flu")
     patient3 = Patients("C", "D", 2, "flu")
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     repo2.add_patient(patient3)
     repo1.add_patients_to_department(repo2, department1)
     self.assertEqual(
         repo1.get_patients_from_department(department1).get_size(), 3)
示例#13
0
 def test_update_patient_by_PNC(self):
     repo = PatientRepository()
     patient1 = Patients("K", "J", 324, "flu")
     patient2 = Patients("L", "R", 2221, "Zika")
     patient3 = Patients("L", "P", 1209, "Yellow fever")
     repo.add_patient(patient1)
     repo.add_patient(patient2)
     repo.add_patient(patient3)
     patient4 = Patients("K", "AA", 2221, "...")
     repo.update_patient_by_PNC(patient4, 2221)
     try:
         if patient1 == patient4:
             assert True
     except Exception as ex:
         assert False
示例#14
0
 def test_get_patient_by_name(self):
     repo = PatientRepository()
     patient1 = Patients("K", "J", 324, "flu")
     patient2 = Patients("L", "R", 2221, "Zika")
     patient3 = Patients("L", "P", 1209, "Yellow fever")
     repo.add_patient(patient1)
     repo.add_patient(patient2)
     repo.add_patient(patient3)
     l = []
     l.append(patient3)
     self.assertEqual(repo.get_patient_by_name("L", "P"), l)
     try:
         self.assertEqual(repo.get_patient_by_name("A", "B"), patient2)
         assert False
     except Exception as ex:
         assert True
示例#15
0
 def test_add_department(self):
     repo1 = DepartmentsRepository()
     repo2 = PatientRepository()
     patient1 = Patients("G", "K", 111, "flu")
     patient2 = Patients("R", "R", 112, "coma")
     department1 = Departments(1, "flue", 4)
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     department1.set_patients(repo2)
     repo1.add_department(department1)
     department2 = Departments(1, "flu", 5)
     try:
         repo1.add_department(department2)
         assert False
     except Exception as ex:
         assert True
     self.assertEqual(repo1.get_size_department(), 1)
示例#16
0
 def test_sort_patients_by_PNC(self):
     repo1 = DepartmentsRepository()
     department1 = Departments(1, "flu", 4)
     repo1.add_department(department1)
     repo2 = PatientRepository()
     patient1 = Patients("A", "B", 111, "flu")
     patient2 = Patients("B", "C", 234, "flu")
     patient3 = Patients("C", "D", 2, "flu")
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     repo2.add_patient(patient3)
     repo1.add_patients_to_department(repo2, department1)
     repo1.sort_patients_by_PNC(department1)
     try:
         l = department1.get_patients()
         if l.get_patient_by_index(0) == patient3 and l.get_patient_by_index(
                 1) == patient1 and l.get_patient_by_index(2) == patient2:
             assert True
     except Exception as ex:
         assert False
示例#17
0
 def test_back(self):
     repo1 = DepartmentsRepository()
     department1 = Departments(1, "flu", 4)
     department2 = Departments(2, "Zika", 3)
     department3 = Departments(3, "coma", 1)
     repo1.add_department(department1)
     repo1.add_department(department2)
     repo1.add_department(department3)
     repo2 = PatientRepository()
     patient1 = Patients("A", "E", 1991115, "flu")
     patient2 = Patients("B", "C", 2344509, "flu")
     patient3 = Patients("A", "A", 2000001, "flu")
     patient4 = Patients("E", "G", 3099809, "Zika")
     patient5 = Patients("Chira", "Maira", 83284289, "flu")
     patient6 = Patients("Anca", "Grad", 1111111, "flu")
     patient7 = Patients("Lolea", "Oana", 2345678, "flu")
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     repo2.add_patient(patient3)
     repo1.add_patients_to_department(repo2, department1)
     repo1.add_patients_to_department(repo2, department2)
     repo1.add_patients_to_department(repo2, department3)
    def sort_departments_and_patients_alphabetically(self):
        """
        this function sorts the departments by their number of patients and also sorts the patients alphabetically
        """
        self.sort_departments_by_number_of_patients()

        def f(x, y):
            if x.get_first_name() == y.get_first_name():
                if x.get_last_name() < y.get_last_name():
                    return True
                return False
            else:
                if x.get_first_name() < y.get_first_name():
                    return True
                return False

        for i in range(self.get_size_department()):
            l = self.__department[i].get_patients().get_all()
            l = utils.my_sort(l, f)
            repo = PatientRepository()
            for el in l:
                repo.add_patient(el)
            self.__department[i].set_patients(repo)
    def sort_patients_by_PNC(self, department):
        """

        :param department: a Department type parameter where the sorting will take place
        :return: a boolean value if the condition is satisfied in the locally defined function f
        """
        i = self.get_index(department)
        if 0 > i > self.get_size_department():
            raise ValueError("The department does not exist")

        def f(x, y):
            if x.get_PNC() < y.get_PNC():
                return True
            return False

        l = []
        for el in self.__department[i].get_patients().get_all():
            l.append(el)
        l = utils.my_sort(l, f)
        repo = PatientRepository()
        for el in l:
            repo.add_patient(el)
        self.__department[i].set_patients(repo)
示例#20
0
 def test_get_a_certain_patient_from_department(self):
     repo1 = DepartmentsRepository()
     department1 = Departments(1, "flue", 4)
     repo1.add_department(department1)
     repo2 = PatientRepository()
     patient1 = Patients("A", "B", 111, "flu")
     patient2 = Patients("B", "C", 234, "flu")
     patient3 = Patients("C", "D", 2, "flu")
     patient4 = Patients("L", "K", 0, "Zika")
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     repo2.add_patient(patient3)
     repo1.add_patients_to_department(repo2, department1)
     self.assertEqual(
         repo1.get_a_certain_patient_from_department_by_PNC(
             department1, patient4), "The patient does not exist")
     try:
         self.assertEqual(
             repo1.get_a_certain_patient_from_department_by_PNC(
                 department1, patient1), patient4)
         assert False
     except Exception as ex:
         assert True
示例#21
0
 def test_delete_patients_with_a_given_disease(self):
     repo = PatientRepository()
     patient1 = Patients("K", "J", 324, "flu")
     patient2 = Patients("L", "R", 2221, "Zika")
     patient3 = Patients("L", "P", 1209, "Yellow fever")
     patient4 = Patients("R", "TT", 362, "flu")
     patient5 = Patients("p", "ZZ", 1010, "flu")
     repo.add_patient(patient1)
     repo.add_patient(patient2)
     repo.add_patient(patient3)
     repo.add_patient(patient4)
     repo.add_patient(patient5)
     repo.delete_patients_with_a_given_disease("flu")
     self.assertEqual(repo.get_size(), 2)
示例#22
0
 def test_delete_patients_from_a_given_interval(self):
     repo = PatientRepository()
     patient1 = Patients("A", "AA", 111, "flu")
     patient2 = Patients("B", "BB", 124, "flu")
     patient3 = Patients("C", "L", 90, "Zika")
     patient4 = Patients("D", "C", 10101, "Denger fever")
     patient5 = Patients("E", "E", 9101, "Zika")
     repo.add_patient(patient1)
     repo.add_patient(patient2)
     repo.add_patient(patient3)
     repo.add_patient(patient4)
     repo.add_patient(patient5)
     repo.delete_patients_from_a_given_interval(1, 3)
     self.assertEqual(repo.get_size(), 2)
示例#23
0
 def test_update_department_by_index(self):
     repo1 = DepartmentsRepository()
     department1 = Departments(1, "flu", 4)
     repo1.add_department(department1)
     repo2 = PatientRepository()
     patient1 = Patients("A", "B", 111, "flu")
     patient2 = Patients("B", "C", 234, "flu")
     patient3 = Patients("C", "D", 2, "flu")
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     repo2.add_patient(patient3)
     department2 = Departments(2, "Zika", 3)
     patient4 = Patients("L", "M", 908, "Zika")
     repo2.add_patient(patient4)
     repo1.update_department_by_index(department2, 0)
     self.assertEqual(department1, department2)
示例#24
0
 def test_update_patients_from_department(self):
     repo1 = DepartmentsRepository()
     department1 = Departments(1, "flue", 4)
     repo1.add_department(department1)
     repo2 = PatientRepository()
     patient1 = Patients("A", "B", 111, "flu")
     patient2 = Patients("B", "C", 234, "flu")
     patient3 = Patients("C", "D", 2, "flu")
     patient4 = Patients("L", "K", 0, "Zika")
     repo2.add_patient(patient1)
     repo2.add_patient(patient2)
     repo2.add_patient(patient3)
     repo2.delete_all_patients()
     repo2.add_patient(patient4)
     repo1.update_patients_from_department(department1, repo2)
     self.assertEqual(department1.get_patients().get_size(), 0)
示例#25
0
 def test_add_patient(self):
     repo = PatientRepository()
     patient1 = Patients("K", "J", 324, "flu")
     repo.add_patient(patient1)
     self.assertEqual(repo.get_size(), 1)
示例#26
0
 def test_add_new_disease(self):
     repo = PatientRepository()
     patient1 = Patients("K", "A", 2121, "flu")
     repo.add_patient(patient1)
     repo.add_new_disease("Zika", patient1)
     self.assertEqual(patient1.get_disease(), "flu, Zika")
示例#27
0
 def test_update_disease(self):
     repo = PatientRepository()
     patient1 = Patients("A", "B", 101, "flu")
     repo.add_patient(patient1)
     repo.update_disease("Zika", patient1)
     self.assertEqual(patient1.get_disease(), "Zika")
示例#28
0
class Departments:
    def __init__(self, id, name, number_of_beds):
        self.__id = id
        self.__name = name
        self.__number_of_beds = number_of_beds
        self.__patients = PatientRepository()

    def get_id(self):
        return self.__id

    def get_name(self):
        return self.__name

    def get_number_of_beds(self):
        return self.__number_of_beds

    def get_patients(self):
        return self.__patients

    def set_id(self, id):
        self.__id = id

    def set_name(self, name):
        self.__name = name

    def set_number_of_beds(self, number_of_beds):
        self.__number_of_beds = number_of_beds

    def set_patients(self, other):
        for el in other.get_all():
            if el.get_disease() == self.get_name() and not (
                    el in self.__patients.get_all()):
                self.__patients.add_patient(el)

    def __str__(self):
        s = ""
        if self.get_patients() == []:
            l = self.get_patients()
            if len(l) != 0:
                s += "The department of ID " + str(self.get_id(
                )) + ", which serves people suffering from " + self.get_name(
                ) + ", having " + str(self.get_number_of_beds(
                )) + " beds has the following patients: " + "\n"
                for i in range(len(l)):
                    s += "\t" + str(l[i]) + "\n"
            else:
                s += "The department of ID " + str(self.get_id(
                )) + ", which serves people suffering from " + self.get_name(
                ) + ", having " + str(self.get_number_of_beds(
                )) + " beds, currently has no patients. " + "\n"
        else:
            l = self.get_patients()
            if l.get_size() != 0:
                s += "The department of ID " + str(self.get_id(
                )) + ", which serves people suffering from " + self.get_name(
                ) + ", having " + str(self.get_number_of_beds(
                )) + " beds has the following patients: " + "\n"
                for i in range(l.get_size()):
                    s += "\t" + str(l.get_patient_by_index(i)) + "\n"
            else:
                s += "The department of ID " + str(self.get_id(
                )) + ", which serves people suffering from " + self.get_name(
                ) + ", having " + str(self.get_number_of_beds(
                )) + " beds, currently has no patients. " + "\n"
        return s

    def __eq__(self, other):
        if self.get_id() == other.get_id():
            return True
        return False
示例#29
0
from infrastructure.repository1 import DepartmentsRepository, Departments
from infrastructure.repository2 import PatientRepository, Patients
from application.controller import Controller
from UI.console import UI
repo1 = DepartmentsRepository()
repo2 = PatientRepository()
ctrl = Controller(repo1, repo2)
patient1 = Patients("Jack", "Daniel", 1991115, "flu")
patient2 = Patients("Peter", "Sunny", 2657809, "ADHD")
patient3 = Patients("Angelina", "Mercy", 2090807, "flu")
patient4 = Patients("Joco", "Opra", 2578887, "Alzheimer")
patient5 = Patients("Alex", "Normand", 1009898, "flu")
patient6 = Patients("Thea", "Mico", 5890798, "ADHD")
repo2.add_patient(patient1)
repo2.add_patient(patient2)
repo2.add_patient(patient3)
repo2.add_patient(patient4)
repo2.add_patient(patient5)
repo2.add_patient(patient6)
department1 = Departments(1, "flu", 210)
department2 = Departments(2, "ADHD", 110)
department3 = Departments(3, "Alzheimer", 50)
department4 = Departments(4, "diabetes", 150)
repo1.add_department(department1)
repo1.add_department(department2)
repo1.add_department(department3)
repo1.add_department(department4)
ui = UI(ctrl)
ui.StartMenu()