Skip to content

Commit

Permalink
Merge pull request #30 from HL7/fix_date_subtraction
Browse files Browse the repository at this point in the history
Fixed #29
  • Loading branch information
plynchnlm authored Nov 19, 2019
2 parents af921b7 + c615acf commit ef8b7c5
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ build
.DS_Store
.editorconfig
Makefile
browser-build/fhirpath.min.js.map
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion browser-build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 11 additions & 0 deletions demo/test/protractor/spec/json.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
2 changes: 1 addition & 1 deletion demo/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
devServer: {
contentBase: './build'
},
devtool: 'inline-source-map',
devtool: 'source-map',
module: {
rules: [
{
Expand Down
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fhirpath",
"version": "0.17.4",
"version": "0.17.5",
"description": "A FHIRPath engine",
"main": "src/fhirpath.js",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/fhirpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
13 changes: 11 additions & 2 deletions src/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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));
};


Expand Down
12 changes: 5 additions & 7 deletions src/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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;
2 changes: 2 additions & 0 deletions test/cases/6.6_math.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
]
},
mode: 'production',
devtool: 'source-map',
output: {
path: __dirname,
filename: 'build/fhirpath.js',
Expand Down

0 comments on commit ef8b7c5

Please sign in to comment.