def tests_hiv_result4a2(self):
        """"""
        self.startup()
        panel = Panel.objects.get(name='Microtube')
        SubjectRequisitionFactory(
            subject_visit=self.subject_visit_male,
            panel=panel,
            aliquot_type=AliquotType.objects.get(alpha_code='WB'),
            site=self.study_site)

        HivTestingHistoryFactory(subject_visit=self.subject_visit_male,
                                 verbal_hiv_result=None,
                                 has_record='No',
                                 other_record='No')
        HivCareAdherenceFactory(subject_visit=self.subject_visit_male,
                                on_arv='No',
                                arv_evidence='No')
        HivResultFactory(
            subject_visit=self.subject_visit_male,
            hiv_result='NEG',
            hiv_result_datetime=self.subject_visit_male.report_datetime)
        subject_status_helper = SubjectStatusHelper(self.subject_visit_male)
        self.assertEquals(subject_status_helper.hiv_result, 'NEG')
        self.assertEquals(subject_status_helper.hiv_result_datetime,
                          self.subject_visit_male.report_datetime)
        self.assertEquals(subject_status_helper.new_pos, None)

        SubjectRequisitionFactory(
            subject_visit=self.subject_visit_male_annual,
            panel=panel,
            aliquot_type=AliquotType.objects.get(alpha_code='WB'),
            site=self.study_site)
        HivTestingHistoryFactory(subject_visit=self.subject_visit_male_annual,
                                 verbal_hiv_result=None,
                                 has_record='No',
                                 other_record='No')
        HivCareAdherenceFactory(subject_visit=self.subject_visit_male_annual,
                                on_arv='Yes',
                                arv_evidence='No')
        HivResultFactory(
            subject_visit=self.subject_visit_male_annual,
            hiv_result='POS',
            hiv_result_datetime=self.subject_visit_male_annual.report_datetime)
        subject_status_helper = SubjectStatusHelper(
            self.subject_visit_male_annual)
        self.assertEquals(subject_status_helper.hiv_result, 'POS')
        self.assertEquals(subject_status_helper.hiv_result_datetime,
                          self.subject_visit_male_annual.report_datetime)
        self.assertEquals(subject_status_helper.new_pos, True)
Example #2
0
 def test_create_aliquot_on_receive(self):
     """Asserts packing list items are created by the packing list."""
     self.startup()
     report_datetime = datetime.today()
     panel = Panel.objects.get(name='Microtube')
     subject_requisition = SubjectRequisitionFactory(
         subject_visit=self.subject_visit_male_annual,
         site=self.study_site,
         panel=panel,
         aliquot_type=AliquotType.objects.get(alpha_code='WB'))
     subject_referral = SubjectReferralFactory(
         subject_visit=self.subject_visit_male_annual,
         report_datetime=report_datetime)
     # receive
     lab_profile = site_labs.get(subject_requisition._meta.object_name)
     receive = lab_profile().receive(subject_requisition)
     identifiers = '\n'.join([
         a.aliquot_identifier
         for a in Aliquot.objects.filter(receive=receive)
     ])
     packing_list = PackingListFactory(list_items=identifiers)
     self.assertGreater(PackingListItem.objects.all().count(), 0)
     for identifier in identifiers:
         self.assertEquals(
             PackingListItem.objects.get(packing_list=packing_list,
                                         item_reference=identifier))
     packing_list = PackingListFactory(list_items=identifiers)
     for identifier in identifiers:
         self.assertEquals(
             PackingListItem.objects.get(packing_list=packing_list,
                                         item_reference=identifier))
    def hiv_result(self, status, subject_visit):
        """ Create HivResult for a particular survey"""
        aliquot_type = AliquotType.objects.all()[0]
        site = StudySite.objects.all()[0]
        microtube_panel = Panel.objects.get(name='Microtube')
        SubjectRequisitionFactory(subject_visit=subject_visit,
                                  panel=microtube_panel,
                                  aliquot_type=aliquot_type,
                                  site=site)

        self._hiv_result = HivResult.objects.create(
            subject_visit=subject_visit,
            hiv_result=status,
            report_datetime=datetime.today(),
            insufficient_vol=NO)
        return self._hiv_result
Example #4
0
 def test_create_aliquot_on_receive(self):
     """Asserts a primary aliquot is created on receiving a requisition."""
     self.startup()
     report_datetime = datetime.today()
     panel = Panel.objects.get(name='Microtube')
     subject_requisition = SubjectRequisitionFactory(
         subject_visit=self.subject_visit_male,
         site=self.study_site,
         panel=panel,
         aliquot_type=AliquotType.objects.get(alpha_code='WB'))
     # receive
     lab_profile = site_lab_profiles.get(
         subject_requisition._meta.object_name)
     receive = lab_profile().receive(subject_requisition)
     # assert primary aliquot
     try:
         Aliquot.objects.get(receive=receive)
     except Aliquot.DoesNotExist as e:
         self.fail(str(e))
Example #5
0
 def test_create_aliquot_on_receive_action(self):
     """Asserts a primary aliquot is created on receiving a requisition (using the action func)."""
     self.startup()
     report_datetime = datetime.today()
     panel = Panel.objects.get(name='Microtube')
     subject_requisition = SubjectRequisitionFactory(
         subject_visit=self.subject_visit_male,
         site=self.study_site,
         panel=panel,
         aliquot_type=AliquotType.objects.get(alpha_code='WB'))
     self.assertEquals(Aliquot.objects.all().count(), 0)
     # receive using the action
     flag_as_received(None, None, [subject_requisition])
     receive = Receive.objects.get(
         requisition_identifier=subject_requisition.requisition_identifier)
     # assert primary aliquot
     try:
         Aliquot.objects.all()[0]
     except IndexError:
         self.fail(str('No Aliquots created after receive'))
     try:
         Aliquot.objects.get(receive=receive)
     except Aliquot.DoesNotExist as e:
         self.fail(str(e))
    def tests_hiv_result4a1(self):
        """Asserts that hiv_result, result_datetime are carried over from baseline if
        HIV result is POS and at annual, new_pos is False."""
        self.startup()
        report_datetime_baseline = self.subject_visit_male.report_datetime
        panel = Panel.objects.get(name='Microtube')
        SubjectRequisitionFactory(
            subject_visit=self.subject_visit_male,
            panel=panel,
            aliquot_type=AliquotType.objects.get(alpha_code='WB'),
            site=self.study_site)
        HivTestingHistoryFactory(subject_visit=self.subject_visit_male,
                                 verbal_hiv_result=None,
                                 has_record='No',
                                 other_record='No')
        HivCareAdherenceFactory(subject_visit=self.subject_visit_male,
                                on_arv='No',
                                arv_evidence='No')
        HivResultFactory(subject_visit=self.subject_visit_male,
                         hiv_result='POS',
                         hiv_result_datetime=report_datetime_baseline)
        subject_status_helper = SubjectStatusHelper(self.subject_visit_male)
        self.assertEquals(subject_status_helper.hiv_result, 'POS')
        self.assertEquals(subject_status_helper.hiv_result_datetime.date(),
                          report_datetime_baseline.date())
        self.assertEquals(subject_status_helper.new_pos, True)

        HivCareAdherenceFactory(subject_visit=self.subject_visit_male_annual,
                                on_arv='Yes',
                                arv_evidence='No')
        subject_status_helper = SubjectStatusHelper(
            self.subject_visit_male_annual)
        self.assertEquals(subject_status_helper.hiv_result, 'POS')
        self.assertEquals(subject_status_helper.hiv_result_datetime.date(),
                          report_datetime_baseline.date())
        self.assertEquals(subject_status_helper.new_pos, False)
Example #7
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 test_p3(self):
        instances = []
        plot = PlotFactory(community='test_community6',
                           household_count=1,
                           status='residential_habitable')
        household = Household.objects.get(plot=plot)
        household_structure = HouseholdStructure.objects.get(
            survey=Survey.objects.all()[0])
        representative_eligibility = RepresentativeEligibilityFactory(
            household_structure=household_structure)
        household_member = HouseholdMemberFactory(
            household_structure=household_structure)
        enrollment_checklist = EnrollmentChecklistFactory(
            household_member=household_member,
            initials=household_member.initials,
            has_identity='Yes',
            dob=date(1989, 01, 01))
        self.assertTrue(enrollment_checklist.is_eligible)
        instances.append(enrollment_checklist)
        self.assertEqual(RegisteredSubject.objects.all().count(), 1)
        registered_subject = RegisteredSubject.objects.all()[0]
        site = StudySite.objects.all()[0]
        subject_consent = SubjectConsentFactory(
            study_site=site,
            household_member=household_member,
            registered_subject=household_member.registered_subject,
            dob=enrollment_checklist.dob,
            initials=enrollment_checklist.initials)
        instances.append(subject_consent)
        self.assertEqual(Appointment.objects.all().count(), 1)
        appointment = Appointment.objects.get(
            registered_subject=registered_subject)
        subject_visit = SubjectVisitFactory(household_member=household_member,
                                            appointment=appointment)
        instances.append(subject_visit)
        aliquot_type = AliquotType.objects.all()[0]
        panel = Panel.objects.all()[0]
        subjects_requisition = SubjectRequisitionFactory(
            subject_visit=subject_visit,
            panel=panel,
            site=site,
            aliquot_type=aliquot_type,
        )
        self.assertEqual(Aliquot.objects.all().count(), 0)
        subjects_requisition.is_receive = True
        subjects_requisition.is_receive_datetime = datetime.now()
        subjects_requisition.save()
        lab_profile = site_lab_profiles.get(
            subjects_requisition._meta.object_name)
        lab_profile().receive(subjects_requisition)
        receive = Receive.objects.all()[0]
        self.assertEqual(Aliquot.objects.all().count(), 1)
        aliquot = Aliquot.objects.all()[0]
        processing = ProcessingFactory(profile=AliquotProfile.objects.all()[0],
                                       aliquot=aliquot)
        for al in Aliquot.objects.all():
            instances.append(al)
        instances.append(processing)
        instances.append(receive)
        self.assertEqual(PackingListItem.objects.all().count(), 0)
        packing_list = PackingListFactory(
            list_items=aliquot.aliquot_identifier)
        instances.append(packing_list)
        packing_list.list_items = al.aliquot_identifier
        print packing_list.list_items
        packing_list.save()
        #self.assertEquals(PackingListItem.objects.all().count(), 1)
        #instances.append(PackingListItem.objects.all()[0])

        print 'INSTANCE: ' + str(instances)
        for obj in instances:
            print 'test natural key on {0}'.format(obj._meta.object_name)
            natural_key = obj.natural_key()
            get_obj = obj.__class__.objects.get_by_natural_key(*natural_key)
            self.assertEqual(obj.pk, get_obj.pk)
        # pp = pprint.PrettyPrinter(indent=4)
        for obj in instances:
            print 'test serializing/deserializing {0}'.format(
                obj._meta.object_name)
            outgoing_transaction = SerializeToTransaction().serialize(
                obj.__class__, obj, False, True, 'default')
            for transaction in serializers.deserialize(
                    "json",
                    FieldCryptor('aes',
                                 'local').decrypt(outgoing_transaction.tx)):
                self.assertEqual(transaction.object.pk, obj.pk)
Example #9
0
    def test_p3(self):
        print 'get a community name from the mapper classes'
        mapper = site_mappers.get_current_mapper()
        community = mapper.map_area
        print 'No. of SURVEY = ' + str(Survey.objects.all().count())
        plot = PlotFactory(community=community, household_count=1, status='residential_habitable')
        print 'No. of HOUSEHOLDS = ' + str(Household.objects.all().count())
        Household.objects.get(plot=plot)
        self.assertEquals(HouseholdStructure.objects.all().count(), 3)
        self.assertEquals(Survey.objects.all().count(), 3)
        household_structure = HouseholdStructure.objects.get(survey=Survey.objects.all()[0])
        RepresentativeEligibilityFactory(household_structure=household_structure)
        household_member = HouseholdMemberFactory(household_structure=household_structure)
        enrollment_checklist = EnrollmentChecklistFactory(household_member=household_member, initials=household_member.initials, has_identity='Yes', dob=date(1989, 01, 01))
        study_site = StudySite.objects.all()[0]
        subject_consent = SubjectConsentFactory(study_site=study_site, household_member=household_member, registered_subject=household_member.registered_subject,
                                                dob=enrollment_checklist.dob, initials=enrollment_checklist.initials)
        print subject_consent.subject_identifier
        print 'get registered subject'
        registered_subject = RegisteredSubject.objects.get(subject_identifier=subject_consent.subject_identifier)
        instances = []
        instances.append(subject_consent)
        instances.append(registered_subject)

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

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

        print 'INSTANCE: ' + str(instances)
        for obj in instances:
            print 'test natural key on {0}'.format(obj._meta.object_name)
            natural_key = obj.natural_key()
            get_obj = obj.__class__.objects.get_by_natural_key(*natural_key)
            self.assertEqual(obj.pk, get_obj.pk)
        # pp = pprint.PrettyPrinter(indent=4)
        for obj in instances:
            print 'test serializing/deserializing {0}'.format(obj._meta.object_name)
            outgoing_transaction = SerializeToTransaction().serialize(obj.__class__, obj, False, True, 'default')
            # pp.pprint(FieldCryptor('aes', 'local').decrypt(outgoing_transaction.tx))
            for transaction in serializers.deserialize("json", FieldCryptor('aes', 'local').decrypt(outgoing_transaction.tx)):
                self.assertEqual(transaction.object.pk, obj.pk)
 def tests_hiv_result10(self):
     """Other record confirms a verbal positive as evidence of HIV infection not on ART."""
     self.startup()
     self.assertTrue(
         RequisitionMetaData.objects.filter(
             appointment=self.subject_visit_male.appointment,
             lab_entry__requisition_panel__name='Microtube',
             entry_status=REQUIRED).count() == 1)
     self.assertTrue(
         RequisitionMetaData.objects.filter(
             appointment=self.subject_visit_male.appointment,
             lab_entry__requisition_panel__name='Research Blood Draw',
             entry_status=NOT_REQUIRED).count() == 1)
     self.assertTrue(
         RequisitionMetaData.objects.filter(
             appointment=self.subject_visit_male.appointment,
             lab_entry__requisition_panel__name='Viral Load',
             entry_status=NOT_REQUIRED).count() == 1)
     site_rule_groups.autodiscover()
     HivTestingHistoryFactory(subject_visit=self.subject_visit_male,
                              verbal_hiv_result='NEG',
                              has_record='No',
                              other_record='No')
     panel = Panel.objects.get(name='Microtube')
     SubjectRequisitionFactory(
         subject_visit=self.subject_visit_male,
         site=self.site_code,
         panel=panel,
         aliquot_type=AliquotType.objects.get(alpha_code='WB'))
     HivResultFactory(
         subject_visit=self.subject_visit_male,
         hiv_result='POS',
         hiv_result_datetime=datetime.today(),
     )
     self.assertTrue(
         ScheduledEntryMetaData.objects.filter(
             appointment=self.subject_visit_male.appointment,
             entry__model_name='hicenrollment',
             entry_status=NOT_REQUIRED).count() == 1)
     self.assertTrue(
         ScheduledEntryMetaData.objects.filter(
             appointment=self.subject_visit_male.appointment,
             entry__model_name='hivresult',
             entry_status=KEYED).count() == 1)
     self.assertTrue(
         ScheduledEntryMetaData.objects.filter(
             appointment=self.subject_visit_male.appointment,
             entry__model_name='pima',
             entry_status=REQUIRED).count() == 1)
     self.assertTrue(
         RequisitionMetaData.objects.filter(
             appointment=self.subject_visit_male.appointment,
             lab_entry__requisition_panel__name='Microtube',
             entry_status=KEYED).count() == 1)
     self.assertTrue(
         RequisitionMetaData.objects.filter(
             appointment=self.subject_visit_male.appointment,
             lab_entry__requisition_panel__name='Research Blood Draw',
             entry_status=REQUIRED).count() == 1)
     self.assertTrue(
         RequisitionMetaData.objects.filter(
             appointment=self.subject_visit_male.appointment,
             lab_entry__requisition_panel__name='Viral Load',
             entry_status=REQUIRED).count() == 1)
     site_rule_groups._registry = {}