Esempio n. 1
0
    def process(self, msg, rmt_sys_code):
        assert isinstance(msg, Message)
        res = True
        implement = Implementation()
        reformer = implement.get_reformer(rmt_sys_code, msg.get_stream_id())

        # сценарий обработки сообщения
        if msg.is_to_remote:
            if msg.is_send_data:
                if remote_system.is_passive(rmt_sys_code):
                    reformed_data = reformer.reform_msg(msg)
                    reformer.send_to_remote_data(reformed_data)
                    hdr = msg.get_header()
                    op_res = OperationResult(msg.get_stream_id())
                    result_msg = op_res.check(hdr.method, hdr.url)
                    if result_msg:
                        self.producer_send_msgs([result_msg])
                elif remote_system.is_active(rmt_sys_code):
                    # todo: не готов вариант взаимодействия с мис
                    miss_req_msgs = reformer.get_missing_requests(msg)
                    miss_data_msgs = self.producer_send_msgs(miss_req_msgs)
                    remote_reformed_data = reformer.get_reformed_data(
                        msg, miss_data_msgs)
                    data_store = Difference()
                    data_store.place(remote_reformed_data)
                    data_store.commit_all_changes()
                else:
                    raise InternalError(
                        'Type of remote system is not define: %s' %
                        rmt_sys_code)
            elif msg.is_send_event:
                reformed_data = reformer.reform_msg(msg)
                res = reformer.send_to_remote_data(reformed_data)
            elif msg.is_result:
                remote_data = msg.get_source_data()
                reformer.conformity_local(remote_data, msg)
            elif msg.is_request:
                reformed_req = reformer.reform_req(msg)
                entity_package = reformer.get_entity_package_by_req(
                    reformed_req)
                self.send_diff_data(entity_package, reformer, reformed_req)
            else:
                raise InternalError('Unexpected message type')
        elif msg.is_to_local:
            raise InternalError('Wrong message direct')
        else:
            raise InternalError('Message direct is not define')
        return res
Esempio n. 2
0
 def get(cls, system_code, entity_code, operation_code, version):
     method = cls.query.join(Entity, Entity.id == cls.entity_id).join(
         System, System.id == Entity.system_id).join(
             Protocol, Protocol.id == cls.protocol_id).join(
                 ApiMethodOperation,
                 ApiMethodOperation.api_method_id == cls.id).join(
                     Operation,
                     Operation.id == ApiMethodOperation.operation_id).join(
                         Host, Host.id == cls.host_id).filter(
                             Entity.code == entity_code,
                             Operation.code == operation_code,
                             System.code == system_code,
                             ApiMethod.version == version,
                         ).first()
     if not method:
         params = {
             'system_code': system_code,
             'entity_code': entity_code,
             'operation_code': operation_code,
             'version': version,
         }
         raise InternalError(
             'Method not registered in %s (%s)' % (cls.__name__, ', '.join(
                 (k + '=%s' % v for k, v in params.items()))))
     params_entities = ApiMethodURLParamEntity.get(method.id)
     sys_url = method.host.url.rstrip('/')
     res = {
         'protocol': method.protocol.code,
         'method': method.method,
         'template_url': sys_url + method.template_url,
         'params_entities': params_entities,
     }
     return res
Esempio n. 3
0
 def get_local_entities(self, header_meta, data):
     remote_entity_code = header_meta['remote_entity_code']
     if remote_entity_code == TambovEntityCode.SMART_PATIENT:
         res = PatientTambovBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TambovEntityCode.REFERRAL:
         res = ReferralTambovBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TambovEntityCode.CLINIC:
         res = ClinicTambovBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TambovEntityCode.EMPLOYEE_POSITION:
         res = EmployeePositionTambovBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TambovEntityCode.HOSPITAL_REC:
         res = HospitalTambovBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TambovEntityCode.BIRTH:
         res = BirthTambovBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TambovEntityCode.TIME:
         res = TimeTambovBuilder(self).build_local_entities(
             header_meta, data)
     else:
         raise InternalError('Unexpected remote_entity_code (%s)' %
                             remote_entity_code)
     return res
Esempio n. 4
0
    def get_filial_code(self, doc_code, workdate):
        sched_reserve_req_data = self.get_doctor_req_data(
            doc_code,
            workdate,
            workdate,
        )

        sched_reserve_req = DataRequest(self.reformer.stream_id)
        sched_reserve_req.set_meta(
            dst_system_code=self.remote_sys_code,
            dst_entity_code=TulaEntityCode.SCHEDULE,
            dst_operation_code=OperationCode.ADD,
            dst_id=None,
            dst_parents_params={},
        )
        sched_reserve_req.set_req_mode(RequestModeCode.XML_DATA)
        self.reformer.set_request_service(sched_reserve_req)
        sched_reserve_req.req_data['body'] = sched_reserve_req_data
        req_result = self.transfer__send_request(sched_reserve_req)
        find_prefix = './/{http://sdsys.ru/}'
        doct_list_frst = req_result.find(find_prefix + 'GETDOCTORLIST')
        if doct_list_frst:
            res = doct_list_frst.findtext(find_prefix + 'FILIAL')
        else:
            raise InternalError(
                'Not found filial for doctor with code = (%s); workdate = (%s)'
                % (doc_code, workdate))
        return res
Esempio n. 5
0
 def get_remote_request(self, header_meta):
     remote_entity_code = header_meta.get('remote_entity_code')
     local_entity_code = header_meta.get('local_entity_code')
     if local_entity_code == RisarEntityCode.CLIENT or remote_entity_code == TambovEntityCode.SMART_PATIENT:
         data_req = PatientTambovBuilder(self).build_remote_request(
             header_meta, TambovEntityCode.SMART_PATIENT)
     elif local_entity_code in (
             RisarEntityCode.MEASURE_RESEARCH,
             RisarEntityCode.MEASURE_SPECIALISTS_CHECKUP,
     ) or remote_entity_code == TambovEntityCode.REND_SERVICE:
         data_req = ServiceTambovBuilder(self).build_remote_request(
             header_meta, TambovEntityCode.REND_SERVICE)
     elif local_entity_code == RisarEntityCode.ORGANIZATION or remote_entity_code == TambovEntityCode.CLINIC:
         data_req = ClinicTambovBuilder(self).build_remote_request(
             header_meta, TambovEntityCode.CLINIC)
     elif local_entity_code == RisarEntityCode.MEASURE_HOSPITALIZATION or remote_entity_code == TambovEntityCode.HOSPITAL_REC:
         data_req = HospitalTambovBuilder(self).build_remote_request(
             header_meta, TambovEntityCode.HOSPITAL_REC)
     elif local_entity_code == RisarEntityCode.DOCTOR or remote_entity_code == TambovEntityCode.EMPLOYEE:
         data_req = EmployeePositionTambovBuilder(
             self).build_remote_request(header_meta,
                                        TambovEntityCode.EMPLOYEE)
     elif local_entity_code == RisarEntityCode.CHILDBIRTH or remote_entity_code == TambovEntityCode.BIRTH:
         data_req = BirthTambovBuilder(self).build_remote_request(
             header_meta, TambovEntityCode.BIRTH)
     elif local_entity_code == RisarEntityCode.SCHEDULE or remote_entity_code == TambovEntityCode.TIME:
         data_req = TimeTambovBuilder(self).build_remote_request(
             header_meta, TambovEntityCode.TIME)
     else:
         raise InternalError('Unexpected local_entity_code (%s)' %
                             local_entity_code)
     self.set_remote_request_params(data_req)
     self.set_request_service(data_req)
     return data_req
Esempio n. 6
0
 def get_remote_entities(self, header_meta, data):
     local_entity_code = header_meta['local_entity_code']
     if local_entity_code == RisarEntityCode.SCHEDULE_TICKET:
         res = ActiveScheduleTicketTulaBuilder(self).build_remote_entities(
             header_meta, data)
     elif local_entity_code == RisarEntityCode.CARD:
         res = CardTulaBuilder(self).build_remote_entities(
             header_meta, data)
     elif local_entity_code == RisarEntityCode.CHECKUP_OBS_FIRST_TICKET:
         res = ActCheckupFirstTicket25TulaBuilder(
             self).build_remote_entities(header_meta, data)
     elif local_entity_code == RisarEntityCode.CHECKUP_OBS_SECOND_TICKET:
         res = ActCheckupSecondTicket25TulaBuilder(
             self).build_remote_entities(header_meta, data)
     elif local_entity_code == RisarEntityCode.CHECKUP_PC_TICKET:
         res = ActCheckupPCTicket25TulaBuilder(self).build_remote_entities(
             header_meta, data)
     elif local_entity_code == RisarEntityCode.CHECKUP_OBS_FIRST:
         res = CheckupFirstTulaBuilder(self).build_remote_entities(
             header_meta, data)
     elif local_entity_code == RisarEntityCode.CHECKUP_OBS_SECOND:
         res = CheckupSecondTulaBuilder(self).build_remote_entities(
             header_meta, data)
     elif local_entity_code == RisarEntityCode.CHECKUP_PC:
         res = CheckupPCTulaBuilder(self).build_remote_entities(
             header_meta, data)
     elif local_entity_code == RisarEntityCode.MEASURE:
         res = MeasureTulaBuilder(self).build_remote_entities(
             header_meta, data)
     elif local_entity_code == RisarEntityCode.EPICRISIS:
         res = EpicrisisTulaBuilder(self).build_remote_entities(
             header_meta, data)
     else:
         raise InternalError('Unexpected local_entity_code')
     return res
Esempio n. 7
0
    def get_entity_package_by_req(self, req):
        """
        Сбор сущностей в пакеты дозапросами. Сюда приходим из планировщика.

        Args:
            req: данные для запроса корневой сущности

        Returns: мета данные и пакеты сущностей
        """
        # todo: рассмотреть возможность использования MatchingEntity для автосборки пакетов
        meta = req.meta
        dst_entity = meta['dst_entity_code']
        if dst_entity == TambovEntityCode.SMART_PATIENT:
            res = PatientTambovBuilder(self).build_remote_entity_packages(req)
        elif dst_entity == TambovEntityCode.REND_SERVICE:
            res = ServiceTambovBuilder(self).build_remote_entity_packages(req)
        elif dst_entity == TambovEntityCode.CLINIC:
            res = ClinicTambovBuilder(self).build_remote_entity_packages(req)
        elif dst_entity == TambovEntityCode.HOSPITAL_REC:
            res = HospitalTambovBuilder(self).build_remote_entity_packages(req)
        elif dst_entity == TambovEntityCode.EMPLOYEE:
            res = EmployeePositionTambovBuilder(
                self).build_remote_entity_packages(req)
        elif dst_entity == TambovEntityCode.BIRTH:
            res = BirthTambovBuilder(self).build_remote_entity_packages(req)
        elif dst_entity == TambovEntityCode.TIME:
            res = TimeTambovBuilder(self).build_remote_entity_packages(req)
        else:
            raise InternalError('Unexpected dst_entity (%s)' % dst_entity)
        return res
Esempio n. 8
0
 def diag_code(cls, diag_id):
     cls.init()
     res = cls.id__code__map.get(diag_id)
     if not res:
         raise InternalError(
             'For diag_id (%s) not found match diag_code in "%s" file' %
             (diag_id, cls.fname))
     return res
Esempio n. 9
0
 def get_measure_type(cls, prototype_id):
     cls.init()
     res = cls.srv_prototype__measure__map.get(prototype_id, (0, None))[1]
     if not res:
         raise InternalError(
             'For prototype_id (%s) not found match measure_type in "%s" file' %
             (prototype_id, cls.fname)
         )
     return res
Esempio n. 10
0
 def get_prototype_id_by_prototype_code(cls, prototype_code):
     cls.init()
     res = cls.prototype_code__srv_prototype__map.get(prototype_code)
     if not res:
         raise InternalError(
             'For prototype_code (%s) not found match prototype_id in "%s" file' %
             (prototype_code, cls.fname)
         )
     return res
Esempio n. 11
0
 def get_prototype_id_by_mes_code(cls, measure_code, error_ignore=False):
     cls.init()
     res = cls.measure_code__srv_prototype__map.get(measure_code)
     if not res and not error_ignore:
         raise InternalError(
             'For measure_code (%s) not found match prototype_id in "%s" file' %
             (measure_code, cls.fname)
         )
     return res
Esempio n. 12
0
 def get_measure_code(cls, prototype_id, error_ignore=False):
     cls.init()
     res = cls.srv_prototype__measure_code__map.get(prototype_id, (None,))[0]
     if not res and not error_ignore:
         raise InternalError(
             'For prototype_id (%s) not found match measure_code in "%s" file' %
             (prototype_id, cls.fname)
         )
     return res
Esempio n. 13
0
 def get_reformer(self, rmt_sys_code, stream_id):
     try:
         reformer_cls, transfer_cls = imp_map[rmt_sys_code]
     except KeyError:
         raise InternalError(
             'Unknown remote system code "%s" in implements' % rmt_sys_code)
     reformer = reformer_cls(stream_id)
     reformer.set_transfer(transfer_cls())
     return reformer
Esempio n. 14
0
 def get_id(cls, system_code, entity_code):
     entity_id = cls.query.join(System, System.id == cls.system_id).filter(
         cls.code == entity_code,
         System.code == system_code,
     ).value(cls.id)
     if not entity_id:
         raise InternalError('Entity not exist (%s, %s)' %
                             (system_code, entity_code))
     return entity_id
Esempio n. 15
0
 def get_entity(cls, method_code):
     method = cls.query.join(Entity, Entity.id == cls.entity_id).join(
         System, System.id == Entity.system_id).filter(
             cls.method_code == method_code, ).first()
     if not method:
         raise InternalError('Service method (%s) not registered in %s' %
                             (method_code, cls.__name__))
     res = {
         'entity_code': method.entity.code,
         'system_code': method.entity.system.code,
     }
     return res
Esempio n. 16
0
 def get_remote_request(self, header_meta):
     remote_entity_code = header_meta.get('remote_entity_code')
     local_entity_code = header_meta.get('local_entity_code')
     # if local_entity_code == RisarEntityCode.SCHEDULE or remote_entity_code == TulaEntityCode.SCHEDULE:
     #     data_req = ScheduleTulaBuilder(self).build_remote_request(header_meta, TulaEntityCode.SCHEDULE)
     # else:
     #     raise InternalError('Unexpected local_entity_code (%s)' % local_entity_code)
     raise InternalError('Unexpected local_entity_code (%s)' %
                         local_entity_code)
     self.set_remote_request_params(data_req)
     self.set_request_service(data_req)
     return data_req
Esempio n. 17
0
 def build_remote_entity_packages(self, reformed_req):
     package = EntitiesPackage(self, self.remote_sys_code)
     req_meta = reformed_req.meta
     if req_meta['dst_operation_code'] == OperationCode.READ_MANY:
         package.enable_diff_check()
         clinic_id = req_meta['dst_parents_params']['clinic']['id']
         clinic_sched = []
         today = date.today()
         # today = date(2016, 12, 29)  # todo для тестов
         # range_val = 14
         range_val = 7  # todo для тестов
         max_date = today + timedelta(range_val)
         package.set_diff_key_range(('_'.join(
             (str(clinic_id), today.isoformat())), '_'.join(
                 (str(clinic_id), max_date.isoformat()))))
         locations_set = set()
         # for prototype_id in (5201,):  # todo для тестов Прием врача-акушера-гинеколога
         for prototype_id in (5202, 5203):  # первичный и повторный осмотр
             services = self.get_services(clinic_id, prototype_id)
             for service_data in services:
                 locations = self.get_locations(clinic_id,
                                                service_data['id'])
                 locations_set.update(locations)
         for location_id in locations_set:
             # if location_id not in ('14813',):  # todo для тестов
             #     continue
             employee_position_id = self.get_employee_position(location_id)
             if employee_position_id:
                 for inc in range(range_val):
                     sched_date = today + timedelta(inc)
                     sched_date_iso = sched_date.isoformat()
                     times = self.get_times(reformed_req, sched_date,
                                            location_id)
                     for time_data in times['timePeriod']:
                         self.set_times(clinic_sched, time_data,
                                        sched_date_iso,
                                        employee_position_id)
                     slots = self.get_reserved(sched_date, location_id)
                     for slot_data in slots:
                         if slot_data['status'] == '4':
                             # отмененная запись
                             continue
                         self.set_reserved(clinic_sched, slot_data,
                                           sched_date_iso,
                                           employee_position_id)
         self.set_package_data(package, reformed_req, req_meta,
                               clinic_sched, clinic_id)
     # elif req_meta['dst_operation_code'] == OperationCode.READ_ONE:
     #     self.set_times([req_meta['dst_id']], package, req_meta)
     else:
         raise InternalError('Unexpected dst_operation_code')
     return package
Esempio n. 18
0
 def after_send_func(entity_meta, entity_body, answer_body):
     if src_operation_code != OperationCode.DELETE:
         res = self.reformer.update_local_match_parent(
             RisarEntityCode.SCHEDULE_TICKET,
             TulaEntityCode.SCHEDULE_TICKET,
             schedule_ticket_data['schedule_ticket_id'],
             matching_parent_id,
         )
         if not res:
             raise InternalError(
                 u'Не удалось привязать тикет (%s) к родителю (%s)' %
                 (schedule_ticket_data['schedule_ticket_id'],
                  matching_parent_id))
Esempio n. 19
0
    def send(self, msg):
        assert isinstance(msg, Message)

        res = True
        if msg.is_to_local:
            # доп. очередь, т.к. основная может быть забита входящим потоком
            local_back_task.apply_async(args=(msg, ), queue=back_queue_name)
        elif msg.is_to_remote:
            if msg.is_send_data:
                implement = Implementation()
                for rmt_sys_code in remote_system.get_codes():
                    for queue_name in remote_system.get_queue_names(
                            rmt_sys_code):
                        reformer = implement.get_reformer(
                            rmt_sys_code, msg.get_stream_id())
                        entity_package = reformer.get_entity_package_by_msg(
                            msg)
                        self.send_diff_data(entity_package, reformer, msg,
                                            rmt_sys_code, queue_name)
            elif msg.is_send_event:
                implement = Implementation()
                rmt_sys_code = remote_system.get_event_system_code()
                reformer = implement.get_reformer(rmt_sys_code,
                                                  msg.get_stream_id())
                entity_package = reformer.get_entity_package_by_msg(msg)
                msgs = reformer.create_to_remote_messages(entity_package)
                res = all(self.send_msgs(msgs, rmt_sys_code, async=False))
            elif msg.is_request:
                rmt_sys_code = msg.get_header().meta['remote_system_code']
                sync_remote_task(msg, rmt_sys_code)
            elif msg.is_result:
                rmt_sys_code = msg.get_header().meta['remote_system_code']
                sync_remote_task(msg, rmt_sys_code)
            else:
                raise InternalError('Unexpected message type')
        else:
            raise InternalError('Message direct missing')
        return res
Esempio n. 20
0
 def build_remote_entity_packages(self, reformed_req):
     package = EntitiesPackage(self, self.remote_sys_code)
     req_meta = reformed_req.meta
     if req_meta['dst_operation_code'] == OperationCode.READ_MANY:
         package.enable_diff_check()
         package.set_diff_key_range(('', ''))
         req = reformed_req.copy()
         clinics_ids = self.transfer__send_request(req)
         self.set_clinics(clinics_ids, package, req_meta)
     elif req_meta['dst_operation_code'] == OperationCode.READ_ONE:
         self.set_clinics([req_meta['dst_id']], package, req_meta)
     else:
         raise InternalError('Unexpected dst_operation_code')
     return package
Esempio n. 21
0
 def build_remote_entity_packages(self, reformed_req):
     package = EntitiesPackage(self, self.remote_sys_code)
     req_meta = reformed_req.meta
     if req_meta['dst_operation_code'] == OperationCode.READ_MANY:
         employees_ids = self.get_employees_ids(reformed_req)
         package.enable_diff_check()
         diff_key = req_meta['dst_parents_params']['organization']['id']
         package.set_diff_key_range((diff_key, diff_key))
         self.set_employees_positions(employees_ids, package, req_meta,
                                      diff_key)
     elif req_meta['dst_operation_code'] == OperationCode.READ_ONE:
         self.set_employees_positions([req_meta['dst_id']], package,
                                      req_meta)
     else:
         raise InternalError('Unexpected dst_operation_code')
     return package
Esempio n. 22
0
 def get_local_entities(self, header_meta, data):
     remote_entity_code = header_meta['remote_entity_code']
     if remote_entity_code == TulaEntityCode.CLIENT:
         res = ClientTulaBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TulaEntityCode.ORGANIZATION:
         res = OrganizationTulaBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TulaEntityCode.ORG_DEPARTMENT:
         res = OrgDepartmentTulaBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TulaEntityCode.DOCTOR:
         res = DoctorTulaBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TulaEntityCode.REFBOOK:
         res = RefbookTulaBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TulaEntityCode.MEASURE_SPECIALISTS_CHECKUP:
         res = SpecialistsCheckupTulaBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TulaEntityCode.MEASURE_HOSPITALIZATION:
         res = HospitalizationTulaBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TulaEntityCode.MEASURE_RESEARCH:
         res = ResearchTulaBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TulaEntityCode.CHILDBIRTH:
         res = ChildbirthTulaBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TulaEntityCode.CHECKUP_OBS_FIRST_TICKET:
         res = PassCheckupFirstTicket25TulaBuilder(
             self).build_local_entities(header_meta, data)
     elif remote_entity_code == TulaEntityCode.CHECKUP_OBS_SECOND_TICKET:
         res = PassCheckupSecondTicket25TulaBuilder(
             self).build_local_entities(header_meta, data)
     elif remote_entity_code == TulaEntityCode.CHECKUP_PC_TICKET:
         res = PassCheckupPCTicket25TulaBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TulaEntityCode.SCHEDULE:
         res = ScheduleTulaBuilder(self).build_local_entities(
             header_meta, data)
     elif remote_entity_code == TulaEntityCode.SCHEDULE_TICKET:
         res = PassiveScheduleTicketTulaBuilder(self).build_local_entities(
             header_meta, data)
     else:
         raise InternalError('Unexpected remote_entity_code')
     return res
Esempio n. 23
0
 def execute(self, req):
     if isinstance(req, DataRequest):
         req_meta = req.meta  # .protocol
     else:
         assert isinstance(req, ReqEntity)
         req_meta = req['meta']
     if req_meta.get('dst_protocol_code',
                     ProtocolCode.SOAP) == ProtocolCode.SOAP:
         req_result = self.soap_protocol(req, req_meta)
     elif req_meta['dst_protocol_code'] == ProtocolCode.REST:
         req_result = self.rest_protocol(req, req_meta)
     else:
         raise InternalError('Unexpected protocol (%s)' %
                             req_meta['dst_protocol_code'])
     res = self.answer.process(req_result, req_meta, req.data,
                               req.get_stream_id())
     return res
Esempio n. 24
0
 def get_remote_entities(self, header_meta, data):
     local_entity_code = header_meta['local_entity_code']
     if local_entity_code == RisarEntityCode.CHECKUP_OBS_FIRST_TICKET:
         res = CaseTambovBuilder(self).build_remote_entities_first(
             header_meta, data)
     elif local_entity_code == RisarEntityCode.CHECKUP_OBS_SECOND_TICKET:
         res = CaseTambovBuilder(self).build_remote_entities_second(
             header_meta, data)
     elif local_entity_code == RisarEntityCode.MEASURE:
         res = ReferralTambovBuilder(self).build_remote_entities(
             header_meta, data)
     elif local_entity_code == RisarEntityCode.EXCHANGE_CARD:
         res = ServiceTambovBuilder(self).build_remote_entities_exch_card(
             header_meta, data)
     else:
         raise InternalError('Unexpected local_entity_code (%s)' %
                             local_entity_code)
     return res
Esempio n. 25
0
    def get_entity_package_by_req(self, req):
        """
        Сбор сущностей в пакеты дозапросами. Сюда приходим из планировщика.

        Args:
            req: данные для запроса корневой сущности

        Returns: мета данные и пакеты сущностей
        """
        # todo: рассмотреть возможность использования MatchingEntity для автосборки пакетов
        meta = req.meta
        dst_entity = meta['dst_entity_code']
        # if dst_entity == TulaEntityCode.SCHEDULE:
        #     res = ScheduleTulaBuilder(self).build_remote_entity_packages(req)
        # else:
        #     raise InternalError('Unexpected dst_entity (%s)' % dst_entity)
        raise InternalError('Unexpected dst_entity (%s)' % dst_entity)
        return res
Esempio n. 26
0
class RemoteProducer(object):
    main_queues = app.config['main_queues']
    main_queue_name = main_queues['risar_main']

    def send(self, msg, async=True):
        assert isinstance(msg, Message)
        # todo: на время тестирования без обработки исключений
        if os.environ.get('TESTING') == '1' and not app.config['SERVER']:
            async = False
        res = None
        if msg.is_to_local:
            args = (msg, )
            if async:
                local_task.apply_async(args=args, queue=self.main_queue_name)
            else:
                res = sync_local_task(*args)
        else:
            raise InternalError('Unexpected message direct')
        return res
Esempio n. 27
0
    def execute(self, req_data):
        from sirius.blueprints.api.local_service.producer import LocalProducer

        entity_code = req_data.entity.code
        system_code = req_data.system.code
        stream_id = get_stream_id()
        sampling_method_name = req_data.sampling_method
        logger.info('stream_id: %s Scheduler execute %s %s %s' % (stream_id, system_code, entity_code, sampling_method_name))
        if sampling_method_name:
            sampling_method_func = getattr(self, sampling_method_name, None)
            if callable(sampling_method_func):
                sampling_method_func(system_code, entity_code, stream_id)
            else:
                raise InternalError(
                    'Sampling method (%s) not found' %
                    sampling_method_name
                )
        else:
            msg = self.create_message(system_code, entity_code)
            producer = LocalProducer()
            producer.send(msg)
Esempio n. 28
0
    def get_entity_package_by_msg(self, msg):
        assert isinstance(msg, Message)

        meta = msg.get_header().meta
        src_entity = meta['local_entity_code']
        if not src_entity:
            serv_method = ServiceMethod.get_entity(meta['local_service_code'])
            src_system_code = serv_method['system_code']
            src_entity = serv_method['entity_code']
            meta['local_entity_code'] = src_entity
        if src_entity == RisarEntityCode.SCHEDULE_TICKET:
            res = ActiveScheduleTicketTulaBuilder(
                self).build_local_entity_packages(msg)
        elif src_entity == RisarEntityCode.CARD:
            res = CardTulaBuilder(self).build_local_entity_packages(msg)
        elif src_entity == RisarEntityCode.CHECKUP_OBS_FIRST_TICKET:
            res = ActCheckupFirstTicket25TulaBuilder(
                self).build_local_entity_packages(msg)
        elif src_entity == RisarEntityCode.CHECKUP_OBS_SECOND_TICKET:
            res = ActCheckupSecondTicket25TulaBuilder(
                self).build_local_entity_packages(msg)
        elif src_entity == RisarEntityCode.CHECKUP_PC_TICKET:
            res = ActCheckupPCTicket25TulaBuilder(
                self).build_local_entity_packages(msg)
        elif src_entity == RisarEntityCode.CHECKUP_OBS_FIRST:
            res = CheckupFirstTulaBuilder(self).build_local_entity_packages(
                msg)
        elif src_entity == RisarEntityCode.CHECKUP_OBS_SECOND:
            res = CheckupSecondTulaBuilder(self).build_local_entity_packages(
                msg)
        elif src_entity == RisarEntityCode.CHECKUP_PC:
            res = CheckupPCTulaBuilder(self).build_local_entity_packages(msg)
        elif src_entity == RisarEntityCode.MEASURE:
            res = MeasureTulaBuilder(self).build_local_entity_packages(msg)
        elif src_entity == RisarEntityCode.EPICRISIS:
            res = EpicrisisTulaBuilder(self).build_local_entity_packages(msg)
        else:
            raise InternalError('Unexpected entity code')
        return res
Esempio n. 29
0
    def get_entity_package_by_msg(self, msg):
        assert isinstance(msg, Message)

        meta = msg.get_header().meta
        src_entity = meta['local_entity_code']
        if not src_entity:
            serv_method = ServiceMethod.get_entity(meta['local_service_code'])
            src_system_code = serv_method['system_code']
            src_entity = serv_method['entity_code']
            meta['local_entity_code'] = src_entity
        if src_entity in (
                RisarEntityCode.CHECKUP_OBS_FIRST_TICKET,
                RisarEntityCode.CHECKUP_OBS_SECOND_TICKET,
        ):
            res = CaseTambovBuilder(self).build_local_entity_packages(msg)
        elif src_entity == RisarEntityCode.MEASURE:
            res = ReferralTambovBuilder(self).build_local_entity_packages(msg)
        elif src_entity == RisarEntityCode.EXCHANGE_CARD:
            res = ServiceTambovBuilder(
                self).build_local_entity_packages_exch_card(msg)
        else:
            raise InternalError('Unexpected src_entity (%s)' % src_entity)
        return res
Esempio n. 30
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