Пример #1
0
 def test_eligible_subject4(self):
     """Assert 'eligible' and 'is' flags  if passes enrollment checklist for BHS and household is enrolled."""
     # eligible member
     household_member = HouseholdMemberFactory(
         household_structure=self.household_structure,
         gender='M',
         age_in_years=25,
         study_resident='Yes',
         initials='EE')
     # who is an eligible subject
     EnrollmentChecklistFactory(household_member=household_member,
                                gender='M',
                                dob=date.today() - relativedelta(years=25),
                                initials=household_member.initials,
                                part_time_resident='Yes')
     # who is consented
     SubjectConsentFactory(
         household_member=household_member,
         gender='M',
         dob=date.today() - relativedelta(years=25),
         first_name='ERIKFIRST',
         last_name='ERIKLAST',
         initials=household_member.initials,
     )
     self.assertTrue(household_member.eligible_member)
     self.assertTrue(household_member.eligible_subject)
     self.assertFalse(household_member.eligible_htc)
     self.assertTrue(household_member.is_consented)
     self.assertFalse(household_member.is_htc_only)
    def test_eligible_bhs(self):
        """Assert for eligible for BHS, household enrolled."""
        #self.startup()
        self.enroll_household()
        household_member = HouseholdMemberFactory(first_name='ERIK', initials='EXW', age_in_years=64, study_resident='Yes', household_structure=self.household_structure)
        household_member.member_status = BHS_SCREEN
        household_member.save()
        pk = household_member.pk
        household_member = HouseholdMember.objects.get(pk=pk)
        EnrollmentChecklistFactory(
            household_member=household_member,
            gender='M',
            dob=date.today() - relativedelta(years=64),
            guardian='No',
            initials=household_member.initials,
            part_time_resident='Yes')
        pk = household_member.pk
        household_member = HouseholdMember.objects.get(pk=pk)
        options = [BHS, BHS_ELIGIBLE, DECEASED, REFUSED]
        options.append(household_member.member_status)
        options = list(set(options))
        options.sort()
        member_status_choices = [(item, item) for item in options]
        x = household_member.member_status_choices
#         print x
#         print member_status_choices
        self.assertEqual(x, member_status_choices)
Пример #3
0
 def enroll_household(self):
     household_member = HouseholdMemberFactory(
         first_name='ERIK',
         initials='EW',
         age_in_years=18,
         study_resident='Yes',
         household_structure=self.source_household_structure)
     enrollment_checklist = EnrollmentChecklistFactory(
         household_member=household_member,
         gender='M',
         dob=date.today() - relativedelta(years=18),
         guardian='No',
         initials=household_member.initials,
         part_time_resident='Yes')
     from bhp066.apps.bcpp_subject.tests.factories import SubjectConsentFactory
     self.subject_consent = SubjectConsentFactory(
         household_member=enrollment_checklist.household_member,
         first_name="ERIK",
         last_name='WERIK',
         gender='M',
         dob=date.today() - relativedelta(years=18),
         initials=household_member.initials,
         study_site=self.study_site,
     )
     self.assertEqual(self.subject_consent.household_member.member_status,
                      BHS)
     self.assertTrue(
         self.subject_consent.household_member.household_structure.enrolled)
     return household_member
Пример #4
0
    def test_eligible_subject3(self):
        """Assert 'eligible' and 'is' flags  if fails enrollment checklist for BHS and household is enrolled.

        Fails eligibility but is eligible for HTC by age."""
        # eligible member
        household_member = HouseholdMemberFactory(
            household_structure=self.household_structure,
            gender='M',
            age_in_years=25,
            study_resident='Yes',
            initials='EE')
        # who is an eligible subject
        EnrollmentChecklistFactory(household_member=household_member,
                                   gender='M',
                                   dob=date.today() - relativedelta(years=25),
                                   initials=household_member.initials,
                                   part_time_resident='Yes')
        # who is consented
        SubjectConsentFactory(
            household_member=household_member,
            gender='M',
            dob=date.today() - relativedelta(years=25),
            first_name='ERIKFIRST',
            last_name='ERIKLAST',
            initials=household_member.initials,
        )
        # the household is now enrolled
        self.assertTrue(
            household_member.household_structure.household.enrolled)
        # an ineligible member
        household_member = HouseholdMemberFactory(
            household_structure=self.household_structure,
            gender='M',
            age_in_years=65,
            study_resident='No')
        # who fails eligibility ...should not be able get to this via the interface
        EnrollmentChecklistFactory(household_member=household_member,
                                   gender='M',
                                   dob=date.today() - relativedelta(years=65),
                                   initials=household_member.initials,
                                   part_time_resident='No')
        # should only be eligible_htc
        self.assertFalse(household_member.eligible_member)
        self.assertFalse(household_member.eligible_subject)
        self.assertTrue(household_member.eligible_htc)
        self.assertFalse(household_member.is_consented)
        self.assertFalse(household_member.is_htc_only)
Пример #5
0
 def enrollment_checklist(self, household_member, guardian=None):
     return EnrollmentChecklistFactory(
         household_member=household_member,
         report_datetime=datetime.today(),
         gender=household_member.gender,
         dob=date.today() -
         relativedelta(years=household_member.age_in_years),
         guardian=NO or guardian,
         initials=household_member.initials,
         part_time_resident=household_member.study_resident)
Пример #6
0
    def setUp(self):
        site_mappers.autodiscover()
        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        self.app_config = BcppAppConfiguration()
        self.app_config.prepare()
        site_lab_tracker.autodiscover()
        BcppSubjectVisitSchedule().build()
        site_rule_groups.autodiscover()
        self.mapper = site_mappers.get_current_mapper()
#         self.app_config.prep_survey_for_tests()

        self.community = 'test_community'
        plot = PlotFactory(community=self.community, household_count=1, status='residential_habitable')

        survey = Survey.objects.all().order_by('datetime_start')[0]

        self.study_site = StudySite.objects.get(site_code='01')

        self.household_structure = HouseholdStructure.objects.get(household__plot=plot, survey=survey)
        RepresentativeEligibilityFactory(household_structure=self.household_structure)

        self.male_dob = date.today() - relativedelta(years=25)
        self.male_age_in_years = 25
        self.male_first_name = 'ERIK'
        self.male_initials = "EW"

        self.household_member_male_T0 = HouseholdMemberFactory(
            household_structure=self.household_structure, gender='M',
            age_in_years=self.male_age_in_years, first_name=self.male_first_name,
            initials=self.male_initials
        )

        EnrollmentChecklistFactory(
            household_member=self.household_member_male_T0,
            gender='M',
            citizen='Yes',
            dob=self.male_dob,
            guardian='No',
            initials=self.household_member_male_T0.initials,
            part_time_resident='Yes'
        )

        self.subject_consent_male = SubjectConsentFactory(household_member=self.household_member_male_T0, study_site=self.study_site, gender='M', dob=self.male_dob, first_name=self.male_first_name, initials=self.male_initials)

        self.registered_subject_male = RegisteredSubject.objects.get(subject_identifier=self.subject_consent_male.subject_identifier)

        self.appointment_male_T0 = Appointment.objects.get(registered_subject=self.registered_subject_male, visit_definition__code='T0')

        self.subject_visit_male_T0 = SubjectVisitFactory(appointment=self.appointment_male_T0, household_member=self.household_member_male_T0)
        SubjectLocatorFactory(registered_subject=self.subject_visit_male_T0.appointment.registered_subject, subject_visit=self.subject_visit_male_T0)
        self.household_member_T1 = None
        self.update_call_list_class = UpdateCallList()
Пример #7
0
 def test_enrollment_checklist_deleted_on_fail(self):
     household_member = HouseholdMemberFactory(
         household_structure=self.household_structure,
         gender='M',
         age_in_years=50,
         present_today='No',  # on day of survey
         study_resident='No')
     EnrollmentChecklistFactory(household_member=household_member,
                                gender='M',
                                dob=date.today() - relativedelta(years=50),
                                initials=household_member.initials,
                                part_time_resident='No')
     self.assertEqual(
         EnrollmentChecklist.objects.filter(
             household_member=household_member).count(), 0)
Пример #8
0
 def test_eligible_subject1(self):
     """Assert 'eligible' and 'is' flags  if passes enrollment checklist for BHS."""
     household_member = HouseholdMemberFactory(
         household_structure=self.household_structure,
         gender='M',
         age_in_years=50,
         present_today='No',  # on day of survey
         study_resident='Yes')
     EnrollmentChecklistFactory(household_member=household_member,
                                gender='M',
                                dob=date.today() - relativedelta(years=50),
                                initials=household_member.initials)
     self.assertTrue(household_member.eligible_member)
     self.assertTrue(household_member.eligible_subject)
     self.assertFalse(household_member.eligible_htc)
     self.assertFalse(household_member.is_consented)
     self.assertFalse(household_member.is_htc_only)
Пример #9
0
 def enroll_household(self, household_member=None):
     if not household_member:
         household_member = HouseholdMemberFactory(
             first_name='ERIK',
             initials='EW',
             age_in_years=18,
             present_today='Yes',
             study_resident='Yes',
             household_structure=self.household_structure,
             inability_to_participate=NOT_APPLICABLE)
     self.assertEquals(household_member.member_status, BHS_SCREEN)
     enrollment_checklist = EnrollmentChecklistFactory(
         household_member=household_member,
         report_datetime=datetime.today(),
         gender='M',
         dob=date.today() - relativedelta(years=18),
         guardian='No',
         initials=household_member.initials,
         part_time_resident='Yes')
     household_member = HouseholdMember.objects.get(
         pk=enrollment_checklist.household_member.pk)
     self.assertEquals(household_member.member_status, BHS_ELIGIBLE)
     from bhp066.apps.bcpp_subject.tests.factories import SubjectConsentFactory
     subject_consent = SubjectConsentFactory(
         household_member=household_member,
         registered_subject=household_member.registered_subject,
         first_name=household_member.first_name,
         last_name='WERIK',
         gender=household_member.gender,
         dob=date.today() - relativedelta(years=18),
         initials=household_member.initials,
         study_site=self.study_site,
     )
     household_member = HouseholdMember.objects.get(
         pk=subject_consent.household_member.pk)
     self.household_structure = household_member.household_structure
     self.assertEquals(household_member.member_status, BHS)
     self.assertTrue(self.household_structure.enrolled)
     self.assertTrue(self.household_structure.household.enrolled)
     self.assertTrue(self.household_structure.household.plot.bhs)
     return household_member
Пример #10
0
 def test_enrolled2(self):
     """Assert enrolled is True if eligible member consents."""
     SurveyFactory()
     plot = PlotFactory(community=self.mapper().map_area,
                        household_count=3,
                        status='residential_habitable')
     for household in Household.objects.filter(plot=plot):
         household_log = HouseholdLog.objects.get(
             household_structure__household=household)
         household_log_entry = HouseholdLogEntryFactory(
             household_log=household_log)
     household_structure = household_log.household_structure
     RepresentativeEligibilityFactory(
         household_structure=household_structure)
     HouseholdMemberFactory(household_structure=household_structure,
                            age_in_years=10)
     HouseholdMemberFactory(household_structure=household_structure,
                            age_in_years=74)
     household_member = HouseholdMemberFactory(
         household_structure=household_structure,
         age_in_years=25,
         initials='NN')
     HouseholdMemberFactory(household_structure=household_structure,
                            age_in_years=50)
     household_structure = HouseholdStructure.objects.get(
         pk=household_structure.pk)
     dob = date.today() - relativedelta(years=25)
     enrollment_checklist = EnrollmentChecklistFactory(
         household_member=household_member,
         report_datetime=household_member.created,
         dob=dob,
         initials='NN')
     self.assertFalse(household_structure.enrolled)
     self.assertTrue(enrollment_checklist.is_eligible)
     household_member = HouseholdMember.objects.get(pk=household_member.pk)
     SubjectConsentFactory(household_member=household_member,
                           dob=dob,
                           initials='NN')
     household_structure = HouseholdStructure.objects.get(
         pk=household_structure.pk)
     self.assertTrue(household_structure.enrolled)
Пример #11
0
    def test_eligible_subject2(self):
        """Assert 'eligible' and 'is' flags  if fails enrollment checklist for BHS but household not enrolled.

        Fails eligibility but is eligible for HTC by age."""
        household_member = HouseholdMemberFactory(
            household_structure=self.household_structure,
            gender='M',
            age_in_years=50,
            present_today='No',  # on day of survey
            study_resident='No')
        # should not be able get to this via the interface
        EnrollmentChecklistFactory(household_member=household_member,
                                   gender='M',
                                   dob=date.today() - relativedelta(years=50),
                                   initials=household_member.initials,
                                   part_time_resident='No')
        self.assertFalse(household_member.eligible_member)
        self.assertFalse(household_member.eligible_subject)
        self.assertFalse(household_member.eligible_htc)
        self.assertFalse(household_member.is_consented)
        self.assertFalse(household_member.is_htc_only)
    def test_eligible_htc_with_bhs_screen_option(self):
        """Assert for not eligible for BHS but eligible for HTC (household enrolled), but with option to still screen for BHS in case eligibility information changes"""
        #self.startup()
        household_member = self.enroll_household()
        household_member = HouseholdMemberFactory(first_name='ERIK', initials='EXW', age_in_years=64, study_resident='Yes', household_structure=household_member.household_structure)
        self.assertTrue(household_member.household_structure.enrolled)
        enrollment_checklist = EnrollmentChecklistFactory(
            household_member=household_member,
            gender='M',
            dob=date.today() - relativedelta(years=64),
            guardian='No',
            has_identity='No',
            initials=household_member.initials,
            part_time_resident='Yes')
        self.assertEqual(household_member.member_status, HTC_ELIGIBLE)
        options = [BHS_SCREEN, HTC_ELIGIBLE]
        options.append(enrollment_checklist.household_member.member_status)
        options = list(set(options))
        options.sort()
        member_status_choices = [(item, item) for item in options]
#         pprint.pprint(member_status_choices)
#         pprint.pprint(enrollment_checklist.household_member.member_status_choices)
        self.assertEqual(enrollment_checklist.household_member.member_status_choices, member_status_choices)
    def setUp(self):
        site_mappers.autodiscover()
        from bhp066.apps.bcpp_subject.visit_schedule import BcppSubjectVisitSchedule
        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        self.app_config = BcppAppConfiguration()
        self.app_config.prepare()
        self.app_config.prep_survey_for_tests()
        site_lab_tracker.autodiscover()
        BcppSubjectVisitSchedule().build()
        site_rule_groups.autodiscover()

        plot = PlotFactory(community=self.community,
                           household_count=1,
                           status='residential_habitable')

        self.survey_bhs = Survey.objects.get(survey_slug='bcpp-year-1')

        self.survey_ahs = Survey.objects.get(survey_slug='bcpp-year-2')

        self.study_site = StudySite.objects.get(site_code='01')

        self.household_structure_bhs = HouseholdStructure.objects.get(
            household__plot=plot, survey=self.survey_bhs)
        self.household_structure_ahs = HouseholdStructure.objects.get(
            household__plot=plot, survey=self.survey_ahs)
        self.create_household_log_entry(self.household_structure_bhs)

        RepresentativeEligibilityFactory(
            household_structure=self.household_structure_bhs)

        self.male_dob = date.today() - relativedelta(years=25)
        self.male_age_in_years = 25
        self.male_first_name = 'ERIK'
        self.male_last_name = 'HIEWAI'
        self.male_initials = "EW"

        self.household_member_male_T0 = HouseholdMemberFactory(
            household_structure=self.household_structure_bhs,
            gender='M',
            age_in_years=self.male_age_in_years,
            first_name=self.male_first_name,
            initials=self.male_initials)
        HeadHouseholdEligibilityFactory(
            household_member=self.household_member_male_T0,
            household_structure=self.household_structure_bhs)
        self.household_member_male_T0.eligible_hoh = True
        self.household_member_male_T0.save()

        HouseholdInfoFactory(household_member=self.household_member_male_T0,
                             household_structure=self.household_structure_bhs,
                             registered_subject=self.household_member_male_T0.
                             registered_subject)

        self.enrollment = EnrollmentChecklistFactory(
            household_member=self.household_member_male_T0,
            gender='M',
            citizen='Yes',
            dob=self.male_dob,
            guardian='No',
            initials=self.household_member_male_T0.initials,
            part_time_resident='Yes')
        self.subject_consent_male = SubjectConsentFactory(
            household_member=self.household_member_male_T0,
            confirm_identity='101119811',
            identity='101119811',
            study_site=self.study_site,
            gender='M',
            dob=self.male_dob,
            first_name=self.male_first_name,
            initials=self.male_initials)
        self.data = {
            'last_name':
            'WIZZY',
            'is_minor':
            'No',
            'witness_name':
            None,
            'is_literate':
            'Yes',
            'subject_type':
            'subject',
            'consent_copy':
            'Yes',
            'is_verified':
            False,
            'consent_signature':
            None,
            'first_name':
            'ERIK',
            'dm_comment':
            None,
            'is_dob_estimated':
            None,
            'verified_by':
            None,
            'user_modified':
            u'',
            'is_signed':
            True,
            'is_verified_datetime':
            None,
            'subject_identifier_aka':
            None,
            'version':
            u'4',
            'citizen':
            'Yes',
            'legal_marriage':
            u'N/A',
            'assessment_score':
            'Yes',
            'is_incarcerated':
            'No',
            'consent_reviewed':
            'Yes',
            'study_questions':
            'Yes',
            'sid':
            None,
            'study_site_id':
            self.study_site.id,
            'may_store_samples':
            YES,
            'consent_version_recent':
            None,
            'subject_identifier':
            self.household_member_male_T0.registered_subject.
            subject_identifier,
            'subject_identifier_as_pk':
            self.household_member_male_T0.registered_subject.id,
            'community':
            u'test_community',
            'using':
            'default',
            'marriage_certificate_no':
            None,
            'identity':
            '317918515',
            'confirm_identity':
            '317918515',
            'registered_subject_id':
            self.household_member_male_T0.registered_subject.id,
            'identity_type':
            'OMANG',
            'language':
            u'not specified',
            'guardian_name':
            None,
            'gender':
            'M',
            'household_member':
            self.household_member_male_T0.id,
            'marriage_certificate':
            u'N/A',
            'dob':
            self.male_dob,
            'study_site':
            self.study_site.id,
            'initials':
            'EW',
            'language':
            'en',
            'is_dob_estimated':
            '-',
            'consent_signature':
            YES,
            'consent_datetime':
            datetime.today(),
            'version':
            1
        }
Пример #14
0
    def test_p3(self):
        instances = []
        plot = PlotFactory(community='test_community6',
                           household_count=1,
                           status='residential_habitable')
        household = Household.objects.get(plot=plot)
        household_structure = HouseholdStructure.objects.get(
            survey=Survey.objects.all()[0])
        representative_eligibility = RepresentativeEligibilityFactory(
            household_structure=household_structure)
        household_member = HouseholdMemberFactory(
            household_structure=household_structure)
        enrollment_checklist = EnrollmentChecklistFactory(
            household_member=household_member,
            initials=household_member.initials,
            has_identity='Yes',
            dob=date(1989, 01, 01))
        self.assertTrue(enrollment_checklist.is_eligible)
        instances.append(enrollment_checklist)
        self.assertEqual(RegisteredSubject.objects.all().count(), 1)
        registered_subject = RegisteredSubject.objects.all()[0]
        site = StudySite.objects.all()[0]
        subject_consent = SubjectConsentFactory(
            study_site=site,
            household_member=household_member,
            registered_subject=household_member.registered_subject,
            dob=enrollment_checklist.dob,
            initials=enrollment_checklist.initials)
        instances.append(subject_consent)
        self.assertEqual(Appointment.objects.all().count(), 1)
        appointment = Appointment.objects.get(
            registered_subject=registered_subject)
        subject_visit = SubjectVisitFactory(household_member=household_member,
                                            appointment=appointment)
        instances.append(subject_visit)
        aliquot_type = AliquotType.objects.all()[0]
        panel = Panel.objects.all()[0]
        subjects_requisition = SubjectRequisitionFactory(
            subject_visit=subject_visit,
            panel=panel,
            site=site,
            aliquot_type=aliquot_type,
        )
        self.assertEqual(Aliquot.objects.all().count(), 0)
        subjects_requisition.is_receive = True
        subjects_requisition.is_receive_datetime = datetime.now()
        subjects_requisition.save()
        lab_profile = site_lab_profiles.get(
            subjects_requisition._meta.object_name)
        lab_profile().receive(subjects_requisition)
        receive = Receive.objects.all()[0]
        self.assertEqual(Aliquot.objects.all().count(), 1)
        aliquot = Aliquot.objects.all()[0]
        processing = ProcessingFactory(profile=AliquotProfile.objects.all()[0],
                                       aliquot=aliquot)
        for al in Aliquot.objects.all():
            instances.append(al)
        instances.append(processing)
        instances.append(receive)
        self.assertEqual(PackingListItem.objects.all().count(), 0)
        packing_list = PackingListFactory(
            list_items=aliquot.aliquot_identifier)
        instances.append(packing_list)
        packing_list.list_items = al.aliquot_identifier
        print packing_list.list_items
        packing_list.save()
        #self.assertEquals(PackingListItem.objects.all().count(), 1)
        #instances.append(PackingListItem.objects.all()[0])

        print 'INSTANCE: ' + str(instances)
        for obj in instances:
            print 'test natural key on {0}'.format(obj._meta.object_name)
            natural_key = obj.natural_key()
            get_obj = obj.__class__.objects.get_by_natural_key(*natural_key)
            self.assertEqual(obj.pk, get_obj.pk)
        # pp = pprint.PrettyPrinter(indent=4)
        for obj in instances:
            print 'test serializing/deserializing {0}'.format(
                obj._meta.object_name)
            outgoing_transaction = SerializeToTransaction().serialize(
                obj.__class__, obj, False, True, 'default')
            for transaction in serializers.deserialize(
                    "json",
                    FieldCryptor('aes',
                                 'local').decrypt(outgoing_transaction.tx)):
                self.assertEqual(transaction.object.pk, obj.pk)
    def setUp(self):
        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        BcppAppConfiguration().prepare()
        site_lab_tracker.autodiscover()
        BcppSubjectVisitSchedule().build()
        site_rule_groups.autodiscover()

        plot = PlotFactory(community=self.community,
                           household_count=1,
                           status='residential_habitable')

        survey_T0 = Survey.objects.get(survey_slug='bcpp-year-1')
        survey_T1 = Survey.objects.get(survey_slug='bcpp-year-2')
        survey_T2 = Survey.objects.get(survey_slug='bcpp-year-3')

        self.study_site = StudySite.objects.get(site_code='01')

        self.household_structure = HouseholdStructure.objects.get(
            household__plot=plot, survey=survey_T0)
        self.household_structure_y2 = HouseholdStructure.objects.get(
            household__plot=plot, survey=survey_T1)
        self.household_structure_y3 = HouseholdStructure.objects.get(
            household__plot=plot, survey=survey_T2)
        RepresentativeEligibilityFactory(
            household_structure=self.household_structure)
        RepresentativeEligibilityFactory(
            household_structure=self.household_structure_y2)
        RepresentativeEligibilityFactory(
            household_structure=self.household_structure_y3)
        HouseholdMemberFactory(household_structure=self.household_structure)
        #HouseholdMemberFactory(household_structure=self.household_structure)
        #HouseholdMemberFactory(household_structure=self.household_structure)

        male_dob = date.today() - relativedelta(years=25)
        male_age_in_years = 25
        male_first_name = 'ERIK'
        male_initials = "EW"
        female_dob = date.today() - relativedelta(years=35)
        female_age_in_years = 35
        female_first_name = 'ERIKA'
        female_initials = "EW"
        registered_subject = RegisteredSubjectFactory(
            registration_identifier='123456467')
        self.household_member_female_T0 = HouseholdMemberFactory(
            household_structure=self.household_structure,
            gender='F',
            age_in_years=female_age_in_years,
            first_name=female_first_name,
            initials=female_initials,
            registered_subject=registered_subject)
        registered_subject = RegisteredSubjectFactory(
            registration_identifier='123456468')
        self.household_member_male_T0 = HouseholdMemberFactory(
            household_structure=self.household_structure,
            gender='M',
            age_in_years=male_age_in_years,
            first_name=male_first_name,
            initials=male_initials,
            registered_subject=registered_subject)
        self.household_member_female_T0.member_status = 'BHS_SCREEN'
        self.household_member_male_T0.member_status = 'BHS_SCREEN'
        self.household_member_female_T0.save()
        self.household_member_male_T0.save()
        EnrollmentChecklistFactory(
            household_member=self.household_member_female_T0,
            gender='F',
            citizen=YES,
            dob=female_dob,
            guardian=NO,
            initials=self.household_member_female_T0.initials,
            part_time_resident=YES)
        EnrollmentChecklistFactory(
            household_member=self.household_member_male_T0,
            gender='M',
            citizen=YES,
            dob=male_dob,
            guardian=NO,
            initials=self.household_member_male_T0.initials,
            part_time_resident=YES)
        subject_consent_female = SubjectConsentFactory(
            household_member=self.household_member_female_T0,
            confirm_identity='101129811',
            identity='101129811',
            study_site=self.study_site,
            gender='F',
            dob=female_dob,
            first_name=female_first_name,
            initials=female_initials)
        subject_consent_male = SubjectConsentFactory(
            household_member=self.household_member_male_T0,
            confirm_identity='101119811',
            identity='101119811',
            study_site=self.study_site,
            gender='M',
            dob=male_dob,
            first_name=male_first_name,
            initials=male_initials)
        self.assertEqual(
            HouseholdStructure.objects.filter(
                household=self.household_structure.household,
                survey=survey_T0,
                enumerated=True,
                enrolled=True).count(), 1)

        enumeration_helper_T2 = EnumerationHelper(
            self.household_structure.household, survey_T0, survey_T1)
        enumeration_helper_T2.add_members_from_survey()
        self.household_member_female = HouseholdMember.objects.get(
            internal_identifier=self.household_member_female_T0.
            internal_identifier,
            household_structure__survey=survey_T1)
        self.household_member_male = HouseholdMember.objects.get(
            internal_identifier=self.household_member_male_T0.
            internal_identifier,
            household_structure__survey=survey_T1)
        self.assertEqual(
            HouseholdStructure.objects.filter(
                household=self.household_structure_y2.household,
                survey=survey_T1,
                enumerated=True,
                enrolled=True).count(), 1)

        enumeration_helper_T3 = EnumerationHelper(
            self.household_structure.household, survey_T1, survey_T2)
        enumeration_helper_T3.add_members_from_survey()
        self.household_member_female_T2 = HouseholdMember.objects.get(
            internal_identifier=self.household_member_female.
            internal_identifier,
            household_structure__survey=survey_T2)
        self.household_member_male_T2 = HouseholdMember.objects.get(
            internal_identifier=self.household_member_male.internal_identifier,
            household_structure__survey=survey_T2)
        self.assertEqual(
            HouseholdStructure.objects.filter(
                household=self.household_structure_y3.household,
                survey=survey_T2,
                enumerated=True,
                enrolled=True).count(), 1)

        self.registered_subject_female = RegisteredSubject.objects.get(
            subject_identifier=subject_consent_female.subject_identifier)
        self.registered_subject_male = RegisteredSubject.objects.get(
            subject_identifier=subject_consent_male.subject_identifier)
        self.appointment_female = Appointment.objects.get(
            registered_subject=self.registered_subject_female,
            visit_definition__code='T1')
        self.appointment_female_T0 = Appointment.objects.get(
            registered_subject=self.registered_subject_female,
            visit_definition__code='T0')
        self.appointment_female_T2 = Appointment.objects.get(
            registered_subject=self.registered_subject_female,
            visit_definition__code='T2')
        self.subject_visit_female_T0 = SubjectVisitFactory(
            appointment=self.appointment_female_T0,
            household_member=self.household_member_female_T0)
        self.subject_visit_female = SubjectVisitFactory(
            appointment=self.appointment_female,
            household_member=self.household_member_female)
        self.subject_visit_female_T2 = SubjectVisitFactory(
            appointment=self.appointment_female_T2,
            household_member=self.household_member_female_T2)
        self.appointment_male = Appointment.objects.get(
            registered_subject=self.registered_subject_male,
            visit_definition__code='T1')
        self.appointment_male_T0 = Appointment.objects.get(
            registered_subject=self.registered_subject_male,
            visit_definition__code='T0')
        self.appointment_male_T2 = Appointment.objects.get(
            registered_subject=self.registered_subject_male,
            visit_definition__code='T2')
        self.subject_visit_male_T0 = SubjectVisitFactory(
            appointment=self.appointment_male_T0,
            household_member=self.household_member_male_T0)
        self.subject_visit_male = SubjectVisitFactory(
            appointment=self.appointment_male,
            household_member=self.household_member_male)
        self.subject_visit_male_T2 = SubjectVisitFactory(
            appointment=self.appointment_male_T2,
            household_member=self.household_member_male_T2)
Пример #16
0
 def test_updates_household_structure_counts(self):
     """Assert household_member updates household structure member_count and enrolled_member_count."""
     self.assertEquals(self.household_structure.member_count, 0)
     self.assertEquals(self.household_structure.enrolled_member_count, 0)
     household_member = HouseholdMemberFactory(
         household_structure=self.household_structure,
         gender='M',
         age_in_years=25,
         study_resident='Yes',
         initials='EE')
     # who is an eligible subject
     EnrollmentChecklistFactory(household_member=household_member,
                                gender='M',
                                dob=date.today() - relativedelta(years=25),
                                initials=household_member.initials,
                                part_time_resident='Yes')
     self.assertEquals(
         HouseholdStructure.objects.get(
             pk=self.household_structure.pk).member_count, 1)
     self.assertEquals(
         HouseholdStructure.objects.get(
             pk=self.household_structure.pk).enrolled_member_count, 0)
     # who is consented
     SubjectConsentFactory(
         household_member=household_member,
         gender='M',
         dob=date.today() - relativedelta(years=25),
         first_name='ERIKFIRST',
         last_name='ERIKLAST',
         initials=household_member.initials,
     )
     self.assertTrue(household_member.is_consented)
     self.assertEquals(
         HouseholdStructure.objects.get(
             pk=self.household_structure.pk).member_count, 1)
     self.assertEquals(
         HouseholdStructure.objects.get(
             pk=self.household_structure.pk).enrolled_member_count, 1)
     household_member = HouseholdMemberFactory(
         household_structure=self.household_structure,
         gender='M',
         age_in_years=35,
         study_resident='Yes',
         initials='DD')
     # who is an eligible subject
     EnrollmentChecklistFactory(household_member=household_member,
                                gender='M',
                                dob=date.today() - relativedelta(years=35),
                                initials=household_member.initials,
                                part_time_resident='Yes')
     self.assertEquals(
         HouseholdStructure.objects.get(
             pk=self.household_structure.pk).member_count, 2)
     # who is consented
     SubjectConsentFactory(
         household_member=household_member,
         gender='M',
         dob=date.today() - relativedelta(years=35),
         first_name='DRIKFIRST',
         last_name='DRIKLAST',
         initials=household_member.initials,
     )
     self.assertEquals(
         HouseholdStructure.objects.get(
             pk=self.household_structure.pk).member_count, 2)
     self.assertEquals(
         HouseholdStructure.objects.get(
             pk=self.household_structure.pk).enrolled_member_count, 2)
Пример #17
0
    def test_p3(self):
        print 'get a community name from the mapper classes'
        mapper = site_mappers.get_current_mapper()
        community = mapper.map_area
        print 'No. of SURVEY = ' + str(Survey.objects.all().count())
        plot = PlotFactory(community=community, household_count=1, status='residential_habitable')
        print 'No. of HOUSEHOLDS = ' + str(Household.objects.all().count())
        Household.objects.get(plot=plot)
        self.assertEquals(HouseholdStructure.objects.all().count(), 3)
        self.assertEquals(Survey.objects.all().count(), 3)
        household_structure = HouseholdStructure.objects.get(survey=Survey.objects.all()[0])
        RepresentativeEligibilityFactory(household_structure=household_structure)
        household_member = HouseholdMemberFactory(household_structure=household_structure)
        enrollment_checklist = EnrollmentChecklistFactory(household_member=household_member, initials=household_member.initials, has_identity='Yes', dob=date(1989, 01, 01))
        study_site = StudySite.objects.all()[0]
        subject_consent = SubjectConsentFactory(study_site=study_site, household_member=household_member, registered_subject=household_member.registered_subject,
                                                dob=enrollment_checklist.dob, initials=enrollment_checklist.initials)
        print subject_consent.subject_identifier
        print 'get registered subject'
        registered_subject = RegisteredSubject.objects.get(subject_identifier=subject_consent.subject_identifier)
        instances = []
        instances.append(subject_consent)
        instances.append(registered_subject)

        print 'test natural key / get_by_natural_key on subject_visit'
        print 'No. of ENTRIES = ' + str(Entry.objects.all().count())
#         content_type = ContentType.objects.get(app_label='bcpp_subject', model='subjectvisit')
#         content_type_map = ContentTypeMap.objects.get(content_type=content_type)
        self.assertEqual(VisitDefinition.objects.all().count(), 2)
        visit_definition = VisitDefinition.objects.get(code='T0')
        print 'No. of Appointments = ' + str(Appointment.objects.all().count())
        appointment = Appointment.objects.get(visit_definition=visit_definition)
        # print 'No. of ScheduledEntryMetaData before Visit = '+str(ScheduledEntryMetaData.objects.all().count())
        subject_visit = SubjectVisitFactory(appointment=appointment, household_member=household_member)
        signals.post_save.disconnect(entry_meta_data_on_post_save, weak=False, dispatch_uid="entry_meta_data_on_post_save")

        aliquot_type = AliquotType.objects.all()[0]
        site = StudySite.objects.all()[0]
        microtube_panel = Panel.objects.get(name='Microtube')
        requisition1 = SubjectRequisitionFactory(subject_visit=subject_visit, panel=microtube_panel, aliquot_type=aliquot_type, site=site)
#         print requisition1.aliquot_type.numeric_code
        elisa_panel = Panel.objects.get(name='ELISA')
        requisition2 = SubjectRequisitionFactory(subject_visit=subject_visit, panel=elisa_panel, aliquot_type=aliquot_type, site=site)
        signals.post_save.connect(entry_meta_data_on_post_save, weak=False, dispatch_uid="entry_meta_data_on_post_save")
        subject_locator = SubjectLocatorFactory(subject_visit=subject_visit, registered_subject=registered_subject)
        year_1_survey = Survey.objects.get(survey_slug='bcpp-year-1')
        call_list = CallListFactory(household_member=household_member, label='call_label_1')
        call_log = CallLogFactory(household_member=household_member, survey=year_1_survey, label='call_label_1')
        call_log2 = CallLogFactory(household_member=household_member, survey=year_1_survey, label='call_label_2')
        call_log_entry = CallLogEntryFactory(call_log=call_log, survey=year_1_survey, call_datetime=datetime.now())
        call_log_entry2 = CallLogEntryFactory(call_log=call_log, survey=year_1_survey, call_datetime=datetime.now() + timedelta(minutes=3))
        instances.append(subject_locator)
        instances.append(requisition1)
        instances.append(requisition2)
        instances.append(call_log)
        instances.append(call_log2)
        instances.append(call_log_entry)
        instances.append(call_log_entry2)
        instances.append(call_list)

        print 'INSTANCE: ' + str(instances)
        for obj in instances:
            print 'test natural key on {0}'.format(obj._meta.object_name)
            natural_key = obj.natural_key()
            get_obj = obj.__class__.objects.get_by_natural_key(*natural_key)
            self.assertEqual(obj.pk, get_obj.pk)
        # pp = pprint.PrettyPrinter(indent=4)
        for obj in instances:
            print 'test serializing/deserializing {0}'.format(obj._meta.object_name)
            outgoing_transaction = SerializeToTransaction().serialize(obj.__class__, obj, False, True, 'default')
            # pp.pprint(FieldCryptor('aes', 'local').decrypt(outgoing_transaction.tx))
            for transaction in serializers.deserialize("json", FieldCryptor('aes', 'local').decrypt(outgoing_transaction.tx)):
                self.assertEqual(transaction.object.pk, obj.pk)
Пример #18
0
    def setUp(self):
        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        BcppAppConfiguration().prepare()
        site_lab_tracker.autodiscover()
        BcppSubjectVisitSchedule().build()
        site_rule_groups.autodiscover()

        plot = PlotFactory(community=self.community,
                           household_count=1,
                           status='residential_habitable')

        survey = Survey.objects.all().order_by('datetime_start')[0]

        self.study_site = StudySite.objects.get(site_code='14')

        self.household_structure = HouseholdStructure.objects.get(
            household__plot=plot, survey=survey)
        RepresentativeEligibilityFactory(
            household_structure=self.household_structure)
        HouseholdMemberFactory(household_structure=self.household_structure)

        self.male_dob = date.today() - relativedelta(years=25)
        self.male_age_in_years = 25
        self.male_first_name = 'ERIK'
        self.male_initials = "EW"
        female_dob = date.today() - relativedelta(years=35)
        female_age_in_years = 35
        female_first_name = 'ERIKA'
        female_initials = "EW"

        self.household_member_female_T0 = HouseholdMemberFactory(
            household_structure=self.household_structure,
            gender='F',
            age_in_years=female_age_in_years,
            first_name=female_first_name,
            initials=female_initials)
        self.household_member_male_T0 = HouseholdMemberFactory(
            household_structure=self.household_structure,
            gender='M',
            age_in_years=self.male_age_in_years,
            first_name=self.male_first_name,
            initials=self.male_initials)

        EnrollmentChecklistFactory(
            household_member=self.household_member_male_T0,
            gender='M',
            citizen='Yes',
            dob=self.male_dob,
            guardian='No',
            initials=self.household_member_male_T0.initials,
            part_time_resident='Yes')

        EnrollmentChecklistFactory(
            household_member=self.household_member_female_T0,
            gender='F',
            citizen='Yes',
            dob=female_dob,
            guardian='No',
            initials=self.household_member_female_T0.initials,
            part_time_resident='Yes')

        subject_consent_female = SubjectConsentFactory(
            household_member=self.household_member_female_T0,
            study_site=self.study_site,
            gender='F',
            dob=female_dob,
            first_name=female_first_name,
            initials=female_initials)
        self.subject_consent_male = SubjectConsentFactory(
            household_member=self.household_member_male_T0,
            study_site=self.study_site,
            gender='M',
            dob=self.male_dob,
            first_name=self.male_first_name,
            initials=self.male_initials)

        self.registered_subject_male = RegisteredSubject.objects.get(
            subject_identifier=self.subject_consent_male.subject_identifier)
        self.registered_subject_female = RegisteredSubject.objects.get(
            subject_identifier=subject_consent_female.subject_identifier)

        self.appointment_male_T0 = Appointment.objects.get(
            registered_subject=self.registered_subject_male,
            visit_definition__code='T0')
        self.appointment_female_T0 = Appointment.objects.get(
            registered_subject=self.registered_subject_female,
            visit_definition__code='T0')

        self.subject_visit_male_T0 = SubjectVisitFactory(
            appointment=self.appointment_male_T0,
            household_member=self.household_member_male_T0)
        self.subject_visit_female_T0 = SubjectVisitFactory(
            appointment=self.appointment_female_T0,
            household_member=self.household_member_female_T0)

        Quota.objects.create(app_label='bcpp_subject',
                             model_name='PimaVl',
                             target=1,
                             expires_datetime=timezone.now() +
                             timedelta(days=1))
        self.assertEqual(1, Quota.objects.all().count())
    def create_baseline(self, household):
        household_structure = HouseholdStructure.objects.get(
            household=household, survey=self.survey1)
        self.household_structure = household_structure
        RepresentativeEligibilityFactory(
            household_structure=household_structure)
        #         HouseholdMemberFactory(household_structure=household_structure)
        #         HouseholdMemberFactory(household_structure=household_structure)
        #         HouseholdMemberFactory(household_structure=household_structure)

        HouseholdMember = get_model('bcpp_household_member', 'HouseholdMember')

        self.household_member_female = HouseholdMember.objects.create(
            household_structure=household_structure,
            first_name='SUE',
            initials='SW',
            gender='F',
            age_in_years=25,
            study_resident='Yes',
            relation='sister',
            inability_to_participate=NOT_APPLICABLE)
        self.household_member_male = HouseholdMember.objects.create(
            household_structure=household_structure,
            first_name='ERIK',
            initials='EW',
            gender='M',
            age_in_years=25,
            study_resident='Yes',
            relation='brother',
            inability_to_participate=NOT_APPLICABLE)
        #         self.household_member_female.save()
        #         self.household_member_male.save()

        enrollment_male = EnrollmentChecklistFactory(
            household_member=self.household_member_male,
            initials=self.household_member_male.initials,
            gender=self.household_member_male.gender,
            dob=date.today() -
            relativedelta(years=self.household_member_male.age_in_years),
            guardian=NOT_APPLICABLE,
            part_time_resident='Yes',
            citizen='Yes')
        self.household_member_female = HouseholdMember.objects.get(
            pk=self.household_member_female.pk)

        enrollment_female = EnrollmentChecklistFactory(
            household_member=self.household_member_female,
            initials=self.household_member_female.initials,
            gender=self.household_member_female.gender,
            dob=date.today() -
            relativedelta(years=self.household_member_female.age_in_years),
            guardian=NOT_APPLICABLE,
            part_time_resident='Yes',
            citizen='Yes')
        self.household_member_male = HouseholdMember.objects.get(
            pk=self.household_member_male.pk)

        subject_consent_female = SubjectConsentFactory(
            consent_datetime=datetime.today(),
            household_member=self.household_member_female,
            registered_subject=self.household_member_female.registered_subject,
            gender='F',
            dob=enrollment_female.dob,
            first_name='SUE',
            last_name='W',
            citizen='Yes',
            confirm_identity='101129811',
            identity='101129811',
            initials=enrollment_female.initials,
            study_site=self.study_site)
        subject_consent_male = SubjectConsentFactory(
            consent_datetime=datetime.today(),
            household_member=self.household_member_male,
            registered_subject=self.household_member_male.registered_subject,
            gender='M',
            dob=enrollment_male.dob,
            first_name=self.household_member_male.first_name,
            last_name='W',
            citizen='Yes',
            confirm_identity='101119811',
            identity='101119811',
            initials=enrollment_male.initials,
            study_site=self.study_site)

        # FIXME: need this to be fixed, not getting gender right!
        self.registered_subject_female = RegisteredSubject.objects.get(
            subject_identifier=subject_consent_female.subject_identifier)
        self.registered_subject_male = RegisteredSubject.objects.get(
            subject_identifier=subject_consent_male.subject_identifier)
        appointment_female = Appointment.objects.get(
            registered_subject=self.registered_subject_female,
            visit_definition__time_point=0)
        self.subject_visit_female = SubjectVisitFactory(
            report_datetime=datetime.today(),
            appointment=appointment_female,
            household_member=self.household_member_female)
        appointment_male = Appointment.objects.get(
            registered_subject=self.registered_subject_male,
            visit_definition__time_point=0)
        self.subject_visit_male = SubjectVisitFactory(
            report_datetime=datetime.today(),
            appointment=appointment_male,
            household_member=self.household_member_male)
class TestSubjectConsentForm(TestCase):

    app_label = 'bcpp_subject'
    community = 'test_community'

    @override_settings(
        SITE_CODE='01',
        CURRENT_COMMUNITY='test_community',
        CURRENT_SURVEY='bcpp-year-2',
        CURRENT_COMMUNITY_CHECK=False,
        LIMIT_EDIT_TO_CURRENT_SURVEY=True,
        LIMIT_EDIT_TO_CURRENT_COMMUNITY=True,
        FILTERED_DEFAULT_SEARCH=True,
    )
    def setUp(self):
        site_mappers.autodiscover()
        from bhp066.apps.bcpp_subject.visit_schedule import BcppSubjectVisitSchedule
        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        self.app_config = BcppAppConfiguration()
        self.app_config.prepare()
        self.app_config.prep_survey_for_tests()
        site_lab_tracker.autodiscover()
        BcppSubjectVisitSchedule().build()
        site_rule_groups.autodiscover()

        plot = PlotFactory(community=self.community,
                           household_count=1,
                           status='residential_habitable')

        self.survey_bhs = Survey.objects.get(survey_slug='bcpp-year-1')

        self.survey_ahs = Survey.objects.get(survey_slug='bcpp-year-2')

        self.study_site = StudySite.objects.get(site_code='01')

        self.household_structure_bhs = HouseholdStructure.objects.get(
            household__plot=plot, survey=self.survey_bhs)
        self.household_structure_ahs = HouseholdStructure.objects.get(
            household__plot=plot, survey=self.survey_ahs)
        self.create_household_log_entry(self.household_structure_bhs)

        RepresentativeEligibilityFactory(
            household_structure=self.household_structure_bhs)

        self.male_dob = date.today() - relativedelta(years=25)
        self.male_age_in_years = 25
        self.male_first_name = 'ERIK'
        self.male_last_name = 'HIEWAI'
        self.male_initials = "EW"

        self.household_member_male_T0 = HouseholdMemberFactory(
            household_structure=self.household_structure_bhs,
            gender='M',
            age_in_years=self.male_age_in_years,
            first_name=self.male_first_name,
            initials=self.male_initials)
        HeadHouseholdEligibilityFactory(
            household_member=self.household_member_male_T0,
            household_structure=self.household_structure_bhs)
        self.household_member_male_T0.eligible_hoh = True
        self.household_member_male_T0.save()

        HouseholdInfoFactory(household_member=self.household_member_male_T0,
                             household_structure=self.household_structure_bhs,
                             registered_subject=self.household_member_male_T0.
                             registered_subject)

        self.enrollment = EnrollmentChecklistFactory(
            household_member=self.household_member_male_T0,
            gender='M',
            citizen='Yes',
            dob=self.male_dob,
            guardian='No',
            initials=self.household_member_male_T0.initials,
            part_time_resident='Yes')
        self.subject_consent_male = SubjectConsentFactory(
            household_member=self.household_member_male_T0,
            confirm_identity='101119811',
            identity='101119811',
            study_site=self.study_site,
            gender='M',
            dob=self.male_dob,
            first_name=self.male_first_name,
            initials=self.male_initials)
        self.data = {
            'last_name':
            'WIZZY',
            'is_minor':
            'No',
            'witness_name':
            None,
            'is_literate':
            'Yes',
            'subject_type':
            'subject',
            'consent_copy':
            'Yes',
            'is_verified':
            False,
            'consent_signature':
            None,
            'first_name':
            'ERIK',
            'dm_comment':
            None,
            'is_dob_estimated':
            None,
            'verified_by':
            None,
            'user_modified':
            u'',
            'is_signed':
            True,
            'is_verified_datetime':
            None,
            'subject_identifier_aka':
            None,
            'version':
            u'4',
            'citizen':
            'Yes',
            'legal_marriage':
            u'N/A',
            'assessment_score':
            'Yes',
            'is_incarcerated':
            'No',
            'consent_reviewed':
            'Yes',
            'study_questions':
            'Yes',
            'sid':
            None,
            'study_site_id':
            self.study_site.id,
            'may_store_samples':
            YES,
            'consent_version_recent':
            None,
            'subject_identifier':
            self.household_member_male_T0.registered_subject.
            subject_identifier,
            'subject_identifier_as_pk':
            self.household_member_male_T0.registered_subject.id,
            'community':
            u'test_community',
            'using':
            'default',
            'marriage_certificate_no':
            None,
            'identity':
            '317918515',
            'confirm_identity':
            '317918515',
            'registered_subject_id':
            self.household_member_male_T0.registered_subject.id,
            'identity_type':
            'OMANG',
            'language':
            u'not specified',
            'guardian_name':
            None,
            'gender':
            'M',
            'household_member':
            self.household_member_male_T0.id,
            'marriage_certificate':
            u'N/A',
            'dob':
            self.male_dob,
            'study_site':
            self.study_site.id,
            'initials':
            'EW',
            'language':
            'en',
            'is_dob_estimated':
            '-',
            'consent_signature':
            YES,
            'consent_datetime':
            datetime.today(),
            'version':
            1
        }

    def create_household_log_entry(self, household_structure):
        household_log = HouseholdLog.objects.filter(
            household_structure=household_structure).last()
        HouseholdLogEntry.objects.all().delete()
        HouseholdLogEntryFactory(household_log=household_log)

    @override_settings(
        SITE_CODE='01',
        CURRENT_COMMUNITY='test_community',
        CURRENT_SURVEY='bcpp-year-2',
        CURRENT_COMMUNITY_CHECK=False,
        LIMIT_EDIT_TO_CURRENT_SURVEY=True,
        LIMIT_EDIT_TO_CURRENT_COMMUNITY=True,
        FILTERED_DEFAULT_SEARCH=True,
    )
    def test_subject_consent_age_above_64_at_bhs(self):
        """ For all participants who are above 64 at bhs are not eligible."""
        from bhp066.apps.bcpp_subject.forms.subject_consent_form import SubjectConsentForm
        self.male_dob = date.today() - relativedelta(years=65)
        self.data['dob'] = self.male_dob
        self.data['household_member'] = self.household_member_male_T0.id
        consent_form = SubjectConsentForm(data=self.data)
        self.assertIn(
            u"Subject's age is 65y. Subject is not eligible for consent.",
            consent_form.errors.get("__all__"))

    @override_settings(
        SITE_CODE='01',
        CURRENT_COMMUNITY='test_community',
        CURRENT_SURVEY='bcpp-year-1',
        CURRENT_COMMUNITY_CHECK=False,
        LIMIT_EDIT_TO_CURRENT_SURVEY=True,
        LIMIT_EDIT_TO_CURRENT_COMMUNITY=True,
        FILTERED_DEFAULT_SEARCH=True,
    )
    def test_subject_consent_age_within_65_at_bhs(self):
        """ For all participants within 65 at bhs are eligible."""
        self.app_config.prep_survey_for_tests()
        self.subject_consent_male.version = 2
        self.subject_consent_male.save_base()
        from bhp066.apps.bcpp_subject.forms.subject_consent_form import SubjectConsentForm
        dob = date.today() - relativedelta(years=64)
        self.household_member_male_T0.age_in_years = 64
        self.household_member_male_T0.save()
        self.enrollment.dob = dob
        self.enrollment.save_base()
        self.data['dob'] = dob
        self.data['identity'] = '317918514'
        self.data['confirm_identity'] = '317918514'
        consent_form = SubjectConsentForm(data=self.data)
        print consent_form.errors
        consent_form.save()
        self.assertEqual(
            RegisteredSubject.objects.filter(
                identity=self.data['identity']).count(), 1)

    @override_settings(
        SITE_CODE='01',
        CURRENT_COMMUNITY='test_community',
        CURRENT_SURVEY='bcpp-year-2',
        CURRENT_COMMUNITY_CHECK=False,
        LIMIT_EDIT_TO_CURRENT_SURVEY=True,
        LIMIT_EDIT_TO_CURRENT_COMMUNITY=True,
        FILTERED_DEFAULT_SEARCH=True,
    )
    def test_subject_consent_age_above_64_at_ahs(self):
        """ Test identity on
        """

        dob = date.today() - relativedelta(years=65)
        self.household_member_male_T0.age_in_years = 65
        self.household_member_male_T0.save_base()
        self.subject_consent_male.dob = dob
        self.enrollment.dob = dob
        self.enrollment.save_base()
        self.subject_consent_male.save_base()

        self.app_config.prep_survey_for_tests()
        from bhp066.apps.bcpp_subject.forms.subject_consent_form import SubjectConsentForm

        enumeration_helper = EnumerationHelper(
            self.household_structure_ahs.household, self.survey_bhs,
            self.survey_ahs)
        enumeration_helper.add_members_from_survey()
        self.household_member = HouseholdMember.objects.get(
            registered_subject__identity='101119811',
            household_structure__survey=self.survey_ahs,
        )
        dob = date.today() - relativedelta(years=65)
        self.household_member.age_in_years = 65
        self.household_member.save_base()

        HeadHouseholdEligibilityFactory(
            household_member=self.household_member,
            household_structure=self.household_member.household_structure)
        self.enrollment.dob = dob
        self.enrollment.save_base()

        self.subject_consent = SubjectConsent.objects.get(
            household_member=self.household_member_male_T0)
        self.subject_consent.version = 2
        self.subject_consent.save_base()

        self.create_household_log_entry(self.household_structure_ahs)

        self.data['dob'] = dob
        self.data['household_member'] = self.household_member.id
        self.data['identity'] = '101119811'
        self.data['confirm_identity'] = '101119811'
        consent_form = SubjectConsentForm(data=self.data)
        print consent_form.errors
        self.assertTrue(consent_form.is_valid())

    @override_settings(
        SITE_CODE='01',
        CURRENT_COMMUNITY='test_community',
        CURRENT_SURVEY='bcpp-year-2',
        CURRENT_COMMUNITY_CHECK=False,
        LIMIT_EDIT_TO_CURRENT_SURVEY=True,
        LIMIT_EDIT_TO_CURRENT_COMMUNITY=True,
        FILTERED_DEFAULT_SEARCH=True,
    )
    def test_subject_consent_age_within_65_at_ahs(self):
        """ Test identity on
        """
        self.app_config.prep_survey_for_tests()
        from bhp066.apps.bcpp_subject.forms.subject_consent_form import SubjectConsentForm

        enumeration_helper = EnumerationHelper(
            self.household_structure_ahs.household, self.survey_bhs,
            self.survey_ahs)
        enumeration_helper.add_members_from_survey()
        self.household_member = HouseholdMember.objects.get(
            registered_subject__identity='101119811',
            household_structure__survey=self.survey_ahs)
        HeadHouseholdEligibilityFactory(
            household_member=self.household_member,
            household_structure=self.household_member.household_structure)
        self.subject_consent = SubjectConsent.objects.get(
            household_member=self.household_member_male_T0)
        self.subject_consent.version = 2
        self.subject_consent.save_base()

        self.data['household_member'] = self.household_member.id
        self.data['identity'] = '101119811'
        self.data['confirm_identity'] = '101119811'

        self.create_household_log_entry(self.household_structure_ahs)

        consent_form = SubjectConsentForm(data=self.data)
        self.assertTrue(consent_form.is_valid())

    @override_settings(
        SITE_CODE='01',
        CURRENT_COMMUNITY='test_community',
        CURRENT_SURVEY='bcpp-year-2',
        CURRENT_COMMUNITY_CHECK=False,
        LIMIT_EDIT_TO_CURRENT_SURVEY=True,
        LIMIT_EDIT_TO_CURRENT_COMMUNITY=True,
        FILTERED_DEFAULT_SEARCH=True,
    )
    def test_surname_marrige_at_ahs(self):
        """ Test identity on
        """
        self.app_config.prep_survey_for_tests()
        from bhp066.apps.bcpp_subject.forms.subject_consent_form import SubjectConsentForm
        enumeration_helper = EnumerationHelper(
            self.household_structure_ahs.household, self.survey_bhs,
            self.survey_ahs)
        enumeration_helper.add_members_from_survey()
        self.household_member = HouseholdMember.objects.get(
            registered_subject__identity='101119811',
            household_structure__survey=self.survey_ahs)
        self.household_member.personal_details_changed = YES
        self.household_member.details_change_reason = 'married'
        self.household_member.last_name = 'SETSIBA'
        self.household_member.initials = 'ES'
        self.household_member.save()

        self.create_household_log_entry(self.household_structure_ahs)

        HeadHouseholdEligibilityFactory(
            household_member=self.household_member,
            household_structure=self.household_member.household_structure)

        self.subject_consent = SubjectConsent.objects.get(
            household_member=self.household_member_male_T0)
        self.subject_consent.version = 2
        self.subject_consent.save_base()
        self.data['household_member'] = self.household_member.id
        self.data['identity'] = '101119811'
        self.data['confirm_identity'] = '101119811'
        self.data['last_name'] = 'SETSIBA'
        self.data['initials'] = 'ES'
        consent_form = SubjectConsentForm(data=self.data)
        self.assertTrue(consent_form.is_valid())
        consent_form.save()
        consent = SubjectConsent.objects.get(
            household_member=self.household_member)
        consent_form = SubjectConsentForm(data=self.data, instance=consent)
        consent_form.save()

    @override_settings(
        SITE_CODE='01',
        CURRENT_COMMUNITY='test_community',
        CURRENT_SURVEY='bcpp-year-1',
        CURRENT_COMMUNITY_CHECK=False,
        LIMIT_EDIT_TO_CURRENT_SURVEY=True,
        LIMIT_EDIT_TO_CURRENT_COMMUNITY=True,
        FILTERED_DEFAULT_SEARCH=True,
    )
    def test_validate_legal_marriage_at_bhs(self):
        self.data['citizen'] = NO
        self.data['identity'] = '101119811'
        self.data['confirm_identity'] = '101119811'
        from bhp066.apps.bcpp_subject.forms.subject_consent_form import SubjectConsentForm
        self.data['legal_marriage'] = YES
        self.data['marriage_certificate'] = YES
        self.data['marriage_certificate_no'] = '12421'
        self.enrollment.citizen = NO
        self.enrollment.save_base()
        consent_form = SubjectConsentForm(data=self.data)
        print consent_form.errors
        self.assertTrue(consent_form.is_valid())

    @override_settings(
        SITE_CODE='01',
        CURRENT_COMMUNITY='test_community',
        CURRENT_SURVEY='bcpp-year-1',
        CURRENT_COMMUNITY_CHECK=False,
        LIMIT_EDIT_TO_CURRENT_SURVEY=True,
        LIMIT_EDIT_TO_CURRENT_COMMUNITY=True,
        FILTERED_DEFAULT_SEARCH=True,
    )
    def test_validate_legal_marriage_at_bhs_not_valid(self):
        self.data['citizen'] = NO
        self.data['identity'] = '101119811'
        self.data['confirm_identity'] = '101119811'
        from bhp066.apps.bcpp_subject.forms.subject_consent_form import SubjectConsentForm
        self.data['legal_marriage'] = YES
        self.data['marriage_certificate'] = YES
        self.enrollment.citizen = NO
        self.enrollment.save_base()
        consent_form = SubjectConsentForm(data=self.data)
        self.assertIn(
            u'You wrote subject is NOT a citizen and has marriage certificate. Please provide certificate number.',
            consent_form.errors.get("__all__"))
        self.assertFalse(consent_form.is_valid())
Пример #21
0
    def setUp(self):
        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        BcppAppConfiguration().prepare()
        site_lab_tracker.autodiscover()
        BcppSubjectVisitSchedule().build()
        site_rule_groups.autodiscover()
        self.study_site = StudySite.objects.get(site_code='01')
        self.survey = Survey.objects.all()[0]
        plot = PlotFactory(community=self.community,
                           household_count=1,
                           status='residential_habitable')
        survey = Survey.objects.all().order_by('datetime_start')[0]
        next_survey = Survey.objects.all().order_by('datetime_start')[1]

        self.household_structure = HouseholdStructure.objects.get(
            household__plot=plot, survey=survey)
        self.household_structure_y2 = HouseholdStructure.objects.get(
            household__plot=plot, survey=next_survey)
        RepresentativeEligibilityFactory(
            household_structure=self.household_structure)
        RepresentativeEligibilityFactory(
            household_structure=self.household_structure_y2)

        self.female_dob = date(1989, 10, 10)
        self.female_age_in_years = relativedelta(date.today(),
                                                 self.female_dob).years
        self.female_first_name = 'ERIKA'
        self.female_last_name = 'WAXON'
        self.female_initials = "EW"

        self.household_member_female_T0 = HouseholdMemberFactory(
            household_structure=self.household_structure,
            gender='F',
            age_in_years=self.female_age_in_years,
            first_name=self.female_first_name,
            initials=self.female_initials)
        self.household_member_female_T0.member_status = 'BHS_SCREEN'
        self.household_member_female_T0.save()
        self.assertEqual(self.household_member_female_T0.member_status,
                         'BHS_SCREEN')
        self.enrollment_checklist_female = EnrollmentChecklistFactory(
            household_member=self.household_member_female_T0,
            gender='F',
            citizen='Yes',
            dob=self.female_dob,
            guardian='No',
            initials=self.household_member_female_T0.initials,
            part_time_resident='Yes')
        self.subject_consent_female = SubjectConsentFactory(
            household_member=self.household_member_female_T0,
            study_site=self.study_site,
            gender='F',
            dob=self.female_dob,
            first_name=self.female_first_name,
            last_name=self.female_last_name,
            initials=self.female_initials)
        self.registered_subject_female = RegisteredSubject.objects.get(
            subject_identifier=self.subject_consent_female.subject_identifier)

        enumeration_helper = EnumerationHelper(
            self.household_structure.household, survey, next_survey)
        self.household_member_female = enumeration_helper.create_member_on_target(
            self.household_member_female_T0)
        self.appointment_female = Appointment.objects.get(
            registered_subject=self.registered_subject_female,
            visit_definition__code='T1')
        self.appointment_female_T0 = Appointment.objects.get(
            registered_subject=self.registered_subject_female,
            visit_definition__code='T0')
        self.subject_visit_female_T0 = SubjectVisitFactory(
            appointment=self.appointment_female_T0,
            household_member=self.household_member_female_T0)
        self.subject_visit_female = SubjectVisitFactory(
            appointment=self.appointment_female,
            household_member=self.household_member_female)
        self.locator_female_T0 = SubjectLocatorFactory(
            subject_visit=self.subject_visit_female_T0,
            registered_subject=self.registered_subject_female)
        self.residency_mobility_female_T0 = ResidencyMobilityFactory(
            subject_visit=self.subject_visit_female_T0)
        microtube_panel = Panel.objects.get(name='Microtube')
        aliquot_type = AliquotType.objects.all()[0]
        self.subject_requisition_T0 = SubjectRequisitionFactory(
            subject_visit=self.subject_visit_female_T0,
            panel=microtube_panel,
            aliquot_type=aliquot_type)
        self.hiv_result_today_T0 = HivResultFactory(
            subject_visit=self.subject_visit_female_T0, hiv_result=NEG)
    def setUp(self):
        site_mappers.autodiscover()
        from bhp066.apps.bcpp_subject.visit_schedule import BcppSubjectVisitSchedule
        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        self.app_config = BcppAppConfiguration()
        self.app_config.prepare()
        self.app_config.prep_survey_for_tests()
        site_lab_tracker.autodiscover()
        BcppSubjectVisitSchedule().build()
        site_rule_groups.autodiscover()

        plot = PlotFactory(community=self.community,
                           household_count=1,
                           status='residential_habitable')

        self.survey_bhs = Survey.objects.get(survey_slug='bcpp-year-1')

        self.survey_ahs = Survey.objects.get(survey_slug='bcpp-year-2')

        self.study_site = StudySite.objects.get(site_code='01')

        self.household_structure_bhs = HouseholdStructure.objects.get(
            household__plot=plot, survey=self.survey_bhs)
        self.household_structure_ahs = HouseholdStructure.objects.get(
            household__plot=plot, survey=self.survey_ahs)
        self.create_household_log_entry(self.household_structure_bhs)

        RepresentativeEligibilityFactory(
            household_structure=self.household_structure_bhs)

        self.male_dob = date.today() - relativedelta(years=25)
        self.male_age_in_years = 25
        self.male_first_name = 'ERIK'
        self.male_last_name = 'HIEWAI'
        self.male_initials = "EW"

        self.household_member_male_T0 = HouseholdMemberFactory(
            household_structure=self.household_structure_bhs,
            gender='M',
            age_in_years=self.male_age_in_years,
            first_name=self.male_first_name,
            initials=self.male_initials)
        HeadHouseholdEligibilityFactory(
            household_member=self.household_member_male_T0,
            household_structure=self.household_structure_bhs)
        self.household_member_male_T0.eligible_hoh = True
        self.household_member_male_T0.save()

        HouseholdInfoFactory(household_member=self.household_member_male_T0,
                             household_structure=self.household_structure_bhs,
                             registered_subject=self.household_member_male_T0.
                             registered_subject)

        self.enrollment = EnrollmentChecklistFactory(
            household_member=self.household_member_male_T0,
            gender='M',
            citizen='Yes',
            dob=self.male_dob,
            guardian='No',
            initials=self.household_member_male_T0.initials,
            part_time_resident='Yes')
        self.subject_consent_male = SubjectConsentFactory(
            household_member=self.household_member_male_T0,
            confirm_identity='101119811',
            identity='101119811',
            study_site=self.study_site,
            gender='M',
            dob=self.male_dob,
            first_name=self.male_first_name,
            initials=self.male_initials)
        self.appointment = Appointment.objects.get(
            registered_subject=self.household_member_male_T0.
            registered_subject,
            visit_definition__code='T0')

        self.subject_visit = SubjectVisitFactory(
            household_member=self.household_member_male_T0,
            appointment=self.appointment)

        self.registered_subject = RegisteredSubject.objects.get(
            subject_identifier=self.subject_consent_male.subject_identifier)

        self.sexual_data = {
            'subject_visit': self.subject_visit.id,
            'alcohol_sex': 'Myself',
            'report_datetime': datetime.today(),
            'condom': NO,
            'more_sex': NO,
            'ever_sex': YES,
            'first_sex': 20,
            'last_year_partners': None,
            'lifetime_sex_partners': 1,
            'more_sex': None,
            'subject_visit_id': None,
            'user_modified': u'',
        }
        self.data = {
            'subject_visit': self.subject_visit.id,
            'concurrent': NO,
            'first_partner_live': None,
            'first_condom_freq': u'Sometimes',
            'first_disclose': u'Yes',
            'first_exchange': u'30-39',
            'first_first_sex': u'Years',
            'first_first_sex_calc': 3L,
            'first_haart': None,
            'first_partner_arm': None,
            'first_partner_cp': u'No',
            'first_partner_hiv': u'not_sure',
            'first_relationship': u'Long-term partner',
            'first_sex_current': u'Yes',
            'first_sex_freq': None,
            'goods_exchange': u'No',
            'partner_hiv_test': u'not_sure',
            'past_year_sex_freq': u'About once a month',
            'report_datetime': datetime.today(),
            'sex_partner_community': u'N/A',
            'subject_visit_id': None,
            'third_last_sex': u'Days',
            'third_last_sex_calc': 7L,
            'user_modified': u''
        }