def setup(self):
     site_lab_tracker.autodiscover()
     StudySpecificFactory()
     StudySiteFactory()
     content_type_map_helper = ContentTypeMapHelper()
     content_type_map_helper.populate()
     content_type_map_helper.sync()
     visit_tracking_content_type_map = ContentTypeMap.objects.get(content_type__model__iexact='TestVisit')
     self.visit_definition = VisitDefinitionFactory(code='9999', title='Test', visit_tracking_content_type_map=visit_tracking_content_type_map)
     self.registered_subject = RegisteredSubjectFactory(subject_identifier='062-7982139-3', subject_type='maternal')
     study_site = StudySiteFactory(site_code='99', site_name='test site')
     self.appointment = AppointmentFactory(
         appt_datetime=datetime.today(),
         best_appt_datetime=datetime.today(),
         appt_status=NEW_APPT,
         study_site=study_site,
         visit_definition=self.visit_definition,
         registered_subject=self.registered_subject,
         )
     # create a admin_user
     self.admin_user = User.objects.create(username='******', password='******')
     self.admin_user.set_password('1234')
     self.admin_user.is_staff = True
     self.admin_user.is_active = True
     self.admin_user.is_superuser = True
     self.admin_user.save()
    def setUp(self):

        from bhp066.apps.bcpp.app_configuration.classes import BcppAppConfiguration

        self.household_structure = None
        self.registered_subject = None
        self.representative_eligibility = None
        self.study_site = None
        self.intervention = None

        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        BcppAppConfiguration().prepare()
        site_lab_tracker.autodiscover()
        BcppSubjectVisitSchedule().build()

        self.survey1 = Survey.objects.get(survey_name='BCPP Year 2')  # see app_configuration
        plot = PlotFactory(community='digawana', household_count=1, status='residential_habitable')
        household = Household.objects.get(plot=plot)
        self.household_structure = HouseholdStructure.objects.get(household=household, survey=self.survey1)
        self.representative_eligibility = RepresentativeEligibilityFactory(household_structure=self.household_structure)
        self.study_site = StudySite.objects.get(site_code=site_mappers.get_current_mapper().map_code)
        self.intervention = site_mappers.get_registry(settings.CURRENT_COMMUNITY)().intervention
    def test_is_new_appointment(self):
        """
        is_new_appointment() should return False if not "new" and "new" must be listed in the choices tuple.
        """
        site_lab_tracker.autodiscover()
        StudySpecificFactory()
        StudySiteFactory()
        content_type_map_helper = ContentTypeMapHelper()
        content_type_map_helper.populate()
        content_type_map_helper.sync()
 
        appointment = Appointment()
        dte = datetime.today()
        appointment.appt_datetime = dte
        self.assertEqual(appointment.is_new_appointment(), True, 'Expected is_new_appointment() to return True for appt_status=\'{0}\'. Got \'{1}\''.format(appointment.appt_status, appointment.is_new_appointment()))
        appointment.appt_status = COMPLETE_APPT
        self.assertEqual(appointment.is_new_appointment(), False, 'Expected is_new_appointment() to return False for appt_status=\'{0}\'. Got \'{1}\''.format(appointment.appt_status, appointment.is_new_appointment()))
        appointment.appt_status = 'incomplete'
        self.assertEqual(appointment.is_new_appointment(), False, 'Expected is_new_appointment() to return False for appt_status=\'{0}\'. Got \'{1}\''.format(appointment.appt_status, appointment.is_new_appointment()))
        appointment.appt_status = 'cancelled'
        self.assertEqual(appointment.is_new_appointment(), False, 'Expected is_new_appointment() to return False for appt_status=\'{0}\'. Got \'{1}\''.format(appointment.appt_status, appointment.is_new_appointment()))
        is_found_new = False
        for choice in APPT_STATUS:
            appointment.appt_status = choice[0]
            if appointment.appt_status == NEW_APPT:
                # flag to show "new" exists in tuple
                is_found_new = True
                self.assertEqual(appointment.is_new_appointment(), True)
            else:
                # all other cases return False
                self.assertEqual(appointment.is_new_appointment(), False)
        # test "new" case exists in choices
        self.assertEqual(is_found_new, True)
예제 #4
0
 def setUp(self):
     try:
         site_lab_profiles.register(MpepuMaternalProfile())
     except AlreadyRegistered:
         pass
     MpepuAppConfiguration().prepare()
     site_lab_tracker.autodiscover()
     site_visit_schedules.autodiscover()
     site_visit_schedules.build_all()
     study_site = StudySiteFactory()
     MaternalConsent.objects.all().delete()
     self.maternal_consent1 = MaternalConsentFactory(study_site=study_site)
     print "Maternal Consent: {}".format(self.maternal_consent1)
     self.registered_subject1 = RegisteredSubject.objects.get(
         subject_identifier=self.maternal_consent1.subject_identifier)
     self.post_elibility1 = MaternalEligibilityPostFactory(
         maternal_consent=self.maternal_consent1,
         registered_subject=self.registered_subject1)
     self.maternal_consent2 = MaternalConsentFactory(study_site=study_site)
     print "Maternal Consent: {}".format(self.maternal_consent2)
     self.registered_subject2 = RegisteredSubject.objects.get(
         subject_identifier=self.maternal_consent2.subject_identifier)
     self.post_elibility2 = MaternalEligibilityPostFactory(
         maternal_consent=self.maternal_consent2,
         registered_subject=self.registered_subject2)
     self.maternal_consent3 = MaternalConsentFactory(study_site=study_site)
     print "Maternal Consent: {}".format(self.maternal_consent3)
     self.registered_subject3 = RegisteredSubject.objects.get(
         subject_identifier=self.maternal_consent3.subject_identifier)
     self.post_elibility3 = MaternalEligibilityPostFactory(
         maternal_consent=self.maternal_consent3,
         registered_subject=self.registered_subject3)
예제 #5
0
 def setUp(self):
     try:
         site_lab_profiles.register(BcppSubjectProfile())
     except AlreadyRegisteredLabProfile:
         pass
     BcppAppConfiguration()
     site_lab_tracker.autodiscover()
     BcppSubjectVisitSchedule().build()
 def setUp(self):
     try:
         site_lab_profiles.register(MpepuMaternalProfile())
     except AlreadyRegistered:
         pass
     MpepuAppConfiguration().prepare()
     site_lab_tracker.autodiscover()
     site_visit_schedules.autodiscover()
     site_visit_schedules.build_all()
예제 #7
0
 def startup(self):
     from bhp066.apps.bcpp.app_configuration.classes import BcppAppConfiguration
     try:
         site_lab_profiles.register(BcppSubjectProfile())
     except AlreadyRegisteredLabProfile:
         pass
     BcppAppConfiguration()
     site_lab_tracker.autodiscover()
     BcppSubjectVisitSchedule().build()
예제 #8
0
 def setUp(self):
     try:
         site_lab_profiles.register(ClinicSubjectProfile())
     except AlreadyRegisteredLabProfile:
         pass
     site_mappers.autodiscover()
     BcppAppConfiguration().prepare()
     site_lab_tracker.autodiscover()
     BcppClinicVisitSchedule().build()
예제 #9
0
 def startup(self):
     try:
         site_lab_profiles.register(TestLabProfile())
     except AlreadyRegisteredLabProfile:
         pass
     TestAppConfiguration()
     site_lab_tracker.autodiscover()
     TestVisitSchedule().build()
     self.study_site = StudySite.objects.all()[0]
예제 #10
0
 def setUp(self):
     try:
         site_lab_profiles.register(BcppSubjectProfile())
     except AlreadyRegisteredLabProfile:
         pass
     site_mappers.autodiscover()
     BcppAppConfiguration.confirm_site_code_in_settings = False
     BcppAppConfiguration().prepare()
     site_lab_tracker.autodiscover()
     BcppSubjectVisitSchedule().build()
예제 #11
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()
    def setUp(self):

        site_mappers.autodiscover()

        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        bcpp_app_configuration.prepare()
        site_lab_tracker.autodiscover()
        BcppSubjectVisitSchedule().build()
        site_rule_groups.autodiscover()

        self.household_structure = None
        self.registered_subject = None
        self.representative_eligibility = None
        self.study_site = None
        self.intervention = None

        self.community = site_mappers.get_current_mapper().map_area
        self.study_site = StudySite.objects.get(
            site_code=site_mappers.get_current_mapper().map_code)
        self.site_code = self.study_site
        self.intervention = site_mappers.get_current_mapper().intervention
        self.survey1 = Survey.objects.get(
            survey_name='BCPP Year 1')  # see app_configuration
        self.survey2 = Survey.objects.get(
            survey_name='BCPP Year 2')  # see app_configuration
        plot = PlotFactory(community=self.community,
                           household_count=1,
                           status='residential_habitable')
        household = Household.objects.get(plot=plot)
        self.create_baseline(household)

        self.data = {
            'household_member': self.household_member_male.id,
            'report_datetime': datetime.today(),
            'first_name': 'SETS',
            'initials': 'SA',
            'dob': datetime.today() + relativedelta(years=-20),
            'guardian': NO,
            'gender': MALE,
            'has_identity': YES,
            'identity': '317918515',
            'identity_type': 'OMANG',
            'citizen': YES,
            'part_time_resident': YES,
            'literacy': YES,
            'guardian': YES,
            'inability_to_participate': 'N/A',
            'hiv_status': 'NEG',
            'legal_marriage': 'N/A',
            'marriage_certificate': 'N/A'
        }
예제 #13
0
    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
 def setUp(self):
     try:
         site_lab_profiles.register(HnsccSubjectProfile())
     except AlreadyRegistered:
         pass
     HnsccAppConfiguration().prepare()
     site_lab_tracker.autodiscover()
     site_visit_schedules.autodiscover()
     site_visit_schedules.build_all()
     print "assert appointment is created for enrolled subject"
     self.enrolled_subject = EnrolledSubjectFactory()
     self.appointment = Appointment.objects.get(registered_subject=self.enrolled_subject.registered_subject)
예제 #15
0
 def setUp(self):
     try:
         site_lab_profiles.register(MpepuInfantProfile())
     except AlreadyRegistered:
         pass
     MpepuAppConfiguration().prepare()
     site_lab_tracker.autodiscover()
     site_visit_schedules.autodiscover()
     site_visit_schedules.build_all()
     study_site = StudySiteFactory()
     content_type_map = ContentTypeMap.objects.get(
         model='maternalconsent', app_label='mpepu_maternal')
     consent_catalogue = ConsentCatalogueFactory(
         content_type_map=content_type_map)
     consent_catalogue.add_for_app = 'mpepu_infant'
     consent_catalogue.save()
     delivery_days_ago = 20
     self.delivery_datetime = datetime.today() - timedelta(
         days=delivery_days_ago - 3)
     print "Consent a mother"
     self.maternal_consent = MaternalConsentFactory(
         study_site=study_site,
         consent_datetime=datetime.today() -
         timedelta(days=delivery_days_ago))
     print "Consent: {}".format(self.maternal_consent)
     m_registered_subject = RegisteredSubject.objects.get(
         subject_identifier=self.maternal_consent.subject_identifier)
     print 'check if mother is eligible'
     self.maternal_eligibility = MaternalEligibilityPostFactory(
         maternal_consent=self.maternal_consent,
         registered_subject=m_registered_subject,
         registration_datetime=datetime.today() -
         timedelta(days=delivery_days_ago))
     print 'get the 2000M visit'
     self.m_appointment = Appointment.objects.get(
         registered_subject=m_registered_subject,
         visit_definition__code='2000M')
     print 'create a maternal visit for the 2000M visit'
     self.maternal_visit = MaternalVisitFactory(
         appointment=self.m_appointment,
         report_datetime=datetime.today() -
         timedelta(days=delivery_days_ago))
     print 'create a maternal_lab_del registering 2 of 2 infants'
     self.maternal_lab_del = MaternalLabDelFactory(
         maternal_visit=self.maternal_visit,
         live_infants=1,
         live_infants_to_register=1,
         delivery_datetime=self.delivery_datetime,
         has_ga='Yes',
         ga=37,
     )
     print 'maternal lab del: {}'.format(self.maternal_lab_del)
예제 #16
0
 def setUp(self):
     try:
         site_lab_profiles.register(MpepuInfantProfile())
     except AlreadyRegistered:
         pass
     MpepuAppConfiguration().prepare()
     site_lab_tracker.autodiscover()
     site_visit_schedules.autodiscover()
     site_visit_schedules.build_all()
     self.study_site = StudySiteFactory()
     content_type_map = ContentTypeMap.objects.get(model='maternalconsent', app_label='mpepu_maternal')
     consent_catalogue = ConsentCatalogueFactory(content_type_map=content_type_map)
     consent_catalogue.add_for_app = 'mpepu_infant'
     consent_catalogue.save()
예제 #17
0
    def setUp(self):

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

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

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

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

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

        self.test_rule_group_sched_cls = TestRuleGroupSched

        self.test_visit_factory = TestVisitFactory

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

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

        self.registered_subject = RegisteredSubject.objects.get(subject_identifier=self.test_consent.subject_identifier)
        self.appointment = Appointment.objects.get(registered_subject=self.registered_subject)
예제 #18
0
 def setUp(self):
     self.test_visit_factory = TestVisitFactory
     try:
         site_lab_profiles.register(TestLabProfile())
     except AlreadyRegisteredLabProfile:
         pass
     TestAppConfiguration()
     site_lab_tracker.autodiscover()
     TestVisitSchedule().rebuild()
     study_site = StudySite.objects.all()[0]
     subject_consent = TestConsentWithMixinFactory(study_site=study_site)
     self.registered_subject = RegisteredSubject.objects.get(subject_identifier=subject_consent.subject_identifier)
     self.consent = TestConsentWithMixin.objects.get(registered_subject=self.registered_subject)
     appointment = Appointment.objects.get(registered_subject=self.registered_subject)
     self.test_visit = TestVisitFactory(appointment=appointment)
예제 #19
0
    def setUp(self):
        site_lab_tracker.autodiscover()
        StudySpecificFactory()
        study_site = StudySiteFactory()
        content_type_map_helper = ContentTypeMapHelper()
        content_type_map_helper.populate()
        content_type_map_helper.sync()

#         content_type_map = ContentTypeMap.objects.get(content_type__model='testconsentwithmixin')
#         consent_catalogue = ConsentCatalogueFactory(name='v1', content_type_map=content_type_map)
#         consent_catalogue.add_for_app = 'bhp_base_test'
#         consent_catalogue.save()

        self.test_visit_schedule = TestVisitSchedule()
        self.test_visit_schedule.build()
예제 #20
0
    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)
예제 #21
0
    def setUp(self):
        try:
            site_lab_profiles.register(TestLabProfile())
        except AlreadyRegisteredLabProfile:
            pass
        site_lab_tracker.autodiscover()

        TestAppConfiguration()

        TestVisitSchedule().rebuild()

        self.test_visit_factory = TestVisitFactory
        self.study_site = StudySite.objects.all()[0]
        self.visit_definition = VisitDefinition.objects.get(code='1000')
        self.test_consent = TestConsentWithMixinFactory(gender='M', study_site=self.study_site)
        self.registered_subject = RegisteredSubject.objects.get(subject_identifier=self.test_consent.subject_identifier)
        self.appointment_count = VisitDefinition.objects.all().count()
        self.appointment = Appointment.objects.get(registered_subject=self.registered_subject, visit_definition__code='1000')
    def test_maternal_eligibility(self):

        site_lab_tracker.autodiscover()
        study_specific = StudySpecificFactory()
        StudySiteFactory()

        content_type_map_helper = ContentTypeMapHelper()
        content_type_map_helper.populate()
        content_type_map_helper.sync()
        content_type_map = ContentTypeMap.objects.get(
            model__iexact=ResistanceConsent._meta.object_name)
        ConsentCatalogueFactory(
            name=self.app_label,
            content_type_map=content_type_map,
            consent_type='sub-study',
            version=1,
            start_datetime=study_specific.study_start_datetime,
            end_datetime=datetime(datetime.today().year + 5, 1, 1),
            add_for_app=self.app_label)

        maternal_consent = MaternalConsentFactory(first_name='MELISSA',
                                                  gender='F',
                                                  dob='1994-03-25',
                                                  identity='111121111')
        self.assertEqual(MaternalConsent.objects.all().count(), 1)
        print maternal_consent.subject_identifier
        resistance_consent = ResistanceConsentFactory(first_name='MELISSA',
                                                      gender='F',
                                                      dob='1994-03-25',
                                                      identity='111121111')
        self.assertEqual(ResistanceConsent.objects.all().count(), 1)
        print resistance_consent.subject_identifier
        print 'resistance consent does exists'

        print 'assert there is no eligibility'
        self.assertEqual(ResistanceEligibility.objects.all().count(), 0)

        print 'create eligibility for mother'
        eligibility = ResistanceEligibilityFactory(co_enrolled='Yes',
                                                   status_evidence='Yes',
                                                   lates_cd4=250,
                                                   who_illness='No')
        self.assertEqual(ResistanceEligibility.objects.all().count(), 1)
        print eligibility
    def startup(self):

        site_mappers.autodiscover()

        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        bcpp_app_configuration.prepare()
        site_lab_tracker.autodiscover()
        BcppSubjectVisitSchedule().build()
        site_rule_groups.autodiscover()
        #         site_visit_schedules.autodiscover()
        #         site_visit_schedules.build_all()

        self.household_structure = None
        self.registered_subject = None
        self.representative_eligibility = None
        self.study_site = None
        self.intervention = None
        #         try:
        #             site_lab_profiles.register(BcppSubjectProfile())
        #         except AlreadyRegisteredLabProfile:
        #             pass
        #         BcppAppConfiguration()
        #         site_lab_tracker.autodiscover()
        #         BcppSubjectVisitSchedule().build()

        self.community = site_mappers.get_current_mapper().map_area
        self.study_site = StudySite.objects.get(
            site_code=site_mappers.get_current_mapper().map_code)
        self.site_code = self.study_site
        self.intervention = site_mappers.get_current_mapper().intervention
        self.survey1 = Survey.objects.get(
            survey_name='BCPP Year 1')  # see app_configuration
        self.survey2 = Survey.objects.get(
            survey_name='BCPP Year 2')  # see app_configuration
        plot = PlotFactory(community=self.community,
                           household_count=1,
                           status='residential_habitable')
        household = Household.objects.get(plot=plot)
        self.create_baseline(household)
        self.create_annual(household)
예제 #24
0
    def setUp(self):

        from bhp066.apps.bcpp.app_configuration.classes import BcppAppConfiguration

        self.household_structure = None
        self.registered_subject = None
        self.representative_eligibility = None
        self.study_site = None
        self.intervention = None

        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        site_mappers.autodiscover()
        # set current community manually (not from settings)
        site_mappers.current_community = 'test_community'
        BcppAppConfiguration.study_start_datetime = datetime.today(
        ) + relativedelta(days=-2)
        BcppAppConfiguration.study_end_datetime = datetime.today(
        ) + relativedelta(days=45)
        bcpp_app_configuration = BcppAppConfiguration()
        # bypass any check of site_code and community against settings
        bcpp_app_configuration.confirm_site_code_in_settings = False
        bcpp_app_configuration.confirm_community_in_settings = False
        bcpp_app_configuration.prepare()
        site_lab_tracker.autodiscover()
        BcppSubjectVisitSchedule().build()

        self.survey1 = Survey.objects.get(
            survey_name='BCPP Year 1')  # see app_configuration
        plot = PlotFactory(community='test_community',
                           household_count=1,
                           status='residential_habitable')
        household = Household.objects.get(plot=plot)
        self.household_structure = HouseholdStructure.objects.get(
            household=household, survey=self.survey1)
        self.representative_eligibility = RepresentativeEligibilityFactory(
            household_structure=self.household_structure)
        self.study_site = StudySite.objects.get(
            site_code=site_mappers.get_current_mapper().map_code)
        self.intervention = site_mappers.get_current_mapper().intervention
예제 #25
0
    def setUp(self):
        self.household_member = None
        self.subject_consent = None
        self.registered_subject = None
        try:
            site_lab_profiles.register(BcppSubjectProfile())
        except AlreadyRegisteredLabProfile:
            pass
        bcpp_app_configuration.prepare()
        site_lab_tracker.autodiscover()
        site_visit_schedules.autodiscover()
        site_visit_schedules.build_all()

        self.survey = Survey.objects.current_survey()
        self.plot = PlotFactory(community='oodi', household_count=1, status='bcpp_clinic')
        self.household = HouseholdFactory(plot=self.plot)
        self.household_structure = HouseholdStructure.objects.get(household=self.household, survey=self.survey)
        self.study_site = StudySite.objects.get(site_code=site_mappers.get_current_mapper().map_code)
        self.intervention = site_mappers.get_current_mapper().intervention
        site_mappers.get_current_mapper().verify_survey_dates()
예제 #26
0
    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 setUp(self):
        from edc.testing.tests.factories import TestVisitFactory
        self.test_visit_factory = TestVisitFactory
        site_lab_tracker.autodiscover()
        study_specific = StudySpecificFactory()
        StudySiteFactory()
        content_type_map_helper = ContentTypeMapHelper()
        content_type_map_helper.populate()
        content_type_map_helper.sync()
        content_type_map = ContentTypeMap.objects.get(content_type__model='TestConsentWithMixin'.lower())
        ConsentCatalogueFactory(
            name=self.app_label,
            consent_type='study',
            content_type_map=content_type_map,
            version=1,
            start_datetime=study_specific.study_start_datetime,
            end_datetime=datetime(datetime.today().year + 5, 1, 1),
            add_for_app=self.app_label)
        membership_form = MembershipFormFactory(content_type_map=content_type_map, category='subject')
        schedule_group = ScheduleGroupFactory(membership_form=membership_form, group_name='GROUP_NAME', grouping_key='GROUPING_KEY')
        visit_tracking_content_type_map = ContentTypeMap.objects.get(content_type__model='testvisit')
        self.visit_definition = VisitDefinitionFactory(code='T0', title='T0', grouping='subject', visit_tracking_content_type_map=visit_tracking_content_type_map)
        self.visit_definition.schedule_group.add(schedule_group)

        # add entries
        content_type_map = ContentTypeMap.objects.get(app_label='testing', model='testscheduledmodel1')
        EntryFactory(content_type_map=content_type_map, visit_definition=self.visit_definition, entry_order=100, entry_category='clinic', app_label='testing', model_name='testscheduledmodel1')
        content_type_map = ContentTypeMap.objects.get(app_label='testing', model='testscheduledmodel2')
        EntryFactory(content_type_map=content_type_map, visit_definition=self.visit_definition, entry_order=110, entry_category='clinic', app_label='testing', model_name='testscheduledmodel2')
        content_type_map = ContentTypeMap.objects.get(app_label='testing', model='testscheduledmodel3')
        EntryFactory(content_type_map=content_type_map, visit_definition=self.visit_definition, entry_order=120, entry_category='clinic', app_label='testing', model_name='testscheduledmodel3')

        # add requisitions
        LabEntryFactory(visit_definition=self.visit_definition, entry_order=100)
        LabEntryFactory(visit_definition=self.visit_definition, entry_order=110)
        LabEntryFactory(visit_definition=self.visit_definition, entry_order=120)

        self.test_consent = TestConsentWithMixinFactory(gender='M')

        self.registered_subject = RegisteredSubject.objects.get(subject_identifier=self.test_consent.subject_identifier)
        self.appointment = Appointment.objects.get(registered_subject=self.registered_subject)
예제 #28
0
 def setUp(self):
     try:
         site_lab_profiles.register(MpepuMaternalProfile())
     except AlreadyRegistered:
         pass
     MpepuAppConfiguration().prepare()
     site_lab_tracker.autodiscover()
     site_visit_schedules.autodiscover()
     site_visit_schedules.build_all()
     study_site = StudySiteFactory()
     print "Consenting a mother"
     MaternalConsent.objects.all().delete()
     self.maternal_consent = MaternalConsentFactory(study_site=study_site)
     print "Maternal Consent: {}".format(self.maternal_consent)
     print 'get maternal registered subject'
     self.registered_subject = RegisteredSubject.objects.get(
         subject_identifier=self.maternal_consent.subject_identifier)
     print "check if mother is eligible"
     self.post_elibility = MaternalEligibilityPostFactory(
         maternal_consent=self.maternal_consent,
         registered_subject=self.maternal_consent.registered_subject)
예제 #29
0
    def test_audit_trail(self):
        site_lab_tracker.autodiscover()
        StudySpecificFactory()
        StudySiteFactory()
        content_type_map_helper = ContentTypeMapHelper()
        content_type_map_helper.populate()
        content_type_map_helper.sync()
        visit_tracking_content_type_map = ContentTypeMap.objects.get(content_type__model='testvisit')

        visit_definition = VisitDefinitionFactory(code='1000', title='Test', visit_tracking_content_type_map=visit_tracking_content_type_map)
        registered_subject = RegisteredSubjectFactory(subject_identifier='12345')
        appointment = Appointment.objects.create(
            appt_datetime=datetime.today(),
            best_appt_datetime=datetime.today(),
            appt_status='new',
            study_site=None,
            visit_definition=visit_definition,
            registered_subject=registered_subject
            )
        # check for the audit trail
        #self.assertTrue(Appointment.history.filter(id=appointment.pk))
        pre_appointment_contact = PreAppointmentContact.objects.create(appointment=appointment, contact_datetime=datetime.today(), is_contacted='Yes', is_confirmed=False)
예제 #30
0
    def test_p1(self):
        site_lab_tracker.autodiscover()
        study_specific = StudySpecificFactory()
        StudySiteFactory()

        content_type_map_helper = ContentTypeMapHelper()
        content_type_map_helper.populate()
        content_type_map_helper.sync()
        content_type_map = ContentTypeMap.objects.get(model__iexact=ResistanceConsent._meta.object_name)
        ConsentCatalogueFactory(
            name=self.app_label,
            content_type_map=content_type_map,
            consent_type='sub-study',
            version=1,
            start_datetime=study_specific.study_start_datetime,
            end_datetime=datetime(datetime.today().year + 5, 1, 1),
            add_for_app=self.app_label)

        print 'confirming that a maternal consent exists'
        consent = MaternalConsentFactory(first_name='MELISSA', gender='F', dob='1994-03-25', identity='111121111')
        self.assertEqual(MaternalConsent.objects.all().count(), 1)
        print consent.subject_identifier

        print 'assert one maternal consent registers one registered_subject'
        self.assertEqual(MaternalConsent.objects.all().count(), RegisteredSubject.objects.all().count())

        print 'consent first resistance mother'
        consent1 = ResistanceConsentFactory(first_name='MELISSA', gender='F', dob='1994-03-25', identity='111121111')
        self.assertEqual(ResistanceConsent.objects.all().count(), 1)
        print consent1.subject_identifier

        print 'assert that the subject identifier of both consents remains the same'
        self.assertEqual(consent.subject_identifier, consent1.subject_identifier)

        print 'assert that the subject identifier on consent1 == subject identifier in registered_subject'
        self.assertEqual(consent1.subject_identifier, RegisteredSubject.objects.get(subject_identifier=consent1.subject_identifier).subject_identifier)
예제 #31
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.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 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)
예제 #34
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())
예제 #35
0
    def test_p3(self):
        site_lab_tracker.autodiscover()
        StudySpecificFactory()
        study_site = StudySiteFactory()
        content_type_map_helper = ContentTypeMapHelper()
        content_type_map_helper.populate()
        content_type_map_helper.sync()
        print 'setup the consent catalogue for app {0}'.format(self.app_label)
        content_type_map = ContentTypeMap.objects.get(
            content_type__model=self.subject_consent._meta.object_name.lower())
        consent_catalogue = ConsentCatalogueFactory(
            name=self.consent_catalogue_name,
            content_type_map=content_type_map)
        consent_catalogue.add_for_app = self.app_label
        consent_catalogue.save()

        print 'setup bhp_visit'
        content_type_map = ContentTypeMap.objects.get(
            content_type__model=MaternalEligibilityAnte._meta.object_name.
            lower())
        membership_form = MembershipFormFactory(
            content_type_map=content_type_map)
        schedule_group = ScheduleGroupFactory(
            membership_form=membership_form,
            group_name='Maternal Ante Natal Reg',
            grouping_key='ELIGIBILITY')
        visit_definition = VisitDefinitionFactory(
            code='1000M',
            title='Maternal Ante Natal Registration',
            grouping='maternal')
        visit_definition.schedule_group.add(schedule_group)

        content_type_map = ContentTypeMap.objects.get(
            content_type__model=MaternalEligibilityPost._meta.object_name.
            lower())
        membership_form = MembershipFormFactory(
            content_type_map=content_type_map)
        schedule_group = ScheduleGroupFactory(
            membership_form=membership_form,
            group_name='Maternal Post Partum Reg',
            grouping_key='ELIGIBILITY')
        visit_definition = VisitDefinitionFactory(
            code='2000M',
            title='Maternal Post Natal Registration',
            grouping='maternal')
        visit_definition.schedule_group.add(schedule_group)

        content_type_map = ContentTypeMap.objects.get(
            content_type__model=MaternalPostReg._meta.object_name.lower())
        membership_form = MembershipFormFactory(
            content_type_map=content_type_map)
        schedule_group = ScheduleGroupFactory(
            membership_form=membership_form,
            group_name='Post Partum Follow-up')
        visit_definition = VisitDefinitionFactory(code='2010M',
                                                  title='Infant Randomization',
                                                  grouping='maternal')
        visit_definition.schedule_group.add(schedule_group)

        print 'consent a mother'
        maternal_consent = MaternalConsentFactory(study_site=study_site)
        print maternal_consent.subject_identifier
        print 'get subject registered subject'
        registered_subject = RegisteredSubject.objects.get(
            subject_identifier=maternal_consent.subject_identifier)
        print 'enroll mother ante natal'
        maternal_eligibility_ante = MaternalEligibilityAnteFactory(
            maternal_consent=maternal_consent,
            registered_subject=registered_subject)

        instances = [maternal_eligibility_ante]

        print 'test natural key / get_by_natural_key on subject_visit'
        appointment = Appointment.objects.get(
            registered_subject=registered_subject,
            visit_definition__code='1000M')
        subject_visit = MaternalVisitFactory(appointment=appointment)
        instances.append(subject_visit)
        print 'NOTE, not all models tested'
        print 'test serialization.'
        self.serialize_deserialize(instances)
    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)
예제 #37
0
    def setUp(self):
        try:
            site_lab_profiles.register(MpepuInfantProfile())
        except AlreadyRegistered:
            pass
        MpepuAppConfiguration().prepare()
        site_lab_tracker.autodiscover()
        site_visit_schedules.autodiscover()
        site_visit_schedules.build_all()
        admin.autodiscover()
        study_site = StudySiteFactory()
        content_type_map = ContentTypeMap.objects.get(
            model='maternalconsent', app_label='mpepu_maternal')
        consent_catalogue = ConsentCatalogueFactory(
            content_type_map=content_type_map)
        consent_catalogue.add_for_app = 'mpepu_infant'
        consent_catalogue.save()

        self.delivery_days_ago = 20
        self.delivery_datetime = datetime.today() - timedelta(
            days=self.delivery_days_ago - 3)
        print "Consent a mother"
        self.maternal_consent = MaternalConsentFactory(
            study_site=study_site,
            consent_datetime=datetime.today() -
            timedelta(days=self.delivery_days_ago))
        print "Consent: {}".format(self.maternal_consent)
        registered_subject = RegisteredSubject.objects.get(
            subject_identifier=self.maternal_consent.subject_identifier)
        print 'check if mother is eligible'
        maternal_eligibility = MaternalEligibilityPostFactory(
            maternal_consent=self.maternal_consent,
            registered_subject=registered_subject,
            registration_datetime=datetime.today() -
            timedelta(days=self.delivery_days_ago))
        print 'get the 2000M visit'
        appointment = Appointment.objects.get(
            registered_subject=registered_subject,
            visit_definition__code='2000M')
        print 'create a maternal visit for the 2000M visit'
        maternal_visit = MaternalVisitFactory(
            appointment=appointment,
            report_datetime=datetime.today() -
            timedelta(days=self.delivery_days_ago))
        print 'create a maternal_lab_del registering 2 of 2 infants'
        self.maternal_lab_del = MaternalLabDelFactory(
            maternal_visit=maternal_visit,
            live_infants=2,
            live_infants_to_register=2,
            delivery_datetime=self.delivery_datetime,
            has_ga='Yes',
            ga=37,
        )
        print 'maternal lab del: {}'.format(self.maternal_lab_del)
        print 'get registered subject of the first infant'
        self.registered_subject1 = RegisteredSubject.objects.filter(
            relative_identifier=self.maternal_consent.subject_identifier
        ).order_by('subject_identifier')[0]
        print 'first registered subject {}'.format(self.registered_subject1)
        self.infant_birth1 = InfantBirthFactory(
            registered_subject=self.registered_subject1,
            maternal_lab_del=self.maternal_lab_del,
            dob=self.delivery_datetime.date())
        print 'first infant birth {}'.format(self.infant_birth1)
        appointment1 = Appointment.objects.get(
            registered_subject=self.registered_subject1,
            visit_definition__code='2000')
        infant_visit1 = InfantVisitFactory(appointment=appointment1,
                                           report_datetime=datetime.today(),
                                           reason='scheduled',
                                           study_status='onstudy notrando')
        print 'get registered subject of the second infant'
        self.registered_subject2 = RegisteredSubject.objects.filter(
            relative_identifier=self.maternal_consent.subject_identifier
        ).order_by('subject_identifier')[1]
        print 'second registered subject {}'.format(self.registered_subject2)
        self.infant_birth2 = InfantBirthFactory(
            registered_subject=self.registered_subject2,
            maternal_lab_del=self.maternal_lab_del,
            dob=self.delivery_datetime.date())
        print 'second infant birth {}'.format(self.infant_birth2)
        appointment2 = Appointment.objects.get(
            registered_subject=self.registered_subject2,
            visit_definition__code='2000')
        infant_visit2 = InfantVisitFactory(appointment=appointment2,
                                           report_datetime=datetime.today(),
                                           reason='scheduled',
                                           study_status='onstudy notrando')
예제 #38
0
    def test_p1(self):
        try:
            site_lab_profiles.register(MpepuMaternalProfile())
        except AlreadyRegistered:
            pass
        MpepuAppConfiguration().prepare()
        site_lab_tracker.autodiscover()
        StudySpecificFactory()
        study_site = StudySiteFactory()
        MpepuAppConfiguration().prepare()
        content_type_map_helper = ContentTypeMapHelper()
        content_type_map_helper.populate()
        content_type_map_helper.sync()
        print 'setup the consent catalogue for app {0}'.format(self.app_label)
        content_type_map = ContentTypeMap.objects.get(
            content_type__model=self.subject_consent._meta.object_name.lower())
        consent_catalogue = ConsentCatalogueFactory(
            name=self.consent_catalogue_name,
            content_type_map=content_type_map)
        consent_catalogue.add_for_app = self.app_label
        consent_catalogue.save()

        print 'setup bhp_visit'
        content_type_map = ContentTypeMap.objects.get(
            content_type__model=MaternalEligibilityAnte._meta.object_name.
            lower())
        membership_form = MembershipFormFactory(
            content_type_map=content_type_map)
        schedule_group = ScheduleGroupFactory(
            membership_form=membership_form,
            group_name='Maternal Ante Natal Reg',
            grouping_key='ELIGIBILITY')
        visit_definition = VisitDefinitionFactory(
            code='1000M',
            title='Maternal Ante Natal Registration',
            grouping='maternal')
        visit_definition.schedule_group.add(schedule_group)

        content_type_map = ContentTypeMap.objects.get(
            content_type__model=MaternalEligibilityPost._meta.object_name.
            lower())
        membership_form = MembershipFormFactory(
            content_type_map=content_type_map)
        schedule_group = ScheduleGroupFactory(
            membership_form=membership_form,
            group_name='Maternal Post Partum Reg',
            grouping_key='ELIGIBILITY')
        visit_definition = VisitDefinitionFactory(
            code='2000M',
            title='Maternal Post Natal Registration',
            grouping='maternal')
        visit_definition.schedule_group.add(schedule_group)

        content_type_map = ContentTypeMap.objects.get(
            content_type__model=MaternalPostReg._meta.object_name.lower())
        membership_form = MembershipFormFactory(
            content_type_map=content_type_map)
        schedule_group = ScheduleGroupFactory(
            membership_form=membership_form,
            group_name='Post Partum Follow-up')
        visit_definition = VisitDefinitionFactory(code='2010M',
                                                  title='Infant Randomization',
                                                  grouping='maternal')
        visit_definition.schedule_group.add(schedule_group)

        print 'consent a mother (2 days ago)'
        maternal_consent = MaternalConsentFactory(
            study_site=study_site,
            consent_datetime=datetime.today() - timedelta(days=2))
        print maternal_consent.subject_identifier
        print 'get maternal registered subject'
        registered_subject = RegisteredSubject.objects.get(
            subject_identifier=maternal_consent.subject_identifier)
        print 'take mother off study (1 day ago)'
        maternal_off_study = MaternalOffStudyFactory(
            registered_subject=registered_subject,
            offstudy_date=date.today() - timedelta(days=1))
        print 'Off study: {0}'.format(maternal_off_study)
        print 'confirm cannot add a registration form today'
        self.assertRaises(SubjectOffStudyError,
                          MaternalEligibilityAnteFactory,
                          maternal_consent=maternal_consent,
                          registered_subject=registered_subject,
                          registration_datetime=datetime.today() -
                          timedelta(days=0))

        print 'consent a mother (3 days ago)'
        maternal_consent = MaternalConsentFactory(
            study_site=study_site,
            consent_datetime=datetime.today() - timedelta(days=3))
        print maternal_consent.subject_identifier
        print 'get maternal registered subject'
        registered_subject = RegisteredSubject.objects.get(
            subject_identifier=maternal_consent.subject_identifier)
        print 'add a registration form 2 days ago'
        maternal_eligibility = MaternalEligibilityAnteFactory(
            maternal_consent=maternal_consent,
            registered_subject=registered_subject,
            registration_datetime=datetime.today() - timedelta(days=2))
        print 'confirm appointments'
        appointment = Appointment.objects.get(
            registered_subject=registered_subject,
            visit_definition__code='1000M')
        print 'Appointment {0} {1}'.format(appointment,
                                           appointment.appt_datetime)
        print 'take mother off study (1 day ago)'
        maternal_off_study = MaternalOffStudyFactory(
            registered_subject=registered_subject,
            offstudy_date=appointment.appt_datetime - timedelta(days=1))
        print 'Off study: {0} offstudy_datetime={1}'.format(
            maternal_off_study,
            date.today() - timedelta(days=1))
        print 'confirm appointments deleted'
        self.assertEquals(
            Appointment.objects.filter(registered_subject=registered_subject,
                                       visit_definition__code='1000M').count(),
            0)

        print 'consent a mother (4 days ago)'
        maternal_consent = MaternalConsentFactory(
            study_site=study_site,
            consent_datetime=datetime.today() - timedelta(days=4))
        print maternal_consent.subject_identifier
        print 'get maternal registered subject'
        registered_subject = RegisteredSubject.objects.get(
            subject_identifier=maternal_consent.subject_identifier)
        print 'add a registration form 3 days ago'
        maternal_eligibility = MaternalEligibilityAnteFactory(
            maternal_consent=maternal_consent,
            registered_subject=registered_subject,
            registration_datetime=datetime.today() - timedelta(days=3))
        print 'confirm appointments'
        appointment = Appointment.objects.get(
            registered_subject=registered_subject,
            visit_definition__code='1000M')
        print 'add a visit form 2 days ago'
        appointment = Appointment.objects.get(
            registered_subject=registered_subject,
            visit_definition__code='1000M')
        maternal_visit = MaternalVisitFactory(
            appointment=appointment,
            report_datetime=datetime.today() - timedelta(days=2))
        print 'confirm cannot take mother off study (3 day ago)'
        self.assertRaises(SubjectOffStudyDateError,
                          MaternalOffStudyFactory,
                          registered_subject=registered_subject,
                          offstudy_date=date.today() - timedelta(days=3))
        print 'confirm can take mother off study (2 day ago)'
        maternal_off_study = MaternalOffStudyFactory(
            registered_subject=registered_subject,
            offstudy_date=date.today() - timedelta(days=2))
        print 'Off study: {0}'.format(maternal_off_study)
        print 'confirm appointments not deleted'
        self.assertEquals(
            Appointment.objects.filter(registered_subject=registered_subject,
                                       visit_definition__code='1000M').count(),
            1)
    def test_validate_appt_status(self):
        # setup visit 1000
        from edc.testing.tests.factories import TestRegistrationFactory, TestVisitFactory, TestConsentFactory, TestScheduledModelFactory
        app_label = 'bhp_base_test'
        site_lab_tracker.autodiscover()
        StudySpecificFactory()
        StudySiteFactory()
        content_type_map_helper = ContentTypeMapHelper()
        content_type_map_helper.populate()
        content_type_map_helper.sync()
        print 'setup the consent catalogue for app {0}'.format(app_label)
        content_type_map = ContentTypeMap.objects.get(content_type__model=TestConsent._meta.object_name.lower())
 
        print 'setup bhp_visit (1000, 1010, 1020, 1030)'
        content_type_map = ContentTypeMap.objects.get(content_type__model='testregistration')
        visit_tracking_content_type_map = ContentTypeMap.objects.get(content_type__model='testvisit')
        membership_form = MembershipFormFactory(content_type_map=content_type_map)
        schedule_group = ScheduleGroupFactory(membership_form=membership_form, group_name='Test Reg', grouping_key='REGISTRATION')
        visit_definition = VisitDefinitionFactory(code='1000', title='Test Registration 00', grouping='test_subject', 
                                                  time_point=0,
                                                  base_interval=0,
                                                  base_interval_unit='D',
                                                  visit_tracking_content_type_map=visit_tracking_content_type_map)
        visit_definition.schedule_group.add(schedule_group)
        visit_definition = VisitDefinitionFactory(code='1010', title='Test Registration 10', grouping='test_subject',
                                                  time_point=10,
                                                  base_interval=1,
                                                  base_interval_unit='M',
                                                  visit_tracking_content_type_map=visit_tracking_content_type_map)
        visit_definition.schedule_group.add(schedule_group)
        content_type_map = ContentTypeMap.objects.get(content_type__model=TestScheduledModel._meta.object_name.lower())
        EntryFactory(visit_definition=visit_definition, content_type_map=content_type_map)
 
        visit_definition = VisitDefinitionFactory(code='1020', title='Test Registration 20', grouping='test_subject',
                                                  time_point=20,
                                                  base_interval=2,
                                                  base_interval_unit='M',
                                                  visit_tracking_content_type_map=visit_tracking_content_type_map)
        visit_definition.schedule_group.add(schedule_group)
        visit_definition = VisitDefinitionFactory(code='1030', title='Test Registration 30', grouping='test_subject',
                                                  time_point=30,
                                                  base_interval=3,
                                                  base_interval_unit='M',
                                                  visit_tracking_content_type_map=visit_tracking_content_type_map)
        visit_definition.schedule_group.add(schedule_group)
        # add consent
        test_consent = TestConsentFactory()
        # add registration
        registered_subject = RegisteredSubject.objects.get(subject_identifier=test_consent.subject_identifier)
        self.assertEquals(Appointment.objects.all().count(), 0)
        print 'complete a registration form'
        test_registration = TestRegistrationFactory(registered_subject=registered_subject)
        print 'assert 4 appointments created'
        self.assertEquals(Appointment.objects.all().count(), 4)
        print 'assert all set to new'
        for appointment in Appointment.objects.all():
            self.assertEqual(appointment.appt_status, NEW_APPT)
        print 'attempt to set appointment status, assert reverts to New or Cancelled when no visit tracking'
        for appt_status in APPT_STATUS:
            appointment.appt_status = appt_status[0]
            appointment.save()
            if appt_status == 'cancelled':
                self.assertIn(appointment.appt_status, ['cancelled'])
            else:
                self.assertIn(appointment.appt_status, [NEW_APPT, 'cancelled'])
            print '    {0} becomes {1}'.format(appt_status[0], appointment.appt_status) 
 
        print 'get appointment 1000'
        appointment = Appointment.objects.get(registered_subject=registered_subject, visit_definition__code='1000')
        print 'add a visit tracking form for appointment 1000'
        test_visit = TestVisitFactory(appointment=appointment, reason='scheduled')
        print 'confirm appt_status changes to \'in_progress\''
        self.assertEquals(appointment.appt_status, 'in_progress')
        print 'confirm not scheduled entries for visit'
        self.assertEqual(ScheduledEntryMetaData.objects.filter(appointment=appointment).count(), 0)
        print 'try changing status'
        for appt_status in APPT_STATUS:
            appointment = Appointment.objects.get(registered_subject=registered_subject, visit_definition__code='1000', visit_instance='0')
            print 'appointment status is {0}'.format(appointment.appt_status)
            #print 'assert there is only one appointment instance'
            #self.assertEquals(Appointment.objects.all().count(), 1)
            print '    attempt to change to {0}'.format(appt_status[0])
            appointment.appt_status = appt_status[0]
            print '    save'
            if appt_status[0] == 'cancelled':
                appointment.save()
                print '    assert still in_progress'
                self.assertEquals(appointment.appt_status, 'in_progress')
            elif appt_status[0] == NEW_APPT:
                appointment.save()
                print '    assert still in_progress'
                self.assertEquals(appointment.appt_status, 'in_progress')
            elif appt_status[0] == 'in_progress':
                appointment.save()
                print '    assert still in_progress'
                self.assertEquals(appointment.appt_status, 'in_progress')
            elif appt_status[0] == COMPLETE_APPT:
                appointment.save()
                print '    assert allows change to Done'
                self.assertEquals(appointment.appt_status, COMPLETE_APPT)
            elif appt_status[0] == 'incomplete':
                appointment.save()
                print '    assert changes to Done'
                self.assertEquals(appointment.appt_status, COMPLETE_APPT)
            else:
                raise TypeError()
 
        print 'get appointment 1010, which has entries'
        appointment = Appointment.objects.get(registered_subject=registered_subject, visit_definition__code='1010')
        print 'add a visit tracking form for appointment 1010'
        test_visit = TestVisitFactory(appointment=appointment, reason='scheduled')
        print 'confirm appt_status changes to \'in_progress\''
        self.assertEquals(appointment.appt_status, 'in_progress')
        print 'confirm not scheduled entries for visit'
        self.assertEqual(ScheduledEntryMetaData.objects.filter(appointment=appointment).count(), 1)
        print 'try changing status'
        for appt_status in APPT_STATUS:
            appointment = Appointment.objects.get(registered_subject=registered_subject, visit_definition__code='1010', visit_instance='0')
            print 'appointment status is {0}'.format(appointment.appt_status)
            #print 'assert there is only one appointment instance'
            #self.assertEquals(Appointment.objects.all().count(), 1)
            print '    attempt to change to {0}'.format(appt_status[0])
            appointment.appt_status = appt_status[0]
            print '    save'
            if appt_status[0] == 'cancelled':
                appointment.save()
                print '    assert still in_progress'
                self.assertEquals(appointment.appt_status, 'in_progress')
            elif appt_status[0] == NEW_APPT:
                appointment.save()
                print '    assert still in_progress'
                self.assertEquals(appointment.appt_status, 'in_progress')
            elif appt_status[0] == 'in_progress':
                appointment.save()
                print '    assert still in_progress'
                self.assertEquals(appointment.appt_status, 'in_progress')
            elif appt_status[0] == COMPLETE_APPT:
                appointment.save()
                print '    assert change to Incomplete'
                self.assertEquals(appointment.appt_status, 'incomplete')
            elif appt_status[0] == 'incomplete':
                appointment.save()
                print '    assert leaves as incomplete'
                self.assertEquals(appointment.appt_status, 'incomplete')
            else:
                raise TypeError()
 
        print 'add the TestScheduledModel for visit 1010, scheduledentry should be KEYED'
        TestScheduledModelFactory(test_visit=test_visit)
        print 'assert is KEYED in ScheduledEntryMetaData'
        #for obj in ScheduledEntryMetaData.objects.filter(appointment=appointment):
        #    print obj.entry_status
        ScheduledEntryMetaData.objects.filter(appointment=appointment).update(entry_status='KEYED')
        self.assertEqual(ScheduledEntryMetaData.objects.filter(appointment=appointment, entry_status='KEYED').count(), 1)
        print 'try changing status'
        for appt_status in APPT_STATUS:
            appointment = Appointment.objects.get(registered_subject=registered_subject, visit_definition__code='1010', visit_instance='0')
            print 'appointment status is {0}'.format(appointment.appt_status)
            #print 'assert there is only one appointment instance'
            #self.assertEquals(Appointment.objects.all().count(), 1)
            print '    attempt to change to {0}'.format(appt_status[0])
            appointment.appt_status = appt_status[0]
            print '    save'
            if appt_status[0] == 'cancelled':
                appointment.save()
                print '    assert change to in_progress'
                self.assertEquals(appointment.appt_status, 'in_progress')
            elif appt_status[0] == NEW_APPT:
                appointment.save()
                print '    assert change to in_progress'
                self.assertEquals(appointment.appt_status, 'in_progress')
            elif appt_status[0] == 'in_progress':
                appointment.save()
                print '    assert still in_progress'
                self.assertEquals(appointment.appt_status, 'in_progress')
            elif appt_status[0] == COMPLETE_APPT:
                appointment.save()
                print '    assert still Done'
                self.assertEquals(appointment.appt_status, COMPLETE_APPT)
            elif appt_status[0] == 'incomplete':
                appointment.save()
                print '    assert change to Done'
                self.assertEquals(appointment.appt_status, COMPLETE_APPT)
            else:
                raise TypeError()
예제 #40
0
from edc.dashboard.section.classes import site_sections
from edc.lab.lab_profile.classes import site_lab_profiles
from edc.dashboard.subject.views import additional_requisition
from edc.subject.lab_tracker.classes import site_lab_tracker
from edc.subject.rule_groups.classes import site_rule_groups
from edc.subject.visit_schedule.classes import site_visit_schedules

from apps.hnscc.app_configuration.classes import HnsccAppConfiguration

site_lab_profiles.autodiscover()
dajaxice_autodiscover()
HnsccAppConfiguration().prepare()
site_visit_schedules.autodiscover()
site_visit_schedules.build_all()
site_rule_groups.autodiscover()
site_lab_tracker.autodiscover()
data_manager.prepare()
site_sections.autodiscover()
site_sections.update_section_lists()
admin.autodiscover()

for model in get_models():
    try:
        django_databrowse.site.register(model)
    except:
        pass

APP_NAME = settings.APP_NAME

urlpatterns = patterns(
    '',
예제 #41
0
from edc.dashboard.subject.views import additional_requisition
from edc.map.classes import site_mappers
from edc.subject.lab_tracker.classes import site_lab_tracker
from edc.subject.rule_groups.classes import site_rule_groups
from edc.subject.visit_schedule.classes import site_visit_schedules

from bhp066.apps.bcpp.app_configuration.classes import bcpp_app_configuration

site_lab_profiles.autodiscover()
dajaxice_autodiscover()
site_mappers.autodiscover()
bcpp_app_configuration.prepare()
site_visit_schedules.autodiscover()
site_visit_schedules.build_all()
site_rule_groups.autodiscover()
site_lab_tracker.autodiscover()
data_manager.prepare()
site_sections.autodiscover()
site_sections.update_section_lists()
admin.autodiscover()

site_mappers.get_current_mapper().verify_survey_dates()

for model in get_models():
    try:
        django_databrowse.site.register(model)
    except:
        pass

APP_NAME = settings.APP_NAME
예제 #42
0
    def setUp(self):

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

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

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

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

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

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

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

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

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

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

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

        self.test_visit_factory = TestVisitFactory

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

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

        self.registered_subject = RegisteredSubject.objects.get(subject_identifier=self.test_consent.subject_identifier)
        self.appointment = Appointment.objects.get(registered_subject=self.registered_subject)
예제 #43
0
    def setUp(self):
        try:
            site_lab_profiles.register(MpepuInfantProfile())
        except AlreadyRegistered:
            pass
        MpepuAppConfiguration().prepare()
        site_lab_tracker.autodiscover()
        site_visit_schedules.autodiscover()
        site_visit_schedules.build_all()
        study_site = StudySiteFactory()
        content_type_map = ContentTypeMap.objects.get(
            model='maternalconsent', app_label='mpepu_maternal')
        consent_catalogue = ConsentCatalogueFactory(
            content_type_map=content_type_map)
        consent_catalogue.add_for_app = 'mpepu_infant'
        consent_catalogue.save()

        delivery_days_ago = 20
        delivery_datetime = datetime.today() - timedelta(
            days=delivery_days_ago - 3)
        #         print "Consent a mother"
        self.maternal_consent = MaternalConsentFactory(
            study_site=study_site,
            consent_datetime=datetime.today() -
            timedelta(days=delivery_days_ago))
        #         print "Consent: {}".format(self.maternal_consent)
        self.registered_subject = RegisteredSubject.objects.get(
            subject_identifier=self.maternal_consent.subject_identifier)
        #         print 'check if mother is eligible'
        self.maternal_eligibility = MaternalEligibilityPostFactory(
            maternal_consent=self.maternal_consent,
            registered_subject=self.registered_subject,
            registration_datetime=datetime.today() -
            timedelta(days=delivery_days_ago))
        #         print 'get the 2000M visit'
        self.m_appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='2000M')
        #         print 'create a maternal visit for the 2000M visit'
        self.maternal_visit = MaternalVisitFactory(
            appointment=self.m_appointment,
            report_datetime=datetime.today() -
            timedelta(days=delivery_days_ago))
        #         print 'create a maternal_lab_del registering 2 of 2 infants'
        self.maternal_lab_del = MaternalLabDelFactory(
            maternal_visit=self.maternal_visit,
            live_infants=1,
            live_infants_to_register=1,
            delivery_datetime=delivery_datetime,
            has_ga='Yes',
            ga=37,
        )
        #         print 'maternal lab del: {}'.format(self.maternal_lab_del)
        #         print 'get registered subject of the infant'
        self.registered_subject = RegisteredSubject.objects.filter(
            relative_identifier=self.maternal_consent.subject_identifier
        ).order_by('subject_identifier')[0]
        print 'infant registered subject {}'.format(self.registered_subject)
        self.infant_birth = InfantBirthFactory(
            registered_subject=self.registered_subject,
            maternal_lab_del=self.maternal_lab_del,
            dob=delivery_datetime.date())
        #         print 'infant birth {}'.format(self.infant_birth)
        self.appointment = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='2000')
        self.infant_visit = InfantVisitFactory(
            appointment=self.appointment,
            report_datetime=datetime.today(),
            reason='scheduled',
            study_status='onstudy notrando')
        self.infant_eligibility = InfantEligibilityFactory(
            infant_birth=self.infant_birth,
            registered_subject=self.registered_subject)
        #         print 'infant eligibility {}'.format(self.infant_eligibility)
        self.app_2010 = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='2010')
        self.visit_2010 = InfantVisitFactory(
            appointment=self.app_2010,
            report_datetime=datetime.today(),
            reason='scheduled',
            study_status='onstudy rando today')
        self.app_2020 = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='2020')
        self.visit_2020 = InfantVisitFactory(
            appointment=self.app_2020,
            report_datetime=datetime.today(),
            reason='scheduled',
            study_status='onstudy rando ondrug')
        self.app_2030 = Appointment.objects.get(
            registered_subject=self.registered_subject,
            visit_definition__code='2030')
        self.visit_2030 = InfantVisitFactory(
            appointment=self.app_2030,
            report_datetime=datetime.today(),
            reason='scheduled',
            study_status='onstudy rando ondrug')