Skip to content

Commit e91a4cc

Browse files
committed
Better display
1 parent 512fe13 commit e91a4cc

5 files changed

Lines changed: 55 additions & 12 deletions

File tree

dr-controler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function setPatientList() {
4444
}
4545

4646
// --- patients
47-
const patients = await drLib.getPatientsList();
47+
const patients = await drLib.getPatientsList(100);
4848
for (const patient of Object.values(patients)) {
4949
const row = table.insertRow(-1);
5050
const cellStatus = row.insertCell(-1);

dr-lib.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,33 @@ function showLoginButton (loginSpanId, stateChangeCallBack) {
5151

5252
const patients = {};
5353

54-
async function getPatientsList () {
55-
const res = await drConnection.api([{ method: 'events.get', params: { types: ['credentials/pryv-api-endpoint'] } }]);
54+
async function getPatientsList (limit = 100) {
55+
const res = await drConnection.api([{ method: 'events.get', params: { types: ['credentials/pryv-api-endpoint'], limit } }]);
5656
const patientApiEndpointEvents = res[0].events;
57+
58+
// -- remove duplicates
59+
const duplicateEventId = [];
60+
const uniques = {};
5761
for (const patientEvent of patientApiEndpointEvents) {
62+
if (patientEvent.type === 'credentials/pryv-api-endpoint') {
63+
const apiEndpoint = patientEvent.content;
64+
if (uniques[apiEndpoint]) {
65+
// -- duplicate
66+
duplicateEventId.push(patientEvent.id);
67+
console.log('## Duplicate patient event', patientEvent);
68+
} else {
69+
uniques[apiEndpoint] = patientEvent;
70+
}
71+
}
72+
}
73+
if (duplicateEventId.length > 0) {
74+
const removeDuplicatesApiCalls = duplicateEventId.map(id => ({ method: 'events.delete', params: { id} }));
75+
const removeDuplicates = await drConnection.api(removeDuplicatesApiCalls);
76+
console.log('## Removed duplicates', removeDuplicates);
77+
}
78+
79+
// -- get the patients
80+
for (const patientEvent of Object.values(uniques)) {
5881
const patient = await getPatientDetails(patientEvent);
5982
if (patient) {
6083
patients[patient.apiEndpoint] = patient;

patient-home-controler.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,18 @@ function getRequestFrormApiEndPoint() {
3434
// --------- Update form list --------- //
3535
async function showFormList(formsInfo) {
3636
console.log('## showFormList', formsInfo);
37+
38+
39+
// -- table
3740
const table = document.getElementById('questionnary-table');
41+
42+
3843
for (const formInfo of formsInfo) {
3944

4045
// fill the table row
4146
const row = table.insertRow(-1);
4247
const cellQuestionnary = row.insertCell(-1);
43-
cellQuestionnary.innerHTML = formInfo.questionaryId;
48+
cellQuestionnary.innerHTML = `<button type="button" class="btn btn-secondary mb-sm">${formInfo.questionaryId}</button>`;
4449
cellQuestionnary.onclick = function () {
4550
showFormDetails(formInfo);
4651
};
@@ -61,10 +66,21 @@ async function showFormDetails(formInfo) {
6166
if (!show) return;
6267
const formDetails = await patientHomeLib.getQuestionnaryDetails(formInfo);
6368
console.log('## showFormDetails', formDetails);
69+
70+
// - form title
71+
const formTitle = document.getElementById('card-questionnary-details-title');
72+
formTitle.innerHTML = formInfo.questionaryId;
73+
6474
// - permissions
65-
const table = document.getElementById('access-request');
75+
const tbody = document.getElementById('access-request').getElementsByTagName('tbody')[0];;
76+
77+
// clear previous content
78+
while (tbody.firstChild) {
79+
tbody.removeChild(tbody.firstChild);
80+
}
81+
6682
for (const permission of formDetails.permissions) {
67-
const row = table.insertRow(-1);
83+
const row = tbody.insertRow(-1);
6884
const cellStream = row.insertCell(-1);
6985
cellStream.innerHTML = permission.name;
7086
const cellLevel = row.insertCell(-1);
@@ -92,6 +108,6 @@ async function showFormDetails(formInfo) {
92108
}
93109

94110
// - json
95-
const jsonContent = document.getElementById('card-questionnary-details-content');
96-
jsonContent.innerHTML = '<pre>' + JSON.stringify(formInfo.formEvent, null, 2) + '<pre>';
111+
// const jsonContent = document.getElementById('card-questionnary-details-content');
112+
// jsonContent.innerHTML = '<pre>' + JSON.stringify(formInfo.formEvent, null, 2) + '<pre>';
97113
}

patient-profile-controler.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ window.onload = async (event) => {
1010
console.log('## patientApiEndpoint:', patientApiEndpoint);
1111
await connect(patientApiEndpoint, questionaryId);
1212
updateFormContent('profile');
13-
document.getElementById('submit-button-profile').addEventListener("click", function () { submitForm('profile'); });
13+
document.getElementById('submit-button-profile').addEventListener("click", function () {
14+
submitForm('profile');
15+
});
1416
}
1517

1618

@@ -86,4 +88,5 @@ async function submitForm(formKey) {
8688
}
8789
}
8890
await patientLib.handleFormSubmit(formKey, values);
91+
alert('Form submitted successfully');
8992
};

patient.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
<script src="common-data-defs.js"></script>
1616
<script src="patient-home-controler.js"></script>
1717
<script src="patient-home-lib.js"></script>
18-
<script src="patient-lib.js"></script>
1918

2019
<body>
2120
<div class="container">
@@ -55,9 +54,10 @@ <h2>Questionnary details</h2>
5554
<div id="card-questionnary-details">
5655
<span id="card-questionnary-details-nothing">
5756
<h3>Nothing selected</h3>
58-
<p>Please select a questionnary to see its details.</p>
57+
<p>Please select a questionnary on the list above.</p>
5958
</span>
6059
<div id="card-questionnary-details-something" style="display: none;">
60+
<h3> Questionnary: <span id="card-questionnary-details-title"></span></h3>
6161
<table>
6262
<tr>
6363
<td>
@@ -67,11 +67,12 @@ <h3>Permission request</h3>
6767
<th><B>Stream</B></th>
6868
<th><B>Level</B></th>
6969
</thead>
70-
<tbody>
70+
<tbody id="access-request-body">
7171
<!-- will be filled by getQuestionaireDetails-->
7272
</tbody>
7373
</table>
7474
</td>
75+
<td>&nbsp; &nbsp;</td>
7576
<td>
7677
<button type="button" id="grant-access-button" class="btn btn-primary mb-2">Open</button>
7778
</td>

0 commit comments

Comments
 (0)