Sha256: 3a288f0bff6e251be2073c83ad0884f1e47d79ed0673a3d3eb7266b7a8adcb74

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 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
      data = Medivo::Appointment.make(params[:lab_code], params[:time], params[:user])
      render :json=> data
    rescue Exception => e
      appointment_error_handler(e)
    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

2 entries across 2 versions & 1 rubygems

Version Path
medivo-0.2.21 app/controllers/medivo/labs_controller.rb
medivo-0.2.20 app/controllers/medivo/labs_controller.rb