Skip to content

Commit ce05d30

Browse files
IGNT-70 Add _includeHidden support for REST
1 parent 4c55276 commit ce05d30

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

src/operations/common/patientQueryCreator.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ class PatientQueryCreator {
4343
* @param {import('mongodb').Document} query
4444
* @param {string} resourceType
4545
* @param {boolean} useHistoryTable
46+
* @param {boolean} excludeRestricted Exclude restricted resources (default to true)
4647
* @return {import('mongodb').Document}
4748
*/
48-
getQueryWithPatientFilter({patientIds, query, resourceType, useHistoryTable, personIds}) {
49+
getQueryWithPatientFilter({patientIds, query, resourceType, useHistoryTable, personIds, excludeRestricted = true}) {
4950
if (!this.patientFilterManager.canAccessResourceWithPatientScope({resourceType})) {
5051
throw new ForbiddenError(`Resource type ${resourceType} cannot be accessed via a patient scope`);
5152
}
@@ -124,8 +125,7 @@ class PatientQueryCreator {
124125
resourceType,
125126
parsedArgs,
126127
useHistoryTable,
127-
operation: OPERATIONS.READ,
128-
isUser: true
128+
operation: OPERATIONS.READ
129129
}));
130130
}
131131
if (patientsUuidQuery) {
@@ -201,8 +201,7 @@ class PatientQueryCreator {
201201
resourceType,
202202
parsedArgs,
203203
useHistoryTable,
204-
operation: OPERATIONS.READ,
205-
isUser: true
204+
operation: OPERATIONS.READ
206205
}));
207206
}
208207
if (patientsNonUuidQuery) {
@@ -278,8 +277,7 @@ class PatientQueryCreator {
278277
resourceType,
279278
parsedArgs,
280279
useHistoryTable,
281-
operation: OPERATIONS.READ,
282-
isUser: true
280+
operation: OPERATIONS.READ
283281
}));
284282
}
285283
if (personsQuery) {
@@ -300,17 +298,19 @@ class PatientQueryCreator {
300298
}
301299

302300
// apply filter to exclude resources with restricted security
303-
query.$and = query.$and || [];
304-
query.$and.push({
305-
'meta.security': {
306-
$not: {
307-
$elemMatch: {
308-
system: RESOURCE_RESTRICTION_TAG.SYSTEM,
309-
code: RESOURCE_RESTRICTION_TAG.CODE
301+
if (excludeRestricted) {
302+
query.$and = query.$and || [];
303+
query.$and.push({
304+
'meta.security': {
305+
$not: {
306+
$elemMatch: {
307+
system: RESOURCE_RESTRICTION_TAG.SYSTEM,
308+
code: RESOURCE_RESTRICTION_TAG.CODE
309+
}
310310
}
311311
}
312-
}
313-
});
312+
});
313+
}
314314
return query;
315315
}
316316
}

src/operations/query/r4.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ class R4SearchQueryCreator {
6262
* @param {ParsedArgs} parsedArgs
6363
* @param {boolean|undefined} [useHistoryTable]
6464
* @param {string} operation
65-
* @param {boolean} isUser
6665
* @returns {{query:import('mongodb').Document, columns: Set}} A query object to use with Mongo
6766
*/
68-
buildR4SearchQuery ({ resourceType, parsedArgs, useHistoryTable, operation, isUser }) {
67+
buildR4SearchQuery ({ resourceType, parsedArgs, useHistoryTable, operation }) {
6968
assertIsValid(resourceType);
7069
assertTypeEquals(parsedArgs, ParsedArgs);
7170

@@ -156,7 +155,7 @@ class R4SearchQueryCreator {
156155
// Handling case of 'hidden' tag in meta
157156
if (
158157
!parsedArgs.id &&
159-
(isUser || !isTrue(parsedArgs._includeHidden)) &&
158+
(!isTrue(parsedArgs._includeHidden)) &&
160159
operation !== DELETE &&
161160
!useHistoryTable &&
162161
resourceType !== 'AuditEvent'

src/operations/search/searchManager.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ class SearchManager {
237237

238238
if (accessViaPatientScopes) {
239239
shouldUpdateColumns = true;
240+
const excludeRestricted = !parsedArgs.id &&
241+
(!isTrue(parsedArgs._includeHidden)) &&
242+
operation !== DELETE &&
243+
!useHistoryTable &&
244+
resourceType !== 'AuditEvent';
245+
240246
/**
241247
* @type {string[]}
242248
*/
@@ -250,7 +256,8 @@ class SearchManager {
250256
} else {
251257
query = this.patientQueryCreator.getQueryWithPatientFilter({
252258
patientIds: allPatientIdsFromJwtToken, query, resourceType, useHistoryTable,
253-
personIds: personIdFromJwtToken ? [personIdFromJwtToken] : null
259+
personIds: personIdFromJwtToken ? [personIdFromJwtToken] : null,
260+
excludeRestricted
254261
});
255262
}
256263
} else if (securityTags && securityTags.length > 0) {

0 commit comments

Comments
 (0)