Class: Formulary::FormularyItemFactory
- Inherits:
-
Object
- Object
- Formulary::FormularyItemFactory
- Defined in:
- lib/formulary/formulary_item_factory.rb
Overview
Class to build FormularyItem (FHIR Basic) resources from a QHPPlanDrug
Instance Attribute Summary collapse
-
#plan ⇒ Object
readonly
Returns the value of attribute plan.
-
#plan_drug ⇒ Object
readonly
Returns the value of attribute plan_drug.
Instance Method Summary collapse
- #availability_period_extension ⇒ Object private
- #availability_status_extension ⇒ Object private
-
#build ⇒ Object
Construct a FHIR Basic instance.
- #code ⇒ Object private
- #drug_tier_extension ⇒ Object private
- #extension ⇒ Object private
- #formulary_reference_extension ⇒ Object private
-
#initialize(plan, plan_drug) ⇒ FormularyItemFactory
constructor
A new instance of FormularyItemFactory.
- #meta ⇒ Object private
- #pharmacy_type_extension(pharmacy_type) ⇒ Object private
- #pharmacy_type_extensions ⇒ Object private
- #prior_auth_extension ⇒ Object private
- #prior_auth_new_start_extension ⇒ Object private
- #quantity_limit_detail_extension ⇒ Object private
- #quantity_limit_extension ⇒ Object private
- #step_therapy_extension ⇒ Object private
- #step_therapy_new_start_extension ⇒ Object private
- #subject ⇒ Object private
- #text ⇒ Object private
Constructor Details
#initialize(plan, plan_drug) ⇒ FormularyItemFactory
Returns a new instance of FormularyItemFactory.
12 13 14 15 |
# File 'lib/formulary/formulary_item_factory.rb', line 12 def initialize(plan, plan_drug) @plan = plan @plan_drug = plan_drug end |
Instance Attribute Details
#plan ⇒ Object (readonly)
Returns the value of attribute plan.
10 11 12 |
# File 'lib/formulary/formulary_item_factory.rb', line 10 def plan @plan end |
#plan_drug ⇒ Object (readonly)
Returns the value of attribute plan_drug.
10 11 12 |
# File 'lib/formulary/formulary_item_factory.rb', line 10 def plan_drug @plan_drug end |
Instance Method Details
#availability_period_extension ⇒ Object (private)
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/formulary/formulary_item_factory.rb', line 97 def availability_period_extension current_year = Date.today.year { url: AVAILABILITY_PERIOD_EXTENSION, valuePeriod: { start: "#{current_year}-01-01", end: "#{current_year}-12-31", }, } end |
#availability_status_extension ⇒ Object (private)
90 91 92 93 94 95 |
# File 'lib/formulary/formulary_item_factory.rb', line 90 def availability_status_extension { url: AVAILABILITY_STATUS_EXTENSION, valueCode: "active", } end |
#build ⇒ Object
Construct a FHIR Basic instance
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/formulary/formulary_item_factory.rb', line 18 def build FHIR::Basic.new( id: FORMULARY_ITEM_ID_PREFIX + plan.id + "-" + plan_drug.rxnorm_code, meta: , text: text, extension: extension, code: code, subject: subject, ) end |
#code ⇒ Object (private)
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/formulary/formulary_item_factory.rb', line 61 def code { coding: [ { system: FORMULARY_ITEM_SYSTEM, code: "formulary-item", display: "Formulary Item", }, ], } end |
#drug_tier_extension ⇒ Object (private)
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/formulary/formulary_item_factory.rb', line 139 def drug_tier_extension { url: DRUG_TIER_ID_EXTENSION, valueCodeableConcept: { coding: [ { code: plan_drug.tier, display: DRUG_TIER_DISPLAY[plan_drug.tier], system: DRUG_TIER_SYSTEM, }, ], }, } end |
#extension ⇒ Object (private)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/formulary/formulary_item_factory.rb', line 45 def extension [ formulary_reference_extension, availability_status_extension, availability_period_extension, pharmacy_type_extensions, drug_tier_extension, prior_auth_extension, prior_auth_new_start_extension, step_therapy_extension, step_therapy_new_start_extension, quantity_limit_extension, quantity_limit_detail_extension, ].flatten.compact end |
#formulary_reference_extension ⇒ Object (private)
80 81 82 83 84 85 86 87 88 |
# File 'lib/formulary/formulary_item_factory.rb', line 80 def formulary_reference_extension { url: FORMULARY_REFERENCE_EXTENSION, valueReference: { reference: "InsurancePlan/" + FORMULARY_ID_PREFIX + plan.id, type: "InsurancePlan", }, } end |
#meta ⇒ Object (private)
31 32 33 34 35 36 |
# File 'lib/formulary/formulary_item_factory.rb', line 31 def { profile: [FORMULARY_ITEM_PROFILE], lastUpdated: "2021-08-31T10:03:10Z", } end |
#pharmacy_type_extension(pharmacy_type) ⇒ Object (private)
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/formulary/formulary_item_factory.rb', line 122 def pharmacy_type_extension(pharmacy_type) return if pharmacy_type.nil? { url: PHARMACY_TYPE_EXTENSION, valueCodeableConcept: { coding: [ { code: pharmacy_type, display: PHARMACY_TYPE_DISPLAY[pharmacy_type], system: PHARMACY_TYPE_SYSTEM, }, ], }, } end |
#pharmacy_type_extensions ⇒ Object (private)
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/formulary/formulary_item_factory.rb', line 108 def pharmacy_type_extensions pharmacy_list = Array.new # Put all pharmacy types into an array plan.tiers.each do |tier| qhp_drug = QHPDrugTier.new(tier) qhp_drug.cost_sharing.each do |cost_sharing| if (pharmacy_list.include?(cost_sharing.pharmacy_type) == false) pharmacy_list.push(cost_sharing.pharmacy_type) end end end pharmacy_list.map { |pharmacy_type| pharmacy_type_extension(pharmacy_type) } end |
#prior_auth_extension ⇒ Object (private)
154 155 156 157 158 159 |
# File 'lib/formulary/formulary_item_factory.rb', line 154 def prior_auth_extension { url: PRIOR_AUTH_EXTENSION, valueBoolean: plan_drug.prior_auth?, } end |
#prior_auth_new_start_extension ⇒ Object (private)
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/formulary/formulary_item_factory.rb', line 161 def prior_auth_new_start_extension if plan_drug.prior_auth? # Compute a number to get a new start only value related to this formulary item compnumber = plan_drug.rxnorm_code.tr("^0-9", "") + plan.id.tr("^0-9", "") #.to_i.digits.sum.to_s while compnumber.length > 1 compnumber = compnumber.to_i.digits.sum.to_s end compnumber = compnumber.to_i % 2 { url: PRIOR_AUTH_NEW_START_EXTENSION, valueBoolean: compnumber.zero?, } end end |
#quantity_limit_detail_extension ⇒ Object (private)
206 207 208 209 210 211 |
# File 'lib/formulary/formulary_item_factory.rb', line 206 def quantity_limit_detail_extension if plan_drug.quantity_limit? ext = QuantityLimitDetailExtensionFactory.new(plan_drug.name) ext.build end end |
#quantity_limit_extension ⇒ Object (private)
199 200 201 202 203 204 |
# File 'lib/formulary/formulary_item_factory.rb', line 199 def quantity_limit_extension { url: QUANTITY_LIMIT_EXTENSION, valueBoolean: plan_drug.quantity_limit?, } end |
#step_therapy_extension ⇒ Object (private)
177 178 179 180 181 182 |
# File 'lib/formulary/formulary_item_factory.rb', line 177 def step_therapy_extension { url: STEP_THERAPY_EXTENSION, valueBoolean: plan_drug.step_therapy_limit?, } end |
#step_therapy_new_start_extension ⇒ Object (private)
184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/formulary/formulary_item_factory.rb', line 184 def step_therapy_new_start_extension if plan_drug.step_therapy_limit? # Compute a number to get a new start only value related to this formulary item compnumber = plan_drug.rxnorm_code.tr("^0-5", "") + plan.id.tr("^0-5", "") #.to_i.digits.sum.to_s while compnumber.length > 1 compnumber = compnumber.to_i.digits.sum.to_s end compnumber = compnumber.to_i % 2 { url: STEP_THERAPY_NEW_START_EXTENSION, valueBoolean: compnumber.zero?, } end end |
#subject ⇒ Object (private)
73 74 75 76 77 78 |
# File 'lib/formulary/formulary_item_factory.rb', line 73 def subject { reference: "MedicationKnowledge/" + DRUG_ID_PREFIX + plan_drug.rxnorm_code, type: "MedicationKnowledge", } end |
#text ⇒ Object (private)
38 39 40 41 42 43 |
# File 'lib/formulary/formulary_item_factory.rb', line 38 def text { status: "generated", div: "<div xmlns=\"http://www.w3.org/1999/xhtml\">Formulary Item for Plan: #{plan.id}; RxNorm: #{plan_drug.rxnorm_code}</div>", } end |