Skip to content

Commit b86f5bc

Browse files
committed
Cleanup and download works again
1 parent f92c018 commit b86f5bc

3 files changed

Lines changed: 11 additions & 60 deletions

File tree

common-data-defs.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
import { hdsModel } from './common-lib.js';
32
const v2 = {
43
'questionary-x': {
54
title: 'Demo with Profile and TTC-TTA 3',
@@ -64,31 +63,6 @@ const v2 = {
6463
}
6564
}
6665

67-
68-
function utilGetPermissions (questionaryId) {
69-
const preRequest = v2[questionaryId].permissionsPreRequest || [];
70-
const itemKeys = utilGetAllItemKeys(questionaryId);
71-
const permissions = hdsModel().authorizations.forItemKeys(itemKeys, { preRequest });
72-
return permissions
73-
}
74-
75-
76-
/**
77-
* get all itemKeys of a questionnary
78-
* @param {*} questionaryId
79-
*/
80-
function utilGetAllItemKeys (questionaryId) {
81-
const questionary = v2[questionaryId];
82-
const itemKeys = [];
83-
for (const formContent of Object.values(questionary.forms)) {
84-
itemKeys.push(...formContent.itemKeys);
85-
}
86-
return itemKeys;
87-
}
88-
8966
export const dataDefs = {
90-
appId: 'demo-dr-forms',
9167
v2questionnaires: v2,
92-
utilGetAllItemKeys,
93-
utilGetPermissions
9468
};

dr-controler.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { stateGetApp } from './common-lib.js';
12
import { drLib } from './dr-lib.js';
23
import { exportXLSFile } from './exporToXLS.js';
34

@@ -36,7 +37,7 @@ async function setQuestionnaries() {
3637
tbody.removeChild(tbody.firstChild);
3738
}
3839

39-
const appManaging = drLib.getAppManaging();
40+
const appManaging = await stateGetApp('managing');
4041

4142
const collectors = await appManaging.getCollectors();
4243
for (const collector of collectors) {
@@ -76,7 +77,7 @@ async function showQuestionnary(questionaryId) {
7677
return;
7778
}
7879

79-
const appManaging = drLib.getAppManaging();
80+
const appManaging = await stateGetApp('managing');
8081
// get questionnary (Controller)
8182
const collector = await appManaging.getCollectorById(questionaryId);
8283
await collector.init(); // load controller data only when needed
@@ -103,7 +104,7 @@ async function showQuestionnary(questionaryId) {
103104
await refreshInviteList(collector);
104105

105106
// show current patients
106-
await refreshPatientList(collector);
107+
const {headers, patientsData} = await refreshPatientList(collector);
107108

108109
//const {headers, patientsData} = await refreshPatientList(questionaryId);
109110
document.getElementById('button-download').onclick = async () => {

dr-lib.js

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,13 @@ import { hdsModel, serviceInfoUrl, initHDSModel, stateSaveApp } from "./common-l
77
const APP_MANAGING_STREAMID = 'app-dr-hds';
88
/** The name of this application */
99
const APP_MANAGING_NAME = 'HDS Dr App PoC';
10-
/** The app Manging */
11-
let appManaging; // initalized during pryvAuthStateChange
1210

1311
export const drLib = {
14-
// OK for v2
1512
showLoginButton,
16-
getAppManaging,
1713
getPatientsData,
18-
getPatientDetails,
19-
// OLD
20-
getFirstFormFields
14+
getPatientDetails
2115
};
2216

23-
/**
24-
* exposes appManaging for the app
25-
*/
26-
function getAppManaging () {
27-
return appManaging;
28-
}
29-
3017
function showLoginButton (loginSpanId, stateChangeCallBack) {
3118
const authSettings = {
3219
spanButtonID: loginSpanId, // div id the DOM that will be replaced by the Service specific button
@@ -63,13 +50,12 @@ function showLoginButton (loginSpanId, stateChangeCallBack) {
6350
console.log("##pryvAuthStateChange", state);
6451
if (state.id === HDSLib.pryv.Browser.AuthStates.AUTHORIZED) {
6552
await initHDSModel(); // hds model needs to be initialized
66-
appManaging = await HDSLib.appTemplates.AppManagingAccount.newFromApiEndpoint(APP_MANAGING_STREAMID, state.apiEndpoint, APP_MANAGING_NAME);
53+
const appManaging = await HDSLib.appTemplates.AppManagingAccount.newFromApiEndpoint(APP_MANAGING_STREAMID, state.apiEndpoint, APP_MANAGING_NAME);
6754
stateSaveApp('managing', appManaging);
6855
await initDemoAccount(appManaging);
6956
stateChangeCallBack("loggedIN");
7057
}
7158
if (state.id === HDSLib.pryv.Browser.AuthStates.INITIALIZED) {
72-
appManaging = null;
7359
stateSaveApp('managing', null);
7460
stateChangeCallBack("loggedOUT");
7561
}
@@ -152,8 +138,11 @@ async function getPatientsData (collector) {
152138
createdAt: 'Date'
153139
}
154140
// headers from first form
155-
const itemDefs = getFirstFormFields(requestContent.app.data.forms);
156-
for (const itemDef of itemDefs) {
141+
const firstForm = Object.values(requestContent.app.data.forms)[0];
142+
const itemDefs = [];
143+
for (const itemKey of firstForm.itemKeys) {
144+
const itemDef = hdsModel().itemsDefs.forKey(itemKey);
145+
itemDefs.push(itemDef);
157146
headers[itemDef.key] = HDSLib.l(itemDef.data.label);
158147
}
159148

@@ -220,19 +209,6 @@ async function getPatientDetails(invite, itemDefs) {
220209
return patient;
221210
}
222211

223-
/**
224-
* get the list of rows for the initial table
225-
*/
226-
function getFirstFormFields(forms) {
227-
const firstForm = Object.values(forms)[0];
228-
const itemDefs = [];
229-
for (const itemKey of firstForm.itemKeys) {
230-
itemDefs.push(hdsModel().itemsDefs.forKey(itemKey));
231-
}
232-
233-
return itemDefs;
234-
}
235-
236212
/**
237213
* Link an event to a data field from form
238214
* @param {*} event

0 commit comments

Comments
 (0)