-
Notifications
You must be signed in to change notification settings - Fork 1
/
launcher.html
194 lines (186 loc) · 6.39 KB
/
launcher.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html>
<head>
<title>SMART App launcher</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
}
h1 {
color: #333;
}
#container {
display: flex;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
#left-content, #right-content {
flex: 1;
padding: 20px;
background-color: #fff;
}
#left-content {
border-right: 1px solid #ccc;
}
/* Center headings in their containers */
#left-content h1, #right-content h1 {
text-align: center;
}
#patientList ul {
list-style-type: none;
padding: 0;
}
#patientList li {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
padding: 10px;
border-bottom: 1px solid #eee;
}
.launch-button {
background-color: #007BFF;
color: #fff;
padding: 6px 12px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
}
.launch-button:hover {
background-color: #0056b3;
}
/* Center the button on the right side */
#right-content {
text-align: center;
}
/* Center the main title */
body > h1 {
text-align: center;
margin-top: 20px;
}
/* Style paragraphs */
#left-content p, #right-content p {
text-align: left;
color: #555;
margin-bottom: 15px;
}
</style>
</head>
<body>
<h1>Demo Launcher</h1>
<div id="container">
<div id="left-content">
<div id="patientList">
<h1>EHR Launch</h1>
<p>
This emulates the launch process from an EHR. You can select the patient context and launch the "Growth Chart" Smart App.
</p>
<p>
Please use "Sign in with Keycloak". Credentials:<br>
<strong>Username:</strong> patient<br>
<strong>Password:</strong> password
</p>
<ul id="patients"></ul>
</div>
</div>
<div id="right-content">
<h1>Patient Standalone Launch</h1>
<p>This emulates the patient standalone launch process. You need to launch the smart app. Your patient context has already been selected.</p>
<button class="launch-button" onclick="launch('4013bde2-8ef4-54ef-8790-11413950fc72')">Launch Growth Chart App</button>
</div>
</div>
<script>
// Client credentials
const client_id = 'ehr';
const client_secret = 'verysecret';
// Encode credentials in Base64
const credentials = btoa(client_id + ':' + client_secret);
// Headers for Basic Authentication
const headers = {
'Authorization': 'Basic ' + credentials
};
// FHIR API endpoint
const fhirUrl = 'http://localhost:8080/fhir/Patient?_count=20&birthdate=ge2000';
// Fetch patients using Basic Auth
fetch(fhirUrl, {
method: 'GET',
headers: headers
})
.then(response => response.json())
.then(fhirData => {
displayPatients(fhirData);
})
.catch(error => {
console.error('Error fetching patients:', error);
});
function launch(patientId) {
const fhirUrl = 'http://localhost:8080/rpc';
let body = {
method: "aidbox.smart/get-launch-uri",
params: {
user: "practitioner",
iss: "http://localhost:8080/fhir",
client: "growth_chart",
ctx: { patient: patientId }
}
};
fetch(fhirUrl, {
method: 'POST',
headers: {
'Authorization': 'Basic ' + credentials,
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
})
.then(response => response.json())
.then(resp => {
window.location = resp.result.uri;
})
.catch(error => {
console.error('Error launching app:', error);
});
}
function displayPatients(fhirData){
const patientList = document.getElementById('patientList');
patientList.style.display = 'block';
const patientsUl = document.getElementById('patients');
patientsUl.innerHTML = '';
if(fhirData && fhirData.entry){
fhirData.entry.forEach(function(entry){
const patient = entry.resource;
let name = 'Unknown';
let id = patient.id;
if(patient.name && patient.name.length > 0){
const nameObj = patient.name[0];
const given = nameObj.given ? nameObj.given.join(' ') : '';
const family = nameObj.family || '';
const birthDate = patient.birthDate || '';
name = `${given} ${family} (${birthDate})`;
}
const li = document.createElement('li');
const nameSpan = document.createElement('span');
nameSpan.innerHTML = `<strong>${name}</strong>`;
const button = document.createElement('button');
button.className = 'launch-button';
button.innerText = 'Launch Growth Chart App';
button.onclick = function() {
launch(id);
};
li.appendChild(nameSpan);
li.appendChild(button);
patientsUl.appendChild(li);
});
} else {
const li = document.createElement('li');
li.textContent = 'No patients found.';
patientsUl.appendChild(li);
}
}
</script>
</body>
</html>