def test_get_case_blocks_from_observations(self): self.setUpRepeaterForExtCase() encounter = self.get_json('encounter') observations = encounter['observations'] case_block_kwargs, case_blocks = get_case_block_kwargs_from_observations( observations, get_observation_mappings(self.repeater), ('test-case-id', 'patient', 'default-owner-id')) self.assertEqual(case_block_kwargs, {'update': {}}) self.assertEqual(len(case_blocks), 1) date_modified = case_blocks[0].date_modified.isoformat() + 'Z' date_opened = case_blocks[0].date_opened case_block = f""" <case case_id="{case_blocks[0].case_id}" » date_modified="{date_modified}" » xmlns="http://commcarehq.org/case/transaction/v2"> <create> <case_type>observation</case_type> <case_name>HEIGHT</case_name> <owner_id>default-owner-id</owner_id> </create> <update> <date_opened>{date_opened}</date_opened> <observation_value>105</observation_value> </update> <index> <parent case_type="patient" relationship="extension">test-case-id</parent> </index> </case>""" case_block = ''.join( (l.strip() for l in case_block.split('\n'))).replace('»', '') self.assertEqual(case_blocks[0].as_text(), case_block)
def test_get_case_block_kwargs_from_observations(self): self.setUpRepeater() encounter = self.get_json('encounter') observations = encounter['observations'] case_block_kwargs, case_blocks = get_case_block_kwargs_from_observations( observations, get_observation_mappings(self.repeater), (None, None, None)) self.assertEqual(case_block_kwargs, {'update': {'height': 105}}) self.assertEqual(case_blocks, [])
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 = get_observation_mappings(repeater) eq(observation_mappings, { '397b9631-2911-435a-bf8a-ae4468b9c1d4': [ ObservationMapping( 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' } } ), ObservationMapping( concept='397b9631-2911-435a-bf8a-ae4468b9c1d4', case_property='bahmni_abnormal_temperature', value={ "direction": 'in', "doc_type": "ConstantString", "value": '' } ) ] })