Ejemplo n.º 1
0
def to_object(eligible_nurses, assignments):
    """ Turn nurses into objects.
        We also consider the amount of patients a nurse has in a while loop here.
        For the very first patient, nurses do not have any patients assigned to them,
        therefore all eligible nurses are considered when it comes to assigning.

        When it comes to near the end of the patients list, we have nurses who have
        already been assigned to a patient. There is a chance that all nurses who
        meet hard constraints are already assigned. If so, we then consider nurses
        who have 1 patient, then 2 patients, and so on up to 3."""
    eligible_nurse_objects = []
    i = 0
    while len(eligible_nurse_objects) < 1 and i < 3:
        for row in eligible_nurses:
            # if nurse assigned
            if row[0] in assignments:
                # if nurse has i patients (we use this if our eligible nurses are all assigned. Then we
                # resort to assigning nurses with more than 1 patient)
                if assignments[row[0]]["num_patients"] == i:
                    x = Nurse(row[0], row[1], row[2], row[3], row[4], row[5],
                              row[6], row[7], row[8], row[9], row[10], row[11],
                              row[12], row[13], row[14], row[15], row[16])
                    eligible_nurse_objects.append(x)
            # if nurse is not assigned
            elif row[0] not in assignments:
                x = Nurse(row[0], row[1], row[2], row[3], row[4], row[5],
                          row[6], row[7], row[8], row[9], row[10], row[11],
                          row[12], row[13], row[14], row[15], row[16])
                eligible_nurse_objects.append(x)
        # for the next iteration, start considering nurses with i += 1 patients.
        if len(eligible_nurse_objects) < 1:
            i += 1
    return eligible_nurse_objects, assignments
Ejemplo n.º 2
0
 def test_invalid_fte(self):
     """fte"""
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, None, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, -1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
Ejemplo n.º 3
0
    def setUp(self):
        """ creates a test fixture before each test method has run """
        self.nurse = Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True,
                           False, "charge", "previous", "dta", "comment", True,
                           True)

        self.long_str = ""
        for i in range(260):
            self.long_str += "a"
Ejemplo n.º 4
0
 def test_invalid_advanced_role(self):
     """advanced_role"""
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False, 1,
               "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
               self.long_str, "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False, None,
               "previous", "dta", "comment", True, True)
Ejemplo n.º 5
0
 def test_invalid_rotation(self):
     """rotation"""
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, 1, 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, self.long_str, 5, 1.1, 0, True, True,
               False, "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, None, 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
Ejemplo n.º 6
0
 def test_invalid_clinical_area(self):
     """clinical_area"""
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", 1, 7, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "AB", 7, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", None, 7, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
Ejemplo n.º 7
0
 def test_invalid_id(self):
     """id"""
     with self.assertRaises(ValueError):
         Nurse("12", "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(-2, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(None, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
Ejemplo n.º 8
0
 def test_invalid_group(self):
     """group"""
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", "5", 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", None, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", -1, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
Ejemplo n.º 9
0
 def test_invalid_name(self):
     """name"""
     with self.assertRaises(ValueError):
         Nurse(12, 12, "A", 7, "a", 5, 1.1, 0, True, True, False, "charge",
               "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, self.long_str, "A", 7, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, None, "A", 7, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
Ejemplo n.º 10
0
 def test_invalid_comments(self):
     """comments"""
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", 1, True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", None, True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", self.long_str, True, True)
Ejemplo n.º 11
0
    def __init_medical_body(self):
        self.adm_doctors.append(AdmissionDoctor(1, 'Dr. Jonson', 'doctores_admision'))
        self.adm_doctors.append(AdmissionDoctor(2, 'Dra. Gina', 'doctores_admision'))

        self.eme_doctors.append(EmergencyDoctor(1, 'Dr. Sebastian'))
        self.eme_doctors.append(EmergencyDoctor(2, 'Dr. Kevin'))
        self.eme_doctors.append(EmergencyDoctor(3, 'Dra. Angie'))

        self.nurses.append(Nurse(1, 'Dr. Nicolas'))
        self.nurses.append(Nurse(2, 'Dra. Nicolas'))
        self.nurses.append(Nurse(3, 'Dra. Nicolas'))
        self.nurses.append(Nurse(4, 'Dra. Nicolas'))
        self.nurses.append(Nurse(5, 'Dra. Nicolas'))
Ejemplo n.º 12
0
 def test_invalid_bed_num(self):
     """bed_num"""
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", "7", "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", None, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", -1, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 15, "a", 5, 1.1, 0, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
Ejemplo n.º 13
0
def SwitchToRoleMenu():

    if (staff_role == "d"):
        doctor = Doctor(staff_name, staff_id)
        doctor.doctorMenu()
    elif (staff_role == "n"):
        nurse = Nurse(staff_name, staff_id)
        nurse.InitializeNurseMenu()
    elif (staff_role == "a"):
        admin = Admin(staff_name, staff_id)
        admin.AdminMenu()
    else:
        print("\nSomething went wrong please re-login")
    Login()
Ejemplo n.º 14
0
 def test_invalid_skill_level(self):
     """skill_level"""
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, "0", True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, None, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, -1, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 6, True, True, False,
               "charge", "previous", "dta", "comment", True, True)
Ejemplo n.º 15
0
    def test_nurse_multihandlers(self, fake_fs_connected, wait_exception,
                                 event_name):
        _a = False
        _b = False

        def handle_a(event):
            nonlocal _a
            _a = True

        def handle_b(event):
            nonlocal _b
            _b = True

        nurse = Nurse(run_circles=1000)
        if event_name.find('CUSTOM ') != -1:
            handler_name = event_name[event_name.find('CUSTOM ') +
                                      len('CUSTOM '):]
        else:
            handler_name = event_name
        nurse.set_event_handler(handler_name, handle_a)
        nurse.set_event_handler(handler_name, handle_b)
        nurse.subscribe(event_name)
        nurse.run()

        assert fake_fs_connected.is_set()
        assert _a ^ wait_exception
        assert _b ^ wait_exception
Ejemplo n.º 16
0
    def setUp(self):
        """ creates a test fixture before each test method has run """
        self.nurse = Nurse(12, "Jane", "Doe", "A", 7, 5, 0, False, False,
                           False, True)


# TDD is going greeeaaaaaattt
Ejemplo n.º 17
0
 def test_handler_detected_speech(self, fake_fs_connected, wait_exception,
                                  event_name, rabbitmq_proc):
     ds_handler = handlers.DetectedSpeechHandler()
     nurse = Nurse(run_circles=1000)
     nurse.set_event_handler(event_name, ds_handler)
     nurse.subscribe(event_name)
     nurse.run()
     # todo принять в RabbitMQ и потом проверить на наличие в очереди сообщение:
     """
    def __init__(self):
        super(CovidInvasion, self).__init__()

        pygame.init()
        self.settings = Settings()

        # self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        self.settings.screen_width = self.screen.get_rect().width
        self.settings.screen_height = self.screen.get_rect().height

        pygame.display.set_caption("COVID Invasion")

        self.nurse = Nurse(self)
        self.vaccines = pygame.sprite.Group()
        self.viruses = pygame.sprite.Group()

        self._create_fleet()
Ejemplo n.º 19
0
def grab_nurses():
    nurses = []

    cursor.execute("SELECT * FROM nurses WHERE current=True")
    nurse_list = cursor.fetchall()

    for row in nurse_list:
        x = Nurse(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11],
                         row[12], row[13], row[14], row[15], row[16], row[17], row[18])
        nurses.append(x)
    
    return nurses
Ejemplo n.º 20
0
def grab_nurses(nurses, assignments, cursor):
    """ Grabs all nurses who are currently on shift """
    cursor.execute("SELECT * FROM nurses WHERE current_shift=1")
    nurse_list = cursor.fetchall()

    # Turn them into an object
    for row in nurse_list:
        x = Nurse(row[0], row[1], row[2], row[3], row[4], row[5], row[6],
                  row[7], row[8], row[9], row[10], row[11], row[12], row[13],
                  row[14], row[15], row[16])
        nurses.append(x)
        # Initialize the assignments dict with all the nurses
        assignments[row[0]] = {'num_patients': 0, 'patients': [], 'prev_p': []}
    return nurses, assignments
Ejemplo n.º 21
0
 def getHospNurse(self):
     print('The nurse is: ', end="")
     nurse = Nurse()
     print(nurse.nurseName)
Ejemplo n.º 22
0
def main():
    patients = grab_patients()
    nurses = grab_nurses()

    assignments = {}

    # Pair previous patient with nurse. Assume that hard constraints are not checked
    for n in nurses:
        prev_p = n.get_previous_patients()
        prev_p_list = prev_p.split(",") # assume that prev_p is a comma separated list of patient IDs

        for p in patients:
            if p.get_id() == prev_p_list[-1]:
                if n.get_id() not in assignments:
                    assignments[n.get_id()]["num_patients"] = 0
                    assignments[n.get_id()]["patients"] = []

                assignments[n.get_id()]["num_patients"] += 1
                assignments[n.get_id()]["patients"].append(p.get_id())
                # set patient to be assigned
                p.set_assigned(True)

    # Get all nurses that are eligible for each patient
    for p in patients:
        if p.get_assigned != True:
            transfer = p.get_transfer()
            a_trained = p.get_a_trained()
            acuity = p.get_acuity()
            picc = p.get_picc()
            one_to_one = p.get_one_to_one()
            clinical_area = p.get_clinical_area()
            twin = p.get_twin()
            priority = p.get_priority()

            # get nurses that match the hard constraints
            sql_query = customize_sql(transfer, a_trained, acuity)
            cursor.execute(sql_query)
            eligible_nurses = cursor.fetchall()
            eligible_nurse_objects = []

            i = 0
            while len(eligible_nurse_objects) < 1 and i < 4:
                for row in eligible_nurses:
                    # if nurse assigned
                    if row[0] in assignments:
                        # if nurse has i patients (we use this if our eligible nurses are all assigned. Then we
                        # resort to assigning nurses with more than 1 patient)
                        if assignments[row[0]]["num_patients"] == i:
                            x = Nurse(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9],
                                      row[10], row[11], row[12], row[13], row[14], row[15], row[16], row[17], row[18])
                            eligible_nurse_objects.append(x)
                    # if nurse is not assigned
                    elif row[0] not in assignments:
                        x = Nurse(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9],
                                  row[10], row[11], row[12], row[13], row[14], row[15], row[16], row[17], row[18])
                        eligible_nurse_objects.append(x)
                # for the next iteration, start considering nurses with i += 1 patients.
                if len(eligible_nurse_objects) < 1:
                    i += 1


            nurse_weights = {}
            max_points = 0


            for eno in eligible_nurse_objects:
                if eno.get_id() not in nurse_weights:
                    nurse_weights[eno.get_id()] = 0

                # if nurse matches clinical area, give nurse 4 points
                if eno.get_clinical_area() == clinical_area:
                    nurse_weights[eno.get_id()] += 4

                # if nurse matches picc, give nurse 3 points
                if eno.get_picc() == picc:
                    nurse_weights[eno.get_id()] += 3

                # if nurse matches priority, give nurse 2 points
                if eno.get_priority() == priority:
                    nurse_weights[eno.get_id()] += 2
                
                if nurse_weights[eno.get_id()] > max_points:
                    max_points = nurse_weights[eno.get_id()]

            eligible_max_nurses = []

            for eno in eligible_nurse_objects:
                if nurse_weights[eno.get_id()] == max_points:
                    eligible_max_nurses.append(eno.get_id())
            
            # algorithm that matches nurse to patient starting from lowest skill level
            sorted_eligible_nurses = sorted(eligible_nurse_objects, key=lambda x: x.skill_level, reverse=False)

            for sen in sorted_eligible_nurses:
                if sen.get_id() in eligible_max_nurses:
                    if sen.get_id() not in assignments:
                        assignments[sen.get_id()]["num_patients"] = 0
                        assignments[sen.get_id()]["patients"] = []

                    assignments[sen.get_id()]["num_patients"] += 1
                    assignments[sen.get_id()]["patients"].append(p.get_id())
                    # set patient to be assigned
                    p.set_assigned(True)

            # We haven't iterated by num_patients yet
            # 1:1 can be overridden when we run out of nurses

            print(eligible_nurses)
Ejemplo n.º 23
0
def test_nurse_connection_exception():
    with pytest.raises(Exception) as exc_info:
        nurse = Nurse('127.0.0.1', 8021, 'ClueCon', -1)
        assert 'Connection to FreeSWITCH failed!' in str(exc_info.value)
Ejemplo n.º 24
0
 def test_nurse_connection(self, fake_fs_connected):
     nurse = Nurse('127.0.0.1', 8021, 'ClueCon', 1000)
     assert fake_fs_connected.is_set()
class CovidInvasion(object):
    """Overall class to manage game assets and behavior"""
    def __init__(self):
        super(CovidInvasion, self).__init__()

        pygame.init()
        self.settings = Settings()

        # self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
        self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        self.settings.screen_width = self.screen.get_rect().width
        self.settings.screen_height = self.screen.get_rect().height

        pygame.display.set_caption("COVID Invasion")

        self.nurse = Nurse(self)
        self.vaccines = pygame.sprite.Group()
        self.viruses = pygame.sprite.Group()

        self._create_fleet()

    def _create_fleet(self):
        """create the fleet of viruses"""
        # create a virus and find the number of viruses in a row
        # spacing between each virus is equal to one virus width
        virus = Virus(self)
        virus_width, virus_height = virus.rect.size
        available_space_x = self.settings.screen_width - (2 * virus_width)
        number_viruses_x = available_space_x // (2 * virus_width)

        # determine the number of rows of viruses that fit on the screen
        nurse_height = self.nurse.rect.height
        available_space_y = (self.settings.screen_height - (3 * virus_height) -
                             nurse_height)
        number_rows = available_space_y // (2 * virus_height)

        # create full fleet of viruses
        for row_number in range(number_rows):
            for virus_number in range(number_viruses_x):
                self._create_virus(virus_number, row_number)

    def _create_virus(self, virus_number, row_number):
        """create a virus and place it in the row"""
        virus = Virus(self)
        virus_width, virus_height = virus.rect.size
        virus.x = virus_width + 2 * virus_width * virus_number
        virus.rect.x = virus.x
        virus.rect.y = virus.rect.height + 2 * virus.rect.height * row_number
        self.viruses.add(virus)

    def run_game(self):
        """Start the main loop for the game"""
        while True:
            self._check_events()
            self.nurse.update()
            self._update_vaccines()
            self._update_screen()

            # make the most recently drawn screen visible
            pygame.display.flip()

    def _check_events(self):
        # Watch for keyboard and mouse events
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            elif event.type == pygame.KEYDOWN:
                self._check_keydown_events(event)
            elif event.type == pygame.KEYUP:
                self._check_keyup_events(event)

    def _check_keydown_events(self, event):
        """respond to key presses"""
        if event.key == pygame.K_RIGHT:
            self.nurse.moving_right = True
        elif event.key == pygame.K_LEFT:
            self.nurse.moving_left = True
        elif event.key == pygame.K_q:
            sys.exit()
        elif event.key == pygame.K_SPACE:
            self._fire_vaccine()

    def _check_keyup_events(self, event):
        """respond to key releases"""
        if event.key == pygame.K_RIGHT:
            self.nurse.moving_right = False
        elif event.key == pygame.K_LEFT:
            self.nurse.moving_left = False

    def _fire_vaccine(self):
        """create a new vaccine and add it to the vaccines group"""
        if len(self.vaccines) < self.settings.vaccines_allowed:
            new_vaccine = Vaccine(self)
            self.vaccines.add(new_vaccine)

    def _update_screen(self):
        # redraw the screen
        self.screen.fill(self.settings.bg_color)
        self.nurse.blitme()
        for vaccine in self.vaccines.sprites():
            vaccine.draw_vaccine()
        self.viruses.draw(self.screen)

    def _update_vaccines(self):
        """update position of vaccines and get rid of old vaccines"""
        self.vaccines.update()

        # get rid of vaccines that have disappeared
        for vaccine in self.vaccines.copy():
            if vaccine.rect.bottom <= 0:
                self.vaccines.remove(vaccine)
 def nurse(self):
     self._canvas.destroy()
     Nurse(self.root)
Ejemplo n.º 27
0
def assign_nurse_patient() -> dict:
    """ Assign nurses to patients"""

    cursor.execute("SELECT * FROM variables")
    variables = cursor.fetchall()

    assignments = {}

    # Create "pod" data structure that stores: num_patients, how many transfers, skill level counts, how many a-trained

    num_clinical_areas = 6  # variables[0]
    clinical_areas = {}

    for _ in range(num_clinical_areas):
        clinical_areas[chr(num_clinical_areas + 65)] = {
            "patients": 0,
            "transfers": 0,
            "level": {
                1: 0,
                2: 0,
                3: 0,
                4: 0,
                5: 0
            },
            "a-trained": 0,
            "picc": 0
        }

    # pods = {
    #     "A": {"patients": 0, "transfers": 0, "level": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, "a-trained": 0},
    #     "B": {"patients": 0, "transfers": 0, "level": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, "a-trained": 0},
    #     "C": {"patients": 0, "transfers": 0, "level": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, "a-trained": 0},
    #     "D": {"patients": 0, "transfers": 0, "level": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, "a-trained": 0},
    #     "E": {"patients": 0, "transfers": 0, "level": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, "a-trained": 0},
    #     "F": {"patients": 0, "transfers": 0, "level": {1: 0, 2: 0, 3: 0, 4: 0, 5: 0}, "a-trained": 0}
    # }

    # We can modularize this. This gets all patients.
    cursor.execute("SELECT * FROM patients WHERE current=True")
    patient_list = cursor.fetchall()

    # ---------------
    # Maybe we can turn each nurse and patients into objects, then we can have a list of nurse objects and a list of patient objects?

    # Initialize patient and nurse lists
    patients = []
    nurses = []

    # append current Patient objects into patients list
    for row in patient_list:
        x = Patient(row[0], row[1], row[2], row[3], row[4], row[5], row[6],
                    row[7], row[8], row[9], row[10], row[11], row[12], row[13],
                    row[14])
        patients.append(x)
    print(patients)

    # We can also modularize this.
    cursor.execute("SELECT * FROM nurses WHERE current=True")
    nurse_list = cursor.fetchall()

    # append current Patient objects into patients list
    for row in nurse_list:
        x = Nurse(row[0], row[1], row[2], row[3], row[4], row[5], row[6],
                  row[7], row[8], row[9], row[10], row[11], row[12], row[13],
                  row[14], row[15], row[16], row[17], row[18], row[19])
        nurses.append(x)
    print(nurses)

    # filling in pod info
    for row in patient_list:
        # row[2] points to the bed column in patient list
        clinical_areas[row[3]]["patients"] += 1
        # row[2][0] points to the first letter in bed column which is the pod.
        # pods[#][0] points to the num_patients of the pod object.

        # Increment skill level counts
        clinical_areas[row[3]]["level"][row[5]] += 1
        if row[6]:
            # Increment amount of a-trained in pod object if patient needs a-trained
            clinical_areas[row[3]]["a-trained"] += 1
        if row[7]:
            # Increment amount of transfers in pod object if patient needs transfer
            clinical_areas[row[3]]["transfers"] += 1
        if row[8]:
            # Increment amount of picc in pod object if patient needs picc
            clinical_areas[row[3]]["picc"] += 1

    print(clinical_areas)

    # hard match nurses with patients they've been with (regardless of pod)
    #   In the case of multiple previous patients:
    #       - check skill-level
    #       - check geography (if needed)

    # previous_patients = {
    #     "1": {name, timestamp of admission, timestamp of discharge},
    #     "69": {anothern ame, timestapm, timestamp}
    # }

    matched_patients = []

    for n in nurses:
        prev_p = n.get_previous_patients()
        for p in patients:
            if prev_p.get(p.get_id(), False):
                assignments[n.get_id()] = p.get_id()
                n.set_assigned(True)
                # matched_patients.append(p.get_id())

    # assess all previous patients and pair
    # check if same clinical area (try to assign all to same nurse)
    # check recency. Favour most recent
    # check skill level (favour highest skill level first. Reject if not enough)

    # for nurse in nurse_list:

    #     if (nurse[13][0] in patient_list) and (nurse[18] is not True): # check if the latest patient the nurse has been with exists in patient list, and check if the nurse is not assigned
    #         assignments[nurse[1] + nurse[2]] = nurse[13][0] # hard match nurse with the latest previous patient entry (assuming previous patients is stored as list)
    #         nurse[18] = True # mark them as assigned

    # A trained nurses go to "Rabbit Pod" as much as needed
    # for ca in clinical_areas.keys():
    # allocate ceil(clinical_areas[ca]["a_trained"]/2) a_trained nurses

    # check skill level
    # assign

    # for pod in pods:
    #     if pod has a_trained patient:
    #         num_a_trained = 8
    #         allocate 8/2 ceiling a trained
    #         allocate nurses with a_Trained to this pod

    # for nurse in nurse_list:
    #     if nurse[9]:
    #         nurse[3] = 'F'  # Sets nurse pod to MBC clinical area
    #         nurse[10] = True  # Marks the nurse as assigned

    # split the remaining nurses according to "pod's needs"
    #       - A-trained

    ##################### PSEUDO CODE #########################
    ## Adds nurse to pod with a_trained ##
    # for pod in pods:
    #   count = pod["a_trained"]
    #   for _ in range(count):
    #       for nurse in nurse_list:
    #           if nurse[10] == False and nurse[6] == True:
    #               nurse[3] = pod  # Sets nurse to pod
    #               nurse[10] = True
    ###########################################################

    #       - transfer available for patient who needs it

    ##################### PSEUDO CODE #########################
    ## Adds nurse to pod with transfer ##
    # for pod in pods:
    #   count = pod["transfers"]
    #   for _ in range(count):
    #       for nurse in nurse_list:
    #           if nurse[10] == False and nurse[7] == True:
    #               nurse[3] = pod  # Sets nurse to pod
    #               nurse[10] = True
    ###########################################################

    #       - number of patients in a pod
    #       - Ensure enough skill level per pod
    #       - ensure PICC match

    # Special Role Assignments (note: not assigned to a pod/patient)

    # Assign nurses to patients
    #       - 1:1 (we think) hard constraint
    #       - A-trained match
    #       - Transfer match
    #       - PICC match
    #       - sort by skill level and pair the lower skill-level nurses first

    # Match first valid pair
    # for i in patients.keys():
    #     for j in nurses.keys():
    #         if (nurses[j][2] < 1) and (patients[i][2] < 1):
    #             if nurses[j][1] >= patients[i][1]:
    #                 try:
    #                     assignments[nurses[j][0]] = patients[i][0]
    #                     nurses[j][2] += 1
    #                     patients[i][2] += 1
    #                 except IndexError:
    #                     assignments["null" + str(i)] = patients[i][0]

    try:
        response = app.response_class(status=200,
                                      response=json.dumps(assignments))
    except ValueError as error:
        response = app.response_class(status=400, response=str(error))

    return response
Ejemplo n.º 28
0
class TestNurse(TestCase):
    """ Unit tests for the Nurse class """
    def setUp(self):
        """ creates a test fixture before each test method has run """
        self.nurse = Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True,
                           False, "charge", "previous", "dta", "comment", True,
                           True)

        self.long_str = ""
        for i in range(260):
            self.long_str += "a"

    def test_getters(self):
        self.assertEqual(self.nurse.get_id(), 12)
        self.assertEqual(self.nurse.get_name(), "Jane")
        self.assertEqual(self.nurse.get_clinical_area(), "A")
        self.assertEqual(self.nurse.get_bed_num(), 7)
        self.assertEqual(self.nurse.get_rotation(), "a")
        self.assertEqual(self.nurse.get_group(), 5)
        self.assertEqual(self.nurse.get_fte(), 1.1)
        self.assertEqual(self.nurse.get_skill_level(), 0)
        self.assertEqual(self.nurse.get_a_trained(), True)
        self.assertEqual(self.nurse.get_transfer(), True)
        self.assertEqual(self.nurse.get_picc(), False)
        self.assertEqual(self.nurse.get_advanced_role(), "charge")
        self.assertEqual(self.nurse.get_previous_patients(), "previous")
        self.assertEqual(self.nurse.get_dta(), "dta")
        self.assertEqual(self.nurse.get_comment(), "comment")
        self.assertEqual(self.nurse.get_priority(), True)
        self.assertEqual(self.nurse.get_current_shift(), True)
        self.nurse.set_assigned(True)
        self.assertEqual(self.nurse.get_assigned(), True)

    def test_invalid_id(self):
        """id"""
        with self.assertRaises(ValueError):
            Nurse("12", "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(-2, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(None, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)

    def test_invalid_bed_num(self):
        """bed_num"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", "7", "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", None, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", -1, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 15, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)

    def test_invalid_group(self):
        """group"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", "5", 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", None, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", -1, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)

    def test_invalid_skill_level(self):
        """skill_level"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, "0", True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, None, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, -1, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 6, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)

    def test_invalid_name(self):
        """name"""
        with self.assertRaises(ValueError):
            Nurse(12, 12, "A", 7, "a", 5, 1.1, 0, True, True, False, "charge",
                  "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, self.long_str, "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, None, "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)

    def test_invalid_clinical_area(self):
        """clinical_area"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", 1, 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "AB", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", None, 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)

    def test_invalid_rotation(self):
        """rotation"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, 1, 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, self.long_str, 5, 1.1, 0, True, True,
                  False, "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, None, 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)

    def test_invalid_advanced_role(self):
        """advanced_role"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False, 1,
                  "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  self.long_str, "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False, None,
                  "previous", "dta", "comment", True, True)

    def test_invalid_previous_patients(self):
        """previous_patients"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", 1, "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", None, "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", self.long_str, "dta", "comment", True, True)

    def test_invalid_dta(self):
        """dta"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", 1, "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", self.long_str, "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", None, "comment", True, True)

    def test_invalid_comments(self):
        """comments"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", 1, True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", None, True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, False,
                  "charge", "previous", "dta", self.long_str, True, True)

    def test_invalid_fte(self):
        """fte"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, None, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, -1, 0, True, True, False,
                  "charge", "previous", "dta", "comment", True, True)

    def test_invalid_a_trained(self):
        """a_trained"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, None, True, False,
                  "charge", "previous", "dta", "comment", True, True)

    def test_invalid_transfer(self):
        """transfer"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, None, False,
                  "charge", "previous", "dta", "comment", True, True)

    def test_invalid_picc(self):
        """picc"""
        with self.assertRaises(ValueError):
            Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, None,
                  "charge", "previous", "dta", "comment", True, True)

    def test_to_dict(self):
        """to_dict"""
        self.nurse.assigned = True
        self.assertEqual(
            self.nurse.to_dict(), {
                "id": 12,
                "name": "Jane",
                "clinical_area": "A",
                "bed_num": 7,
                "rotation": "a",
                "fte": 1.1,
                "group": 5,
                "skill_level": 0,
                "a_trained": True,
                "transfer": True,
                "picc": False,
                "advanced_role": "charge",
                "previous_patients": "previous",
                "dta": "dta",
                "comments": "comment",
                "priority": True,
                "current shift": True,
                "assigned": True
            })
Ejemplo n.º 29
0
 def test_invalid_picc(self):
     """picc"""
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, True, True, None,
               "charge", "previous", "dta", "comment", True, True)
Ejemplo n.º 30
0
 def test_invalid_a_trained(self):
     """a_trained"""
     with self.assertRaises(ValueError):
         Nurse(12, "Jane", "A", 7, "a", 5, 1.1, 0, None, True, False,
               "charge", "previous", "dta", "comment", True, True)