Class: Formulary::FormularyDrugFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/formulary/formulary_drug_factory.rb

Overview

Class to build FormularyDrug resources from a QHPPlanDrug

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plan_drug) ⇒ FormularyDrugFactory

Returns a new instance of FormularyDrugFactory.



12
13
14
# File 'lib/formulary/formulary_drug_factory.rb', line 12

def initialize(plan_drug)
  @plan_drug = plan_drug
end

Instance Attribute Details

#plan_drugObject (readonly)

Returns the value of attribute plan_drug.



10
11
12
# File 'lib/formulary/formulary_drug_factory.rb', line 10

def plan_drug
  @plan_drug
end

Instance Method Details

#build(id = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/formulary/formulary_drug_factory.rb', line 16

def build(id = nil)
  FHIR::MedicationKnowledge.new(
    id: "#{DRUG_ID_PREFIX}#{id}",
    code: code,
    status: "active",
    doseForm: dose_form,
    # TODO Need to do related Medication Knowledge (possibly optional based on testing outcomes)
    # Can we add classigfication for testing? Will need to build out source data more.
    meta: meta,
  )
end

#codeObject (private)



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/formulary/formulary_drug_factory.rb', line 30

def code
  {
    coding: [
      {
        system: RXNORM_SYSTEM,
        code: plan_drug.rxnorm_code,
        display: plan_drug.name,
      },
    ],
  }
end

#dose_formObject (private)



42
43
44
45
46
47
48
49
50
# File 'lib/formulary/formulary_drug_factory.rb', line 42

def dose_form
  json_data = File.read("doseform.json")
  dose_forms = JSON.parse(json_data, :symbolize_names => true)
  coding = dose_forms.find { |coding| plan_drug.name.downcase.include?(coding[:display].downcase) }
  return if coding.nil?
  {
    coding: [coding],
  }
end

#metaObject (private)



59
60
61
62
63
64
65
# File 'lib/formulary/formulary_drug_factory.rb', line 59

def meta
  current_date = Date.today.to_s
  {
    profile: [FORMULARY_DRUG_PROFILE],
    lastUpdated: "#{current_date}T10:03:10Z",
  }
end

#textObject (private)



52
53
54
55
56
57
# File 'lib/formulary/formulary_drug_factory.rb', line 52

def text
  {
    status: "generated",
    div: %(<div xmlns="http://www.w3.org/1999/xhtml">#{plan_drug.name}</div>),
  }
end