Skip to content

Commit 370bc14

Browse files
authored
Merge pull request #765 from Project-MONAI/AC-1567
AC-1567 Updated workflow request event trigger process
2 parents 3f13648 + 893df6a commit 370bc14

File tree

7 files changed

+218
-27
lines changed

7 files changed

+218
-27
lines changed

src/WorkflowManager/Database/Interfaces/IWorkflowRepository.cs

+18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System;
1818
using System.Collections.Generic;
1919
using System.Threading.Tasks;
20+
using Monai.Deploy.Messaging.Events;
2021
using Monai.Deploy.WorkflowManager.Contracts.Models;
2122

2223
namespace Monai.Deploy.WorkflowManager.Database.Interfaces
@@ -67,6 +68,23 @@ public interface IWorkflowRepository
6768
/// <param name="aeTitle">An aeTitle to retrieve workflows for.</param>
6869
Task<IList<WorkflowRevision>> GetWorkflowsByAeTitleAsync(List<string> aeTitles);
6970

71+
/// <summary>
72+
/// Retrieves a list of workflows based..<br/>
73+
/// if clinical workflow has AET no data origin. => WorkflowRequestEvents received with CalledAET with that AET this workflow (regardless of what the CallingAET is)<br/>
74+
/// if clinical workflow has AET and data_orgins => only WorkflowRequestEvents with CalledAET with that AET and CallingAET trigger this workflow.<br/>
75+
/// </summary>
76+
/// <example>
77+
/// If clinical workflow (workflow revision) exists with AET “MONAI” but no data_origins set
78+
/// Any inbound WorkflowRequestEvents with CalledAET = “MONAI” trigger this workflow (regardless of what the CallingAET is)
79+
///
80+
/// If clinical workflow (workflow revision) exists with AET “MONAI” and data_origins set as “PACS”
81+
/// Only inbound WorkflowRequestEvents with CalledAET = “MONAI” and CallingAET = “PACS” trigger this workflow
82+
/// </example>
83+
/// <param name="calledAeTitle"></param>
84+
/// <param name="sallingAeTitle"></param>
85+
/// <returns></returns>
86+
Task<IList<WorkflowRevision>> GetWorkflowsForWorkflowRequestAsync(string calledAeTitle, string callingAeTitle);
87+
7088
/// <summary>
7189
/// Creates a workflow object.
7290
/// </summary>

src/WorkflowManager/Database/Repositories/WorkflowRepository.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,29 @@ public async Task<IList<WorkflowRevision>> GetWorkflowsByAeTitleAsync(List<strin
199199
return workflows;
200200
}
201201

202+
public async Task<IList<WorkflowRevision>> GetWorkflowsForWorkflowRequestAsync(string calledAeTitle, string callingAeTitle)
203+
{
204+
Guard.Against.NullOrEmpty(calledAeTitle);
205+
Guard.Against.NullOrEmpty(callingAeTitle);
206+
207+
var wfs = await _workflowCollection
208+
.Find(x =>
209+
x.Workflow != null &&
210+
x.Workflow.InformaticsGateway != null &&
211+
((x.Workflow.InformaticsGateway.AeTitle == calledAeTitle &&
212+
(x.Workflow.InformaticsGateway.DataOrigins == null ||
213+
x.Workflow.InformaticsGateway.DataOrigins.Length == 0)) ||
214+
x.Workflow.InformaticsGateway.AeTitle == calledAeTitle &&
215+
x.Workflow.InformaticsGateway.DataOrigins != null &&
216+
x.Workflow.InformaticsGateway.DataOrigins.Any(d => d == callingAeTitle)) &&
217+
x.Deleted == null)
218+
.ToListAsync();
219+
return wfs;
220+
}
221+
202222
public async Task<string> CreateAsync(Workflow workflow)
203223
{
204-
Guard.Against.Null(workflow, nameof(workflow));
224+
Guard.Against.Null(workflow);
205225

206226
var workflowRevision = new WorkflowRevision
207227
{

src/WorkflowManager/WorkflowExecuter/Services/WorkflowExecuterService.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,8 @@ public async Task<bool> ProcessPayload(WorkflowRequestEvent message, Payload pay
117117
}
118118
else
119119
{
120-
var aeTitles = new List<string>
121-
{
122-
message.CalledAeTitle,
123-
message.CallingAeTitle
124-
};
125-
126-
workflows = await _workflowRepository.GetWorkflowsByAeTitleAsync(aeTitles) as List<WorkflowRevision>;
120+
var result = await _workflowRepository.GetWorkflowsForWorkflowRequestAsync(message.CalledAeTitle, message.CallingAeTitle);
121+
workflows = new List<WorkflowRevision>(result);
127122
}
128123

129124
if (workflows is null || workflows.Any() is false)

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/Features/WorkflowRequest.feature

+23
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ Scenario Outline: Publish a valid workflow request which creates multiple workfl
4242
| Basic_Workflow_1 | Basic_Workflow_2 | Basic_Multi_Id_WF_Request |
4343
| Basic_Workflow_1 | Basic_Workflow_3 | Basic_AeTitle_WF_Request |
4444

45+
@WorkflowRequest
46+
Scenario Outline: Publish a workflow request which triggers a worflow based on called_aet and calling_aet
47+
Given I have a clinical workflow <workflow>
48+
When I publish a Workflow Request Message <workflowRequestMessage> with no artifacts
49+
Then I can see 1 Workflow Instance is created
50+
And 1 Task Dispatch event is published
51+
Examples:
52+
| workflow | workflowRequestMessage |
53+
| Workflow_Called_AET | Called_AET_AIDE_Calling_AET_TEST |
54+
| Workflow_Called_AET_Calling_AET | Called_AET_AIDE_Calling_AET_PACS1 |
55+
| Workflow_Called_AET_Multi_Calling_AET | Called_AET_AIDE_Calling_AET_PACS1 |
56+
| Workflow_Called_AET_Multi_Calling_AET | Called_AET_AIDE_Calling_AET_PACS2 |
57+
58+
@WorkflowRequest
59+
Scenario Outline: Publish a workflow request which doesnt trigger a worflow based calling_aet
60+
Given I have a clinical workflow <workflow>
61+
When I publish a Workflow Request Message <workflowRequestMessage> with no artifacts
62+
Then I can see no Workflow Instances are created
63+
Examples:
64+
| workflow | workflowRequestMessage |
65+
| Workflow_Called_AET_Calling_AET | Called_AET_AIDE_Calling_AET_TEST |
66+
| Workflow_Called_AET_Multi_Calling_AET | Called_AET_AIDE_Calling_AET_TEST |
67+
4568
@WorkflowRequest
4669
Scenario: Publish a valid workflow request with mismatched AE title and workflow ID
4770
Given I have a clinical workflow Basic_Workflow_1

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/TestData/WorkflowRequestTestData.cs

+51-9
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public static class WorkflowRequestsTestData
3939
Workflows = new List<string>() { },
4040
CorrelationId = Guid.NewGuid().ToString(),
4141
Timestamp = DateTime.UtcNow,
42-
CalledAeTitle = "Basic_AE",
43-
CallingAeTitle = "Basic_AE_3",
42+
CalledAeTitle = "MONAI",
43+
CallingAeTitle = "PACS",
4444
}
4545
},
4646
new WorkflowRequestTestData
@@ -95,7 +95,7 @@ public static class WorkflowRequestsTestData
9595
Workflows = new List<string>() { },
9696
CorrelationId = Guid.NewGuid().ToString(),
9797
Timestamp = DateTime.UtcNow,
98-
CalledAeTitle = "Multi_Revision",
98+
CalledAeTitle = "MONAI_2",
9999
CallingAeTitle = "MWM",
100100
}
101101
},
@@ -258,8 +258,8 @@ public static class WorkflowRequestsTestData
258258
Workflows = new List<string>() { },
259259
CorrelationId = Guid.NewGuid().ToString(),
260260
Timestamp = DateTime.UtcNow,
261-
CalledAeTitle = "MWM",
262-
CallingAeTitle = "Basic_AE",
261+
CalledAeTitle = "MONAI",
262+
CallingAeTitle = "PACS",
263263
}
264264
},
265265
new WorkflowRequestTestData
@@ -272,8 +272,8 @@ public static class WorkflowRequestsTestData
272272
Workflows = new List<string>() { },
273273
CorrelationId = Guid.NewGuid().ToString(),
274274
Timestamp = DateTime.UtcNow,
275-
CalledAeTitle = "Basic_AE",
276-
CallingAeTitle = "MWM",
275+
CalledAeTitle = "MONAI",
276+
CallingAeTitle = "PACS",
277277
}
278278
},
279279
new WorkflowRequestTestData
@@ -286,8 +286,8 @@ public static class WorkflowRequestsTestData
286286
Workflows = new List<string>() { },
287287
CorrelationId = Guid.NewGuid().ToString(),
288288
Timestamp = DateTime.UtcNow,
289-
CalledAeTitle = "Basic_AE",
290-
CallingAeTitle = "MWM",
289+
CalledAeTitle = "MONAI",
290+
CallingAeTitle = "PACS",
291291
}
292292
},
293293
new WorkflowRequestTestData
@@ -346,6 +346,48 @@ public static class WorkflowRequestsTestData
346346
CallingAeTitle = "Non_Existent_Calling_AE",
347347
}
348348
},
349+
new WorkflowRequestTestData
350+
{
351+
Name = "Called_AET_AIDE_Calling_AET_TEST",
352+
WorkflowRequestMessage = new WorkflowRequestMessage
353+
{
354+
Bucket = "bucket1",
355+
PayloadId = Guid.NewGuid(),
356+
Workflows = new List<string>() { },
357+
CorrelationId = Guid.NewGuid().ToString(),
358+
Timestamp = DateTime.UtcNow,
359+
CalledAeTitle = "AIDE",
360+
CallingAeTitle = "TEST",
361+
}
362+
},
363+
new WorkflowRequestTestData
364+
{
365+
Name = "Called_AET_AIDE_Calling_AET_PACS1",
366+
WorkflowRequestMessage = new WorkflowRequestMessage
367+
{
368+
Bucket = "bucket1",
369+
PayloadId = Guid.NewGuid(),
370+
Workflows = new List<string>() { },
371+
CorrelationId = Guid.NewGuid().ToString(),
372+
Timestamp = DateTime.UtcNow,
373+
CalledAeTitle = "AIDE",
374+
CallingAeTitle = "PACS1",
375+
}
376+
},
377+
new WorkflowRequestTestData
378+
{
379+
Name = "Called_AET_AIDE_Calling_AET_PACS2",
380+
WorkflowRequestMessage = new WorkflowRequestMessage
381+
{
382+
Bucket = "bucket1",
383+
PayloadId = Guid.NewGuid(),
384+
Workflows = new List<string>() { },
385+
CorrelationId = Guid.NewGuid().ToString(),
386+
Timestamp = DateTime.UtcNow,
387+
CalledAeTitle = "AIDE",
388+
CallingAeTitle = "PACS2",
389+
}
390+
},
349391
};
350392
}
351393
}

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/TestData/WorkflowRevisionTestData.cs

+102-10
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static class WorkflowRevisionsTestData
5454
},
5555
InformaticsGateway = new InformaticsGateway()
5656
{
57-
AeTitle = "Basic_AE"
57+
AeTitle = "MONAI"
5858
}
5959
}
6060
}
@@ -84,7 +84,7 @@ public static class WorkflowRevisionsTestData
8484
},
8585
InformaticsGateway = new InformaticsGateway()
8686
{
87-
AeTitle = "Basic_AE"
87+
AeTitle = "MONAI"
8888
}
8989
}
9090
}
@@ -114,7 +114,7 @@ public static class WorkflowRevisionsTestData
114114
},
115115
InformaticsGateway = new InformaticsGateway()
116116
{
117-
AeTitle = "Basic_AE_3"
117+
AeTitle = "MONAI"
118118
}
119119
}
120120
}
@@ -181,7 +181,7 @@ public static class WorkflowRevisionsTestData
181181
},
182182
new WorkflowRevisionTestData()
183183
{
184-
Name = "Basic_Workflow_Multiple_Revisions_1",
184+
Name = "Basic_Workflow_Multiple_Revisions_1", //not to be confused with 'Basic_Workflow_multiple_revisions_1' (lower case)
185185
WorkflowRevision = new WorkflowRevision()
186186
{
187187
Id = Guid.NewGuid().ToString(),
@@ -204,7 +204,7 @@ public static class WorkflowRevisionsTestData
204204
},
205205
InformaticsGateway = new InformaticsGateway()
206206
{
207-
AeTitle = "Multi_Revision"
207+
AeTitle = "MONAI"
208208
}
209209
}
210210
}
@@ -234,7 +234,7 @@ public static class WorkflowRevisionsTestData
234234
},
235235
InformaticsGateway = new InformaticsGateway()
236236
{
237-
AeTitle = "Multi_Revision"
237+
AeTitle = "MONAI_2"
238238
}
239239
}
240240
}
@@ -331,7 +331,7 @@ public static class WorkflowRevisionsTestData
331331
},
332332
InformaticsGateway = new InformaticsGateway()
333333
{
334-
AeTitle = "Multi_Created"
334+
AeTitle = "Multi_Req"
335335
}
336336
}
337337
}
@@ -675,7 +675,7 @@ public static class WorkflowRevisionsTestData
675675
},
676676
new WorkflowRevisionTestData()
677677
{
678-
Name = "Basic_Workflow_multiple_revisions_1",
678+
Name = "Basic_Workflow_multiple_revisions_1", //not to be confused with 'Basic_Workflow_Multiple_Revisions_1' (upper case)
679679
WorkflowRevision = new WorkflowRevision()
680680
{
681681
Id = Guid.NewGuid().ToString(),
@@ -698,7 +698,7 @@ public static class WorkflowRevisionsTestData
698698
},
699699
InformaticsGateway = new InformaticsGateway()
700700
{
701-
AeTitle = "Basic_AE"
701+
AeTitle = "MONAI_2"
702702
}
703703
}
704704
}
@@ -728,7 +728,7 @@ public static class WorkflowRevisionsTestData
728728
},
729729
InformaticsGateway = new InformaticsGateway()
730730
{
731-
AeTitle = "Basic_AE"
731+
AeTitle = "MONAI_2"
732732
}
733733
}
734734
}
@@ -3036,6 +3036,98 @@ public static class WorkflowRevisionsTestData
30363036
}
30373037
}
30383038
},
3039+
new WorkflowRevisionTestData()
3040+
{
3041+
Name = "Workflow_Called_AET",
3042+
WorkflowRevision = new WorkflowRevision()
3043+
{
3044+
Id = Guid.NewGuid().ToString(),
3045+
WorkflowId = Guid.NewGuid().ToString(),
3046+
Revision = 1,
3047+
Workflow = new Workflow()
3048+
{
3049+
Name = "Basic workflow 1",
3050+
Description = "Basic workflow 1",
3051+
Version = "1",
3052+
Tasks = new TaskObject[]
3053+
{
3054+
new TaskObject
3055+
{
3056+
Id = Guid.NewGuid().ToString(),
3057+
Type = "Basic_task",
3058+
Description = "Basic Workflow 1 Task 1",
3059+
Artifacts = new ArtifactMap(),
3060+
}
3061+
},
3062+
InformaticsGateway = new InformaticsGateway()
3063+
{
3064+
AeTitle = "AIDE"
3065+
}
3066+
}
3067+
}
3068+
},
3069+
new WorkflowRevisionTestData()
3070+
{
3071+
Name = "Workflow_Called_AET_Calling_AET",
3072+
WorkflowRevision = new WorkflowRevision()
3073+
{
3074+
Id = Guid.NewGuid().ToString(),
3075+
WorkflowId = Guid.NewGuid().ToString(),
3076+
Revision = 1,
3077+
Workflow = new Workflow()
3078+
{
3079+
Name = "Basic workflow 1",
3080+
Description = "Basic workflow 1",
3081+
Version = "1",
3082+
Tasks = new TaskObject[]
3083+
{
3084+
new TaskObject
3085+
{
3086+
Id = Guid.NewGuid().ToString(),
3087+
Type = "Basic_task",
3088+
Description = "Basic Workflow 1 Task 1",
3089+
Artifacts = new ArtifactMap(),
3090+
}
3091+
},
3092+
InformaticsGateway = new InformaticsGateway()
3093+
{
3094+
AeTitle = "AIDE",
3095+
DataOrigins = new string[] { "PACS1" }
3096+
}
3097+
}
3098+
}
3099+
},
3100+
new WorkflowRevisionTestData()
3101+
{
3102+
Name = "Workflow_Called_AET_Multi_Calling_AET",
3103+
WorkflowRevision = new WorkflowRevision()
3104+
{
3105+
Id = Guid.NewGuid().ToString(),
3106+
WorkflowId = Guid.NewGuid().ToString(),
3107+
Revision = 1,
3108+
Workflow = new Workflow()
3109+
{
3110+
Name = "Basic workflow 1",
3111+
Description = "Basic workflow 1",
3112+
Version = "1",
3113+
Tasks = new TaskObject[]
3114+
{
3115+
new TaskObject
3116+
{
3117+
Id = Guid.NewGuid().ToString(),
3118+
Type = "Basic_task",
3119+
Description = "Basic Workflow 1 Task 1",
3120+
Artifacts = new ArtifactMap(),
3121+
}
3122+
},
3123+
InformaticsGateway = new InformaticsGateway()
3124+
{
3125+
AeTitle = "AIDE",
3126+
DataOrigins = new string[] { "PACS1", "PACS2" }
3127+
}
3128+
}
3129+
}
3130+
},
30393131
};
30403132
}
30413133
}

0 commit comments

Comments
 (0)