Skip to content

Commit

Permalink
OR Multiple _typeFilters
Browse files Browse the repository at this point in the history
  • Loading branch information
elsaperelli committed Dec 11, 2024
1 parent eb42a6c commit 32ad477
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/services/export.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ function validateExportParams(parameters, reply) {
}

if (parameters._typeFilter) {
const typeFilterArray = parameters._typeFilter.split(',');
const typeFilterArray = Array.isArray(parameters._typeFilter)
? parameters._typeFilter

Check warning on line 233 in src/services/export.service.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
: parameters._typeFilter.split(',');
const unsupportedTypeFilterTypes = [];
typeFilterArray.forEach(line => {
const resourceType = line.substring(0, line.indexOf('?'));
Expand Down
3 changes: 2 additions & 1 deletion src/util/exportToNDJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <resource type>?<query>
tyq.forEach(query => {
Expand All @@ -104,6 +104,7 @@ const exportToNDJson = async jobOptions => {
valueSetQueries[resourceType] = { [property]: [propertyValue] };
}
} else {
// TODO: this gets overwritten for subqueries with "&" operators
subqueries[property] = propertyValue;
}

Check warning on line 109 in src/util/exportToNDJson.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
});
Expand Down
9 changes: 9 additions & 0 deletions test/util/exportToNDJson.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit 32ad477

Please sign in to comment.