fhir.js
Version:
FHIR javascript client
58 lines (50 loc) • 1.66 kB
JavaScript
// Generated by CoffeeScript 1.9.3
(function() {
var ltype, merge, resolve, utils, wrap;
var resolve = require('./references');
merge = require('merge');
utils = require('../utils');
ltype = utils.type;
wrap = function(cfg, search) {
var resourceBoundary;
resourceBoundary = function(stack) {
var res;
res = function(acc, val) {
return acc != null ? acc : ((val != null ? val.resourceType : void 0) && (val != null ? val.contained : void 0) ? val : null);
};
return stack.reduce(res, null);
};
return function(params) {
var graph, graphCb, graphify, success, type;
type = params.type, success = params.success, graph = params.graph;
graphify = function(bundle, content) {
var resolveRefs;
resolveRefs = function(value, context) {
var mapto, ref;
if (value.reference) {
mapto = resolve.sync(merge(true, params, {
reference: value,
bundle: bundle,
resource: resourceBoundary(context)
}));
return (ref = mapto != null ? mapto.content : void 0) != null ? ref : value;
} else {
return value;
}
};
return utils.postwalk(resolveRefs, content, []);
};
graphCb = graph ? function(bundle, status, xhr) {
var entries;
entries = bundle.entry.map(function(e) {
return e.content;
});
return success(graphify(bundle, entries));
} : success;
return search(merge(true, params, {
success: graphCb
}));
};
};
module.exports = wrap;
}).call(this);