Skip to content

Commit 514f109

Browse files
committed
App now handles multiples forms
1 parent 83e3b70 commit 514f109

12 files changed

Lines changed: 525 additions & 176 deletions

Technical_flow.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ They contains personal data with the following streams
5151
- body-height: -event of type "length/*" meters or ...
5252
- body-weigth: -event of type "mass/*" kg or ...
5353
- demo-dr-form: (stream to track states and usage of this app)
54+
- inbox
55+
- accepted
56+
- rejected
5457
```
5558

5659
##### Tracking fertility awareness contents

common-data-defs.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
const patientBaseStreams = [
23
// profile
34
{id: 'profile-name', name: 'Name', parentId: 'profile'},
@@ -136,10 +137,21 @@ const formHistoricalContent = [
136137
}
137138
]
138139

140+
questionnaires = {
141+
'demo-dr-forms-questionary-x': {
142+
permissions: patientBasePermissions.map(perm => ({
143+
streamId: perm.id,
144+
level: 'read',
145+
name: perm.name,
146+
})),
147+
patientBaseStreams
148+
}
149+
}
139150

140151
const dataDefs = {
141152
patientBaseStreams,
142153
patientBasePermissions,
143154
formProfileContent,
144-
formHistoricalContent
155+
formHistoricalContent,
156+
questionnaires
145157
};

dr-lib.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ async function getPatientsList () {
6262
};
6363
const patientConnection = new Pryv.Connection(patient.apiEndpoint);
6464
// -- get patient info
65-
const patientInfo = await patientConnection.accessInfo();
66-
patient.username = patientInfo.user.username;
65+
try {
66+
const patientInfo = await patientConnection.accessInfo();
67+
patient.username = patientInfo.user.username;
68+
} catch (e) {
69+
console.error('## Error getting patient info: ' + patient.apiEndpoint, e);
70+
continue;
71+
}
72+
6773

6874
// -- get data
6975
const profileEvents = await patientConnection.api([{ method: 'events.get', params: { limit: 100 } }]);

dr.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<img src="https://healthdatasafe.github.io/style/images/Horizontal/hds-logo-hz-1024x400-hz-color.png" alt="Logo" width="300px">
2222
<h1>Demo Form - Dr's page</h1>
2323
<div class="card">
24-
<div class="card-body">
24+
<div class="card-login">
2525
<h2 class="card-title">Welcome</h2>
2626
<span id="login-button"></span>
2727
<br><br>
@@ -38,12 +38,12 @@ <h2 class="card-title">Welcome</h2>
3838
</div>
3939
</div>
4040
<div class="card" id="data-view" style="visibility: hidden;">
41-
<div class="card-body">
41+
<div class="card-login">
4242
<h2 class="card-title">Sharing link</h2>
4343
<span id="sharing-link">
4444

4545
</div>
46-
<div class="card-body">
46+
<div class="card-login">
4747
<h2 class="card-title">Patients</h2>
4848
<table id='patients-table' class="table">
4949
<thead>

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<h1>Demo Form</h1>
1919
<table width="100%">
2020
<td>
21-
<div class="card-body">
21+
<div class="card-login">
2222
<h2><A class="card-title" HREF="dr.html">Dr's Page</A></h2>
2323
From this page you will be able to visualize the data from patients and share an invitation link to fill your questionnaire.
2424
<BR>
@@ -43,7 +43,7 @@ <h2><A class="card-title" HREF="dr.html">Dr's Page</A></h2>
4343
</div>
4444
</td>
4545
<td>
46-
<div class="card-body">
46+
<div class="card-login">
4747
<!--
4848
<h2><A class="card-title" HREF="patient.html">Patient's Page</A></h2>
4949
From this page you will be able to visualize your current data and forms you particpated in.<BR>

patient-history.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
7+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
8+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
9+
<link rel="icon" href="https://healthdatasafe.github.io/style/images/Favicon/favicon.ico" type="image/x-icon">
10+
<link rel="stylesheet" type="text/css" href="https://healthdatasafe.github.io/style/hds.min.css">
11+
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400">
12+
<title>Demo Form - Patient's page</title>
13+
</head>
14+
<script src="https://api.pryv.com/lib-js/pryv.js"></script>
15+
<script src="common-data-defs.js"></script>
16+
<script src="patient-controler.js"></script>
17+
<script src="patient-lib.js"></script>
18+
19+
<body>
20+
<div class="container">
21+
<img src="https://healthdatasafe.github.io/style/images/Horizontal/hds-logo-hz-1024x400-hz-color.png" alt="Logo" width="300px">
22+
<h1>Demo Form - Patient's page</h1>
23+
<div class="card">
24+
<div class="card-login">
25+
<h2 class="card-title">Welcome</h2>
26+
<span id="login-button"></span>
27+
<br><br>
28+
<span id="welcome-message-mme">
29+
Dear Madam, from this page you will answer a questionnary to be shared with your Doctor.
30+
</span>
31+
<br>
32+
<span id="welcome-message-viewer" style="visibility: hidden;"> Welcome message
33+
</span>
34+
<br>
35+
<span id="please-login">
36+
Please login.
37+
</span>
38+
</div>
39+
</div>
40+
<div class="card" id="card-content" style="visibility: hidden;">
41+
<form id="form-historical">
42+
<h2 class="card-title">Historical Data</h2>
43+
<div class="form-group">
44+
<div class="input-group" id="inputs-historical">
45+
<!-- HERE WILL GO THE INPUTS-->
46+
</div>
47+
</div>
48+
<button type="button" id="submit-button-historical" class="btn btn-primary mb-2">Submit</button>
49+
</form>
50+
</div>
51+
</div>
52+
</body>
53+
54+
</html>

patient-home-controler.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* UI management code.
3+
* Relies on patientLib for API calls and data management
4+
*
5+
* @param {*} event
6+
*/
7+
8+
window.onload = (event) => {
9+
stateChange('loggedOut');
10+
patientHomeLib.showLoginButton('login-button', stateChange);
11+
};
12+
13+
async function stateChange(state) {
14+
if (state === 'loggedIN') {
15+
document.getElementById('please-login').style.visibility = 'hidden';
16+
document.getElementById('card-content').style.visibility = 'visible';
17+
const formApiEndpoint = getRequestFrormApiEndPoint();
18+
console.log('## formApiEndpoint:', formApiEndpoint);
19+
const formsInfo = await patientHomeLib.getForms(formApiEndpoint);
20+
showFormList(formsInfo)
21+
} else {
22+
document.getElementById('please-login').style.visibility = 'visible';
23+
document.getElementById('card-content').style.visibility = 'hidden';
24+
}
25+
}
26+
27+
// ------- Get Dr's info -------- //
28+
function getRequestFrormApiEndPoint() {
29+
const params = new URLSearchParams(document.location.search);
30+
const formApiEndpoint = params.get('formApiEndpoint');
31+
return formApiEndpoint || null;
32+
}
33+
34+
// --------- Update form list --------- //
35+
async function showFormList(formsInfo) {
36+
console.log('## showFormList', formsInfo);
37+
const table = document.getElementById('questionnary-table');
38+
for (const formInfo of formsInfo) {
39+
40+
// fill the table row
41+
const row = table.insertRow(-1);
42+
const cellQuestionnary = row.insertCell(-1);
43+
cellQuestionnary.innerHTML = formInfo.questionaryId;
44+
cellQuestionnary.onclick = function () {
45+
showFormDetails(formInfo);
46+
};
47+
48+
const cellDr = row.insertCell(-1);
49+
cellDr.innerHTML = formInfo.drUserId;
50+
51+
const cellStatus = row.insertCell(-1);
52+
cellStatus.innerHTML = formInfo.formEvent.streamIds[0];
53+
}
54+
}
55+
56+
// ----------- Show form details ----------- //
57+
async function showFormDetails(formInfo) {
58+
const show = !!formInfo;
59+
document.getElementById('card-questionnary-details-nothing').style.display = show ? 'none' : 'block';
60+
document.getElementById('card-questionnary-details-something').style.display= show ? 'block' : 'none';
61+
if (!show) return;
62+
const formDetails = await patientHomeLib.getQuestionnaryDetails(formInfo);
63+
console.log('## showFormDetails', formDetails);
64+
// - permissions
65+
const table = document.getElementById('access-request');
66+
for (const permission of formDetails.permissions) {
67+
const row = table.insertRow(-1);
68+
const cellStream = row.insertCell(-1);
69+
cellStream.innerHTML = permission.name;
70+
const cellLevel = row.insertCell(-1);
71+
cellLevel.innerHTML = permission.level;
72+
}
73+
// - grant access / open
74+
const button = document.getElementById('grant-access-button');
75+
76+
// -- pass the apiEndpoint to the next page !! Insecure just for demo
77+
const openHREF = `patient-profile.html?patientApiEndpoint=${patientHomeLib.getPatientApiEndpoint()}&questionaryId=${formInfo.questionaryId}`;
78+
if (formDetails.status === 'accepted') {
79+
button.innerHTML = 'Open';
80+
button.onclick = async function () {
81+
// await patientHomeLib.publishAccess(formInfo, formDetails.sharedApiEndpoint);
82+
document.location.href = openHREF;
83+
};
84+
}
85+
else {
86+
button.innerHTML = 'Grant access and Open';
87+
button.onclick = async function () {
88+
await patientHomeLib.grantAccess(formInfo, formDetails);
89+
document.location.href = openHREF;
90+
};
91+
}
92+
93+
// - json
94+
const jsonContent = document.getElementById('card-questionnary-details-content');
95+
jsonContent.innerHTML = '<pre>' + JSON.stringify(formInfo.formEvent, null, 2) + '<pre>';
96+
}

0 commit comments

Comments
 (0)