Versions Compared

Key

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

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.

...

To retrieve and update FHIR Resources, you need to first authorize your app and get a fhirClientFHIR 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 just 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 IdID.

Code Block
languagejs
titleUpdate a Resource
<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>