Beispiel #1
0
 def test_previous_visit_required(self):
     print 'get registered subject of the infant'
     registered_subject = RegisteredSubject.objects.filter(
         relative_identifier=self.maternal_consent.subject_identifier
     ).order_by('subject_identifier')[0]
     print 'infant registered subject {}'.format(registered_subject)
     infant_birth = InfantBirthFactory(
         registered_subject=registered_subject,
         maternal_lab_del=self.maternal_lab_del,
         dob=self.delivery_datetime.date())
     print 'infant birth {}'.format(infant_birth)
     print 'get 2000 appointment'
     appointment_2000 = Appointment.objects.get(
         registered_subject=registered_subject,
         visit_definition__code='2000')
     print '2000 appointment {}'.format(appointment_2000)
     infant_visit_2000 = InfantVisitFactory(
         appointment=appointment_2000,
         report_datetime=datetime.today(),
         reason='scheduled',
         study_status='onstudy notrando')
     print '2000 infant visit {}'.format(infant_visit_2000)
     print 'get 2010 appointment'
     appointment_2010 = Appointment.objects.get(
         registered_subject=registered_subject,
         visit_definition__code='2010')
     print 'Infant Eligibility'
     infant_eligibility = InfantEligibilityFactory(
         infant_birth=infant_birth, registered_subject=registered_subject)
     print 'infant eligibility {}'.format(infant_eligibility)
     print 'assert that the rest of the visits were created'
     appointment_all = Appointment.objects.filter(
         registered_subject=registered_subject)
     self.assertEqual(appointment_all.count(), 9)
     print 'assert that trying to save a visit before the previous one has been filled in will fail'
     appointment_2030 = Appointment.objects.get(
         registered_subject=registered_subject,
         visit_definition__code='2030')
     self.assertRaises(ValidationError,
                       InfantVisitFactory,
                       appointment=appointment_2030)
     print 'assert that saving previous visit then re-saving the visit will save.'
     infant_visit_2010 = InfantVisitFactory(
         appointment=appointment_2010,
         report_datetime=datetime.today(),
         reason='scheduled',
         study_status='onstudy ondrug')
     appointment_2020 = Appointment.objects.get(
         registered_subject=registered_subject,
         visit_definition__code='2020')
     infant_visit_2020 = InfantVisitFactory(
         appointment=appointment_2020,
         report_datetime=datetime.today(),
         reason='scheduled')
     infant_visit_2030 = InfantVisitFactory(
         appointment=appointment_2030,
         report_datetime=datetime.today(),
         reason='scheduled')
     print 'infant 2030 visit {}'.format(infant_visit_2030)
    def test_multiple_birth_rando(self):

        original_sids = self.populate_rando()

        print "assert that infant 1 is eligible to be randomised"
        allow_rando1 = Eligibility().check(current_consent_version=2,
                                           dob=self.delivery_datetime.date(),
                                           ga=37,
                                           weight=4,
                                           clinical_jaundice='No',
                                           anemia_neutropenia='No',
                                           exception_cls=ValidationError,
                                           suppress_exception=False)
        self.assertTrue(allow_rando1, "Infant Cannot be randomized")
        infant_eligibility1 = InfantEligibilityFactory(
            infant_birth=self.infant_birth1,
            registered_subject=self.infant_birth1.registered_subject,
            rando_bf_duration='N/A',
            congen_anomaly='No',
            maternal_art_status='ON',
            maternal_feeding_choice='FF',
            randomization_site='Gaborone',
            ctx_contra='No',
        )
        print 'Infant Eligibility {}'.format(infant_eligibility1)
        print 'assert that the rest of the appointments were created, i.e. 2000,2010,2020,2030,2060,2090,2120,2150,2180'
        all_appointments = Appointment.objects.filter(
            registered_subject=self.registered_subject1)
        self.assertEqual(all_appointments.count(), 9)
        print 'confirm infant 1 was randomized'
        print InfantRando.objects.randomize(
            infant_eligibility=infant_eligibility1)
        print "Infant 1 Rando {}".format(
            InfantRando.objects.get(subject_identifier=self.
                                    registered_subject1.subject_identifier))
        print "assert that infant 2 is eligible to be randomised"
        allow_rando2 = Eligibility().check(current_consent_version=2,
                                           dob=self.delivery_datetime.date(),
                                           ga=37,
                                           weight=3.9,
                                           clinical_jaundice='No',
                                           anemia_neutropenia='No',
                                           exception_cls=ValidationError,
                                           suppress_exception=False)
        self.assertTrue(allow_rando2, "Infant Cannot be randomized")
        infant_eligibility2 = InfantEligibilityFactory(
            infant_birth=self.infant_birth2,
            registered_subject=self.infant_birth2.registered_subject,
            rando_bf_duration='No',
            congen_anomaly='No',
            maternal_art_status='ON',
            maternal_feeding_choice='BF',
            randomization_site='Molepolole',
            ctx_contra='No',
        )
        print infant_eligibility2
        print 'assert that the rest of the appointments were created, i.e. 2000,2010,2020,2030,2060,2090,2120,2150,2180'
        all_appointments = Appointment.objects.filter(
            registered_subject=self.registered_subject2)
        self.assertEqual(all_appointments.count(), 9)
        print 'confirm infant 2 was randomized'
        InfantRando.objects.randomize(infant_eligibility=infant_eligibility2)
        print "Inafnt 2 Rando {}".format(
            InfantRando.objects.get(subject_identifier=self.
                                    registered_subject2.subject_identifier))
        rando1 = InfantRando.objects.get(
            subject_identifier=self.registered_subject1.subject_identifier)
        rando2 = InfantRando.objects.get(
            subject_identifier=self.registered_subject1.subject_identifier)
        print "assert that the twins were randomized to the same feeding arm"
        self.assertEquals(rando1.feeding_choice, rando2.feeding_choice)
        print "assert that the twins were randomized to the same breast feeding duration"
        self.assertEqual(rando1.bf_duration, rando2.bf_duration)
        print "assert that the twins were randomized to the same rx arm"
        self.assertEqual(rando1.rx, rando2.rx)
        print "assert that the twins were randomized to the same stratum"
        self.assertEqual(rando1.stratum, rando2.stratum)
        print "assert that the twins were randomized to the same site"
        self.assertEqual(rando1.site, rando2.site)

        print "ensure original set rando fields remain unchanged"
        og = original_sids.get(sid=rando1.sid)
        print "assert that for sid assigned twin 1, rx remained unchanged"
        self.assertEqual(og.rx, rando1.rx)
        print "assert that for sid assigned twin 1, site remained unchanged"
        self.assertEqual(og.site, rando1.site)
        print "assert that for sid assigned twin 1, stratum remained unchanged"
        self.assertEqual(og.stratum, rando1.stratum)
        print "assert that for sid assigned twin 1, bf_duration remained unchanged"
        if infant_eligibility1.maternal_feeding_choice == 'BF':
            self.assertEqual(og.bf_duration, rando1.bf_duration)
        og = original_sids.get(sid=rando2.sid)
        print "assert that for sid assigned twin 2, rx remained unchanged"
        self.assertEqual(og.rx, rando2.rx)
        print "assert that for sid assigned twin 2, site remained unchanged"
        self.assertEqual(og.site, rando2.site)
        print "assert that for sid assigned twin 2, stratum remained unchanged"
        self.assertEqual(og.stratum, rando2.stratum)
        print "assert that for sid assigned twin 2, bf_duration remained unchanged"
        if infant_eligibility2.maternal_feeding_choice == 'BF':
            self.assertEqual(og.bf_duration, rando2.bf_duration)
Beispiel #3
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')
Beispiel #4
0
class InfantRuleGroupsTests(TestCase):
    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')
#         self.fu = InfantFuFactory(infant_visit=visit_2010)
#         self.fu_physical = InfantFuPhysicalFactory(infant_fu=self.fu, infant_visit=visit_2010)
#         self.fu_dx = InfantFuDxFactory(infant_fu=self.fu, infant_visit=visit_2010)

    def teardown(self):
        RegisteredSubject.objects.all().delete()
        MaternalConsent.objects.all().delete()
        InfantBirth.objects.all().delete()
        InfantEligibility.objects.all().delete()
        InfantVisit.objects.all().delete()
        Appointment.objects.all().delete()
        MaternalLabDel.objects.all().delete()
        MaternalEligibilityPost.objects.all().delete()
        MaternalVisit.objects.all().delete()

    def test_infant_birth_data_rule_group(self):
        """If indicated 'Yes' for congenital anomalies in InfantBirthData then CongenitalAnomalies form is required"""
        print "Assert that upon creation of a 2000 visit Congenital anomalies is NEW"
        entry = Entry.objects.get(visit_definition__code='2000',
                                  model_name='infantcongenitalanomalies')
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.infant_visit.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NOT_REQUIRED')

        print "Assert that if has congenital anomalies is indicated as Yes then Congenital Anomalies form is New"
        birth_data = InfantBirthDataFactory(infant_birth=self.infant_birth,
                                            infant_visit=self.infant_visit,
                                            congenital_anomalities='Yes')
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.infant_visit.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NEW')

        print "Assert that if has congenital anomalies as indicated as No then Congenital Anomalies form is NOT_REQUIRED"
        birth_data.congenital_anomalities = 'No'
        birth_data.save()
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.infant_visit.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NOT_REQUIRED')

    def test_infant_arv_proph_rule_group(self):
        """If Infant was supposed to be taking NVP propylaxis, then 
        NVP Adherence should be required, otherwise it should be not required"""
        print "Assert that upon creation of a visit after 2000 InfantnNvpAdeherance is NEW"
        entry = Entry.objects.get(visit_definition__code='2010',
                                  model_name='infantnvpadherence')
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2010.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NEW')

        print "Assert that if prophylactic_nvp is No then InfantNvpAdherance is NOT_REQUIRED"
        infant_arv_proph = InfantArvProphFactory(infant_visit=self.visit_2010,
                                                 prophylatic_nvp='No')
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2010.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NOT_REQUIRED')

        print "Assert that if prophylactic_nvp is Yes then InfantNvpAdherance is NEW"
        infant_arv_proph.prophylatic_nvp = 'Yes'
        infant_arv_proph.save()
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2010.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NEW')

    def test_infant_fu_rule_group_diarrhea(self):
        """Check InfantFu rule groups on diarrhea"""
        print "Assert that upon creation of a visit after 2000 InfantFuD is NEW"
        entry = Entry.objects.get(visit_definition__code='2010',
                                  model_name='infantfud')
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2010.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NEW')

        print "Assert that if diarrhea_illness is No then InfantFuD is NOT_REQUIRED"
        infant_fu = InfantFuFactory(infant_visit=self.visit_2010,
                                    diarrhea_illness='No')
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2010.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NOT_REQUIRED')

        print "Assert that if diarrhea_illness is YES then InfantFuD is NEW"
        infant_fu.diarrhea_illness = 'Yes'
        infant_fu.save()
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2010.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NEW')

    def test_infant_fu_rule_group_dx(self):
        """Check InfantFu rule groups on diagnosis"""
        print "Assert that upon creation of a visit after 2000 InfantFuDx is NEW"
        entry = Entry.objects.get(visit_definition__code='2010',
                                  model_name='infantfudx')
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2010.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NEW')

        print "Assert that if has_dx is No then InfantFuDx is NOT_REQUIRED"
        infant_fu = InfantFuFactory(infant_visit=self.visit_2010, has_dx='No')
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2010.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NOT_REQUIRED')

        print "Assert that if has_dx is YES then InfantFuDx is NEW"
        infant_fu.has_dx = 'Yes'
        infant_fu.save()
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2010.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NEW')

    def test_infant_study_drug_rule_group(self):
        """Check rule group on CTX """
        print "Assert that upon creation of a visit after 2000 InfantCtxPlaceboAdh is NEW"
        entry = Entry.objects.get(visit_definition__code='2020',
                                  model_name='infantctxplaceboadh')
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2020.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NEW')

        print "Assert that if on_placebo_status is No then InfantCtxPlaceboAdh is NOT_REQUIRED"
        study_drug = InfantStudyDrugFactory(infant_visit=self.visit_2020,
                                            on_placebo_status='No')
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2020.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NOT_REQUIRED')

        print "Assert that if on_placebo_status is YES then InfantCtxPlaceboAdh is NEW"
        study_drug.on_placebo_status = 'Yes'
        study_drug.save()
        meta_data = ScheduledEntryMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2020.appointment,
            entry=entry)
        self.assertEqual(meta_data.entry_status, 'NEW')

    def test_stool_sampling_rule_group(self):
        """Check rule group on stool sampling"""
        print "Assert that upon creation of a 2010 visit, stool sample is required."
        lab_entry = LabEntry.objects.get(
            model_name='infantrequisition',
            requisition_panel__name='Stool storage',
            visit_definition__code='2010')

        print "Assert that if sample_obtained is indicated as Yes then InfantStoolCollection is New"
        stool = InfantStoolCollectionFactory(infant_visit=self.visit_2010,
                                             sample_obtained='Yes')
        requisition = RequisitionMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2010.appointment,
            lab_entry=lab_entry)
        self.assertEqual(requisition.entry_status, 'NEW')

        print "Assert that if sample_obtained is indicated as No then InfantStoolCollection is NOT_REQUIRED"
        stool.sample_obtained = 'No'
        stool.save()
        requisition = RequisitionMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2010.appointment,
            lab_entry=lab_entry)
        self.assertEqual(requisition.entry_status, 'NOT_REQUIRED')

    def test_feeding_choice_rule_groups(self):
        """Check rule group on feeding choice"""
        print "Assert that when a 2030 visit is created DNA PCR is NEW"
        lab_entry = LabEntry.objects.get(model_name='infantrequisition',
                                         requisition_panel__name='DNA PCR',
                                         visit_definition__code='2030')
        requisition = RequisitionMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2030.appointment,
            lab_entry=lab_entry)
        self.assertEqual(requisition.entry_status, 'NEW')

        #         print "Assert that if Formula feeeding DNA PCR is NOT_REQUIRED"
        #         self.infant_eligibility.maternal_feeding_choice = 'FF'
        #         self.infant_eligibility.appointment = self.app_2030
        #         self.infant_eligibility.save()
        #         requisition = RequisitionMetaData.objects.get(registered_subject=self.registered_subject, appointment=self.visit_2030.appointment, lab_entry=lab_entry)
        #         self.assertEqual(requisition.entry_status, 'NOT_REQUIRED')

        print "Assert that if Beastfeeeding DNA PCR is NEW"
        self.infant_eligibility.maternal_feeding_choice = 'BF'
        self.infant_eligibility.appointment = self.app_2030
        self.infant_eligibility.save()
        requisition = RequisitionMetaData.objects.get(
            registered_subject=self.registered_subject,
            appointment=self.visit_2030.appointment,
            lab_entry=lab_entry)
        self.assertEqual(requisition.entry_status, 'NEW')
Beispiel #5
0
    def test_meta_data_status_info_source_telephone(self):
        print 'get registered subject of the infant'
        registered_subject = RegisteredSubject.objects.filter(
            relative_identifier=self.maternal_consent.subject_identifier
        ).order_by('subject_identifier')[0]
        print 'infant registered subject {}'.format(registered_subject)
        infant_birth = InfantBirthFactory(
            registered_subject=registered_subject,
            maternal_lab_del=self.maternal_lab_del,
            dob=self.delivery_datetime.date())
        print 'infant birth {}'.format(infant_birth)
        print 'Infant Eligibility'
        infant_eligibility = InfantEligibilityFactory(
            infant_birth=infant_birth,
            registered_subject=infant_birth.registered_subject,
            rando_bf_duration='N/A',
            congen_anomaly='No',
            maternal_art_status='ON',
            maternal_feeding_choice='FF',
            randomization_site='Gaborone',
            ctx_contra='No',
        )
        print 'infant eligibility {}'.format(infant_eligibility)
        print 'randomize infant'
        RandoTestHelper().populate_rando()
        infant_rando = InfantRando.objects.randomize(
            infant_eligibility=infant_eligibility)
        print 'Infant Rando {}'.format(infant_rando)

        appointment_2000 = Appointment.objects.get(
            registered_subject=registered_subject,
            visit_definition__code='2000')
        InfantVisitFactory(appointment=appointment_2000,
                           report_datetime=datetime.today(),
                           reason='scheduled',
                           study_status='onstudy notrando')
        appointment_2010 = Appointment.objects.get(
            registered_subject=registered_subject,
            visit_definition__code='2010')
        InfantVisitFactory(appointment=appointment_2010,
                           report_datetime=datetime.today(),
                           reason='scheduled',
                           study_status='onstudy rando today')
        appointment_2020 = Appointment.objects.get(
            registered_subject=registered_subject,
            visit_definition__code='2020')
        infant_visit = InfantVisitFactory(appointment=appointment_2020,
                                          report_datetime=datetime.today())

        infant_visit.info_source = 'telephone'
        infant_visit.change_meta_data_status_if_info_source_is_telephone()

        forms = [
            'infantfu', 'infantfuphysical', 'infantfud', 'infantfudx',
            'infantfudx2proph', 'infantfunewmed', 'infantfumed'
        ]
        for form in forms:
            print 'assert that {0} status is \'NOT_REQUIRED\' for a visit where info_source is \'Telephone\''.format(
                form)
            entry = Entry.objects.get(
                model_name=form,
                visit_definition_id=appointment_2020.visit_definition_id)
            meta_data = ScheduledEntryMetaData.objects.get(
                appointment=appointment_2020,
                registered_subject=infant_birth.registered_subject,
                entry=entry)
            self.assertEqual(meta_data.entry_status, 'NOT_REQUIRED')
Beispiel #6
0
    def test_meta_data_status_reason_death_sid_not_none(self):
        print 'get registered subject of the infant'
        registered_subject = RegisteredSubject.objects.filter(
            relative_identifier=self.maternal_consent.subject_identifier
        ).order_by('subject_identifier')[0]
        print 'infant registered subject {}'.format(registered_subject)
        infant_birth = InfantBirthFactory(
            registered_subject=registered_subject,
            maternal_lab_del=self.maternal_lab_del,
            dob=self.delivery_datetime.date())
        print 'infant birth {}'.format(infant_birth)
        print 'Infant Eligibility'
        infant_eligibility = InfantEligibilityFactory(
            infant_birth=infant_birth,
            registered_subject=infant_birth.registered_subject,
            rando_bf_duration='N/A',
            congen_anomaly='No',
            maternal_art_status='ON',
            maternal_feeding_choice='FF',
            randomization_site='Gaborone',
            ctx_contra='No',
        )
        print 'infant eligibility {}'.format(infant_eligibility)
        print 'randomize infant'
        RandoTestHelper().populate_rando()
        infant_rando = InfantRando.objects.randomize(
            infant_eligibility=infant_eligibility)
        print 'Infant Rando {}'.format(infant_rando)

        appointment_2000 = Appointment.objects.get(
            registered_subject=registered_subject,
            visit_definition__code='2000')
        InfantVisitFactory(appointment=appointment_2000,
                           report_datetime=datetime.today(),
                           reason='scheduled',
                           study_status='onstudy notrando')
        appointment_2010 = Appointment.objects.get(
            registered_subject=registered_subject,
            visit_definition__code='2010')
        InfantVisitFactory(appointment=appointment_2010,
                           report_datetime=datetime.today(),
                           reason='scheduled',
                           study_status='onstudy rando today')
        appointment_2020 = Appointment.objects.get(
            registered_subject=registered_subject,
            visit_definition__code='2020')
        InfantVisitFactory(appointment=appointment_2020,
                           report_datetime=datetime.today(),
                           reason='death',
                           study_status='offstudy')

        forms = [
            'infantdeath', 'infantsurvival', 'infantverbalautopsy',
            'infantoffstudy'
        ]
        for form in forms:
            print 'assert that {0} status is \'NEW\' for a visit where visit is dead and sid is not none'.format(
                form)
            entry = Entry.objects.get(
                model_name=form,
                visit_definition_id=appointment_2020.visit_definition_id)
            meta_data = ScheduledEntryMetaData.objects.get(
                appointment=appointment_2020,
                registered_subject=registered_subject,
                entry=entry)
            self.assertEqual(meta_data.entry_status, 'NEW')
Beispiel #7
0
    def test_meta_data_status_initial_state(self):
        print 'get registered subject of the infant'
        registered_subject = RegisteredSubject.objects.filter(
            relative_identifier=self.maternal_consent.subject_identifier
        ).order_by('subject_identifier')[0]
        print 'infant registered subject {}'.format(registered_subject)
        infant_birth = InfantBirthFactory(
            registered_subject=registered_subject,
            maternal_lab_del=self.maternal_lab_del,
            dob=self.delivery_datetime.date())
        print 'infant birth {}'.format(infant_birth)
        print 'Infant Eligibility'
        infant_eligibility = InfantEligibilityFactory(
            infant_birth=infant_birth, registered_subject=registered_subject)
        print 'infant eligibility {}'.format(infant_eligibility)

        print 'check initial state of additional forms for visits greater than 2020'
        visits = ['2000', '2010']
        forms = [
            'infantdeath', 'infantverbalautopsy', 'infantsurvival',
            'infantoffstudy'
        ]
        for visit in visits:
            appointment = Appointment.objects.get(
                registered_subject=registered_subject,
                visit_definition__code=visit)
            InfantVisitFactory(appointment=appointment,
                               report_datetime=datetime.today(),
                               reason='scheduled',
                               study_status='onstudy notrando')
            for form in forms:
                print 'assert that {0} initial state is NOT_REQUIRED for a {1} visit where reason is not DEAD or LOST'.format(
                    form, visit)
                entry = Entry.objects.get(
                    model_name=form,
                    visit_definition_id=appointment.visit_definition_id)
                meta_data = ScheduledEntryMetaData.objects.get(
                    appointment=appointment,
                    registered_subject=registered_subject,
                    entry=entry)
                self.assertEqual(meta_data.entry_status, 'NOT_REQUIRED')

        print 'check initial state of additional forms for visits greater than 2020'
        visits = ['2020', '2030', '2060', '2090', '2120', '2150', '2180']
        forms = [
            'infantdeath', 'infantoffdrug', 'infantverbalautopsy',
            'infantsurvival', 'infantoffstudy'
        ]
        for visit in visits:
            appointment = Appointment.objects.get(
                registered_subject=registered_subject,
                visit_definition__code=visit)
            iv = InfantVisitFactory(appointment=appointment,
                                    report_datetime=datetime.today(),
                                    reason='scheduled',
                                    study_status='onstudy ondrug')
            for form in forms:
                print 'assert that {0} initial status is NOT_REQUIRED for a {1} visit where reason is not DEAD or LOST'.format(
                    form, visit)
                entry = Entry.objects.get(
                    model_name=form,
                    visit_definition_id=appointment.visit_definition_id)
                meta_data = ScheduledEntryMetaData.objects.get(
                    appointment=appointment,
                    registered_subject=registered_subject,
                    entry=entry)
                #Infantoffdrug because new at 2180 if it was not filled in at 2150
                if iv.appointment.visit_definition.code != '2180' and form != 'infantoffdrug':
                    self.assertEqual(meta_data.entry_status, 'NOT_REQUIRED')
Beispiel #8
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()

        print "register a mother "
        delivery_days_ago = 20
        delivery_datetime = datetime.today() - timedelta(
            days=delivery_days_ago - 3)
        maternal_consent = MaternalConsentFactory(
            study_site=study_site,
            consent_datetime=datetime.today() -
            timedelta(days=delivery_days_ago))
        print "Consent: {}".format(maternal_consent)
        m_registered_subject = RegisteredSubject.objects.get(
            subject_identifier=maternal_consent.subject_identifier)
        maternal_eligibility = MaternalEligibilityPostFactory(
            maternal_consent=maternal_consent,
            registered_subject=m_registered_subject,
            registration_datetime=datetime.today() -
            timedelta(days=delivery_days_ago))
        appointment = Appointment.objects.get(
            registered_subject=m_registered_subject,
            visit_definition__code='2000M')
        maternal_visit = MaternalVisitFactory(
            appointment=appointment,
            report_datetime=datetime.today() -
            timedelta(days=delivery_days_ago))
        print 'create a maternal_lab_del registering 2 of 2 infants'
        maternal_lab_del = MaternalLabDelFactory(
            maternal_visit=maternal_visit,
            live_infants=2,
            live_infants_to_register=2,
            delivery_datetime=delivery_datetime,
            has_ga='Yes',
            ga=37,
        )
        print 'maternal lab del: {}'.format(maternal_lab_del)
        print 'register infant 1 of 2'
        self.registered_subject1 = RegisteredSubject.objects.filter(
            relative_identifier=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=maternal_lab_del,
            dob=delivery_datetime.date())
        print 'first infant birth {}'.format(self.infant_birth1)
        self.infant_eligibility1 = InfantEligibilityFactory(
            infant_birth=self.infant_birth1,
            registered_subject=self.infant_birth1.registered_subject,
            clinical_jaundice='No',
            anemia_neutropenia='No',
            hiv_result_reference='PENDING',
            maternal_feeding_choice='BF',
            maternal_art_status='ON',
            rando_bf_duration='Yes',
            ctx_contra='No',
            congen_anomaly='No',
            randomization_site='Gaborone',
        )
        print 'First infant Eligibility {}'.format(self.infant_eligibility1)

        print "register infant 2 of 2"
        self.registered_subject2 = RegisteredSubject.objects.filter(
            relative_identifier=maternal_consent.subject_identifier).order_by(
                'subject_identifier')[1]
        print 'second registered subject {}'.format(self.registered_subject2)
        infant_birth2 = InfantBirthFactory(
            registered_subject=self.registered_subject2,
            maternal_lab_del=maternal_lab_del,
            dob=delivery_datetime.date())
        print 'second infant birth {}'.format(infant_birth2)
        self.registered_subject2.dob = infant_birth2.dob
        self.registered_subject2.gender = infant_birth2.gender
        self.registered_subject2.initials = infant_birth2.initials
        self.registered_subject2.relative_identifier = m_registered_subject.subject_identifier
        self.registered_subject2.save()