Skip to content

Commit

Permalink
Merge branch 'bugfix/LF-3224/async-boolean-bug' into 'master'
Browse files Browse the repository at this point in the history
Async boolean bug

See merge request lfor/fhirpath.js!25
  • Loading branch information
yuriy-sedinkin committed Jan 23, 2025
2 parents 90a2f39 + 001e874 commit 25ea062
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
This log documents significant changes for each release. This project follows
[Semantic Versioning](http://semver.org/).

## [3.16.3] - 2025-01-21
### Fixed
- Bug with async boolean expressions (when an operator takes an async value as
a singleton parameter).

## [3.16.2] - 2025-01-16
### Fixed
- Bug with toString when userInvocationTable passed.
Expand Down
4 changes: 2 additions & 2 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": "3.16.2",
"version": "3.16.3",
"description": "A FHIRPath engine",
"main": "src/fhirpath.js",
"types": "src/fhirpath.d.ts",
Expand Down
5 changes: 4 additions & 1 deletion src/fhirpath.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,10 @@ function makeParam(ctx, parentData, type, param) {
}
}
}
return misc.singleton(res, type);

return res instanceof Promise ?
res.then(r => misc.singleton(r, type)) :
misc.singleton(res, type);
}

function doInvoke(ctx, fnName, data, rawParams){
Expand Down
34 changes: 30 additions & 4 deletions test/async-functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ function mockFetchResults(results) {
}

describe('Async functions', () => {
afterEach(() => {
fetchSpy?.mockRestore();
})

describe('%terminologies.validateVS', () => {
afterEach(() => {
fetchSpy?.mockRestore();
})

it('should work ', (done) => {
mockFetchResults([
[/code=29463-7/, {
Expand Down Expand Up @@ -305,6 +304,33 @@ describe('Async functions', () => {
);
expect(result).toThrow('The asynchronous function "memberOf" is not allowed. To enable asynchronous functions, use the async=true or async="always" option.');
});

it('should correctly process an async result in a boolean expression (when it is a singleton parameter)', (done) => {
mockFetchResults([
[/ValueSet\/\$validate-code/, {
"resourceType": "Parameters",
"parameter": [
{
"name": "result",
"valueBoolean": true
}
]
}]
]);
let result = fhirpath.evaluate(
resource,
"Observation.code.memberOf('http://hl7.org/fhir/ValueSet/observation-vitalsignresult') or false",
{},
model,
{ async: true, terminologyUrl: "https://lforms-fhir.nlm.nih.gov/baseR4" }
);
expect(result instanceof Promise).toBe(true);
result.then((r) => {
expect(r).toEqual([true]);
done();
})
});

});

it('should be a conversion of the result to a Promise when option async is set to "always"', (done) => {
Expand Down

0 comments on commit 25ea062

Please sign in to comment.