Introduction
This sample will demonstrate how to update a FHIR Patient Resource using the FHIR RESTful API and the SMART on FHIR JavaScript Client.
Authorize Your App
To retrieve and update FHIR Resources, you need to first authorize your app and get a fhirClient.
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 just 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.
<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>