@@ -43,9 +43,10 @@ class PatientQueryCreator {
43
43
* @param {import('mongodb').Document } query
44
44
* @param {string } resourceType
45
45
* @param {boolean } useHistoryTable
46
+ * @param {boolean } excludeRestricted Exclude restricted resources (default to true)
46
47
* @return {import('mongodb').Document }
47
48
*/
48
- getQueryWithPatientFilter ( { patientIds, query, resourceType, useHistoryTable, personIds} ) {
49
+ getQueryWithPatientFilter ( { patientIds, query, resourceType, useHistoryTable, personIds, excludeRestricted = true } ) {
49
50
if ( ! this . patientFilterManager . canAccessResourceWithPatientScope ( { resourceType} ) ) {
50
51
throw new ForbiddenError ( `Resource type ${ resourceType } cannot be accessed via a patient scope` ) ;
51
52
}
@@ -124,8 +125,7 @@ class PatientQueryCreator {
124
125
resourceType,
125
126
parsedArgs,
126
127
useHistoryTable,
127
- operation : OPERATIONS . READ ,
128
- isUser : true
128
+ operation : OPERATIONS . READ
129
129
} ) ) ;
130
130
}
131
131
if ( patientsUuidQuery ) {
@@ -201,8 +201,7 @@ class PatientQueryCreator {
201
201
resourceType,
202
202
parsedArgs,
203
203
useHistoryTable,
204
- operation : OPERATIONS . READ ,
205
- isUser : true
204
+ operation : OPERATIONS . READ
206
205
} ) ) ;
207
206
}
208
207
if ( patientsNonUuidQuery ) {
@@ -278,8 +277,7 @@ class PatientQueryCreator {
278
277
resourceType,
279
278
parsedArgs,
280
279
useHistoryTable,
281
- operation : OPERATIONS . READ ,
282
- isUser : true
280
+ operation : OPERATIONS . READ
283
281
} ) ) ;
284
282
}
285
283
if ( personsQuery ) {
@@ -300,17 +298,19 @@ class PatientQueryCreator {
300
298
}
301
299
302
300
// 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
+ }
310
310
}
311
311
}
312
- }
313
- } ) ;
312
+ } ) ;
313
+ }
314
314
return query ;
315
315
}
316
316
}
0 commit comments