-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
252 lines (214 loc) · 8.57 KB
/
index.html
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>RCPCH ROP Window Calculator</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap" rel="stylesheet">
<style>
body {
font-family: "Montserrat", sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 1em;
}
form {
display: flex;
flex-direction: column;
}
label {
margin-bottom: 0.5em;
}
input {
margin-bottom: 0.8em;
font-size: 1.4em;
}
input:invalid {
border: 3px solid red;
}
.output {
display: none;
border-top: 1px solid silver;
padding: 1em 0;
}
h2 {
margin: 0;
padding: 0;
}
.screening-window {
display: grid;
grid-template-columns: 1fr 4fr;
column-gap: 1em;
row-gap: 0.5em;
font-size: 1.4em;
}
.screening-window__label {
display: flex;
flex-direction: column;
justify-content: center;
}
.screening-window__label__text {
background-color: rgb(51, 102, 204);
color: white;
font-weight: bold;
padding: 0.2em;
text-align: center;
}
.screening-window__value {
font-size: 1.4em;
}
.screening-window__description {
font-size: 0.8em;
color: gray;
}
</style>
</head>
<body>
<form>
<label for="gestational_age_weeks">
Gestational age (weeks) [22-42]:
</label>
<input
id="gestational_age_weeks"
type="number"
required
min="22"
max="42"
value="34"
/>
<label for="gestational_age_days">
Gestational age (days) [0-6]:
</label>
<input
id="gestational_age_days"
type="number"
required
min="0"
max="6"
value="3"
/>
<label for="birth_weight">
Birth weight (grams):
</label>
<input
id="birth_weight"
type="number"
value="1151"
required
min="0"
/>
<label for="date_of_birth">
Date of birth:
</label>
<input
id="date_of_birth"
type="date"
required
value="2023-01-01"
/>
</form>
<div id="not-eligible" class="output">
<h2>Not Eligible</h2>
<p>
All infants less than 31 weeks gestational age (up to and including 30 weeks
and 6 days) OR less than 1501g birth weight should be examined to screen for
the presence of ROP (one criterion to be met for inclusion) [Evidence level: High
(Grade: B)]
</p>
</div>
<div id="screening-window" class="output">
<div class="screening-window">
<div class="screening-window__label">
<span class="screening-window__label__text">
Start
</span>
</div>
<div id="window_start">
<div id="window_start_date" class="screening-window__value">
</div>
<div id="window_start_days" class="screening-window__description">
</div>
</div>
<div class="screening-window__label">
<span class="screening-window__label__text">
End
</span>
</div>
<div id="window_end">
<div id="window_end_date" class="screening-window__value">
</div>
<div id="window_end_days" class="screening-window__description">
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/global/luxon.min.js"></script>
<script type="text/javascript">
const form = document.querySelector("form");
const notEligiblePanel = document.getElementById("not-eligible");
const screeningWindowPanel = document.getElementById("screening-window");
const windowStartDate = document.getElementById("window_start_date");
const windowStartDays = document.getElementById("window_start_days");
const windowEndDate = document.getElementById("window_end_date");
const windowEndDays = document.getElementById("window_end_days");
function getIntValue(id) {
return parseInt(document.getElementById(id).value, 10);
}
function isEligible(gestationalAge, birthWeight) {
const thirtyWeeksAndSixDays = (30 * 7) + 6;
return gestationalAge <= thirtyWeeksAndSixDays || birthWeight < 1501;
}
function calculateWindow(gestationalAgeDays, dateOfBirth) {
const thirtyOneWeeks = 31 * 7;
const postNatalStart = dateOfBirth.plus({ days: 28 });
let start;
// For infants born before 31+0 weeks gestational age
if(gestationalAgeDays < thirtyOneWeeks) {
// the first ROP examination should be performed between 31+0 and 31+6 weeks postmenstrual age
// or at 4 completed weeks postnatal age (28–34 days), whichever is later
const postMenstrualStart = dateOfBirth.minus({ days: gestationalAgeDays }).plus({ weeks: 31 });
console.log({ postMenstrualStart: postMenstrualStart.toISO(), postNatalStart: postNatalStart.toISO() });
start = postMenstrualStart > postNatalStart ? postMenstrualStart : postNatalStart;
} else {
// the first ROP examination should be performed at 36 weeks postmenstrual age or 4 completed
// weeks postnatal age (28–34 days), whichever is sooner
const postMenstrualStart = dateOfBirth.minus({ days: gestationalAgeDays }).plus({ weeks: 36 });
start = postMenstrualStart < postNatalStart ? postMenstrualStart : postNatalStart;
}
if(start < dateOfBirth) {
start = dateOfBirth;
}
const end = start.plus({ days: 6 });
return { start, end };
}
function updateOutput() {
notEligiblePanel.style.display = 'none';
screeningWindowPanel.style.display = 'none';
if(form.checkValidity()) {
const gestationalAgeWeeks = getIntValue("gestational_age_weeks");
const gestationalAgeDays = getIntValue("gestational_age_days");
const birthWeight = getIntValue("birth_weight");
const dateOfBirth = luxon.DateTime.fromISO(document.getElementById("date_of_birth").value);
// Useful page covering definitions: https://embryology.med.unsw.edu.au/embryology/index.php?title=Gestational_Age#Perinatal_Period
const gestationalAge = (gestationalAgeWeeks * 7) + gestationalAgeDays;
if(isEligible(gestationalAge, birthWeight)) {
screeningWindowPanel.style.display = 'block';
const { start, end } = calculateWindow(gestationalAge, dateOfBirth);
// DATE_SHORT means US users see MM/DD/YYYY and UK users see DD/MM/YYYY
const startDate = start.toLocaleString(luxon.DateTime.DATE_SHORT);
const startDaysFromBirth = start.diff(dateOfBirth, 'days').days;
const endDate = end.toLocaleString(luxon.DateTime.DATE_SHORT);
const endDaysFromBirth = end.diff(dateOfBirth, 'days').days;
windowStartDate.innerHTML = startDate;
windowStartDays.innerHTML = `${startDaysFromBirth} days from birth`;
windowEndDate.innerHTML = endDate;
windowEndDays.innerHTML = `${endDaysFromBirth} days from birth`;
} else {
notEligiblePanel.style.display = 'block';
}
}
}
form.addEventListener("input", updateOutput);
document.addEventListener("DOMContentLoaded", updateOutput);
</script>
</body>