-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollisionCheck_InfoRetrieval.cs
215 lines (171 loc) · 8.27 KB
/
CollisionCheck_InfoRetrieval.cs
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VMS.TPS.Common.Model.API;
using VMS.TPS.Common.Model.Types;
using System.Diagnostics;
/*
Collision Check Info Retrieval
This program targets .NET Framework 4.6.1
This program is a stand-alone command line program, however it is NOT designed to be used on its own and is EXPRESSELY ONLY for use by my collision check program to do SQL queries for it.
Back when I had access to the Aria DB this worked, but not anymore
The connection string to connect to the DB goes in the App.config file. I deleted the string that was there because it contains usenames and passwords, as well as in the connection string in the code here
Copyright (C) 2021 Zackary Thomas Ricci Morelli
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
I can be contacted at: zackmorelli@gmail.com
*/
namespace CollisionCheck_InfoRetrieval
{
static class CollisionCheck_InfoRetrieval
{
[STAThread]
static void Main(string[] args)
{
double GantryStartAngle = -1.0;
double? GantryEndAngle = -1.0;
string ArcDirection = null; // either CW, CC, or NONE (meaning no Arc!)
Console.Title = "Querying ARIA database (takes about 10 seconds)";
try
{
string argnet = null;
foreach (string rg in args)
{
argnet = argnet + rg;
}
// The arguments were separated by commas when they were passed to the process that started this program in Collision Check. we know what each one is becaue we know the order we passed them in Collision Check.
string[] arglist = argnet.Split(',');
string patientId = arglist[0]; // LINQ can't handle array indexes with entities (i.e. EF database entities)
string courseId = arglist[1];
string planId = arglist[2];
string beamId = arglist[3];
// MessageBox.Show("PatientId: " + patientId);
// MessageBox.Show("courseId: " + courseId);
// MessageBox.Show("planId: " + planId);
// MessageBox.Show("beamId: " + beamId);
long patser = -1;
long cser = -1;
long plser = -1;
long rser = -1;
string ConnectionString = @"Data Source=WVVRNDBP01SS;Initial Catalog=variansystem;Integrated Security=False;User Id=;Password=";
//data source=WVVRNDBP01SS;initial catalog=variansystem;integrated security=False;User Id=;Password=
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand command;
SqlDataReader datareader;
string sql;
conn.Open();
sql = "USE variansystem SELECT PatientSer FROM dbo.Patient WHERE PatientId = '" + patientId + "'";
command = new SqlCommand(sql, conn);
datareader = command.ExecuteReader();
while(datareader.Read())
{
patser = (long)datareader["PatientSer"];
}
conn.Close();
if(patser == -1)
{
MessageBox.Show("Error: Could not find this patient in the database!");
}
//MessageBox.Show("patser: " + patser);
conn.Open();
sql = "USE variansystem SELECT CourseSer FROM dbo.Course WHERE PatientSer = " + patser;
command = new SqlCommand(sql, conn);
datareader = command.ExecuteReader();
while (datareader.Read())
{
cser = (long)datareader["CourseSer"];
}
conn.Close();
if (cser == -1)
{
MessageBox.Show("Error: Could not find this treatment course in the database!");
}
//MessageBox.Show("Course Ser: " + cser);
conn.Open();
sql = "USE variansystem SELECT PlanSetupSer FROM dbo.PlanSetup WHERE CourseSer = " + cser;
command = new SqlCommand(sql, conn);
datareader = command.ExecuteReader();
while (datareader.Read())
{
plser = (long)datareader["PlanSetupSer"];
}
conn.Close();
if (plser == -1)
{
MessageBox.Show("Error: Could not find this plan in the database!");
}
conn.Open();
sql = "USE variansystem SELECT RadiationSer FROM dbo.Radiation WHERE PlanSetupSer = " + plser;
command = new SqlCommand(sql, conn);
datareader = command.ExecuteReader();
while (datareader.Read())
{
rser = (long)datareader["RadiationSer"];
}
conn.Close();
if (rser == -1)
{
MessageBox.Show("Error: Could not find beam " + beamId + " in the database!");
}
conn.Open();
sql = "USE variansystem SELECT GantryRtn, GantryRtnDirection, StopAngle FROM dbo.ExternalField WHERE RadiationSer = " + rser;
command = new SqlCommand(sql, conn);
datareader = command.ExecuteReader();
//MessageBox.Show("Trig");
while (datareader.Read())
{
GantryStartAngle = Convert.ToDouble(datareader["GantryRtn"]);
object EA = (object)datareader["StopAngle"];
if(EA is DBNull)
{
GantryEndAngle = -1.0;
}
else
{
GantryEndAngle = Convert.ToDouble(EA);
}
ArcDirection = (string)datareader["GantryRtnDirection"];
}
conn.Close();
if (GantryStartAngle == -1.0)
{
MessageBox.Show("Error: Could not find the gantry rotation information for beam " + beamId + " in the database!");
}
if(GantryEndAngle == null)
{
GantryEndAngle = -1.0;
}
// MessageBox.Show("Arc Direction: " + ArcDirection);
// MessageBox.Show("Gantry Start Angle: " + GantryStartAngle);
// MessageBox.Show("Gantry End Angle: " + GantryEndAngle);
// The standard output of the console has been redirected to the main collision check program that this calls, so the lines below are the output of this program.
// The collision check program starts this program as a separate process on the computer and then saves the output of the process as a streamreader that it passes on to the rest of the collisioncheck program
Console.WriteLine(ArcDirection);
Console.WriteLine(GantryStartAngle);
Console.WriteLine(GantryEndAngle);
}
catch (Exception e)
{
MessageBox.Show("Database querying Error - \n\n" + e.ToString() + "\n\n" + " Stack Trace: \n\n " + e.StackTrace);
}
}
}
}