handlebars-helpers-fhir
Advanced tools
Comparing version 0.0.5 to 0.0.6
14
index.js
@@ -59,3 +59,7 @@ const fhirpath = require('fhirpath'); | ||
let criteria = `where(resourceType=\'${type}\').where(id=\'${id}\')`; | ||
let expression = `entry.content.${criteria}|entry.resource.${criteria}|contained.${criteria}`; | ||
let expression = config.location | ||
.map((item)=>{ | ||
return `${item}.${criteria}`; | ||
}) | ||
.join('|'); | ||
let match = fhirpath.evaluate(options.data.root, expression)[0]; | ||
@@ -67,4 +71,10 @@ | ||
//TODO: unless FHIR | ||
var config = { | ||
location: ['entry.resource', 'contained'] | ||
}; | ||
module.exports.useOptions = function(options){ | ||
config = options | ||
}; | ||
module.exports.registerWith = function (handlebars) { | ||
@@ -71,0 +81,0 @@ handlebars.registerHelper('if-fhir', makeIf()); |
'use strict'; | ||
const handlebars = require('handlebars'); | ||
require('./index').registerWith(handlebars); | ||
const helpers = require('./index'); | ||
helpers.registerWith(handlebars); | ||
@@ -407,3 +408,31 @@ const should = require('chai').should(); | ||
it('should render block using a bundled resource (DSTU1 bundle syntax)', () => { | ||
it('should render block using a contained resource', () => { | ||
let template = "{{#resolve-fhir . expression='Foo.bar.reference'}}Value is: {{val}}{{/resolve-fhir}}"; | ||
let compiledTemplate = handlebars.compile(template); | ||
let resource = { | ||
resourceType: 'Foo', | ||
bar: { | ||
reference: 'Bar/1' | ||
}, | ||
val: 'a', | ||
contained: [ | ||
{ | ||
resourceType: 'Bar', | ||
id: '1', | ||
val: 'b' | ||
} | ||
] | ||
}; | ||
let result = compiledTemplate(resource); | ||
should.exist(result); | ||
result.should.equal('Value is: b'); | ||
}); | ||
it('should render block using a custom bundled resource (DSTU1 bundle syntax)', () => { | ||
helpers.useOptions({ | ||
location: ['content.entry.content', 'entry.content', 'entry.resource', 'contained'] | ||
}); | ||
let template = "{{#resolve-fhir . expression='entry.content.Foo.bar.reference'}}Value is: {{val}}{{/resolve-fhir}}"; | ||
@@ -440,27 +469,2 @@ let compiledTemplate = handlebars.compile(template); | ||
it('should render block using a contained resource', () => { | ||
let template = "{{#resolve-fhir . expression='Foo.bar.reference'}}Value is: {{val}}{{/resolve-fhir}}"; | ||
let compiledTemplate = handlebars.compile(template); | ||
let resource = { | ||
resourceType: 'Foo', | ||
bar: { | ||
reference: 'Bar/1' | ||
}, | ||
val: 'a', | ||
contained: [ | ||
{ | ||
resourceType: 'Bar', | ||
id: '1', | ||
val: 'b' | ||
} | ||
] | ||
}; | ||
let result = compiledTemplate(resource); | ||
should.exist(result); | ||
result.should.equal('Value is: b'); | ||
}); | ||
it('should not render block when referenced resource not found', () => { | ||
@@ -467,0 +471,0 @@ let template = "{{#resolve-fhir . expression='entry.resource.Foo.bar.reference'}}Value is: {{val}}{{/resolve-fhir}}"; |
{ | ||
"name": "handlebars-helpers-fhir", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Helper functions for the Handlebars templating engine using fhirpath to reference HL7 FHIR resources from within templates.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
91920
541