blue-button-generate
Advanced tools
Comparing version 1.4.0-beta.6 to 1.4.0-beta.7
22
index.js
@@ -8,5 +8,9 @@ "use strict"; | ||
var bbu = require("blue-button-util"); | ||
var engine = require('./lib/engine'); | ||
var documentLevel = require('./lib/documentLevel'); | ||
var bbuo = bbu.object; | ||
var createContext = (function () { | ||
@@ -26,5 +30,11 @@ var base = { | ||
return function () { | ||
return function (options) { | ||
var result = Object.create(base); | ||
result.references = {}; | ||
if (options.meta && options.addUniqueIds) { | ||
result.rootId = bbuo.deepValue(options.meta, 'identifiers.0.identifier'); | ||
} else { | ||
result.rootId = null; | ||
} | ||
return result; | ||
@@ -34,11 +44,13 @@ }; | ||
var generate = exports.generate = function (template, input) { | ||
var context = createContext(); | ||
var generate = exports.generate = function (template, input, options) { | ||
var context = createContext(options); | ||
return engine.create(documentLevel.ccd, input, context); | ||
}; | ||
exports.generateCCD = function (input) { | ||
exports.generateCCD = function (input, options) { | ||
options = options || {}; | ||
var data = input.data ? input.data : input; | ||
data.identifiers = input.meta && input.meta.identifiers; | ||
return generate(documentLevel.ccd, data); | ||
options.meta = input.meta; | ||
return generate(documentLevel.ccd, data, options); | ||
}; |
@@ -11,3 +11,3 @@ "use strict"; | ||
return function (input) { | ||
return input[key0] || input[key1] || input[key2] || input[key3]; | ||
return input.hasOwnProperty(key0) || input.hasOwnProperty(key1) || input.hasOwnProperty(key2) || input.hasOwnProperty(key3); | ||
}; | ||
@@ -14,0 +14,0 @@ }; |
@@ -11,3 +11,3 @@ "use strict"; | ||
} | ||
if (text) { | ||
if ((text !== null) && (text !== undefined)) { | ||
return text; | ||
@@ -78,6 +78,6 @@ } | ||
var condition = template.existsWhen; | ||
if ((!condition) || condition(input)) { | ||
if ((!condition) || condition(input, context)) { | ||
var name = template.key; | ||
var text = expandText(input, template); | ||
if (text || template.content || template.attributes) { | ||
if (((text !== null) && (text !== undefined)) || template.content || template.attributes) { | ||
var node = xmlutil.newNode(xmlDoc, name, text); | ||
@@ -98,3 +98,26 @@ | ||
pieces.forEach(function (piece) { | ||
input = input && input[piece]; | ||
if (Array.isArray(input) && (piece !== "0")) { | ||
var nextInputs = []; | ||
input.forEach(function (inputElement) { | ||
var nextInput = inputElement[piece]; | ||
if (nextInput) { | ||
if (Array.isArray(nextInput)) { | ||
nextInput.forEach(function (nextInputElement) { | ||
if (nextInputElement) { | ||
nextInputs.push(nextInputElement); | ||
} | ||
}); | ||
} else { | ||
nextInputs.push(nextInput); | ||
} | ||
} | ||
}); | ||
if (nextInputs.length === 0) { | ||
input = null; | ||
} else { | ||
input = nextInputs; | ||
} | ||
} else { | ||
input = input && input[piece]; | ||
} | ||
}); | ||
@@ -101,0 +124,0 @@ } |
@@ -149,2 +149,3 @@ "use strict"; | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.30"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, | ||
@@ -151,0 +152,0 @@ fieldLevel.templateCode("AllergyProblemAct"), |
@@ -21,2 +21,3 @@ "use strict"; | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.49"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -23,0 +24,0 @@ key: "code", |
@@ -112,2 +112,3 @@ "use strict"; | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.52"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, | ||
@@ -114,0 +115,0 @@ fieldLevel.text(leafLevel.nextReference("immunization")), |
@@ -150,2 +150,3 @@ "use strict"; | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.16"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -152,0 +153,0 @@ key: "text", |
@@ -150,2 +150,3 @@ "use strict"; | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.60"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, | ||
@@ -152,0 +153,0 @@ fieldLevel.templateCode("CoverageActivity"), |
@@ -20,2 +20,3 @@ "use strict"; | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.39"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -42,2 +43,3 @@ key: "code", | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.44"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -64,2 +66,3 @@ key: "code", | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.41"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -86,2 +89,3 @@ key: "code", | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.40"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -108,2 +112,3 @@ key: "code", | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.42"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -130,2 +135,3 @@ key: "code", | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.43"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -152,2 +158,3 @@ key: "code", | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.20"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -154,0 +161,0 @@ key: "code", |
@@ -140,3 +140,4 @@ "use strict"; | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.3"), | ||
fieldLevel.templateCode("ProblemConcernAct"), { | ||
fieldLevel.templateCode("ProblemConcernAct"), | ||
fieldLevel.uniqueId, { | ||
key: "id", | ||
@@ -143,0 +144,0 @@ attributes: { |
@@ -22,2 +22,3 @@ "use strict"; | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.12"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -80,2 +81,3 @@ key: "code", | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.14"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -165,2 +167,3 @@ key: "code", | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.13"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -167,0 +170,0 @@ key: "code", |
@@ -29,7 +29,10 @@ "use strict"; | ||
attributes: { | ||
"xsi:type": "PQ", | ||
"xsi:type": function (input) { | ||
return input.text ? "ST" : "PQ"; | ||
}, | ||
value: leafLevel.inputProperty("value"), | ||
unit: leafLevel.inputProperty("unit") | ||
}, | ||
existsWhen: condition.keyExists("value"), | ||
text: leafLevel.inputProperty("text"), | ||
existsWhen: condition.eitherKeyExists("value", "text"), | ||
required: true | ||
@@ -98,2 +101,3 @@ }, { | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.1"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -100,0 +104,0 @@ key: "code", |
@@ -18,2 +18,3 @@ "use strict"; | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.38"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, { | ||
@@ -60,2 +61,3 @@ key: "code", | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.78"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, | ||
@@ -62,0 +64,0 @@ fieldLevel.templateCode("SmokingStatusObservation"), |
@@ -74,2 +74,3 @@ "use strict"; | ||
fieldLevel.templateId("2.16.840.1.113883.10.20.22.4.26"), | ||
fieldLevel.uniqueId, | ||
fieldLevel.id, | ||
@@ -76,0 +77,0 @@ fieldLevel.templateCode("VitalSignsOrganizer"), { |
"use strict"; | ||
var bbm = require("blue-button-meta"); | ||
var uuid = require('uuid'); | ||
@@ -58,2 +59,17 @@ var condition = require("./condition"); | ||
exports.uniqueId = { | ||
key: "id", | ||
attributes: { | ||
root: function (input, context) { | ||
return context.rootId; | ||
}, | ||
extension: function () { | ||
return uuid.v4(); | ||
} | ||
}, | ||
existsWhen: function (input, context) { | ||
return context.rootId; | ||
} | ||
}; | ||
exports.statusCodeCompleted = { | ||
@@ -60,0 +76,0 @@ key: "statusCode", |
"use strict"; | ||
var bbu = require("blue-button-util"); | ||
var translate = require('./translate'); | ||
var bbuo = bbu.object; | ||
var bbud = bbu.datetime; | ||
exports.input = function (input) { | ||
@@ -72,1 +77,31 @@ return input; | ||
}; | ||
exports.deepInputProperty = function (deepProperty, defaultValue) { | ||
return function (input) { | ||
var value = bbuo.deepValue(input, deepProperty); | ||
value = bbuo.exists(value) ? value : defaultValue; | ||
if (typeof value !== 'string') { | ||
value = value.toString(); | ||
} | ||
return value; | ||
}; | ||
}; | ||
exports.deepInputDate = function (deepProperty, defaultValue) { | ||
return function (input) { | ||
var value = bbuo.deepValue(input, deepProperty); | ||
if (!bbuo.exists(value)) { | ||
return defaultValue; | ||
} else { | ||
value = bbud.modelToDate({ | ||
date: value.date, | ||
precision: value.precision // workaround a bug in bbud. Changes precision. | ||
}); | ||
if (bbuo.exists(value)) { | ||
return value; | ||
} else { | ||
return defaultValue; | ||
} | ||
} | ||
}; | ||
}; |
"use strict"; | ||
var bbu = require("blue-button-util"); | ||
var fieldLevel = require("./fieldLevel"); | ||
var entryLevel = require("./entryLevel"); | ||
var leafLevel = require('./leafLevel'); | ||
var contentModifier = require("./contentModifier"); | ||
var required = contentModifier.required; | ||
var bbud = bbu.datetime; | ||
var bbuo = bbu.object; | ||
var nda = "No Data Available"; | ||
var getText = function (topArrayKey, headers, values) { | ||
var result = { | ||
key: "text", | ||
content: [{ | ||
key: "table", | ||
attributes: { | ||
border: "1", | ||
width: "100%" | ||
}, | ||
content: [{ | ||
key: "thead", | ||
content: [{ | ||
key: "tr", | ||
content: [] | ||
}] | ||
}, { | ||
key: "tbody", | ||
content: [{ | ||
key: "tr", | ||
content: [], | ||
dataKey: topArrayKey | ||
}] | ||
}] | ||
}] | ||
}; | ||
var headerTarget = result.content[0].content[0].content[0].content; | ||
headers.forEach(function (header) { | ||
var element = { | ||
key: "th", | ||
text: header | ||
}; | ||
headerTarget.push(element); | ||
}); | ||
var valueTarget = result.content[0].content[1].content[0].content; | ||
values.forEach(function (value) { | ||
var data; | ||
if (typeof value !== 'function') { | ||
data = leafLevel.deepInputProperty(value, ""); | ||
} else { | ||
data = value; | ||
} | ||
var element = { | ||
key: "td", | ||
text: data | ||
}; | ||
valueTarget.push(element); | ||
}); | ||
return result; | ||
}; | ||
var alllergiesTextHeaders = ["Substance", "Overall Severity", "Reaction", "Reaction Severity", "Status"]; | ||
var allergiesTextRow = [ | ||
leafLevel.deepInputProperty("observation.allergen.name", ""), | ||
leafLevel.deepInputProperty("observation.severity.code.name", ""), | ||
leafLevel.deepInputProperty("observation.reactions.0.reaction.name", ""), | ||
leafLevel.deepInputProperty("observation.reactions.0.severity.code.name", ""), | ||
leafLevel.deepInputProperty("observation.status.name", "") | ||
]; | ||
exports.allergiesSectionEntriesRequired = { | ||
@@ -17,6 +84,4 @@ key: "component", | ||
fieldLevel.templateCode("AllergiesSection"), | ||
fieldLevel.templateTitle("AllergiesSection"), { | ||
key: "text", | ||
text: "" | ||
}, { | ||
fieldLevel.templateTitle("AllergiesSection"), | ||
getText('allergies', alllergiesTextHeaders, allergiesTextRow), { | ||
key: "entry", | ||
@@ -36,2 +101,21 @@ attributes: { | ||
var medicationsTextHeaders = ["Medication Class", "# fills", "Last fill date"]; | ||
var medicationsTextRow = [ // Name, did not find class in the medication blue-button-data | ||
function (input) { | ||
var value = bbuo.deepValue(input, 'product.product.name'); | ||
if (!bbuo.exists(value)) { | ||
value = bbuo.deepValue(input, 'product.unencoded_name'); | ||
} | ||
if (!bbuo.exists(value)) { | ||
return ""; | ||
} else { | ||
return value; | ||
} | ||
}, | ||
leafLevel.deepInputProperty("supply.repeatNumber", ""), | ||
function () { | ||
return nda; | ||
} | ||
]; | ||
exports.medicationsSectionEntriesRequired = { | ||
@@ -45,6 +129,4 @@ key: "component", | ||
fieldLevel.templateCode("MedicationsSection"), | ||
fieldLevel.templateTitle("MedicationsSection"), { | ||
key: "text", | ||
text: "" | ||
}, { | ||
fieldLevel.templateTitle("MedicationsSection"), | ||
getText('medications', medicationsTextHeaders, medicationsTextRow), { | ||
key: "entry", | ||
@@ -132,3 +214,62 @@ attributes: { | ||
key: "text", | ||
text: "" | ||
content: [{ | ||
key: "table", | ||
content: [{ | ||
key: "thead", | ||
content: [{ | ||
key: "th", | ||
attributes: { | ||
colspan: "7" | ||
}, | ||
text: "Laboratory Results" | ||
}, { | ||
key: "tr", | ||
content: [{ | ||
key: "th", | ||
text: leafLevel.input, | ||
dataTransform: function () { | ||
return ['Test', 'Result', 'Units', 'Ref low', 'Ref high', 'Date', 'Source']; | ||
} | ||
}] | ||
}] | ||
}, { | ||
key: "tbody", | ||
content: [{ | ||
key: "tr", | ||
content: [{ | ||
key: "td", | ||
attributes: { | ||
colspan: "7" | ||
}, | ||
text: leafLevel.deepInputProperty('result_set.name', nda), | ||
}] | ||
}, { | ||
key: "tr", | ||
content: [{ | ||
key: "td", | ||
text: leafLevel.deepInputProperty("result.name", nda) | ||
}, { | ||
key: "td", | ||
text: leafLevel.deepInputProperty("value", nda) | ||
}, { | ||
key: "td", | ||
text: leafLevel.deepInputProperty("unit", nda) | ||
}, { | ||
key: "td", | ||
text: leafLevel.deepInputProperty("reference_range.low", nda) | ||
}, { | ||
key: "td", | ||
text: leafLevel.deepInputProperty("reference_range.high", nda) | ||
}, { | ||
key: "td", | ||
text: leafLevel.deepInputDate("date_time.point", nda), | ||
}, { | ||
key: "td", | ||
text: nda | ||
}], | ||
dataKey: 'results' | ||
}], | ||
dataKey: 'results' | ||
}] | ||
}] | ||
}, { | ||
@@ -159,3 +300,52 @@ key: "entry", | ||
key: "text", | ||
text: "" | ||
content: [{ | ||
key: "table", | ||
content: [{ | ||
key: "caption", | ||
text: "Emergency Room Visits" | ||
}, { | ||
key: "thead", | ||
content: [{ | ||
key: "tr", | ||
content: [{ | ||
key: "th", | ||
text: leafLevel.input, | ||
dataTransform: function () { | ||
return ['Facility', 'Date of Service', 'Diagnosis/Complaint']; | ||
} | ||
}] | ||
}] | ||
}, { | ||
key: "tbody", | ||
content: [{ | ||
key: "tr", | ||
content: [{ | ||
key: "td", | ||
text: leafLevel.deepInputProperty("locations.0.name", nda) | ||
}, { | ||
key: "td", | ||
text: function (input) { | ||
var value = bbuo.deepValue(input, "date_time.point"); | ||
if (value) { | ||
value = bbud.modelToDate({ | ||
date: value.date, | ||
precision: value.precision // workaround a bug in bbud. Changes precision. | ||
}); | ||
if (value) { | ||
var vps = value.split('-'); | ||
if (vps.length === 3) { | ||
return [vps[1], vps[2], vps[0]].join('/'); | ||
} | ||
} | ||
} | ||
return nda; | ||
} | ||
}, { | ||
key: "td", | ||
text: leafLevel.deepInputProperty("findings.0.value.name", nda) | ||
}], | ||
}], | ||
dataKey: 'encounters' | ||
}] | ||
}] | ||
}, { | ||
@@ -162,0 +352,0 @@ key: "entry", |
{ | ||
"name": "blue-button-generate", | ||
"version": "1.4.0-beta.6", | ||
"version": "1.4.0-beta.7", | ||
"description": "Blue Button CCDA Generator.", | ||
@@ -33,7 +33,9 @@ "main": "./index.js", | ||
"blue-button-meta": "^1.3.0", | ||
"blue-button-util": "^1.4.1", | ||
"libxmljs": "~0.12.0", | ||
"moment": "~2.8.4" | ||
"moment": "~2.8.4", | ||
"uuid": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"blue-button": "^1.4.0", | ||
"blue-button": "~1.4.1", | ||
"brfs": "~1.2.0", | ||
@@ -40,0 +42,0 @@ "chai": "~1.10.0", |
@@ -84,7 +84,2 @@ var expect = require('chai').expect; | ||
delete result2.errors; | ||
result.data.results.forEach(function (entry) { | ||
entry.results.forEach(function (r) { | ||
delete r.text; | ||
}); | ||
}); | ||
@@ -91,0 +86,0 @@ assert.deepEqual(result2, result); |
@@ -333,5 +333,2 @@ "use strict"; | ||
}, { | ||
xpath: t.resultObs + '/h:value[@xsi:type="ST"]', | ||
action: "removeNode" | ||
}, { | ||
xpath: t.resultObs + '/h:value[@value]', | ||
@@ -338,0 +335,0 @@ action: "removeZeros" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
26041005
172
558541
5
5
+ Addedblue-button-util@^1.4.1
+ Addeduuid@^2.0.1
+ Addedblue-button-util@1.5.0(transitive)
+ Addedlodash@2.4.2(transitive)
+ Addeduuid@2.0.3(transitive)