Class: Formulary::FormularyFactory

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

Overview

Class to build Formulary resources from a QHPPlan

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plan) ⇒ FormularyFactory

Returns a new instance of FormularyFactory.



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

def initialize(plan)
  @plan = plan
end

Instance Attribute Details

#planObject (readonly)

Returns the value of attribute plan.



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

def plan
  @plan
end

Instance Method Details

#buildObject



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

def build
  name.strip!

  FHIR::InsurancePlan.new(
    id: FORMULARY_ID_PREFIX + plan.id,
    meta: meta,
    text: text,
    identifier: identifier,
    status: "active",
    name: name,
    type: type,
    period: period,
  )
end

#identifierObject (private)



47
48
49
# File 'lib/formulary/formulary_factory.rb', line 47

def identifier
  [{ value: FORMULARY_ID_PREFIX + plan.id }]
end

#metaObject (private)



33
34
35
36
37
38
# File 'lib/formulary/formulary_factory.rb', line 33

def meta
  {
    profile: [FORMULARY_PROFILE],
    lastUpdated: plan.last_updated + "T00:00:00Z",
  }
end

#nameObject (private)

Returns the plan marketing name [String].

Returns:

  • the plan marketing name [String]



52
53
54
# File 'lib/formulary/formulary_factory.rb', line 52

def name
  plan.marketing_name
end

#periodObject (private)



68
69
70
71
72
73
74
# File 'lib/formulary/formulary_factory.rb', line 68

def period
  current_year = Date.today.year
  {
    "start": "#{current_year}-01-01",
    "end": "#{current_year}-12-31",
  }
end

#textObject (private)



40
41
42
43
44
45
# File 'lib/formulary/formulary_factory.rb', line 40

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

#typeObject (private)



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/formulary/formulary_factory.rb', line 56

def type
  {
    coding: [
      {
        system: FORMULARY_TYPE_SYSTEM,
        code: FORMULARY_TYPE_CS_CODE,
        display: FORMULARY_TYPE_CS_DISPLAY,
      },
    ],
  }
end