Skip to content

Commit

Permalink
Merge pull request #12 in LFOR/fhirpath.js from bugfix/LF-1465/substr…
Browse files Browse the repository at this point in the history
…ing-function-issue to master

* commit 'e18db57735e40b28b09d99256d5ac4e249322231':
  Updated version info
  Fixed issue with calling function "substring" without a second parameter
  • Loading branch information
plynchnlm committed Jun 5, 2020
2 parents 0098641 + e18db57 commit 8da56ba
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
This log documents significant changes for each release. This project follows
[Semantic Versioning](http://semver.org/).

## [2.2.1] - 2020-06-03
### Fixed
- Issue with substring function without a second parameter

## [2.2.0] - 2020-05-26
### Added
- Function aggregate(aggregator, init)
Expand Down
33 changes: 9 additions & 24 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": "2.2.0",
"version": "2.2.1",
"description": "A FHIRPath engine",
"main": "src/fhirpath.js",
"dependencies": {
Expand Down
6 changes: 6 additions & 0 deletions src/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ engine.indexOf = function(coll, substr){

engine.substring = function(coll, start, length){
var str = ensureStringSingleton(coll);
if (util.isEmpty(start) || start < 0 || start >= str.length) {
return [];
}
if (length === undefined || util.isEmpty(length)) {
return str.substring(start);
}
return str.substring(start, start + length);
};

Expand Down
2 changes: 0 additions & 2 deletions test/cases/5.5_conversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ tests:
- desc: inequality
expression: "datetime.toDateTime() = @2010-02-06T19:17-05:00"
result: [false]
focus: true

- 'group: toTime':
- desc: equality
Expand All @@ -85,7 +84,6 @@ tests:
- desc: inequality operator
expression: "time.toTime() != @T18:15-05:00"
result: [true]
focus: true


- desc: '5.5.4. toString() : string'
Expand Down
10 changes: 8 additions & 2 deletions test/cases/5.6_string_manipulation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ tests:

- desc: '** substring without length'
expression: Functions.str.attr.substring(5)
disable: true
result: ['string']

- desc: '** substring with outside index'
expression: Functions.str.attr.substring(55)
disable: true
result: []

- desc: '** substring with empty index'
expression: Functions.str.attr.substring(EmptyStart)
result: []

- desc: '** substring with outside length'
expression: Functions.str.attr.substring(5, 55)
result: ['string']

- desc: '** substring with empty length'
expression: Functions.str.attr.substring(5, EmptyLength)
result: ['string']


- desc: '5.6.3. startsWith(prefix : string) : boolean'
# If the input collection contains a single item of type string, the function will return true when the input string starts with the given prefix. Also returns true when prefix is the empty string.
Expand Down
12 changes: 3 additions & 9 deletions test/cases/fhir-r4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ tests:
- 'group: Dollar':
- desc: '** testDollarThis1'
inputfile: patient-example.json
disable: true
expression: Patient.name.given.where(substring($this.length()-3) = 'out')
result: []
- desc: '** testDollarThis2'
inputfile: patient-example.json
disable: true
expression: Patient.name.given.where(substring($this.length()-3) = 'ter')
result:
- Peter
Expand Down Expand Up @@ -1023,11 +1022,10 @@ tests:
- ''
- desc: '** test'
inputfile: questionnaire-example.json
disable: true
expression: 'Questionnaire.descendants().linkId.select(substring(0,1)).distinct()'
result:
- ''
- ''
- '1'
- '2'
- 'group: testCount':
- desc: '** test'
inputfile: patient-example.json
Expand Down Expand Up @@ -1363,7 +1361,6 @@ tests:
- 'group: testSubstring':
- desc: '** test'
inputfile: patient-example.json
disable: true
expression: '''12345''.substring(2) = ''345'''
result:
- true
Expand All @@ -1374,19 +1371,16 @@ tests:
- true
- desc: '** test'
inputfile: patient-example.json
disable: true
expression: '''12345''.substring(2,5) = ''345'''
result:
- true
- desc: '** test'
inputfile: patient-example.json
disable: true
expression: '''12345''.substring(25).empty()'
result:
- true
- desc: '** test'
inputfile: patient-example.json
disable: true
expression: '''12345''.substring(-1).empty()'
result:
- true
Expand Down

0 comments on commit 8da56ba

Please sign in to comment.