def handle_response(self, result, repeat_record): if isinstance(result, Exception): attempt = repeat_record.handle_exception(result) self.generator.handle_exception(result, repeat_record) return attempt # A successful response returns a Nikshay ID like 00001 # Failures also return with status code 200 and some message like # Dublicate Entry or Invalid data format # (Dublicate is not a typo) message = parse_SOAP_response( repeat_record.repeater.url, repeat_record.repeater.operation, result, ) if isinstance(message, basestring) and message.isdigit(): attempt = repeat_record.handle_success(result) self.generator.handle_success(result, self.payload_doc(repeat_record), repeat_record) else: attempt = repeat_record.handle_failure(result) self.generator.handle_failure(result, self.payload_doc(repeat_record), repeat_record) return attempt
def handle_success(self, response, payload_doc, repeat_record): # A successful response returns a Nikshay ID like 00001 # Failures also return with status code 200 and some message like # Dublicate Entry or Invalid data format # (Dublicate is not a typo) message = parse_SOAP_response(repeat_record.repeater.url, repeat_record.repeater.operation, response) try: if isinstance(message, basestring) and message.isdigit(): health_facility_id = self._get_person_locations( payload_doc).pcp nikshay_id = '-'.join([health_facility_id, message]) update_case( payload_doc.domain, payload_doc.case_id, { "private_nikshay_registered": "true", "nikshay_id": nikshay_id, "private_nikshay_error": "", }, external_id=nikshay_id, ) else: self.handle_failure(message, payload_doc, repeat_record) except NikshayResponseException as e: _save_error_message(payload_doc.domain, payload_doc.case_id, unicode(e.message))
def handle_response(self, result, repeat_record): if isinstance(result, Exception): attempt = repeat_record.handle_exception(result) self.generator.handle_exception(result, repeat_record) return attempt # A successful response looks like HE_ID: 125344 # Failures also return with status code 200 and some message like # Character are not allowed........ # (........ is a part of the actual message) message = parse_SOAP_response(repeat_record.repeater.url, repeat_record.repeater.operation, result, verify=self.verify) # message does not give the final node message here so need to find the real message # look at SUCCESSFUL_HEALTH_ESTABLISHMENT_RESPONSE for example message_node = message.find("NewDataSet/HE_DETAILS/Message") already_registered_id_node = message.find("NewDataSet/Table1/HE_ID") if already_registered_id_node is not None: attempt = repeat_record.handle_success(result) self.generator.handle_success(result, self.payload_doc(repeat_record), repeat_record) elif message_node is not None and re.search( HEALTH_ESTABLISHMENT_SUCCESS_RESPONSE_REGEX, message_node.text): attempt = repeat_record.handle_success(result) self.generator.handle_success(result, self.payload_doc(repeat_record), repeat_record) else: attempt = repeat_record.handle_failure(result) self.generator.handle_failure(result, self.payload_doc(repeat_record), repeat_record) return attempt
def handle_failure(self, response, payload_doc, repeat_record): message = parse_SOAP_response( repeat_record.repeater.url, repeat_record.repeater.operation, response, ) _save_error_message(payload_doc.domain, payload_doc.case_id, unicode(message), "private_nikshay_registered", "private_nikshay_error" )
def handle_success(self, response, payload_doc, repeat_record): message = parse_SOAP_response( repeat_record.repeater.url, repeat_record.repeater.operation, response, ) message_text = message.find("NewDataSet/HE_DETAILS/Message").text health_facility_id = re.match(HEALTH_ESTABLISHMENT_SUCCESS_RESPONSE_REGEX, message_text).groups()[0] if payload_doc.metadata.get('nikshay_code'): # The repeater checks for this to be absent but in case its added after the trigger # and before its fetched from Nikshay, just keep a copy of the older value for ref payload_doc.metadata['old_nikshay_code'] = payload_doc.metadata.get('nikshay_code') payload_doc.metadata['nikshay_code'] = health_facility_id payload_doc.save()
def handle_success(self, response, payload_doc, repeat_record): message = parse_SOAP_response( repeat_record.repeater.url, repeat_record.repeater.operation, response, ) try: health_facility_id = self._get_person_locations(payload_doc).pcp except NikshayLocationNotFound as e: self.handle_exception(e, repeat_record) else: nikshay_id = '-'.join([health_facility_id, message]) update_case( payload_doc.domain, payload_doc.case_id, { "private_nikshay_registered": "true", "nikshay_id": nikshay_id, "private_nikshay_error": "", }, external_id=nikshay_id, )