-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdr-patient-view-controler.js
More file actions
78 lines (66 loc) · 2.23 KB
/
dr-patient-view-controler.js
File metadata and controls
78 lines (66 loc) · 2.23 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
import { stateGetApp } from "./common-lib.js";
import { drPatientLib } from "./dr-patient-view-lib.js";
import { exportXLSFile } from './exporToXLS.js';
/**
* Based on
* - drApiConnecion
* - patientApiConnection
* - questionaryId
*
* Display live update of data
*/
let invite;
window.onload = async (event) => {
await HDSLib.initHDSModel();
// get collectorId & inviteKey from URL
const params = new URLSearchParams(document.location.search);
const collectorId = params.get('collectorId');
const inviteKey = params.get('inviteKey');
// get app from state management
const appManaging = await stateGetApp('managing');
const collector = await appManaging.getCollectorById(collectorId);
invite = await collector.getInviteByKey(inviteKey);
console.log('# Loaded with invite', invite);
await drPatientLib.setRefresh(invite, refresh)
// -- home button
document.getElementById('home-button').href= 'dr.html?collectorId=' + collectorId;
// - form title
const formTitle = document.getElementById('card-questionnary-details-title');
formTitle.innerHTML = collector.name;
document.getElementById('patient-label').innerHTML = invite.displayName;
}
const tableHeaders = {
time: 'Date',
formLabel: 'Label',
formType: 'Type',
streamAndType: 'Stream And Type',
value: 'Value',
description: 'Description'
}
const downloadHeaders = Object.assign({
streamId: 'Stream Id',
eventType: 'Event Type'
}, tableHeaders);
async function refresh (lines) {
// -- set download button
document.getElementById('button-download').onclick = async () => {
await exportXLSFile(downloadHeaders, lines, invite.displayName + '-' + invite.collector.name);
};
// -- update table
const table = document.getElementById('patient-data-table');
table.innerHTML = '';
const headerRow = table.insertRow(-1);
for (const thLabel of Object.values(tableHeaders)) {
const headerCell = document.createElement("TH");
headerCell.innerHTML = thLabel;
headerRow.appendChild(headerCell);
}
for (const line of lines) {
const row = table.insertRow(-1);
for (const key of Object.keys(tableHeaders)) {
const cell = row.insertCell(-1);
const v = line[key];
cell.innerHTML = v != null ? v : '' ;
}
}
}