Exemple #1
0
def api_request_local():
    data = request.get_json()
    rld = RequestLocalData(data)
    msg = Message(None, rld.stream_id)
    msg.to_local_service()
    msg.set_request_type()
    msg.set_method(rld.request_method, rld.request_url)
    msg.get_header().meta.update(rld.get_msg_meta())
    prod = LocalProducer()
    res = prod.send(msg)
    return res, rld.stream_id
Exemple #2
0
    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)
Exemple #3
0
 def check(self, method, url):
     msg = None
     op_res = self.get_operation_result()
     if op_res is not None:
         data = {'result': op_res}
         msg = Message(data, self.stream_id)
         msg.to_local_service()
         msg.set_result_type()
         msg.set_method('put', url + 'result/')
     return msg
Exemple #4
0
def api_send_event_remote():
    data = request.get_json()
    rld = RequestLocalData(data)
    msg = Message(rld.body, rld.stream_id)
    msg.to_remote_service()
    msg.set_send_event_type()
    msg.get_header().meta.update(rld.get_msg_meta())
    prod = LocalProducer()
    res = prod.send(msg)
    return res, rld.stream_id
Exemple #5
0
 def create_message(self, system_code, entity_code, operation_code=OperationCode.READ_MANY):
     # создает сообщение с параметрами, по которым сообщение реформируется
     # в данные для правильного запроса сущностей из Удаленной системы
     sub_stream_id = get_stream_id()
     msg = Message(None, sub_stream_id)
     msg.to_remote_service()
     msg.set_request_type()
     meta = msg.get_header().meta
     meta['local_entity_code'] = entity_code
     meta['local_operation_code'] = operation_code
     meta['remote_system_code'] = system_code
     return msg
Exemple #6
0
 def request_patient(self, patient_uid):
     from sirius.blueprints.api.local_service.producer import LocalProducer
     msg = Message(None, self.reformer.stream_id)
     msg.to_remote_service()
     msg.set_request_type()
     meta = msg.get_header().meta
     meta['local_operation_code'] = OperationCode.READ_ONE
     meta['remote_system_code'] = self.remote_sys_code
     meta['remote_entity_code'] = TambovEntityCode.SMART_PATIENT
     meta['remote_main_id'] = patient_uid
     prod = LocalProducer()
     try:
         res = prod.send(msg)
     except LoggedException:
         res = False
     return res
Exemple #7
0
def api_request_remote():
    # запрос данных из удаленной системы по ID удаленной системы
    # если коды внешней системы и шины разъедутся, придется вынести RisarEntityCode
    data = request.get_json()
    rld = RequestLocalData(data)
    msg = Message(None, rld.stream_id)
    msg.to_remote_service()
    msg.set_request_type()
    meta = msg.get_header().meta
    meta['local_operation_code'] = OperationCode.READ_ONE
    meta['remote_system_code'] = rld.data.get('remote_system_code')
    meta['remote_entity_code'] = rld.data.get('remote_entity_code')
    meta['remote_main_id'] = rld.data.get('remote_main_id')
    prod = LocalProducer()
    res = prod.send(msg)
    return res, rld.stream_id
Exemple #8
0
    def process(self, msg):
        assert isinstance(msg, Message)
        res = None
        hdr = msg.get_header()
        # сценарий обработки сообщения
        if msg.is_request:
            parser, answer = request_by_url(
                hdr.method, hdr.url, msg.get_data(), msg.get_stream_id()
            )
            local_data = parser.get_data(answer)

            next_msg = Message(local_data, msg.get_stream_id())
            next_msg.to_remote_service()
            next_msg.set_send_data_type()
            next_msg.get_header().meta.update(hdr.meta)

            if msg.is_immediate_answer:
                res = next_msg
            else:
                prod = LocalProducer()
                prod.send(next_msg)
        elif msg.is_result:
            parser, answer = request_by_url(
                hdr.method, hdr.url, msg.get_data(), msg.get_stream_id()
            )
            req_res = parser.get_data(answer)
        elif msg.is_send_data:
            implement = Implementation()
            rmt_sys_code = msg.get_header().meta['remote_system_code']
            reformer = implement.get_reformer(rmt_sys_code, msg.get_stream_id())
            entities = reformer.reform_msg(msg)
            reformer.send_to_local_data(entities, request_by_url)
        else:
            raise InternalError('Message has not type')

        return res
Exemple #9
0
    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)
Exemple #10
0
    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
Exemple #11
0
    def get_hospital_rec(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 = {
        #     'filters': {
        #         'id': 3  # todo: при тестировании работаем пока с одной картой
        #     }
        # }
        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():
            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)  # searchHspRecord
                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
Exemple #12
0
    def send_exchange_card(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
        )
        # todo: фильтр для двойняшек
        data = {
            'filters': {
                'pregnancyWeek': 32,  # в рисар нет таких пока
                # 'id': 22,
            }
        }
        # data = {
        #     'filters': {
        #         'id': 14  # todo: при тестировании работаем пока с одной картой
        #     }
        # }
        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)

        fname = 'exchange_card_template.xml'
        rel_path = 'sirius/blueprints/api/remote_service/tambov/active/service/'
        with open(os.path.join(rel_path, fname)) as pr:
            template_text = pr.read()
        exch_card_req = {
            'doc': {
                'context_type': 'risar_exchange_card',
                'template_text': template_text,
                'template_name': 'exchange_card',
                'id': 0,
                'context': '',
                'event_id': 345
            }
        }
        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

                sub_stream_id = get_stream_id()
                exch_card_req['doc']['event_id'] = card_data['card_id']
                # POST /print_subsystem/fill_template
                exch_card_method = reformer.get_api_method(
                    SystemCode.LOCAL, RisarEntityCode.EXCHANGE_CARD,
                    OperationCode.ADD
                )
                msg = Message(exch_card_req, sub_stream_id)
                msg.to_local_service()
                msg.set_request_type()
                msg.set_immediate_answer()
                msg.set_method(exch_card_method['method'], exch_card_method['template_url'])
                exch_card_msg = producer.send(msg, async=False)

                exch_card_data = {
                    'card_LPU': card_data['card_LPU'],
                    'exch_card': exch_card_msg.get_data(),
                }
                msg = Message(exch_card_data, sub_stream_id)
                msg.to_remote_service()
                msg.set_send_data_type()
                meta = msg.get_header().meta
                meta['local_entity_code'] = entity_code
                meta['local_operation_code'] = OperationCode.ADD
                meta['local_main_param_name'] = 'card_id'
                meta['local_main_id'] = card_data['card_id']
                meta['remote_system_code'] = system_code

                meta['local_parents_params'] = {
                    'card_id': {'entity': RisarEntityCode.CARD, 'id': card_data['card_id']},
                    'regionalCode': {'entity': RisarEntityCode.ORGANIZATION, 'id': card_data['card_LPU']},
                }
                LocalProducer().send(msg)
            except LoggedException:
                pass
Exemple #13
0
    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