Hello,
my group is developing an EHR app, an for self-teaching purposes I am currently fiddling around with a JS script, written originally for v1 of the SMART on FHIR client but now trying to make it compatible with v2. (I didn't write it myself; it comes from this tutorial
https://engineering.cerner.com/smart-on-fhir-tutorial/)
So far, I have successfully launched the SMART app, and the OAuth2 has gone through, creating a FHIR Client (smart.patient) object.
Then, I tried to submit a smart.patient.request() for Nancy Smart: smart.patient.request(...input parameters...)
The resulting promise gets fulfilled, and when I use console.dir(patient) to look at what is there, I see that the Promise object does indeed contain the name, gender, address, and other requested information from the query for this patient. However, any subsequent attempts to read the properties of this patient (e.g., name) will fail, with the console error saying this property cannot be read because it is "undefined".
The script is written with JQuery; if "pt" is the result of patient.read() (which is fulfilled) and "obv" is the smart.patient.request(...) (which is also fulfilled), then trying to do something like the lines below:
$.when(pt, obv).done(function (patient, obv) {
var fname = '';
var lname = '';
if (typeof
patient.name[0] !== 'undefined') {
fname =
patient.name[0].given.join(' ');
lname =
patient.name[0].family.join(' ');
}
});
this will fail with the error that patient.gender is undefined, even though I can see in the console (if I print "patient" there) that it shouldn't be. This when(...).done(...){} segment worked with the v1 FHIR client; is there anything about v2 that would break it? If so, what?
Any advice as to how I can debug this would be greatly appreciated, and let me know if anything in my problem statement was unclear (I am still new to SMART/FHIR lingo).
Thanks,
Francesca Ricci-Tam