Sha256: 2ea86dca0b4999efeb3652f654fc4da6059994caf99696b4266d46d62ef800f6

Contents?: true

Size: 998 Bytes

Versions: 1

Compression:

Stored size: 998 Bytes

Contents

# encoding: utf-8

module CalendarioAgendamentos

	def get_agendamentos(conditions)
		agendamentos = Agendamento.includes(:paciente).where(conditions.join(' and ')).order('agendamentos.data,  agendamentos.turno_id asc')
		agendamentos_calendario = Array.new

		manha = Time.new(2010, 10, 10, 7, 0)
		tarde = Time.new(2010, 10, 10, 13, 0)
		data = nil

		agendamentos.each do |agendamento|
			if agendamento.data != data
				data = agendamento.data
				manha = Time.new(2010, 10, 10, 7, 0)
				tarde = Time.new(2010, 10, 10, 13, 0)
			end

			if agendamento.turno_id == 1
				inicio = DateTime.new(data.year, data.month, data.day, manha.hour, manha.min)
				manha = manha + 1800
			else
				inicio = DateTime.new(data.year, data.month, data.day, tarde.hour, tarde.min)
				tarde = tarde + 1800
			end

			agendamentos_calendario << { 'id' => agendamento.id, 'title' => agendamento.paciente.nome, 'start' => inicio , 'end' => (inicio + 30.minutes) }
		end

		return agendamentos_calendario
	end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
omniauth-sabia-1.0.1 lib/calendario_agendamentos.rb