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

fhir

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fhir - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

test/assert.js

32

dstu1/jsParser.js

@@ -12,4 +12,10 @@ var util = require('./util');

var value = obj;
if (typeof value == 'string') {
value = value.replace(/&/g, '&');
}
var primitiveNode = node.ele(name);
primitiveNode.att('value', obj);
primitiveNode.att('value', value);
};

@@ -49,3 +55,3 @@

var buildExtensionProperty = function(node, obj) {
if (!obj || !obj.extension) {
if (!obj || !obj.extension || obj.extension.length == 0) {
return;

@@ -149,6 +155,12 @@ }

if (obj.div) {
var divValue = obj.div;
if (divValue) {
if (typeof divValue == 'string') {
divValue = divValue.replace(/&/g, '&');
}
var childDiv = newNode.ele('div');
childDiv.att('xmlns', 'http://www.w3.org/1999/xhtml');
childDiv.raw(obj.div);
childDiv.raw(divValue);
}

@@ -453,2 +465,3 @@ };

case 'extension':
case 'Extension':
buildFunction = buildExtension;

@@ -511,3 +524,3 @@ break;

if (elementType) {
throw 'Type not recognized';
throw 'Type not recognized: ' + elementType;
}

@@ -538,5 +551,5 @@ }

for (var i in obj) {
if (i.toString().indexOf('_') == 0) {
if (i.toString().indexOf('_') == 0 && obj[i]) {
node.att(i.substring(1), obj[i]);
} else if (i == "id" && elementPath.indexOf('Bundle') != 0) {
} else if (i == "id" && elementPath.indexOf('Bundle') != 0 && obj[i]) {
node.att('id', obj[i]);

@@ -610,3 +623,6 @@ }

buildFeedPrimitive(node, obj, 'id');
buildFeedLink(node, obj);
buildFeedAuthor(node, obj);
buildFeedCategory(node, obj);

@@ -622,4 +638,2 @@ if (obj.entry && obj.entry.length > 0) {

buildFeedPrimitive(newEntry, obj.entry[i], 'published');
buildFeedAuthor(newEntry, obj.entry[i]);
buildFeedCategory(newEntry, obj.entry[i]);

@@ -626,0 +640,0 @@ if (obj.entry[i].content) {

var xml2js = require('xml2js');
var util = require('./util');
module.exports = function(profiles) {
module.exports = function(profiles, obj) {
var self = this;
var builder = new xml2js.Builder({explicitRoot: false, headless: true, rootName: 'div', renderOpts: { 'pretty': false }});
var objRoot, objNs;
var objNamespaces = {};
var ATOM_NS = 'http://www.w3.org/2005/Atom';
var FHIR_NS = 'http://hl7.org/fhir';
var XHTML_NS = 'http://www.w3.org/1999/xhtml';
// Get the root property from the obj
for (var i in obj) {
objRoot = obj[i];
break;
}
if (!objRoot) {
throw 'No root property found after parsing XML document';
}
if (objRoot['$']) {
// Extract the namespaces
for (var i in objRoot['$']) {
if (i == 'xmlns') {
objNs = objRoot['$'][i];
} else if (i.indexOf('xmlns:') == 0) {
objNamespaces[objRoot['$'][i]] = i.substring(6);
}
}
}
var getXmlValue = function(xmlObj) {

@@ -26,8 +53,10 @@ var hasProperties = false;

var populateXmlValue = function(obj, xmlObj, property, isArray) {
var xmlObjProp = self.GetProperty(xmlObj, FHIR_NS, property);
if (isArray) {
if (xmlObj[property] && xmlObj[property].length > 0) {
if (xmlObjProp && xmlObjProp.length > 0) {
obj[property] = [];
for (var i in xmlObj[property]) {
var value = getXmlValue(xmlObj[property][i]);
for (var i in xmlObjProp) {
var value = getXmlValue(xmlObjProp[i]);
obj[property].push(value);

@@ -37,4 +66,4 @@ }

} else {
if (xmlObj[property] && xmlObj[property].length > 0) {
obj[property] = getXmlValue(xmlObj[property][0]);
if (xmlObjProp && xmlObjProp.length > 0) {
obj[property] = getXmlValue(xmlObjProp[0]);
}

@@ -68,4 +97,5 @@ }

if (xmlObj.valueSet && xmlObj.valueSet.length > 0) {
obj.valueSet = parseXmlResourceReference(xmlObj.valueSet[0]);
var valueSetProp = self.GetProperty(xmlObj, FHIR_NS, 'valueSet');
if (valueSetProp && valueSetProp.length > 0) {
obj.valueSet = parseXmlResourceReference(valueSetProp[0]);
}

@@ -88,4 +118,5 @@

if (xmlObj.assigner && xmlObj.assigner.length > 0) {
obj.assigner = parseXmlResourceReference(xmlObj.assigner[0]);
var assignerProp = self.GetProperty(xmlObj, FHIR_NS, 'assigner');
if (assignerProp && assignerProp.length > 0) {
obj.assigner = parseXmlResourceReference(assignerProp[0]);
}

@@ -103,7 +134,8 @@

if (xmlObj.coding && xmlObj.coding.length > 0) {
var codingProp = self.GetProperty(xmlObj, FHIR_NS, 'coding');
if (codingProp && codingProp.length > 0) {
obj.coding = [];
for (var i in xmlObj.coding) {
var coding = parseXmlCoding(xmlObj.coding[i]);
for (var i in codingProp) {
var coding = parseXmlCoding(codingProp[i]);
obj.coding.push(coding);

@@ -145,4 +177,5 @@ }

if (xmlObj.period && xmlObj.period.length > 0) {
obj.period = parseXmlPeriod(xmlObj.period[0]);
var periodProp = self.GetProperty(xmlObj, FHIR_NS, 'period');
if (periodProp && periodProp.length > 0) {
obj.period = parseXmlPeriod(periodProp[0]);
}

@@ -181,10 +214,25 @@

var populateXmlExtension = function(obj, xmlObj) {
if (xmlObj.extension && xmlObj.extension.length > 0) {
if (!xmlObj) {
return;
}
var extensionProp = self.GetProperty(xmlObj, FHIR_NS, 'extension');
if (extensionProp && extensionProp.length > 0) {
obj.extension = [];
for (var i in xmlObj.extension) {
var extension = parseXmlExtension(xmlObj.extension[i]);
for (var i in extensionProp) {
var extension = parseXmlExtension(extensionProp[i]);
obj.extension.push(extension);
}
}
var modifierExtensionProp = self.GetProperty(xmlObj, FHIR_NS, 'modifierExtension');
if (modifierExtensionProp && modifierExtensionProp.length > 0) {
obj.modifierExtension = [];
for (var i in modifierExtensionProp) {
var extension = parseXmlExtension(modifierExtensionProp[i]);
obj.modifierExtension.push(extension);
}
}
};

@@ -197,13 +245,19 @@

if (xmlObj.div && xmlObj.div.length > 0) {
if (xmlObj.div[0]['$']) {
delete xmlObj.div[0]['$'];
var divProp = self.GetProperty(xmlObj, XHTML_NS, 'div');
if (divProp && divProp.length > 0) {
if (divProp[0]['$']) {
delete divProp[0]['$'];
}
var xml = builder.buildObject(xmlObj.div[0]);
obj.div = xml;
if (typeof divProp[0] == 'string') {
obj.div = divProp[0];
} else {
var xml = builder.buildObject(divProp[0]);
obj.div = xml;
}
}
if (xmlObj.status && xmlObj.status.length > 0) {
obj.status = getXmlValue(xmlObj.status[0]);
var statusProp = self.GetProperty(xmlObj, FHIR_NS, 'status');
if (statusProp && statusProp.length > 0) {
obj.status = getXmlValue(statusProp[0]);
}

@@ -231,3 +285,3 @@

};
var parseXmlRatio = function(xmlObj) {

@@ -237,9 +291,11 @@ var obj = {};

populateXmlExtension(obj, xmlObj);
if (xmlObj.numerator && xmlObj.numerator.length > 0) {
obj.numerator = parseXmlQuantity(xmlObj.numerator[0]);
var numeratorProp = self.GetProperty(xmlObj, FHIR_NS, 'numerator');
if (numeratorProp && numeratorProp.length > 0) {
obj.numerator = parseXmlQuantity(numeratorProp[0]);
}
if (xmlObj.denominator && xmlObj.denominator.length > 0) {
obj.denominator = parseXmlQuantity(xmlObj.denominator[0]);
var denominatorProp = self.GetProperty(xmlObj, FHIR_NS, 'denominator');
if (denominatorProp && denominatorProp.length > 0) {
obj.denominator = parseXmlQuantity(denominatorProp[0]);
}

@@ -296,4 +352,5 @@

if (xmlObj.period && xmlObj.period.length > 0) {
obj.period = parseXmlPeriod(xmlObj.period[0]);
var periodProp = self.GetProperty(xmlObj, FHIR_NS, 'period');
if (periodProp && periodProp.length > 0) {
obj.period = parseXmlPeriod(periodProp[0]);
}

@@ -315,4 +372,5 @@

if (xmlObj.period && xmlObj.period.length > 0) {
obj.period = parseXmlPeriod(xmlObj.period[0]);
var periodProp = self.GetProperty(xmlObj, FHIR_NS, 'period');
if (periodProp && periodProp.length > 0) {
obj.period = parseXmlPeriod(periodProp[0]);
}

@@ -348,7 +406,8 @@

if (xmlObj.event && xmlObj.event.length > 0) {
var eventProp = self.GetProperty(xmlObj, FHIR_NS, 'event');
if (eventProp && eventProp.length > 0) {
obj.event = [];
for (var i in xmlObj.event) {
var event = parseXmlPeriod(xmlObj.event[i]);
for (var i in eventProp) {
var event = parseXmlPeriod(eventProp[i]);
obj.event.push(event);

@@ -358,11 +417,12 @@ }

if (xmlObj.repeat && xmlObj.repeat.length > 0) {
var repeatProp = self.GetProperty(xmlObj, FHIR_NS, 'repeat');
if (repeatProp && repeatProp.length > 0) {
obj.repeat = {};
populateXmlValue(obj.repeat, xmlObj.repeat[0], 'frequency');
populateXmlValue(obj.repeat, xmlObj.repeat[0], 'when');
populateXmlValue(obj.repeat, xmlObj.repeat[0], 'duration');
populateXmlValue(obj.repeat, xmlObj.repeat[0], 'units');
populateXmlValue(obj.repeat, xmlObj.repeat[0], 'count');
populateXmlValue(obj.repeat, xmlObj.repeat[0], 'end');
populateXmlValue(obj.repeat, repeatProp[0], 'frequency');
populateXmlValue(obj.repeat, repeatProp[0], 'when');
populateXmlValue(obj.repeat, repeatProp[0], 'duration');
populateXmlValue(obj.repeat, repeatProp[0], 'units');
populateXmlValue(obj.repeat, repeatProp[0], 'count');
populateXmlValue(obj.repeat, repeatProp[0], 'end');
}

@@ -389,2 +449,28 @@

self.GetProperty = function(obj, ns, propertyName) {
if (!obj) {
return;
}
/* Code to make sure prefixes match. Now stripping prefixes, though... so no need. Keeping code around in case namespaces are needed in future
var nsPrefix = '';
if (ns != objNs && !obj[propertyName]) {
if (!objNamespaces[ns]) {
throw 'Namespace not found in XML document: ' + ns;
}
nsPrefix = objNamespaces[ns] + ':';
} else if (obj[propertyName] && obj[propertyName]['$']) {
if (obj[propertyName]['$']['xmlns'] && obj[propertyName]['$']['xmlns'] != ns) {
throw 'Property found does not have a matching xmlns (expected: ' + ns + ', got ' + obj[propertyName]['$']['xmlns']
}
}
return obj[nsPrefix + propertyName];
*/
return obj[propertyName];
};
self.ParseXmlDataType = function(elementOrType, currentXmlObj) {

@@ -499,3 +585,9 @@ var type = typeof elementOrType == 'string' ?

var nextElementPath = elementPath + '.' + i;
var localName = i;
if (localName.indexOf(':') > 0) {
localName = localName.substring(localName.indexOf(':') + 1);
}
var nextElementPath = elementPath + '.' + localName;
var element = util.FindElement(nextElementPath, profiles);

@@ -508,3 +600,3 @@

if (element.definition.max == '*') {
currentJSObj[i] = [];
currentJSObj[localName] = [];

@@ -515,6 +607,6 @@ for (var x in currentXmlObj[i]) {

if (dataTypeValue) {
currentJSObj[i].push(dataTypeValue);
currentJSObj[localName].push(dataTypeValue);
} else {
var nextXmlObj = self.PopulateFromXmlObject({}, currentXmlObj[i][x], nextElementPath);
currentJSObj[i].push(nextXmlObj);
currentJSObj[localName].push(nextXmlObj);
}

@@ -526,5 +618,5 @@ }

if (dataTypeValue) {
currentJSObj[i] = dataTypeValue;
currentJSObj[localName] = dataTypeValue;
} else {
currentJSObj[i] = self.PopulateFromXmlObject({}, currentXmlObj[i][0], nextElementPath);
currentJSObj[localName] = self.PopulateFromXmlObject({}, currentXmlObj[i][0], nextElementPath);
}

@@ -542,2 +634,262 @@ }

};
var parseFeedLink = function(xmlObj) {
if (!xmlObj || !xmlObj['$']) {
return;
}
var feedLink = {};
if (xmlObj['$'].href) {
feedLink.href = xmlObj['$'].href;
}
if (xmlObj['$'].hreflang) {
feedLink.hreflang = xmlObj['$'].hreflang;
}
if (xmlObj['$'].length) {
try {
feedLink.length = parseInt(xmlObj['$'].length);
} catch (ex) { }
}
if (xmlObj['$'].rel) {
feedLink.rel = xmlObj['$'].rel;
}
if (xmlObj['$'].title) {
feedLink.title = xmlObj['$'].title;
}
if (xmlObj['$'].type) {
feedLink.type = xmlObj['$'].type;
}
return feedLink;
};
var parseFeedAuthor = function(xmlObj) {
if (!xmlObj) {
return;
}
var newAuthor = {};
var nameProp = self.GetProperty(xmlObj, ATOM_NS, 'name');
if (nameProp && nameProp.length == 1 && typeof nameProp[0] == 'string') {
newAuthor.name = nameProp[0];
}
var uriProp = self.GetProperty(xmlObj, ATOM_NS, 'uri');
if (uriProp && uriProp.length == 1 && typeof uriProp[0] == 'string') {
newAuthor.uri = uriProp[0];
}
return newAuthor;
};
var parseFeedCategory = function(xmlObj) {
if (!xmlObj) {
return;
}
var newCategory = {};
if (!xmlObj['$']) {
return;
}
if (xmlObj['$'].label) {
newCategory.label = xmlObj['$'].label;
}
if (xmlObj['$'].scheme) {
newCategory.scheme = xmlObj['$'].scheme;
}
if (xmlObj['$'].term) {
newCategory.term = xmlObj['$'].term;
}
return newCategory;
};
self.PopulateBundle = function(currentJSObj, currentXmlObj) {
var titleProp = self.GetProperty(currentXmlObj, ATOM_NS, 'title');
if (titleProp && titleProp.length == 1) {
currentJSObj.title = titleProp[0];
}
var updatedProp = self.GetProperty(currentXmlObj, ATOM_NS, 'updated');
if (updatedProp && updatedProp.length == 1) {
currentJSObj.updated = updatedProp[0];
}
var idProp = self.GetProperty(currentXmlObj, ATOM_NS, 'id');
if (idProp && idProp.length == 1) {
currentJSObj.id = idProp[0];
}
// Links
var linkProp = self.GetProperty(currentXmlObj, ATOM_NS, 'link');
if (linkProp && linkProp.length > 0) {
for (var i in linkProp) {
var currentLink = linkProp[i];
var newLink = parseFeedLink(currentLink);
if (!newLink) {
continue;
}
if (!currentJSObj.link) {
currentJSObj.link = [];
}
currentJSObj.link.push(newLink);
}
}
// Authors
var authorProp = self.GetProperty(currentXmlObj, ATOM_NS, 'author');
if (authorProp && authorProp.length > 0) {
for (var i in authorProp) {
var currentAuthor = authorProp[i];
var newAuthor = parseFeedAuthor(currentAuthor);
if (!newAuthor) {
continue;
}
if (!currentJSObj.author) {
currentJSObj.author = [];
}
currentJSObj.author.push(newAuthor);
}
}
// Categories
var categoryProp = self.GetProperty(currentXmlObj, ATOM_NS, 'category');
if (categoryProp && categoryProp.length > 0) {
for (var i in categoryProp) {
var currentCategory = categoryProp[i];
var newCategory = parseFeedCategory(currentCategory);
if (!newCategory) {
continue;
}
if (!currentJSObj.category) {
currentJSObj.category = [];
}
currentJSObj.category.push(newCategory);
}
}
var entryProp = self.GetProperty(currentXmlObj, ATOM_NS, 'entry');
if (entryProp && entryProp.length > 0) {
for (var i in entryProp) {
var currentEntry = entryProp[i];
var newEntry = {};
var entryTitleProp = self.GetProperty(currentEntry, ATOM_NS, 'title');
if (entryTitleProp && entryTitleProp.length == 1) {
newEntry.title = entryTitleProp[0];
}
var entryLinkProp = self.GetProperty(currentEntry, ATOM_NS, 'link');
var feedLink = parseFeedLink(entryLinkProp);
if (feedLink) {
newEntry.link = feedLink;
}
var entryIdProp = self.GetProperty(currentEntry, ATOM_NS, 'id');
if (entryIdProp && entryIdProp.length == 1) {
newEntry.id = entryIdProp[0];
}
var entryUpdatedProp = self.GetProperty(currentEntry, ATOM_NS, 'updated');
if (entryUpdatedProp && entryUpdatedProp.length == 1) {
newEntry.updated = entryUpdatedProp[0];
}
var entryPublishedProp = self.GetProperty(currentEntry, ATOM_NS, 'published');
if (entryPublishedProp && entryPublishedProp.length == 1) {
newEntry.published = entryPublishedProp[0];
}
// Authors
var entryAuthorsProp = self.GetProperty(currentEntry, ATOM_NS, 'author');
if (entryAuthorsProp && entryAuthorsProp.length > 0) {
for (var x in entryAuthorsProp) {
var currentEntryAuthor = entryAuthorsProp[x];
var newEntryAuthor = parseFeedAuthor(currentEntryAuthor);
if (!newEntryAuthor) {
continue;
}
if (!newEntry.author) {
newEntry.author = [];
}
newEntry.author.push(newEntryAuthor);
}
}
// Categories
var entryCategoriesProp = self.GetProperty(currentEntry, ATOM_NS, 'category');
if (entryCategoriesProp && entryCategoriesProp.length > 0) {
for (var x in entryCategoriesProp) {
var currentEntryCategory = entryCategoriesProp[x];
var newEntryCategory = parseFeedCategory(currentEntryCategory);
if (!newEntryCategory) {
continue;
}
if (!newEntry.category) {
newEntry.category = [];
}
newEntry.category.push(newEntryCategory);
}
}
// Content
var entryContentProp = self.GetProperty(currentEntry, ATOM_NS, 'content');
if (entryContentProp && entryContentProp.length == 1) {
for (var x in entryContentProp[0]) {
if (x == '$' || entryContentProp[0][x].length != 1) {
continue;
}
var newEntryContent = {
resourceType: x.indexOf(':') > 0 ? x.substring(x.indexOf(':') + 1) : x
};
newEntryContent = self.PopulateFromXmlObject(newEntryContent, entryContentProp[0][x][0], newEntryContent.resourceType);
if (newEntryContent) {
newEntry.content = newEntryContent;
}
break;
}
}
// TODO: Summary
if (!currentJSObj.entry) {
currentJSObj.entry = [];
}
currentJSObj.entry.push(newEntry);
}
}
return currentJSObj;
};
};

@@ -51,3 +51,6 @@ var xml2js = require('xml2js');

var parser = new xml2js.Parser();
var options = {
tagNameProcessors: [xml2js.processors.stripPrefix]
};
var parser = new xml2js.Parser(options);

@@ -60,12 +63,23 @@ try {

var obj = {};
var xmlParser = new XmlParser(profiles);
try {
var obj = {};
var xmlParser = new XmlParser(profiles, result);
for (var i in result) {
obj.resourceType = i;
obj = xmlParser.PopulateFromXmlObject(obj, result[i], i);
break;
for (var i in result) {
obj.resourceType = i;
if (obj.resourceType == 'feed') {
delete obj.resourceType;
obj = xmlParser.PopulateBundle(obj, result[i]);
} else {
obj = xmlParser.PopulateFromXmlObject(obj, result[i], i);
}
break;
}
deferred.resolve(obj);
} catch (ex) {
deferred.reject(ex);
}
deferred.resolve(obj);
});

@@ -72,0 +86,0 @@ } catch (ex) {

{
"name": "fhir",
"version": "1.0.4",
"version": "1.0.5",
"description": "Node.JS library for serializing/deserializing FHIR resources between JS/JSON and XML using various node.js XML libraries",

@@ -5,0 +5,0 @@ "readme": "README.md",

@@ -19,3 +19,3 @@ # FHIR.js

```
var FHIR = require('FHIR.js');
var FHIR = require('fhir');
var fhir = new FHIR(FHIR.DSTU1);

@@ -27,2 +27,3 @@ ```

```
var FHIR = require('fhir');
var myPatient = {

@@ -39,2 +40,3 @@ resourceType: 'Patient',

```
var FHIR = require('fhir');
var myPatient = {

@@ -52,2 +54,3 @@ resourceType: 'Patient',

```
var FHIR = require('fhir');
var myPatientXml = '<Patient xmlns="http://hl7.org/fhir"><name><use value="official"/><family value="Chalmers"/><given value="Peter"/><given value="James"/></name></Patient>';

@@ -67,2 +70,3 @@ var fhir = new FHIR(FHIR.DSTU1);

```
var FHIR = require('fhir');
var myPatientXml = '<Patient xmlns="http://hl7.org/fhir"><name><use value="official"/><family value="Chalmers"/><given value="Peter"/><given value="James"/></name></Patient>';

@@ -69,0 +73,0 @@ var fhir = new FHIR(FHIR.DSTU1);

@@ -19,2 +19,4 @@ var Fhir = require('../fhir');

var bundleXml = fs.readFileSync('./test/data/bundle.xml').toString();
var bundle2Xml = fs.readFileSync('./test/data/bundle2.xml').toString();
var bundle3Xml = fs.readFileSync('./test/data/bundle3.xml').toString();

@@ -207,3 +209,3 @@ it('should create a JS Composition object', function(done) {

it('should create a JS Bundle object', function(done) {
it('should create a JS Bundle object from bundle.xml', function(done) {
var fhir = new Fhir(Fhir.DSTU1);

@@ -214,21 +216,14 @@ fhir.XmlToObject(bundleXml)

assert.equal(obj.base, 'http://example.com/base');
assert.equal(obj.id, 'bundle-example');
assert.equal(obj.resourceType, 'Bundle');
assert.equal(obj.type, 'searchset');
assert.equal(obj.total, 3);
assert.equal(obj.title, 'Document Bundle');
assert.equal(obj.updated, '2014-09-09T15:28:48.386Z');
assert.equal(obj.id, 'urn:uuid:da398469-3921-4ab5-9b5e-755d3f88a564');
// assert entries
assert(obj.entry);
assert.equal(obj.entry.length, 2);
assert(obj.entry[0].resource);
assert.equal(obj.entry[0].resource.resourceType, 'MedicationPrescription');
assert(obj.entry[0].resource.medication);
assert(obj.entry[0].resource.patient);
assert(obj.entry[0].search);
assert.equal(obj.entry[0].search.mode, 'match');
assert.equal(obj.entry[0].search.score, 1);
assert.equal(obj.entry[1].resource.resourceType, 'Medication');
assert.equal(obj.entry[1].resource._id, 'example');
assert.equal(obj.entry[1].search.mode, 'include');
assert.equal(obj.entry.length, 11);
assert(obj.entry[0].content);
assert.equal(obj.entry[0].content.resourceType, 'Composition');
assert(obj.entry[0].content.encounter);
assert(obj.entry[0].content.custodian);
assert.equal(obj.entry[0].title, 'Entry 0 for document bundle');

@@ -238,6 +233,2 @@ // assert links

assert.equal(obj.link.length, 2);
assert.equal(obj.link[0].relation, 'self');
assert.equal(obj.link[0].url, 'https://example.com/base/MedicationPrescription?patient=347&_include=MedicationPrescription.medication');
assert.equal(obj.link[1].relation, 'next');
assert.equal(obj.link[1].url, 'https://example.com/base/MedicationPrescription?patient=347&searchId=ff15fd40-ff71-4b48-b366-09c706bed9d0&page=2');

@@ -250,3 +241,72 @@ done();

});
it('should create a JS Bundle object from bundle2.xml', function(done) {
var fhir = new Fhir(Fhir.DSTU1);
fhir.XmlToObject(bundle2Xml)
.then(function (obj) {
assert(obj);
assert.equal(obj.title, 'CDA converted to FHIR');
assert.equal(obj.id, 'cid:d9');
// assert entries
assert(obj.entry);
assert.equal(obj.entry.length, 90);
assert(obj.entry[0].content);
assert.equal(obj.entry[0].content.resourceType, 'Composition');
assert(obj.entry[0].content.custodian);
assert.equal(obj.entry[0].content.date, '2012-09-15T00:00-04:00');
assert(obj.entry[0].content.section);
assert.equal(obj.entry[0].content.section.length, 14);
assert.equal(obj.entry[0].content.title, 'Community Health and Hospitals: Health Summary');
assert.equal(obj.entry[0].title, 'Composition');
done();
})
.catch(function(err) {
done(err);
});
});
it('should create a JS Bundle object from bundle3.xml', function(done) {
var fhir = new Fhir(Fhir.DSTU1);
fhir.XmlToObject(bundle3Xml)
.then(function (obj) {
assert(obj);
assert.equal(obj.title, 'CDA converted to FHIR 2');
assert.equal(obj.id, 'cid:d9');
// assert entries
assert(obj.entry);
assert.equal(obj.entry.length, 1);
assert(obj.entry[0].content);
var composition = obj.entry[0].content;
assert.equal(composition.resourceType, 'Composition');
assert(composition.custodian);
assert.equal(composition.date, '2012-09-15T00:00-04:00');
assert.equal(composition.title, 'Community Health and Hospitals: Health Summary');
assert.equal(obj.entry[0].title, 'Composition');
assert(composition.section);
assert.equal(composition.section.length, 1);
var section = composition.section[0];
assert.equal(section.title, 'ADVANCE DIRECTIVES');
assert(section.code);
assert(section.code.coding);
assert.equal(section.code.coding.length, 1);
assert.equal(section.code.coding[0].code, '42348-3');
assert.equal(section.code.coding[0].system, 'http://loinc.org');
assert(section.content);
assert.equal(section.content.display, 'ADVANCE DIRECTIVES');
assert.equal(section.content.reference, 'cid:d9e621');
done();
})
.catch(function(err) {
done(err);
});
});
});
});
var Fhir = require('../fhir');
var fs = require('fs');
var assert = require('assert');
var assert = require('./assert');
var xpath = require('xpath');
var dom = require('xmldom').DOMParser;
var xpathSelect = xpath.useNamespaces({
"fhir": "http://hl7.org/fhir",
"atom": "http://www.w3.org/2005/Atom"
});
assert.xpathEqual = function(node, xpathString, value) {
var nodes = xpathSelect(xpathString, node);
if (nodes.length == 0) {
assert.fail('xpath did not return any nodes: ' + xpathString);
}
var node = nodes[0];
if (!node || (!node.value && !node.data)) {
assert.fail('xpath node does not have a value: ' + xpathString);
}
assert.equal(node.value ? node.value : node.data, value);
};
assert.xpathNodeName = function(node, xpathString, name) {
var nodeName = xpathSelect('name(' + xpathString + ')', node);
assert.equal(nodeName, name, 'xpath node name does not match: ' + xpathString);
};
assert.xpathCount = function(node, xpathString, count) {
var actual = xpathSelect('count(' + xpathString + ')', node);
assert.equal(actual, count, 'Did not find correct number of nodes: ' + xpathString);
};
describe('JS to XML for FHIR DSTU 1', function() {

@@ -39,0 +8,0 @@ var compositionJson = fs.readFileSync('./test/data/composition.json').toString();

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