@@ -18,16 +18,37 @@ module ElectronMobius =
18
18
let baseUrl = " http://mobiusfx/quick/electron"
19
19
20
20
// Shortcuts wrapped in try-catch to handle potential exceptions
21
- let pt = tryMe context.Patient " No Patient"
22
- let plan = tryMe context.ExternalPlanSetup " No Plan"
23
- let beam = tryMe ( context.ExternalPlanSetup.Beams |> Seq.head) " No Beam"
24
- let dose = tryMe context.ExternalPlanSetup.Dose " No Dose"
21
+ let pt =
22
+ tryMe
23
+ context.Patient
24
+ " No Patient"
25
+
26
+ let plan =
27
+ tryMe
28
+ context.ExternalPlanSetup
29
+ " No Plan"
30
+
31
+ let beam =
32
+ let firstBeam =
33
+ context.ExternalPlanSetup.Beams
34
+ |> Seq.head
35
+
36
+ tryMe
37
+ firstBeam
38
+ " No Beam"
39
+
40
+ let dose =
41
+ tryMe
42
+ context.ExternalPlanSetup.Dose
43
+ " No Dose"
25
44
26
45
if not ( plan.IsEntireBodyAndBolusesCoveredByCalculationArea()) then
27
- warnAndQuit " Calculation Area does not cover entire Body and Boluses"
46
+ warnAndQuit
47
+ " Calculation Area does not cover entire Body and Boluses"
28
48
29
49
let trySelectEnergy
30
- ( beam : Beam ) : Result < string , string > =
50
+ ( beam : Beam )
51
+ : Result < string , string > =
31
52
32
53
match beam.EnergyModeDisplayName with
33
54
| " 6E" -> Ok " 6"
@@ -37,7 +58,8 @@ module ElectronMobius =
37
58
| _ -> Error " Beam Energy did not match 6E / 9E / 12E or 16E"
38
59
39
60
let trySelectApplicator
40
- ( beam : Beam ) : Result < string , string > =
61
+ ( beam : Beam )
62
+ : Result < string , string > =
41
63
42
64
match beam.Applicator.Id with
43
65
| " A06" -> Ok " 6x6"
@@ -48,73 +70,70 @@ module ElectronMobius =
48
70
| _ -> Error " Applicator is outside of expected values"
49
71
50
72
// Single Computation Expression to either full working data or the first Error msg
51
- let urlCE = result {
52
-
53
- let patientName = pt.Name //cannot be null
54
-
55
- let patientId = pt.Id //cannot be null
56
-
57
- let machineName = beam.TreatmentUnit.Id //"Accelerator08" //cannot be null
73
+ let urlCE =
74
+ result {
75
+ let patientName = pt.Name //cannot be null
76
+ let patientId = pt.Id //cannot be null
58
77
59
- let! beamEnergy = trySelectEnergy beam
60
-
61
- let! applicator = trySelectApplicator beam
62
-
63
- let! width , length = guessApertureDiameters dose
64
-
65
- let cutoutWidth = ( width * 0.1 |> roundTo1). ToString()
66
- let cutoutLength = ( length * 0.1 |> roundTo1). ToString()
67
-
68
- let! ssd =
69
- match ( beam.Boluses |> Seq.toList) with // head?
70
- | [ b] ->
71
- let ssdToBolusInCm = ( beam.GetSourceToBolusDistance( b) * 0.1 |> roundTo1). ToString()
72
- Ok ( ssdToBolusInCm)
73
- | [] ->
74
- warn " No Bolus found on the beam. Really? \n Calculation will continue without bolus"
75
- let ssdInCm = ( beam.SSD * 0.1 |> roundTo1). ToString()
76
- Ok ( ssdInCm)
77
- | _ ->
78
- Error " We cannot calculate if there are more than one bolus on the beam"
78
+ let machineName = beam.TreatmentUnit.Id //"Accelerator08" //cannot be null
79
+ let! beamEnergy = trySelectEnergy beam
80
+ let! applicator = trySelectApplicator beam
79
81
80
- let depthPct =
81
-
82
- let dmaxInPercent =
83
- if plan.Dose.DoseMax3D.IsRelativeDoseValue then
84
- plan.Dose.DoseMax3D.Dose
85
- else
86
- ( plan.Dose.DoseMax3D.Dose / plan.TotalDose.Dose) * 100.0
87
-
88
- (( 200.0 - dmaxInPercent) |> roundTo1 ). ToString()
89
-
90
- let beamDose =
91
- ( plan.PlannedDosePerFraction.Dose * 100.0 ). ToString() // in cGy
92
-
93
- let beamName = beam.Id
94
-
95
- let tpsMu = //cannot be null. dose is calculated
96
- ( beam.Meterset.Value |> roundTo1). ToString()
97
-
98
- // Generate the URL
99
- let url =
100
- generateUrl
101
- baseUrl
102
- patientName
103
- patientId
104
- machineName
105
- beamEnergy
106
- applicator
107
- cutoutWidth
108
- cutoutLength
109
- ssd
110
- depthPct
111
- beamDose
112
- beamName
113
- tpsMu
114
-
115
- return url
116
-
117
- }
82
+ let! width , length = guessApertureDiameters dose
83
+
84
+ let cutoutWidth = ( width * 0.1 |> roundTo1). ToString()
85
+ let cutoutLength = ( length * 0.1 |> roundTo1). ToString()
86
+
87
+ let! ssd =
88
+ match ( beam.Boluses |> Seq.toList) with // head?
89
+ | [ b] ->
90
+ let ssdToBolusInCm = ( beam.GetSourceToBolusDistance( b) * 0.1 |> roundTo1). ToString()
91
+ Ok ( ssdToBolusInCm)
92
+ | [] ->
93
+ warn " No Bolus found on the beam. Really? \n Calculation will continue without bolus"
94
+ let ssdInCm = ( beam.SSD * 0.1 |> roundTo1). ToString()
95
+ Ok ( ssdInCm)
96
+ | _ ->
97
+ Error " We cannot calculate if there are more than one bolus on the beam"
98
+
99
+ let depthPct =
100
+
101
+ let dmaxInPercent =
102
+ if plan.Dose.DoseMax3D.IsRelativeDoseValue then
103
+ plan.Dose.DoseMax3D.Dose
104
+ else
105
+ ( plan.Dose.DoseMax3D.Dose / plan.TotalDose.Dose) * 100.0
106
+
107
+ (( 200.0 - dmaxInPercent) |> roundTo1 ). ToString()
108
+
109
+ let beamDose =
110
+ ( plan.PlannedDosePerFraction.Dose * 100.0 ). ToString() // in cGy
111
+
112
+ let beamName = beam.Id
113
+
114
+ let tpsMu = //cannot be null. dose is calculated
115
+ ( beam.Meterset.Value |> roundTo1). ToString()
116
+
117
+ // Generate the URL
118
+ let url =
119
+ generateUrl
120
+ baseUrl
121
+ patientName
122
+ patientId
123
+ machineName
124
+ beamEnergy
125
+ applicator
126
+ cutoutWidth
127
+ cutoutLength
128
+ ssd
129
+ depthPct
130
+ beamDose
131
+ beamName
132
+ tpsMu
133
+
134
+ return url
135
+
136
+ }
118
137
119
138
match urlCE with
120
139
| Ok url -> openUrlInBrowser url
0 commit comments