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.127 spec/support/drugs_spec_helper.rb
renalware-core-2.0.126 spec/support/drugs_spec_helper.rb
renalware-core-2.0.125 spec/support/drugs_spec_helper.rb
renalware-core-2.0.124 spec/support/drugs_spec_helper.rb
renalware-core-2.0.123 spec/support/drugs_spec_helper.rb
renalware-core-2.0.121 spec/support/drugs_spec_helper.rb
renalware-core-2.0.120 spec/support/drugs_spec_helper.rb
renalware-core-2.0.119 spec/support/drugs_spec_helper.rb
renalware-core-2.0.118 spec/support/drugs_spec_helper.rb
renalware-core-2.0.117 spec/support/drugs_spec_helper.rb
renalware-core-2.0.116 spec/support/drugs_spec_helper.rb
renalware-core-2.0.115 spec/support/drugs_spec_helper.rb
renalware-core-2.0.113 spec/support/drugs_spec_helper.rb
renalware-core-2.0.112 spec/support/drugs_spec_helper.rb
renalware-core-2.0.111 spec/support/drugs_spec_helper.rb
renalware-core-2.0.110 spec/support/drugs_spec_helper.rb
renalware-core-2.0.109 spec/support/drugs_spec_helper.rb
renalware-core-2.0.108 spec/support/drugs_spec_helper.rb
renalware-core-2.0.106 spec/support/drugs_spec_helper.rb
renalware-core-2.0.105 spec/support/drugs_spec_helper.rb