<commit_before>module Renalware
  class PeritonitisEpisodesController < BaseController

    before_action :load_patient, :except => [:index, :destroy]
    before_action :load_peritonitis_episode, :only => [:show, :edit, :update]

    def new
      @peritonitis_episode = PeritonitisEpisode.new
    end

    def create
      @peritonitis_episode = PeritonitisEpisode.new(peritonitis_episode_params)
      @peritonitis_episode.patient_id = @patient.id
      if @peritonitis_episode.save
        redirect_to patient_peritonitis_episode_path(@patient, @peritonitis_episode),
          notice: t(".success", model_name: "peritonitis episode")
      else
        flash[:error] = t(".failed", model_name: "peritonitis episode")
        render :new
      end
    end

    def edit
      render
    end

    def update
      @peritonitis_episode.update(peritonitis_episode_params)
    end

    private

    def peritonitis_episode_params
      params.require(:peritonitis_episode).permit(
        :diagnosis_date, :treatment_start_date, :treatment_end_date,
        :episode_type_id, :catheter_removed, :line_break, :exit_site_infection,
        :diarrhoea, :abdominal_pain, :fluid_description_id, :white_cell_total,
        :white_cell_neutro, :white_cell_lympho, :white_cell_degen,
        :white_cell_other, :notes
      )
    end

    def load_peritonitis_episode
      @peritonitis_episode = PeritonitisEpisode.find(params[:id])
    end
  end
end
<commit_msg>Scope to patient when finding episode<commit_after>module Renalware
  class PeritonitisEpisodesController < BaseController

    before_action :load_patient, :except => [:index, :destroy]
    before_action :load_peritonitis_episode, :only => [:show, :edit, :update]

    def new
      @peritonitis_episode = PeritonitisEpisode.new
    end

    def create
      @peritonitis_episode = PeritonitisEpisode.new(peritonitis_episode_params)
      @peritonitis_episode.patient_id = @patient.id
      if @peritonitis_episode.save
        redirect_to patient_peritonitis_episode_path(@patient, @peritonitis_episode),
          notice: t(".success", model_name: "peritonitis episode")
      else
        flash[:error] = t(".failed", model_name: "peritonitis episode")
        render :new
      end
    end

    def edit
      render
    end

    def update
      @peritonitis_episode.update(peritonitis_episode_params)
    end

    private

    def peritonitis_episode_params
      params.require(:peritonitis_episode).permit(
        :diagnosis_date, :treatment_start_date, :treatment_end_date,
        :episode_type_id, :catheter_removed, :line_break, :exit_site_infection,
        :diarrhoea, :abdominal_pain, :fluid_description_id, :white_cell_total,
        :white_cell_neutro, :white_cell_lympho, :white_cell_degen,
        :white_cell_other, :notes
      )
    end

    def load_peritonitis_episode
      @peritonitis_episode = PeritonitisEpisode.for_patient(@patient).find(params[:id])
    end
  end
end

{'fraction_non_alphanumeric': 0.08322056833558863, 'fraction_numerical': 0.0, 'mean_word_length': 3.642072213500785, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4228241', 'n_tokens_mistral': 1058, 'n_tokens_neox': 951, 'n_words': 171}