[843] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Data;
|
---|
| 5 | using System.Text;
|
---|
| 6 | using System.Diagnostics;
|
---|
| 7 | using IndianHealthService.BMXNet;
|
---|
| 8 |
|
---|
| 9 | namespace IndianHealthService.ClinicalScheduling
|
---|
| 10 | {
|
---|
| 11 | /// <summary>
|
---|
| 12 | /// Data Access Layer
|
---|
| 13 | /// </summary>
|
---|
| 14 | public class DAL
|
---|
| 15 | {
|
---|
| 16 | private BMXNetConnectInfo _thisConnection; // set in constructor
|
---|
[848] | 17 |
|
---|
[843] | 18 | delegate DataTable RPMSDataTableDelegate(string CommandString, string TableName); // for use in calling (Sync and Async)
|
---|
[1117] | 19 | delegate string TransmitRPCAsync(string RPCName, string Params); //same idea
|
---|
[843] | 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 |
|
---|
[1044] | 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>
|
---|
[843] | 36 | public DataTable GetVersion(string nmsp)
|
---|
| 37 | {
|
---|
| 38 | string cmd = String.Format("BMX VERSION INFO^{0}", nmsp);
|
---|
| 39 | return RPMSDataTable(cmd, "");
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[1044] | 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>
|
---|
[843] | 47 | public DataTable GetUserInfo(string DUZ)
|
---|
| 48 | {
|
---|
| 49 | string cmd = String.Format("BSDX SCHEDULING USER INFO^{0}", DUZ);
|
---|
| 50 | return RPMSDataTable(cmd, "");
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[1044] | 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>
|
---|
[843] | 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 |
|
---|
[848] | 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 | }
|
---|
[843] | 95 |
|
---|
[848] | 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 | }
|
---|
[843] | 109 |
|
---|
| 110 | /// <summary>
|
---|
[848] | 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 |
|
---|
[1044] | 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>
|
---|
[850] | 136 | public DataTable GetRebookedAppointments(string sApptList)
|
---|
| 137 | {
|
---|
| 138 | string cmd = String.Format("BSDX REBOOK LIST^{0}", sApptList);
|
---|
| 139 | return RPMSDataTable(cmd, "");
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[1044] | 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>
|
---|
[850] | 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 |
|
---|
[1039] | 160 | /// <summary>
|
---|
| 161 | /// Delete All Slots for a Resource
|
---|
| 162 | /// </summary>
|
---|
[1044] | 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>
|
---|
[1039] | 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 | }
|
---|
[850] | 175 |
|
---|
[848] | 176 | /// <summary>
|
---|
[1117] | 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>
|
---|
[1140] | 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 | public bool ScheduleRadiologyExam(int DFN, int examIEN)
|
---|
| 209 | {
|
---|
| 210 | string result = _thisConnection.bmxNetLib.TransmitRPC("BSDX SCHEDULE RAD EXAM", string.Format("{0}^{1}",DFN,examIEN));
|
---|
| 211 | return result == "1" ? true : false;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | /// <summary>
|
---|
[1117] | 215 | /// Save User Preference in DB For Printing Routing Slip
|
---|
| 216 | /// Uses Parameter BSDX AUTO PRINT RS
|
---|
| 217 | /// </summary>
|
---|
| 218 | /// <remarks>
|
---|
| 219 | /// Notice Code-Fu for Async Save...
|
---|
| 220 | /// </remarks>
|
---|
| 221 | public bool AutoPrintRoutingSlip
|
---|
| 222 | {
|
---|
| 223 | get
|
---|
| 224 | {
|
---|
| 225 | string val = _thisConnection.bmxNetLib.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT RS"); //1 = true; 0 = false; "" = not set
|
---|
| 226 | return val == "1" ? true : false;
|
---|
| 227 | }
|
---|
| 228 | set
|
---|
| 229 | {
|
---|
| 230 | TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.bmxNetLib.TransmitRPC);
|
---|
| 231 | // 0 = success; anything else is wrong. Not being tested here as its success is not critical to application use.
|
---|
| 232 | _asyncTransmitter.BeginInvoke("BSDX SET PARAM", String.Format("{0}^{1}", "BSDX AUTO PRINT RS", value ? "1" : "0"), null, null);
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 | /// <summary>
|
---|
| 237 | /// Save User Preference in DB For Printing Routing Slip
|
---|
| 238 | /// Uses Parameter BSDX AUTO PRINT AS
|
---|
| 239 | /// </summary>
|
---|
| 240 | /// <remarks>
|
---|
| 241 | /// Notice Code-Fu for Async Save...
|
---|
| 242 | /// </remarks>
|
---|
| 243 | public bool AutoPrintAppointmentSlip
|
---|
| 244 | {
|
---|
| 245 | get
|
---|
| 246 | {
|
---|
| 247 | string val = _thisConnection.bmxNetLib.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT AS"); //1 = true; 0 = false; "" = not set
|
---|
| 248 | return val == "1" ? true : false;
|
---|
| 249 | }
|
---|
| 250 | set
|
---|
| 251 | {
|
---|
| 252 | TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.bmxNetLib.TransmitRPC);
|
---|
| 253 | // 0 = success; anything else is wrong. Not being tested here as its success is not critical to application use.
|
---|
| 254 | _asyncTransmitter.BeginInvoke("BSDX SET PARAM", String.Format("{0}^{1}", "BSDX AUTO PRINT AS", value ? "1" : "0"), null, null);
|
---|
| 255 | }
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 |
|
---|
| 259 |
|
---|
| 260 | /// <summary>
|
---|
[843] | 261 | /// Workhorse
|
---|
| 262 | /// </summary>
|
---|
| 263 | /// <param name="sSQL"></param>
|
---|
| 264 | /// <param name="sTableName"></param>
|
---|
| 265 | /// <returns></returns>
|
---|
| 266 | private DataTable RPMSDataTable(string sSQL, string sTableName)
|
---|
| 267 | {
|
---|
| 268 | //Retrieves a recordset from RPMS
|
---|
| 269 | string sErrorMessage = "";
|
---|
| 270 | DataTable dtOut;
|
---|
| 271 |
|
---|
| 272 | #if TRACE
|
---|
| 273 | DateTime sendTime = DateTime.Now;
|
---|
| 274 | #endif
|
---|
| 275 | try
|
---|
| 276 | {
|
---|
| 277 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(_thisConnection.RPMSDataTable);
|
---|
| 278 | dtOut = (DataTable)rdtd.Invoke(sSQL, sTableName);
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | catch (Exception ex)
|
---|
| 282 | {
|
---|
[848] | 283 | sErrorMessage = "DAL.RPMSDataTable error: " + ex.Message;
|
---|
[843] | 284 | throw ex;
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | #if TRACE
|
---|
| 288 | DateTime receiveTime = DateTime.Now;
|
---|
| 289 | TimeSpan executionTime = receiveTime - sendTime;
|
---|
| 290 | Debug.Write("RPMSDataTable Execution Time: " + executionTime.Milliseconds + " ms.\n");
|
---|
| 291 | #endif
|
---|
| 292 |
|
---|
| 293 | return dtOut;
|
---|
| 294 |
|
---|
| 295 | }
|
---|
| 296 | }
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 |
|
---|