Last active
April 11, 2019 17:01
-
-
Save hansenms/8233439bff73d2365b355e30263aefea to your computer and use it in GitHub Desktop.
Simple JS FHIR client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script> | |
</head> | |
<body> | |
<h1>FHIR Client Example</h1> | |
<div> | |
<p> | |
<b>Token:</b> | |
<div id="token"></div> | |
</p> | |
</div> | |
<div> | |
<p> | |
<b>Patients:</b> | |
<div id="patients"></div> | |
</p> | |
</div> | |
<script> | |
$(document).ready(function(){ | |
$.get("/.auth/me", function(data, status){ | |
//Print the token | |
$("#token").text(data[0].access_token); | |
//Get all patients | |
$.ajax( | |
{ | |
type: "GET", | |
url: "https://fhirsampdev.azurehealthcareapis.com/Patient", | |
beforeSend: function(xhdr) { | |
xhdr.setRequestHeader('Authorization', 'Bearer ' + data[0].access_token); | |
}, | |
success: function(result, status) { | |
//Create a list of patients | |
patientListHtml = '<ol>'; | |
$.each(result.entry, function(index, val){ | |
patientListHtml += '<li>' + val.resource.name[0].family + ', ' + val.resource.name[0].given + ' (' + val.resource.id + ')'; | |
}) | |
patientListHtml += '</ol>'; | |
$("#patients").html(patientListHtml); | |
} | |
} | |
); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment