-
Notifications
You must be signed in to change notification settings - Fork 0
/
ped-med.js
108 lines (89 loc) · 2.35 KB
/
ped-med.js
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
import data from './config.js'
export class PedMed extends HTMLElement {
static get observedAttributes() {
return ['med', 'schema', 'result']
}
get med() {
return this.getAttribute('med')
}
set med(val) {
this.setAttribute('med', val)
}
get schema() {
return this.getAttribute('schema')
}
set schema(val) {
this.setAttribute('schema', val)
}
get result() {
return this.getAttribute('result')
}
set result(val) {
this.setAttribute('result', val)
}
constructor() {
super()
this.meds = data.meds
this.med = 0
this.schema = 0
this.dosage = data.meds[0].schema[0].dosage
this.shadow = this.attachShadow({mode: 'open'})
.innerHTML = `
<p>
<input
class="input"
type="number"
inputmode="decimal"
placeholder="Gewicht">
</p>
<p>
<select class="med-selector">
${this.meds.map(function(key, index){
return "<option value='" + index +"'>" + key.name + "</option>"
})}
</select>
</p>
<p>
<select class="schema-selector">
${this.meds[this.med].schema.map(function(key, index){
return "<option value='" + index +"'>" + key.name + "</option>"
})}
</select>
</p>
<p>
<input class="output" type="text" placeholder="Dosis" readonly>
</p>`
this.input = this.shadowRoot.querySelector('.input')
this.medSelector = this.shadowRoot.querySelector('.med-selector')
this.schemaSelector = this.shadowRoot.querySelector('.schema-selector')
this.output = this.shadowRoot.querySelector('.output')
}
connectedCallback() {
this.input.addEventListener('input', e => {
this.calc()
})
this.medSelector.addEventListener('change', e => {
this.selectMed()
this.calc()
})
this.schemaSelector.addEventListener('change', e => {
this.selectSchema()
this.calc()
})
}
attributeChangedCallback(name, oldVal, newVal) {
this.output.value = this.result
}
selectMed() {
this.med = this.medSelector.value
}
selectSchema() {
this.schema = this.schemaSelector.value
}
calc() {
let med = this.meds[this.med]
let schema = med.schema[this.schema]
let weight = this.input.value
this.result = schema.dosage(weight)
}
}