Sha256: 3f1dec53be1b4d3f5b844b1b968ae1f46526533cfb98941b3eb253f9abe59b11

Contents?: true

Size: 1001 Bytes

Versions: 1

Compression:

Stored size: 1001 Bytes

Contents

# coding: utf-8

class TipoExame < ApplicationRecord
  has_many :exames
  belongs_to :especialidade

  before_destroy :verificar_exames

  def verificar_exames
    if self.exames.size > 0
      errors.add(:base, "O tipo de exame não pode ser excluído pois existem exames deste tipo!")
      return false
    end
    return true
  end

  def transferir_exames(tipo_exame_destino)
    self.exames.each do |exame|
      exame.update_attributes(:tipo_exame_id => tipo_exame_destino.id)
    end
    exames = Exame.where(:tipo_exame_id => self.id)
    return exames.empty?
  end

  def self.select(especialidade, selected)
    options = "<option value="">Selecione</option>"
    self.where(:especialidade_id => especialidade.id).order(:nome).each do |tipo|
      if tipo.id == selected
        options << "<option selected='selected' value='#{tipo.id}'>#{tipo.nome}</option>"
      else
        options << "<option value='#{tipo.id}'>#{tipo.nome}</option>"
      end
    end
    return options
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-sabia-1.0.1 app/models/tipo_exame.rb