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.0.40 spec/support/drugs_spec_helper.rb
renalware-core-2.0.39 spec/support/drugs_spec_helper.rb
renalware-core-2.0.38 spec/support/drugs_spec_helper.rb
renalware-core-2.0.37 spec/support/drugs_spec_helper.rb
renalware-core-2.0.36 spec/support/drugs_spec_helper.rb
renalware-core-2.0.35 spec/support/drugs_spec_helper.rb
renalware-core-2.0.34 spec/support/drugs_spec_helper.rb
renalware-core-2.0.33 spec/support/drugs_spec_helper.rb
renalware-core-2.0.32 spec/support/drugs_spec_helper.rb
renalware-core-2.0.31 spec/support/drugs_spec_helper.rb
renalware-core-2.0.30 spec/support/drugs_spec_helper.rb
renalware-core-2.0.28 spec/support/drugs_spec_helper.rb
renalware-core-2.0.27 spec/support/drugs_spec_helper.rb
renalware-core-2.0.26 spec/support/drugs_spec_helper.rb
renalware-core-2.0.25 spec/support/drugs_spec_helper.rb
renalware-core-2.0.24 spec/support/drugs_spec_helper.rb
renalware-core-2.0.23 spec/support/drugs_spec_helper.rb
renalware-core-2.0.22 spec/support/drugs_spec_helper.rb
renalware-core-2.0.21 spec/support/drugs_spec_helper.rb
renalware-core-2.0.20 spec/support/drugs_spec_helper.rb