How to fetch MedicationOrder resource using SMART on FHIR

113 views
Skip to first unread message

k1...@umbc.edu

unread,
Nov 28, 2018, 4:47:16 PM11/28/18
to Cerner FHIR Developers
Hi,

I am struggling with fetching medication order of Wilma Smart (Aspirin, Glucovance, etc) using SMART on FHIR js library. 

My code is based on Cerner's tutorial (https://engineering.cerner.com/smart-on-fhir-tutorial/).

Here is the code I tried. :

function onReady(smart)  {
      if (smart.hasOwnProperty('patient')) {
        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',
                              'http://loinc.org|3141-9']
                      }
                    }
                  });

        var medOrder = smart.patient.api.fetchAll({
          type: 'MedicationOrder',
          query: {
            patient: '4342008'
          }
        });
        console.log(medOrder);
        
       ...

I checked the console output for medOrder by Chrome inspection tool and it gave me this:

Screen Shot 2018-11-28 at 4.34.43 PM.png




























I also tried this but I got the same result

var medOrder = smart.patient.api.search({
          type: 'MedicationOrder',
          query: {
            patient: '4342008'
          }
        });

How can I fetch MedicationOrder resource?

Thank you

Kol Kheang (Cerner)

unread,
Nov 28, 2018, 10:41:45 PM11/28/18
to Cerner FHIR Developers
Hello!

I think when you call:

smart.patient.api.fetchAll

The patient is already in scope.  You don't need to include the patient id in the query, similar to the Observation code block above.

In your example, I don't see the call back function for the response of MedicationOrder.  Could you add code similar to this https://github.com/cerner/smart-on-fhir-tutorial/blob/gh-pages/example-smart-app/src/js/example-smart-app.js#L27-L68 to define callback for your MedicationOrder call?

You may want to check this out for more information about success/done call back.

You can set medication status in the query block if you wanted.  See our supported query params here: https://fhir.cerner.com/millennium/dstu2/medications/medication-order/#parameters


Regards,
Kol

k1...@umbc.edu

unread,
Nov 29, 2018, 4:52:43 PM11/29/18
to Cerner FHIR Developers
Thank you very much :)

I followed your advice and made it work with this code:

var medicationOrder = smart.patient.api.fetchAll({
          type: 'MedicationOrder',
          query: {
            _count: 4
          }
        });

  $.when(pt, medicationOrder).fail(onError);
  $.when(pt, medicationOrder).done(function(patient, medicationOrder) {
     console.log(medicationOrder);
  });

Actually, I am not a web developer, but I found Cerner's tutorial is the only tutorial which helps me understand how SMART on FHIR works.
Thank you for the tutorial and advice.

Kol Kheang (Cerner)

unread,
Nov 30, 2018, 4:18:34 PM11/30/18
to Cerner FHIR Developers
Awesome!  Glad you got it working!

Reply all
Reply to author
Forward
0 new messages