Sha256: a5935d685e48d99e1790f3068819ff67bb3539d29ec6868e31a3be5fb92395fd

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

module Medivo
  class LabsController < ActionController::Base

    def index
      lab_data = Medivo::Lab.data_for_zip(params[:zip_code])
      render :json=> lab_data
    end

    def find_appointment
      date = Date.strptime(params[:date], "%m/%d/%Y")
      data = Medivo::Appointment.find(params[:lab_code], date, params[:am_pm])
      render :json=> {times: data}
    rescue => e
      appointment_error_handler(e)
    end

    def make_appointment
      time = Time.parse(params[:time])
      data = Medivo::Appointment.make(params[:lab_code], time, params[:user])
      render :json=> data
    rescue Exception => e
      appointment_error_handler(e)
    end

    def cancel_appointment
      data = Medivo::Appointment.cancel(params[:confirmation], params[:first_name], params[:last_name])
      render :json=> data
    rescue Exception => e
      render :status=> 500, json: {message: e.message}
    end

    def appointment_error_handler(e)
      case e
        when RestClient::RequestTimeout, RestClient::InternalServerError
          render :status=> e.http_code, json: {message: "Could be lab_code is wrong, or labcorp server is down"}
        when RestClient::Exception
          render :status=> e.http_code, json: {message: e.response}
        else
          render :status=> 500, json: {message: e.message}
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
medivo-0.2.24 app/controllers/medivo/labs_controller.rb