-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdr-patient-view-lib.js
More file actions
74 lines (60 loc) · 1.8 KB
/
dr-patient-view-lib.js
File metadata and controls
74 lines (60 loc) · 1.8 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
export const drPatientLib = {
setRefresh
}
async function setRefresh(invite, refreshCallBack) {
async function doRefresh () {
const lines = await getPatientData(invite);
refreshCallBack(lines);
}
await invite.connection.socket.open();
invite.connection.socket.on('eventsChanged', async () => {
await doRefresh();
});
// do it once
doRefresh();
}
async function getPatientData (invite) {
const patientData = [];
const queryParams = { limit: 10000};
function forEachEvent(event) {
patientData.push(getLineForEvent (event));
}
await invite.connection.getEventsStreamed(queryParams, forEachEvent);
return patientData;
}
function getLineForEvent (event) {
const model = HDSLib.getHDSModel();
const line = {
time: (new Date(event.time * 1000)).toISOString(),
formLabel: 'Unkown',
formType: 'Unkown',
streamAndType: event.streamId + ' - ' + event.type,
value: JSON.stringify(event.content),
description: ''
}
const itemDef = model.itemsDefs.forEvent(event, false);
if (itemDef) {
line.streamId = event.streamIds[0];
line.eventType = event.type;
line.formLabel = itemDef.label;
line.formType = itemDef.data.type;
if (line.formType === 'date') {
line.value = (new Date(event.time * 1000)).toISOString().split('T')[0];
}
if (line.formType === 'select') {
line.value = event.content;
if (event.type === 'ratio/generic') {
line.value = event.content.value;
}
const selected = itemDef.data.options.find((o) => ( o.value === line.value ));
line.description = selected != null ? HDSLib.l(selected.label) : '-';
}
if (line.formType === 'checkbox') {
if (event.type === 'activity/plain') {
line.description = 'X';
line.value = 'x';
}
}
}
return line;
}