Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OR Multiple _typeFilters #54

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}

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
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
Loading