-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdonut_algo.rb
187 lines (144 loc) · 10.6 KB
/
donut_algo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
require 'pokitdok'
# medication_array = ['metoprolol', 'lisinopril', 'metformin', 'simvastatin', 'tamsulosin', 'alendronate', 'levothyroxine', 'sertraline', 'hydrochlorothiazide']
# pd = PokitDok::PokitDok.new("RrslJ6itUf2akQHs1Zal", "NdHPmIQXiBGGTwRGYqh1qsKuDGVbgyQlqSzc4q5n")
$pokitdok_call = [{"drug"=>"MEMANTINE HCL 10 MG TABLET", "tier"=>3, "tier_name"=>"preferred brand", "prior_auth"=>true, "limit_amount"=>"60", "step_therapy"=>false, "quantity_limit"=>true, "limit_days"=>30, "retail"=>{"oop_30_day"=>{"amount"=>"35.00", "currency"=>"USD"}, "total_cost_30_day"=>{"amount"=>"46.71", "currency"=>"USD"}, "ins_pay_30_day"=>{"amount"=>"11.71", "currency"=>"USD"}}, "mail"=>{"oop_90_day"=>{"amount"=>"90.00", "currency"=>"USD"}, "total_cost_90_day"=>{"amount"=>"135.39", "currency"=>"USD"}, "ins_pay_90_day"=>{"amount"=>"45.39", "currency"=>"USD"}}}, {"drug"=>"TAMSULOSIN HCL 0.4 MG CAPSULE", "tier"=>2, "tier_name"=>"generic", "prior_auth"=>false, "step_therapy"=>false, "quantity_limit"=>false, "retail"=>{"oop_30_day"=>{"amount"=>"8.00", "currency"=>"USD"}, "total_cost_30_day"=>{"amount"=>"12.44", "currency"=>"USD"}, "ins_pay_30_day"=>{"amount"=>"4.44", "currency"=>"USD"}}, "mail"=>{"oop_90_day"=>{"amount"=>"0.00", "currency"=>"USD"}, "total_cost_90_day"=>{"amount"=>"33.84", "currency"=>"USD"}, "ins_pay_90_day"=>{"amount"=>"33.84", "currency"=>"USD"}}}, {"drug"=>"METOPROLOL TARTRATE 50 MG TAB", "tier"=>1, "tier_name"=>"preferred generic", "prior_auth"=>false, "step_therapy"=>false, "quantity_limit"=>false, "retail"=>{"oop_30_day"=>{"amount"=>"4.00", "currency"=>"USD"}, "total_cost_30_day"=>{"amount"=>"6.85", "currency"=>"USD"}, "ins_pay_30_day"=>{"amount"=>"2.85", "currency"=>"USD"}}, "mail"=>{"oop_90_day"=>{"amount"=>"0.00", "currency"=>"USD"}, "total_cost_90_day"=>{"amount"=>"19.01", "currency"=>"USD"}, "ins_pay_90_day"=>{"amount"=>"19.01", "currency"=>"USD"}}}, {"drug"=>"LISINOPRIL 30 MG TABLET", "tier"=>1, "tier_name"=>"preferred generic", "prior_auth"=>false, "limit_amount"=>"60", "step_therapy"=>false, "quantity_limit"=>true, "limit_days"=>30, "retail"=>{"oop_30_day"=>{"amount"=>"4.00", "currency"=>"USD"}, "total_cost_30_day"=>{"amount"=>"5.91", "currency"=>"USD"}, "ins_pay_30_day"=>{"amount"=>"1.91", "currency"=>"USD"}}, "mail"=>{"oop_90_day"=>{"amount"=>"0.00", "currency"=>"USD"}, "total_cost_90_day"=>{"amount"=>"16.15", "currency"=>"USD"}, "ins_pay_90_day"=>{"amount"=>"16.15", "currency"=>"USD"}}}, {"drug"=>"METFORMIN HCL 1,000 MG TABLET", "tier"=>1, "tier_name"=>"preferred generic", "prior_auth"=>false, "limit_amount"=>"75", "step_therapy"=>false, "quantity_limit"=>true, "limit_days"=>30, "retail"=>{"oop_30_day"=>{"amount"=>"4.00", "currency"=>"USD"}, "total_cost_30_day"=>{"amount"=>"6.52", "currency"=>"USD"}, "ins_pay_30_day"=>{"amount"=>"2.52", "currency"=>"USD"}}, "mail"=>{"oop_90_day"=>{"amount"=>"0.00", "currency"=>"USD"}, "total_cost_90_day"=>{"amount"=>"18.04", "currency"=>"USD"}, "ins_pay_90_day"=>{"amount"=>"18.04", "currency"=>"USD"}}}, {"drug"=>"SIMVASTATIN 80 MG TABLET", "tier"=>1, "tier_name"=>"preferred generic", "prior_auth"=>false, "limit_amount"=>"30", "step_therapy"=>false, "quantity_limit"=>true, "limit_days"=>30, "retail"=>{"oop_30_day"=>{"amount"=>"4.00", "currency"=>"USD"}, "total_cost_30_day"=>{"amount"=>"6.68", "currency"=>"USD"}, "ins_pay_30_day"=>{"amount"=>"2.68", "currency"=>"USD"}}, "mail"=>{"oop_90_day"=>{"amount"=>"0.00", "currency"=>"USD"}, "total_cost_90_day"=>{"amount"=>"18.60", "currency"=>"USD"}, "ins_pay_90_day"=>{"amount"=>"18.60", "currency"=>"USD"}}}, {"drug"=>"TAMSULOSIN HCL 0.4 MG CAPSULE", "tier"=>2, "tier_name"=>"generic", "prior_auth"=>false, "step_therapy"=>false, "quantity_limit"=>false, "retail"=>{"oop_30_day"=>{"amount"=>"8.00", "currency"=>"USD"}, "total_cost_30_day"=>{"amount"=>"12.44", "currency"=>"USD"}, "ins_pay_30_day"=>{"amount"=>"4.44", "currency"=>"USD"}}, "mail"=>{"oop_90_day"=>{"amount"=>"0.00", "currency"=>"USD"}, "total_cost_90_day"=>{"amount"=>"33.84", "currency"=>"USD"}, "ins_pay_90_day"=>{"amount"=>"33.84", "currency"=>"USD"}}}, {"drug"=>"ALENDRONATE SODIUM 5 MG TABLET", "tier"=>1, "tier_name"=>"preferred generic", "prior_auth"=>false, "limit_amount"=>"30", "step_therapy"=>false, "quantity_limit"=>true, "limit_days"=>30, "retail"=>{"oop_30_day"=>{"amount"=>"4.00", "currency"=>"USD"}, "total_cost_30_day"=>{"amount"=>"7.50", "currency"=>"USD"}, "ins_pay_30_day"=>{"amount"=>"3.50", "currency"=>"USD"}}, "mail"=>{"oop_90_day"=>{"amount"=>"0.00", "currency"=>"USD"}, "total_cost_90_day"=>{"amount"=>"20.54", "currency"=>"USD"}, "ins_pay_90_day"=>{"amount"=>"20.54", "currency"=>"USD"}}}, {"drug"=>"LEVOTHYROXINE 100 MCG VIAL", "tier"=>5, "tier_name"=>"specialty tier", "prior_auth"=>false, "step_therapy"=>false, "quantity_limit"=>false, "retail"=>{"oop_30_day"=>{"amount"=>"24.67", "currency"=>"USD"}, "total_cost_30_day"=>{"amount"=>"74.76", "currency"=>"USD"}, "ins_pay_30_day"=>{"amount"=>"50.09", "currency"=>"USD"}}, "mail"=>{"oop_90_day"=>{"amount"=>"73.45", "currency"=>"USD"}, "total_cost_90_day"=>{"amount"=>"222.57", "currency"=>"USD"}, "ins_pay_90_day"=>{"amount"=>"149.12", "currency"=>"USD"}}}, {"drug"=>"SERTRALINE HCL 25 MG TABLET", "tier"=>1, "tier_name"=>"preferred generic", "prior_auth"=>false, "step_therapy"=>false, "quantity_limit"=>false, "retail"=>{"oop_30_day"=>{"amount"=>"4.00", "currency"=>"USD"}, "total_cost_30_day"=>{"amount"=>"6.20", "currency"=>"USD"}, "ins_pay_30_day"=>{"amount"=>"2.20", "currency"=>"USD"}}, "mail"=>{"oop_90_day"=>{"amount"=>"0.00", "currency"=>"USD"}, "total_cost_90_day"=>{"amount"=>"16.82", "currency"=>"USD"}, "ins_pay_90_day"=>{"amount"=>"16.82", "currency"=>"USD"}}}, {"drug"=>"HYDROCHLOROTHIAZIDE 12.5 MG TB", "tier"=>1, "tier_name"=>"preferred generic", "prior_auth"=>false, "step_therapy"=>false, "quantity_limit"=>false, "retail"=>{"oop_30_day"=>{"amount"=>"4.00", "currency"=>"USD"}, "total_cost_30_day"=>{"amount"=>"6.03", "currency"=>"USD"}, "ins_pay_30_day"=>{"amount"=>"2.03", "currency"=>"USD"}}, "mail"=>{"oop_90_day"=>{"amount"=>"0.00", "currency"=>"USD"}, "total_cost_90_day"=>{"amount"=>"16.37", "currency"=>"USD"}, "ins_pay_90_day"=>{"amount"=>"16.37", "currency"=>"USD"}}}]
$total_cost = []
$pt_costs_monthy_no_dh = []
$pt_costs_monthy_during_dh = []
$costs_toward_dh = []
pt_costs_monthy_after_dh = []
#calling pokitdok api for each med in array
# medication_array.each do |medication|
# test = pd.pharmacy_formulary(trading_partner_id: 'medicare_national', plan_number: 'S5820003', drug: medication)
# $pokitdok_call << test['data'][0]
# end
#grand total drug(what patient pays and insurance so the total rx cost)
def get_grand_total_one_month
$pokitdok_call.each do |drug|
$total_cost << drug['retail']['total_cost_30_day']['amount'].to_f
end
sum_total_cost = $total_cost.inject(:+)
end
def is_in_donut_hole_this_year?
get_grand_total_one_month * 12 > 3310
end
def months_not_in_dh
$total_cost = []
i = 1
while i <= 12
if get_grand_total_one_month * i >= 3310
return i
break
end
i += 1
end
return 12
end
#does not include dispensing fee? does not factor deductable
def patient_monthly_costs_before_dh
$pt_costs_monthy_no_dh = []
$pokitdok_call.each do |drug|
$pt_costs_monthy_no_dh << drug['retail']['oop_30_day']['amount'].to_f
end
$pt_costs_monthy_no_dh.inject(:+).round(2)
end
#does not include dispensing fee?
def patient_monthly_costs_during_dh
$pt_costs_monthy_during_dh = []
$pokitdok_call.each do |drug|
#Patient pays no more than 45% of ⇒ plan’s cost for covered brand-name prescription drugs + pharmacy’s dispensing fee
if drug['tier'] == 1
$pt_costs_monthy_during_dh << (drug['retail']['total_cost_30_day']['amount'].to_f * 0.58)
#patient pays 58% of cost, 58% of cost goes toward geting out of donut hole
elsif drug['tier'] == 2
$pt_costs_monthy_during_dh << (drug['retail']['total_cost_30_day']['amount'].to_f * 0.45)
elsif drug['tier'] == 3
$pt_costs_monthy_during_dh << (drug['retail']['total_cost_30_day']['amount'].to_f * 0.45)
else
$pt_costs_monthy_during_dh << drug['retail']['total_cost_30_day']['amount'].to_f
end
end
$pt_costs_monthy_during_dh.inject(:+).round(2)
end
#different than patient costs because only includes tier 1 and 2
def monthly_costs_toward_getting_out_dh
$costs_toward_dh = []
$pokitdok_call.each do |drug|
#Patient pays no more than 45% of ⇒ plan’s cost for covered brand-name prescription drugs + pharmacy’s dispensing fee
if drug['tier'] == 1
$costs_toward_dh << drug['retail']['total_cost_30_day']['amount'].to_f * 0.58
#patient pays 58% of cost, 58% of cost goes toward geting out of donut hole
elsif drug['tier'] == 2
$costs_toward_dh << drug['retail']['total_cost_30_day']['amount'].to_f * 0.45
elsif drug['tier'] == 3
$costs_toward_dh << drug['retail']['total_cost_30_day']['amount'].to_f * 0.45
end
end
$costs_toward_dh.inject(:+).round(2)
end
def months_in_dh
i = 1
while i <= 12
if monthly_costs_toward_getting_out_dh * i >= 1540
return i
break
end
i += 1
end
return 12 - months_not_in_dh
end
def patient_monthly_costs_after_dh
$pt_costs_monthy_after_dh = []
$pokitdok_call.each do |drug|
#Patient pays no more than 45% of ⇒ plan’s cost for covered brand-name prescription drugs + pharmacy’s dispensing fee
if drug['tier'] == 1
$pt_costs_monthy_after_dh << 2.65
#patient pays 58% of cost, 58% of cost goes toward geting out of donut hole
elsif drug['tier'] == 2
$pt_costs_monthy_after_dh << 2.65
elsif drug['tier'] == 3
$pt_costs_monthy_after_dh << 2.65
else
$pt_costs_monthy_during_dh << 6.60
end
end
$pt_costs_monthy_after_dh.inject(:+).round(2)
end
def graph_output
output_hash = {}
if is_in_donut_hole_this_year?
months_not_in_dh.times do |i|
output_hash[i + 1] = { cost: patient_monthly_costs_before_dh,in_dh: false}
end
months_in_dh.times do |i|
output_hash[i + 1 + months_not_in_dh] = { cost: patient_monthly_costs_during_dh, in_dh: true }
end
(12 - (months_in_dh + months_not_in_dh)).times do |i|
output_hash[i + 1 + months_in_dh + months_not_in_dh] = { cost: patient_monthly_costs_after_dh, in_dh: false }
end
else
12.times do |i|
output_hash[i + 1] = { cost: patient_monthly_costs_before_dh,in_dh: false}
end
end
output_hash
end
p graph_output
# p $pokitdok_call
# p get_grand_total_one_month
# p is_in_donut_hole_this_year?
# p months_not_in_dh
# p patient_monthly_costs_before_dh
# p patient_monthly_costs_during_dh
# p monthly_costs_toward_getting_out_dh
# p months_in_dh
# p patient_monthly_costs_after_dh
# plans = pd.pharmacy_plans(trading_partner_id:'medicare_national', plan_number:'S5820003')
# Retrieve provider information by NPI
# test = pd.providers(npi: '1467560003')
# test.each do |el|
# puts el
# end
# plans.each do |plan|
# ap plan
# end