bluebutton
Version:
BlueButton.js helps developers navigate complex health data with ease.
62 lines (53 loc) • 1.67 kB
JavaScript
/*
* ...
*/
/* exported BlueButton */
var BlueButton = function (source, opts) {
var type, parsedData, parsedDocument;
// Look for options
if (!opts) opts = {};
// Detect and parse the source data
parsedData = Core.parseData(source);
// Detect and parse the document
if (opts.parser) {
// TODO: parse the document with provided custom parser
parsedDocument = opts.parser();
} else {
type = Documents.detect(parsedData);
switch (type) {
case 'c32':
parsedData = Documents.C32.process(parsedData);
parsedDocument = Parsers.C32.run(parsedData);
break;
case 'ccda':
parsedData = Documents.CCDA.process(parsedData);
parsedDocument = Parsers.CCDA.run(parsedData);
break;
case 'json':
/* Expects a call like:
* BlueButton(json string, {
* generatorType: 'ccda',
* template: < EJS file contents >
* })
* The returned "type" will be the requested type (not "json")
* and the XML will be turned as a string in the 'data' key
*/
switch (opts.generatorType) {
// only the unit tests ever need to worry about this testingMode argument
case 'c32':
type = 'c32';
parsedDocument = Generators.C32.run(parsedData, opts.template, opts.testingMode);
break;
case 'ccda':
type = 'ccda';
parsedDocument = Generators.CCDA.run(parsedData, opts.template, opts.testingMode);
break;
}
}
}
return {
type: type,
data: parsedDocument,
source: parsedData
};
};