Skip to content

Commit 905f0a5

Browse files
Merge pull request #51 in LFOR/fhirpath.js from bugfix/LF-2590/third-party-pr-to-fix-toquantity to master
* commit 'f092318de6ce2e2d71fe5fc922e8b40894e33c7c': npm audit fix Changes as per review toQuantity() for subclasses of Quantity consider Duration object in convertData
2 parents b1d41e0 + f092318 commit 905f0a5

10 files changed

Lines changed: 1443 additions & 2956 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
This log documents significant changes for each release. This project follows
44
[Semantic Versioning](http://semver.org/).
55

6+
## [3.3.2] - 2023-03-29
7+
### Fixed
8+
- toQuantity() now works with subclasses of Quantity.
9+
610
## [3.3.1] - 2022-11-22
711
### Fixed
812
- Aggregate init parameter can be any type, not just an integer.

browser-build/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function makeBaseConfig() {
1212
devtool: 'source-map',
1313
output: {
1414
libraryTarget: 'window',
15-
path: __dirname
15+
path: __dirname,
16+
chunkFormat: 'commonjs'
1617
},
1718
module: {
1819
rules: [

demo/package-lock.json

Lines changed: 929 additions & 1881 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
"yaml-loader": "^0.5.0"
1010
},
1111
"devDependencies": {
12-
"css-loader": "^6.7.1",
13-
"file-loader": "^1.1.11",
12+
"css-loader": "^6.7.3",
13+
"file-loader": "^6.2.0",
1414
"html-webpack-plugin": "^5.5.0",
1515
"js-yaml": "^3.13.1",
16-
"style-loader": "^3.3.1",
17-
"webpack": "^5.11.1",
18-
"webpack-cli": "^4.9.1",
19-
"webpack-dev-server": "^4.7.3",
16+
"style-loader": "^3.3.2",
17+
"webpack": "^5.78.0",
18+
"webpack-cli": "^5.0.1",
19+
"webpack-dev-server": "^4.13.2",
2020
"webpack-serve": "^4.0.0"
2121
},
2222
"scripts": {

demo/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module.exports = {
22
entry: './public/app.js',
33
output: {
44
path: __dirname + '/build',
5-
filename: 'app.js'
5+
filename: 'app.js',
6+
chunkFormat: 'commonjs'
67
},
78
devServer: {
89
static: './build'

package-lock.json

Lines changed: 443 additions & 1036 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fhirpath",
3-
"version": "3.3.1",
3+
"version": "3.3.2",
44
"description": "A FHIRPath engine",
55
"main": "src/fhirpath.js",
66
"dependencies": {

src/types.js

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,25 +1065,23 @@ class ResourceNode {
10651065
*/
10661066
convertData() {
10671067
var data = this.data;
1068-
switch (this.path) {
1069-
case 'Quantity':
1070-
if (data?.system === ucumSystemUrl) {
1071-
if (typeof data.value === 'number' && typeof data.code === 'string') {
1072-
if (data.comparator !== undefined)
1073-
throw new Error('Cannot convert a FHIR.Quantity that has a comparator');
1074-
data =
1075-
new FP_Quantity(data.value, FP_Quantity.mapUCUMCodeToTimeUnits[data.code] || '\'' + data.code + '\'');
1076-
}
1068+
if (TypeInfo.isType(this.path, 'Quantity')) {
1069+
if (data?.system === ucumSystemUrl) {
1070+
if (typeof data.value === 'number' && typeof data.code === 'string') {
1071+
if (data.comparator !== undefined)
1072+
throw new Error('Cannot convert a FHIR.Quantity that has a comparator');
1073+
data = new FP_Quantity(
1074+
data.value,
1075+
FP_Quantity.mapUCUMCodeToTimeUnits[data.code] || '\'' + data.code + '\''
1076+
);
10771077
}
1078-
break;
1079-
case 'date':
1080-
data = FP_Date.checkString(data) || data;
1081-
break;
1082-
case 'dateTime':
1083-
data = FP_DateTime.checkString(data) || data;
1084-
break;
1085-
case 'time':
1086-
data = FP_Time.checkString(data) || data;
1078+
}
1079+
} else if (this.path === 'date') {
1080+
data = FP_Date.checkString(data) || data;
1081+
} else if (this.path === 'dateTime') {
1082+
data = FP_DateTime.checkString(data) || data;
1083+
} else if (this.path === 'time') {
1084+
data = FP_Time.checkString(data) || data;
10871085
}
10881086

10891087
return data;
@@ -1122,23 +1120,34 @@ class TypeInfo {
11221120
* @return {boolean}
11231121
*/
11241122
is(other) {
1125-
if (other instanceof TypeInfo
1126-
&& (!this.namespace || !other.namespace || this.namespace === other.namespace)) {
1127-
if (TypeInfo.model && (!this.namespace || this.namespace === TypeInfo.FHIR)) {
1128-
let name = this.name;
1129-
do {
1130-
if (name === other.name) {
1131-
return true;
1132-
}
1133-
} while ((name = TypeInfo.model.type2Parent[name]));
1134-
} else {
1135-
return this.name === other.name;
1136-
}
1123+
if (
1124+
other instanceof TypeInfo &&
1125+
(!this.namespace || !other.namespace || this.namespace === other.namespace)
1126+
) {
1127+
return TypeInfo.model && (!this.namespace || this.namespace === TypeInfo.FHIR)
1128+
? TypeInfo.isType(this.name, other.name)
1129+
: this.name === other.name;
11371130
}
11381131
return false;
11391132
}
11401133
}
11411134

1135+
/**
1136+
* Checks if the type name or its parent type name is equal to
1137+
* the expected type name.
1138+
* @param type - type name to check.
1139+
* @param superType - expected type name.
1140+
* @return {boolean}
1141+
*/
1142+
TypeInfo.isType = function(type, superType) {
1143+
do {
1144+
if (type === superType) {
1145+
return true;
1146+
}
1147+
} while ((type = TypeInfo.model?.type2Parent[type]));
1148+
return false;
1149+
};
1150+
11421151
// Available namespaces:
11431152
TypeInfo.System = 'System';
11441153
TypeInfo.FHIR = 'FHIR';

test/cases/5.5_conversion.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ tests:
163163
expression: '''1 year''.toQuantity() ~ 1 ''a'''
164164
result:
165165
- true
166+
- desc: '** Duration to Quantity'
167+
inputfile: medicationrequest-example.json
168+
expression: "MedicationRequest.dispenseRequest.expectedSupplyDuration.toQuantity() = 3 days"
169+
model: 'r4'
170+
result:
171+
- true
166172
- desc: '** UCUM units'
167173
inputfile: patient-example.json
168174
expression: "'1 \\'cm\\''.toQuantity('mm').value = 10"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"resourceType": "MedicationRequest",
3+
"dispenseRequest": {
4+
"expectedSupplyDuration": {
5+
"value": 3,
6+
"unit": "days",
7+
"system": "http://unitsofmeasure.org",
8+
"code": "d"
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)