Skip to content

Commit 55498c0

Browse files
committed
Preparing for Historical data
1 parent 7b0174f commit 55498c0

6 files changed

Lines changed: 97 additions & 27 deletions

common-data-defs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ questionnaires = {
159159
name: 'Profile',
160160
content: formProfileContent
161161
},
162-
historical: {
162+
history: {
163163
type: 'recurring',
164164
key: 'recurring-x',
165-
name: 'Historical',
165+
name: 'History',
166166
content: formHistoricalContent
167167
}
168168
}

patient-history-controler.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* UI management code.
3+
* Relies on patientLib for API calls and data management
4+
*
5+
* @param {*} event
6+
*/
7+
8+
window.onload = async (event) => {
9+
const { patientApiEndpoint, questionaryId } = getPatientApiEndpointAndFormId();
10+
console.log('## patientApiEndpoint:', patientApiEndpoint);
11+
await connect(patientApiEndpoint, questionaryId);
12+
// -- navigation
13+
document.getElementById('nav-profile').onclick = () => {
14+
document.location.href = 'patient-profile.html' + patientLib.getNavigationQueryParams();
15+
};
16+
17+
// -- connection
18+
updateFormContent(questionaryId, 'history');
19+
document.getElementById('submit-button-history').addEventListener("click", function () {
20+
submitForm(questionaryId, 'history');
21+
});
22+
}
23+
24+
25+
// ------- Get Questionnary and endpoint info -------- //
26+
function getPatientApiEndpointAndFormId() {
27+
const params = new URLSearchParams(document.location.search);
28+
const patientApiEndpoint = params.get('patientApiEndpoint');
29+
const questionaryId = params.get('questionaryId');
30+
if (!patientApiEndpoint) {
31+
alert('No patientApiEndpoint found in the URL');
32+
return;
33+
}
34+
if (!questionaryId) {
35+
alert('No questionaryId found in the URL');
36+
return;
37+
}
38+
return { patientApiEndpoint, questionaryId };
39+
}
40+
41+
42+
// ------- Form -------- //
43+
44+
/**
45+
* Take the from content from the definition and actual values and create the HTML
46+
*/
47+
async function updateFormContent(questionaryId, formKey) {
48+
const formData = await patientLib.getFormContent(questionaryId, formKey);
49+
console.log('Form content:', formData);
50+
51+
}
52+
53+
/**
54+
* Submit the form and send the data to the API
55+
*/
56+
async function submitForm(questionaryId, formKey) {
57+
58+
};

patient-history.html

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,33 @@
1313
</head>
1414
<script src="https://api.pryv.com/lib-js/pryv.js"></script>
1515
<script src="common-data-defs.js"></script>
16-
<script src="patient-controler.js"></script>
16+
<script src="patient-history-controler.js"></script>
1717
<script src="patient-lib.js"></script>
1818

1919
<body>
2020
<div class="container">
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 - Patient's page</h1>
2323
<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>
24+
<div class="card-header">
25+
<table>
26+
<tr>
27+
<td><A HREF="patient.html" class="btn btn-primary">Home</A></td>
28+
<td>&nbsp;</td>
29+
<td><button id="nav-profile" class="btn btn-primary">Profile</button></td>
30+
</tr>
31+
</table>
3832
</div>
3933
</div>
40-
<div class="card" id="card-content" style="visibility: hidden;">
41-
<form id="form-historical">
34+
<div class="card" id="card-content" >
35+
<form id="form-history">
4236
<h2 class="card-title">Historical Data</h2>
4337
<div class="form-group">
44-
<div class="input-group" id="inputs-historical">
38+
<div class="input-group" id="inputs-history">
4539
<!-- HERE WILL GO THE INPUTS-->
4640
</div>
4741
</div>
48-
<button type="button" id="submit-button-historical" class="btn btn-primary mb-2">Submit</button>
42+
<button type="button" id="submit-button-history" class="btn btn-primary mb-2">Submit</button>
4943
</form>
5044
</div>
5145
</div>

patient-lib.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
const patientLib = {
22
handleFormSubmit,
33
getFormContent,
4-
connect
4+
connect,
5+
getNavigationQueryParams
56
}
67

78
let connection = null;
8-
let questionaryId = null;
9+
let _questionaryId = null;
910
async function connect (apiEndpoint, questionaryId) {
1011
connection = new Pryv.Connection(apiEndpoint);
12+
_questionaryId = questionaryId;
1113
const accessInfo = await connection.accessInfo();
1214
console.log('## Patient connected', accessInfo);
1315
return accessInfo;
1416
}
1517

18+
function getNavigationQueryParams() {
19+
return `?patientApiEndpoint=${connection.apiEndpoint}&questionaryId=${_questionaryId}`
20+
}
21+
1622
// ---------------- form content ---------------- //
1723

1824
async function getFormContent (questionaryId, formKey) {
1925
const form = dataDefs.questionnaires[questionaryId].forms[formKey];
20-
console.log('## getFormContent', form);
26+
console.log('## getFormContent', form, questionaryId, formKey);
2127
if (form.type === 'permanent') {
2228
return getFormPermanentContent(form);
2329
}
24-
if (formKey === 'recurring') {
30+
if (form.type === 'recurring') {
2531
return getFormRecurringContent(form);
2632
}
2733
return [];

patient-profile-controler.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ window.onload = async (event) => {
99
const { patientApiEndpoint, questionaryId } = getPatientApiEndpointAndFormId();
1010
console.log('## patientApiEndpoint:', patientApiEndpoint);
1111
await connect(patientApiEndpoint, questionaryId);
12+
// -- navigation
13+
document.getElementById('nav-history').onclick = () => {
14+
document.location.href = 'patient-history.html' + patientLib.getNavigationQueryParams();
15+
};
16+
// -- content
1217
updateFormContent(questionaryId, 'profile');
1318
document.getElementById('submit-button-profile').addEventListener("click", function () {
1419
submitForm(questionaryId, 'profile');
1520
});
21+
1622
}
1723

1824

19-
// ------- Get Dr's info -------- //
25+
// ------- Get Questionnary and endpoint info -------- //
2026
function getPatientApiEndpointAndFormId() {
2127
const params = new URLSearchParams(document.location.search);
2228
const patientApiEndpoint = params.get('patientApiEndpoint');

patient-profile.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@
2222
<h1>Demo Form - Patient's page</h1>
2323
<div class="card">
2424
<div class="card-header">
25-
<A HREF="patient.html" class="btn btn-primary">Home</A>
25+
<table>
26+
<tr>
27+
<td><A HREF="patient.html" class="btn btn-primary">Home</A></td>
28+
<td>&nbsp;</td>
29+
<td><button id="nav-history" class="btn btn-primary">History</button></td>
30+
</tr>
31+
</table>
2632
</div>
2733
</div>
2834
<div class="card" id="card-content">

0 commit comments

Comments
 (0)