source: Scheduling/trunk/cs/bsdx0200GUISourceCode/DAL.cs@ 1474

Last change on this file since 1474 was 1474, checked in by Sam Habiel, 12 years ago

Finally, v 1.7 to the main repo. I will delete the branch after this.

This commit merges all the BMX4 changes in the Scheduling GUI back to the main trunk.

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