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(CrfMetaData.objects.filter(registered_subject=self.registered_subject, entry__model_name__in=rg.test_rule.target_model_names).count(), 0) TestVisitFactory(appointment=self.appointment) self.assertEqual(CrfMetaData.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().prepare() 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 self.study_site = '40' 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=self.study_site, 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)
alternative=NOT_REQUIRED), target_model=['reproductivehealth']) srh_utilization = CrfRule(logic=Logic( predicate=func_show_srh_services_utilization, consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=['maternalsrh']) class Meta: app_label = 'mb_maternal' source_fk = None source_model = RegisteredSubject site_rule_groups.register(MaternalRegisteredSubjectRuleGroup) class MaternalArvHistoryRuleGroup(RuleGroup): arv_history_required = CrfRule(logic=Logic( predicate=(('prior_health_haart', 'equals', YES), ('prev_pregnancy_arv', 'equals', YES, 'or')), consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=['maternalarvhistory']) class Meta: app_label = 'mb_maternal' source_fk = (MaternalVisit, 'maternal_visit') source_model = MaternalClinicalHistory
class InfantBirthDataRuleGroup(RuleGroup): congenital_anomalities_yes = CrfRule( logic=Logic(predicate=('congenital_anomalities', 'equals', YES), consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=['infantcongenitalanomalies']) class Meta: app_label = 'mb_infant' source_fk = (InfantVisit, 'infant_visit') source_model = InfantBirthData site_rule_groups.register(InfantBirthDataRuleGroup) class InfantFuRuleGroup(RuleGroup): physical_assessment_yes = CrfRule(logic=Logic( predicate=('physical_assessment', 'equals', YES), consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=['infantfuphysical']) has_dx_yes = CrfRule(logic=Logic(predicate=('has_dx', 'equals', YES), consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=['infantfudx'])
def setUp(self): try: site_lab_profiles.register(TestLabProfile()) except AlreadyRegisteredLabProfile: pass TestAppConfiguration().prepare() 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 = CrfRule( 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 = CrfRule( 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 = CrfRule( 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 = CrfRule( 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 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.visit_definition = VisitDefinition.objects.get(code='1000') self.test_consent = TestConsentWithMixinFactory( gender='M', study_site='40', 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)
logic=Logic(predicate=func_show_srh_forms, consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=["reproductivehealth"], ) srh_utilization = CrfRule( logic=Logic(predicate=func_show_srh_services_utilization, consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=["maternalsrh"], ) class Meta: app_label = "mb_maternal" source_fk = None source_model = RegisteredSubject site_rule_groups.register(MaternalRegisteredSubjectRuleGroup) class MaternalArvHistoryRuleGroup(RuleGroup): arv_history_required = CrfRule( logic=Logic( predicate=(("prior_health_haart", "equals", YES), ("prev_pregnancy_arv", "equals", YES, "or")), consequence=UNKEYED, alternative=NOT_REQUIRED, ), target_model=["maternalarvhistory"], ) class Meta: app_label = "mb_maternal"
target_model=[('td_maternal', 'maternalultrasoundinitial')]) srh_services = CrfRule( logic=Logic( predicate=func_show_srh_services_utilization, consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=[('td_maternal', 'maternalsrh')]) class Meta: app_label = 'td_maternal' source_fk = None source_model = RegisteredSubject site_rule_groups.register(MaternalRegisteredSubjectRuleGroup) class MaternalRequisitionRuleGroup(RuleGroup): require_vl_prn = RequisitionRule( logic=Logic( predicate=func_mother_pos_vl, consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=[('td_lab', 'maternalrequisition')], target_requisition_panels=['Viral Load']) require_pbmc_vl = RequisitionRule( logic=Logic( predicate=require_pbmc_vl,
class InfantBirthDataRuleGroup(RuleGroup): congenital_anomalities_yes = CrfRule( logic=Logic( predicate=('congenital_anomalities', 'equals', YES), consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=['infantcongenitalanomalies']) class Meta: app_label = 'mb_infant' source_fk = (InfantVisit, 'infant_visit') source_model = InfantBirthData site_rule_groups.register(InfantBirthDataRuleGroup) class InfantFuRuleGroup(RuleGroup): physical_assessment_yes = CrfRule( logic=Logic( predicate=('physical_assessment', 'equals', YES), consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=['infantfuphysical']) has_dx_yes = CrfRule( logic=Logic( predicate=('has_dx', 'equals', YES), consequence=UNKEYED,
target_model=[('td_infant', 'infantnvpdispensing'), ]) nvp_adjustment = CrfRule( logic=Logic( predicate=func_show_nvp_adjustment_2010, consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=[('td_infant', 'infantnvpadjustment'), ]) class Meta: app_label = 'td_infant' source_fk = None source_model = RegisteredSubject site_rule_groups.register(InfantRegisteredSubjectRuleGroup) class InfantFuRuleGroup(RuleGroup): physical_assessment_yes = CrfRule( logic=Logic( predicate=('physical_assessment', 'equals', YES), consequence=UNKEYED, alternative=NOT_REQUIRED), target_model=[('td_infant', 'infantfuphysical'), ]) has_dx_yes = CrfRule( logic=Logic( predicate=('has_dx', 'equals', YES), consequence=UNKEYED,