def test_get_case_location_ancestor_repeaters_multi(self): """ get_case_location_ancestor_repeaters should return the repeater at the closest ancestor location """ form, (gardens_case, ) = _create_case( domain=self.domain, case_id=uuid.uuid4().hex, owner_id=self.locations['Gardens'].location_id) cape_town_repeater = OpenmrsRepeater.wrap({ 'doc_type': 'OpenmrsRepeater', 'domain': self.domain, 'location_id': self.locations['Cape Town'].location_id, }) cape_town_repeater.save() western_cape_repeater = OpenmrsRepeater.wrap({ 'doc_type': 'OpenmrsRepeater', 'domain': self.domain, 'location_id': self.locations['Western Cape'].location_id, }) western_cape_repeater.save() repeaters = get_case_location_ancestor_repeaters(gardens_case) self.assertEqual(repeaters, [cape_town_repeater])
def setUpRepeater(self): observations = [ { "doc_type": "ObservationMapping", "concept": "5090AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "value": { "doc_type": "FormQuestion", "form_question": "/data/height" }, "case_property": "height" } ] diagnoses = [ { "doc_type": "ObservationMapping", "concept": "f7e8da66-f9a7-4463-a8ca-99d8aeec17a0", "value": { "doc_type": "FormQuestionMap", "form_question": "/data/bahmni_hypothermia", "value_map": { "emergency_room_user_id": "Hypothermia", # Value must match diagnosis name }, "direction": "in", }, "case_property": "owner_id" } ] self.repeater = OpenmrsRepeater.wrap(self.get_repeater_dict(observations, diagnoses))
def setUpClass(cls): super().setUpClass() cls.domain = create_domain(TEST_DOMAIN) cls.location_type = LocationType.objects.create( domain=TEST_DOMAIN, name='test_location_type', ) cls.location = SQLLocation.objects.create( domain=TEST_DOMAIN, name='test location', location_id='test_location', location_type=cls.location_type, ) cls.user = CommCareUser.create(TEST_DOMAIN, 'username', 'password', None, None, location=cls.location) cls.repeater = OpenmrsRepeater.wrap({ "domain": TEST_DOMAIN, "url": "https://demo.mybahmni.org/openmrs/", "auth_type": BASIC_AUTH, "username": "******", "password": "******", "white_listed_case_types": ["case"], "location_id": cls.location.location_id, "atom_feed_enabled": True, "openmrs_config": { "openmrs_provider": "", "case_config": {}, "form_configs": [] } }) cls.repeater.save()
def test_observation_mappings(): repeater = OpenmrsRepeater.wrap({ "openmrs_config": { "openmrs_provider": "", "case_config": {}, "form_configs": [{ "xmlns": "http://openrosa.org/formdesigner/9ECA0608-307A-4357-954D-5A79E45C3879", "openmrs_encounter_type": "81852aee-3f10-11e4-adec-0800271c1b75", "openmrs_visit_type": "c23d6c9d-3f10-11e4-adec-0800271c1b75", "openmrs_observations": [ { "concept": "397b9631-2911-435a-bf8a-ae4468b9c1d4", "case_property": "abnormal_temperature", "value": { "doc_type": "FormQuestionMap", "form_question": "/data/abnormal_temperature", "value_map": { "yes": "05ced69b-0790-4aad-852f-ba31fe82fbd9", "no": "eea8e4e9-4a91-416c-b0f5-ef0acfbc51c0" }, }, }, { "concept": "397b9631-2911-435a-bf8a-ae4468b9c1d4", "case_property": "bahmni_abnormal_temperature", "value": { "doc_type": "ConstantString", "value": "", "direction": "in", }, }, ] }] } }) observation_mappings = repeater.observation_mappings eq(observation_mappings, { '397b9631-2911-435a-bf8a-ae4468b9c1d4': [ ObservationMapping( concept='397b9631-2911-435a-bf8a-ae4468b9c1d4', case_property='abnormal_temperature', value=FormQuestionMap( form_question='/data/abnormal_temperature', value_map={ 'yes': '05ced69b-0790-4aad-852f-ba31fe82fbd9', 'no': 'eea8e4e9-4a91-416c-b0f5-ef0acfbc51c0' } ) ), ObservationMapping( concept='397b9631-2911-435a-bf8a-ae4468b9c1d4', case_property='bahmni_abnormal_temperature', value=ConstantString( direction='in', doc_type='ConstantString', value='' ) ) ] })
def setUpRepeater(self): observations = [{ "doc_type": "ObservationMapping", "concept": "5090AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "value": { "doc_type": "FormQuestion", "form_question": "/data/height" }, "case_property": "height" }] diagnoses = [ { "doc_type": "ObservationMapping", "concept": "f7e8da66-f9a7-4463-a8ca-99d8aeec17a0", "value": { "doc_type": "FormQuestionMap", "direction": "in", "form_question": "[unused when direction == 'in']", "value_map": { "emergency_room_user_id": "Hypothermia", # Value must match diagnosis name } }, "case_property": "owner_id" }, { "doc_type": "ObservationMapping", "concept": "f7e8da66-f9a7-4463-a8ca-99d8aeec17a0", "value": { "doc_type": "JsonPathCasePropertyMap", "direction": "in", "jsonpath": "codedAnswer.name", "case_property": "[unused when direction == 'in']", "value_map": { "yes": "Hypothermia" } }, "case_property": "hypothermia_diagnosis" }, { "doc_type": "ObservationMapping", "concept": "f7e8da66-f9a7-4463-a8ca-99d8aeec17a0", "value": { "doc_type": "JsonPathCaseProperty", "direction": "in", "jsonpath": "diagnosisDateTime", "case_property": "[unused when direction == 'in']", "commcare_data_type": "cc_date", "external_data_type": "omrs_datetime" }, "case_property": "hypothermia_date" } ] self.repeater = OpenmrsRepeater.wrap( self.get_repeater_dict(observations, diagnoses))
def test_get_case_location_ancestor_repeaters_same(self): """ get_case_location_ancestor_repeaters should return the repeater at the same location as the case """ gardens = self.locations['Gardens'] form, (case, ) = _create_case(domain=self.domain, case_id=uuid.uuid4().hex, owner_id=gardens.location_id) gardens_repeater = OpenmrsRepeater.wrap({ 'doc_type': 'OpenmrsRepeater', 'domain': self.domain, 'location_id': gardens.location_id, }) gardens_repeater.save() repeaters = get_case_location_ancestor_repeaters(case) self.assertEqual(repeaters, [gardens_repeater])
def test_get_case_location_ancestor_repeaters_multi(self): """ get_case_location_ancestor_repeaters should return the repeater at the closest ancestor location """ form, (gardens_case, ) = _create_case( domain=self.domain, case_id=uuid.uuid4().hex, owner_id=self.locations['Gardens'].location_id ) cape_town_repeater = OpenmrsRepeater.wrap({ 'doc_type': 'OpenmrsRepeater', 'domain': self.domain, 'location_id': self.locations['Cape Town'].location_id, }) cape_town_repeater.save() western_cape_repeater = OpenmrsRepeater.wrap({ 'doc_type': 'OpenmrsRepeater', 'domain': self.domain, 'location_id': self.locations['Western Cape'].location_id, }) western_cape_repeater.save() repeaters = get_case_location_ancestor_repeaters(gardens_case) self.assertEqual(repeaters, [cape_town_repeater])
def test_get_case_location_ancestor_repeaters_same(self): """ get_case_location_ancestor_repeaters should return the repeater at the same location as the case """ gardens = self.locations['Gardens'] form, (case, ) = _create_case(domain=self.domain, case_id=uuid.uuid4().hex, owner_id=gardens.location_id) gardens_repeater = OpenmrsRepeater.wrap({ 'doc_type': 'OpenmrsRepeater', 'domain': self.domain, 'location_id': gardens.location_id, }) gardens_repeater.save() repeaters = get_case_location_ancestor_repeaters(case) self.assertEqual(repeaters, [gardens_repeater])
def setUpRepeaterForExtCase(self): observations = [ { "doc_type": "ObservationMapping", "concept": "5090AAAAAAAAAAAAAAAAAAAAAAAAAAAA", "value": { "doc_type": "FormQuestion", "form_question": "/data/height" }, "indexed_case_mapping": { "identifier": "parent", "case_type": "observation", "relationship": "extension", "case_properties": [ { "doc_type": "JsonPathCaseProperty", "jsonpath": "concept.name", "case_property": "case_name", }, { "doc_type": "JsonPathCaseProperty", "jsonpath": "value", "case_property": "observation_value", } ] } } ] diagnoses = [ { "doc_type": "ObservationMapping", "concept": "f7e8da66-f9a7-4463-a8ca-99d8aeec17a0", "value": { "doc_type": "FormQuestionMap", "form_question": "/data/bahmni_hypothermia", "value_map": { "emergency_room_user_id": "Hypothermia", # Value must match diagnosis name }, "direction": "in", }, "indexed_case_mapping": { "identifier": "parent", "case_type": "diagnosis", "relationship": "extension", "case_properties": [ { "doc_type": "JsonPathCaseProperty", "jsonpath": "codedAnswer.name", "case_property": "case_name", }, { "doc_type": "JsonPathCaseProperty", "jsonpath": "certainty", "case_property": "certainty", }, { "doc_type": "JsonPathCasePropertyMap", "jsonpath": "order", "case_property": "is_primary", "value_map": { "yes": "PRIMARY", "no": "SECONDARY" } }, { "doc_type": "CasePropertyConstantValue", "case_property": "code", "value": "T68 (ICD 10 - WHO)" } ] } } ] self.repeater = OpenmrsRepeater.wrap(self.get_repeater_dict(observations, diagnoses))