Skip to content

Commit

Permalink
OR Multiple _typeFilters (#54)
Browse files Browse the repository at this point in the history
* OR Multiple _typeFilters

* Comment update
  • Loading branch information
elsaperelli authored Dec 16, 2024
1 parent 269d549 commit 535e176
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 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
: parameters._typeFilter.split(',');
const unsupportedTypeFilterTypes = [];
typeFilterArray.forEach(line => {
const resourceType = line.substring(0, line.indexOf('?'));
Expand Down
5 changes: 3 additions & 2 deletions src/util/exportToNDJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ const exportToNDJson = async jobOptions => {
const searchParameterQueries = {};
const valueSetQueries = {};
if (typeFilter) {
// subqueries may be joined together with a comma for a logical "or"
const tyq = typeFilter.split(',');
// 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 <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;
}
});
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 535e176

Please sign in to comment.