Sha256: ce038e6b1b17c91fee668ecedeac60d6a6a815ab4774431b9207ccd892ff3020

Contents?: true

Size: 1.65 KB

Versions: 54

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/clinics"

module Renalware
  module Clinics
    class AppointmentsController < BaseController
      include Renalware::Concerns::Pageable

      def index
        appointments_query = AppointmentQuery.new(query_params)
        appointments = appointments_query.call.page(page).per(per_page)
        authorize appointments

        render :index, locals: {
          appointments: appointments,
          query: appointments_query.search,
          clinics: Clinic.ordered,
          users: User.ordered,
          request_html_form_params: build_params_for_html_form(appointments)
        }
      end

      def new
        render_new(Appointment.new)
      end

      def create
        appointment = Appointment.new(appointment_params)
        authorize appointment
        if appointment.save_by(current_user)
          redirect_to appointments_path, notice: t(".success", model_name: "Appointment")
        else
          render_new(appointment)
        end
      end

      private

      def render_new(appointment)
        authorize appointment
        render :new, locals: { appointment: appointment }
      end

      def build_params_for_html_form(appointments)
        OpenStruct.new(
          patient_ids: appointments.map(&:patient_id).uniq
        )
      end

      def query_params
        params.fetch(:q, {})
      end

      def appointment_params
        params
          .require(:clinics_appointment)
          .permit(
            :patient_id,
            :clinic_id,
            :starts_at,
            :outcome_notes,
            :dna_notes,
            :consultant_id)
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
renalware-core-2.0.167 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.166 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.165 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.164 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.163 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.162 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.161 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.160 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.159 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.158 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.157 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.156 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.155 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.153 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.152 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.151 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.149 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.148 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.147 app/controllers/renalware/clinics/appointments_controller.rb
renalware-core-2.0.146 app/controllers/renalware/clinics/appointments_controller.rb