diff --git a/.gitignore b/.gitignore index bc2cd3e..5d4e70a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ build .DS_Store .editorconfig Makefile +browser-build/fhirpath.min.js.map diff --git a/CHANGELOG.md b/CHANGELOG.md index 439a294..ebc773f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,13 @@ This log documents significant changes for each release. This project follows [Semantic Versioning](http://semver.org/). +## [0.17.5] - 2019-11-18 +### Fixed +- Although one could add a Quantity to a date, subtracting the quantity resulted + in an error. +- Fixed functions toDateTime() and toTime(), for the minified versions of the + code. + ## [0.17.4] - 2019-10-22 ### Fixed - Fixed the compile API, so that the returned function now takes the "context" diff --git a/browser-build/webpack.config.js b/browser-build/webpack.config.js index ce3cfcb..2e1beca 100644 --- a/browser-build/webpack.config.js +++ b/browser-build/webpack.config.js @@ -7,7 +7,7 @@ module.exports = { entry: './fhirpathRequire.js', mode: 'production', // mode: 'development', - // devtool: 'source-map', + devtool: 'source-map', output: { path: __dirname, filename: './fhirpath.min.js', diff --git a/demo/test/protractor/spec/json.spec.js b/demo/test/protractor/spec/json.spec.js index 7f60ba8..54514ba 100644 --- a/demo/test/protractor/spec/json.spec.js +++ b/demo/test/protractor/spec/json.spec.js @@ -15,4 +15,15 @@ describe('JSON entry mode', function() { expect(cmVal).toContain('"resourceType": "Patient"'); // json expect(output.getText()).toEqual('- Jim'); }); + +}); + +describe('minified FHIRPath', function() { + // This section tests that the minification process has not broken things. + it('should have a working toDateTime()', function () { + $('#path').clear(); + $('#path').sendKeys('birthDate.toDateTime()'); + var EC = protractor.ExpectedConditions; + browser.wait(EC.textToBePresentInElement($('#output'), '1974'), 3000); + }); }); diff --git a/demo/webpack.config.js b/demo/webpack.config.js index 289424e..4106523 100644 --- a/demo/webpack.config.js +++ b/demo/webpack.config.js @@ -7,7 +7,7 @@ module.exports = { devServer: { contentBase: './build' }, - devtool: 'inline-source-map', + devtool: 'source-map', module: { rules: [ { diff --git a/package-lock.json b/package-lock.json index 4a71f2f..5305b3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "fhirpath", - "version": "0.17.4", + "version": "0.17.5", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -8335,9 +8335,9 @@ } }, "handlebars": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.0.tgz", - "integrity": "sha512-xkRtOt3/3DzTKMOt3xahj2M/EqNhY988T+imYSlMgs5fVhLN2fmKVVj0LtEGmb+3UUYV5Qmm1052Mm3dIQxOvw==", + "version": "4.5.3", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.5.3.tgz", + "integrity": "sha512-3yPecJoJHK/4c6aZhSvxOyG4vJKDshV36VHp0iVCDVh7o9w2vwi3NSnL2MMPj3YdduqaBcu7cGbggJQM0br9xA==", "dev": true, "requires": { "neo-async": "^2.6.0", @@ -13882,20 +13882,20 @@ "dev": true }, "uglify-js": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", - "integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==", + "version": "3.6.9", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.9.tgz", + "integrity": "sha512-pcnnhaoG6RtrvHJ1dFncAe8Od6Nuy30oaJ82ts6//sGSXOP5UjBMEthiProjXmMNHOfd93sqlkztifFMcb+4yw==", "dev": true, "optional": true, "requires": { - "commander": "~2.20.0", + "commander": "~2.20.3", "source-map": "~0.6.1" }, "dependencies": { "commander": { - "version": "2.20.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.1.tgz", - "integrity": "sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg==", + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true, "optional": true }, diff --git a/package.json b/package.json index cd27329..6b4d205 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fhirpath", - "version": "0.17.4", + "version": "0.17.5", "description": "A FHIRPath engine", "main": "src/fhirpath.js", "dependencies": { diff --git a/src/fhirpath.js b/src/fhirpath.js index 1c57437..3b97699 100644 --- a/src/fhirpath.js +++ b/src/fhirpath.js @@ -130,7 +130,7 @@ engine.invocationTable = { "inOp": {fn: collections.in, arity: {2: ["Any", "Any"]}}, "&": {fn: math.amp, arity: {2: ["String", "String"]}}, "+": {fn: math.plus, arity: {2: ["Any", "Any"]}, nullable: true}, - "-": {fn: math.minus, arity: {2: ["Number", "Number"]}, nullable: true}, + "-": {fn: math.minus, arity: {2: ["Any", "Any"]}, nullable: true}, "*": {fn: math.mul, arity: {2: ["Number", "Number"]}, nullable: true}, "/": {fn: math.div, arity: {2: ["Number", "Number"]}, nullable: true}, "mod": {fn: math.mod, arity: {2: ["Number", "Number"]}, nullable: true}, diff --git a/src/math.js b/src/math.js index 2ebfd3c..b202b04 100644 --- a/src/math.js +++ b/src/math.js @@ -34,6 +34,7 @@ engine.amp = function(x, y){ }; //HACK: for only polymorphic function +// Actually, "minus" is now also polymorphic engine.plus = function(xs, ys){ if(xs.length == 1 && ys.length == 1) { var x = xs[0]; @@ -51,8 +52,16 @@ engine.plus = function(xs, ys){ throw new Error("Can not " + JSON.stringify(xs) + " + " + JSON.stringify(ys)); }; -engine.minus = function(x, y){ - return x - y; +engine.minus = function(xs, ys){ + if(xs.length == 1 && ys.length == 1) { + var x = xs[0]; + var y = ys[0]; + if(typeof x == "number" && typeof y == "number") + return x - y; + if(x instanceof FP_TimeBase && y instanceof FP_Quantity) + return x.plus(new FP_Quantity(-y.value, y.unit)); + } + throw new Error("Can not " + JSON.stringify(xs) + " - " + JSON.stringify(ys)); }; diff --git a/src/misc.js b/src/misc.js index 72e87f4..2c4042f 100644 --- a/src/misc.js +++ b/src/misc.js @@ -4,8 +4,6 @@ var util = require("./utilities"); var types = require("./types"); -var FP_DateTime = types.FP_DateTime; -var FP_Time = types.FP_Time; var engine = {}; @@ -73,23 +71,23 @@ engine.toString = function(coll){ /** * Defines a function on engine called to+timeType (e.g., toDateTime, etc.). - * @param timeType a class (contsructor) for a time type (e.g. FP_DateTime). + * @param timeType The string name of a class for a time type (e.g. "FP_DateTime"). */ function defineTimeConverter(timeType) { - let timeName = timeType.name.slice(3); + let timeName = timeType.slice(3); // Remove 'FP_' engine['to'+timeName] = function(coll) { var rtn = []; if (coll.length > 1) throw Error('to '+timeName+' called for a collection of length '+coll.length); if (coll.length === 1) { - var t = timeType.checkString(coll[0]); + var t = types[timeType].checkString(coll[0]); if (t) rtn[0] = t; } return rtn; }; } -defineTimeConverter(FP_DateTime); -defineTimeConverter(FP_Time); +defineTimeConverter('FP_DateTime'); +defineTimeConverter('FP_Time'); module.exports = engine; diff --git a/test/cases/6.6_math.yaml b/test/cases/6.6_math.yaml index a13148f..cada6d2 100644 --- a/test/cases/6.6_math.yaml +++ b/test/cases/6.6_math.yaml @@ -143,6 +143,8 @@ tests: result: ['2016-02-29'] - expression: "@2016-02-28 + 2 days" result: ['2016-03-01'] + - expression: "@2016-02-28 - 2 days" + result: ['2016-02-26'] - expression: "@2016-01-01 + 1 month" result: ['2016-02-01'] - expression: "@T09:45:23 + 2 years" diff --git a/webpack.config.js b/webpack.config.js index 6395c49..0673947 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -10,6 +10,7 @@ module.exports = { ] }, mode: 'production', + devtool: 'source-map', output: { path: __dirname, filename: 'build/fhirpath.js',