@@ -217,8 +217,8 @@ def get_consent_definitions(
217
217
)
218
218
cdefs = self .filter_cdefs_by_site_or_raise (site , cdefs , error_messages )
219
219
220
- cdefs , error_msg = self ._filter_cdefs_by_model_or_raise (
221
- screening_model , cdefs , error_messages , attrname = "screening_model"
220
+ cdefs , error_msg = self ._filter_cdefs_by_screening_model_or_raise (
221
+ screening_model , cdefs , error_messages
222
222
)
223
223
224
224
# apply additional criteria
@@ -246,6 +246,33 @@ def _filter_cdefs_by_model_or_raise(
246
246
errror_messages .append (f"model={ model } " )
247
247
return cdefs , errror_messages
248
248
249
+ @staticmethod
250
+ def _filter_cdefs_by_screening_model_or_raise (
251
+ model : str | None ,
252
+ consent_definitions : list [ConsentDefinition ],
253
+ errror_messages : list [str ] = None ,
254
+ ) -> tuple [list [ConsentDefinition ], list [str ]]:
255
+ cdefs = consent_definitions
256
+ if model :
257
+ cdefs = []
258
+ for cdef in consent_definitions :
259
+ if isinstance (cdef .screening_model , list ):
260
+ for screening_model in cdef .screening_model :
261
+ if model == screening_model :
262
+ if cdef not in cdefs :
263
+ cdefs .append (cdef )
264
+ else :
265
+ if model == cdef .screening_model :
266
+ cdefs .append (cdef )
267
+ if not cdefs :
268
+ raise ConsentDefinitionDoesNotExist (
269
+ "There are no consent definitions using this screening model."
270
+ f"Got { model } ."
271
+ )
272
+ else :
273
+ errror_messages .append (f"model={ model } " )
274
+ return cdefs , errror_messages
275
+
249
276
def _filter_cdefs_by_report_datetime_or_raise (
250
277
self ,
251
278
report_datetime : datetime | None ,
0 commit comments