Skip to content

Commit cc9b2f7

Browse files
committed
Initial code
1 parent 9440d4f commit cc9b2f7

6 files changed

Lines changed: 304 additions & 0 deletions

File tree

dr-controler.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* UI management code.
3+
* Relies on drLib for API calls and data management
4+
* @param {*} event
5+
*/
6+
7+
8+
9+
window.onload = (event) => {
10+
stateChange('loggedOut');
11+
drLib.showLoginButton('login-button', stateChange);
12+
};
13+
14+
function stateChange(state) {
15+
if (state === 'loggedIN') {
16+
document.getElementById('please-login').style.visibility = 'hidden';
17+
document.getElementById('data-view').style.visibility = 'visible';
18+
} else {
19+
document.getElementById('please-login').style.visibility = 'visible';
20+
document.getElementById('data-view').style.visibility = 'hidden';
21+
}
22+
}

dr-lib.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
let connection = null;
2+
3+
const drLib = {
4+
showLoginButton
5+
6+
}
7+
8+
function showLoginButton (loginSpanId, stateChangeCallBack) {
9+
10+
const authSettings = {
11+
spanButtonID: loginSpanId, // div id the DOM that will be replaced by the Service specific button
12+
onStateChange: pryvAuthStateChange, // event Listener for Authentication steps
13+
authRequest: { // See: https://api.pryv.com/reference/#auth-request
14+
requestingAppId: 'demo-dr-form-dr', // to customize for your own app
15+
requestedPermissions: [
16+
{
17+
streamId: '*',
18+
level: 'manage'
19+
}
20+
],
21+
clientData: {
22+
'app-web-auth:description': {
23+
'type': 'note/txt',
24+
'content': 'This app allows to send invitation links to patients and visualize and export answers.'
25+
}
26+
},
27+
}
28+
};
29+
30+
// following the APP GUIDELINES: https://api.pryv.com/guides/app-guidelines/
31+
const serviceInfoUrl = Pryv.Browser.serviceInfoFromUrl() || 'https://demo.datasafe.dev/reg/service/info';
32+
Pryv.Browser.setupAuth(authSettings, serviceInfoUrl);
33+
34+
async function pryvAuthStateChange(state) { // called each time the authentication state changes
35+
console.log('##pryvAuthStateChange', state);
36+
if (state.id === Pryv.Browser.AuthStates.AUTHORIZED) {
37+
connection = new Pryv.Connection(state.apiEndpoint);
38+
await initPatientAccount(connection);
39+
stateChangeCallBack('loggedIN');
40+
}
41+
if (state.id === Pryv.Browser.AuthStates.INITIALIZED) {
42+
connection = null;
43+
stateChangeCallBack('loggedOUT');
44+
}
45+
}
46+
}
47+
48+
async function initPatientAccount (connection) {
49+
// create stream structure (even if already exists)
50+
const apiCalls = [
51+
{
52+
method: 'streams.create',
53+
params: {
54+
id: 'patients',
55+
name: 'Patients'
56+
}
57+
},
58+
{
59+
method: 'streams.create',
60+
params: {
61+
id: 'patients-inbox',
62+
name: 'Patients Inbox',
63+
parentId: 'patients'
64+
}
65+
},
66+
{
67+
method: 'streams.create',
68+
params: {
69+
id: 'patients-validated',
70+
name: 'Patients Validted',
71+
parentId: 'patients'
72+
}
73+
},
74+
{
75+
method: 'streams.create',
76+
params: {
77+
id: 'demo-dr-forms',
78+
name: 'Demo Dr Forms'
79+
}
80+
},
81+
{
82+
method: 'streams.create',
83+
params: {
84+
id: 'demo-dr-forms-questionary-x',
85+
name: 'Questionnary x'
86+
}
87+
}
88+
];
89+
const result = await connection.api(apiCalls);
90+
console.log(result);
91+
console.log('## Dr account initialized')
92+
}

dr.html

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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="stylesheet" type="text/css" href="https://api.pryv.com/style/pryv2.min.css">
10+
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400">
11+
<title>Demo Form - Dr's page</title>
12+
</head>
13+
<script src="https://pryv.github.io/lib-js/pryv.js"></script>
14+
<script src="dr-controler.js"></script>
15+
<script src="dr-lib.js"></script>
16+
17+
<body>
18+
<div class="container">
19+
<h1>Demo Form - Dr's page</h1>
20+
<div class="card">
21+
<div class="card-body">
22+
<h2 class="card-title">Welcome</h2>
23+
<span id="login-button"></span>
24+
<br><br>
25+
<span id="welcome-message-mme">
26+
Dear Dr, from this page, you can visualize the data from patients and share an invitation to fill your questionnary.
27+
</span>
28+
<br>
29+
<span id="welcome-message-viewer" style="visibility: hidden;"> Welcome message
30+
</span>
31+
<br>
32+
<span id="please-login">
33+
Please login.
34+
</span>
35+
</div>
36+
</div>
37+
<div class="card" id="data-view" style="visibility: hidden;">
38+
<div class="card-body">
39+
<h2 class="card-title">Data</h2>
40+
<table id='patients-table' class="table">
41+
<thead>
42+
<tr>
43+
<th colspan="2"><b>Patients</b></td>
44+
</tr>
45+
<tr>
46+
<th scope="col">Date</th>
47+
<th scope="col">Name</th>
48+
</tr>
49+
</thead>
50+
<tbody>
51+
</tbody>
52+
</table>
53+
<table id='patients-details-table' class="table">
54+
<thead>
55+
<tr>
56+
<th colspan="3"><b>Blood pressure</b></td>
57+
</tr>
58+
<tr>
59+
<th scope="col">Date</th>
60+
<th scope="col">Systolic</th>
61+
<th scope="col">Diastolic</th>
62+
</tr>
63+
</thead>
64+
<tbody>
65+
</tbody>
66+
</table>
67+
</div>
68+
</div>
69+
</div>
70+
</body>
71+
72+
</html>

patient-controler.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* UI management code.
3+
* Relies on patientLib for API calls and data management
4+
* @param {*} event
5+
*/
6+
7+
8+
9+
window.onload = (event) => {
10+
stateChange('loggedOut');
11+
drLib.showLoginButton('login-button', stateChange);
12+
};
13+
14+
function stateChange(state) {
15+
if (state === 'loggedIN') {
16+
document.getElementById('please-login').style.visibility = 'hidden';
17+
document.getElementById('data-view').style.visibility = 'visible';
18+
} else {
19+
document.getElementById('please-login').style.visibility = 'visible';
20+
document.getElementById('data-view').style.visibility = 'hidden';
21+
}
22+
}

patient-lib.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
let connection = null;
2+
3+
const drLib = {
4+
showLoginButton
5+
6+
}
7+
8+
function showLoginButton (loginSpanId, stateChangeCallBack) {
9+
10+
const authSettings = {
11+
spanButtonID: loginSpanId, // div id the DOM that will be replaced by the Service specific button
12+
onStateChange: pryvAuthStateChange, // event Listener for Authentication steps
13+
authRequest: { // See: https://api.pryv.com/reference/#auth-request
14+
requestingAppId: 'demo-dr-form-patient', // to customize for your own app
15+
requestedPermissions: [
16+
{
17+
streamId: '*',
18+
level: 'manage'
19+
}
20+
],
21+
clientData: {
22+
'app-web-auth:description': {
23+
'type': 'note/txt',
24+
'content': 'This app allows to fill a form and share information with your doctor.'
25+
}
26+
},
27+
}
28+
};
29+
30+
// following the APP GUIDELINES: https://api.pryv.com/guides/app-guidelines/
31+
const serviceInfoUrl = Pryv.Browser.serviceInfoFromUrl() || 'https://demo.datasafe.dev/reg/service/info';
32+
Pryv.Browser.setupAuth(authSettings, serviceInfoUrl);
33+
34+
async function pryvAuthStateChange(state) { // called each time the authentication state changes
35+
console.log('##pryvAuthStateChange', state);
36+
if (state.id === Pryv.Browser.AuthStates.AUTHORIZED) {
37+
connection = new Pryv.Connection(state.apiEndpoint);
38+
await initPatientAccount(connection);
39+
stateChangeCallBack('loggedIN');
40+
}
41+
if (state.id === Pryv.Browser.AuthStates.INITIALIZED) {
42+
connection = null;
43+
stateChangeCallBack('loggedOUT');
44+
}
45+
}
46+
}
47+
48+
async function initPatientAccount (connection) {
49+
50+
console.log('## Patient account initialized')
51+
}

patient.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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="stylesheet" type="text/css" href="https://api.pryv.com/style/pryv2.min.css">
10+
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400">
11+
<title>Demo Form - Patient's page</title>
12+
</head>
13+
<script src="https://api.pryv.com/lib-js/pryv.js"></script>
14+
<script src="patient-controler.js"></script>
15+
<script src="patient-lib.js"></script>
16+
17+
<body>
18+
<div class="container">
19+
<h1>Demo Form - Patient's page</h1>
20+
<div class="card">
21+
<div class="card-body">
22+
<h2 class="card-title">Welcome</h2>
23+
<span id="login-button"></span>
24+
<br><br>
25+
<span id="welcome-message-mme">
26+
Dear Madam, from this page you will answer a questionnary to be shared with your Doctor.
27+
</span>
28+
<br>
29+
<span id="welcome-message-viewer" style="visibility: hidden;"> Welcome message
30+
</span>
31+
<br>
32+
<span id="please-login">
33+
Please login.
34+
</span>
35+
</div>
36+
</div>
37+
<div class="card" id="data-view" style="visibility: hidden;">
38+
Data
39+
</div>
40+
41+
42+
</div>
43+
</body>
44+
45+
</html>

0 commit comments

Comments
 (0)