<commit_before>require 'rails_helper'

module Renalware::Medications
  RSpec.describe TreatableMedicationsQuery, :type => :model do

    let(:treatable) { create(:patient) }

    context "given no filter" do
      let!(:current_medication) { create(:medication, patient: treatable, treatable: treatable) }
      let!(:terminated_medication) { create(:medication, :terminated, patient: treatable, treatable: treatable) }

      subject(:query) { TreatableMedicationsQuery.new(treatable: treatable) }

      it "returns current medications for a treatable target" do
        medications = query.call

        expect(medications).to include(current_medication)
        expect(medications).not_to include(terminated_medication)
      end
    end

    context "given a filter for a drug type" do
      let!(:target_drug_type) { create(:drug_type) }
      let!(:target_drug) { create(:drug, drug_types: [target_drug_type] ) }
      let!(:target_medication) { create(:medication, notes: ":target medication:", patient: treatable, treatable: treatable, drug: target_drug) }

      let!(:other_drug_type) { create(:drug_type) }
      let!(:other_drug) { create(:drug, drug_types: [other_drug_type] ) }
      let!(:other_medication) { create(:medication, notes: ":other medication:", patient: treatable, treatable: treatable, drug: other_drug) }

      subject(:query) { TreatableMedicationsQuery.new(treatable: treatable, search_params: {drug_drug_types_id_eq: target_drug_type.id}) }

      it "returns the current medications matching the specified drug type only" do
        medications = query.call

        expect(medications.map(&:notes)).to include(target_medication.notes)<commit_msg>Fix style violations<commit_after>require "rails_helper"

module Renalware::Medications
  RSpec.describe TreatableMedicationsQuery, type: :model do

    let(:treatable) { create(:patient) }

    context "given no filter" do
      let!(:current_medication) { create(:medication, patient: treatable, treatable: treatable) }
      let!(:terminated_medication) do create(
        :medication, :terminated,
        patient: treatable, treatable: treatable
      )
      end

      subject(:query) { TreatableMedicationsQuery.new(treatable: treatable) }

      it "returns current medications for a treatable target" do
        medications = query.call

        expect(medications).to include(current_medication)
        expect(medications).not_to include(terminated_medication)
      end
    end

    context "given a filter for a drug type" do
      let(:target_drug_type) { create(:drug_type) }
      let(:target_drug) { create(:drug, drug_types: [target_drug_type]) }
      let!(:target_medication) do
        create(
          :medication, notes: ":target medication:",
          patient: treatable, treatable: treatable, drug: target_drug
        )
      end

      let(:other_drug_type) { create(:drug_type) }
      let(:other_drug)  { create(:drug, drug_types: [other_drug_type]) }
      let!(:other_medication) do
        create(
          :medication, notes: ":other medication:",
          patient: treatable, treatable: treatable, drug: other_drug
        )
      end

      subject(:query) do
        TreatableMedicationsQuery.new(
          treatable: treatable,
          search_params: { drug_drug_types_id_eq: target_drug_type.id }
        )
      end

      it "returns the current medications matching the specified drug type only" do
        medications = query.call

        expect(medications.map(&:notes)).to include(target_medication.notes)
{'fraction_non_alphanumeric': 0.10449025698955097, 'fraction_numerical': 0.0, 'mean_word_length': 3.654402102496715, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 4, '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': '3403786', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1003, 'n_words': 241}