-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrain.html
More file actions
552 lines (476 loc) · 17.3 KB
/
Brain.html
File metadata and controls
552 lines (476 loc) · 17.3 KB
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Brain</title>
<style>
:root {
--bg-color: #ffffff;
--border-color: #000000;
--text-color: #000000;
--font-family: "Lucida Grande", -apple-system, sans-serif;
--header-bg: #ececec;
}
@media (prefers-color-scheme: dark) {
:root {
--bg-color: #1a1a2e;
--border-color: #4a4a6a;
--text-color: #e8e8f0;
--header-bg: #16213e;
}
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: var(--font-family);
background-color: var(--bg-color);
color: var(--text-color);
line-height: 1.2;
display: flex;
flex-direction: column;
min-height: 100vh;
}
/* Top Menu Bar */
.menubar {
display: flex;
background-color: var(--header-bg);
border-bottom: 1px solid var(--border-color);
padding: 0 10px;
gap: 15px;
align-items: center;
height: 40px;
flex-shrink: 0;
}
.menu-btn {
background: none;
border: none;
color: var(--text-color);
cursor: pointer;
font-size: 14px;
padding: 5px 10px;
border-radius: 4px;
}
.menu-btn:hover {
background-color: rgba(128, 128, 128, 0.2);
}
/* Main Content Area */
.container {
flex: 1;
padding: 10px;
display: grid;
gap: 15px;
margin: 0 auto;
width: 100%;
max-width: 1400px;
/* Allow it to grow naturally instead of forcing exact vh */
}
/* Layout States matching Brain.java */
.layout-center {
grid-template-columns: 1fr;
max-width: 900px;
}
.layout-split {
grid-template-columns: 1fr 1fr;
align-items: start;
}
/* Patient Box (The "Rectangles") */
.patient-panel {
border: 1px solid var(--border-color);
display: grid;
grid-template-columns: repeat(12, 1fr);
gap: 1px;
background-color: var(--border-color);
/* Let the panel size itself to its contents */
height: max-content;
}
/* Individual text boxes */
.text-box {
background-color: var(--bg-color);
display: flex;
flex-direction: column;
padding: 2px 4px;
position: relative;
}
.text-box label {
font-size: 10px;
font-weight: bold;
color: #555;
position: absolute;
top: 2px;
left: 4px;
pointer-events: none;
}
@media (prefers-color-scheme: dark) {
.text-box label {
color: #aaa;
}
}
.text-box textarea {
width: 100%;
height: 100%;
border: none;
resize: none;
font-family: "Lucida Grande", sans-serif;
color: var(--text-color);
background: transparent;
outline: none;
/* Padding to avoid the label */
padding-top: 14px;
line-height: 1.1;
}
/* Dynamic Font Sizes matching Brain.java */
.layout-center .text-box textarea {
font-size: 14px;
}
.layout-split .text-box textarea {
font-size: 12px;
}
/* Box Positioning mapped exactly to 12 columns */
/* ROW 1: 2 + 5 + 1 + 1 + 3 = 12 */
.box-room {
grid-column: span 2;
}
.box-name {
grid-column: span 5;
}
.box-gender {
grid-column: span 1;
}
.box-age {
grid-column: span 1;
}
.box-code {
grid-column: span 3;
}
/* ROW 2: 3 + 3 + 3 + 3 = 12 */
.box-trach {
grid-column: span 3;
}
.box-day {
grid-column: span 3;
}
.box-noc {
grid-column: span 3;
}
.box-tx {
grid-column: span 3;
}
/* ROW 3: 12 */
.box-hx {
grid-column: span 12;
min-height: 40px;
/* Give HX some room */
}
/* ROW 4: 12 */
.box-notes {
grid-column: span 12;
min-height: 60px;
/* Give Notes space */
}
/* Template Selector Overlay */
#template-selector {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: var(--bg-color);
display: none;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(2, 1fr);
z-index: 100;
}
.template-btn {
background-color: #ffb6c1;
/* light pink */
color: #000000;
border: 1px solid #fff;
font-size: 25px;
cursor: pointer;
}
.template-btn:hover {
background-color: #ff9eac;
}
.template-btn.active {
border: 4px solid #fff;
box-shadow: inset 0 0 0 4px #aaa;
}
/* PRINT STYLES - Strict 1 page Landscape */
@media print {
@page {
size: letter landscape;
margin: 0.15in;
}
body {
background: #fff !important;
color: #000 !important;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
height: 100vh !important;
overflow: hidden !important;
}
.menubar {
display: none !important;
}
.container {
padding: 0 !important;
margin: 0 !important;
gap: 5px !important;
height: auto !important;
max-width: none !important;
/* No grid-auto-rows hack. Let explicit panel heights govern 6 rows. */
}
.patient-panel {
border-color: #000 !important;
background-color: #000 !important;
page-break-inside: avoid !important;
/* Reduced height by another 2% to perfect the 1-page fit */
height: 1.42in !important;
/* Grid cleanly subdivides the height without overlapping */
grid-template-rows: 1fr 1fr 1.5fr 2fr !important;
}
.text-box {
background-color: #fff !important;
/* Remove all possible padding for maximum space */
padding: 0 1px !important;
/* Ensure textboxes stretch in the grid rows */
height: 100% !important;
}
.text-box textarea {
color: #000 !important;
overflow: hidden !important;
font-size: 10px !important;
padding-top: 11px !important;
/* Just enough for label */
line-height: 1 !important;
min-height: 0 !important;
}
.text-box label {
color: #000 !important;
font-size: 8px !important;
top: 0 !important;
left: 1px !important;
}
/* Override the screen min-heights that blow out the page */
.box-hx {
min-height: 14px !important;
}
.box-notes {
min-height: 14px !important;
}
/* Hide empty space strictly */
html,
body {
border: 0 !important;
margin: 0 !important;
padding: 0 !important;
}
}
</style>
</head>
<body>
<div class="menubar">
<button class="menu-btn" onclick="toggleTemplateSelector()" id="homeBtn">Brain 1</button>
<button class="menu-btn" onclick="window.print()">Print</button>
<button class="menu-btn" onclick="addPatient()">Add</button>
<button class="menu-btn" onclick="removePatient()">Remove</button>
<button class="menu-btn" onclick="clearTemplate()">Clear</button>
<span id="patientCount" style="color:gray; font-size:12px; margin-left:10px;"></span>
<div style="margin-left:auto; display:flex; gap:10px;">
<span id="statusText" style="font-size:12px; color:gray; line-height:30px;"></span>
<button class="menu-btn" onclick="exportBackup()">Export Backup</button>
<button class="menu-btn" onclick="document.getElementById('fileInput').click()">Import Backup</button>
<input type="file" id="fileInput" accept=".json" style="display: none" onchange="importBackup(event)">
</div>
</div>
<div class="container" id="main-container">
<!-- Patient panels generated here -->
</div>
<div id="template-selector">
<button class="template-btn" onclick="selectTemplate(1)">Brain 1</button>
<button class="template-btn" onclick="selectTemplate(2)">Brain 2</button>
<button class="template-btn" onclick="selectTemplate(3)">Brain 3</button>
<button class="template-btn" onclick="selectTemplate(4)">Brain 4</button>
<button class="template-btn" onclick="selectTemplate(5)">Brain 5</button>
<button class="template-btn" onclick="selectTemplate(6)">Brain 6</button>
</div>
<script>
const STORAGE_KEY = 'Brain_Data_V2';
let currentTemplate = 1;
let brainData = loadData();
function loadData() {
try {
const data = localStorage.getItem(STORAGE_KEY);
return data ? JSON.parse(data) : {};
} catch (e) {
return {};
}
}
function saveData() {
localStorage.setItem(STORAGE_KEY, JSON.stringify(brainData));
const status = document.getElementById('statusText');
status.textContent = 'Saved.';
setTimeout(() => status.textContent = '', 2000);
}
// Initialize template
function getTemplateData(id) {
if (!brainData[id]) {
brainData[id] = { patients: [] };
// Start with 4 patients on fresh load (simulating common use case)
for (let i = 0; i < 4; i++) {
brainData[id].patients.push(createEmptyPatient());
}
saveData();
}
return brainData[id];
}
function createEmptyPatient() {
return {
room: '', name: '', gender: '', age: '', code: '',
trach: '', day: '', noc: '', tx: '', hx: '', notes: ''
};
}
const FIELDS = [
{ id: 'room', class: 'box-room', label: 'Room' },
{ id: 'name', class: 'box-name', label: 'Name' },
{ id: 'gender', class: 'box-gender', label: 'M/F' },
{ id: 'age', class: 'box-age', label: 'Age' },
{ id: 'code', class: 'box-code', label: 'Code' },
{ id: 'trach', class: 'box-trach', label: 'Trach' },
{ id: 'day', class: 'box-day', label: 'Day' },
{ id: 'noc', class: 'box-noc', label: 'NOC' },
{ id: 'tx', class: 'box-tx', label: 'TX' },
{ id: 'hx', class: 'box-hx', label: 'HX' },
{ id: 'notes', class: 'box-notes', label: 'Notes' }
];
function render() {
const container = document.getElementById('main-container');
const data = getTemplateData(currentTemplate);
// Match Brain.java layout logic limits
// If < 6 patients -> centerSetup (1 column)
// If 6-12 patients -> leftRightSetup (2 columns)
if (data.patients.length < 6) {
container.className = 'container layout-center';
} else {
container.className = 'container layout-split';
}
// Update UI Counters
document.getElementById('homeBtn').textContent = `Brain ${currentTemplate} ▾`;
document.getElementById('patientCount').textContent = `${data.patients.length} patient(s)`;
container.innerHTML = '';
data.patients.forEach((patient, index) => {
const panel = document.createElement('div');
panel.className = 'patient-panel';
FIELDS.forEach(field => {
const box = document.createElement('div');
box.className = `text-box ${field.class}`;
const label = document.createElement('label');
label.textContent = field.label + ':';
const textarea = document.createElement('textarea');
textarea.value = patient[field.id];
// Prevent tabbing out of layout issues
textarea.setAttribute('spellcheck', 'false');
// Auto-save on type
textarea.addEventListener('input', (e) => {
patient[field.id] = e.target.value;
saveData();
});
box.appendChild(label);
box.appendChild(textarea);
panel.appendChild(box);
});
container.appendChild(panel);
});
}
// Actions
function addPatient() {
const data = getTemplateData(currentTemplate);
if (data.patients.length < 12) { // Max 12 patients per template to match 1-page limits
data.patients.push(createEmptyPatient());
saveData();
render();
} else {
alert("Maximum 12 patients per Brain to maintain print formatting.");
}
}
function removePatient() {
const data = getTemplateData(currentTemplate);
if (data.patients.length > 0) {
data.patients.pop(); // Removes the last patient
saveData();
render();
}
}
function clearTemplate() {
const data = getTemplateData(currentTemplate);
if (data.patients.length === 0) return;
if (confirm(`Clear all ${data.patients.length} patients from Brain ${currentTemplate}?`)) {
brainData[currentTemplate] = { patients: [] };
// Reset to 1 empty patient to preserve grid
brainData[currentTemplate].patients.push(createEmptyPatient());
saveData();
render();
}
}
// Template Selection
function toggleTemplateSelector() {
const selector = document.getElementById('template-selector');
if (selector.style.display === 'grid') {
selector.style.display = 'none';
} else {
selector.style.display = 'grid';
document.querySelectorAll('.template-btn').forEach((btn, idx) => {
btn.className = `template-btn ${idx + 1 === currentTemplate ? 'active' : ''}`;
});
}
}
function selectTemplate(id) {
currentTemplate = id;
document.getElementById('template-selector').style.display = 'none';
render();
}
// Backup
function exportBackup() {
const blob = new Blob([JSON.stringify(brainData, null, 2)], { type: 'application/json' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = `brain-backup-${new Date().toISOString().slice(0, 10)}.json`;
link.click();
}
function importBackup(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = (e) => {
try {
const parsed = JSON.parse(e.target.result);
if (confirm('Importing will overwrite current data. Continue?')) {
brainData = parsed;
saveData();
render();
document.getElementById('statusText').textContent = 'Imported.';
}
} catch (err) {
alert('Invalid backup file.');
}
};
reader.readAsText(file);
// Reset input so re-importing the same file works
event.target.value = '';
}
// Init
document.addEventListener('keydown', (e) => {
if ((e.metaKey || e.ctrlKey) && e.key === 's') {
e.preventDefault();
saveData(); // Auto-saves anyway, but respects habit
}
});
// First render
render();
</script>
</body>
</html>