Skip to content

Commit 61bb099

Browse files
committed
Now creating link for Dr
1 parent bbf57b5 commit 61bb099

6 files changed

Lines changed: 91 additions & 12 deletions

File tree

Technical_flow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ They contains personal data with the following streams
3838
- profile-date-of-birth: - event of type "date/iso-8601"
3939
- profile-location: - event of type (to be discussed) "contact/vcard" or "location/city"
4040
- profile-sex: - event of type "attributes/biological-sex"
41-
- familly
42-
- familly-children: events of type "count/generic"
41+
- family
42+
- family-children: events of type "count/generic"
4343
- fertility
4444
- fertility-miscarriages: events of type "count/generic"
4545
- awarness-training: events of type "training/fabm-v1"

dr-controler.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* UI management code.
33
* Relies on drLib for API calls and data management
4+
* Used to seprate the UI from the API calls
45
* @param {*} event
56
*/
67

@@ -15,8 +16,23 @@ function stateChange(state) {
1516
if (state === 'loggedIN') {
1617
document.getElementById('please-login').style.visibility = 'hidden';
1718
document.getElementById('data-view').style.visibility = 'visible';
19+
setSharingLink();
1820
} else {
1921
document.getElementById('please-login').style.visibility = 'visible';
2022
document.getElementById('data-view').style.visibility = 'hidden';
2123
}
2224
}
25+
26+
async function setSharingLink() {
27+
28+
29+
const currentPage = window.location.href;
30+
const posDrHTML = currentPage.indexOf('dr.html');
31+
const patientURL = currentPage.substring(0, posDrHTML) + 'patient.html';
32+
33+
const sharedApiEndpoint = await drLib.getSharingToken();
34+
const sharingLink = patientURL + '?sharedApiEndpoint=' + sharedApiEndpoint;
35+
const sharingMailBody = 'Hello,\n\nI am sending you a link to fill out a form.\nPlease click on the link below to access the form: \n\n' + sharingLink + '\n\nBest regards,\nYour Doctor';
36+
const sharingLinkHTML = `<A HREF="mailto:?subject=Invitation&body=${encodeURI(sharingMailBody)}">Send by email</A> - ${sharingLink}`;
37+
document.getElementById('sharing-link').innerHTML = sharingLinkHTML;
38+
}

dr-lib.js

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
let connection = null;
22

33
const drLib = {
4-
showLoginButton
5-
4+
showLoginButton,
5+
getSharingToken
66
}
77

88
function showLoginButton (loginSpanId, stateChangeCallBack) {
@@ -35,7 +35,7 @@ function showLoginButton (loginSpanId, stateChangeCallBack) {
3535
console.log('##pryvAuthStateChange', state);
3636
if (state.id === Pryv.Browser.AuthStates.AUTHORIZED) {
3737
connection = new Pryv.Connection(state.apiEndpoint);
38-
await initPatientAccount(connection);
38+
await initDrAccount(connection);
3939
stateChangeCallBack('loggedIN');
4040
}
4141
if (state.id === Pryv.Browser.AuthStates.INITIALIZED) {
@@ -45,7 +45,64 @@ function showLoginButton (loginSpanId, stateChangeCallBack) {
4545
}
4646
}
4747

48-
async function initPatientAccount (connection) {
48+
49+
/**
50+
* Initialize the doctor account
51+
* @param {*} connection
52+
*/
53+
async function initDrAccount (connection) {
54+
await initStreams(connection);
55+
console.log('## Dr account initialized')
56+
}
57+
58+
/**
59+
* Initialize or get the sharing token for patients
60+
* @returns
61+
*/
62+
async function getSharingToken () {
63+
const accessesCheckRes = await connection.api([{ method: 'accesses.get', params: {}}]);
64+
const sharedAcess = accessesCheckRes[0].accesses.find(access => access.name === 'demo-dr-form-shared');
65+
if (sharedAcess) {
66+
console.log('## Dr account already has a shared access');
67+
return sharedAcess.apiEndpoint;
68+
}
69+
const accessRes = await connection.api([{
70+
method: 'accesses.create',
71+
params: {
72+
name: 'demo-dr-form-shared',
73+
type: 'shared',
74+
permissions: [{
75+
streamId: 'patients-inbox',
76+
level: 'create-only'
77+
},
78+
{
79+
streamId: 'demo-dr-forms-questionary-x',
80+
level: 'read'
81+
},
82+
{ // for "publicly shared access" always forbid the selfRevoke feature
83+
feature: "selfRevoke",
84+
setting: "forbidden"
85+
}],
86+
clientData: {
87+
'demo-dr-form': {
88+
questionaryId: 'demo-dr-forms-questionary-x'
89+
}
90+
}
91+
}
92+
}]);
93+
console.log('## Dr account shared access created', accessRes);
94+
return accessRes[0].access.apiEndpoint;
95+
}
96+
97+
98+
async function initStreams () {
99+
// check if the account is already initialized
100+
const resStreams = await connection.api([{ method: 'streams.get', params: { parentId: 'patients' } }]);
101+
if (resStreams[0].streams.length > 0) {
102+
console.log('## Dr account streams already initialized');
103+
return;
104+
}
105+
49106
// create stream structure (even if already exists)
50107
const apiCalls = [
51108
{
@@ -87,6 +144,5 @@ async function initPatientAccount (connection) {
87144
}
88145
];
89146
const result = await connection.api(apiCalls);
90-
console.log(result);
91-
console.log('## Dr account initialized')
147+
console.log('## Dr account streams created', result);
92148
}

dr.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
88
<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">
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">
1011
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400">
1112
<title>Demo Form - Dr's page</title>
1213
</head>
@@ -35,6 +36,11 @@ <h2 class="card-title">Welcome</h2>
3536
</div>
3637
</div>
3738
<div class="card" id="data-view" style="visibility: hidden;">
39+
<div class="card-body">
40+
<h2 class="card-title">Sharing link</h2>
41+
<span id="sharing-link">
42+
43+
</div>
3844
<div class="card-body">
3945
<h2 class="card-title">Data</h2>
4046
<table id='patients-table' class="table">

patient-controler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* UI management code.
33
* Relies on patientLib for API calls and data management
4+
*
45
* @param {*} event
56
*/
67

patient-lib.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function showLoginButton (loginSpanId, stateChangeCallBack) {
6262
console.log('##pryvAuthStateChange', state);
6363
if (state.id === Pryv.Browser.AuthStates.AUTHORIZED) {
6464
connection = new Pryv.Connection(state.apiEndpoint);
65-
await initPatientAccount(connection);
65+
await initDrAccount(connection);
6666
stateChangeCallBack('loggedIN');
6767
}
6868
if (state.id === Pryv.Browser.AuthStates.INITIALIZED) {
@@ -73,7 +73,7 @@ function showLoginButton (loginSpanId, stateChangeCallBack) {
7373
}
7474

7575
// Creates the streams structure for the patient account after the user has logged in
76-
async function initPatientAccount (connection) {
76+
async function initDrAccount (connection) {
7777
const patientBaseStreams = [
7878
// profile
7979
{id: 'profile-name', name: 'Name', parentId: 'profile'},
@@ -180,7 +180,7 @@ async function handleFormSubmit (values) {
180180
}
181181

182182
if (value === field.value || value === '') {
183-
// no change
183+
// no change or noting to create
184184
continue;
185185
}
186186

0 commit comments

Comments
 (0)