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

Last change on this file since 1675 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
RevLine 
[1174]1/* Licensed under LGPL */
2
3using System;
[843]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 {
[1474]18 private RemoteSession _thisConnection; // set in constructor
[848]19
[843]20 delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName); // for use in calling (Sync and Async)
[1117]21 delegate string TransmitRPCAsync(string RPCName, string Params); //same idea
[843]22
23 /// <summary>
24 /// Constructor
25 /// </summary>
26 /// <param name="conn">The current connection to use</param>
[1474]27 public DAL(RemoteSession conn)
[843]28 {
29 this._thisConnection = conn;
30 }
31
[1044]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>
[843]38 public DataTable GetVersion(string nmsp)
39 {
40 string cmd = String.Format("BMX VERSION INFO^{0}", nmsp);
[1474]41 return _thisConnection.TableFromCommand(cmd);
[843]42 }
43
[1044]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>
[843]49 public DataTable GetUserInfo(string DUZ)
50 {
51 string cmd = String.Format("BSDX SCHEDULING USER INFO^{0}", DUZ);
[1474]52 return _thisConnection.TableFromCommand(cmd);
[843]53 }
54
[1044]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>
[1474]67 public DataTable GetAccessTypes(DataSet dataSetToTakeTable, string tablename)
[843]68 {
69 string sCommandText = "SELECT * FROM BSDX_ACCESS_TYPE";
[1474]70 DataTable table = _thisConnection.TableFromSQL(sCommandText, dataSetToTakeTable, tablename);
[843]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
[848]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);
[1474]95 return _thisConnection.TableFromCommand(cmd);
[848]96 }
[843]97
[848]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);
[1474]109 return _thisConnection.TableFromCommand(cmd);
[848]110 }
[843]111
112 /// <summary>
[848]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);
[1474]128 return _thisConnection.TableFromCommand(cmd);
[848]129 }
130
[1044]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>
[850]138 public DataTable GetRebookedAppointments(string sApptList)
139 {
140 string cmd = String.Format("BSDX REBOOK LIST^{0}", sApptList);
[1474]141 return _thisConnection.TableFromCommand(cmd);
[850]142 }
143
[1044]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>
[850]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);
[1474]159 return _thisConnection.TableFromCommand(cmd);
[850]160 }
161
[1039]162 /// <summary>
163 /// Delete All Slots for a Resource
164 /// </summary>
[1044]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>
[1039]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);
[1474]175 return _thisConnection.TableFromCommand(cmd);
[1039]176 }
[850]177
[848]178 /// <summary>
[1117]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);
[1474]187 return _thisConnection.TableFromCommand(cmd);
[1117]188 }
189
190 /// <summary>
[1174]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);
[1474]199 DataTable tbl = _thisConnection.TableFromCommand(cmd);
[1174]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;
[1474]220 string result = _thisConnection.TransmitRPC("BSDX SCHEDULE RAD EXAM", string.Format("{0}^{1}^{2}", DFN, examIEN, fmStartDate));
[1174]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 {
[1474]232 string result = _thisConnection.TransmitRPC("BSDX HOLD RAD EXAM", string.Format("{0}^{1}", DFN, examIEN));
[1174]233 return result == "1" ? true : false;
234 }
[1186]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 {
[1474]243 string result = _thisConnection.TransmitRPC("BSDX CAN HOLD RAD EXAM", examIEN.ToString());
[1186]244 return result == "1" ? true : false;
245 }
[1174]246
247 /// <summary>
[1117]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 {
[1474]258 string val = _thisConnection.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT RS"); //1 = true; 0 = false; "" = not set
[1117]259 return val == "1" ? true : false;
260 }
261 set
262 {
[1474]263 TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.TransmitRPC);
[1117]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 {
[1474]280 string val = _thisConnection.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT AS"); //1 = true; 0 = false; "" = not set
[1117]281 return val == "1" ? true : false;
282 }
283 set
284 {
[1474]285 TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.TransmitRPC);
[1117]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>
[843]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 {
[1474]307 RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(_thisConnection.TableFromSQL);
[843]308 dtOut = (DataTable)rdtd.Invoke(sSQL, sTableName);
309 }
310
311 catch (Exception ex)
312 {
[848]313 sErrorMessage = "DAL.RPMSDataTable error: " + ex.Message;
[843]314 throw ex;
315 }
316
317 return dtOut;
318
319 }
320 }
321}
322
323
Note: See TracBrowser for help on using the repository browser.