Skip to content

Commit 79b1a2a

Browse files
authored
Add notifications onto CR Event (#736)
* Add notifications onto CR Event Signed-off-by: Joe Batt <[email protected]> * Add notifications onto CR Event Signed-off-by: Joe Batt <[email protected]> * Add notifications onto CR Event Signed-off-by: Joe Batt <[email protected]> * Add notifications onto CR Event Signed-off-by: Joe Batt <[email protected]> --------- Signed-off-by: Joe Batt <[email protected]>
1 parent a9b9ae9 commit 79b1a2a

File tree

8 files changed

+202
-39
lines changed

8 files changed

+202
-39
lines changed

src/TaskManager/Plug-ins/AideClinicalReview/AideClinicalReviewPlugin.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class AideClinicalReviewPlugin : TaskPluginBase
4646
private string _patientHospitalId;
4747
private string _queueName;
4848
private string _workflowName;
49+
private bool _notifications;
4950
private string _reviewedTaskId;
5051
private string _applicationName;
5152
private string _mode;
@@ -87,6 +88,11 @@ private void Initialize()
8788
_workflowName = Event.TaskPluginArguments[Keys.WorkflowName];
8889
}
8990

91+
if (Event.TaskPluginArguments.ContainsKey(Keys.Notifications))
92+
{
93+
_notifications = Boolean.TryParse(Event.TaskPluginArguments[Keys.Notifications], out bool result);
94+
}
95+
9096
if (Event.TaskPluginArguments.ContainsKey(Keys.ReviewedExecutionId))
9197
{
9298
_reviewedExecutionId = Event.TaskPluginArguments[Keys.ReviewedExecutionId];
@@ -213,6 +219,7 @@ private JsonMessage<ClinicalReviewRequestEvent> GenerateClinicalReviewRequestEve
213219
ReviewedTaskId = _reviewedTaskId,
214220
ReviewedExecutionId = _reviewedExecutionId,
215221
WorkflowName = _workflowName,
222+
Notifications = _notifications,
216223
Files = Event.Inputs,
217224
ReviewerRoles = _reviewerRoles,
218225
PatientMetadata = new PatientMetadata

src/TaskManager/Plug-ins/AideClinicalReview/Events/ClinicalReviewRequestEvent.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ public class ClinicalReviewRequestEvent : EventBase
7171
[Required]
7272
public string WorkflowName { get; set; }
7373

74+
/// <summary>
75+
/// Gets or sets the name of the workflow.
76+
/// </summary>
77+
[JsonProperty(PropertyName = "notifications")]
78+
[Required]
79+
public bool Notifications { get; set; }
80+
7481
/// <summary>
7582
/// Gets or sets patient metadata.
7683
/// </summary>

src/TaskManager/Plug-ins/AideClinicalReview/Keys.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public class Keys
5454
/// </summary>
5555
public static readonly string ReviewerRoles = "reviewer_roles";
5656

57+
/// <summary>
58+
/// Key for the workflow name.
59+
/// </summary>
60+
public static readonly string Notifications = "notifications";
61+
5762
/// <summary>
5863
/// Key for the queue name to send the clinical review message.
5964
/// </summary>

tests/IntegrationTests/TaskManager.IntegrationTests/Features/ClinicalReview.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,13 @@ Scenario: Clincial review task dispatch event triggers clincial review event wit
8282
Given I have a bucket in MinIO bucket1
8383
When A Task Dispatch event is published Task_Dispatch_Clinical_Review_Reviewed_Execution_Id
8484
Then A Clincial Review Request event is published
85+
86+
@ClinicalReviewPlugin
87+
Scenario Outline: Clincial review task dispatch event triggers clincial review event with notifications
88+
Given I have a bucket in MinIO bucket1
89+
When A Task Dispatch event is published <testData>
90+
Then A Clincial Review Request event is published
91+
Examples:
92+
| testData |
93+
| Task_Dispatch_Clinical_Review_Notifications_True |
94+
| Task_Dispatch_Clinical_Review_Notifications_False |
Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
/*
2-
* Copyright 2022 MONAI Consortium
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
1+
/*
2+
* Copyright 2022 MONAI Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
16-
16+
1717
using Monai.Deploy.WorkflowManager.TaskManager.IntegrationTests.Support;
1818

19-
namespace Monai.Deploy.WorkflowManager.TaskManager.IntegrationTests.StepDefinitions
20-
{
19+
namespace Monai.Deploy.WorkflowManager.TaskManager.IntegrationTests.StepDefinitions
20+
{
2121
[Binding]
22-
public class ClinicalReviewStepDefinitions
23-
{
24-
public ClinicalReviewStepDefinitions(ObjectContainer objectContainer, ISpecFlowOutputHelper outputHelper)
25-
{
26-
_outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper));
27-
DataHelper = objectContainer.Resolve<DataHelper>() ?? throw new ArgumentNullException(nameof(DataHelper));
28-
Assertions = new Assertions(_outputHelper);
29-
}
30-
31-
private readonly ISpecFlowOutputHelper _outputHelper;
32-
public DataHelper DataHelper { get; }
33-
public Assertions Assertions { get; }
34-
22+
public class ClinicalReviewStepDefinitions
23+
{
24+
public ClinicalReviewStepDefinitions(ObjectContainer objectContainer, ISpecFlowOutputHelper outputHelper)
25+
{
26+
_outputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper));
27+
DataHelper = objectContainer.Resolve<DataHelper>() ?? throw new ArgumentNullException(nameof(DataHelper));
28+
Assertions = new Assertions(_outputHelper);
29+
}
30+
31+
private readonly ISpecFlowOutputHelper _outputHelper;
32+
public DataHelper DataHelper { get; }
33+
public Assertions Assertions { get; }
34+
3535
[Then(@"A Clincial Review Request event is published")]
36-
public void ThenAClincialReviewRequestIsPublished()
37-
{
38-
var clinicalReviewRequestEvent = DataHelper.GetClinicalReviewRequestEvent();
39-
40-
Assertions.AssertClinicalReviewEvent(clinicalReviewRequestEvent, DataHelper.TaskDispatchEvent);
41-
}
42-
}
43-
}
36+
public void ThenAClincialReviewRequestIsPublished()
37+
{
38+
var clinicalReviewRequestEvent = DataHelper.GetClinicalReviewRequestEvent();
39+
40+
Assertions.AssertClinicalReviewEvent(clinicalReviewRequestEvent, DataHelper.TaskDispatchEvent);
41+
}
42+
}
43+
}

tests/IntegrationTests/TaskManager.IntegrationTests/Support/Assertions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ public void AssertClinicalReviewEvent(ClinicalReviewRequestEvent clinicalReviewR
4040
clinicalReviewRequestEvent.PatientMetadata.PatientName.Should().Be(GetTaskPluginArguments(taskDispatchEvent, "patient_name"));
4141
clinicalReviewRequestEvent.PatientMetadata.PatientSex.Should().Be(GetTaskPluginArguments(taskDispatchEvent, "patient_sex"));
4242
clinicalReviewRequestEvent.PatientMetadata.PatientDob.Should().Be(GetTaskPluginArguments(taskDispatchEvent, "patient_dob"));
43+
try
44+
{
45+
var notifications = GetTaskPluginArguments(taskDispatchEvent, "notifications");
46+
47+
}
48+
catch (Exception ex)
49+
{
50+
clinicalReviewRequestEvent.Notifications.Should().Be(true);
51+
}
52+
4353
clinicalReviewRequestEvent.WorkflowName.Should().Be(GetTaskPluginArguments(taskDispatchEvent, "workflow_name"));
4454

4555
foreach (var file in clinicalReviewRequestEvent.Files)

tests/IntegrationTests/TaskManager.IntegrationTests/TestData/TaskDispatchTestData.cs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,114 @@ public static class TaskDispatchesTestData
11361136
}
11371137
}
11381138
},
1139+
new TaskDispatchTestData
1140+
{
1141+
Name = "Task_Dispatch_Clinical_Review_Notifications_True",
1142+
TaskDispatchEvent = new TaskDispatchEvent()
1143+
{
1144+
PayloadId = Guid.NewGuid().ToString(),
1145+
CorrelationId = Guid.NewGuid().ToString(),
1146+
ExecutionId = Guid.NewGuid().ToString(),
1147+
WorkflowInstanceId = Guid.NewGuid().ToString(),
1148+
TaskId = Guid.NewGuid().ToString(),
1149+
Status = TaskExecutionStatus.Dispatched,
1150+
TaskPluginType = "aide_clinical_review",
1151+
Inputs = new List<Messaging.Common.Storage>()
1152+
{
1153+
new Messaging.Common.Storage
1154+
{
1155+
Name = "input1",
1156+
Endpoint = "//test_1",
1157+
Credentials = new Messaging.Common.Credentials()
1158+
{
1159+
AccessKey = "test1",
1160+
AccessToken = "test1",
1161+
},
1162+
Bucket = "bucket1",
1163+
RelativeRootPath = "//dcm_1"
1164+
},
1165+
},
1166+
IntermediateStorage = new Messaging.Common.Storage
1167+
{
1168+
Name = "input",
1169+
Endpoint = "//test",
1170+
Credentials = new Messaging.Common.Credentials()
1171+
{
1172+
AccessKey = "test",
1173+
AccessToken = "test",
1174+
},
1175+
Bucket = "bucket1",
1176+
RelativeRootPath = "//dcm"
1177+
},
1178+
TaskPluginArguments = new Dictionary<string, string>()
1179+
{
1180+
{ "workflow_name", "Workflow_1" },
1181+
{ "reviewed_task_id", "some_task" },
1182+
{ "reviewed_execution_id", "some_execution" },
1183+
{ "patient_id", "100001" },
1184+
{ "queue_name", "aide.clinical_review.request" },
1185+
{ "reviewer_roles", "" },
1186+
{ "application_name", "app name" },
1187+
{ "application_version", "v1" },
1188+
{ "mode", "QA" },
1189+
{ "notifications", "true" },
1190+
}
1191+
}
1192+
},
1193+
new TaskDispatchTestData
1194+
{
1195+
Name = "Task_Dispatch_Clinical_Review_Notifications_False",
1196+
TaskDispatchEvent = new TaskDispatchEvent()
1197+
{
1198+
PayloadId = Guid.NewGuid().ToString(),
1199+
CorrelationId = Guid.NewGuid().ToString(),
1200+
ExecutionId = Guid.NewGuid().ToString(),
1201+
WorkflowInstanceId = Guid.NewGuid().ToString(),
1202+
TaskId = Guid.NewGuid().ToString(),
1203+
Status = TaskExecutionStatus.Dispatched,
1204+
TaskPluginType = "aide_clinical_review",
1205+
Inputs = new List<Messaging.Common.Storage>()
1206+
{
1207+
new Messaging.Common.Storage
1208+
{
1209+
Name = "input1",
1210+
Endpoint = "//test_1",
1211+
Credentials = new Messaging.Common.Credentials()
1212+
{
1213+
AccessKey = "test1",
1214+
AccessToken = "test1",
1215+
},
1216+
Bucket = "bucket1",
1217+
RelativeRootPath = "//dcm_1"
1218+
},
1219+
},
1220+
IntermediateStorage = new Messaging.Common.Storage
1221+
{
1222+
Name = "input",
1223+
Endpoint = "//test",
1224+
Credentials = new Messaging.Common.Credentials()
1225+
{
1226+
AccessKey = "test",
1227+
AccessToken = "test",
1228+
},
1229+
Bucket = "bucket1",
1230+
RelativeRootPath = "//dcm"
1231+
},
1232+
TaskPluginArguments = new Dictionary<string, string>()
1233+
{
1234+
{ "workflow_name", "Workflow_1" },
1235+
{ "reviewed_task_id", "some_task" },
1236+
{ "reviewed_execution_id", "some_execution" },
1237+
{ "patient_id", "100001" },
1238+
{ "queue_name", "aide.clinical_review.request" },
1239+
{ "reviewer_roles", "" },
1240+
{ "application_name", "app name" },
1241+
{ "application_version", "v1" },
1242+
{ "mode", "QA" },
1243+
{ "notifications", "false" },
1244+
}
1245+
}
1246+
},
11391247
};
11401248
}
11411249
}

tests/UnitTests/TaskManager.AideClinicalReview.Tests/AideClinicalReviewPluginTests.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ public async Task AideClinicalReviewPlugin_ExecuteTask_ReturnsExecutionStatusOnS
105105
_messageBrokerPublisherService.Verify(p => p.Publish(It.Is<string>(m => m == _options.Value.Messaging.Topics.AideClinicalReviewRequest), It.IsAny<Message>()), Times.Once());
106106
}
107107

108+
[Fact(DisplayName = "ExecuteTask - returns ExecutionStatus on success - Notifications false")]
109+
public async Task AideClinicalReviewPlugin_ExecuteTask_ReturnsExecutionStatusOnSuccess_NotificatiosnFalse()
110+
{
111+
var message = GenerateTaskDispatchEventWithValidArguments(true, "false");
112+
113+
var runner = new AideClinicalReviewPlugin(_serviceScopeFactory.Object, _messageBrokerPublisherService.Object, _options, _logger.Object, message);
114+
var result = await runner.ExecuteTask(CancellationToken.None).ConfigureAwait(false);
115+
116+
Assert.Equal(TaskExecutionStatus.Accepted, result.Status);
117+
Assert.Equal(FailureReason.None, result.FailureReason);
118+
Assert.Equal("", result.Errors);
119+
120+
_messageBrokerPublisherService.Verify(p => p.Publish(It.Is<string>(m => m == _options.Value.Messaging.Topics.AideClinicalReviewRequest), It.IsAny<Message>()), Times.Once());
121+
}
122+
108123
[Fact(DisplayName = "ExecuteTask - returns ExecutionStatus on success - Missing ReviewerRoles")]
109124
public async Task AideClinicalReviewPlugin_ExecuteTask_ReturnsExecutionStatusOnSuccessMissingReviewerRoles()
110125
{
@@ -170,7 +185,7 @@ public async Task AideClinicalReviewPlugin_GetStatus_ReturnsExecutionStatusOnSuc
170185
Assert.Equal("", result.Errors);
171186
}
172187

173-
private static TaskDispatchEvent GenerateTaskDispatchEventWithValidArguments(bool acceptance = true)
188+
private static TaskDispatchEvent GenerateTaskDispatchEventWithValidArguments(bool acceptance = true, string notifications = "true")
174189
{
175190
var message = GenerateTaskDispatchEvent();
176191
message.TaskPluginArguments[Keys.WorkflowName] = "workflowName";
@@ -186,6 +201,7 @@ private static TaskDispatchEvent GenerateTaskDispatchEventWithValidArguments(boo
186201
message.TaskPluginArguments[Keys.ApplicationName] = "applicationname";
187202
message.TaskPluginArguments[Keys.Mode] = "mode";
188203
message.TaskPluginArguments[Keys.ReviewerRoles] = "admin,clinician";
204+
message.TaskPluginArguments[Keys.Notifications] = notifications;
189205
message.Metadata[Keys.MetadataAcceptance] = acceptance;
190206
message.Metadata[Keys.MetadataUserId] = "userid";
191207
message.Metadata[Keys.MetadataReason] = "reason";

0 commit comments

Comments
 (0)