-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVisualScripting_Complete.txt
More file actions
136 lines (127 loc) · 4.78 KB
/
VisualScripting_Complete.txt
File metadata and controls
136 lines (127 loc) · 4.78 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
public IEnumerable<Metric> Execute(PlanSetup ps)
{
// TODO: Add your code here.
ValidatePlanSetup(ps);
ValidatePlanDose(ps);
ValidateStructureSet(ps);
//2. is the rx valid?
ValidatePrescription(ps);
//3. relevant structures present and not empty.
Structure body = ps.StructureSet.Structures.SingleOrDefault(x => x.Id.Equals("BODY", StringComparison.OrdinalIgnoreCase));
Structure ptv = ps.StructureSet.Structures.SingleOrDefault(x => x.Id.Equals("PTV", StringComparison.OrdinalIgnoreCase));
Structure ring = ps.StructureSet.Structures.SingleOrDefault(x => x.Id.Equals("2CMRINGFROMPTV", StringComparison.OrdinalIgnoreCase));
Structure lungs = ps.StructureSet.Structures.SingleOrDefault(x => x.Id.Equals("LUNGS-GTV", StringComparison.OrdinalIgnoreCase));
List<Structure> structures = new List<Structure> { body, ptv, ring, lungs };
ValidateStructure(structures);
//4. calculate metrics
Metric cI = new Metric("Conformity Index");
Metric gI = new Metric("Gradient Index");
Metric v20 = new Metric("V20");
if (ptv.Volume < 20)
{
cI.Tolerance = 1.25;
cI.MinorDeviation = 1.40;
gI.Tolerance = 12;
gI.MinorDeviation = 14;
v20.Tolerance = 5;
v20.Tolerance = 8;
}
else if (ptv.Volume <= 40)
{
cI.Tolerance = 1.15;
cI.MinorDeviation = 1.25;
gI.Tolerance = 9;
gI.MinorDeviation = 11;
v20.Tolerance = 6;
v20.Tolerance = 10;
}
else
{
//update these.
cI.Tolerance = 1.25;
cI.MinorDeviation = 1.40;
gI.Tolerance = 12;
gI.MinorDeviation = 14;
v20.Tolerance = 5;
v20.Tolerance = 8;
}
//calculate values.
DoseValue pX = ps.TotalDose;
double v100 = ps.GetVolumeAtDose(body, pX, VolumePresentation.AbsoluteCm3);
cI.Value = v100 / ptv.Volume;
DoseValue halfPx = new DoseValue(pX.Dose / 2, pX.Unit);
double v50 = ps.GetVolumeAtDose(body,halfPx, VolumePresentation.AbsoluteCm3);
gI.Value = v50 / ptv.Volume;
DoseValue twentyGy = new DoseValue(2000, DoseValue.DoseUnit.cGy);
v20.Value = ps.GetVolumeAtDose(lungs, twentyGy, VolumePresentation.AbsoluteCm3);
List<Metric> metrics = new List<Metric>()
{
cI,
gI,
v20
};
foreach(var metric in metrics)
{
metric.Evaluate();
}
return metrics;
}
private void ValidateStructure(List<Structure> structures)
{
//TODO
}
private void ValidatePrescription(PlanSetup ps)
{
DoseValue fiftyFourGy = new DoseValue(5400, DoseValue.DoseUnit.cGy);
DoseValue sixtyGy = new DoseValue(6000, DoseValue.DoseUnit.cGy);
DoseValue fiftyFiveGy = new DoseValue(5500, DoseValue.DoseUnit.cGy);
DoseValue fiftyGy = new DoseValue(5000, DoseValue.DoseUnit.cGy);
DoseValue pX = ps.TotalDose;
int? n = ps.NumberOfFractions;
if(n == null)
{
throw new ApplicationException("No fractions found");
}
bool valid = false;
if(pX == fiftyFourGy && n.Value == 3)
{
valid = true;
}
else if (pX == sixtyGy && n.Value == 5)
{
valid = true;
}
else if (pX == fiftyFiveGy && n.Value == 5)
{
valid = true;
}
else if (pX == fiftyGy && n.Value == 8)
{
valid = true;
}
if (!valid)
{
throw new ApplicationException("Invalid dose and fractionation");
}
}
private void ValidateStructureSet(PlanSetup ps)
{
if(ps.StructureSet == null)
{
throw new ApplicationException("Structure set is null");
}
}
private void ValidatePlanDose(PlanSetup ps)
{
if (!ps.IsDoseValid)
{
throw new ApplicationException("Dose is not valid");
}
}
private void ValidatePlanSetup(PlanSetup ps)
{
if(ps == null)
{
throw new ApplicationException("Plan is not valid");
}
}