Sha256: 21c7fdba6d8e06ec09e08d446c08a281b53829dfd0a268dab2b5952f63e4f844

Contents?: true

Size: 1.32 KB

Versions: 158

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module DrugsSpecHelper
  def load_drugs(*names)
    names.each do |name|
      drug = create(:drug, name: name)
      instance_variable_set(:"@#{name.downcase}", drug)
    end
  end

  # { 'Amoxicillin' => ['Antibiotic', 'Peritonitis'], 'Penicillin' => ['Foo', ...] }
  def load_drugs_by_type(drugs_by_type)
    drugs_by_type.each do |drug_name, drug_type_names|
      drug = assign_drug(drug_name)
      drug_type_names.each { |name| assign_drug_type(drug, name) }
    end
  end

  def load_med_routes
    medication_routes = {
      "PO" => "Per Oral",
      "IV" => "Intravenous",
      "SC" => "Subcutaneous",
      "IM" => "Intramuscular",
      "Other" => "Other (Refer to notes)"
    }

    medication_routes.map do |code, name|
      route = create(:medication_route, code: code, name: name)
      instance_variable_set(:"@#{code.downcase}", route)
    end
  end

  private

  def assign_drug(name)
    drug = create(:drug, name: name)
    instance_variable_set(:"@#{name.downcase}", drug)
  end

  def assign_drug_type(drug, name)
    drug_type = Renalware::Drugs::Type.find_by(code: name.downcase)

    if drug_type.blank?
      drug_type = create(:drug_type, code: name.downcase, name: name)
      instance_variable_set(:"@#{name.downcase}", drug_type)
    end

    drug.drug_types << drug_type
  end
end

Version data entries

158 entries across 158 versions & 1 rubygems

Version Path
renalware-core-2.1.1 spec/support/drugs_spec_helper.rb
renalware-core-2.1.0 spec/support/drugs_spec_helper.rb
renalware-core-2.0.167 spec/support/drugs_spec_helper.rb
renalware-core-2.0.166 spec/support/drugs_spec_helper.rb
renalware-core-2.0.165 spec/support/drugs_spec_helper.rb
renalware-core-2.0.164 spec/support/drugs_spec_helper.rb
renalware-core-2.0.163 spec/support/drugs_spec_helper.rb
renalware-core-2.0.162 spec/support/drugs_spec_helper.rb
renalware-core-2.0.161 spec/support/drugs_spec_helper.rb
renalware-core-2.0.160 spec/support/drugs_spec_helper.rb
renalware-core-2.0.159 spec/support/drugs_spec_helper.rb
renalware-core-2.0.158 spec/support/drugs_spec_helper.rb
renalware-core-2.0.157 spec/support/drugs_spec_helper.rb
renalware-core-2.0.156 spec/support/drugs_spec_helper.rb
renalware-core-2.0.155 spec/support/drugs_spec_helper.rb
renalware-core-2.0.153 spec/support/drugs_spec_helper.rb
renalware-core-2.0.152 spec/support/drugs_spec_helper.rb
renalware-core-2.0.151 spec/support/drugs_spec_helper.rb
renalware-core-2.0.149 spec/support/drugs_spec_helper.rb
renalware-core-2.0.148 spec/support/drugs_spec_helper.rb