-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (48 loc) · 1.9 KB
/
index.js
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
import { Cookie } from "./helpers.js";
const fhirUrl = Cookie.get("fhir_url")
let token_data_cookie = Cookie.get('token_data')
const token_data = token_data_cookie != undefined ? JSON.parse(token_data_cookie) : null;
async function getPatient() {
if (!token_data.access_token || !token_data.patient) {
console.log('no access token or patient found in cookie')
return
}
let response = await fetch(fhirUrl + '/Patient/' + token_data.patient, {
headers: {
'Accept': 'application/json',
'mgw-custom-header-one': 'my-custom-header-value-when-reading-a-patient',
'Authorization': `Bearer ${token_data.access_token}`
}
})
return await response.json()
}
async function getUserPatient() {
if (!token_data.access_token || !token_data.user) {
console.log('no access token or fhirUser found in cookie')
return
}
let response = await fetch(fhirUrl + '/Patient/' + token_data.user, {
headers: {
'Accept': 'application/json',
'mgw-custom-header-two': 'my-custom-header-value-when-reading-a-practitioner',
'Authorization': `Bearer ${token_data.access_token}`
}
})
return await response.json()
}
getPatient().then((data) => {
console.log(data)
document.getElementById('mgw-data-url-patient').textContent = fhirUrl + '/Patient/' + token_data.patient
document.getElementById('mgw-data-content-patient').textContent= JSON.stringify(data)
}).catch((err) => {
debugger
console.log('error fetching patient data')
})
getUserPatient().then((data) => {
console.log(data)
document.getElementById('mgw-data-url-fhir-user').textContent = fhirUrl + '/Patient/' + token_data.user
document.getElementById('mgw-data-content-fhir-user').textContent= JSON.stringify(data)
}).catch((err) => {
debugger
console.log('error fetching user patient data')
})