0

I'm working on creating a SMART on FHIR application based on the Cerner tutorial at https://engineering.cerner.com/smart-on-fhir-tutorial/.

The following is called in example-smart-app.js

    var patient = smart.patient;
    var pt = patient.read();
    var obv = smart.patient.api.fetchAll({
                type: 'Observation',
                query: {
                  code: {
                    $or: ['http://loinc.org|8302-2', 'http://loinc.org|8462-4',
                          'http://loinc.org|8480-6', 'http://loinc.org|2085-9',
                          'http://loinc.org|2089-1', 'http://loinc.org|55284-4']
                  }
                }
              });

I've modified slightly to the following:

    <script>
        fhirOnReady = function(smart) {
            patient = smart.patient;
            pt = patient.read();
            
            var obv = smart.patient.api.fetchAll({
                type: 'Observation',
                query: {
                  code: {
                    $or: [
                      'http://loinc.org|8302-2', 
                      'http://loinc.org|8462-4',
                      'http://loinc.org|8480-6', 
                      'http://loinc.org|2085-9',
                      'http://loinc.org|2089-1', 
                      'http://loinc.org|55284-4'
                    ]
                  }
                }
              });

            var populatePatientData = function(patient) {
                $("#fname").html(patient.name[0].given);
                $("#lname").html(patient.name[0].family);
                $("#gender").html(patient.gender);
                $("#dob").html(patient.birthDate);
            }
            
            $.when(pt, obv).fail(fhirOnError);
        
            $.when(pt, obv).done(
                function(patient, obv) {
                    populatePatientData(patient);
                    $("#patientJson").html(JSON.stringify(patient,undefined,2));
                    $("#patientSuccessMsg").html("<h1>Congratulations, you've also successfully loaded a patient using SMART on FHIR</h1>");
                }
            );

        };
        fhirOnError = function() {
            $("#patientJson").html("An error occurred.\nThis is expected if you are looking at this page from a browser.");
        };
        
        FHIR.oauth2.ready(fhirOnReady, fhirOnError);

    </script>

If I run the above using the SMART App Launcher at https://launch.smarthealthit.org/ everything seems to work as expected.

However, if I remove the call to smart.patient.api.fetchAll for the observations the patient JSON string is empty.

What is the correct way to get the entire patient resource using the SMART on FHIR JavaScript Library described at http://docs.smarthealthit.org/client-js/?

---EDIT ----------------------------------

If I try to implement using the code in the documentation at http://docs.smarthealthit.org/client-js/#smart-api I get the error shown below.

Code

<!-- index.html -->
<script src="./node_module/fhirclient/build/fhir-client.js"></script>
<script>
FHIR.oauth2.ready()
    .then(client => client.request("Patient"))
    .then(console.log)
    .catch(console.error);
</script>

Error enter image description here

Libraries are taken directly from the Cerner tutorial.
enter image description here

John
  • 3,458
  • 4
  • 33
  • 54

1 Answers1

0

SMART apps usually have a "patient" in context that is already part of the data passed over to the system from which you are trying to elicit information. In this case you are trying to hit the Cerner FHIR server to get the observations linked to that Patient. Two things are possible at this point:

  1. The Server may not have the Patient resource, which is why it is using the Id of the patient to fetch all observations
  2. Check your smart SCOPEs, you may not be allowed to read Patient records in it's entirety.
  3. Usually the FHIR endpoint can be deciphered using Fiddler following the launch sequence. As per the SMART exchange the CapabilityStatement is queried for the authorization and Token endpoints. If you are able to see the server then you can tack on the /Patient/id to get the resource but this means you have to have a valid token and the appropriate scope statements in place.
Spindoctor
  • 434
  • 3
  • 17