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 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
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)
def test2(self): """Assert handles a member consented""" household_member = HouseholdMemberFactory( inability_to_participate=NOT_APPLICABLE, first_name='ERIK', initials='EW', age_in_years=64, study_resident='Yes', household_structure=self.household_structure) self.enrollment_checklist(household_member) # household_member.member_status = BHS_ELIGIBLE subject_consent = SubjectConsentFactory( household_member=household_member, initials=household_member.initials, last_name='WWW', dob=date.today() - relativedelta(years=64), identity='123456789', identity_type='OMANG') subject = Subject(household_member) self.assertEqual(subject.subject_consent, subject_consent)
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)
def setUp(self): try: site_lab_profiles.register(BcppSubjectProfile()) except AlreadyRegisteredLabProfile: pass BcppAppConfiguration() site_lab_tracker.autodiscover() BcppSubjectVisitSchedule().build() self.survey1 = Survey.objects.get(survey_name='BCPP Year 1') # see app_configuration site_mappers.autodiscover() mapper = site_mappers.get(site_mappers.get_as_list()[0]) self.community = mapper().get_map_area() gps_degrees_s, gps_minutes_s, gps_degrees_e, gps_minutes_e = mapper().test_location self.plot = PlotFactory(community=self.community, gps_degrees_s=gps_degrees_s, gps_minutes_s=gps_minutes_s, gps_degrees_e=gps_degrees_e, gps_minutes_e=gps_minutes_e, household_count=2, status='residential_habitable') self.household1 = Household.objects.filter(plot=self.plot).order_by('created')[0] self.household_structure1 = HouseholdStructure.objects.get(household=self.household1, survey=self.survey1) self.household2 = Household.objects.filter(plot=self.plot).order_by('created')[1] self.household_member1 = HouseholdMemberFactory(household_structure=self.household_structure1, age_in_years=26, present_today='Yes', member_status='RESEARCH') self.household_member2 = HouseholdMemberFactory(household_structure=self.household_structure1, age_in_years=36, present_today='Yes') self.household_member3 = HouseholdMemberFactory(household_structure=self.household_structure1, age_in_years=12, present_today='Yes') self.household_member4 = HouseholdMemberFactory(household_structure=self.household_structure1, age_in_years=99, present_today='Yes') self.dashboard_type = 'household' self.dashboard_model = 'household' self.dashboard_id = self.household1.pk self.household_member1.eligible_subject = True self.subject_consent = SubjectConsentFactory( household_member=self.household_member1, first_name=self.household_member1.first_name, initials=self.household_member1.initials, registered_subject=self.household_member1.registered_subject)
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
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)
class TestCorrectConsent(TestCase): app_label = 'bcpp_subject' community = 'test_community' 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 test_lastname_and_initials(self): correct_consent = CorrectConsentFactory( subject_consent=self.subject_consent_female, old_last_name=self.female_last_name, new_last_name='DIMSTAR', ) subject_consent = SubjectConsent.objects.get( id=self.subject_consent_female.id) self.assertEquals(subject_consent.initials, 'ED') self.assertEquals( EnrollmentChecklist.objects.get( id=self.enrollment_checklist_female.id).initials, 'ED') self.assertEquals(subject_consent.initials, 'ED') self.assertEquals(subject_consent.last_name, 'DIMSTAR') self.assertFalse(subject_consent.is_verified) self.assertIsNone(subject_consent.is_verified_datetime) self.assertIsNone(subject_consent.verified_by) if not correct_consent.id: self.assertEquals(subject_consent.user_modified, correct_consent.user_created) def test_firstname_and_initials(self): correct_consent = CorrectConsentFactory( subject_consent=self.subject_consent_female, old_first_name=self.female_first_name, new_first_name='GAME', ) subject_consent = SubjectConsent.objects.get( id=self.subject_consent_female.id) self.assertEquals( HouseholdMember.objects.get( id=self.household_member_female_T0.id).initials, 'GW') self.assertEquals( EnrollmentChecklist.objects.get( id=self.enrollment_checklist_female.id).initials, 'GW') self.assertEquals( HouseholdMember.objects.get( id=self.household_member_female_T0.id).first_name, 'GAME') self.assertEquals(subject_consent.first_name, 'GAME') self.assertFalse(subject_consent.is_verified) self.assertIsNone(subject_consent.is_verified_datetime) self.assertIsNone(subject_consent.verified_by) if not correct_consent.id: self.assertEquals(subject_consent.user_modified, correct_consent.user_created) def test_dob(self): hic = HicEnrollmentFactory(subject_visit=self.subject_visit_female_T0, dob=self.female_dob) new_dob = date(1988, 1, 1) age_in_years = relativedelta( self.subject_consent_female.consent_datetime, new_dob).years correct_consent = CorrectConsentFactory( subject_consent=self.subject_consent_female, old_dob=self.female_dob, new_dob=new_dob, ) subject_consent = SubjectConsent.objects.get( id=self.subject_consent_female.id) self.assertEquals( HouseholdMember.objects.get( id=self.household_member_female_T0.id).age_in_years, age_in_years) self.assertEquals( EnrollmentChecklist.objects.get( id=self.enrollment_checklist_female.id).dob, new_dob) self.assertEquals(subject_consent.dob, new_dob) self.assertEquals( HicEnrollment.objects.get( subject_visit=self.subject_visit_female_T0).dob, new_dob) self.assertFalse(subject_consent.is_verified) self.assertIsNone(subject_consent.is_verified_datetime) self.assertIsNone(subject_consent.verified_by) if not correct_consent.id: self.assertEquals(subject_consent.user_modified, correct_consent.user_created) self.assertEquals(hic.user_modified, correct_consent.user_created) def test_gender(self): correct_consent = CorrectConsentFactory( subject_consent=self.subject_consent_female, old_gender='F', new_gender='M', ) subject_consent = SubjectConsent.objects.get( id=self.subject_consent_female.id) self.assertEquals( HouseholdMember.objects.get( id=self.household_member_female_T0.id).gender, 'M') self.assertEquals( EnrollmentChecklist.objects.get( id=self.enrollment_checklist_female.id).gender, 'M') self.assertEquals(subject_consent.gender, 'M') self.assertFalse(subject_consent.is_verified) self.assertIsNone(subject_consent.is_verified_datetime) self.assertIsNone(subject_consent.verified_by) if not correct_consent.id: self.assertEquals(subject_consent.user_modified, correct_consent.user_created) def test_witness(self): self.subject_consent_female.witness_name = 'DIMO' self.subject_consent_female.save(update_fields=['witness_name']) correct_consent = CorrectConsentFactory( subject_consent=self.subject_consent_female, old_witness_name='DIMO', new_witness_name='BIMO', ) subject_consent = SubjectConsent.objects.get( id=self.subject_consent_female.id) self.assertEquals(subject_consent.witness_name, 'BIMO') self.assertFalse(subject_consent.is_verified) self.assertIsNone(subject_consent.is_verified_datetime) self.assertIsNone(subject_consent.verified_by) if not correct_consent.id: self.assertEquals(subject_consent.user_modified, correct_consent.user_created) def test_to_unverify_consent(self): self.subject_consent_female.witness_name = 'DIMO' self.assertFalse(self.subject_consent_female.is_verified) self.assertIsNone(self.subject_consent_female.is_verified_datetime) self.assertIsNone(self.subject_consent_female.verified_by) self.subject_consent_female.is_verified = True self.subject_consent_female.is_verified_datetime = datetime( 2016, 4, 18, 10, 3, 42, 215477) self.subject_consent_female.verified_by = 'ckgathi' self.subject_consent_female.save(update_fields=[ 'witness_name', 'verified_by', 'is_verified_datetime', 'is_verified' ]) self.assertTrue(self.subject_consent_female.is_verified) self.assertEqual(self.subject_consent_female.is_verified_datetime, datetime(2016, 4, 18, 10, 3, 42, 215477)) self.assertEqual(self.subject_consent_female.verified_by, 'ckgathi') correct_consent = CorrectConsentFactory( subject_consent=self.subject_consent_female, old_witness_name='DIMO', new_witness_name='BIMO', ) subject_consent = SubjectConsent.objects.get( id=self.subject_consent_female.id) self.assertEquals(subject_consent.witness_name, 'BIMO') self.assertFalse(self.subject_consent_female.is_verified) self.assertIsNone(self.subject_consent_female.is_verified_datetime) self.assertIsNone(self.subject_consent_female.verified_by) if not correct_consent.id: self.assertEquals(subject_consent.user_modified, correct_consent.user_created)
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 test_household_member1(self): # self.assertTrue(self.household_member.is_eligible) #Create with a < 16 DOB, should make member ineligible #enrollment_checklist.dob = datetime(2000,01,01) #enrollment_checklist.save() #Assert household member ineligible and put it back to its original value #self.assertEqual(household_member.member_status, 'NOT_ELIGIBLE') #enrollment_checklist.dob = datetime(1994,10,10) #household_member.member_status = 'BHS' #enrollment_checklist.save() #Edit enrollment checklist to make them a minor without guardian available self.enrollment_checklist.guardian = 'No' self.enrollment_checklist.dob = datetime(1998, 01, 01).date() #Assert household member ineligible and put back to normal self.household_member.age_in_years = 16 self.enrollment_checklist.save() #self.assertEqual(self.household_member.member_status, 'NOT_ELIGIBLE') self.assertFalse(self.household_member.eligible_subject) self.assertEqual(EnrollmentLoss.objects.all().count(), 1) EnrollmentLoss.objects.get( household_member=self.household_member).delete() self.enrollment_checklist.dob = datetime(1994, 01, 10).date() self.household_member.age_in_years = 20 #self.household_member.member_status = 'BHS' self.enrollment_checklist.guardian = 'Yes' self.enrollment_checklist.save() #Edit enrollment checklist to say they dont have identity self.enrollment_checklist.has_identity = 'No' self.enrollment_checklist.save() #Assert household member ineligible #self.assertEqual(self.household_member.member_status, 'NOT_ELIGIBLE') self.assertFalse(self.household_member.eligible_subject) self.assertEqual(EnrollmentLoss.objects.all().count(), 1) EnrollmentLoss.objects.get( household_member=self.household_member).delete() self.enrollment_checklist.has_identity = 'Yes' self.enrollment_checklist.save() #self.household_member.member_status = 'BHS' #Edit enrollment checklist to say they are a non-citizen married to citizen with valid marriage certificate. self.enrollment_checklist.citizen = 'No' self.enrollment_checklist.legal_marriage = 'Yes' self.enrollment_checklist.marriage_certificate = 'Yes' self.enrollment_checklist.save() #Assert household member is eligible #self.assertEqual(self.household_member.member_status, 'BHS') self.assertTrue(self.household_member.eligible_subject) #self.assertEqual(EnrollmentLoss.objects.all().count(),1) #EnrollmentLoss.objects.get(household_member=household_member).delete() self.enrollment_checklist.citizen = 'Yes' self.enrollment_checklist.legal_marriage = NOT_APPLICABLE self.enrollment_checklist.marriage_certificate = NOT_APPLICABLE self.enrollment_checklist.save() #self.household_member.member_status = 'BHS' #Edit enrollment checklist to say that they are part time residents self.enrollment_checklist.part_time_resident = 'No' self.enrollment_checklist.save() #Assert household member ineligible #self.assertEqual(self.household_member.member_status, 'NOT_ELIGIBLE') self.assertFalse(self.household_member.eligible_subject) self.assertEqual(EnrollmentLoss.objects.all().count(), 1) EnrollmentLoss.objects.get( household_member=self.household_member).delete() self.enrollment_checklist.part_time_resident = 'Yes' self.enrollment_checklist.save() self.household_member.member_status = 'BHS' #Edit enrollment to say that that they are an illitrate without a litirate witness available self.enrollment_checklist.literacy = 'No' self.enrollment_checklist.save() #Assert household member ineligible #self.assertEqual(self.household_member.member_status, 'NOT_ELIGIBLE') self.assertFalse(self.household_member.eligible_subject) self.assertEqual(EnrollmentLoss.objects.all().count(), 1) EnrollmentLoss.objects.get( household_member=self.household_member).delete() self.enrollment_checklist.literacy = 'Yes' self.enrollment_checklist.save() #self.household_member.member_status = 'BHS' #Edit enrollment checklist to say they are not a household resident self.enrollment_checklist.household_residency = 'No' self.enrollment_checklist.save() #Assert household member ineligible #self.assertEqual(self.household_member.member_status, 'NOT_ELIGIBLE') self.assertFalse(self.household_member.eligible_subject) self.assertEqual(EnrollmentLoss.objects.all().count(), 1) EnrollmentLoss.objects.get( household_member=self.household_member).delete() self.enrollment_checklist.household_residency = 'Yes' self.enrollment_checklist.save() #self.household_member.member_status = 'BHS' self.enrollment_checklist.dob = date(1997, 10, 10) self.enrollment_checklist.save() self.subject_consent = SubjectConsentFactory( dob=self.enrollment_checklist.dob, study_site=self.study_site, citizen='Yes', initials=self.enrollment_checklist.initials, household_member=self.household_member, registered_subject=self.household_member.registered_subject, guardian_name="THUSO, THUSO") print self.subject_consent.subject_identifier print 'get registered subject' self.registered_subject = RegisteredSubject.objects.get( subject_identifier=self.subject_consent.subject_identifier) #Assert that you cannot save enrollment checklist after consent entered #Attempt to change dob in consent thats used in enrollment checklist. self.subject_consent.dob = datetime(1971, 01, 01).date() #Assert consent for throwing error self.assertRaises(ValidationError, lambda: self.subject_consent.save()) self.subject_consent.dob = self.enrollment_checklist.dob #Attempt to change citizenship in consent thats used in enrollment checklist self.subject_consent.citizen = 'No' #Assert consent for throwing error self.assertRaises(ValidationError, lambda: self.subject_consent.save()) self.subject_consent.citizen = 'Yes' #Attempt to change Initials in consent to whats used in checklist self.subject_consent.initials = 'OO' #Assert consent throws error self.assertRaises(ValidationError, lambda: self.subject_consent.save()) self.subject_consent.initials = self.enrollment_checklist.initials # #Attempt to guardian status in consents to wats in enrollment checklist # self.enrollment_checklist.guardian = 'Yes' # #Assert consent throws errror # self.assertRaises(TypeError, lambda: self.subject_consent.save()) # self.enrollment_checklist.guardian = self.enrollment_checklist.initials #Attempt to change gender in consent to whats in enrollment checklist self.subject_consent.gender = 'F' #Assert consent throws error self.assertRaises(ValidationError, lambda: self.subject_consent.save()) self.subject_consent.gender = 'M' #Attempt to change marriage status of non citizen to whats different from checklist self.subject_consent.legal_marriage = 'Yes' self.subject_consent.marriage_certificate = 'Yes' #No consent error self.subject_consent.save()
class EnrollmentChecklistTests(TestCase): def __init__(self, *args, **kwargs): self.household_member = None self.subject_consent = None self.enrollment_checklist = None self.registered_subject = None self.study_site = None super(EnrollmentChecklistTests, self).__init__(*args, **kwargs) def setUp(self): try: site_lab_profiles.register(BcppSubjectProfile()) except AlreadyRegisteredLabProfile: pass BcppAppConfiguration() site_lab_tracker.autodiscover() BcppSubjectVisitSchedule().build() self.survey1 = Survey.objects.get( survey_name='BCPP Year 1') # see app_configuration plot = PlotFactory(community='test_community3', household_count=1, status='residential_habitable') household = Household.objects.get(plot=plot) self.household_structure = HouseholdStructure.objects.get( household=household, survey=self.survey1) def test_household_member1(self): # self.assertTrue(self.household_member.is_eligible) #Create with a < 16 DOB, should make member ineligible #enrollment_checklist.dob = datetime(2000,01,01) #enrollment_checklist.save() #Assert household member ineligible and put it back to its original value #self.assertEqual(household_member.member_status, 'NOT_ELIGIBLE') #enrollment_checklist.dob = datetime(1994,10,10) #household_member.member_status = 'BHS' #enrollment_checklist.save() #Edit enrollment checklist to make them a minor without guardian available self.enrollment_checklist.guardian = 'No' self.enrollment_checklist.dob = datetime(1998, 01, 01).date() #Assert household member ineligible and put back to normal self.household_member.age_in_years = 16 self.enrollment_checklist.save() #self.assertEqual(self.household_member.member_status, 'NOT_ELIGIBLE') self.assertFalse(self.household_member.eligible_subject) self.assertEqual(EnrollmentLoss.objects.all().count(), 1) EnrollmentLoss.objects.get( household_member=self.household_member).delete() self.enrollment_checklist.dob = datetime(1994, 01, 10).date() self.household_member.age_in_years = 20 #self.household_member.member_status = 'BHS' self.enrollment_checklist.guardian = 'Yes' self.enrollment_checklist.save() #Edit enrollment checklist to say they dont have identity self.enrollment_checklist.has_identity = 'No' self.enrollment_checklist.save() #Assert household member ineligible #self.assertEqual(self.household_member.member_status, 'NOT_ELIGIBLE') self.assertFalse(self.household_member.eligible_subject) self.assertEqual(EnrollmentLoss.objects.all().count(), 1) EnrollmentLoss.objects.get( household_member=self.household_member).delete() self.enrollment_checklist.has_identity = 'Yes' self.enrollment_checklist.save() #self.household_member.member_status = 'BHS' #Edit enrollment checklist to say they are a non-citizen married to citizen with valid marriage certificate. self.enrollment_checklist.citizen = 'No' self.enrollment_checklist.legal_marriage = 'Yes' self.enrollment_checklist.marriage_certificate = 'Yes' self.enrollment_checklist.save() #Assert household member is eligible #self.assertEqual(self.household_member.member_status, 'BHS') self.assertTrue(self.household_member.eligible_subject) #self.assertEqual(EnrollmentLoss.objects.all().count(),1) #EnrollmentLoss.objects.get(household_member=household_member).delete() self.enrollment_checklist.citizen = 'Yes' self.enrollment_checklist.legal_marriage = NOT_APPLICABLE self.enrollment_checklist.marriage_certificate = NOT_APPLICABLE self.enrollment_checklist.save() #self.household_member.member_status = 'BHS' #Edit enrollment checklist to say that they are part time residents self.enrollment_checklist.part_time_resident = 'No' self.enrollment_checklist.save() #Assert household member ineligible #self.assertEqual(self.household_member.member_status, 'NOT_ELIGIBLE') self.assertFalse(self.household_member.eligible_subject) self.assertEqual(EnrollmentLoss.objects.all().count(), 1) EnrollmentLoss.objects.get( household_member=self.household_member).delete() self.enrollment_checklist.part_time_resident = 'Yes' self.enrollment_checklist.save() self.household_member.member_status = 'BHS' #Edit enrollment to say that that they are an illitrate without a litirate witness available self.enrollment_checklist.literacy = 'No' self.enrollment_checklist.save() #Assert household member ineligible #self.assertEqual(self.household_member.member_status, 'NOT_ELIGIBLE') self.assertFalse(self.household_member.eligible_subject) self.assertEqual(EnrollmentLoss.objects.all().count(), 1) EnrollmentLoss.objects.get( household_member=self.household_member).delete() self.enrollment_checklist.literacy = 'Yes' self.enrollment_checklist.save() #self.household_member.member_status = 'BHS' #Edit enrollment checklist to say they are not a household resident self.enrollment_checklist.household_residency = 'No' self.enrollment_checklist.save() #Assert household member ineligible #self.assertEqual(self.household_member.member_status, 'NOT_ELIGIBLE') self.assertFalse(self.household_member.eligible_subject) self.assertEqual(EnrollmentLoss.objects.all().count(), 1) EnrollmentLoss.objects.get( household_member=self.household_member).delete() self.enrollment_checklist.household_residency = 'Yes' self.enrollment_checklist.save() #self.household_member.member_status = 'BHS' self.enrollment_checklist.dob = date(1997, 10, 10) self.enrollment_checklist.save() self.subject_consent = SubjectConsentFactory( dob=self.enrollment_checklist.dob, study_site=self.study_site, citizen='Yes', initials=self.enrollment_checklist.initials, household_member=self.household_member, registered_subject=self.household_member.registered_subject, guardian_name="THUSO, THUSO") print self.subject_consent.subject_identifier print 'get registered subject' self.registered_subject = RegisteredSubject.objects.get( subject_identifier=self.subject_consent.subject_identifier) #Assert that you cannot save enrollment checklist after consent entered #Attempt to change dob in consent thats used in enrollment checklist. self.subject_consent.dob = datetime(1971, 01, 01).date() #Assert consent for throwing error self.assertRaises(ValidationError, lambda: self.subject_consent.save()) self.subject_consent.dob = self.enrollment_checklist.dob #Attempt to change citizenship in consent thats used in enrollment checklist self.subject_consent.citizen = 'No' #Assert consent for throwing error self.assertRaises(ValidationError, lambda: self.subject_consent.save()) self.subject_consent.citizen = 'Yes' #Attempt to change Initials in consent to whats used in checklist self.subject_consent.initials = 'OO' #Assert consent throws error self.assertRaises(ValidationError, lambda: self.subject_consent.save()) self.subject_consent.initials = self.enrollment_checklist.initials # #Attempt to guardian status in consents to wats in enrollment checklist # self.enrollment_checklist.guardian = 'Yes' # #Assert consent throws errror # self.assertRaises(TypeError, lambda: self.subject_consent.save()) # self.enrollment_checklist.guardian = self.enrollment_checklist.initials #Attempt to change gender in consent to whats in enrollment checklist self.subject_consent.gender = 'F' #Assert consent throws error self.assertRaises(ValidationError, lambda: self.subject_consent.save()) self.subject_consent.gender = 'M' #Attempt to change marriage status of non citizen to whats different from checklist self.subject_consent.legal_marriage = 'Yes' self.subject_consent.marriage_certificate = 'Yes' #No consent error self.subject_consent.save()
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)
def test_p1(self): self.assertTrue(Household.objects.all().count() == 0) self.assertTrue(HouseholdStructure.objects.all().count() == 0) self.assertTrue(HouseholdMember.objects.all().count() == 0) site_lab_tracker.autodiscover() study_specific = StudySpecificFactory() StudySiteFactory() content_type_map_helper = ContentTypeMapHelper() content_type_map_helper.populate() content_type_map_helper.sync() ContentTypeMap.objects.get( model__iexact=SubjectConsent._meta.object_name) setup_dashboard( self) # creates 3 surveys a plot and two HH which -> 6 HHS print 'initialize the HH dashboard which will create HHS' print 'assert no survey for today\'s date' self.survey1.datetime_end = datetime.today() + relativedelta(days=-5) self.survey1.save() self.assertRaises(TypeError, HouseholdDashboard, self.dashboard_type, self.dashboard_id, self.dashboard_model) self.assertEquals(HouseholdStructure.objects.all().count(), 6) print 'update survey1 to include today' self.survey1.datetime_end = datetime.today() + relativedelta(days=+5) self.survey1.save() print 'try again, initialize the HH dashboard which will create HHS' self.household_dashboard = HouseholdDashboard(self.dashboard_type, self.dashboard_id, self.dashboard_model) print 'assert household structure exists for this HH and the three surveys' self.assertEquals( HouseholdStructure.objects.filter( household=self.household1).count(), 3) self.household_structure = self.household_dashboard.get_household_structure( ) print 'create another new HH in community {0}.'.format(self.community) self.assertEquals( HouseholdStructure.objects.filter( household=self.household2).count(), 3) print 'assert no additional hh structure created' self.assertEquals(HouseholdStructure.objects.all().count(), 6) # 2 surveys for each HH = 2 x 3 = 6 print 'create HH members for this survey and HH {0}'.format( self.household1) self.household_member1 = HouseholdMemberFactory( household_structure=self.household_structure) print 'household_member1.registered_subject.pk = {0}'.format( self.household_member1.registered_subject.pk) print 'household_member1.survey = {0}'.format( self.household_member1.survey) self.household_member2 = HouseholdMemberFactory( household_structure=self.household_structure) print self.household_member2.registered_subject.pk self.household_member3 = HouseholdMemberFactory( household_structure=self.household_structure) print self.household_member3.registered_subject.pk self.household_member4 = HouseholdMemberFactory( household_structure=self.household_structure) print self.household_member4.registered_subject.pk # this consent has a fk to registered subject # confirm that the signals do not create more than one registered # subject or anything like that. consent.rs must equal household_member.rs, etc self.assertEqual(Survey.objects.all().count(), 3) print 'assert one RS per HM' self.assertEqual(HouseholdMember.objects.all().count(), RegisteredSubject.objects.all().count()) print 'assert HM1.registered_subject.subject_identifier is a pk (not consented yet)' self.assertRegexpMatches( HouseholdMember.objects.get(pk=self.household_member1.pk). registered_subject.subject_identifier, self.re_pk) print 'consent household_member1' consent1 = SubjectConsentFactory( household_member=self.household_member1) self.assertEqual(Survey.objects.all().count(), 3) print consent1.subject_identifier print HouseholdMember.objects.get( pk=self.household_member1.pk).registered_subject.subject_identifier print 'assert consent1 household member is household_member1' print self.assertEqual(consent1.household_member.pk, self.household_member1.pk) print 'assert still one RS per HM' self.assertEqual(HouseholdMember.objects.all().count(), RegisteredSubject.objects.all().count()) print 'assert subject identifier on consent1 == subject identifier in registered_subject' self.assertEqual( consent1.subject_identifier, RegisteredSubject.objects.get( subject_identifier=consent1.subject_identifier). subject_identifier) print 'assert consent1 registered subject pk = household_member1 registered subject pk' self.assertEqual( consent1.registered_subject.pk, HouseholdMember.objects.get( pk=self.household_member1.pk).registered_subject.pk) print 'assert consent1 registered subject subject identifier = household_member1 registered subject subject_identifier' self.assertEqual( consent1.registered_subject.subject_identifier, HouseholdMember.objects.get(pk=self.household_member1.pk). registered_subject.subject_identifier) print 'assert cannot create a second consent for consented household_member1 {0}'.format( self.household_member1.survey) self.assertRaises(IdentifierError, SubjectConsentFactory, household_member=self.household_member1) # repeat for year 2, make a household_structure, members and consent, etc. # verify FK constraints do not prevent member, consent data # verify that subsequent surveys refer to the same registered subject # that being the one created from the first year print 'repeat for YEAR 2 for household1' print 'assert still have only 3 surveys' self.assertEqual(Survey.objects.all().count(), 3) print 'assert have 4 HHMs for household1 (from survey1' self.assertEqual(HouseholdMember.objects.all().count(), 4) print 'get a household dashboard for survey2 using HH2' self.dashboard_type = 'household' self.dashboard_model = 'household' self.dashboard_id = self.household1.pk print 'instantiate hHH dashboard with household' household_dashboard_survey2 = HouseholdDashboard(self.dashboard_type, self.dashboard_id, self.dashboard_model, survey=self.survey2) print household_dashboard_survey2 self.assertEqual(Survey.objects.all().count(), 3) print 'assert defaults to survey1, HHS for survey1' self.assertEqual(household_dashboard_survey2.get_survey(), self.survey1) self.assertEqual( household_dashboard_survey2.get_household_structure().survey, self.survey1) print 'get a household dashboard for survey2 using HH2' self.household_structure2 = HouseholdStructure.objects.get( household=self.household1, survey=self.survey2) self.dashboard_type = 'household' self.dashboard_model = 'household_structure' self.dashboard_id = self.household_structure2.pk household_dashboard_survey2 = HouseholdDashboard(self.dashboard_type, self.dashboard_id, self.dashboard_model, survey=self.survey2) household_dashboard_survey2 print 'confirm uses HHS2 and survey2' self.assertEqual(household_dashboard_survey2.get_survey(), self.survey2) self.assertEqual( household_dashboard_survey2.get_household_structure().survey, self.survey2) household_structure = household_dashboard_survey2.get_household_structure( ) self.assertEqual(Survey.objects.all().count(), 3) print 'assert household dashboard returns correct household structure if given survey2' self.assertEqual(household_structure.survey.pk, self.survey2.pk) print 'assert household dashboard returns correct household structure if given HH1' self.assertEqual(household_structure.household.pk, self.household1.pk) print 'household_structure={0}, plot={1}'.format( household_structure, household_structure.plot) print 'assert have 4 HHMs imported from first survey after instantiating dashboard' household_dashboard_survey2.get_context() self.assertEqual( HouseholdMember.objects.filter( household_structure=household_structure).count(), 4) print 'assert cannot create a household_member for this survey for known household members (because the dashboard created them)' self.assertRaises( IntegrityError, HouseholdMemberFactory, household_structure=household_structure, survey=self.survey2, registered_subject=self.household_member1.registered_subject) self.assertRaises( IntegrityError, HouseholdMemberFactory, household_structure=household_structure, survey=self.survey2, registered_subject=self.household_member2.registered_subject) self.assertRaises( IntegrityError, HouseholdMemberFactory, household_structure=household_structure, survey=self.survey2, registered_subject=self.household_member3.registered_subject) self.assertRaises( IntegrityError, HouseholdMemberFactory, household_structure=household_structure, survey=self.survey2, registered_subject=self.household_member4.registered_subject) # in BCPP, subject consent has a key to registered subject as does # household member. ensure both are pointing to the same registered_subject # not only for this survey but always. a household_member is created anew # for each survey but still refers to a common registered subject. the same # for the consent, a new consent for each survey but pointing to the same # registered_subject. household_member uses the registered_subject internal # identifier field to figure out which registered subject to use when # setting the attribute for subsequent surveys. print 'get a list of household members for the survey2 household dashboard' household_members = household_dashboard_survey2.get_household_members_as_list( ) household_member1 = household_members[0] print 'assert 8 household members' self.assertEqual(HouseholdMember.objects.all().count(), 8) print '... 4 for survey 1 and 4 for survey 2' self.assertEqual( HouseholdMember.objects.filter(survey=self.survey1).count(), 4) self.assertEqual( HouseholdMember.objects.filter(survey=self.survey2).count(), 4) print 'assert still 4 registered subjects' self.assertEqual(RegisteredSubject.objects.all().count(), 4) print 'assert one RS per 2 HM' self.assertEqual(HouseholdMember.objects.all().count(), RegisteredSubject.objects.all().count() * 2) print 'assert HM1.registered_subject.subject_identifier is a subject identifier (was consented in previous survey)' print HouseholdMember.objects.get( pk=household_member1.pk).registered_subject.subject_identifier print HouseholdMember.objects.get( pk=household_member1.pk ).registered_subject.subject_identifier_as_pk self.assertTrue( HouseholdMember.objects.get(pk=household_member1.pk). registered_subject.subject_identifier.startswith('066')) print 'consent household_member1 (it should find the existing registered subject and subject identifier)' consent1 = SubjectConsentFactory(household_member=household_member1) print consent1.subject_identifier print HouseholdMember.objects.get( pk=household_member1.pk).registered_subject.subject_identifier print 'assert consent1 household member is household_member1' print self.assertEqual(consent1.household_member.pk, household_member1.pk) print 'assert still one RS per HM' self.assertEqual(HouseholdMember.objects.all().count(), RegisteredSubject.objects.all().count() * 2) print 'assert subject identifier on consent1 == subject identifier in registered_subject' self.assertEqual( consent1.subject_identifier, RegisteredSubject.objects.get( subject_identifier=consent1.subject_identifier). subject_identifier) print 'assert consent1 registered subject pk = household_member1 registered subject pk' self.assertEqual( consent1.registered_subject.pk, HouseholdMember.objects.get( pk=household_member1.pk).registered_subject.pk) print 'assert consent1 registered subject subject identifier = household_member1 registered subject subject_identifier' self.assertEqual( consent1.registered_subject.subject_identifier, HouseholdMember.objects.get( pk=household_member1.pk).registered_subject.subject_identifier) print 'assert consent1 registered subject pk = household_member1 registered subject pk for previous survey' self.assertEqual( consent1.registered_subject.pk, HouseholdMember.objects.get( pk=self.household_member1.pk).registered_subject.pk)
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)
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)