Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Excerpt

This sample will show 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:

...

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.

Code Block
languagejs
titleUpdate a Resource
<script type="text/javascript">
...
var patient;

// Read patient
function readPatient() {
  smartfhirClient.patient.read().then(function(pt) {
    patient = pt;
  });
}

function updatePatient() {
  patient.name[0].family[0] = "NewName";
  smartfhirClient.api.update({type: patient.resourceType, data: JSON.stringify(patient), id: patient.id}).then(function(){
        readPatient()
  });
...
</script>