Exemplo n.º 1
0
 def test_rule_updates_meta_data_with_consent_func(self):
     """Assert updates meta data if source is RegisteredSubject and override fields knocked out."""
     site_rule_groups.register(self.test_rule_group_consent_func_cls)
     rg = self.test_rule_group_consent_func_cls()
     self.assertEqual(ScheduledEntryMetaData.objects.filter(registered_subject=self.registered_subject, entry__model_name__in=rg.test_rule.target_model_names).count(), 0)
     self.test_visit_factory(appointment=self.appointment)
     self.assertEqual(ScheduledEntryMetaData.objects.filter(entry_status=NOT_REQUIRED, registered_subject=self.registered_subject, entry__model_name__in=rg.test_rule.target_model_names).count(), 1)
     site_rule_groups.unregister(self.test_rule_group_consent_func_cls)
    def setUp(self):

        try:
            site_lab_profiles.register(TestLabProfile())
        except AlreadyRegisteredLabProfile:
            pass
        TestAppConfiguration()
        site_lab_tracker.autodiscover()
        TestVisitSchedule().build()

        class TestRuleGroupConsent(RuleGroup):
            test_rule = RequisitionRule(
                logic=Logic(
                    predicate=(('may_store_samples', 'equals', NO)),
                    consequence='not_required',
                    alternative='new'),
                target_model=['testrequisition'],
                target_requisition_panels=['research blood draw'])

            class Meta:
                app_label = 'testing'
                source_fk = (RegisteredSubject, 'registered_subject')
                source_model = TestConsentWithMixin
        site_rule_groups.register(TestRuleGroupConsent)

        class TestRuleGroupSched(RuleGroup):
            test_rule = RequisitionRule(
                logic=Logic(
                    predicate=(('f1', 'equals', NO)),
                    consequence='not_required',
                    alternative='new'),
                target_model=['testrequisition'],
                target_requisition_panels=['microtube', 'viral load'])

            class Meta:
                app_label = 'testing'
                source_fk = (TestVisit, 'test_visit')
                source_model = TestScheduledModel1
        site_rule_groups.register(TestRuleGroupSched)

        self.test_rule_group_sched_cls = TestRuleGroupSched

        self.test_visit_factory = TestVisitFactory

        self.visit_definition = VisitDefinition.objects.get(code='1000')

        self.test_consent = TestConsentWithMixinFactory(gender='M', study_site=StudySite.objects.all()[0], may_store_samples=YES)

        self.registered_subject = RegisteredSubject.objects.get(subject_identifier=self.test_consent.subject_identifier)
        self.appointment = Appointment.objects.get(registered_subject=self.registered_subject)
    def test_base1(self):
        site_rule_groups._registry = {}

        class BaseTestRuleGroupSched(RuleGroup):
            test_rule = RequisitionRule(
                logic=Logic(
                    predicate=(('f1', 'equals', NO)),
                    consequence='not_required',
                    alternative='new'),
                target_model=['testrequisition'],
                target_requisition_panels=['microtube', 'viral load'])

            class Meta:
                abstract = True

        class TestRuleGroupSched1(BaseTestRuleGroupSched):
            test_rule2 = RequisitionRule(
                logic=Logic(
                    predicate=(('f2', 'equals', YES)),
                    consequence='not_required',
                    alternative='none'),
                target_model=['testrequisition'],
                target_requisition_panels=['microtube', 'viral load'])

            class Meta:
                app_label = 'testing'
                source_fk = (TestVisit, 'test_visit')
                source_model = TestScheduledModel1
        site_rule_groups.register(TestRuleGroupSched1)

        requisition_panel = RequisitionPanel.objects.get(name='Microtube')
        test_visit = self.test_visit_factory(appointment=self.appointment)
        self.assertEqual(RequisitionMetaData.objects.filter(entry_status=REQUIRED, registered_subject=self.registered_subject, lab_entry__requisition_panel=requisition_panel).count(), 1)
        test_scheduled_model1 = TestScheduledModel1Factory(test_visit=test_visit, f1=NO, f2=NO)
        self.assertEqual(RequisitionMetaData.objects.filter(entry_status=NOT_REQUIRED, registered_subject=self.registered_subject, lab_entry__requisition_panel=requisition_panel).count(), 1)
        test_scheduled_model1.f1 = YES
        test_scheduled_model1.f2 = NO
        test_scheduled_model1.save()
        self.assertEqual(RequisitionMetaData.objects.filter(entry_status=REQUIRED, registered_subject=self.registered_subject, lab_entry__requisition_panel=requisition_panel).count(), 1)
        test_scheduled_model1.f1 = NO
        test_scheduled_model1.save()
        self.assertEqual(RequisitionMetaData.objects.filter(entry_status=NOT_REQUIRED, registered_subject=self.registered_subject, lab_entry__requisition_panel=requisition_panel).count(), 1)
Exemplo n.º 4
0
                                   'htccircumcision', 'malefollowup',
                                   'circumcisionappointment'
                               ])

    male = ScheduledDataRule(logic=Logic(predicate=('gender', 'equals', 'm'),
                                         consequence='not_required',
                                         alternative='new'),
                             target_model=['pregnantfollowup'])

    class Meta:
        app_label = 'bcpp_htc_subject'
        filter_model = (HtcSubjectVisit, 'htc_subject_visit')
        source_model = RegisteredSubject


site_rule_groups.register(GenderRuleGroup)


class HivTestingHistoryRuleGroup(RuleGroup):

    hiv_record = ScheduledDataRule(logic=Logic(predicate=('hiv_record',
                                                          'equals', 'Yes'),
                                               consequence='new',
                                               alternative='not_required'),
                                   target_model=['lasthivrecord'])

    class Meta:
        app_label = 'bcpp_htc_subject'
        filter_model = (HtcSubjectVisit, 'htc_subject_visit')
        source_model = HtcHivTestingHistory
Exemplo n.º 5
0
            predicate=func_maternal_lab,
            consequence='new',
            alternative='none'),
        target_model=[('eit_lab', 'maternalrequisition')],
        target_requisition_panels=['Viral Load', ], )

    """Ensures a CD4 blood draw requisition for the right visits"""
    ctrl_cd4 = RequisitionRule(
        logic=Logic(
            predicate=func_maternal_lab,
            consequence='new',
            alternative='none'),
        target_model=[('eit_lab', 'maternalrequisition')],
        target_requisition_panels=['CD4 (ARV)', ], )

    """Ensures a PBMC blood draw requisition for the right visits"""
    ctrl_pbmc = RequisitionRule(
        logic=Logic(
            predicate=func_maternal_lab,
            consequence='new',
            alternative='none'),
        target_model=[('eit_lab', 'maternalrequisition')],
        target_requisition_panels=['PBMC Plasma (STORE ONLY)', ], )


    class Meta:
        app_label = 'eit_maternal'
        source_fk = None
        source_model = RegisteredSubject
site_rule_groups.register(MaternalLabRuleGroup)
Exemplo n.º 6
0
class InfantBirthDataRuleGroup(RuleGroup):

    congenital_anomalities = ScheduledDataRule(
        logic=Logic(predicate=('congenital_anomalities', 'equals', 'Yes'),
                    consequence='new',
                    alternative='not_required'),
        target_model=['infantcongenitalanomalies'])

    class Meta:
        app_label = 'mpepu_infant'
        source_fk = (InfantVisit, 'infant_visit')
        source_model = InfantBirthData


site_rule_groups.register(InfantBirthDataRuleGroup)


class InfantArvProphRuleGroup(RuleGroup):

    prophylatic_nvp = ScheduledDataRule(logic=Logic(
        predicate=('prophylatic_nvp', 'equals', 'No'),
        consequence='not_required',
        alternative='new'),
                                        target_model=['infantnvpadherence'])

    class Meta:
        app_label = 'mpepu_infant'
        source_fk = (InfantVisit, 'infant_visit')
        source_model = InfantArvProph
Exemplo n.º 7
0
        alternative='not_required'),
                                           target_model=['maternalenrollarv'])

    prev_pregnancy_arv = ScheduledDataRule(logic=Logic(
        predicate=('prev_pregnancy_arv', 'equals', 'Yes'),
        consequence='new',
        alternative='not_required'),
                                           target_model=['maternalenrollclin'])

    class Meta:
        app_label = 'mpepu_maternal'
        source_fk = (MaternalVisit, 'maternal_visit')
        source_model = MaternalEnroll


site_rule_groups.register(MaternalEnrollRuleGroup)


class MaternalArvPregRuleGroup(RuleGroup):

    took_arv = ScheduledDataRule(logic=Logic(predicate=('took_arv', 'equals',
                                                        'Yes'),
                                             consequence='new',
                                             alternative='not_required'),
                                 target_model=['maternalarvpreghistory'])

    start_pp = ScheduledDataRule(logic=Logic(predicate=('start_pp', 'equals',
                                                        'Yes'),
                                             consequence='new',
                                             alternative='not_required'),
                                 target_model=['maternalarvpphistory'])
Exemplo n.º 8
0
        target_requisition_panels=['Viral Load'], )

    rbd_for_pos = RequisitionRule(
        logic=Logic(
            predicate=func_rbd,
            consequence='new',
            alternative='not_required'),
        target_model=[('bcpp_lab', 'subjectrequisition')],
        target_requisition_panels=['Research Blood Draw'], )

    class Meta:
        app_label = 'bcpp_subject'
        source_fk = None
        source_model = RegisteredSubject

site_rule_groups.register(RegisteredSubjectRuleGroup)


class ResourceUtilizationRuleGroup(RuleGroup):

    out_patient = ScheduledDataRule(
        logic=Logic(
            predicate=(('out_patient', 'equals', 'no'), ('out_patient', 'equals', 'Refuse', 'or')),
            consequence='not_required',
            alternative='new'),
        target_model=['outpatientcare'])

    hospitalized = ScheduledDataRule(
        logic=Logic(
            predicate=('hospitalized', 'equals', 0),
            consequence='not_required',
Exemplo n.º 9
0
        target_requisition_panels=['PBMC Plasma (STORE ONLY)', ], )

    """Ensures a elisa blood draw requisition for the right visits"""
    peri_elisa = RequisitionRule(
        logic=Logic(
            predicate=func_peripartum_elisa,
            consequence='new',
            alternative='none'),
        target_model=[('eit_lab', 'infantrequisition')],
        target_requisition_panels=['ELISA', ], )

    class Meta:
        app_label = 'eit_infant'
        source_fk = None
        source_model = RegisteredSubject
site_rule_groups.register(PeripartumRuleGroup)


class AntepartumRuleGroup(RuleGroup):

    """Ensures a Hematology blood draw requisition for the right visits"""
    ante_hema = RequisitionRule(
        logic=Logic(
            predicate=func_antepartum_hema,
            consequence='new',
            alternative='none'),
        target_model=[('eit_lab', 'infantrequisition')],
        target_requisition_panels=['Hematology (ARV)', ], )

    """Ensures a Viral Load blood draw requisition for the right visits"""
    ante_vl = RequisitionRule(
Exemplo n.º 10
0
    initiation = RequisitionRule(
        logic=Logic(predicate=(('registration_type', 'equals', 'initiation'),
                               ('registration_type', 'equals', 'OTHER', 'or')),
                    consequence='new',
                    alternative='not_required'),
        target_model=[('bcpp_lab', 'clinicrequisition')],
        target_requisition_panels=['Clinic Viral Load'],
    )

    class Meta:
        app_label = 'bcpp_clinic'
        source_fk = (ClinicVisit, 'clinic_visit')
        source_model = Questionnaire


site_rule_groups.register(InitiationRequisitionRuleGroup)


class MasaRuleGroup(RuleGroup):

    is_drawn = ScheduledDataRule(logic=Logic(predicate=(('registration_type',
                                                         'equals',
                                                         'masa_vl_scheduled')),
                                             consequence='new',
                                             alternative='not_required'),
                                 target_model=['viralloadtracking'])

    class Meta:
        app_label = 'bcpp_clinic'
        source_fk = (ClinicVisit, 'clinic_visit')
        source_model = Questionnaire
Exemplo n.º 11
0
    def setUp(self):

        try:
            site_lab_profiles.register(TestLabProfile())
        except AlreadyRegisteredLabProfile:
            pass
        TestAppConfiguration()
        site_lab_tracker.autodiscover()
        TestVisitSchedule().build()

        # a test rule group where the source model is RegisteredSubject
        # the rules in this rule group will be only evaluated when the visit instance
        # is created or saved. Note source_fk is None.
        class TestRuleGroupRs(RuleGroup):
            test_rule = ScheduledDataRule(
                logic=Logic(
                    predicate=(('gender', 'equals', 'M')),
                    consequence='not_required',
                    alternative='new'),
                target_model=['testscheduledmodel1'])

            class Meta:
                app_label = 'testing'
                source_fk = None
                source_model = RegisteredSubject
        site_rule_groups.register(TestRuleGroupRs)

        # a test rule group where the source model is a scheduled model.
        # a scheduled model has a FK to the visit instance (source_fk).
        # the rules in this rule group will be evaluated when the source instance
        # is created or saved.
        class TestRuleGroupSched(RuleGroup):
            test_rule = ScheduledDataRule(
                logic=Logic(
                    predicate=(('f1', 'equals', NO)),
                    consequence='not_required',
                    alternative='new'),
                target_model=['testscheduledmodel2'])

            class Meta:
                app_label = 'testing'
                source_fk = (TestVisit, 'test_visit')
                source_model = TestScheduledModel1
        site_rule_groups.register(TestRuleGroupSched)

        # a test rule group where the source model is a consent or membership model.
        # these models have a FK to registered subject (source_fk).
        # the rules in this rule group will only evaluated when the visit instance
        # is created or saved.
        class TestRuleGroupConsent(RuleGroup):
            test_rule = ScheduledDataRule(
                logic=Logic(
                    predicate=(('may_store_samples', 'equals', NO)),
                    consequence='not_required',
                    alternative='new'),
                target_model=['testscheduledmodel3'])

            class Meta:
                app_label = 'testing'
                source_fk = (RegisteredSubject, 'registered_subject')
                source_model = TestConsentWithMixin
        site_rule_groups.register(TestRuleGroupConsent)

        class TestRuleGroupConsentFunc(RuleGroup):
            test_rule = ScheduledDataRule(
                logic=Logic(
                    predicate=func_condition_true,
                    consequence='not_required',
                    alternative='new'),
                target_model=['testscheduledmodel3'])

            class Meta:
                app_label = 'testing'
                source_fk = (RegisteredSubject, 'registered_subject')
                source_model = TestConsentWithMixin
#         site_rule_groups.register(TestRuleGroupConsentFunc)

#         class TestRuleGroupConsentFunc2(RuleGroup):
#             test_rule = ScheduledDataRule(
#                 logic=Logic(
#                     predicate=func_condition_false,
#                     consequence='not_required',
#                     alternative='new'),
#                 target_model=['testscheduledmodel3'])
#
#             class Meta:
#                 app_label = 'testing'
#                 source_fk = (RegisteredSubject, 'registered_subject')
#                 source_model = TestConsentWithMixin
#         site_rule_groups.register(TestRuleGroupConsentFunc2)

        self.test_rule_group_rs_cls = TestRuleGroupRs
        self.test_rule_group_sched_cls = TestRuleGroupSched
        self.test_rule_group_consent_cls = TestRuleGroupConsent
        self.test_rule_group_consent_func_cls = TestRuleGroupConsentFunc
#         self.test_rule_group_consent_func2_cls = TestRuleGroupConsentFunc2

        self.test_visit_factory = TestVisitFactory

        self.visit_definition = VisitDefinition.objects.get(code='1000')

        self.test_consent = TestConsentWithMixinFactory(gender='M', study_site=StudySite.objects.all()[0], may_store_samples=NO)

        self.registered_subject = RegisteredSubject.objects.get(subject_identifier=self.test_consent.subject_identifier)
        self.appointment = Appointment.objects.get(registered_subject=self.registered_subject)