Published
Edited
Apr 14, 2022
1 fork
Insert cell
Insert cell
Insert cell
mutable redirect_uri = "https://observablehq.com/@maloykr1212/fhir-and-observable"
Insert cell
mutable client_id = "2e5f1f2f-583f-425f-8b1f-180107eaef22"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable pretoken = {
var details = {
'code': code.code,
'grant_type': 'authorization_code',
'redirect_uri': redirect_uri,
'client_id': client_id
};

var formBody = [];
for (var property in details) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(details[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
var url = "https://authorization.cerner.com/tenants/ec2458f2-1e24-41c8-b71b-0e701af7583d/protocols/oauth2/profiles/smart-v1/token"
return {url:url, formBody:formBody}
}
Insert cell
Insert cell
token = (fetch(pretoken.url, {
headers:{
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
mode: 'cors',
body: pretoken.formBody,
method: "post",
}).then(response => {
if (!response.ok) throw new Error(response.status);
return response.json();
}).catch(error => {return error;}))
Insert cell
conditions = (fetch("https://fhir-myrecord.cerner.com/r4/ec2458f2-1e24-41c8-b71b-0e701af7583d/Condition?patient="+token.patient, {
headers:{
"Accept": "application/json",
"Authorization": "Bearer "+token.access_token
}
}).then(response => {
if (!response.ok) throw new Error(response.status);
return response.json();
}).catch(error => {return error;}))
Insert cell
Insert cell
Inputs.table(results)
Insert cell
Insert cell
SummaryTable(results)
Insert cell
Plot.dot(results,{
x:"recordedDate",
y:"code"
}).plot()
Insert cell
Plot.plot({
marginLeft: 220,
marks: [
Plot.barX(results, Plot.groupY({x: "sum"}, {y: "code", sort: {y: "x", reverse: true, limit: 10}}))
]
})
Insert cell
Plot.plot({
marginLeft: 220,
marks: [
Plot.barX(results, Plot.groupY({x: "sum"}, {y: "clinicalStatus", sort: {y: "x", reverse: true, limit: 10}}))
]
})
Insert cell
Plot.plot({
marginLeft:200,
marks: [
Plot.barX(results, Plot.groupY({x: "sum"}, {y: "clinicalStatus", sort: {y: "x", reverse: true, limit: 10}}))
]
})
Insert cell
Insert cell
signin = {
//note, you prob want to respect state, it is hard coded here
const url = "https://authorization.cerner.com/tenants/ec2458f2-1e24-41c8-b71b-0e701af7583d/protocols/oauth2/profiles/smart-v1/personas/patient/authorize?response_type=code&client_id="+client_id+"&scope=patient%2FObservation.read%20patient%2FCondition.read%20patient%2FPatient.read%20patient%2FServiceRequest.read%20patient%2Flaunch&redirect_uri="+encodeURIComponent(redirect_uri)+"&aud=https%3A%2F%2Ffhir-myrecord.cerner.com%2Fr4%2Fec2458f2-1e24-41c8-b71b-0e701af7583d&state=eoEMUE98YP5HI591";
invalidation.then(() => URL.revokeObjectURL(url));
return function() {
return new Promise((resolve, reject) => {
const popup = window.open(url, "_blank");
popup.addEventListener("submit", event => {
event.preventDefault();
popup.close();
const login = event.target.login.value.trim();
if (!login) return reject(new Error("empty"));
resolve({login});
});
popup.addEventListener("unload", () => {
if (popup.closed) reject(new Error("closed"));
});
});
};
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more