@@ -215,17 +215,23 @@ private bool Validate(out string details)
215215 errors . Add ( "'transactionId' is required." ) ;
216216 }
217217
218- if ( InputResources . IsNullOrEmpty ( ) ||
219- ! InputResources . Any ( predicate => predicate . Interface != InputInterfaceType . Algorithm ) )
220- {
221- errors . Add ( "No 'inputResources' specified." ) ;
222- }
223-
224218 if ( Application is null )
225219 {
226220 errors . Add ( "No algorithm defined or more than one algorithms defined in 'inputResources'. 'inputResources' must include one algorithm/pipeline for the inference request." ) ;
227221 }
228222
223+ ValidateInputResources ( errors ) ;
224+ ValidateInputMetadata ( errors ) ;
225+ ValidateOUtputResources ( errors ) ;
226+
227+ details = string . Join ( " " , errors ) ;
228+ return errors . Count == 0 ;
229+ }
230+
231+ private void ValidateOUtputResources ( List < string > errors )
232+ {
233+ Guard . Against . Null ( errors , nameof ( errors ) ) ;
234+
229235 if ( InputMetadata . Inputs . IsNullOrEmpty ( ) )
230236 {
231237 errors . Add ( "Request has no `inputMetadata` defined. At least one `inputs` or `inputMetadata` required." ) ;
@@ -237,18 +243,11 @@ private bool Validate(out string details)
237243 CheckInputMetadataDetails ( inputDetails , errors ) ;
238244 }
239245 }
246+ }
240247
241- foreach ( var input in InputResources )
242- {
243- if ( input . Interface == InputInterfaceType . DicomWeb )
244- {
245- CheckDicomWebConnectionDetails ( "inputResources" , errors , input . ConnectionDetails ) ;
246- }
247- else if ( input . Interface == InputInterfaceType . Fhir )
248- {
249- CheckFhirConnectionDetails ( "inputResources" , errors , input . ConnectionDetails ) ;
250- }
251- }
248+ private void ValidateInputMetadata ( List < string > errors )
249+ {
250+ Guard . Against . Null ( errors , nameof ( errors ) ) ;
252251
253252 foreach ( var output in OutputResources )
254253 {
@@ -261,51 +260,37 @@ private bool Validate(out string details)
261260 CheckFhirConnectionDetails ( "outputResources" , errors , output . ConnectionDetails ) ;
262261 }
263262 }
263+ }
264264
265- details = string . Join ( " " , errors ) ;
266- return errors . Count == 0 ;
265+ private void ValidateInputResources ( List < string > errors )
266+ {
267+ Guard . Against . Null ( errors , nameof ( errors ) ) ;
268+
269+ if ( InputResources . IsNullOrEmpty ( ) ||
270+ ! InputResources . Any ( predicate => predicate . Interface != InputInterfaceType . Algorithm ) )
271+ {
272+ errors . Add ( "No 'inputResources' specified." ) ;
273+ }
274+
275+ foreach ( var input in InputResources )
276+ {
277+ if ( input . Interface == InputInterfaceType . DicomWeb )
278+ {
279+ CheckDicomWebConnectionDetails ( "inputResources" , errors , input . ConnectionDetails ) ;
280+ }
281+ else if ( input . Interface == InputInterfaceType . Fhir )
282+ {
283+ CheckFhirConnectionDetails ( "inputResources" , errors , input . ConnectionDetails ) ;
284+ }
285+ }
267286 }
268287
269288 private void CheckInputMetadataDetails ( InferenceRequestDetails details , List < string > errors )
270289 {
271290 switch ( details . Type )
272291 {
273292 case InferenceRequestType . DicomUid :
274- if ( details . Studies . IsNullOrEmpty ( ) )
275- {
276- errors . Add ( "Request type is set to `DICOM_UID` but no `studies` defined." ) ;
277- }
278- else
279- {
280- foreach ( var study in details . Studies )
281- {
282- if ( string . IsNullOrWhiteSpace ( study . StudyInstanceUid ) )
283- {
284- errors . Add ( "`StudyInstanceUID` cannot be empty." ) ;
285- }
286-
287- if ( study . Series is null ) continue ;
288-
289- foreach ( var series in study . Series )
290- {
291- if ( string . IsNullOrWhiteSpace ( series . SeriesInstanceUid ) )
292- {
293- errors . Add ( "`SeriesInstanceUID` cannot be empty." ) ;
294- }
295-
296- if ( series . Instances is null ) continue ;
297-
298- foreach ( var instance in series . Instances )
299- {
300- if ( instance . SopInstanceUid . IsNullOrEmpty ( ) ||
301- instance . SopInstanceUid . Any ( p => string . IsNullOrWhiteSpace ( p ) ) )
302- {
303- errors . Add ( "`SOPInstanceUID` cannot be empty." ) ;
304- }
305- }
306- }
307- }
308- }
293+ CheckInputMetadataWithTypDeicomUid ( details , errors ) ;
309294 break ;
310295
311296 case InferenceRequestType . DicomPatientId :
@@ -323,25 +308,66 @@ private void CheckInputMetadataDetails(InferenceRequestDetails details, List<str
323308 break ;
324309
325310 case InferenceRequestType . FhireResource :
326- if ( details . Resources . IsNullOrEmpty ( ) )
311+ CheckInputMetadataWithTypeFhirResource ( details , errors ) ;
312+ break ;
313+
314+ default :
315+ errors . Add ( $ "'inputMetadata' does not yet support type '{ details . Type } '.") ;
316+ break ;
317+ }
318+ }
319+
320+ private static void CheckInputMetadataWithTypeFhirResource ( InferenceRequestDetails details , List < string > errors )
321+ {
322+ Guard . Against . Null ( details , nameof ( details ) ) ;
323+ Guard . Against . Null ( errors , nameof ( errors ) ) ;
324+
325+ if ( details . Resources . IsNullOrEmpty ( ) )
326+ {
327+ errors . Add ( "Request type is set to `FHIR_RESOURCE` but no FHIR `resources` defined." ) ;
328+ }
329+ else
330+ {
331+ errors . AddRange ( details . Resources . Where ( resource => string . IsNullOrWhiteSpace ( resource . Type ) ) . Select ( resource => "A FHIR resource type cannot be empty." ) ) ;
332+ }
333+ }
334+
335+ private static void CheckInputMetadataWithTypDeicomUid ( InferenceRequestDetails details , List < string > errors )
336+ {
337+ Guard . Against . Null ( details , nameof ( details ) ) ;
338+ Guard . Against . Null ( errors , nameof ( errors ) ) ;
339+
340+ if ( details . Studies . IsNullOrEmpty ( ) )
341+ {
342+ errors . Add ( "Request type is set to `DICOM_UID` but no `studies` defined." ) ;
343+ }
344+ else
345+ {
346+ foreach ( var study in details . Studies )
347+ {
348+ if ( string . IsNullOrWhiteSpace ( study . StudyInstanceUid ) )
327349 {
328- errors . Add ( "Request type is set to `FHIR_RESOURCE` but no FHIR `resources` defined ." ) ;
350+ errors . Add ( "`StudyInstanceUID` cannot be empty ." ) ;
329351 }
330- else
352+
353+ if ( study . Series is null ) continue ;
354+
355+ foreach ( var series in study . Series )
331356 {
332- foreach ( var resource in details . Resources )
357+ if ( string . IsNullOrWhiteSpace ( series . SeriesInstanceUid ) )
333358 {
334- if ( string . IsNullOrWhiteSpace ( resource . Type ) )
335- {
336- errors . Add ( "A FHIR resource type cannot be empty." ) ;
337- }
359+ errors . Add ( "`SeriesInstanceUID` cannot be empty." ) ;
338360 }
339- }
340- break ;
341361
342- default :
343- errors . Add ( $ "'inputMetadata' does not yet support type '{ details . Type } '.") ;
344- break ;
362+ if ( series . Instances is null ) continue ;
363+ errors . AddRange (
364+ series . Instances
365+ . Where (
366+ instance => instance . SopInstanceUid . IsNullOrEmpty ( ) ||
367+ instance . SopInstanceUid . Any ( p => string . IsNullOrWhiteSpace ( p ) ) )
368+ . Select ( instance => "`SOPInstanceUID` cannot be empty." ) ) ;
369+ }
370+ }
345371 }
346372 }
347373
0 commit comments