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

Commit

Permalink
Merge pull request #104 from elationemr/ccda_generation_mu2
Browse files Browse the repository at this point in the history
CCDA generation from BB JSON, parsing of smoking status / functional status sections, parsing of medication schedules, and broader recognition of CCDAs
  • Loading branch information
sankarravi committed May 23, 2014
2 parents 21b499d + bf519a0 commit 6ef8971
Show file tree
Hide file tree
Showing 35 changed files with 5,463 additions and 140 deletions.
1 change: 1 addition & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"Codes": true,
"Core": true,
"Documents": true,
"ejs": true,
"Generators": true,
"Parsers": true,
"Renderers": true
Expand Down
17 changes: 17 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ module.exports = function(grunt) {
"<%= bb.src %>/parsers/ccda.js",
"<%= bb.src %>/parsers/ccda/document.js",
"<%= bb.src %>/parsers/ccda/allergies.js",
"<%= bb.src %>/parsers/ccda/care_plan.js",
"<%= bb.src %>/parsers/ccda/demographics.js",
"<%= bb.src %>/parsers/ccda/encounters.js",
"<%= bb.src %>/parsers/ccda/free_text.js",
"<%= bb.src %>/parsers/ccda/functional_statuses.js",
"<%= bb.src %>/parsers/ccda/immunizations.js",
"<%= bb.src %>/parsers/ccda/instructions.js",
"<%= bb.src %>/parsers/ccda/labs.js",
"<%= bb.src %>/parsers/ccda/medications.js",
"<%= bb.src %>/parsers/ccda/problems.js",
"<%= bb.src %>/parsers/ccda/procedures.js",
"<%= bb.src %>/parsers/ccda/smoking_status.js",
"<%= bb.src %>/parsers/ccda/vitals.js",

"<%= bb.src %>/renderers.js",
Expand All @@ -84,6 +89,17 @@ module.exports = function(grunt) {
dest: "<%= bb.build %>/bluebutton.js"
}
},

copy: {
ejs: {
files: [{
cwd: ".",
src: "<%= bb.src %>/generators/ccda_template.ejs",
dest: "<%= bb.build %>/ccda_template.ejs",
expand: false
}]
}
},

umd: {
all: {
Expand Down Expand Up @@ -157,6 +173,7 @@ module.exports = function(grunt) {
"clean",
"jshint:beforeconcat",
"concat",
"copy",
"umd",
"jshint:afterconcat",
"uglify"
Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,50 @@ require(['bluebutton', 'text!examples/xml/ccd.xml'], function (BlueButton, xml)
</body>
```

## Generation

```JavaScript
var json = fs.readFileSync('./example.json', 'utf-8');
var template = fs.readFileSync('./build/ccda_template.ejs');
var myRecord = BlueButton(json, {
generatorType: 'ccda',
template: template
});

// Log the resulting XML
console.log(myRecord.data);
```

XML Generation requires ejs (https://github.com/visionmedia/ejs).

### Browser Usage

In order to do generation in the browser, include a copy of ejs.js before bluebutton.js (using the visionmedia implementation popular in Node and not the implementation at http://embeddedjs.com/) and then load the ejs template via XHR like so:

```HTML
<body>
<script src="./spec/javascripts/helpers/ejs.js"></script>
<script src="./bluebutton/build/bluebutton.js"></script>
<script>
var json = ...; // client-generated or fetched via XHR, depending on your application
var xhr = new XMLHttpRequest();
xhr.open('get', './bluebutton/build/ccda_template.ejs', false);
xhr.send();
var template = xhr.responseText;
var myRecord = BlueButton(json, {
generatorType: 'ccda',
template: template
});
// Log the resulting XML
console.log(myRecord.data);
</script>
</body>
```


## Creating a Build

Run `grunt` to build the library. A `build/` directory will be created containing the standard and minified builds.
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bluebutton",
"version": "0.0.18",
"version": "0.1.0",
"description": "BlueButton.js allows web developers to parse and navigate complex health data with ease.",
"main": [
"build/bluebutton.js"
Expand Down
20 changes: 20 additions & 0 deletions lib/bluebutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ var BlueButton = function (source, opts) {
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;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var Core = (function () {
* Removes leading and trailing whitespace from a string
*/
var stripWhitespace = function (str) {
if (!str) { return str; }
return str.replace(/^\s+|\s+$/g,'');
};

Expand Down
Loading

0 comments on commit 6ef8971

Please sign in to comment.