Skip to content

Commit

Permalink
Merge pull request #51 in LFOR/fhirpath.js from bugfix/LF-2590/third-…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
yuriy-sedinkin committed Apr 5, 2023
2 parents b1d41e0 + f092318 commit 905f0a5
Show file tree
Hide file tree
Showing 10 changed files with 1,443 additions and 2,956 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/).

## [3.3.2] - 2023-03-29
### Fixed
- toQuantity() now works with subclasses of Quantity.

## [3.3.1] - 2022-11-22
### Fixed
- Aggregate init parameter can be any type, not just an integer.
Expand Down
3 changes: 2 additions & 1 deletion browser-build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function makeBaseConfig() {
devtool: 'source-map',
output: {
libraryTarget: 'window',
path: __dirname
path: __dirname,
chunkFormat: 'commonjs'
},
module: {
rules: [
Expand Down
2,810 changes: 929 additions & 1,881 deletions demo/package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"yaml-loader": "^0.5.0"
},
"devDependencies": {
"css-loader": "^6.7.1",
"file-loader": "^1.1.11",
"css-loader": "^6.7.3",
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.5.0",
"js-yaml": "^3.13.1",
"style-loader": "^3.3.1",
"webpack": "^5.11.1",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.7.3",
"style-loader": "^3.3.2",
"webpack": "^5.78.0",
"webpack-cli": "^5.0.1",
"webpack-dev-server": "^4.13.2",
"webpack-serve": "^4.0.0"
},
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion demo/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module.exports = {
entry: './public/app.js',
output: {
path: __dirname + '/build',
filename: 'app.js'
filename: 'app.js',
chunkFormat: 'commonjs'
},
devServer: {
static: './build'
Expand Down
1,479 changes: 443 additions & 1,036 deletions package-lock.json

Large diffs are not rendered by default.

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": "3.3.1",
"version": "3.3.2",
"description": "A FHIRPath engine",
"main": "src/fhirpath.js",
"dependencies": {
Expand Down
69 changes: 39 additions & 30 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,25 +1065,23 @@ class ResourceNode {
*/
convertData() {
var data = this.data;
switch (this.path) {
case 'Quantity':
if (data?.system === ucumSystemUrl) {
if (typeof data.value === 'number' && typeof data.code === 'string') {
if (data.comparator !== undefined)
throw new Error('Cannot convert a FHIR.Quantity that has a comparator');
data =
new FP_Quantity(data.value, FP_Quantity.mapUCUMCodeToTimeUnits[data.code] || '\'' + data.code + '\'');
}
if (TypeInfo.isType(this.path, 'Quantity')) {
if (data?.system === ucumSystemUrl) {
if (typeof data.value === 'number' && typeof data.code === 'string') {
if (data.comparator !== undefined)
throw new Error('Cannot convert a FHIR.Quantity that has a comparator');
data = new FP_Quantity(
data.value,
FP_Quantity.mapUCUMCodeToTimeUnits[data.code] || '\'' + data.code + '\''
);
}
break;
case 'date':
data = FP_Date.checkString(data) || data;
break;
case 'dateTime':
data = FP_DateTime.checkString(data) || data;
break;
case 'time':
data = FP_Time.checkString(data) || data;
}
} else if (this.path === 'date') {
data = FP_Date.checkString(data) || data;
} else if (this.path === 'dateTime') {
data = FP_DateTime.checkString(data) || data;
} else if (this.path === 'time') {
data = FP_Time.checkString(data) || data;
}

return data;
Expand Down Expand Up @@ -1122,23 +1120,34 @@ class TypeInfo {
* @return {boolean}
*/
is(other) {
if (other instanceof TypeInfo
&& (!this.namespace || !other.namespace || this.namespace === other.namespace)) {
if (TypeInfo.model && (!this.namespace || this.namespace === TypeInfo.FHIR)) {
let name = this.name;
do {
if (name === other.name) {
return true;
}
} while ((name = TypeInfo.model.type2Parent[name]));
} else {
return this.name === other.name;
}
if (
other instanceof TypeInfo &&
(!this.namespace || !other.namespace || this.namespace === other.namespace)
) {
return TypeInfo.model && (!this.namespace || this.namespace === TypeInfo.FHIR)
? TypeInfo.isType(this.name, other.name)
: this.name === other.name;
}
return false;
}
}

/**
* Checks if the type name or its parent type name is equal to
* the expected type name.
* @param type - type name to check.
* @param superType - expected type name.
* @return {boolean}
*/
TypeInfo.isType = function(type, superType) {
do {
if (type === superType) {
return true;
}
} while ((type = TypeInfo.model?.type2Parent[type]));
return false;
};

// Available namespaces:
TypeInfo.System = 'System';
TypeInfo.FHIR = 'FHIR';
Expand Down
6 changes: 6 additions & 0 deletions test/cases/5.5_conversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ tests:
expression: '''1 year''.toQuantity() ~ 1 ''a'''
result:
- true
- desc: '** Duration to Quantity'
inputfile: medicationrequest-example.json
expression: "MedicationRequest.dispenseRequest.expectedSupplyDuration.toQuantity() = 3 days"
model: 'r4'
result:
- true
- desc: '** UCUM units'
inputfile: patient-example.json
expression: "'1 \\'cm\\''.toQuantity('mm').value = 10"
Expand Down
11 changes: 11 additions & 0 deletions test/resources/medicationrequest-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"resourceType": "MedicationRequest",
"dispenseRequest": {
"expectedSupplyDuration": {
"value": 3,
"unit": "days",
"system": "http://unitsofmeasure.org",
"code": "d"
}
}
}

0 comments on commit 905f0a5

Please sign in to comment.