Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
Simplifying parsers, prepping for v0.1
Browse files Browse the repository at this point in the history
- Parsers for each doc type are now in a single file under the
`lib/parsers` directory
- Added new DSL functions for parsing (will be further abstracted to
core lib in the future)
- Adding placeholders for generators, renderers
- Cleaning up JSHint issues
  • Loading branch information
blacktm committed Apr 23, 2014
1 parent 7b6c75a commit 4c8e168
Show file tree
Hide file tree
Showing 34 changed files with 1,902 additions and 2,324 deletions.
13 changes: 10 additions & 3 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
{
"bitwise": true,
"browser": true,
"browser": true,
"devel": true,
"eqeqeq": true,
"es5": true,
"forin": true,
"freeze": true,
"immed": true,
"latedef": true,
"maxlen": 80,
"maxlen": 100,
"newcap": true,
"noarg": true,
"node": true,
"noempty": true,
"nonew": true,
"regexp": true,
"trailing": true,
"undef": true,
"unused": true,
"globals": {
"core": true
"ActiveXObject": false,
"BlueButton": true,
"Codes": true,
"Core": true,
"Parsers": true,
"XML": true
}
}
51 changes: 15 additions & 36 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
module.exports = function(grunt) {

// Configurable paths
var bbConfig = {
build: "./build",
src: "./lib",
test: "./spec/javascripts",
samples: "./sample_data"
};

// Project configuration.
grunt.initConfig({
bb: bbConfig,
pkg: grunt.file.readJSON("package.json"),
banner: "/* BlueButton.js -- <%= pkg.version %> */\n\n",

clean: {
build: ["<%= bb.build %>"]
},

jshint: {
options: {
jshintrc: ".jshintrc"
Expand All @@ -29,7 +29,7 @@ module.exports = function(grunt) {
src: ["<%= bb.build %>/{,*/}*.foo"]
}
},

concat: {
all: {
options: {
Expand All @@ -40,42 +40,21 @@ module.exports = function(grunt) {
"<%= bb.src %>/core.js",
"<%= bb.src %>/xml.js",
"<%= bb.src %>/codes.js",

"<%= bb.src %>/c32/c32.js",
"<%= bb.src %>/c32/allergies.js",
"<%= bb.src %>/c32/demographics.js",
"<%= bb.src %>/c32/encounters.js",
"<%= bb.src %>/c32/immunizations.js",
"<%= bb.src %>/c32/labs.js",
"<%= bb.src %>/c32/medications.js",
"<%= bb.src %>/c32/problems.js",
"<%= bb.src %>/c32/procedures.js",
"<%= bb.src %>/c32/vitals.js",

"<%= bb.src %>/ccda/ccda.js",
"<%= bb.src %>/ccda/allergies.js",
"<%= bb.src %>/ccda/demographics.js",
"<%= bb.src %>/ccda/encounters.js",
"<%= bb.src %>/ccda/immunizations.js",
"<%= bb.src %>/ccda/labs.js",
"<%= bb.src %>/ccda/medications.js",
"<%= bb.src %>/ccda/problems.js",
"<%= bb.src %>/ccda/procedures.js",
"<%= bb.src %>/ccda/vitals.js",

"<%= bb.src %>/parsers/c32.js",
"<%= bb.src %>/parsers/ccda.js",
"<%= bb.src %>/bluebutton.js"
],
dest: "<%= bb.build %>/bluebutton.js"
}
},

umd: {
all: {
src: "<%= bb.build %>/bluebutton.js",
objectToExport: "BlueButton"
}
},

uglify: {
all: {
options: {
Expand All @@ -85,7 +64,7 @@ module.exports = function(grunt) {
dest: "<%= bb.build %>/bluebutton.min.js"
}
},

jasmine: {
browser: {
options: {
Expand All @@ -103,7 +82,7 @@ module.exports = function(grunt) {
src: "<%= bb.build %>/bluebutton.js",
}
},

jasmine_node: {
specNameMatcher: "_spec", // load only specs containing specNameMatcher
projectRoot: "<%= bb.test %>/node_specs",
Expand All @@ -117,7 +96,7 @@ module.exports = function(grunt) {
consolidate: true
}
},

watch: {
all: {
files: "<%= bb.src %>/**/*.js",
Expand All @@ -128,12 +107,12 @@ module.exports = function(grunt) {
}
}
});

// Load all grunt tasks starting with "grunt-"
require("matchdep").filterDev("grunt-contrib-*").forEach(grunt.loadNpmTasks);
grunt.loadNpmTasks('grunt-jasmine-node');
grunt.loadNpmTasks('grunt-umd');

// Define tasks
grunt.registerTask("default", [
"clean",
Expand All @@ -149,5 +128,5 @@ module.exports = function(grunt) {
"jasmine",
"jasmine_node"
]);

};
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[The MIT License (MIT)](http://opensource.org/licenses/MIT)

Copyright (c) 2013 [Tom Black](http://www.blacktm.com) and [contributors](https://github.com/blue-button?tab=members)
Copyright (c) 2014 [Tom Black](http://www.blacktm.com) and [contributors](https://github.com/blue-button?tab=members)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BlueButton.js

BlueButton.js is JavaScript library to help make working with healthcare data easier. [Try the demo.](http://www.bluebuttonjs.com/sandbox)
BlueButton.js helps developers navigate complex health data with ease. [Try the demo.](http://www.bluebuttonjs.com/sandbox)

**This project is under heavy development!** Until a v1 release, the public API will change, a lot.

Expand Down
67 changes: 25 additions & 42 deletions lib/bluebutton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
* bluebutton.js - The public `BlueButton` object.
*/


/* exported BlueButton */
var BlueButton = function (source) {

// Dependancies
Expand All @@ -16,29 +17,25 @@ var BlueButton = function (source) {
// Private Methods
///////////////////////////
var addMethods = function (objects) {
var json = function () { return JSON.stringify(this, null, 2); };

for (var i = 0; i < objects.length; i++) {
objects[i].json = function () { return JSON.stringify(this, null, 2) };
};
objects[i].json = json;
}
};

// Public Methods
///////////////////////////
var doc = function () { return data.document };
var allergies = function () { return data.allergies };
var demographics = function () { return data.demographics };
var encounters = function () { return data.encounters };
var immunizations = function () { return data.immunizations };
var labs = function () { return data.labs };
var medications = function () { return data.medications };
var problems = function () { return data.problems };
var procedures = function () { return data.procedures };
var vitals = function (filters) {
if (filters) {
return Core.filters(data.vitals);
} else {
return data.vitals;
}
};
var doc = function () { return data.document; };
var allergies = function () { return data.allergies; };
var demographics = function () { return data.demographics; };
var encounters = function () { return data.encounters; };
var immunizations = function () { return data.immunizations; };
var labs = function () { return data.labs; };
var medications = function () { return data.medications; };
var problems = function () { return data.problems; };
var procedures = function () { return data.procedures; };
var vitals = function () { return data.vitals; };

// Init
///////////////////////////
Expand All @@ -47,8 +44,8 @@ var BlueButton = function (source) {
source = source.replace(/^\s+|\s+$/g,'');

// Detect document type
if (source.substr(0, 5) == "<?xml") {
xmlDOM = XML.parseXML(source);
if (source.substr(0, 5) === "<?xml") {
xmlDOM = XML.parse(source);

if (!xmlDOM.template('2.16.840.1.113883.3.88.11.32.1').isEmpty()) {
type = "c32";
Expand All @@ -59,41 +56,27 @@ var BlueButton = function (source) {
type = "json";
}

data.document = { type: type };

switch (type) {
case "c32":
data.allergies = C32.Allergies.parse(xmlDOM);
data.demographics = C32.Demographics.parse(xmlDOM);
data.encounters = C32.Encounters.parse(xmlDOM);
data.immunizations = C32.Immunizations.parse(xmlDOM);
data.labs = C32.Labs.parse(xmlDOM);
data.medications = C32.Medications.parse(xmlDOM);
data.problems = C32.Problems.parse(xmlDOM);
data.procedures = C32.Procedures.parse(xmlDOM);
data.vitals = C32.Vitals.parse(xmlDOM);
data = Parsers.C32.run(xmlDOM);
break;
case "ccda":
data.allergies = CCDA.Allergies.parse(xmlDOM);
data.demographics = CCDA.Demographics.parse(xmlDOM);
data.encounters = CCDA.Encounters.parse(xmlDOM);
data.immunizations = CCDA.Immunizations.parse(xmlDOM);
data.labs = CCDA.Labs.parse(xmlDOM);
data.medications = CCDA.Medications.parse(xmlDOM);
data.problems = CCDA.Problems.parse(xmlDOM);
data.procedures = CCDA.Procedures.parse(xmlDOM);
data.vitals = CCDA.Vitals.parse(xmlDOM);
data = Parsers.CCDA.run(xmlDOM);
break;
case "json":
var json;
try {
var json = JSON.parse(source);
json = JSON.parse(source);
} catch (e) {
console.log("BB Exception: Could not parse JSON");
}
console.log("BB Error: Blue Button JSON not yet implemented.");
console.log(json);
break;
}

data.document = { type: type };

addMethods([
data,
data.document,
Expand Down
Loading

0 comments on commit 4c8e168

Please sign in to comment.