From 32ad4770e98423c71775456fadcfebd78e83c9e4 Mon Sep 17 00:00:00 2001 From: Elsa Date: Wed, 11 Dec 2024 09:49:04 -0500 Subject: [PATCH 1/2] OR Multiple _typeFilters --- src/services/export.service.js | 4 +++- src/util/exportToNDJson.js | 3 ++- test/util/exportToNDJson.test.js | 9 +++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/services/export.service.js b/src/services/export.service.js index 56bdc82..f95e3da 100644 --- a/src/services/export.service.js +++ b/src/services/export.service.js @@ -229,7 +229,9 @@ function validateExportParams(parameters, reply) { } if (parameters._typeFilter) { - const typeFilterArray = parameters._typeFilter.split(','); + const typeFilterArray = Array.isArray(parameters._typeFilter) + ? parameters._typeFilter + : parameters._typeFilter.split(','); const unsupportedTypeFilterTypes = []; typeFilterArray.forEach(line => { const resourceType = line.substring(0, line.indexOf('?')); diff --git a/src/util/exportToNDJson.js b/src/util/exportToNDJson.js index 2ce5101..4aa0e38 100644 --- a/src/util/exportToNDJson.js +++ b/src/util/exportToNDJson.js @@ -78,7 +78,7 @@ const exportToNDJson = async jobOptions => { const valueSetQueries = {}; if (typeFilter) { // subqueries may be joined together with a comma for a logical "or" - const tyq = typeFilter.split(','); + const tyq = Array.isArray(typeFilter) ? typeFilter : typeFilter.split(','); // loop over each subquery and extract all search params, which are joined via the "&" operator // each subquery is of the format ? tyq.forEach(query => { @@ -104,6 +104,7 @@ const exportToNDJson = async jobOptions => { valueSetQueries[resourceType] = { [property]: [propertyValue] }; } } else { + // TODO: this gets overwritten for subqueries with "&" operators subqueries[property] = propertyValue; } }); diff --git a/test/util/exportToNDJson.test.js b/test/util/exportToNDJson.test.js index aa7f9c6..cdd2191 100644 --- a/test/util/exportToNDJson.test.js +++ b/test/util/exportToNDJson.test.js @@ -27,6 +27,10 @@ const mockTypeFilter = 'Patient?maritalStatus:in=http://example.com/example-valu const complexMockTypeFilter = 'Patient?maritalStatus:in=http://example.com/example-valueset-1,Encounter?type:in=http://example.com/example-valueset-1,ServiceRequest?code:in=http://example.com/example-valueset-1'; +const mockOrTypeFilter = [ + 'Patient?maritalStatus:in=http://example.com/example-valueset-1', + 'Encounter?type:in=http://example.com/example-valueset-1' +]; const expectedFileNameEncounter = './tmp/123456/Encounter.ndjson'; const expectedFileNameServiceRequest = './tmp/123456/ServiceRequest.ndjson'; const typeFilterWOValueSet = 'Procedure?type:in=http'; @@ -82,6 +86,11 @@ describe('check export logic', () => { expect(fs.existsSync(expectedFileNameEncounter)).toBe(true); expect(fs.existsSync(expectedFileNameServiceRequest)).toBe(true); }); + test('Expect folder created and export successful when Array _typeFilter parameter is retrieved from request', async () => { + await exportToNDJson({ clientEntry: clientId, type: mockType, typeFilter: mockOrTypeFilter }); + expect(fs.existsSync(expectedFileName)).toBe(true); + expect(fs.existsSync(expectedFileNameEncounter)).toBe(true); + }); test('Expect folder created and export to fail when _typeFilter parameter is retrieved from request and contains an invalid param', async () => { // Note: invalid types are checked in the export service await exportToNDJson({ clientEntry: clientId, type: mockType, typeFilter: typeFilterWithInvalidType }); From 9bbd0e07132404ce3d4ccde47a67a9bda3500c3f Mon Sep 17 00:00:00 2001 From: Elsa Date: Mon, 16 Dec 2024 08:56:32 -0500 Subject: [PATCH 2/2] Comment update --- src/util/exportToNDJson.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/exportToNDJson.js b/src/util/exportToNDJson.js index 4aa0e38..683acd4 100644 --- a/src/util/exportToNDJson.js +++ b/src/util/exportToNDJson.js @@ -77,7 +77,7 @@ const exportToNDJson = async jobOptions => { const searchParameterQueries = {}; const valueSetQueries = {}; if (typeFilter) { - // subqueries may be joined together with a comma for a logical "or" + // subqueries may be joined together with a comma or as an array for a logical "or" const tyq = Array.isArray(typeFilter) ? typeFilter : typeFilter.split(','); // loop over each subquery and extract all search params, which are joined via the "&" operator // each subquery is of the format ?