Skip to content

Commit 294a259

Browse files
committed
Returning to correct questionnary
1 parent 23f2474 commit 294a259

4 files changed

Lines changed: 27 additions & 14 deletions

File tree

dr-controler.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,27 @@ async function setQuestionnaries() {
4040
select.add(option);
4141
}
4242

43-
// --
43+
// -- on change
4444
select.onchange = function () {
4545
if (select.value === '') {
4646
showQuestionnary(null);
4747
return;
4848
}
4949
showQuestionnary(select.value);
5050
}
51+
// -- on load
52+
const selectedQuestionnary = getQuestionnaryFromUrl();
53+
if (selectedQuestionnary) {
54+
select.value = selectedQuestionnary;
55+
showQuestionnary(selectedQuestionnary);
56+
}
57+
}
58+
59+
// ------- Get Dr's info -------- //
60+
function getQuestionnaryFromUrl() {
61+
const params = new URLSearchParams(document.location.search);
62+
const questionaryId = params.get('questionaryId');
63+
return questionaryId
5164
}
5265

5366
async function showQuestionnary(questionaryId) {
@@ -100,15 +113,12 @@ async function setPatientList(questionaryId) {
100113
for (const patient of Object.values(patients)) {
101114
const row = table.insertRow(-1);
102115
console.log('>> patient', patient);
103-
row.onclick = function () {
104-
document.location.href = `dr-patient-view.html?patientApiEndpoint=${patient.apiEndpoint}&questionaryId=${questionaryId}`
105-
}
106-
107116

108117
const cellStatus = row.insertCell(-1);
109118
cellStatus.innerHTML = patient.status;
110119
const cellUsername = row.insertCell(-1);
111-
cellUsername.innerHTML = patient.username;
120+
const page = `dr-patient-view.html?patientApiEndpoint=${patient.apiEndpoint}&questionaryId=${questionaryId}`;
121+
cellUsername.innerHTML = `<A HREF="${page}">${patient.username}</A>`;
112122
const patientData = {
113123
status: patient.status,
114124
username: patient.username

dr-lib.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ async function getQuestionnaires() {
6464

6565
const patients = {};
6666

67-
async function getPatientsList(questionnaryId, limit = 100) {
68-
const qStreams = questionnaryStreams(questionnaryId);
67+
async function getPatientsList(questionaryId, limit = 100) {
68+
const qStreams = questionnaryStreams(questionaryId);
6969
const res = await drConnection.api([
7070
{
7171
method: "events.get",
@@ -104,7 +104,7 @@ async function getPatientsList(questionnaryId, limit = 100) {
104104

105105
// -- get the patients
106106
const patientPromises = Object.values(uniques).map((patientEvent) =>
107-
getPatientDetails(questionnaryId, patientEvent)
107+
getPatientDetails(questionaryId, patientEvent)
108108
);
109109
const patientsResults = await Promise.all(patientPromises);
110110

@@ -123,9 +123,9 @@ async function getPatientsList(questionnaryId, limit = 100) {
123123
/**
124124
* get patients details
125125
*/
126-
async function getPatientDetails(questionnaryId, patientEvent) {
126+
async function getPatientDetails(questionaryId, patientEvent) {
127127
// -- check if the event is a patient event
128-
const qStreams = questionnaryStreams(questionnaryId);
128+
const qStreams = questionnaryStreams(questionaryId);
129129
if (patientEvent.type !== "credentials/pryv-api-endpoint") return null;
130130
const patient = {
131131
status: "active",
@@ -170,7 +170,7 @@ async function getPatientDetails(questionnaryId, patientEvent) {
170170

171171
// -- get data
172172
// get profile form data
173-
const formProfile = dataDefs.questionnaires[questionnaryId].forms.profile;
173+
const formProfile = dataDefs.questionnaires[questionaryId].forms.profile;
174174

175175
// get the last value of each field
176176
const apiCalls = formProfile.content.map((field) => ({

dr-patient-view-controler.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { exportCSVFile } from "./exportToCSV.js";
44
* Based on
55
* - drApiConnecion
66
* - patientApiConnection
7-
* - questionnaryId
7+
* - questionaryId
88
*
99
* Display live update of data
1010
*/
@@ -32,6 +32,9 @@ async function refresh () {
3232
const { patientApiEndpoint, questionaryId } = getRequestFrormApiEndPoint();
3333
const { infos, lines } = await drPatientLib.getPatientData(patientApiEndpoint, questionaryId);
3434
console.log('>> zz', infos);
35+
// -- home button
36+
document.getElementById('home-button').href= 'dr.html?questionaryId=' + questionaryId;
37+
3538
// -- set patient Id
3639
const username = infos.user.username;
3740
document.getElementById('patient-label').innerHTML = username;

dr-patient-view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<div class="container">
1919
<img src="https://healthdatasafe.github.io/style/images/Horizontal/hds-logo-hz-1024x400-hz-color.png" alt="Logo" width="300px">
2020
<h1>Demo Form - Dr's Patient View</h1>
21-
<a href="dr.html" class="btn btn-primary">HOME</a>
21+
<a href="dr.html" class="btn btn-primary" id="home-button">HOME</a>
2222
<div class="card">
2323
<div class="card-patient">
2424
<h2> Patient: <span id="patient-label">Patient X</span></h2>

0 commit comments

Comments
 (0)