Пример #1
0
    def test_patient_adoption_last_24_hours(self):
        total_patients = 5
        facilities = get_facilities_for_user(self.user, self.organization.id)

        for facility in facilities:
            for i in range(total_patients):
                self.create_patient(**{
                    'facility': facility
                })

        # Create patients with last_app_use 2 days ago
        now = timezone.now()
        days_ago = now - relativedelta(days=2)
        for facility in facilities:
            for i in range(total_patients):
                self.create_patient(**{
                    'facility': facility,
                    'last_app_use': days_ago
                })

        response = self.client.get(self.url)

        self.assertEqual(
            response.data['patients_last_24_hours'],
            total_patients * facilities.count()
        )
Пример #2
0
    def test_patient_adoption_rate(self):
        total_patients = 5
        total_last_24_hours = 3
        facilities = get_facilities_for_user(self.user, self.organization.id)
        total_facilities = facilities.count()
        now = timezone.now()
        days_ago = now - relativedelta(days=2)

        for facility in facilities:
            for i in range(total_patients):
                kwargs = {
                    'facility': facility
                }
                if i >= total_last_24_hours:
                    kwargs.update({
                        'last_app_use': days_ago
                    })

                self.create_patient(**kwargs)

        adoption_rate = round((total_last_24_hours * total_facilities) /
                              (total_patients * total_facilities) * 100)

        response = self.client.get(self.url)

        self.assertEqual(response.data['adoption_rate'], adoption_rate)
Пример #3
0
    def test_organization_invited_patients(self):
        invited_patients = 5
        facilities = get_facilities_for_user(self.user, self.organization.id)

        for facility in facilities:
            for i in range(invited_patients):
                self.create_patient(**{
                    'facility': facility,
                    'is_invited': True,
                    'is_active': False
                })

        # Create patients for other facility
        for i in range(3):
            self.create_patient(**{
                    'is_invited': True,
                    'is_active': False
                })

        response = self.client.get(self.url)

        self.assertEqual(
            response.data['invited_patients'],
            invited_patients * facilities.count()
        )
Пример #4
0
    def generate_average_outcome_records(self, organization):
        total_care_plans = 5
        total_patients = 6
        num_assessment_tasks = 3
        plans = []
        facilities = get_facilities_for_user(self.user, self.organization.id)

        for facility in facilities:
            for p in range(total_patients):
                patient = self.create_patient(**{'facility': facility})
                for c in range(total_care_plans):
                    plan = self.create_care_plan(patient)
                    plans.append(plan)

                    for t in range(num_assessment_tasks):
                        template = self.create_assessment_task_template(
                            **{'tracks_outcome': True})
                        assessment_template = self.create_plan_assessment_template(
                            plan=plan, assessment_task_template=template)
                        task = self.create_assessment_task(
                            **{
                                'assessment_template': assessment_template,
                            })
                        questions = template.questions.all()
                        self.create_responses_to_multiple_questions(
                            template, task, questions)

        outcome_tasks = AssessmentTask.objects.filter(
            Q(assessment_template__custom_tracks_outcome=True) |
            (Q(assessment_template__custom_tracks_outcome__isnull=True)
             & Q(assessment_template__assessment_task_template__tracks_outcome=
                 True)),
            assessment_template__plan__in=plans,
        ).aggregate(outcome_average=Avg('responses__rating'))
        average = outcome_tasks['outcome_average'] or 0
        average_outcome = round((average / 5) * 100)

        # Create dummy record
        for i in range(5):
            template = self.create_assessment_task_template(
                **{'tracks_outcome': True})
            assessment_template = self.create_plan_assessment_template(
                assessment_task_template=template)
            task = self.create_assessment_task(
                **{'assessment_template': assessment_template})
            self.create_multiple_assessment_questions(template)
            questions = template.questions.all()
            self.create_responses_to_multiple_questions(
                template, task, questions)

        return average_outcome
Пример #5
0
    def test_organization_potential_patients(self):
        potential_patients = 5
        facilities = get_facilities_for_user(self.user, self.organization.id)

        for i in range(potential_patients):
            self.create_potential_patient(**{'facility': facilities})

        # Create patients for other facility
        for i in range(3):
            self.create_potential_patient()

        response = self.client.get(self.url)

        self.assertEqual(response.data['potential_patients'],
                         potential_patients * facilities.count())
Пример #6
0
    def test_get_graph_billable_patients(self):
        total_patients = 5
        total_billable_patients = 3
        facilities = get_facilities_for_user(self.user, self.organization.id)
        facilities_count = facilities.count()
        now = timezone.now()
        last_month = now - relativedelta(months=1)

        for facility in facilities:
            for i in range(total_patients):
                self.create_patient(**{'facility': facility})

            for i in range(total_billable_patients):
                patient = self.create_patient(**{
                    'facility': facility,
                    'payer_reimbursement': True
                })
                plan = self.create_care_plan(patient)
                team_template = self.create_plan_team_template(plan=plan)
                self.create_billed_activity(**{
                    'plan': plan,
                    'team_template': team_template
                })

            # Create billable patients on previous month
            for i in range(total_billable_patients):
                patient = self.create_patient(**{
                    'facility': facility,
                    'payer_reimbursement': True
                })
                plan = self.create_care_plan(patient)
                team_template = self.create_plan_team_template(plan=plan)
                self.create_billed_activity(
                    **{
                        'plan': plan,
                        'team_template': team_template,
                        'activity_datetime': last_month
                    })

        # Create patients for other facility
        for i in range(3):
            self.create_patient()

        response = self.client.get(self.url)

        self.assertEqual(
            response.data['graph'][now.strftime("%B %Y")]['billable_patients'],
            total_billable_patients * facilities_count)
Пример #7
0
    def test_organization_total_patient(self):
        total_patients = 5
        facilities = get_facilities_for_user(self.user, self.organization.id)

        for facility in facilities:
            for i in range(total_patients):
                self.create_patient(**{'facility': facility})

        # Create patients for other facility
        for i in range(3):
            self.create_patient()

        response = self.client.get(self.url)

        self.assertEqual(response.data['active_patients'],
                         total_patients * facilities.count())
Пример #8
0
    def test_get_graph_enrolled_patients(self):
        total_patients = 5
        facilities = get_facilities_for_user(self.user, self.organization.id)
        facilities_count = facilities.count()
        now = timezone.now()

        for facility in facilities:
            for i in range(total_patients):
                self.create_patient(**{'facility': facility})

        # Create patients for other facility
        for i in range(3):
            self.create_patient()

        response = self.client.get(self.url)

        self.assertEqual(
            response.data['graph'][now.strftime("%B %Y")]['enrolled_patients'],
            total_patients * facilities_count)
Пример #9
0
    def generate_average_engagement_records(self,
                                            organization=None,
                                            patient=None):
        total_care_plans = 5
        total_patients = 6
        plans = []
        now = timezone.now()
        due_datetime = now - relativedelta(days=3)
        facilities = get_facilities_for_user(self.user, self.organization.id)

        if organization:
            for facility in facilities:
                for p in range(total_patients):
                    patient = self.create_patient(**{
                        'facility': facility
                    })
                    for c in range(total_care_plans):
                        plan = self.create_care_plan(patient)
                        plans.append(plan)

                        self.generate_assessment_tasks(plan, due_datetime)
                        self.generate_patient_tasks(plan, due_datetime)
                        self.generate_medication_tasks(plan, due_datetime)
                        self.generate_symptom_tasks(plan, due_datetime)
                        self.generate_vital_tasks(plan, due_datetime)

        elif patient:
            for c in range(total_care_plans):
                plan = self.create_care_plan(patient)
                plans.append(plan)

                self.generate_assessment_tasks(plan, due_datetime)
                self.generate_patient_tasks(plan, due_datetime)
                self.generate_medication_tasks(plan, due_datetime)
                self.generate_symptom_tasks(plan, due_datetime)
                self.generate_vital_tasks(plan, due_datetime)

        assessment_tasks = AssessmentTask.objects.filter(
            plan__in=plans,
            due_datetime__lte=now
        )
        patient_tasks = PatientTask.objects.filter(
            patient_template__plan__in=plans,
            due_datetime__lte=now
        )
        medication_tasks = MedicationTask.objects.filter(
            medication_task_template__plan__in=plans,
            due_datetime__lte=now
        )
        symptom_tasks = SymptomTask.objects.filter(
            symptom_template__plan__in=plans,
            due_datetime__lte=now
        )
        vital_tasks = VitalTask.objects.filter(
            plan__in=plans,
            due_datetime__lte=now
        )
        total_patient_tasks = patient_tasks.count()
        total_medication_tasks = medication_tasks.count()
        total_symptom_tasks = symptom_tasks.count()
        total_assessment_tasks = assessment_tasks.count()
        total_vital_tasks = vital_tasks.count()

        completed_patient_tasks = patient_tasks.filter(
            status__in=['missed', 'done']).count()
        completed_medication_tasks = medication_tasks.filter(
            status__in=['missed', 'done']).count()
        completed_symptom_tasks = symptom_tasks.filter(
            is_complete=True).count()
        completed_assessment_tasks = assessment_tasks.filter(
            is_complete=True).count()
        completed_vital_tasks = vital_tasks.filter(
            is_complete=True).count()
        total_completed = (completed_patient_tasks +
                           completed_medication_tasks +
                           completed_symptom_tasks +
                           completed_assessment_tasks +
                           completed_vital_tasks)
        total_tasks = (total_patient_tasks +
                       total_medication_tasks +
                       total_symptom_tasks +
                       total_assessment_tasks +
                       total_vital_tasks)
        return round((total_completed / total_tasks) * 100) \
            if total_tasks > 0 else 0