def send_messages(self, entity_id, param_name, data, service_name, method_code, parents_params=None): msg = Message(data, self.stream_id) msg.to_local_service() msg.set_send_data_type() msg.get_header().meta.update({ 'remote_system_code': self.remote_system_code, 'remote_entity_code': self.entity_code, 'remote_service_code': service_name, 'remote_main_id': entity_id, 'remote_main_param_name': param_name, 'remote_method': method_code, 'remote_parents_params': parents_params, }) # todo: цикл вложенных дозапросов и связывание ответов # todo: строить пакет. рассмотреть объединение сценариев этот и remote.consumer в remote.producer # from sirius.lib.implement import Implementation # implement = Implementation() # reformer = implement.get_reformer(self.remote_system_code, # self.stream_id) # miss_reqs = reformer.get_missing_requests(msg) # miss_data = reformer.transfer_give_data(miss_reqs) # msg.add_missing_data(miss_data) # data_store = Difference() from sirius.blueprints.api.remote_service.producer import \ RemoteProducer producer = RemoteProducer() producer.send(msg)
def get_times(self, system_code, entity_code, stream_id): from sirius.blueprints.api.local_service.producer import LocalProducer from sirius.blueprints.api.remote_service.producer import RemoteProducer from sirius.blueprints.api.local_service.risar.entities import \ RisarEntityCode implement = Implementation() reformer = implement.get_reformer(system_code, stream_id) org_list_method = reformer.get_api_method( SystemCode.LOCAL, RisarEntityCode.ORGANIZATION, OperationCode.READ_MANY ) msg = Message(None, stream_id) msg.to_local_service() msg.set_request_type() msg.set_immediate_answer() msg.set_method(org_list_method['method'], org_list_method['template_url']) producer = RemoteProducer() org_msg = producer.send(msg, async=False) for org_data in org_msg.get_data(): try: if not org_data['regionalCode']: continue if not org_data['regionalCode'] in ('1434663', '89',): # todo: для тестов continue msg = self.create_message(system_code, entity_code) # getTimes meta = msg.get_header().meta meta['local_parents_params'] = { 'regionalCode': {'entity': RisarEntityCode.ORGANIZATION, 'id': org_data['regionalCode']}, } producer = LocalProducer() producer.send(msg) except LoggedException: pass
def get_measures_results_planned(self, system_code, entity_code, stream_id): from sirius.blueprints.api.local_service.producer import LocalProducer from sirius.blueprints.api.remote_service.producer import RemoteProducer from sirius.blueprints.api.local_service.risar.entities import \ RisarEntityCode implement = Implementation() reformer = implement.get_reformer(system_code, stream_id) # /api/integration/<int:api_version>/card/list/ card_list_method = reformer.get_api_method( SystemCode.LOCAL, RisarEntityCode.CARD, OperationCode.READ_MANY ) msg = Message(None, stream_id) msg.to_local_service() msg.set_request_type() msg.set_immediate_answer() msg.set_method(card_list_method['method'], card_list_method['template_url']) producer = RemoteProducer() card_msg = producer.send(msg, async=False) for card_data in card_msg.get_data(): # /api/integration/<int:api_version>/card/<card_id>/measures/list/ measures_list_method = reformer.get_api_method( SystemCode.LOCAL, RisarEntityCode.MEASURE, OperationCode.READ_MANY ) dst_url_params = {} dst_url_params.update({ 'card_id': { 'entity': RisarEntityCode.CARD, 'id': str(card_data['card_id']), } }) dst_url_entities = dict((val['entity'], val['id']) for val in dst_url_params.values()) dst_param_ids = [dst_url_entities[param_entity] for param_entity in measures_list_method['params_entities']] dst_url = measures_list_method['template_url'].format(*dst_param_ids) msg = Message(None, stream_id) msg.to_local_service() msg.set_request_type() msg.set_immediate_answer() msg.set_method( measures_list_method['method'], dst_url, ) producer = RemoteProducer() measures_msg = producer.send(msg, async=False) for measure_data in measures_msg.get_data(): msg = self.create_message(system_code, entity_code) # searchServiceRend meta = msg.get_header().meta meta['local_parents_params'] = { 'card_id': {'entity': RisarEntityCode.CARD, 'id': card_data['card_id']}, 'measure_id': {'entity': RisarEntityCode.MEASURE, 'id': measure_data['measure_id']}, } producer = LocalProducer() producer.send(msg)
def get_measures_results(self, system_code, entity_code, stream_id): from sirius.blueprints.api.local_service.producer import LocalProducer from sirius.blueprints.api.remote_service.producer import RemoteProducer from sirius.blueprints.api.local_service.risar.entities import \ RisarEntityCode from sirius.blueprints.api.remote_service.tambov.entities import \ TambovEntityCode implement = Implementation() reformer = implement.get_reformer(system_code, stream_id) # /api/integration/<int:api_version>/card/list/ card_list_method = reformer.get_api_method( SystemCode.LOCAL, RisarEntityCode.CARD, OperationCode.READ_MANY ) data = None # data = { # 'filters': { # 'id': 14 # todo: при тестировании работаем пока с одной картой # } # } implement = Implementation() reformer = implement.get_reformer(system_code, stream_id) msg = Message(data, stream_id) msg.to_local_service() msg.set_request_type() msg.set_immediate_answer() msg.set_method(card_list_method['method'], card_list_method['template_url']) producer = RemoteProducer() card_msg = producer.send(msg, async=False) for card_data in card_msg.get_data(): try: if not reformer.find_remote_id_by_local( TambovEntityCode.SMART_PATIENT, RisarEntityCode.CARD, card_data['card_id'], ): continue msg = self.create_message(system_code, entity_code) # searchServiceRend meta = msg.get_header().meta meta['local_parents_params'] = { 'card_id': {'entity': RisarEntityCode.CARD, 'id': card_data['card_id']}, } producer = LocalProducer() producer.send(msg) except LoggedException: pass
def get_tula_schedules_notused(self, system_code, entity_code, stream_id): from sirius.blueprints.api.local_service.producer import LocalProducer from sirius.blueprints.api.remote_service.producer import RemoteProducer from sirius.blueprints.api.local_service.risar.entities import \ RisarEntityCode implement = Implementation() reformer = implement.get_reformer(system_code, stream_id) org_list_method = reformer.get_api_method( SystemCode.LOCAL, RisarEntityCode.ORGANIZATION, OperationCode.READ_MANY ) msg = Message(None, stream_id) msg.to_local_service() msg.set_request_type() msg.set_immediate_answer() msg.set_method(org_list_method['method'], org_list_method['template_url']) producer = RemoteProducer() org_msg = producer.send(msg, async=False) for org_data in org_msg.get_data(): doctor_list_method = reformer.get_api_method( SystemCode.LOCAL, RisarEntityCode.DOCTOR, OperationCode.READ_MANY ) dst_url_params = {} dst_url_params.update({ 'organization': { 'entity': RisarEntityCode.ORGANIZATION, 'id': str(org_data['LPU_id']), } }) dst_url_entities = dict( (val['entity'], val['id']) for val in dst_url_params.values()) dst_param_ids = [dst_url_entities[param_entity] for param_entity in doctor_list_method['params_entities']] dst_url = doctor_list_method['template_url'].format(*dst_param_ids) msg = Message(None, stream_id) msg.to_local_service() msg.set_request_type() msg.set_immediate_answer() msg.set_method( doctor_list_method['method'], dst_url, ) producer = RemoteProducer() doctor_msg = producer.send(msg, async=False) for doctor_data in doctor_msg.get_data(): if not doctor_data['regional_code']: # мусор continue try: msg = self.create_message( system_code, entity_code, OperationCode.ADD ) # WebSchedule meta = msg.get_header().meta meta['local_parents_params'] = { 'LPU_id': {'entity': RisarEntityCode.ORGANIZATION, 'id': org_data['LPU_id']}, 'regional_code': {'entity': RisarEntityCode.DOCTOR, 'id': doctor_data['regional_code']}, } producer = LocalProducer() producer.send(msg) except LoggedException: pass