forked from ifmeorg/ifme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
medications_helper.rb
78 lines (68 loc) · 1.97 KB
/
medications_helper.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
# frozen_string_literal: true
module MedicationsHelper
include DateTimeHelper
def present_medication(medication)
{
name: medication.name,
link: medication_path(medication),
actions: {
edit: edit_action(medication),
delete: delete_action(medication)
},
medicationBody: medication_body(medication)
}
end
private
def edit_action(medication)
{
name: t('common.actions.edit'),
link: edit_medication_path(medication)
}
end
def delete_action(medication)
{
name: t('common.actions.delete'),
link: medication_path(medication),
dataConfirm: t('common.actions.confirm'),
dataMethod: 'delete'
}
end
def medication_body(medication)
{
medicationStrength: medication_strength(medication),
quantity: t('medications.quantity'),
medicationDosages: medication_dosages(medication),
refill: t('medications.refill'),
medicationRefill: format_date(medication.refill)
}.merge(medication_units(medication))
end
def medication_units(medication)
{
totalUnits: t('medications.units.display',
count: medication.total,
unit: medication.total_unit),
dosageUnit: t('medications.units.display',
count: medication.dosage,
unit: medication.dosage_unit)
}
end
def medication_strength(medication)
{
strength: t('medications.strength'),
strengthUnits: t('medications.units.display',
count: medication.strength,
unit: medication.strength_unit)
}
end
def medication_dosages(medication)
{
isDaily: medication.daily?,
dosageDaily: t('medications.dosage'),
dosageWeekly: t('medications.weekly_dosage'),
weeklyDosageMap: weekly_dosage(medication)
}
end
def weekly_dosage(medication)
medication.weekly_dosage.map { |i| t(:'date.abbr_day_names')[i] }.join(', ')
end
end