Skip to content

Commit f92c018

Browse files
committed
Most of the flow is working
1 parent 21e8526 commit f92c018

6 files changed

Lines changed: 35 additions & 44 deletions

File tree

dr-controler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function setQuestionnaries() {
5757
// ------- Get Dr's info -------- //
5858
function getQuestionnaryFromUrl() {
5959
const params = new URLSearchParams(document.location.search);
60-
const questionaryId = params.get('questionaryId');
60+
const questionaryId = params.get('collectorId');
6161
return questionaryId
6262
}
6363

@@ -175,7 +175,7 @@ async function refreshPatientList(collector) {
175175
}
176176
row.insertCell(-1).innerHTML = text;
177177
}
178-
178+
179179
}
180180
// return this to be used by Excel Download
181181
return { headers, patientsData };

dr-lib.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { dataDefs } from "./common-data-defs.js";
2-
import { hdsModel, serviceInfoUrl, initHDSModel } from "./common-lib.js"
2+
import { hdsModel, serviceInfoUrl, initHDSModel, stateSaveApp } from "./common-lib.js"
33

4-
// OLD
5-
const appDrStreamId = dataDefs.appId + "-dr"; // simply use the appId + '-dr'
6-
let drConnection = null;
74

85
// NEW
96
/** The "base" stream for this App */
@@ -67,11 +64,13 @@ function showLoginButton (loginSpanId, stateChangeCallBack) {
6764
if (state.id === HDSLib.pryv.Browser.AuthStates.AUTHORIZED) {
6865
await initHDSModel(); // hds model needs to be initialized
6966
appManaging = await HDSLib.appTemplates.AppManagingAccount.newFromApiEndpoint(APP_MANAGING_STREAMID, state.apiEndpoint, APP_MANAGING_NAME);
67+
stateSaveApp('managing', appManaging);
7068
await initDemoAccount(appManaging);
7169
stateChangeCallBack("loggedIN");
7270
}
7371
if (state.id === HDSLib.pryv.Browser.AuthStates.INITIALIZED) {
7472
appManaging = null;
73+
stateSaveApp('managing', null);
7574
stateChangeCallBack("loggedOUT");
7675
}
7776
}

dr-patient-view-controler.js

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { initHDSModel, stateGetApp } from "./common-lib.js";
12
import { drPatientLib } from "./dr-patient-view-lib.js";
23
import { exportXLSFile } from './exporToXLS.js';
3-
import { patientLib } from "./patient-lib.js";
4+
45
/**
56
* Based on
67
* - drApiConnecion
@@ -11,24 +12,29 @@ import { patientLib } from "./patient-lib.js";
1112
*/
1213

1314

14-
let infos;
15-
let username;
16-
let qId;
15+
let invite;
1716
window.onload = async (event) => {
18-
const { patientApiEndpoint, questionaryId } = getRequestFrormApiEndPoint();
19-
infos = await drPatientLib.setRefresh(patientApiEndpoint, questionaryId, refresh)
17+
await initHDSModel();
18+
// get collectorId & inviteKey from URL
19+
const params = new URLSearchParams(document.location.search);
20+
const collectorId = params.get('collectorId');
21+
const inviteKey = params.get('inviteKey');
22+
23+
// get app from state management
24+
const appManaging = await stateGetApp('managing');
25+
const collector = await appManaging.getCollectorById(collectorId);
26+
invite = await collector.getInviteByKey(inviteKey);
27+
console.log('# Loaded with invite', invite);
28+
29+
await drPatientLib.setRefresh(invite, refresh)
2030
// -- home button
21-
document.getElementById('home-button').href= 'dr.html?questionaryId=' + questionaryId;
31+
document.getElementById('home-button').href= 'dr.html?collectorId=' + collectorId;
2232

2333
// - form title
2434
const formTitle = document.getElementById('card-questionnary-details-title');
25-
formTitle.innerHTML = patientLib.getFormTitle(questionaryId);
26-
27-
qId = questionaryId;
35+
formTitle.innerHTML = collector.name;
2836

29-
// -- set patient Id
30-
username = infos.user.username;
31-
document.getElementById('patient-label').innerHTML = username;
37+
document.getElementById('patient-label').innerHTML = invite.displayName;
3238
}
3339

3440
const tableHeaders = {
@@ -48,7 +54,7 @@ const downloadHeaders = Object.assign({
4854
async function refresh (lines) {
4955
// -- set download button
5056
document.getElementById('button-download').onclick = async () => {
51-
await exportXLSFile(downloadHeaders, lines, username + '-' + qId);
57+
await exportXLSFile(downloadHeaders, lines, invite.displayName + '-' + invite.collector.name);
5258
};
5359

5460
// -- update table
@@ -70,11 +76,3 @@ async function refresh (lines) {
7076
}
7177
}
7278
}
73-
74-
// ------- Get Dr's info -------- //
75-
function getRequestFrormApiEndPoint() {
76-
const params = new URLSearchParams(document.location.search);
77-
const patientApiEndpoint = params.get('patientApiEndpoint');
78-
const questionaryId = params.get('questionaryId');
79-
return { patientApiEndpoint, questionaryId };
80-
}

dr-patient-view-lib.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,37 @@ export const drPatientLib = {
66
setRefresh
77
}
88

9-
let connection;
10-
async function setRefresh(patientApiEndoint, questionaryId, refreshCallBack) {
11-
connection = await connectAPIEndpoint(patientApiEndoint);
12-
const infos = await connection.accessInfo();
9+
async function setRefresh(invite, refreshCallBack) {
1310

1411
async function doRefresh () {
15-
const lines = await getPatientData(questionaryId);
12+
const lines = await getPatientData(invite);
1613
refreshCallBack(lines);
1714
}
1815

19-
await connection.socket.open();
20-
connection.socket.on('eventsChanged', async () => {
16+
await invite.connection.socket.open();
17+
invite.connection.socket.on('eventsChanged', async () => {
2118
await doRefresh();
2219
});
2320

2421
// do it once
2522
doRefresh();
26-
return infos;
2723
}
2824

2925

30-
async function getPatientData (questionaryId) {
26+
async function getPatientData (invite) {
3127
const patientData = [];
3228
const queryParams = { limit: 10000};
3329
function forEachEvent(event) {
34-
patientData.push(getLineForEvent (event, questionaryId));
30+
patientData.push(getLineForEvent (event));
3531
}
3632

3733

38-
await connection.getEventsStreamed(queryParams, forEachEvent);
34+
await invite.connection.getEventsStreamed(queryParams, forEachEvent);
3935
return patientData;
4036
}
4137

4238

43-
function getLineForEvent (event, questionaryId) {
39+
function getLineForEvent (event) {
4440
const model = hdsModel();
4541
const line = {
4642
time: (new Date(event.time * 1000)).toISOString(),

dr-patient-view.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Inter:300,400">
1212
<title>Demo Form - Dr's page</title>
1313
</head>
14-
<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>
16-
<script src="https://healthdatasafe.github.io/hds-lib-js/hds-lib.js"></script>
14+
<script src="https://whatever.backloop.dev:5553/hds-lib.js"></script>
1715
<script type="module" src="dr-patient-view-controler.js"></script>
1816

1917
<body style="background-color:powderblue;">

patient-home-lib.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function showLoginButton (loginSpanId, stateChangeCallBack) {
4444
stateChangeCallBack('loggedIN');
4545
}
4646
if (state.id === HDSLib.pryv.Browser.AuthStates.INITIALIZED) {
47-
stateSaveApp(null, 'client');
47+
stateSaveApp('client', null);
4848
stateChangeCallBack('loggedOUT');
4949
}
5050
}

0 commit comments

Comments
 (0)