source: Scheduling/branches/Radiology-Support/cs/bsdx0200GUISourceCode/DAL.cs@ 1167

Last change on this file since 1167 was 1166, checked in by Sam Habiel, 14 years ago

Various Radiology-related Modifications:
DAL: ScheduleRadiologyExam and CancelRadiologyExam methods to DB
CGSchedLib: Organize usings
CGView:

File size: 13.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Data;
5using System.Text;
6using System.Diagnostics;
7using IndianHealthService.BMXNet;
8
9namespace IndianHealthService.ClinicalScheduling
10{
11 /// <summary>
12 /// Data Access Layer
13 /// </summary>
14 public class DAL
15 {
16 private BMXNetConnectInfo _thisConnection; // set in constructor
17
18 delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName); // for use in calling (Sync and Async)
19 delegate string TransmitRPCAsync(string RPCName, string Params); //same idea
20
21 /// <summary>
22 /// Constructor
23 /// </summary>
24 /// <param name="conn">The current connection to use</param>
25 public DAL(BMXNetConnectInfo conn)
26 {
27 this._thisConnection = conn;
28 }
29
30 /// <summary>
31 /// Get Current version from ^ nmsp + APPL(1,0)
32 /// </summary>
33 /// <param name="nmsp">Namespace to ask for. Only "BMX" and "BSDX" are supported.</param>
34 /// <returns>Datatable with the following fields:
35 /// "T00030ERROR^T00030MAJOR_VERSION^T00030MINOR_VERSION^T00030BUILD</returns>
36 public DataTable GetVersion(string nmsp)
37 {
38 string cmd = String.Format("BMX VERSION INFO^{0}", nmsp);
39 return RPMSDataTable(cmd, "");
40 }
41
42 /// <summary>
43 /// Get Scheduling User Info
44 /// </summary>
45 /// <param name="DUZ">You should know what this is</param>
46 /// <returns>Datatable with one column: "MANAGER": One Row that's "YES" or "NO"</returns>
47 public DataTable GetUserInfo(string DUZ)
48 {
49 string cmd = String.Format("BSDX SCHEDULING USER INFO^{0}", DUZ);
50 return RPMSDataTable(cmd, "");
51 }
52
53 /// <summary>
54 /// Get all Access Types from the BSDX ACCESS TYPE file
55 /// </summary>
56 /// <returns>DataTable with the following fields (add _ for spaces)
57 /// ACCESS TYPE NAME (RF), [0;1]
58 /// INACTIVE (S), [0;2]
59 /// DEPARTMENT NAME (P9002018.2'), [0;3]
60 /// DISPLAY COLOR (F), [0;4]
61 /// RED (NJ3,0), [0;5]
62 /// GREEN (NJ3,0), [0;6]
63 /// BLUE (NJ3,0), [0;7]
64 ///</returns>
65 public DataTable GetAccessTypes()
66 {
67 string sCommandText = "SELECT * FROM BSDX_ACCESS_TYPE";
68 DataTable table = RPMSDataTable(sCommandText, "");
69 DataColumn dcKey = table.Columns["BMXIEN"];
70 DataColumn[] dcKeys = new DataColumn[1];
71 dcKeys[0] = dcKey;
72 table.PrimaryKey = dcKeys;
73 return table;
74 }
75
76 /// <summary>
77 /// Get the Patients who have appointments in between dates for the clinics requested
78 /// </summary>
79 /// <param name="sClinicList">| delimited resource list (resource IENS, not names)</param>
80 /// <param name="BeginDate">Self Explanatory</param>
81 /// <param name="EndDate">Self Explanatory</param>
82 /// <returns>DataTable with the following columns:
83 /// T00030Name^D00020DOB^T00030Sex^T00030HRN^D00030ApptDate^T00030Clinic^T00030TypeStatus
84 /// I00010RESOURCEID^T00030APPT_MADE_BY^D00020DATE_APPT_MADE^T00250NOTE^T00030STREET^
85 /// T00030CITY^T00030STATE^T00030ZIP^T00030HOMEPHONE
86 ///</returns>
87 ///<remarks>Mirrors dsPatientApptDisplay2.PatientAppts Schema in this project. Can merge table into schema.</remarks>
88 public DataTable GetClinicSchedules(string sClinicList, DateTime BeginDate, DateTime EndDate)
89 {
90 string sBegin = FMDateTime.Create(BeginDate).DateOnly.FMDateString;
91 string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
92 string cmd = String.Format("BSDX CLINIC LETTERS^{0}^{1}^{2}", sClinicList, sBegin, sEnd);
93 return RPMSDataTable(cmd, "");
94 }
95
96 /// <summary>
97 /// Get the letter templates associated with the requested clinics (reminder letter, cancellation letter etc)
98 /// </summary>
99 /// <param name="sClinicList">| delimited resource list (resource IENS, not names)</param>
100 /// <returns>DataTable with the following columns:
101 /// I00010RESOURCEID^T00030RESOURCE_NAME^T00030LETTER_TEXT^T00030NO_SHOW_LETTER^T00030CLINIC_CANCELLATION_LETTER
102 /// </returns>
103 /// <remarks>Mirrors dsPatientApptDisplay2.BSDXResource Schema. Can merge table into schema.</remarks>
104 public DataTable GetResourceLetters(string sClinicList)
105 {
106 string cmd = String.Format("BSDX RESOURCE LETTERS^{0}", sClinicList);
107 return RPMSDataTable(cmd, "");
108 }
109
110 /// <summary>
111 /// Get the list of Patients who have Rebooked Appointments
112 /// </summary>
113 /// <param name="sClinicList">| delimited resource list (resource IENS, not names)</param>
114 /// <param name="BeginDate">Self Explanatory</param>
115 /// <param name="EndDate">Self Explanatory</param>
116 /// <returns>T00030Name^D00020DOB^T00030Sex^T00030HRN^D00030NewApptDate^T00030Clinic^T00030TypeStatus
117 /// ^I00010RESOURCEID^T00030APPT_MADE_BY^D00020DATE_APPT_MADE^T00250NOTE^T00030STREET^T00030CITY
118 /// ^T00030STATE^T00030ZIP^T00030HOMEPHONE^D00030OldApptDate
119 ///</returns>
120 /// <remarks>Mirrors dsRebookAppts.PatientAppt Schema. Can merge table into schema.</remarks>
121 public DataTable GetRebookedAppointments(string sClinicList, DateTime BeginDate, DateTime EndDate)
122 {
123 string sBegin = FMDateTime.Create(BeginDate).DateOnly.FMDateString;
124 string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
125 string cmd = String.Format("BSDX REBOOK CLINIC LIST^{0}^{1}^{2}", sClinicList, sBegin, sEnd);
126 return RPMSDataTable(cmd, "");
127 }
128
129 /// <summary>
130 /// Should have documented this better when I remembered what this did!
131 /// </summary>
132 /// <param name="sApptList">| delimited list of appointment IENs in ^BSDXAPPT</param>
133 /// <returns>"T00030Name^D00020DOB^T00030Sex^T00030HRN^D00030NewApptDate^T00030Clinic^T00030TypeStatus
134 /// ^I00010RESOURCEID^T00030APPT_MADE_BY^D00020DATE_APPT_MADE^T00250NOTE^T00030STREET^T00030CITY
135 /// ^T00030STATE^T00030ZIP^T00030HOMEPHONE^D00030OldApptDate</returns>
136 public DataTable GetRebookedAppointments(string sApptList)
137 {
138 string cmd = String.Format("BSDX REBOOK LIST^{0}", sApptList);
139 return RPMSDataTable(cmd, "");
140 }
141
142 /// <summary>
143 /// Really does what it says! Gets them by going through the BSDX APPOITMENT file index
144 /// between the specified dates for the Resource.
145 /// </summary>
146 /// <param name="sClinicList">| delmited list of Resource IENs in ^BSDXRES</param>
147 /// <param name="BeginDate"></param>
148 /// <param name="EndDate"></param>
149 /// <returns>"T00030Name^D00020DOB^T00030Sex^T00030HRN^D00030NewApptDate^T00030Clinic^T00030TypeStatus
150 /// ^I00010RESOURCEID^T00030APPT_MADE_BY^D00020DATE_APPT_MADE^T00250NOTE^T00030STREET^T00030CITY
151 /// ^T00030STATE^T00030ZIP^T00030HOMEPHONE^D00030OldApptDate</returns>
152 public DataTable GetCancelledAppointments(string sClinicList, DateTime BeginDate, DateTime EndDate)
153 {
154 string sBegin = FMDateTime.Create(BeginDate).DateOnly.FMDateString;
155 string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
156 string cmd = String.Format("BSDX CANCEL CLINIC LIST^{0}^{1}^{2}", sClinicList, sBegin, sEnd);
157 return RPMSDataTable(cmd, "");
158 }
159
160 /// <summary>
161 /// Delete All Slots for a Resource
162 /// </summary>
163 /// <param name="sResourceID">Integer Resource IEN in BSDX RESOURCE</param>
164 /// <param name="BeginDate">Self-Explanatory</param>
165 /// <param name="EndDate">Self-Explanatory</param>
166 /// <returns>Table with 2 columns: ERRORID & ERRORTEXT
167 /// ErrorID of -1 is A OK (successful operation); anything else is bad.</returns>
168 public DataTable MassSlotDelete(string sResourceID, DateTime BeginDate, DateTime EndDate)
169 {
170 string sBegin = FMDateTime.Create(BeginDate).DateOnly.FMDateString;
171 string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
172 string cmd = String.Format("BSDX CANCEL AV BY DATE^{0}^{1}^{2}", sResourceID, sBegin, sEnd);
173 return RPMSDataTable(cmd, "Cancelled");
174 }
175
176 /// <summary>
177 /// Remove the check-in for the appointment
178 /// </summary>
179 /// <param name="ApptID">Appointment IEN/Key</param>
180 /// <returns>Table with 1 columns: ERRORID. ErrorID of "0" is okay;
181 /// any other (negative numbers plus text) is bad</returns>
182 public DataTable RemoveCheckIn(int ApptID)
183 {
184 string cmd = string.Format("BSDX REMOVE CHECK-IN^{0}", ApptID);
185 return RPMSDataTable(cmd, "");
186 }
187
188 /// <summary>
189 /// TODO
190 /// </summary>
191 /// <param name="DFN"></param>
192 /// <param name="SCIEN"></param>
193 /// <returns></returns>
194 public List<RadiologyExam> GetRadiologyExamsForPatientinHL(int DFN, int SCIEN)
195 {
196 string cmd = string.Format("BSDX GET RAD EXAM FOR PT^{0}^{1}", DFN, SCIEN);
197 DataTable tbl = RPMSDataTable(cmd, "");
198 return (from row in tbl.AsEnumerable()
199 select new RadiologyExam
200 {
201 IEN = row.Field<int>("BMXIEN"),
202 Status = row.Field<string>("STATUS"),
203 Procedure = row.Field<string>("PROCEDURE"),
204 RequestDate = row.Field<DateTime>("REQUEST_DATE")
205 }).ToList();
206 }
207
208 /// <summary>
209 /// TODO
210 /// </summary>
211 /// <param name="DFN"></param>
212 /// <param name="examIEN"></param>
213 /// <returns></returns>
214 public bool ScheduleRadiologyExam(int DFN, int examIEN)
215 {
216 string result = _thisConnection.bmxNetLib.TransmitRPC("BSDX SCHEDULE RAD EXAM", string.Format("{0}^{1}",DFN,examIEN));
217 return result == "1" ? true : false;
218 }
219
220 /// <summary>
221 /// TODO
222 /// </summary>
223 /// <param name="DFN"></param>
224 /// <param name="examIEN"></param>
225 /// <returns></returns>
226 public bool CancelRadiologyExam(int DFN, int examIEN)
227 {
228 string result = _thisConnection.bmxNetLib.TransmitRPC("BSDX HOLD RAD EXAM", string.Format("{0}^{1}", DFN, examIEN));
229 return result == "1" ? true : false;
230 }
231
232 /// <summary>
233 /// Save User Preference in DB For Printing Routing Slip
234 /// Uses Parameter BSDX AUTO PRINT RS
235 /// </summary>
236 /// <remarks>
237 /// Notice Code-Fu for Async Save...
238 /// </remarks>
239 public bool AutoPrintRoutingSlip
240 {
241 get
242 {
243 string val = _thisConnection.bmxNetLib.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT RS"); //1 = true; 0 = false; "" = not set
244 return val == "1" ? true : false;
245 }
246 set
247 {
248 TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.bmxNetLib.TransmitRPC);
249 // 0 = success; anything else is wrong. Not being tested here as its success is not critical to application use.
250 _asyncTransmitter.BeginInvoke("BSDX SET PARAM", String.Format("{0}^{1}", "BSDX AUTO PRINT RS", value ? "1" : "0"), null, null);
251 }
252 }
253
254 /// <summary>
255 /// Save User Preference in DB For Printing Routing Slip
256 /// Uses Parameter BSDX AUTO PRINT AS
257 /// </summary>
258 /// <remarks>
259 /// Notice Code-Fu for Async Save...
260 /// </remarks>
261 public bool AutoPrintAppointmentSlip
262 {
263 get
264 {
265 string val = _thisConnection.bmxNetLib.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT AS"); //1 = true; 0 = false; "" = not set
266 return val == "1" ? true : false;
267 }
268 set
269 {
270 TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.bmxNetLib.TransmitRPC);
271 // 0 = success; anything else is wrong. Not being tested here as its success is not critical to application use.
272 _asyncTransmitter.BeginInvoke("BSDX SET PARAM", String.Format("{0}^{1}", "BSDX AUTO PRINT AS", value ? "1" : "0"), null, null);
273 }
274 }
275
276
277
278 /// <summary>
279 /// Workhorse
280 /// </summary>
281 /// <param name="sSQL"></param>
282 /// <param name="sTableName"></param>
283 /// <returns></returns>
284 private DataTable RPMSDataTable(string sSQL, string sTableName)
285 {
286 //Retrieves a recordset from RPMS
287 string sErrorMessage = "";
288 DataTable dtOut;
289
290#if TRACE
291 DateTime sendTime = DateTime.Now;
292#endif
293 try
294 {
295 RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(_thisConnection.RPMSDataTable);
296 dtOut = (DataTable)rdtd.Invoke(sSQL, sTableName);
297 }
298
299 catch (Exception ex)
300 {
301 sErrorMessage = "DAL.RPMSDataTable error: " + ex.Message;
302 throw ex;
303 }
304
305#if TRACE
306 DateTime receiveTime = DateTime.Now;
307 TimeSpan executionTime = receiveTime - sendTime;
308 Debug.Write("RPMSDataTable Execution Time: " + executionTime.Milliseconds + " ms.\n");
309#endif
310
311 return dtOut;
312
313 }
314 }
315}
316
317
Note: See TracBrowser for help on using the repository browser.