Sha256: a13ca139c9152c5137a08c59c545716d1c230e9d05fb78ad230ab47270724701

Contents?: true

Size: 1.86 KB

Versions: 35

Compression:

Stored size: 1.86 KB

Contents

require_dependency "renalware/hd/base_controller"

module Renalware
  module PD
    class InfectionOrganismsController < BaseController
      def index
        @infectable = infectable_class.find(infectable_id)
        @infection_organisms = @infectable.infection_organisms

        authorize @infectable.patient
      end

      def new
        @infectable = infectable_class.find(infectable_id)
        @infection_organism = InfectionOrganism.new

        authorize @infectable.patient
      end

      def create
        @infectable = infectable_class.find(infectable_id)

        authorize @infectable.patient

        @infection_organism = @infectable.infection_organisms.create(infection_organism_params)
      end

      def edit
        @infection_organism = InfectionOrganism.find(params[:id])
        @infectable = @infection_organism.infectable

        authorize @infectable.patient
      end

      def update
        @infection_organism = InfectionOrganism.find(params[:id])
        @infectable = @infection_organism.infectable

        authorize @infectable.patient

        @infection_organism.update(infection_organism_params)
      end

      def destroy
        @infection_organism = InfectionOrganism.find(params[:id])
        @infectable = @infection_organism.infectable
        @infection_organisms = @infectable.infection_organisms

        authorize @infectable.patient

        @infection_organism.destroy!
      end

      private

      def infection_organism_params
        params
          .require(:pd_infection_organism)
          .permit(:organism_code_id, :sensitivity, :resistance)
      end

      def infectable_class
        @infectable_class ||= infectable_type.singularize.classify.constantize
      end

      def infectable_type
        params.fetch(:infectable_type)
      end

      def infectable_id
        params.fetch(:infectable_id)
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.15 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.14 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.13 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.12 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.11 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.9 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.8 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.7 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.5 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.4 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.3 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.2 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.1 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.0 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/pd/infection_organisms_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/pd/infection_organisms_controller.rb