| 1 | /* Licensed under LGPL */ | 
|---|
| 2 |  | 
|---|
| 3 | using System; | 
|---|
| 4 | using System.Collections.Generic; | 
|---|
| 5 | using System.Linq; | 
|---|
| 6 | using System.Data; | 
|---|
| 7 | using System.Text; | 
|---|
| 8 | using System.Diagnostics; | 
|---|
| 9 | using IndianHealthService.BMXNet; | 
|---|
| 10 |  | 
|---|
| 11 | namespace 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 | /// Save User Preference in DB For Printing Routing Slip | 
|---|
| 238 | /// Uses Parameter BSDX AUTO PRINT RS | 
|---|
| 239 | /// </summary> | 
|---|
| 240 | /// <remarks> | 
|---|
| 241 | /// Notice Code-Fu for Async Save... | 
|---|
| 242 | /// </remarks> | 
|---|
| 243 | public bool AutoPrintRoutingSlip | 
|---|
| 244 | { | 
|---|
| 245 | get | 
|---|
| 246 | { | 
|---|
| 247 | string val = _thisConnection.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT RS");  //1 = true; 0 = false; "" = not set | 
|---|
| 248 | return val == "1" ? true : false; | 
|---|
| 249 | } | 
|---|
| 250 | set | 
|---|
| 251 | { | 
|---|
| 252 | TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.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 RS", value ? "1" : "0"), null, null); | 
|---|
| 255 | } | 
|---|
| 256 | } | 
|---|
| 257 |  | 
|---|
| 258 | /// <summary> | 
|---|
| 259 | /// Save User Preference in DB For Printing Routing Slip | 
|---|
| 260 | /// Uses Parameter BSDX AUTO PRINT AS | 
|---|
| 261 | /// </summary> | 
|---|
| 262 | /// <remarks> | 
|---|
| 263 | /// Notice Code-Fu for Async Save... | 
|---|
| 264 | /// </remarks> | 
|---|
| 265 | public bool AutoPrintAppointmentSlip | 
|---|
| 266 | { | 
|---|
| 267 | get | 
|---|
| 268 | { | 
|---|
| 269 | string val = _thisConnection.TransmitRPC("BSDX GET PARAM", "BSDX AUTO PRINT AS");  //1 = true; 0 = false; "" = not set | 
|---|
| 270 | return val == "1" ? true : false; | 
|---|
| 271 | } | 
|---|
| 272 | set | 
|---|
| 273 | { | 
|---|
| 274 | TransmitRPCAsync _asyncTransmitter = new TransmitRPCAsync(_thisConnection.TransmitRPC); | 
|---|
| 275 | // 0 = success; anything else is wrong. Not being tested here as its success is not critical to application use. | 
|---|
| 276 | _asyncTransmitter.BeginInvoke("BSDX SET PARAM", String.Format("{0}^{1}", "BSDX AUTO PRINT AS", value ? "1" : "0"), null, null); | 
|---|
| 277 | } | 
|---|
| 278 | } | 
|---|
| 279 |  | 
|---|
| 280 |  | 
|---|
| 281 |  | 
|---|
| 282 | /// <summary> | 
|---|
| 283 | /// Workhorse | 
|---|
| 284 | /// </summary> | 
|---|
| 285 | /// <param name="sSQL"></param> | 
|---|
| 286 | /// <param name="sTableName"></param> | 
|---|
| 287 | /// <returns></returns> | 
|---|
| 288 | private DataTable RPMSDataTable(string sSQL, string sTableName) | 
|---|
| 289 | { | 
|---|
| 290 | //Retrieves a recordset from RPMS | 
|---|
| 291 | string sErrorMessage = ""; | 
|---|
| 292 | DataTable dtOut; | 
|---|
| 293 |  | 
|---|
| 294 | try | 
|---|
| 295 | { | 
|---|
| 296 | RPMSDataTableDelegate rdtd = new RPMSDataTableDelegate(_thisConnection.TableFromSQL); | 
|---|
| 297 | dtOut = (DataTable)rdtd.Invoke(sSQL, sTableName); | 
|---|
| 298 | } | 
|---|
| 299 |  | 
|---|
| 300 | catch (Exception ex) | 
|---|
| 301 | { | 
|---|
| 302 | sErrorMessage = "DAL.RPMSDataTable error: " + ex.Message; | 
|---|
| 303 | throw ex; | 
|---|
| 304 | } | 
|---|
| 305 |  | 
|---|
| 306 | return dtOut; | 
|---|
| 307 |  | 
|---|
| 308 | } | 
|---|
| 309 | } | 
|---|
| 310 | } | 
|---|
| 311 |  | 
|---|
| 312 |  | 
|---|