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

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

Comments in DAL

File size: 9.6 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
20 /// <summary>
21 /// Constructor
22 /// </summary>
23 /// <param name="conn">The current connection to use</param>
24 public DAL(BMXNetConnectInfo conn)
25 {
26 this._thisConnection = conn;
27 }
28
29 /// <summary>
30 /// Get Current version from ^ nmsp + APPL(1,0)
31 /// </summary>
32 /// <param name="nmsp">Namespace to ask for. Only "BMX" and "BSDX" are supported.</param>
33 /// <returns>Datatable with the following fields:
34 /// "T00030ERROR^T00030MAJOR_VERSION^T00030MINOR_VERSION^T00030BUILD</returns>
35 public DataTable GetVersion(string nmsp)
36 {
37 string cmd = String.Format("BMX VERSION INFO^{0}", nmsp);
38 return RPMSDataTable(cmd, "");
39 }
40
41 /// <summary>
42 /// Get Scheduling User Info
43 /// </summary>
44 /// <param name="DUZ">You should know what this is</param>
45 /// <returns>Datatable with one column: "MANAGER": One Row that's "YES" or "NO"</returns>
46 public DataTable GetUserInfo(string DUZ)
47 {
48 string cmd = String.Format("BSDX SCHEDULING USER INFO^{0}", DUZ);
49 return RPMSDataTable(cmd, "");
50 }
51
52 /// <summary>
53 /// Get all Access Types from the BSDX ACCESS TYPE file
54 /// </summary>
55 /// <returns>DataTable with the following fields (add _ for spaces)
56 /// ACCESS TYPE NAME (RF), [0;1]
57 /// INACTIVE (S), [0;2]
58 /// DEPARTMENT NAME (P9002018.2'), [0;3]
59 /// DISPLAY COLOR (F), [0;4]
60 /// RED (NJ3,0), [0;5]
61 /// GREEN (NJ3,0), [0;6]
62 /// BLUE (NJ3,0), [0;7]
63 ///</returns>
64 public DataTable GetAccessTypes()
65 {
66 string sCommandText = "SELECT * FROM BSDX_ACCESS_TYPE";
67 DataTable table = RPMSDataTable(sCommandText, "");
68 DataColumn dcKey = table.Columns["BMXIEN"];
69 DataColumn[] dcKeys = new DataColumn[1];
70 dcKeys[0] = dcKey;
71 table.PrimaryKey = dcKeys;
72 return table;
73 }
74
75 /// <summary>
76 /// Get the Patients who have appointments in between dates for the clinics requested
77 /// </summary>
78 /// <param name="sClinicList">| delimited resource list (resource IENS, not names)</param>
79 /// <param name="BeginDate">Self Explanatory</param>
80 /// <param name="EndDate">Self Explanatory</param>
81 /// <returns>DataTable with the following columns:
82 /// T00030Name^D00020DOB^T00030Sex^T00030HRN^D00030ApptDate^T00030Clinic^T00030TypeStatus
83 /// I00010RESOURCEID^T00030APPT_MADE_BY^D00020DATE_APPT_MADE^T00250NOTE^T00030STREET^
84 /// T00030CITY^T00030STATE^T00030ZIP^T00030HOMEPHONE
85 ///</returns>
86 ///<remarks>Mirrors dsPatientApptDisplay2.PatientAppts Schema in this project. Can merge table into schema.</remarks>
87 public DataTable GetClinicSchedules(string sClinicList, DateTime BeginDate, DateTime EndDate)
88 {
89 string sBegin = FMDateTime.Create(BeginDate).DateOnly.FMDateString;
90 string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
91 string cmd = String.Format("BSDX CLINIC LETTERS^{0}^{1}^{2}", sClinicList, sBegin, sEnd);
92 return RPMSDataTable(cmd, "");
93 }
94
95 /// <summary>
96 /// Get the letter templates associated with the requested clinics (reminder letter, cancellation letter etc)
97 /// </summary>
98 /// <param name="sClinicList">| delimited resource list (resource IENS, not names)</param>
99 /// <returns>DataTable with the following columns:
100 /// I00010RESOURCEID^T00030RESOURCE_NAME^T00030LETTER_TEXT^T00030NO_SHOW_LETTER^T00030CLINIC_CANCELLATION_LETTER
101 /// </returns>
102 /// <remarks>Mirrors dsPatientApptDisplay2.BSDXResource Schema. Can merge table into schema.</remarks>
103 public DataTable GetResourceLetters(string sClinicList)
104 {
105 string cmd = String.Format("BSDX RESOURCE LETTERS^{0}", sClinicList);
106 return RPMSDataTable(cmd, "");
107 }
108
109 /// <summary>
110 /// Get the list of Patients who have Rebooked Appointments
111 /// </summary>
112 /// <param name="sClinicList">| delimited resource list (resource IENS, not names)</param>
113 /// <param name="BeginDate">Self Explanatory</param>
114 /// <param name="EndDate">Self Explanatory</param>
115 /// <returns>T00030Name^D00020DOB^T00030Sex^T00030HRN^D00030NewApptDate^T00030Clinic^T00030TypeStatus
116 /// ^I00010RESOURCEID^T00030APPT_MADE_BY^D00020DATE_APPT_MADE^T00250NOTE^T00030STREET^T00030CITY
117 /// ^T00030STATE^T00030ZIP^T00030HOMEPHONE^D00030OldApptDate
118 ///</returns>
119 /// <remarks>Mirrors dsRebookAppts.PatientAppt Schema. Can merge table into schema.</remarks>
120 public DataTable GetRebookedAppointments(string sClinicList, DateTime BeginDate, DateTime EndDate)
121 {
122 string sBegin = FMDateTime.Create(BeginDate).DateOnly.FMDateString;
123 string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
124 string cmd = String.Format("BSDX REBOOK CLINIC LIST^{0}^{1}^{2}", sClinicList, sBegin, sEnd);
125 return RPMSDataTable(cmd, "");
126 }
127
128 /// <summary>
129 /// Should have documented this better when I remembered what this did!
130 /// </summary>
131 /// <param name="sApptList">| delimited list of appointment IENs in ^BSDXAPPT</param>
132 /// <returns>"T00030Name^D00020DOB^T00030Sex^T00030HRN^D00030NewApptDate^T00030Clinic^T00030TypeStatus
133 /// ^I00010RESOURCEID^T00030APPT_MADE_BY^D00020DATE_APPT_MADE^T00250NOTE^T00030STREET^T00030CITY
134 /// ^T00030STATE^T00030ZIP^T00030HOMEPHONE^D00030OldApptDate</returns>
135 public DataTable GetRebookedAppointments(string sApptList)
136 {
137 string cmd = String.Format("BSDX REBOOK LIST^{0}", sApptList);
138 return RPMSDataTable(cmd, "");
139 }
140
141 /// <summary>
142 /// Really does what it says! Gets them by going through the BSDX APPOITMENT file index
143 /// between the specified dates for the Resource.
144 /// </summary>
145 /// <param name="sClinicList">| delmited list of Resource IENs in ^BSDXRES</param>
146 /// <param name="BeginDate"></param>
147 /// <param name="EndDate"></param>
148 /// <returns>"T00030Name^D00020DOB^T00030Sex^T00030HRN^D00030NewApptDate^T00030Clinic^T00030TypeStatus
149 /// ^I00010RESOURCEID^T00030APPT_MADE_BY^D00020DATE_APPT_MADE^T00250NOTE^T00030STREET^T00030CITY
150 /// ^T00030STATE^T00030ZIP^T00030HOMEPHONE^D00030OldApptDate</returns>
151 public DataTable GetCancelledAppointments(string sClinicList, DateTime BeginDate, DateTime EndDate)
152 {
153 string sBegin = FMDateTime.Create(BeginDate).DateOnly.FMDateString;
154 string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
155 string cmd = String.Format("BSDX CANCEL CLINIC LIST^{0}^{1}^{2}", sClinicList, sBegin, sEnd);
156 return RPMSDataTable(cmd, "");
157 }
158
159 /// <summary>
160 /// Delete All Slots for a Resource
161 /// </summary>
162 /// <param name="sResourceID">Integer Resource IEN in BSDX RESOURCE</param>
163 /// <param name="BeginDate">Self-Explanatory</param>
164 /// <param name="EndDate">Self-Explanatory</param>
165 /// <returns>Table with 2 columns: ERRORID & ERRORTEXT
166 /// ErrorID of -1 is A OK (successful operation); anything else is bad.</returns>
167 public DataTable MassSlotDelete(string sResourceID, DateTime BeginDate, DateTime EndDate)
168 {
169 string sBegin = FMDateTime.Create(BeginDate).DateOnly.FMDateString;
170 string sEnd = FMDateTime.Create(EndDate).DateOnly.FMDateString;
171 string cmd = String.Format("BSDX CANCEL AV BY DATE^{0}^{1}^{2}", sResourceID, sBegin, sEnd);
172 return RPMSDataTable(cmd, "Cancelled");
173 }
174
175 /// <summary>
176 /// Workhorse
177 /// </summary>
178 /// <param name="sSQL"></param>
179 /// <param name="sTableName"></param>
180 /// <returns></returns>
181 private DataTable RPMSDataTable(string sSQL, string sTableName)
182 {
183 //Retrieves a recordset from RPMS
184 string sErrorMessage = "";
185 DataTable dtOut;
186
187#if TRACE
188 DateTime sendTime = DateTime.Now;
189#endif
190 try
191 {
192 RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(_thisConnection.RPMSDataTable);
193 dtOut = (DataTable)rdtd.Invoke(sSQL, sTableName);
194 }
195
196 catch (Exception ex)
197 {
198 sErrorMessage = "DAL.RPMSDataTable error: " + ex.Message;
199 throw ex;
200 }
201
202#if TRACE
203 DateTime receiveTime = DateTime.Now;
204 TimeSpan executionTime = receiveTime - sendTime;
205 Debug.Write("RPMSDataTable Execution Time: " + executionTime.Milliseconds + " ms.\n");
206#endif
207
208 return dtOut;
209
210 }
211 }
212}
213
214
Note: See TracBrowser for help on using the repository browser.