<commit_before>from collections import OrderedDict
from datetime import date

from django.core.management import call_command
from django.test import TestCase

from casexml.apps.case.sharedmodels import CommCareCaseIndex
from corehq.apps.domain.models import Domain
from corehq.apps.locations.models import SQLLocation, LocationType
from corehq.form_processor.interfaces.dbaccessors import CaseAccessors
from custom.enikshay.nikshay_datamigration.models import Followup, Outcome, PatientDetail


class TestCreateEnikshayCases(TestCase):

    def setUp(self):
        super(TestCreateEnikshayCases, self).setUp()

        patient_detail = PatientDetail.objects.create(
            Tbunitcode=1,
            PregId='MH-ABD-05-16-0001',
            pname='A B C',
            pgender='M',
            page=18,
            paadharno=867386000000,
            paddress='Cambridge MA',
            pmob='9987328695',
            pregdate1=date(2016, 12, 13),
            cmob='123',
            dcpulmunory='',
            dotpType=1,
            PHI=2,
            atbtreatment='',
            Ptype=3,
            pcategory=4,

        )
        Outcome.objects.create(
            PatientId=patient_detail,
            HIVStatus='negative',
        )
        # Household.objects.create(
        #     PatientID=patient_detail,
        # )
        for i in range(5):
            Followup.objects.create(
                id=i+1,
                PatientID=patient_detail,
            )

        self.domain = Domain(name='enikshay-test-domain')
        self.domain.save()

        loc_type = LocationType.objects.create(
            domain=self.domain.name,
            name='nik'
        )

        SQLLocation.objects.create(
            domain=self.domain.name,
            location_type=loc_type,
            metadata={
                'nikshay_code': 'MH-ABD-05-16',
            },
        )

        self.case_accessor = CaseAccessors(self.domain.name)

    def tearDown(self):
        Outcome.objects.all().delete()
        Followup.objects.all().delete()
        # Household.objects.all().delete()
        PatientDetail.objects.all().delete()

        self.domain.delete()

        SQLLocation.objects.all().delete()
        LocationType.objects.all().delete()

        super(TestCreateEnikshayCases, self).tearDown()

    def test_case_properties(self):
        call_command('create_enikshay_cases', self.domain.name)

        # self.assertEqual(
        #     ['MH-ABD-05-16-0001'],
        #     self.case_accessor.get_case_ids_in_domain(
        #         type='person'
        #     )
        # )

        person_case = self.case_accessor.get_case(self.case_accessor.get_case_ids_in_domain(type='person')[0])
        self.assertEqual(
            OrderedDict([
                ('aadhaar_number', '867386000000'),
                ('age_entered', '18'),
                ('current_address', 'Cambridge MA'),
                ('current_address_district_choice', ''),
                ('current_address_state_choice', 'default'),
                ('first_name', 'A'),
                ('last_name', 'C'),
                ('middle_name', 'B'),
                ('migration_created_case', 'True'),
                ('nikshay_id', 'MH-ABD-05-16-0001'),
                ('permanent_address_district_choice', ''),
                ('permanent_address_state_choice', 'default'),
                ('phi', '2'),
                ('sex', 'male'),
                ('tu_choice', '1'),
            ]),
            person_case.dynamic_case_properties()
        )<commit_msg>test for person case name<commit_after>from collections import OrderedDict
from datetime import date

from django.core.management import call_command
from django.test import TestCase

from casexml.apps.case.sharedmodels import CommCareCaseIndex
from corehq.apps.domain.models import Domain
from corehq.apps.locations.models import SQLLocation, LocationType
from corehq.form_processor.interfaces.dbaccessors import CaseAccessors
from custom.enikshay.nikshay_datamigration.models import Followup, Outcome, PatientDetail


class TestCreateEnikshayCases(TestCase):

    def setUp(self):
        super(TestCreateEnikshayCases, self).setUp()

        patient_detail = PatientDetail.objects.create(
            Tbunitcode=1,
            PregId='MH-ABD-05-16-0001',
            pname='A B C',
            pgender='M',
            page=18,
            paadharno=867386000000,
            paddress='Cambridge MA',
            pmob='9987328695',
            pregdate1=date(2016, 12, 13),
            cmob='123',
            dcpulmunory='',
            dotpType=1,
            PHI=2,
            atbtreatment='',
            Ptype=3,
            pcategory=4,

        )
        Outcome.objects.create(
            PatientId=patient_detail,
            HIVStatus='negative',
        )
        # Household.objects.create(
        #     PatientID=patient_detail,
        # )
        for i in range(5):
            Followup.objects.create(
                id=i+1,
                PatientID=patient_detail,
            )

        self.domain = Domain(name='enikshay-test-domain')
        self.domain.save()

        loc_type = LocationType.objects.create(
            domain=self.domain.name,
            name='nik'
        )

        SQLLocation.objects.create(
            domain=self.domain.name,
            location_type=loc_type,
            metadata={
                'nikshay_code': 'MH-ABD-05-16',
            },
        )

        self.case_accessor = CaseAccessors(self.domain.name)

    def tearDown(self):
        Outcome.objects.all().delete()
        Followup.objects.all().delete()
        # Household.objects.all().delete()
        PatientDetail.objects.all().delete()

        self.domain.delete()

        SQLLocation.objects.all().delete()
        LocationType.objects.all().delete()

        super(TestCreateEnikshayCases, self).tearDown()

    def test_case_properties(self):
        call_command('create_enikshay_cases', self.domain.name)

        # self.assertEqual(
        #     ['MH-ABD-05-16-0001'],
        #     self.case_accessor.get_case_ids_in_domain(
        #         type='person'
        #     )
        # )

        person_case = self.case_accessor.get_case(self.case_accessor.get_case_ids_in_domain(type='person')[0])
        self.assertEqual(
            OrderedDict([
                ('aadhaar_number', '867386000000'),
                ('age_entered', '18'),
                ('current_address', 'Cambridge MA'),
                ('current_address_district_choice', ''),
                ('current_address_state_choice', 'default'),
                ('first_name', 'A'),
                ('last_name', 'C'),
                ('middle_name', 'B'),
                ('migration_created_case', 'True'),
                ('nikshay_id', 'MH-ABD-05-16-0001'),
                ('permanent_address_district_choice', ''),
                ('permanent_address_state_choice', 'default'),
                ('phi', '2'),
                ('sex', 'male'),
                ('tu_choice', '1'),
            ]),
            person_case.dynamic_case_properties()
        )
        self.assertEqual('A B C', person_case.name)
{'fraction_non_alphanumeric': 0.1186558839933073, 'fraction_numerical': 0.024539877300613498, 'mean_word_length': 1.900525677315002, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '141069', 'n_tokens_mistral': 2259, 'n_tokens_neox': 2045, 'n_words': 304}