I'm experimenting with this application using the FHIR.js API and would like to create an iterator for any CarePlans that reference multiple goals; if a person clicks on an arrow the user can cycle through the goals by a click action event. I'm using a generator function and it seems to work, but I'm receiving an undefined value on the first call of my .next
method. Can anyone care to explain why this provides the first yield using this function?
refs = ["#goal-1", "#goal-2", "#goal-3", "#goal-4", "#goal-5"];
//Goal Id tags referenced for CarePlan
function* referenceGetter(refs, resource) {
var i=0;
var x;
while (true){
window.FHIR.oauth2.ready(smart=>{
smart.api.search({type: resource, query:{_id: refs[i]}})
.done(e=>{x =
e.data.entry[0].resource;i++;
})
.fail(err=>{x= err;i++;});
});
//Yield the returned bundles here;
yield x;
}
}
When I run:
getRefs = referenceGetter(refs, "Goal");
getRefs.next()
The first return object is
{value: undefined, done: true}
But then it retrieves the first reference to the first id if I call it again. Any help would be immensely appreciated.
Thank You
Consider:
I'm utilizing the stu3-ver smart-on-fhir api.