<commit_before>module API
  class ConsultationsController < BaseController
    def last
      consultation = patient.consultations.last
      render json: consultation
    end

    def previous
      consultation = Consultation.find(previous_consultation_id)
      render json: consultation
    end

    def next
      consultation = Consultation.find(next_consultation_id)
      render json: consultation
    end

    private

    def previous_consultation_id
      patient_consultations[current_consultation_index.succ]
    end

    def next_consultation_id
      consultation_index = current_consultation_index.pred
      return nil if consultation_index < 0

      patient_consultations[consultation_index]
    end

    def current_consultation_index
      patient_consultations.index(current_consultation)
    end

    def current_consultation
      params[:current_consultation].to_i
    end

    def patient
      Patient.find(params[:patient_id])
    end

    def patient_consultations
      @consultations ||= patient.consultations.pluck(:id).reverse
    end
  end
end
<commit_msg>Refactor: Use `most_recent` instead of `last` on consultations<commit_after>module API
  class ConsultationsController < BaseController
    def last
      consultation = patient.consultations.most_recent
      render json: consultation
    end

    def previous
      consultation = Consultation.find(previous_consultation_id)
      render json: consultation
    end

    def next
      consultation = Consultation.find(next_consultation_id)
      render json: consultation
    end

    private

    def patient
      Patient.find(params[:patient_id])
    end

    def patient_consultations
      @consultations ||= patient.consultations.ordered_by_date.pluck(:id).reverse
    end

    def previous_consultation_id
      patient_consultations[current_consultation_index.succ]
    end

    def next_consultation_id
      consultation_index = current_consultation_index.pred
      return nil if consultation_index < 0

      patient_consultations[consultation_index]
    end

    def current_consultation_index
      patient_consultations.index(current_consultation)
    end

    def current_consultation
      params[:current_consultation].to_i
    end
  end
end

{'fraction_non_alphanumeric': 0.046181172291296625, 'fraction_numerical': 0.0008880994671403197, 'mean_word_length': 3.3078393881453154, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5992912', 'n_tokens_mistral': 649, 'n_tokens_neox': 635, 'n_words': 135}