def send_request(self, repeat_record, payload): # Notify admins if API version is not supported self.get_api_version() value_source_configs = [] for case_config in self.dhis2_entity_config.case_configs: value_source_configs.append(case_config.org_unit_id) value_source_configs.append(case_config.tei_id) for value_source_config in case_config.attributes.values(): value_source_configs.append(value_source_config) case_trigger_infos = get_relevant_case_updates_from_form_json( self.domain, payload, case_types=self.white_listed_case_types, extra_fields=[ c['case_property'] for c in value_source_configs if 'case_property' in c ], form_question_values=get_form_question_values(payload), ) requests = self.connection_settings.get_requests( repeat_record.payload_id) try: return send_dhis2_entities(requests, self, case_trigger_infos) except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() tb_lines = traceback.format_exception(exc_type, exc_value, exc_traceback) requests.notify_error( f"Error sending Entities to {self}: {exc_value!r}", details="".join(tb_lines)) raise
def test_get_case_updates_for_registration(self): """ get_relevant_case_updates_from_form_json should fetch case updates from teh given form JSON """ self.assertEqual( get_relevant_case_updates_from_form_json( 'openmrs-repeater-test', self.get_json('registration'), case_types=['paciente'], extra_fields=[] ), [ CaseTriggerInfo( domain='openmrs-repeater-test', case_id='65e55473-e83b-4d78-9dde-eaf949758997', type='paciente', name='Elsa', owner_id=None, modified_by=None, updates={ 'case_name': 'Elsa', 'case_type': 'paciente', 'owner_id': '9393007a6921eecd4a9f20eefb5c7a8e', 'estado_tarv': '1', 'tb': '0' }, created=True, closed=False, extra_fields={}, form_question_values={} ) ] )
def send_request(self, repeat_record, payload): value_source_configs: Iterable[JsonDict] = chain( self.openmrs_config.case_config.patient_identifiers.values(), self.openmrs_config.case_config.person_properties.values(), self.openmrs_config.case_config.person_preferred_name.values(), self.openmrs_config.case_config.person_preferred_address.values(), self.openmrs_config.case_config.person_attributes.values(), ) case_trigger_infos = get_relevant_case_updates_from_form_json( self.domain, payload, case_types=self.white_listed_case_types, extra_fields=[ conf["case_property"] for conf in value_source_configs if "case_property" in conf ], form_question_values=get_form_question_values(payload), ) requests = get_requests(self, repeat_record.payload_id) try: response = send_openmrs_data( requests, self.domain, payload, self.openmrs_config, case_trigger_infos, ) except Exception as err: requests.notify_exception(str(err)) return RepeaterResponse(400, 'Bad Request', pformat_json(str(err))) return response
def test__get_relevant_case_updates_from_form_json_without_case_types( self, get_cases): get_cases.return_value = [self.case_1, self.case_2] result = get_relevant_case_updates_from_form_json( self.domain, _get_form_json(), [], self.extra_fields) self.assertEqual(len(result), 3)
def test_get_case_updates_for_followup(self): """ Specifying `extra_fields` should fetch the current value from the case """ self.assertEqual( get_relevant_case_updates_from_form_json( 'openmrs-repeater-test', self.get_json('followup'), case_types=['paciente'], extra_fields=['name', 'estado_tarv', 'tb', 'bandersnatch'], ), [ CaseTriggerInfo(domain='openmrs-repeater-test', case_id='65e55473-e83b-4d78-9dde-eaf949758997', type='paciente', name='Elsa', owner_id=None, modified_by=None, updates={ 'estado_tarv': '1', 'tb': '1' }, created=False, closed=False, extra_fields={ 'name': 'Elsa', 'estado_tarv': '1', 'tb': '0', 'bandersnatch': None }, form_question_values={}) ])
def get_payload_info( cls, payload_generator: BasePayloadGenerator, ) -> Tuple[dict, CaseTriggerInfo]: payload = payload_generator.get_payload(None, cls.form) if isinstance(payload, str): payload = json.loads(payload) [info] = get_relevant_case_updates_from_form_json( cls.domain, payload, case_types=None, extra_fields=list(cls.case_update.keys()), form_question_values=get_form_question_values(payload), ) return payload, info
def get_payload_info( self, payload_generator: BasePayloadGenerator, ) -> Tuple[dict, CaseTriggerInfo]: payload = payload_generator.get_payload(None, self.form) if isinstance(payload, str): payload = json.loads(payload) [info] = get_relevant_case_updates_from_form_json( self.domain, payload, case_types=None, extra_fields=['year', 'breakfast', 'decimal'], form_question_values=get_form_question_values(payload), ) return payload, info