@@ -251,7 +251,7 @@ await _artifactsRepository
251251 return true ;
252252 }
253253
254- private async Task ProcessArtifactReceivedOutputs ( ArtifactsReceivedEvent message , WorkflowInstance workflowInstance , TaskObject task , string taskId )
254+ private async Task ProcessArtifactReceivedOutputs ( ArtifactsReceivedEvent message , WorkflowInstance workflowInstance , TaskObject taskTemplate , string taskId )
255255 {
256256 var artifactList = message . Artifacts . Select ( a => $ "{ a . Path } ") . ToList ( ) ;
257257 var artifactsInStorage = ( await _storageService . VerifyObjectsExistAsync ( workflowInstance . BucketId , artifactList , default ) ) ?? new Dictionary < string , bool > ( ) ;
@@ -263,22 +263,36 @@ private async Task ProcessArtifactReceivedOutputs(ArtifactsReceivedEvent message
263263
264264 var messageArtifactsInStorage = message . Artifacts . Where ( m => artifactsInStorage . First ( a => a . Value && a . Key == $ "{ m . Path } ") . Value ) . ToList ( ) ;
265265
266+ var addedNew = false ;
266267 var validArtifacts = new Dictionary < string , string > ( ) ;
267268 foreach ( var artifact in messageArtifactsInStorage )
268269 {
269- var match = task . Artifacts . Output . FirstOrDefault ( t => t . Type == artifact . Type ) ;
270+ var match = taskTemplate . Artifacts . Output . FirstOrDefault ( t => t . Type == artifact . Type ) ;
270271 if ( match is not null && validArtifacts . ContainsKey ( match ! . Name ) is false )
271272 {
272273 validArtifacts . Add ( match . Name , $ "{ artifact . Path } ") ;
274+
273275 }
274276 }
275277
276278 var currentTask = workflowInstance . Tasks ? . Find ( t => t . TaskId == taskId ) ;
277279
278- currentTask ! . OutputArtifacts = validArtifacts ; // adding the actual paths here, the parent function does the saving of the changes
279280
280- _logger . AddingFilesToWorkflowInstance ( workflowInstance . Id , taskId , JsonConvert . SerializeObject ( validArtifacts ) ) ;
281- await _workflowInstanceRepository . UpdateTaskOutputArtifactsAsync ( workflowInstance . Id , taskId , validArtifacts ) ;
281+ foreach ( var artifact in validArtifacts )
282+ {
283+ if ( currentTask ? . OutputArtifacts . ContainsKey ( artifact . Key ) is false )
284+ {
285+ // adding the actual paths here, the parent function does the saving of the changes
286+ currentTask ? . OutputArtifacts . Add ( artifact . Key , artifact . Value ) ;
287+ addedNew = true ;
288+ }
289+ }
290+
291+ if ( currentTask is not null && addedNew )
292+ {
293+ _logger . AddingFilesToWorkflowInstance ( workflowInstance . Id , taskId , JsonConvert . SerializeObject ( validArtifacts ) ) ;
294+ await _workflowInstanceRepository . UpdateTaskAsync ( workflowInstance . Id , taskId , currentTask ) ;
295+ }
282296 }
283297
284298 private async Task < bool > AllRequiredArtifactsReceivedAsync ( ArtifactsReceivedEvent message , WorkflowInstance workflowInstance ,
@@ -511,9 +525,13 @@ public async Task<bool> ProcessExportComplete(ExportCompleteEvent message, strin
511525 return false ;
512526 }
513527
514- if ( string . Compare ( task . TaskType , ValidationConstants . ExportTaskType , true ) == 0 )
528+ switch ( task . TaskType )
515529 {
516- return await HandleTaskDestinations ( workflowInstance , workflow , task , correlationId ) ;
530+ case TaskTypeConstants . DicomExportTask :
531+ case TaskTypeConstants . HL7ExportTask :
532+ return await HandleTaskDestinations ( workflowInstance , workflow , task , correlationId ) ;
533+ default :
534+ break ;
517535 }
518536 }
519537
@@ -612,7 +630,12 @@ private async Task<bool> ExternalAppRequest(ExternalAppRequestEvent externalAppR
612630 return true ;
613631 }
614632
615- private async Task HandleDicomExportAsync ( WorkflowRevision workflow , WorkflowInstance workflowInstance , TaskExecution task , string correlationId , List < string > ? plugins = null )
633+ private async Task HandleDicomExportAsync (
634+ WorkflowRevision workflow ,
635+ WorkflowInstance workflowInstance ,
636+ TaskExecution task ,
637+ string correlationId ,
638+ List < string > ? plugins = null )
616639 {
617640 plugins ??= new List < string > ( ) ;
618641 var ( exportList , artifactValues ) = await GetExportsAndArtifcts ( workflow , workflowInstance , task , correlationId ) ;
@@ -629,15 +652,20 @@ private async Task HandleDicomExportAsync(WorkflowRevision workflow, WorkflowIns
629652 await _workflowInstanceRepository . UpdateTaskStatusAsync ( workflowInstance . Id , task . TaskId , TaskExecutionStatus . Dispatched ) ;
630653 }
631654
632- private async Task < ( string [ ] ? exportList , string [ ] ? artifactValues ) > GetExportsAndArtifcts ( WorkflowRevision workflow , WorkflowInstance workflowInstance , TaskExecution task , string correlationId )
655+ private async Task < ( string [ ] ? exportList , string [ ] ? artifactValues ) > GetExportsAndArtifcts (
656+ WorkflowRevision workflow ,
657+ WorkflowInstance workflowInstance ,
658+ TaskExecution task ,
659+ string correlationId ,
660+ bool enforceDcmOnly = true )
633661 {
634662 var exportList = workflow . Workflow ? . Tasks ? . FirstOrDefault ( t => t . Id == task . TaskId ) ? . ExportDestinations . Select ( e => e . Name ) . ToArray ( ) ;
635663 if ( exportList is null || ! exportList . Any ( ) )
636664 {
637665 exportList = null ;
638666 }
639667
640- var artifactValues = await GetArtifactValues ( workflow , workflowInstance , task , exportList , correlationId ) ;
668+ var artifactValues = await GetArtifactValues ( workflow , workflowInstance , task , exportList , correlationId , enforceDcmOnly ) ;
641669
642670 if ( artifactValues . IsNullOrEmpty ( ) )
643671 {
@@ -646,7 +674,12 @@ private async Task HandleDicomExportAsync(WorkflowRevision workflow, WorkflowIns
646674 return ( exportList , artifactValues ) ;
647675 }
648676
649- private async Task < string [ ] > GetArtifactValues ( WorkflowRevision workflow , WorkflowInstance workflowInstance , TaskExecution task , string [ ] ? exportList , string correlationId )
677+ private async Task < string [ ] > GetArtifactValues (
678+ WorkflowRevision workflow , WorkflowInstance workflowInstance ,
679+ TaskExecution task ,
680+ string [ ] ? exportList ,
681+ string correlationId ,
682+ bool enforceDcmOnly = true )
650683 {
651684 var artifactValues = GetDicomExports ( workflow , task , exportList ) ;
652685
@@ -660,7 +693,7 @@ private async Task<string[]> GetArtifactValues(WorkflowRevision workflow, Workfl
660693 artifact ,
661694 true ) ;
662695
663- var dcmFiles = objects ? . Where ( o => o . IsValidDicomFile ( ) ) ? . ToList ( ) ;
696+ var dcmFiles = objects ? . Where ( o => o . IsValidDicomFile ( ) || enforceDcmOnly is false ) ? . ToList ( ) ;
664697
665698 if ( dcmFiles ? . IsNullOrEmpty ( ) is false )
666699 {
@@ -681,7 +714,7 @@ private async Task<string[]> GetArtifactValues(WorkflowRevision workflow, Workfl
681714
682715 private async Task HandleHl7ExportAsync ( WorkflowRevision workflow , WorkflowInstance workflowInstance , TaskExecution task , string correlationId )
683716 {
684- var ( exportList , artifactValues ) = await GetExportsAndArtifcts ( workflow , workflowInstance , task , correlationId ) ;
717+ var ( exportList , artifactValues ) = await GetExportsAndArtifcts ( workflow , workflowInstance , task , correlationId , false ) ;
685718
686719 if ( exportList is null || artifactValues is null )
687720 {
0 commit comments