<commit_before>class VisitsController < ApplicationController

  expose(:all_visits) { Visit.ordered.decorate }
  expose(:visits)
  expose_decorated(:visit, attributes: :permitted_params)

  def create
    if visit.save
      send_confirmation
      redirect_to root_path
    else
      render :new
    end
  end

  def update
    if visit.save
      send_confirmation
      redirect_to root_path
    else
      render :edit
    end
  end

  def destroy
    visit.destroy
    redirect_to root_path
  end

  private

  def permitted_params
    params.require(:visit).permit(:patient_id, :speciality_id, :doctor_id, :confirmed, :date, :reason, :note, :instructions, procedure_ids: [], recognition_ids: [], med_ids: [])
  end

  def send_confirmation
    PatientMailer.confirm_visit(visit).deliver if visit.patient.email.present? and visit.date.present?
  end

end<commit_msg>check visit doctor and patient<commit_after>class VisitsController < ApplicationController

  expose(:all_visits) { Visit.ordered.decorate }
  expose(:visits)
  expose_decorated(:visit, attributes: :permitted_params)

  before_filter :authenticate_stuff!, only: :index
  before_filter :visit_patient_and_doctor, except: :index

  def create
    if visit.save
      send_confirmation
      redirect_to root_path
    else
      render :new
    end
  end

  def update
    if visit.save
      send_confirmation
      redirect_to root_path
    else
      render :edit
    end
  end

  def destroy
    visit.destroy
    redirect_to root_path
  end

  private

  def permitted_params
    params.require(:visit).permit(:patient_id, :speciality_id, :doctor_id, :confirmed, :date, :reason, :note, :instructions, procedure_ids: [], recognition_ids: [], med_ids: [])
  end

  def send_confirmation
    PatientMailer.confirm_visit(visit).deliver if visit.patient.email.present? and visit.date.present?
  end

  def visit_patient_and_doctor
    if doctor?
      redirect_to root_path unless visit.doctor == current_user
    elsif patient?
      redirect_to root_path unless visit.patient == current_user
    end
  end

end
{'fraction_non_alphanumeric': 0.07540826128722382, 'fraction_numerical': 0.0, 'mean_word_length': 3.5579868708971554, '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': '4536679', 'n_tokens_mistral': 655, 'n_tokens_neox': 632, 'n_words': 155}