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

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

CGAVDocument: Don't Update Grid. Leave that to CGAVView.
CGAVView: When updating grid, make a copy of appointments, and use the copy, so there won't be clashes when updating appointments in the background.
CGDocument: Minor Changes in AppointmentNoShow; New method AppointmentUndoCheckIn
CGDocumentManager: Resequenced load order b/c UserPreferences now talks to DB.
DAL: New Methods to save autoprint preferences; new delegate to enable some async stuff
DCheckIn & DAppointPage: _myCodeIsFiringIstheCheckBoxChangedEvent added to protect against firing event when setting checkbox in the code.
DPatientLetter: No changes.
UserPreferences: Now gets and saves user preferences from DB.

File size: 12.1 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 /// Save User Preference in DB For Printing Routing Slip
190 /// Uses Parameter BSDX AUTO PRINT RS
191 /// </summary>
192 /// <remarks>
193 /// Notice Code-Fu for Async Save...
194 /// </remarks>
195 public bool AutoPrintRoutingSlip
196 {
197 get
198 {
199 string val = _thisConnection.bmxNetLib.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT RS"); //1 = true; 0 = false; "" = not set
200 return val == "1" ? true : false;
201 }
202 set
203 {
204 TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.bmxNetLib.TransmitRPC);
205 // 0 = success; anything else is wrong. Not being tested here as its success is not critical to application use.
206 _asyncTransmitter.BeginInvoke("BSDX SET PARAM", String.Format("{0}^{1}", "BSDX AUTO PRINT RS", value ? "1" : "0"), null, null);
207 }
208 }
209
210 /// <summary>
211 /// Save User Preference in DB For Printing Routing Slip
212 /// Uses Parameter BSDX AUTO PRINT AS
213 /// </summary>
214 /// <remarks>
215 /// Notice Code-Fu for Async Save...
216 /// </remarks>
217 public bool AutoPrintAppointmentSlip
218 {
219 get
220 {
221 string val = _thisConnection.bmxNetLib.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT AS"); //1 = true; 0 = false; "" = not set
222 return val == "1" ? true : false;
223 }
224 set
225 {
226 TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.bmxNetLib.TransmitRPC);
227 // 0 = success; anything else is wrong. Not being tested here as its success is not critical to application use.
228 _asyncTransmitter.BeginInvoke("BSDX SET PARAM", String.Format("{0}^{1}", "BSDX AUTO PRINT AS", value ? "1" : "0"), null, null);
229 }
230 }
231
232
233
234 /// <summary>
235 /// Workhorse
236 /// </summary>
237 /// <param name="sSQL"></param>
238 /// <param name="sTableName"></param>
239 /// <returns></returns>
240 private DataTable RPMSDataTable(string sSQL, string sTableName)
241 {
242 //Retrieves a recordset from RPMS
243 string sErrorMessage = "";
244 DataTable dtOut;
245
246#if TRACE
247 DateTime sendTime = DateTime.Now;
248#endif
249 try
250 {
251 RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(_thisConnection.RPMSDataTable);
252 dtOut = (DataTable)rdtd.Invoke(sSQL, sTableName);
253 }
254
255 catch (Exception ex)
256 {
257 sErrorMessage = "DAL.RPMSDataTable error: " + ex.Message;
258 throw ex;
259 }
260
261#if TRACE
262 DateTime receiveTime = DateTime.Now;
263 TimeSpan executionTime = receiveTime - sendTime;
264 Debug.Write("RPMSDataTable Execution Time: " + executionTime.Milliseconds + " ms.\n");
265#endif
266
267 return dtOut;
268
269 }
270 }
271}
272
273
Note: See TracBrowser for help on using the repository browser.