def get_consent_object(self): try: household_member = self.subject_visit.household_member except AttributeError: household_member = self.household_member if household_member.anonymous: consent_object = site_consents.get_consent( consent_model=self._meta.anonymous_consent_model, consent_group=settings.ANONYMOUS_CONSENT_GROUP, report_datetime=self.report_datetime) else: consent_object = site_consents.get_consent( consent_model=self._meta.consent_model, report_datetime=self.report_datetime) return consent_object
def consent_object(self): """Returns the consent model. """ default_consent_group = django_apps.get_app_config( 'edc_consent').default_consent_group consent_object = site_consents.get_consent( report_datetime=self.object.report_datetime, consent_group=default_consent_group) return consent_object
def consent_object(self): if not self._consent_object: if self.anonymous: anonymous_consent_group = django_apps.get_app_config( 'bcpp_consent').anonymous_consent_group try: self._consent_object = site_consents.get_consent( report_datetime=self.report_datetime, consent_group=anonymous_consent_group) except ConsentDoesNotExist: self._consent_object = None else: default_consent_group = django_apps.get_app_config( 'edc_consent').default_consent_group try: self._consent_object = site_consents.get_consent( report_datetime=self.report_datetime, consent_group=default_consent_group) except ConsentDoesNotExist: self._consent_object = None return self._consent_object
def get_consent(self, subject_identifier, report_datetime): """Return an instance of the consent model. """ cleaned_data = self.cleaned_data if cleaned_data.get('household_member').anonymous: consent_object = site_consents.get_consent( report_datetime=report_datetime, consent_group=settings.ANONYMOUS_CONSENT_GROUP, consent_model=self._meta.model._meta.anonymous_consent_model) else: consent_object = site_consents.get_consent( report_datetime=report_datetime, consent_group=self._meta.model._meta.consent_group, consent_model=self._meta.model._meta.consent_model) try: obj = consent_object.model.consent.consent_for_period( subject_identifier=subject_identifier, report_datetime=report_datetime) except consent_object.model.DoesNotExist: raise forms.ValidationError( '\'{}\' does not exist to cover this subject on {}.'.format( consent_object.model._meta.verbose_name, report_datetime=report_datetime.strftime('Y%-%m-%d %Z'))) return obj
def setUp(self): django_apps.app_configs['edc_device'].device_id = '99' self.survey_schedule_object = site_surveys.get_survey_schedules()[0] self.household_structure = self.member_helper.make_household_ready_for_enumeration( make_hoh=False, report_datetime=self.survey_schedule_object.start) household_status = ELIGIBLE_REPRESENTATIVE_PRESENT mommy.make_recipe('household.householdlogentry', report_datetime=get_utcnow(), household_log=self.household_structure.householdlog, household_status=household_status) # add another member, OK! household_member = self.member_helper.add_household_member( self.household_structure, relation='Mother') enrollment_checklist = mommy.make_recipe( 'member.enrollmentchecklist', household_member=household_member, report_datetime=self.household_structure.report_datetime, dob=(self.household_structure.report_datetime - relativedelta(years=household_member.age_in_years)).date(), gender=household_member.gender, initials=household_member.initials, ) # fake values fake_identity = fake.credit_card_number() last_name = fake.last_name().upper() initials = enrollment_checklist.initials last_name = initials[1] + last_name options = { 'identity': '317115159', 'confirm_identity': '317115159', } try: registered_subject = RegisteredSubject.objects.get( registration_identifier=household_member.internal_identifier) except RegisteredSubject.DoesNotExist: identity = options.get('identity', fake_identity) confirm_identity = options.get('confirm_identity', fake_identity) dob = options.get('dob', enrollment_checklist.dob) else: identity = options.get('identity', registered_subject.identity) confirm_identity = options.get('confirm_identity', registered_subject.identity) dob = registered_subject.dob self.report_datetime = self.get_utcnow() consent_object = site_consents.get_consent( report_datetime=self.report_datetime, consent_model='bcpp_subject.subjectconsent') consent_options = dict( first_name=household_member.first_name, last_name=last_name, consent_datetime=self.report_datetime, version=consent_object.version, dob=dob, gender=options.get('gender', enrollment_checklist.gender), initials=initials, is_literate=options.get('is_literate', enrollment_checklist.literacy), witness_name=options.get( 'witness_name', fake.last_name() if enrollment_checklist.literacy == NO else None), legal_marriage=options.get('legal_marriage', enrollment_checklist.legal_marriage), marriage_certificate=options.get( 'marriage_certificate', enrollment_checklist.marriage_certificate), guardian_name=options.get( 'guardian_name', fake.name() if enrollment_checklist.guardian == YES else None), identity=identity, confirm_identity=confirm_identity) # add subject consent self.subject_consent = SubjectConsent.objects.create( household_member=household_member, survey_schedule=household_member.survey_schedule_object. field_value, **consent_options) SubjectLocator.objects.create( subject_identifier=self.subject_consent.subject_identifier, report_datetime=self.report_datetime, alt_contact_cell_number='72200111', has_alt_contact=NO, alt_contact_name=None, alt_contact_rel=None, alt_contact_cell=None, other_alt_contact_cell='760000111', alt_contact_tel=None)
def add_subject_consent(self, household_member=None, survey_schedule=None, **options): """Returns a subject consent. * Consents the given `household_member`. If `household_member`=None will create one using `options` then consent him/her. * Adds the enrollment checklist for the `household_member`, if it does not exist. * Creates a HoH household member if one does not already exist. """ if household_member and survey_schedule: raise TestMixinError( 'If \'household_member\' is specified, \'survey_' 'schedule\' is not required.') if not household_member: survey_schedule = survey_schedule or self.get_survey_schedule(0) household_structure = self.make_household_ready_for_enumeration( make_hoh=False, survey_schedule=survey_schedule) household_member = self.add_household_member( household_structure, relation=HEAD_OF_HOUSEHOLD, **options) self.assertTrue(household_member.eligible_member) else: household_structure = household_member.household_structure try: enrollment_checklist = EnrollmentChecklist.objects.get( household_member=household_member) self.assertTrue(enrollment_checklist.is_eligible) except EnrollmentChecklist.DoesNotExist: self.assertTrue(household_member.eligible_member) household_member = self.add_enrollment_checklist( household_member, **options) household_member = HouseholdMember.objects.get( pk=household_member.pk) self.assertTrue(household_member.eligible_subject) enrollment_checklist = household_member.enrollmentchecklist # update options for subject consent from enrollment checklist report_datetime = options.get('report_datetime') or self.get_utcnow() consent_object = site_consents.get_consent( report_datetime=report_datetime, consent_model='bcpp_subject.subjectconsent') # fake values fake_identity = fake.credit_card_number() last_name = fake.last_name().upper() initials = options.get('initials', enrollment_checklist.initials) last_name = initials[1] + last_name # if RegisteredSubject exists, use those values unless # explicitly provided through 'options' # see UpdatesOrCreatesRegistrationModelMixin in subject_consent try: registered_subject = RegisteredSubject.objects.get( registration_identifier=household_member.internal_identifier) except RegisteredSubject.DoesNotExist: identity = options.get('identity', fake_identity) confirm_identity = options.get('confirm_identity', fake_identity) dob = options.get('dob', enrollment_checklist.dob) else: identity = options.get('identity', registered_subject.identity) confirm_identity = options.get('confirm_identity', registered_subject.identity) dob = options.get('dob', registered_subject.dob) consent_options = dict( first_name=household_member.first_name, last_name=last_name, version=consent_object.version, consent_datetime=report_datetime, dob=dob, gender=options.get('gender', enrollment_checklist.gender), initials=initials, is_literate=options.get('is_literate', enrollment_checklist.literacy), witness_name=options.get( 'witness_name', fake.last_name() if enrollment_checklist.literacy == NO else None), legal_marriage=options.get('legal_marriage', enrollment_checklist.legal_marriage), marriage_certificate=options.get( 'marriage_certificate', enrollment_checklist.marriage_certificate), guardian_name=options.get( 'guardian_name', fake.name() if enrollment_checklist.guardian == YES else None), identity=identity, confirm_identity=confirm_identity) # add subject consent with transaction.atomic(): try: subject_consent = mommy.make_recipe( 'bcpp_subject.subjectconsent', household_member=household_member, survey_schedule=household_member.survey_schedule_object. field_value, **consent_options) except IntegrityError: subject_consent = None if not subject_consent: # subject consent not added, fetching existing subject_consent = SubjectConsent.objects.get( subject_identifier=household_member.subject_identifier, version=consent_object.version) return subject_consent