def setUp(self):
     self.user = User.objects.create_user(
         self.allowed_user_username,
         '*****@*****.**',
         self.allowed_user_password,
     )
     self.health_facility = HealthFacility.objects.create(name='Hospital X')
     CaseInvestigator.objects.create(
         user=self.user,
         health_facility=self.health_facility,
         is_admin=False,
     )
     self.patient = Patient(health_facility=self.health_facility)
     self.patient.save()
예제 #2
0
    def setUp(cls):
        Group.objects.create(name='Patient')
        Group.objects.create(name='Doctor')
        Group.objects.create(name='Nurse')
        Group.objects.create(name='Admin')
        cls.hospital = Hospital.objects.create(name="Hospital1")

        cls.P_user = User.objects.create(username="******",
                                         password="******",
                                         email="*****@*****.**",
                                         first_name="PTest",
                                         last_name="LastName")
        cls.N_user = User.objects.create(username="******",
                                         password="******",
                                         email="*****@*****.**",
                                         first_name="NTest",
                                         last_name="LastName")
        cls.D_user = User.objects.create(username="******",
                                         password="******",
                                         email="*****@*****.**",
                                         first_name="DTest",
                                         last_name="LastName")
        cls.A_user = User.objects.create(username="******",
                                         password="******",
                                         email="*****@*****.**",
                                         first_name="ATest",
                                         last_name="LastName")

        cls.patient1 = Patient.create(cls.P_user, "1/1/1960", "M", "A-", "75",
                                      "190", "Death", "Type 2 Diabetes",
                                      "Geico", "Hospital1",
                                      "*****@*****.**")

        cls.doctor = Doctor.create(cls.D_user, cls.hospital, "4438483228")

        Results.objects.create(name="Test",
                               notes="This is a test",
                               patient=None,
                               files='results.png',
                               doctor=cls.D_user,
                               date=timezone.now(),
                               released=False)
        Results.objects.create(name="Test2",
                               notes="This is a test",
                               patient=None,
                               files=None,
                               doctor=cls.D_user,
                               date=timezone.now(),
                               released=False)
예제 #3
0
 def create_patient(self, status):
     hf = HealthFacility()
     hf.name = 'HF'
     hf.save()
     self.health_facility = hf
     patient = Patient()
     patient.health_facility = hf
     if status:
         patient.status = status
     patient.contact_phone_number = self.contact_phone_number
     patient.first_name = self.first_name
     patient.last_name = self.last_name
     self.info_code = patient.info_code
     self.patient = patient
     return patient
예제 #4
0
 def create_patient(self, status):
     hf = HealthFacility()
     hf.name = 'HF'
     hf.save()
     self.health_facility = hf
     patient = Patient()
     patient.health_facility = hf
     if status:
         patient.status = status
     patient.contact_phone_number = self.contact_phone_number
     patient.first_name = self.first_name
     patient.last_name = self.last_name
     self.info_code = patient.info_code
     self.patient = patient
     return patient
예제 #5
0
    def get_morning_noti_type(cls, patient: Patient):
        medi_management = patient.medication_manage_flag and patient.medication_noti_time_list_to_str(
        )

        if patient.next_visiting_date_time:
            visit_today = patient.next_visiting_date_time.date(
            ) == datetime.datetime.today().astimezone().date()
        else:
            visit_today = None

        if medi_management and visit_today:
            return cls.MORNING_MEDI_MANAGEMENT_TRUE_AND_VISIT_TODAY

        elif medi_management and not visit_today:
            return cls.MORNING_MEDI_MANAGEMENT_TRUE

        elif not medi_management and visit_today:
            return cls.MORNING_MEDI_MANAGEMENT_FALSE_AND_VISIT_TODAY

        elif not medi_management and not visit_today:
            return cls.MORNING_MEDI_MANAGEMENT_FALSE
예제 #6
0
    def test_create_appointment(self):
        """
        Checks if appointment can be created
        :return: True if the appointment is created
        """

        date = 10 / 12 / 20
        pat = Patient(User, date, "Male", "AB-", 10, 10, None, None, None,
                      None)

        doc = Doctor(User, "634-1242")

        hosp = Hospital(name='Hospital 1')

        app = Appointment(patient=pat,
                          doctor=doc,
                          hospital=hosp,
                          appointmentStart='1800-01-01 08:00:00',
                          appointmentNotes='Note!')

        print(app.hospital.name)

        self.assertEqual(app.hospital.name != 'Hospital 2', True)
class TestPatientPermissions(APITestCase):

    fixtures = ['groups.json']
    allowed_user_username = '******'
    allowed_user_password = '******'

    def setUp(self):
        self.user = User.objects.create_user(
            self.allowed_user_username,
            '*****@*****.**',
            self.allowed_user_password,
        )
        self.health_facility = HealthFacility.objects.create(name='Hospital X')
        CaseInvestigator.objects.create(
            user=self.user,
            health_facility=self.health_facility,
            is_admin=False,
        )
        self.patient = Patient(health_facility=self.health_facility)
        self.patient.save()

    def get_response_results_tuple(self, url):
        response = self.client.get(url)
        results = response.data.get('results', None)
        return (response, results)

    def test_permissions_user_in_same_HF_can_view(self):
        """
        Assert that Patients in one HealthFacility are visible to
        CaseInvestigators belonging to that HealthFacility.
        """
        self.client.login(username=self.allowed_user_username,
                          password=self.allowed_user_password)

        # TODO: Since not all HTML templates are in place yet,
        # the standard way of specifying or URL:
        #
        #     client.get(reverse('patient-list'))
        #
        # throws a TemplateDoesNotExist error.
        # response = self.client.get('/patients/.json')
        # results = response.data['results']
        response, results = self.get_response_results_tuple('/patients/.json')
        # Our first user belongs to the same HealthFacility as the Patient does.
        # Hence, the retrieved list should include the the patient just created.
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            results[0]['info_code'],
            self.patient.info_code,
        )

        _, results = self.get_response_results_tuple('/health-facilities/.json')
        self.assertEqual(len(results), 1)

    def test_permissions_user_in_other_HF_can_not_view(self):
        """
        Assert that Patients in one HealthFacility are not visible to
        CaseInvestigators not belonging to that HealthFacility.
        """
        user = User.objects.create_user(
            'test-user-2', '*****@*****.**', 'password')
        health_facility = HealthFacility.objects.create(name='Hospital Y')
        CaseInvestigator.objects.create(
            user=user,
            health_facility=health_facility,
            is_admin=False,
        )
        self.client.login(username='******', password='******')

        response, results = self.get_response_results_tuple('/patients/.json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(results), 0)

        _, results = self.get_response_results_tuple('/health-facilities/.json')
        self.assertEqual(len(results), 1)

    def test_permissions_superuser(self):
        """
        Finally, assert that a superuser can view all HealthFacilities.
        """
        User.objects.create_superuser(
            'superuser', '*****@*****.**', 'password')
        self.client.login(username='******', password='******')
        _, results = self.get_response_results_tuple('/health-facilities/.json')
        self.assertEqual(len(results), 1)