From 001e8745bb595991bc7310aea49e266dd6441cd1 Mon Sep 17 00:00:00 2001 From: sedinkinya Date: Tue, 21 Jan 2025 16:12:29 -0500 Subject: [PATCH] Async boolean bug LF-3224 --- CHANGELOG.md | 5 +++++ package-lock.json | 4 ++-- package.json | 2 +- src/fhirpath.js | 5 ++++- test/async-functions.test.js | 34 ++++++++++++++++++++++++++++++---- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbc1649..da853d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/package-lock.json b/package-lock.json index 766823c..a0fdca0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fhirpath", - "version": "3.16.2", + "version": "3.16.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "fhirpath", - "version": "3.16.2", + "version": "3.16.3", "hasInstallScript": true, "license": "SEE LICENSE in LICENSE.md", "dependencies": { diff --git a/package.json b/package.json index f7d462e..dc4120f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/fhirpath.js b/src/fhirpath.js index 66fba29..af87540 100644 --- a/src/fhirpath.js +++ b/src/fhirpath.js @@ -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){ diff --git a/test/async-functions.test.js b/test/async-functions.test.js index 82f3416..b8b0c72 100644 --- a/test/async-functions.test.js +++ b/test/async-functions.test.js @@ -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/, { @@ -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) => {