New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

blue-button-fhir

Package Overview
Dependencies
Maintainers
4
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blue-button-fhir - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

lib/json2Json.js

139

lib/fhir.js
"use strict";
var engine = require('./engine');
var bbu = require('blue-button-util');
var json2Json = require('./json2Json');
var rootLogger = require('./logger');
var resourceStore = require('./resourceStore');
var templates = require('./templates');
var condition = require('./resource/condition');
var allergyIntolerance = require('./resource/allergyIntolerance');
var observation_vital = require('./resource/observation-vital');
var observation_result = require('./resource/observation-result');
var observation_result_single = require('./resource/observation-result-single');
var medicationAdministration = require('./resource/medicationAdministration');
var medicationPrescription = require('./resource/medicationPrescription');
var bbuobject = bbu.object;

@@ -19,4 +15,16 @@ var logger = rootLogger.child({

var resourceToModel = exports.resourceToModel = function (store, resourceModel, resource) {
var resourceDict = Object.create(store.index);
var toResourceDictionary = exports.toResourceDictionary = function (bundleEntries) {
var result = {};
if (bundleEntries) {
bundleEntries.forEach(function (bundleEntry) {
var resource = bundleEntry.content;
var id = bundleEntry.id;
result[id] = resource;
});
}
return result;
};
var resourceToModel = exports.resourceToModel = function (resourceDictionary, template, resource) {
var localResourceDictionary = Object.create(resourceDictionary);
var contained = resource.contained;

@@ -26,13 +34,13 @@ if (contained) {

var id = e.id;
resourceDict['#' + id] = e;
localResourceDictionary['#' + id] = e;
});
}
var runner = engine(resourceDict);
var result = runner.run(resource, resourceModel.template);
var j2j = json2Json.instance(localResourceDictionary);
var result = j2j.run(template, resource);
return result;
};
var entryResources = exports.entryResources = (function () {
var pullRelatedOutOfContention = function (body, r, indexDictionary, doNotAddDictionary) {
body.related.forEach(function (component) {
var topBundleEntryInfos = exports.topBundleEntryInfos = (function () {
var pullRelatedOutOfContention = function (content, r, indexDictionary, doNotAddDictionary) {
content.related.forEach(function (component) {
var id = component.target.reference;

@@ -54,19 +62,18 @@ doNotAddDictionary[id] = true;

},
Observation: function (resource, r, indexDictionary, doNotAddDictionary) {
var body = resource.body;
var isVital = body && body.extension && body.extension[0].valueCoding && (body.extension[0].valueCoding.code === '8716-3');
if (isVital) {
if (body.related) {
Observation: function (bundleEntry, r, indexDictionary, doNotAddDictionary) {
var content = bundleEntry.content;
var extensionCode = bbuobject.deepValue(content, 'extension.0.valueCoding.code');
if (extensionCode === '8716-3') {
if (content.related) {
return null;
} else {
return 'observation_vital';
return 'observation-vital';
}
}
var isResult = body && body.extension && body.extension[0].valueCoding && (body.extension[0].valueCoding.code === '11502-2');
if (isResult) {
if (body.related) {
pullRelatedOutOfContention(body, r, indexDictionary, doNotAddDictionary);
return 'observation_result';
if (extensionCode === '11502-2') {
if (content.related) {
pullRelatedOutOfContention(content, r, indexDictionary, doNotAddDictionary);
return 'observation-result';
} else {
return 'observation_result_single';
return 'observation-result-single';
}

@@ -78,4 +85,4 @@ }

},
MedicationAdministration: function (resource, r, indexDictionary, doNotAddDictionary) {
var id = resource.body.prescription.reference;
MedicationAdministration: function (bundleEntry, r, indexDictionary, doNotAddDictionary) {
var id = bundleEntry.content.prescription.reference;
doNotAddDictionary[id] = true;

@@ -90,16 +97,16 @@ var existingIndex = indexDictionary[id];

return function (resources) {
return function (bundleEntries) {
var indexDictionary = {};
var doNotAddDictionary = {};
var preliminaryResult = resources.reduce(function (r, resource) {
var type = resource.type;
var preliminaryResult = bundleEntries.reduce(function (r, bundleEntry) {
var type = bundleEntry.content.resourceType;
var fn = resourceToHandlerKey[type];
if (fn) {
var id = type + '/' + resource.id;
var id = bundleEntry.id;
if (!doNotAddDictionary[id]) {
var hk = fn(resource, r, indexDictionary, doNotAddDictionary);
var hk = fn(bundleEntry, r, indexDictionary, doNotAddDictionary);
if (hk) {
r.push({
resource: resource,
handlerKey: hk
bundleEntry: bundleEntry,
templateKey: hk
});

@@ -135,39 +142,35 @@ indexDictionary[id] = r.length - 1;

var modellers = {
condition: condition,
allergyIntolerance: allergyIntolerance,
observation_vital: observation_vital,
observation_result: observation_result,
observation_result_single: observation_result_single,
medicationAdministration: medicationAdministration,
medicationPrescription: medicationPrescription
};
return function (input) {
var resources = input;
if (input.resourceType === 'Bundle') {
var bundle = input;
resources = [];
var entries = bundle && bundle.entry;
entries.forEach(function (entry) {
var pieces = entry.id.split('/');
var resource = {
type: pieces[0],
id: pieces[1],
body: entry.content
var backwardCompatibility = function (bundle) {
if (Array.isArray(bundle)) {
var resources = bundle;
bundle = {
resourceType: 'Bundle',
entry: []
};
resources.forEach(function (resource) {
var bundleEntry = {
id: resource.type + '/' + resource.id,
content: resource.body
};
resources.push(resource);
bundle.entry.push(bundleEntry);
});
return bundle;
} else {
return bundle;
}
};
return function (bundle) {
logger.trace('started toModel');
bundle = backwardCompatibility(bundle); // remove in 1.5
var store = resourceStore.create(resources);
var bundleEntries = bundle && bundle.entry;
var resourceDictionary = toResourceDictionary(bundleEntries);
var fn = function (entryResource) {
var handlerKey = entryResource.handlerKey;
var modeller = modellers[handlerKey];
var value = resourceToModel(store, modeller, entryResource.resource.body);
var fn = function (topBundleEntryInfo) {
var templateKey = topBundleEntryInfo.templateKey;
var template = templates[templateKey];
var value = resourceToModel(resourceDictionary, template, topBundleEntryInfo.bundleEntry.content);
return {
type: modeller.type,
type: template.type,
value: value

@@ -177,3 +180,3 @@ };

var ers = entryResources(resources);
var ers = topBundleEntryInfos(bundleEntries);
var results = ers.map(fn);

@@ -180,0 +183,0 @@ var model = {

{
"name": "blue-button-fhir",
"version": "1.4.0",
"version": "1.4.1",
"description": "Blue Button FHIR to Model Translator",

@@ -27,3 +27,4 @@ "main": "./index.js",

"blue-button-meta": "~1.3.0",
"blue-button-util": "~1.4.0",
"blue-button-util": "~1.4.1",
"blue-button-json2json": "~1.4.0",
"bunyan": "~1.2.3",

@@ -30,0 +31,0 @@ "lodash": "~2.4.1"

@@ -49,1 +49,6 @@ blue-button-fhir

[Mocha](http://mochajs.org/) and [Grunt](http://gruntjs.com/) are used for testing this project. Simply run `grunt` in the project directory to run all the tests.
## License
Licensed under [Apache 2.0](./LICENSE).

@@ -0,1 +1,5 @@

# v1.4.1 - March 8, 2015
- Move template based json tranformations to blue-button-json2jsom
# v1.4.0 - February 27, 2015

@@ -2,0 +6,0 @@

@@ -10,5 +10,4 @@ "use strict";

cases[0].resources = [{
"type": "AdverseReaction",
"id": "a-0-0",
"body": {
"id": "AdverseReaction/a-0-0",
"content": {
"resourceType": "AdverseReaction",

@@ -30,5 +29,4 @@ "subject": na,

}, {
"type": "AllergyIntolerance",
"id": "a-0-1",
"body": {
"id": "AllergyIntolerance/a-0-1",
"content": {
"resourceType": "AllergyIntolerance",

@@ -50,5 +48,4 @@ "criticality": "medium",

}, {
"type": "Substance",
"id": "a-0-2",
"body": {
"id": "Substance/a-0-2",
"content": {
"resourceType": "Substance",

@@ -114,5 +111,4 @@ "text": na,

cases[1].resources = [{
"type": "AdverseReaction",
"id": "a-1-0",
"body": {
"id": "AdverseReaction/a-1-0",
"content": {
"resourceType": "AdverseReaction",

@@ -134,5 +130,4 @@ "subject": na,

}, {
"type": "AllergyIntolerance",
"id": "a-1-1",
"body": {
"id": "AllergyIntolerance/a-1-1",
"content": {
"resourceType": "AllergyIntolerance",

@@ -139,0 +134,0 @@ "criticality": "medium",

@@ -10,5 +10,4 @@ "use strict";

cases[0].resources = [{
"type": "Condition",
"id": "c-0-0",
"body": {
"id": "Condition/c-0-0",
"content": {
"resourceType": "Condition",

@@ -55,5 +54,4 @@ "status": "confirmed",

cases[1].resources = [{
"type": "Condition",
"id": "c-1-0",
"body": {
"id": "Condition/c-1-0",
"content": {
"resourceType": "Condition",

@@ -96,5 +94,4 @@ "status": "confirmed",

cases[2].resources = [{
"type": "Condition",
"id": "c-2-0",
"body": {
"id": "Condition/c-2-0",
"content": {
"resourceType": "Condition",

@@ -101,0 +98,0 @@ "status": "confirmed",

@@ -10,5 +10,4 @@ "use strict";

cases[0].resources = [{
"type": "MedicationPrescription",
"id": "ma-0-0",
"body": {
"id": "MedicationPrescription/ma-0-0",
"content": {
"resourceType": "MedicationPrescription",

@@ -76,5 +75,4 @@ "status": "active",

}, {
"type": "MedicationAdministration",
"id": "ma-0-1",
"body": {
"id": "MedicationAdministration/ma-0-1",
"content": {
"resourceType": "MedicationAdministration",

@@ -81,0 +79,0 @@ "status": "completed",

@@ -10,5 +10,4 @@ "use strict";

cases[0].resources = [{
"type": "MedicationPrescription",
"id": "mp-0-0",
"body": {
"id": "MedicationPrescription/mp-0-0",
"content": {
"resourceType": "MedicationPrescription",

@@ -62,5 +61,4 @@ "status": "completed",

}, {
"type": "Medication",
"id": "mp-0-1",
"body": {
"id": "Medication/mp-0-1",
"content": {
"resourceType": "Medication",

@@ -146,5 +144,4 @@ "text": {

cases[1].resources = [{
"type": "MedicationPrescription",
"id": "mp-1-0",
"body": {
"id": "MedicationPrescription/mp-1-0",
"content": {
"resourceType": "MedicationPrescription",

@@ -199,5 +196,4 @@ "status": "active",

cases[2].resources = [{
"type": "MedicationPrescription",
"id": "mp-2-0",
"body": {
"id": "MedicationPrescription/mp-2-0",
"content": {
"resourceType": "MedicationPrescription",

@@ -271,5 +267,4 @@ "status": "completed",

cases[3].resources = [{
"type": "MedicationPrescription",
"id": "mp-3-0",
"body": {
"id": "MedicationPrescription/mp-3-0",
"content": {
"resourceType": "MedicationPrescription",

@@ -276,0 +271,0 @@ "status": "active",

@@ -10,5 +10,4 @@ "use strict";

cases[0].resources = [{
"type": "Observation",
"id": "ors-0-0",
"body": {
"id": "Observation/ors-0-0",
"content": {
"resourceType": "Observation",

@@ -15,0 +14,0 @@ "name": {

@@ -10,5 +10,4 @@ "use strict";

cases[0].resources = [{
"type": "Observation",
"id": "or-0-0",
"body": {
"id": "Observation/or-0-0",
"content": {
"resourceType": "Observation",

@@ -62,5 +61,4 @@ "name": {

}, {
"type": "Observation",
"id": "or-0-1",
"body": {
"id": "Observation/or-0-1",
"content": {
"resourceType": "Observation",

@@ -125,5 +123,4 @@ "name": {

}, {
"type": "Observation",
"id": "or-0-2",
"body": {
"id": "Observation/or-0-2",
"content": {
"resourceType": "Observation",

@@ -188,5 +185,4 @@ "name": {

}, {
"type": "Observation",
"id": "or-0-3",
"body": {
"id": "Observation/or-0-3",
"content": {
"resourceType": "Observation",

@@ -205,3 +201,3 @@ "name": {

"related": [{
"type": "has-component",
"id": "has-component",
"target": {

@@ -211,3 +207,3 @@ "reference": "Observation/or-0-0"

}, {
"type": "has-component",
"id": "has-component",
"target": {

@@ -217,3 +213,3 @@ "reference": "Observation/or-0-1"

}, {
"type": "has-component",
"id": "has-component",
"target": {

@@ -311,1 +307,98 @@ "reference": "Observation/or-0-2"

};
cases[1] = {};
cases[1].resources = [{
"type": "Observation",
"id": "Observation/or-1-0",
"content": {
"resourceType": "Observation",
"name": {
"coding": [{
"system": "http://loinc.org",
"code": "26515-7",
"display": "Copy of BLOOD COUNT, PLATELET, AUTOMATED"
}],
"text": "Copy of BLOOD COUNT, PLATELET, AUTOMATED"
},
"valueQuantity": {
"value": 170
},
"issued": "2013-05-30T21:25:23.000Z",
"status": "final",
"reliability": "ok",
"extension": [{
"url": "http://amida.com/fhir/Profile/extensions#observation-type",
"valueCoding": {
"code": "11502-2",
"display": "Laboratory report",
"system": "http://loinc.org"
}
}],
"interpretation": {
"coding": [{
"system": "http://hl7.org/fhir/v2/0078",
"code": "N",
"display": "Normal"
}],
"text": "Normal"
}
}
}, {
"id": "Observation/or-1-1",
"content": {
"resourceType": "Observation",
"name": {
"coding": [{
"system": "urn:oid:2.16.840.1.113883.6.12",
"code": "85049",
"display": "Copy of BLOOD COUNT, PLATELET, AUTOMATED (85049)"
}],
"text": "Copy of BLOOD COUNT, PLATELET, AUTOMATED (85049)"
},
"status": "final",
"reliability": "ok",
"related": [{
"type": "has-component",
"target": {
"reference": "Observation/or-1-0"
}
}],
"extension": [{
"url": "http://amida.com/fhir/Profile/extensions#observation-type",
"valueCoding": {
"code": "11502-2",
"display": "Laboratory report",
"system": "http://loinc.org"
}
}]
}
}];
cases[1].input = cases[1].resources[1];
cases[1].result = {
"result_set": {
"name": "Copy of BLOOD COUNT, PLATELET, AUTOMATED (85049)",
"code": "85049",
"code_system_name": "CPT"
},
"results": [{
"result": {
"name": "Copy of BLOOD COUNT, PLATELET, AUTOMATED",
"code": "26515-7",
"code_system_name": "LOINC"
},
"value": 170,
"interpretations": [
"Normal"
],
"date_time": {
"point": {
"date": "2013-05-30T00:00:00.000Z",
"precision": "day"
}
},
"status": "completed"
}]
};

@@ -5,10 +5,9 @@ "use strict";

var na = null;
cases[0] = {};
var na = null;
cases[0].resources = [{
"type": "Observation",
"id": "ov-0-0",
"body": {
"id": "Observation/ov-0-0",
"content": {
"resourceType": "Observation",

@@ -76,5 +75,4 @@ "name": {

cases[1].resources = [{
"type": "Observation",
"id": "ov-1-0",
"body": {
"id": "Observation/ov-1-0",
"content": {
"resourceType": "Observation",

@@ -142,5 +140,4 @@ "name": {

cases[2].resources = [{
"type": "Observation",
"id": "ov-2-0",
"body": {
"id": "Observation/ov-2-0",
"content": {
"resourceType": "Observation",

@@ -208,5 +205,4 @@ "name": {

cases[3].resources = [{
"type": "Observation",
"id": "ov-3-0",
"body": {
"id": "Observation/ov-3-0",
"content": {
"resourceType": "Observation",

@@ -274,5 +270,4 @@ "name": {

cases[4].resources = [{
"type": "Observation",
"id": "ov-4-0",
"body": {
"id": "Observation/ov-4-0",
"content": {
"resourceType": "Observation",

@@ -340,5 +335,4 @@ "name": {

cases[5].resources = [{
"type": "Observation",
"id": "ov-5-0",
"body": {
"id": "Observation/ov-5-0",
"content": {
"resourceType": "Observation",

@@ -406,5 +400,4 @@ "name": {

cases[6].resources = [{
"type": "Observation",
"id": "ov-6-0",
"body": {
"id": "Observation/ov-6-0",
"content": {
"resourceType": "Observation",

@@ -472,5 +465,4 @@ "name": {

cases[7].resources = [{
"type": "Observation",
"id": "0",
"body": {
"id": "Observation/0",
"content": {
"resourceType": "Observation",

@@ -477,0 +469,0 @@ "name": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc