<commit_before>module Renalware
  class ClinicVisitsController < BaseController
    load_and_authorize_resource

    before_filter :load_patient
    before_filter :load_clinic_visit, only: [:edit, :update, :destroy]

    def index
      @clinic_visits = @patient.clinic_visits
    end

    def new
      @clinic_visit = ClinicVisit.new(patient: @patient)
    end

    def create
      @clinic_visit = ClinicVisit.new(clinic_visit_params)

      if @clinic_visit.save
        redirect_to patient_clinic_visits_path(@patient)
      else
        flash[:error] = 'Failed to save clinic'
        render :new
      end
    end

    def update
      if @clinic_visit.update_attributes(clinic_visit_params)
        redirect_to patient_clinic_visits_path(@patient)
      else
        flash[:error] = 'Failed to update clinic'
        render :new
      end
    end

    def destroy
      if @clinic_visit.destroy
        redirect_to patient_clinic_visits_path(@patient)
      else
        flash[:error] = 'Failed to delete clinic'
        render :index
      end
    end

    private

    def clinic_visit_params
      params.require(:clinic_visit).permit(
        :patient_id, :date, :height, :weight,
        :bp, :urine_blood, :urine_protein, :notes)
    end

    def load_clinic_visit
      @clinic_visit = ClinicVisit.find(params[:id])
    end
  end
end<commit_msg>Removed cancancan method, added pundit 'authorize' method to clinic visit controller actions.<commit_after>module Renalware
  class ClinicVisitsController < BaseController

    before_filter :load_patient
    before_filter :load_clinic_visit, only: [:edit, :update, :destroy]

    def index
      @clinic_visits = @patient.clinic_visits
      authorize @clinic_visits
    end

    def new
      @clinic_visit = ClinicVisit.new(patient: @patient)
      authorize @clinic_visit
    end

    def create
      @clinic_visit = ClinicVisit.new(clinic_visit_params)
      authorize @clinic_visit
      if @clinic_visit.save
        redirect_to patient_clinic_visits_path(@patient)
      else
        flash[:error] = 'Failed to save clinic'
        render :new
      end
    end

    def update
      if @clinic_visit.update_attributes(clinic_visit_params)
        redirect_to patient_clinic_visits_path(@patient)
      else
        flash[:error] = 'Failed to update clinic'
        render :new
      end
    end

    def destroy
      if @clinic_visit.destroy
        redirect_to patient_clinic_visits_path(@patient)
      else
        flash[:error] = 'Failed to delete clinic'
        render :index
      end
    end

    private

    def clinic_visit_params
      params.require(:clinic_visit).permit(
        :patient_id, :date, :height, :weight,
        :bp, :urine_blood, :urine_protein, :notes)
    end

    def load_clinic_visit
      @clinic_visit = ClinicVisit.find(params[:id])
      authorize @clinic_visit
    end
  end
end
{'fraction_non_alphanumeric': 0.07132963988919667, 'fraction_numerical': 0.0, 'mean_word_length': 2.718146718146718, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3222078', 'n_tokens_mistral': 956, 'n_tokens_neox': 882, 'n_words': 207}