Introduction
Excerpt |
---|
This sample will show demonstrate how to update a FHIR Patient Resource using the FHIR RESTful API and the SMART on FHIR JavaScript Client. |
FHIR RESTful API
Query to find the Patient
Given a patient id "UpdateExamplePatient", find the patient:
SMART on FHIR JavaScript Client
*Note, this example is not following the SMART on FHIR launch specification. In your code, you will not connect to an EHR this way, but will be given the serviceUrl and patient values from the launch request. See Quick Start for details.
...
Authorize Your App
To retrieve and update FHIR Resources, you need to first authorize your app and get a FHIR Client.
Query A Patient Resource and Update Last Name
In this snippet, we have a readPatient function which retrieves the Patient FHIR Resource and stores the result in a var named patient. The updatePatient function updates the patient's family name. (A Patient FHIR Resource can have multiple names and multiple family names within each name. We are simply updating the first family name for the first name ex. patient.name[0].family[0]) The updatePatient function then uses the fhirClient to update the FHIR Resource, passing the resource type, stringified Patient Resource and the Patient Resource ID.
Code Block | ||||
---|---|---|---|---|
| ||||
<script type="text/javascript">
...
var patient;
// Read patient
function readPatient() {
fhirClient.patient.read().then(function(pt) {
patient = pt;
});
}
function updatePatient() {
patient.name[0].family[0] = "NewName";
fhirClient.api.update({type: patient.resourceType, data: JSON.stringify(patient), id: patient.id}).then(function(){
readPatient()
});
...
</script> |