Skip to content

Commit 5117f42

Browse files
committed
Partial Dr view implemented
1 parent 532d857 commit 5117f42

4 files changed

Lines changed: 156 additions & 0 deletions

File tree

dr-controler.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ async function setPatientList(questionaryId) {
9999
const patientsData = [];
100100
for (const patient of Object.values(patients)) {
101101
const row = table.insertRow(-1);
102+
console.log('>> patient', patient);
103+
row.onclick = function () {
104+
document.location.href = `dr-patient-view.html?patientApiEndpoint=${patient.apiEndpoint}&questionaryId=${questionaryId}`
105+
}
106+
107+
102108
const cellStatus = row.insertCell(-1);
103109
cellStatus.innerHTML = patient.status;
104110
const cellUsername = row.insertCell(-1);

dr-patient-view-controler.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { drPatientLib } from "./dr-patient-view-lib.js";
2+
3+
/**
4+
* Based on
5+
* - drApiConnecion
6+
* - patientApiConnection
7+
* - questionnaryId
8+
*
9+
* Display live update of data
10+
*/
11+
12+
13+
window.onload = async (event) => {
14+
refresh();
15+
}
16+
17+
const tableHeaders = {
18+
time: 'Date',
19+
formLabel: 'Questionnary',
20+
formType: 'Type',
21+
label: 'Label',
22+
value: 'Value',
23+
description: 'Description'
24+
}
25+
26+
async function refresh () {
27+
const { patientApiEndpoint, questionaryId } = getRequestFrormApiEndPoint();
28+
console.log('>> zz', patientApiEndpoint, questionaryId);
29+
const lines = await drPatientLib.getPatientData(patientApiEndpoint, questionaryId);
30+
const table = document.getElementById('patient-data-table');
31+
const headerRow = table.insertRow(-1);
32+
for (const thLabel of Object.values(tableHeaders)) {
33+
const headerCell = document.createElement("TH");
34+
headerCell.innerHTML = thLabel;
35+
headerRow.appendChild(headerCell);
36+
}
37+
for (const line of lines) {
38+
console.log('>> line', line);
39+
const row = table.insertRow(-1);
40+
for (const key of Object.keys(tableHeaders)) {
41+
const cell = row.insertCell(-1);
42+
const v = line[key];
43+
cell.innerHTML = v != null ? v : '' ;
44+
}
45+
}
46+
}
47+
48+
// ------- Get Dr's info -------- //
49+
function getRequestFrormApiEndPoint() {
50+
const params = new URLSearchParams(document.location.search);
51+
const patientApiEndpoint = params.get('patientApiEndpoint');
52+
const questionaryId = params.get('questionaryId');
53+
return { patientApiEndpoint, questionaryId };
54+
}

dr-patient-view-lib.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
import { dataDefs } from './common-data-defs.js';
3+
4+
export const drPatientLib = {
5+
getPatientData
6+
}
7+
8+
// prepare data for easy lookup
9+
// map streamId/EventType with form data
10+
const eventMapByQuestionnary = {};
11+
for (const [questionaryId, questionary] of Object.entries(dataDefs.questionnaires)) {
12+
eventMapByQuestionnary[questionaryId] = {};
13+
for (const form of Object.values(questionary.forms)) {
14+
for (const field of form.content) {
15+
eventMapByQuestionnary[questionaryId][field.streamId + ':' + field.eventType] = Object.assign({
16+
formLabel: form.name,
17+
formType: form.type
18+
}, field);
19+
}
20+
}
21+
}
22+
console.log('>> eventMapByQuestionnary', eventMapByQuestionnary);
23+
24+
async function getPatientData (patientApiEndoint, questionaryId) {
25+
const patientData = [];
26+
const queryParams = { limit: 10000};
27+
function forEachEvent(event) {
28+
patientData.push(getLineForEvent (event, questionaryId));
29+
}
30+
31+
const connection = new Pryv.Connection(patientApiEndoint);
32+
await connection.getEventsStreamed(queryParams, forEachEvent);
33+
return patientData;
34+
}
35+
36+
37+
function getLineForEvent (event, questionaryId) {
38+
const line = {
39+
time: (new Date(event.time * 1000)).toISOString(),
40+
formLabel: 'Unkown',
41+
formType: 'Unkown',
42+
label: event.streamId + ' - ' + event.type,
43+
value: JSON.stringify(event.content),
44+
description: ''
45+
}
46+
47+
const field = eventMapByQuestionnary[questionaryId][event.streamId + ':' + event.type];
48+
console.log('>> field', field, event);
49+
if (field) {
50+
Object.assign(line, field);
51+
if (field.type === 'date') {
52+
line.value = (new Date(event.time * 1000)).toISOString().split('T')[0];
53+
}
54+
if (field.type === 'select') {
55+
line.value = event.content;
56+
57+
const selected = field.options.find((o) => ( o.value === line.value ));
58+
line.description = selected?.label;
59+
}
60+
}
61+
return line;
62+
}

dr-patient-view.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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=Inter:300,400">
12+
<title>Demo Form - Dr's page</title>
13+
</head>
14+
<script src="https://pryv.github.io/lib-js/pryv.js"></script>
15+
<script type="module" src="dr-patient-view-controler.js"></script>
16+
17+
<body>
18+
<div class="container">
19+
<img src="https://healthdatasafe.github.io/style/images/Horizontal/hds-logo-hz-1024x400-hz-color.png" alt="Logo" width="300px">
20+
<h1>Demo Form - Dr's Patient View</h1>
21+
<div class="card">
22+
<div class="card-patient">
23+
Patient: <h2 class="patient-label">Patient X</h2>
24+
</div>
25+
</div>
26+
<div class="card" id="data-view">
27+
<table id="patient-data-table" class="table">
28+
29+
</table>
30+
</div>
31+
</div>
32+
</body>
33+
34+
</html>

0 commit comments

Comments
 (0)