Beispiel #1
0
 def existing_person_case(self):
     """
     Get the existing person case for this nikshay ID, or None if no episode case exists
     """
     if self.existing_occurrence_case:
         try:
             return get_first_parent_of_case(
                 self.domain, self.existing_occurrence_case.case_id, PERSON_CASE_TYPE
             )
         except ENikshayCaseNotFound:
             return None
Beispiel #2
0
 def existing_occurrence_case(self):
     """
     Get the existing occurrence case for this nikshay ID, or None if no occurrence case exists
     """
     if self.existing_episode_case:
         try:
             return get_first_parent_of_case(
                 self.domain, self.existing_episode_case.case_id, OCCURRENCE_CASE_TYPE
             )
         except ENikshayCaseNotFound:
             return None
Beispiel #3
0
def _get_case_ids_related_to_episode(domain, episode_case_id):
    occurrence_case = get_first_parent_of_case(domain, episode_case_id, CASE_TYPE_OCCURRENCE)
    person_case = get_first_parent_of_case(domain, occurrence_case.case_id, CASE_TYPE_PERSON)
    return _get_case_ids_related_to_person(domain, person_case.case_id)
Beispiel #4
0
    def test(self):
        migrator = ENikshay2BMigrator(self.domain, commit=True)
        # first check some utils
        person_case_ids = migrator.get_relevant_person_case_ids()
        person_case_sets = list(
            migrator.get_relevant_person_case_sets(person_case_ids))
        self.assertEqual(1, len(person_case_sets))
        person = person_case_sets[0]

        self.assertEqual('roland-deschain', person.person.case_id)
        self.assertItemsEqual(['roland-deschain-occurrence'],
                              [c.case_id for c in person.occurrences])
        self.assertItemsEqual(['roland-deschain-occurrence-episode'],
                              [c.case_id for c in person.episodes])
        self.assertItemsEqual(['roland-deschain-occurrence-test'],
                              [c.case_id for c in person.tests])
        self.assertItemsEqual(['roland-deschain-referral'],
                              [c.case_id for c in person.referrals])
        self.assertItemsEqual(['roland-deschain-referral-trail'],
                              [c.case_id for c in person.trails])
        self.assertItemsEqual(
            ['roland-deschain-occurrence-episode-drtb_hiv_referral'],
            [c.case_id for c in person.drtb_hiv])

        # run the actual migration
        migrator.migrate()

        # check the results
        accessor = CaseAccessors(self.domain)
        new_person = accessor.get_case(person.person.case_id)
        self.assertDictContainsSubset(
            {
                'area': 'phi_area',
                'referred_outside_enikshay_date': 'date_referred_out',
                'referred_outside_enikshay_by_id': 'referred_by_id',
                'contact_phone_number': '911234567890',
                'current_episode_type': "confirmed_tb",
                'alcohol_history': "alcohol_history",
                'alcohol_deaddiction': "alcohol_deaddiction",
                'tobacco_user': "******",
                'occupation': "occupation",
                'phone_number_other': "phone_number_other",
                'phi_name': 'PHI',
                'tu_name': 'TU',
                'tu_id': self.locations['TU'].location_id,
                'dto_name': 'DTO',
                'dto_id': self.locations['DTO'].location_id,
                'dataset': 'real',
                'updated_by_migration': 'enikshay_2b_case_properties',
            }, new_person.dynamic_case_properties())

        new_occurrence = accessor.get_case(person.occurrences[0].case_id)
        self.assertDictContainsSubset(
            {
                'current_episode_type': 'confirmed_tb',
                'disease_classification': 'disease_classification',
                'site_choice': 'site_choice',
                'site_detail': 'site_detail',
                'key_population_status': 'key_population_status',
                'key_populations': 'key_populations',
            }, new_occurrence.dynamic_case_properties())

        new_episode = accessor.get_case(person.episodes[0].case_id)
        self.assertDictContainsSubset(
            {
                'treatment_status': 'initiated_second_line_treatment',
                'date_of_diagnosis': 'date_reported',
                'dosage_display': 'full_dosage',
                'dosage_summary': 'full_dosage',
                'rft_general': 'diagnosis_dstb',
                'diagnosis_test_type': 'chest_x-ray',
                'diagnosis_test_type_label': "Chest X-ray",
                'is_active': 'yes',
            }, new_episode.dynamic_case_properties())

        new_test = accessor.get_case(person.tests[0].case_id)
        self.assertDictContainsSubset(
            {
                'is_direct_test_entry': 'no',
                'rft_drtb_diagnosis': 'diagnostic_drtb_test_reason',
                'dataset': 'real',
                'rft_general': 'diagnosis_dstb',
                'rft_dstb_diagnosis': 'diagnostic_test_reason',
                'rft_dstb_followup': 'definitely_not_private_ntm',
                'episode_case_id': 'roland-deschain-occurrence-episode',
                'result_summary_display':
                "TB Detected\nR: Res\nCount of bacilli: 11\nthat looks infected",
                'drug_resistance_list': 'r',
            }, new_test.dynamic_case_properties())

        new_referral = accessor.get_case(person.referrals[0].case_id)
        self.assertDictContainsSubset(
            {
                'referral_initiated_date': 'referral_date',
                'referred_to_name': 'referred_to_location_name',
                'referred_by_name': '',
                'referral_rejection_reason_other_detail':
                'reason_for_refusal_other_detail',
                'referral_rejection_reason': 'reason_for_refusal',
                'referral_closed_date': 'acceptance_refusal_date',
                'accepted_by_name': 'phi',
            }, new_referral.dynamic_case_properties())
        parent = get_first_parent_of_case(self.domain, new_referral,
                                          'occurrence')
        self.assertEqual(new_occurrence.case_id, parent.case_id)

        new_trail = accessor.get_case(person.trails[0].case_id)
        parent = get_first_parent_of_case(self.domain, new_trail, 'occurrence')
        self.assertEqual(new_occurrence.case_id, parent.case_id)

        new_drtb_hiv = accessor.get_case(person.drtb_hiv[0].case_id)
        self.assertTrue(new_drtb_hiv.closed)

        secondary_owner_id = accessor.get_case_ids_in_domain(
            type='secondary_owner')[0]
        new_secondary_owner = accessor.get_case(secondary_owner_id)
        self.assertEqual('person_id-drtb-hiv', new_secondary_owner.name)
        self.assertDictContainsSubset({
            'secondary_owner_type': 'drtb-hiv',
        }, new_secondary_owner.dynamic_case_properties())
        self.assertEqual("drtb_hiv_referral_owner",
                         new_secondary_owner.owner_id)
        parent = get_first_parent_of_case(self.domain, new_secondary_owner,
                                          'occurrence')
        self.assertEqual(new_occurrence.case_id, parent.case_id)