Skip to content

Commit 3269b36

Browse files
committed
Live data update
1 parent 01de0bb commit 3269b36

5 files changed

Lines changed: 45 additions & 24 deletions

File tree

dr-controler.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ async function setPatientList(questionaryId) {
112112
const patientsData = [];
113113
for (const patient of Object.values(patients)) {
114114
const row = table.insertRow(-1);
115-
console.log('>> patient', patient);
116115

117116
const cellStatus = row.insertCell(-1);
118117
cellStatus.innerHTML = patient.status;

dr-patient-view-controler.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@ import { exportCSVFile } from "./exportToCSV.js";
1010
*/
1111

1212

13+
let infos;
1314
window.onload = async (event) => {
14-
refresh();
15+
const { patientApiEndpoint, questionaryId } = getRequestFrormApiEndPoint();
16+
infos = drPatientLib.setRefresh(patientApiEndpoint, questionaryId, refresh)
17+
// -- home button
18+
document.getElementById('home-button').href= 'dr.html?questionaryId=' + questionaryId;
19+
20+
// -- set patient Id
21+
const username = infos.user.username;
22+
document.getElementById('patient-label').innerHTML = username;
23+
1524
}
1625

1726
const tableHeaders = {
@@ -28,32 +37,23 @@ const downloadHeaders = Object.assign({
2837
eventType: 'Event Type'
2938
}, tableHeaders);
3039

31-
async function refresh () {
32-
const { patientApiEndpoint, questionaryId } = getRequestFrormApiEndPoint();
33-
const { infos, lines } = await drPatientLib.getPatientData(patientApiEndpoint, questionaryId);
34-
console.log('>> zz', infos);
35-
// -- home button
36-
document.getElementById('home-button').href= 'dr.html?questionaryId=' + questionaryId;
37-
38-
// -- set patient Id
39-
const username = infos.user.username;
40-
document.getElementById('patient-label').innerHTML = username;
41-
40+
async function refresh (lines) {
4241
// -- set download button
4342
document.getElementById('button-download').onclick = () => {
4443
exportCSVFile(downloadHeaders, lines, username + '-' + questionaryId);
4544
};
4645

4746
// -- update table
4847
const table = document.getElementById('patient-data-table');
48+
table.innerHTML = '';
49+
4950
const headerRow = table.insertRow(-1);
5051
for (const thLabel of Object.values(tableHeaders)) {
5152
const headerCell = document.createElement("TH");
5253
headerCell.innerHTML = thLabel;
5354
headerRow.appendChild(headerCell);
5455
}
5556
for (const line of lines) {
56-
console.log('>> line', line);
5757
const row = table.insertRow(-1);
5858
for (const key of Object.keys(tableHeaders)) {
5959
const cell = row.insertCell(-1);

dr-patient-view-lib.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,31 @@
22
import { dataDefs } from './common-data-defs.js';
33

44
export const drPatientLib = {
5-
getPatientData
5+
setRefresh
66
}
77

8+
let connection;
9+
async function setRefresh(patientApiEndoint, questionaryId, refreshCallBack) {
10+
connection = new Pryv.Connection(patientApiEndoint);
11+
const infos = await connection.accessInfo();
12+
13+
async function doRefresh () {
14+
const lines = await getPatientData(questionaryId);
15+
refreshCallBack(lines);
16+
}
17+
18+
await connection.socket.open();
19+
connection.socket.on('eventsChanged', async () => {
20+
console.log('>> refresh event');
21+
await doRefresh();
22+
});
23+
24+
// do it once
25+
doRefresh();
26+
return infos;
27+
}
28+
29+
830
// prepare data for easy lookup
931
// map streamId/EventType with form data
1032
const eventMapByQuestionnary = {};
@@ -19,19 +41,17 @@ for (const [questionaryId, questionary] of Object.entries(dataDefs.questionnaire
1941
}
2042
}
2143
}
22-
console.log('>> eventMapByQuestionnary', eventMapByQuestionnary);
2344

24-
async function getPatientData (patientApiEndoint, questionaryId) {
45+
async function getPatientData (questionaryId) {
2546
const patientData = [];
2647
const queryParams = { limit: 10000};
2748
function forEachEvent(event) {
2849
patientData.push(getLineForEvent (event, questionaryId));
2950
}
3051

31-
const connection = new Pryv.Connection(patientApiEndoint);
32-
const infos = await connection.accessInfo();
52+
3353
await connection.getEventsStreamed(queryParams, forEachEvent);
34-
return { infos, lines: patientData };
54+
return patientData;
3555
}
3656

3757

@@ -46,15 +66,17 @@ function getLineForEvent (event, questionaryId) {
4666
}
4767

4868
const field = eventMapByQuestionnary[questionaryId][event.streamId + ':' + event.type];
49-
console.log('>> field', field, event);
5069
if (field) {
5170
Object.assign(line, field);
5271
if (field.type === 'date') {
5372
line.value = (new Date(event.time * 1000)).toISOString().split('T')[0];
5473
}
5574
if (field.type === 'select') {
5675
line.value = event.content;
57-
76+
if (field.eventType === 'ratio/generic') {
77+
line.value = event.content.value;
78+
}
79+
5880
const selected = field.options.find((o) => ( o.value === line.value ));
5981
line.description = selected?.label;
6082
}

dr-patient-view.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<title>Demo Form - Dr's page</title>
1313
</head>
1414
<script src="https://pryv.github.io/lib-js/pryv.js"></script>
15+
<script src="https://api.pryv.com/lib-js/pryv-socket.io.js"></script>
1516
<script type="module" src="dr-patient-view-controler.js"></script>
1617

1718
<body>

patient-history-controler.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ async function refreshAll(dateStr) {
6161

6262
updateFormContent(formData);
6363
document.getElementById("submit-button-list").onclick = function () {
64-
submitForm(formData, dateStr);
64+
submitForm(formData, new Date(dateStr));
6565
};
6666
}
6767

6868
async function refreshDataTable(currentDateStr) {
69-
console.log('>> refreshTable', currentDateStr);
7069
let currentValue = {};
7170
const { questionaryId, formKey } = navData;
7271
const tableData = await patientLib.getHistoricalContent(

0 commit comments

Comments
 (0)