-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanCompare.cs
More file actions
330 lines (300 loc) · 14.6 KB
/
planCompare.cs
File metadata and controls
330 lines (300 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
using System;
using System.Linq;
using System.Text;
using System.Windows;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using VMS.TPS.Common.Model.API;
using VMS.TPS.Common.Model.Types;
using System.Windows.Controls;
using System.Windows.Media;
[assembly: AssemblyVersion("1.0.0.1")]
namespace VMS.TPS
{
public class Script
{
public Script()
{
}
private void AddCheckTitle(string titleText, Panel panel)
{
var label = new Label();
label.Content = titleText;
label.HorizontalAlignment = HorizontalAlignment.Left;
label.FontSize = 13;
label.FontWeight = FontWeights.Bold;
label.Foreground = Brushes.Blue;
panel.Children.Add(label);
}
private void AddColumn(string columnText, Grid grid, int columnIndex, FontWeight fontWeightStyle, Brush brushFG, Brush brushBG)
{
grid.ColumnDefinitions.Add(new ColumnDefinition());
var label = new Label();
label.Content = columnText;
label.HorizontalAlignment = HorizontalAlignment.Center;
label.SetValue(Grid.RowProperty, 0);
label.SetValue(Grid.ColumnProperty, columnIndex);
label.FontWeight = fontWeightStyle;
label.Foreground = brushFG;
label.Background = brushBG;
grid.Children.Add(label);
}
private void AddRow(string rowText, Grid grid, bool addRowStatus, int columnIndex, int rowIndex, FontWeight fontWeightStyle, Brush brushFG, Brush brushBG)
{
if (addRowStatus == true)
grid.RowDefinitions.Add(new RowDefinition());
var label = new Label();
label.Content = rowText;
label.HorizontalAlignment = HorizontalAlignment.Center;
label.SetValue(Grid.RowProperty, rowIndex);
label.SetValue(Grid.ColumnProperty, columnIndex);
label.FontWeight = fontWeightStyle;
label.Foreground = brushFG;
label.Background = brushBG;
grid.Children.Add(label);
}
[MethodImpl(MethodImplOptions.NoInlining)]
public void Execute(ScriptContext context /*, System.Windows.Window window, ScriptEnvironment environment*/)
{
// TODO : Add here the code that is called when the script is launched from Eclipse.
if (context.PlanSetup == null)
{
MessageBox.Show("Warning: no plan is loaded.");
return;
}
if (context.PlanSetup.ProtocolID.Count() == 0)
{
MessageBox.Show("Warning: no clinical protocol is attached the plan.");
return;
}
int prescriptionRowCount = 0;
int prescriptionColCount = 0;
int qualityIndicesRowCount = 0;
int qualityIndicesColCount = 0;
//define pop-up window.
var window = new Window();
var scrollView = new ScrollViewer();
var listView = new ListView();
scrollView.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
scrollView.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
var panel = new StackPanel();
panel.Orientation = Orientation.Vertical;
panel.Background = Brushes.White;
//define labels of patient & protocol Information
AddCheckTitle("Patient Information ", panel);
var labelPat = new Label();
labelPat.Content = "";
labelPat.HorizontalAlignment = HorizontalAlignment.Left;
labelPat.FontSize = 15;
labelPat.FontWeight = FontWeights.Bold;
labelPat.Foreground = Brushes.Black;
panel.Children.Add(labelPat);
var labelProtocol = new Label();
labelProtocol.Content = "";
labelProtocol.HorizontalAlignment = HorizontalAlignment.Left;
labelProtocol.FontSize = 15;
labelProtocol.FontWeight = FontWeights.Bold;
labelProtocol.Foreground = Brushes.Black;
panel.Children.Add(labelProtocol);
//define labels of clinical protocol.
AddCheckTitle("Prescriptions ", panel);
var gridPrescription = new Grid();
AddColumn(" Structure ", gridPrescription, 0, FontWeights.Normal, Brushes.Black, Brushes.White);
gridPrescription.RowDefinitions.Add(new RowDefinition());
gridPrescription.ShowGridLines = true;
panel.Children.Add(gridPrescription);
prescriptionRowCount++;
prescriptionColCount++;
AddCheckTitle("Quality Indices ", panel);
var gridQualityIndices = new Grid();
AddColumn(" Structure ", gridQualityIndices, 0, FontWeights.Normal, Brushes.Black, Brushes.White);
gridQualityIndices.RowDefinitions.Add(new RowDefinition());
gridQualityIndices.ShowGridLines = true;
panel.Children.Add(gridQualityIndices);
qualityIndicesRowCount++;
qualityIndicesColCount++;
//define close button.
var OKbutton = new Button();
OKbutton.Content = "Close";
//OKbutton.FontSize = 14;
OKbutton.IsCancel = true;
OKbutton.IsDefault = true;
OKbutton.HorizontalAlignment = HorizontalAlignment.Right;
OKbutton.Margin = new Thickness(0, 10, 30, 10);
OKbutton.Width = 80;
OKbutton.Height = 25;
panel.Children.Add(OKbutton);
scrollView.Content = panel;
window.Content = scrollView;
window.Title = "PlanCompare(Clinical Protocol)";
window.SizeToContent = SizeToContent.WidthAndHeight;
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
//////////////////////////////////////////////////////////////////
Patient patient = context.Patient;
Course course = context.Course;
string modifier = "";
//set label patient ID & name,protocol ID.
labelPat.Content = string.Format("Patiet ID: {0} / Name: {1},{2} {3}", patient.Id, patient.LastName, patient.FirstName, patient.MiddleName);
labelProtocol.Content = string.Format("Protocol ID: {0}", context.PlanSetup.ProtocolID.Replace("_", "__"));
//set column title of priscrition grid.
prescriptionColCount++;
AddColumn(" Prescription ", gridPrescription, 1, FontWeights.Normal, Brushes.Black, Brushes.White);
prescriptionColCount++;
AddColumn(" FractionDose ", gridPrescription, 2, FontWeights.Normal, Brushes.Black, Brushes.White);
prescriptionColCount++;
AddColumn(" TotalDose ", gridPrescription, 3, FontWeights.Normal, Brushes.Black, Brushes.White);
//set column title of quality indices grid.
qualityIndicesColCount++;
AddColumn(" Index ", gridQualityIndices, 1, FontWeights.Normal, Brushes.Black, Brushes.White);
qualityIndicesColCount++;
AddColumn(" TargetValue ", gridQualityIndices, 2, FontWeights.Normal, Brushes.Black, Brushes.White);
//get clinical protocol information.
var prescriptions = new List<ProtocolPhasePrescription>();
var measures = new List<ProtocolPhaseMeasure>();
context.PlanSetup.GetProtocolPrescriptionsAndMeasures(ref prescriptions, ref measures);
//set prescriptions on each row.
foreach (ProtocolPhasePrescription prescription in prescriptions)
{
AddRow(prescription.StructureId,
gridPrescription, true, 0, prescriptionRowCount, FontWeights.Normal, Brushes.Black, Brushes.White);
// replace with eclipse UI notation.
if (prescription.PrescModifier.ToString() == "PrescriptionModifierAtLeast")
{
modifier = " At least " + prescription.PrescParameter.ToString() + " % recievs more than ";
}
else if (prescription.PrescModifier.ToString() == "PrescriptionModifierAtMost")
{
modifier = " At most " + prescription.PrescParameter.ToString() + " % recievs more than ";
}
else if (prescription.PrescModifier.ToString() == "PrescriptionModifierMinDose")
{
modifier = " Minimum dose is ";
}
else if (prescription.PrescModifier.ToString() == "PrescriptionModifierMaxDose")
{
modifier = " Maximum dose is ";
}
else if (prescription.PrescModifier.ToString() == "PrescriptionModifierMeanDose")
{
modifier = " Mean dose is ";
}
else
{
modifier = prescription.PrescModifier.ToString();
}
AddRow(modifier,
gridPrescription, false, 1, prescriptionRowCount, FontWeights.Normal, Brushes.Black, Brushes.White);
AddRow(prescription.TargetFractionDose.ToString(),
gridPrescription, false, 2, prescriptionRowCount, FontWeights.Normal, Brushes.Black, Brushes.White);
AddRow(prescription.TargetTotalDose.ToString(),
gridPrescription, false, 3, prescriptionRowCount, FontWeights.Normal, Brushes.Black, Brushes.White);
prescriptionRowCount++;
}
//set quality indices on each row.
foreach (ProtocolPhaseMeasure measure in measures)
{
AddRow(measure.StructureId,
gridQualityIndices, true, 0, qualityIndicesRowCount, FontWeights.Normal, Brushes.Black, Brushes.White);
// replace with eclipse UI notation.
if (measure.Modifier.ToString() == "MeasureModifierAtMost")
{
modifier = " is less than ";
}
else if (measure.Modifier.ToString() == "MeasureModifierAtLeast")
{
modifier = " is more than ";
}
else if (measure.Modifier.ToString() == "MeasureModifierTarget")
{
modifier = " is ";
}
else
{
modifier = measure.Modifier.ToString();
}
AddRow(measure.TypeText.ToString() + modifier,
gridQualityIndices, false, 1, qualityIndicesRowCount, FontWeights.Normal, Brushes.Black, Brushes.White);
AddRow(measure.TargetValue.ToString(),
gridQualityIndices, false, 2, qualityIndicesRowCount, FontWeights.Normal, Brushes.Black, Brushes.White);
qualityIndicesRowCount++;
}
//set actual values each plan.
foreach (PlanSetup plan in course.PlanSetups)
{
//exclude plan without clinical protocol.
if (plan.ProtocolID.Count() > 0)
{
AddColumn(plan.Id, gridPrescription, prescriptionColCount, FontWeights.Normal, Brushes.Black, Brushes.White);
AddColumn(plan.Id, gridQualityIndices, qualityIndicesColCount, FontWeights.Normal, Brushes.Black, Brushes.White);
//get clinical protocol information of each plan.
var prescriptions2 = new List<ProtocolPhasePrescription>();
var measures2 = new List<ProtocolPhaseMeasure>();
plan.GetProtocolPrescriptionsAndMeasures(ref prescriptions2, ref measures2);
prescriptionRowCount = 1;
//set prescription on each row.
foreach (ProtocolPhasePrescription prescription in prescriptions2)
{
//set color in case
if (prescription.TargetIsMet == true)
{
AddRow(prescription.ActualTotalDose.ToString(),
gridPrescription,
false,
prescriptionColCount,
prescriptionRowCount,
FontWeights.Bold,
Brushes.Black,
Brushes.LightGreen);
}
else
{
AddRow(prescription.ActualTotalDose.ToString(),
gridPrescription,
false,
prescriptionColCount,
prescriptionRowCount,
FontWeights.Bold,
Brushes.Black,
Brushes.HotPink);
}
prescriptionRowCount++;
}
qualityIndicesRowCount = 1;
//set quality indices on each row.
foreach (ProtocolPhaseMeasure measure in measures2)
{
//set color in case
if (measure.TargetIsMet == true)
{
AddRow(string.Format(" {0:f2}", Math.Round(measure.ActualValue, 2)),
gridQualityIndices,
false,
qualityIndicesColCount,
qualityIndicesRowCount,
FontWeights.Bold,
Brushes.Black,
Brushes.LightGreen);
}
else
{
AddRow(string.Format(" {0:f2}", Math.Round(measure.ActualValue, 2)),
gridQualityIndices,
false,
qualityIndicesColCount,
qualityIndicesRowCount,
FontWeights.Bold,
Brushes.Black,
Brushes.HotPink);
}
qualityIndicesRowCount++;
}
prescriptionColCount++;
qualityIndicesColCount++;
}
}
//show window
window.ShowDialog();
}
}
}