Example #1
0
    def can_delete_event(event, out_msg=None):
        if out_msg is None:
            out_msg = {'message': u'ok'}

        if not event:
            out_msg['message'] = u'Обращение еще не создано'
            return False
        if current_user.has_right('adm', 'evtDelAll'):
            return True
        elif current_user.has_right('evtDelOwn') and not event.is_closed:
            if current_user.id_any_in(event.execPerson_id,
                                      event.createPerson_id):
                if event.payments:
                    out_msg['message'] = u'В обращении есть платежи по услугам'
                    return False
                for action in event.actions:
                    # Проверка, что все действия не были изменены после создания обращения
                    # или, что не появилось новых действий
                    if action.modifyPerson_id != event.createPerson_id:
                        out_msg['message'] = u'В обращении были созданы новые или отредактированы первоначальные ' \
                                             u'документы'
                        return False
                    # не закрыто
                    if action.status == ActionStatus.finished[0]:
                        out_msg[
                            'message'] = u'В обращении есть закрытые документы'
                        return False
                    # не отмечено "Считать"
                    if action.account == 1:
                        out_msg[
                            'message'] = u'В обращении есть услуги, отмеченные для оплаты'
                        return False
                return True
        out_msg['message'] = u'У пользователя нет прав на удаление обращения'
        return False
Example #2
0
 def can_create_action(event_id, at_id, class_=None):
     from nemesis.models.event import Event
     from nemesis.models.actions import ActionType
     event = Event.query.get_or_404(event_id)
     class_ = class_ if class_ is not None else ActionType.query.get_or_404(
         at_id).class_
     createRight = u'client%sCreate' % modeRights[class_]
     return (current_user.has_right('adm') or
             (not event.is_closed and current_user.has_right(createRight)))
Example #3
0
 def can_edit_event(event):
     return event and (current_user.has_right('adm') or (
         (event.is_closed and current_user.id_any_in(
             event.createPerson_id, event.execPerson_id)
          and current_user.has_right('evtEditClosed')) or
         (not event.is_closed
          and current_user.has_right('clientEventUpdate'))
         and not event.is_stationary)  # TODO: or check exec_person.id?
                       )
Example #4
0
 def can_delete_action(action):
     return action and (
         # админу можно всё
         current_user.has_right('adm') or (
             # остальным - только если обращение не закрыто
             not action.event.is_closed and (
                 # либо есть право на удаление любых действий
                 current_user.has_right('actDelAll') or (
                     # либо только своих
                     current_user.has_right('actDelOwn') and
                     (current_user.id_any_in(action.createPerson_id,
                                             action.person_id))))))
Example #5
0
 def can_edit_action(action):
     updateRight = u'client%sUpdate' % modeRights[action.actionType.class_]
     return action and (
         # админу можно всё
         current_user.has_right('adm') or (
             # действие не закрыто
             action.status < 2 and
             # остальным - только если обращение не закрыто
             not action.event.is_closed and (
                 # либо есть право редактировать любые действия
                 current_user.has_right('editOtherpeopleAction') or (
                     # либо право на свои определённых классов
                     current_user.has_right(updateRight) and current_user.
                     id_any_in(action.createPerson_id, action.person_id)))))
Example #6
0
 def can_delete_event(event):
     # TODO: check payments
     if current_user.has_right('evtDelAll') or current_user.has_right(
             'adm'):
         return True, ''
     elif current_user.has_right('evtDelOwn'):
         if event.execPerson_id == current_user.id:
             return True, ''
         elif event.createPerson_id == current_user.id:
             # Проверка, что все действия не были изменены после создания обращения
             # или, что не появилось новых действий
             for action in event.actions:
                 if action.modifyPerson_id != event.createPerson_id:
                     return False, u'В обращении были созданы новые или отредактированы первоначальные документы'
             return True, ''
     return False, u'У пользователя нет прав на удаление обращения'
Example #7
0
    def can_create_event(event, out_msg=None):
        if out_msg is None:
            out_msg = {'message': u'ok'}

        base_msg = u'У пользователя нет прав на создание обращений типа %s'
        event_type = event and event.eventType
        if not event_type:
            out_msg['message'] = u'У обращения не указан тип'
            return False
        if current_user.has_right('adm'):
            return True
        # есть ли ограничения на создание обращений определенных EventType
        if event.is_policlinic and event.is_paid:
            if not current_user.has_right(urEventPoliclinicPaidCreate):
                out_msg['message'] = base_msg % unicode(event_type)
                return False
        elif event.is_policlinic and event.is_oms:
            if not current_user.has_right(urEventPoliclinicOmsCreate):
                out_msg['message'] = base_msg % unicode(event_type)
                return False
            client = event.client
            if not (client.policy and client.policy.is_valid(event.setDate)):
                out_msg['message'] = u'Нельзя создавать обращения %s для пациентов без ' \
                                     u'действующего полиса ОМС' % unicode(event_type)
                return False
            if client.is_adult:
                out_msg[
                    'message'] = u'Нельзя создавать обращения %s для пациентов старше 18 лет' % unicode(
                        event_type)
                return False
            if not safe_traverse_attrs(client, 'reg_address', 'is_russian'):
                out_msg['message'] = u'Нельзя создавать обращения %s для пациентов без адреса ' \
                                     u'регистрации в РФ' % unicode(event_type)
                return False
        elif event.is_policlinic and event.is_dms:
            if not current_user.has_right(urEventPoliclinicDmsCreate):
                out_msg['message'] = base_msg % unicode(event_type)
                return False
        elif event.is_diagnostic and event.is_paid:
            if not current_user.has_right(urEventDiagnosticPaidCreate):
                out_msg['message'] = base_msg % unicode(event_type)
                return False
        elif event.is_diagnostic and event.is_budget:
            if not current_user.has_right(urEventDiagnosticBudgetCreate):
                out_msg['message'] = base_msg % unicode(event_type)
                return False
        # все остальные можно
        return True
Example #8
0
    def can_close_event(event, out_msg=None):
        if out_msg is None:
            out_msg = {'message': u'ok'}

        base_msg = u'У пользователя нет прав на закрытие обращений типа %s'
        event_type = event and event.eventType
        if not event:
            out_msg['message'] = u'Обращение еще не создано'
            return False
        if event.is_closed:
            out_msg['message'] = u'Обращение уже закрыто'
            return False
        if current_user.has_right('adm'):
            return True
        # Состояние пользователя
        if not current_user.id_any_in(event.execPerson_id,
                                      event.createPerson_id):
            out_msg[
                'message'] = u'Пользователь не является создателем или ответственным за обращение'
            return False
        # есть ли ограничения на закрытие обращений определенных EventType
        if event.is_policlinic and event.is_paid:
            if not current_user.has_right(urEventPoliclinicPaidClose):
                out_msg['message'] = base_msg % unicode(event_type)
                return False
        elif event.is_policlinic and event.is_oms:
            if not current_user.has_right(urEventPoliclinicOmsClose):
                out_msg['message'] = base_msg % unicode(event_type)
                return False
        elif event.is_policlinic and event.is_dms:
            if not current_user.has_right(urEventPoliclinicDmsClose):
                out_msg['message'] = base_msg % unicode(event_type)
                return False
        elif event.is_diagnostic and event.is_paid:
            if not current_user.has_right(urEventDiagnosticPaidClose):
                out_msg['message'] = base_msg % unicode(event_type)
                return False
        elif event.is_diagnostic and event.is_budget:
            if not current_user.has_right(urEventDiagnosticBudgetClose):
                out_msg['message'] = base_msg % unicode(event_type)
                return False
        # все остальные можно
        return True
Example #9
0
 def can_read_actions_treatment(event):
     readRight = u'client%sRead' % modeRights[2]
     return event and (current_user.has_right('adm') or
                       (current_user.has_right(readRight) and
                        (not event.is_diagnostic)))
Example #10
0
 def can_read_actions_lab(event):
     readRight = u'client%sRead' % modeRights[1]
     return event and (current_user.has_right('adm') or
                       (current_user.has_right(readRight)))
Example #11
0
 def can_read_action(action):
     readRight = u'client%sRead' % modeRights[action.actionType.class_]
     return action and (current_user.has_right('adm') or
                        (current_user.has_right(readRight)
                         and current_user.id_any_in(action.createPerson_id,
                                                    action.person_id)))
Example #12
0
 def can_edit_dignoses(event):
     return event and (current_user.has_right('adm') or
                       (UserProfileManager.has_ui_doctor()
                        and not UserProfileManager.has_ui_diag_doctor()))
Example #13
0
 def can_read_dignoses(event):
     return event and (current_user.has_right('adm') or
                       (UserProfileManager.has_ui_doctor()
                        and not event.is_diagnostic))
Example #14
0
 def can_edit_event_payment_info(event):
     return current_user.has_right('adm') or (
         (current_user.has_right('evtPaymentInfoUpdate') and
          (not event.is_closed if event else True)))