protected virtual void Dispose(bool disposing) { if (disposing) { var appSettings = ConfigurationManager.AppSettings; appSettings[type.Name] = LastTouch.ToString(); } }
protected virtual void Dispose(bool disposing) { if (disposing) { var appSettings = ConfigurationManager.AppSettings; try { var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var settings = configFile.AppSettings.Settings; if (settings[type.Name] == null) { settings.Add(type.Name, LastTouch.ToString()); } else { settings[type.Name].Value = LastTouch.ToString(); } if (settings["RefreshRate"] == null) { settings.Add("RefreshRate", (RefreshRate / 1000).ToString()); } else { settings["RefreshRate"].Value = (RefreshRate / 1000).ToString(); } if (settings["UseAscii"] == null) { settings.Add("UseAscii", UseAscii.ToString()); } else { settings["UseAscii"].Value = UseAscii.ToString(); } configFile.Save(ConfigurationSaveMode.Modified); //ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); } catch (Exception ex) { EventLogger.Error($"Failed to save configuration: {ex.Message}"); throw; } } }
public void ReadPrescriptionRecords() { try { _scrip.Clear(); var rxID = string.Empty; int refills = 0, refillsUsed = 0; // Load the translaton table -- Database Column Name to Gateway Tag Name TranslationTable.Add("Rx_ID", "RxSys_RxNum"); TranslationTable.Add("Patient_ID", "RxSys_PatID"); TranslationTable.Add("Prescriber_ID", "RxSys_DocID"); TranslationTable.Add("Dispensed_Item_ID", "RxSys_DrugID"); TranslationTable.Add("NDC_Code", "NDCNum"); TranslationTable.Add("Instruction_Signa_Text", "Sig"); TranslationTable.Add("Dispense_Date", "RxStartDate"); TranslationTable.Add("Last_Dispense_Stop_Date", "RxStopDate"); TranslationTable.Add("Script_Status", "Status"); TranslationTable.Add("Discontinue_Date", "DiscontinueDate"); TranslationTable.Add("Comments", "Comments"); TranslationTable.Add("Total_Refills_Authorized", "Refills"); TranslationTable.Add("Dosage_Signa_Code", "DoseScheduleName"); TranslationTable.Add("QtyPerDose", "QtyPerDose"); TranslationTable.Add("Quantity_Dispensed", "QtyDispensed"); var recordSet = Db.ExecuteQuery($"SELECT * FROM Rx WHERE MSSQLTS > '{LastTouch.ToString()}'; "); if (ValidTable(recordSet)) { foreach (DataRow record in recordSet.Tables[0].Rows) { if ((long)record["MSSQLTS"] > LastTouch) { LastTouch = (long)record["MSSQLTS"]; } // Print the DataType of each column in the table. foreach (DataColumn column in record.Table.Columns) { if (TranslationTable.TryGetValue(column.ColumnName, out var tmp)) { var tag = tmp; var val = record[column.ColumnName].ToString(); switch (column.ColumnName) { case "Rx_ID": rxID = val; GetNotes(rxID); break; case "Total_Refills_Authorized": refills = Convert.ToInt32(val); continue; case "Total_Refills_Used": refillsUsed = Convert.ToInt32(val); if (refills >= refillsUsed) { refills -= refillsUsed; _scrip.SetField("Refills", refills.ToString(), true); } continue; default: break; } // Update the local drug record _scrip.SetField(tag, val, true); } } try { Mutex.WaitOne(); using (var gw = new TcpClient(GatewayIp, GatewayPort)) { using (var stream = gw.GetStream()) { _scrip.Write(stream); } } Mutex.ReleaseMutex(); } catch (Exception ex) { EventLogger.Error($"Failed reading patient record: {ex.Message}"); throw; } finally { Mutex.ReleaseMutex(); } } } } catch (Exception e) { throw new Exception("Failed to get Scrip Record " + e.Message); } }
public void ReadFacilityRecords() { _facility.Clear(); try { // Load the translaton table -- Database Column Name to Gateway Tag Name TranslationTable.Add("RxSys_LocID", "RxSys_LocID"); TranslationTable.Add("RxSys_StoreID", "RxSys_StoreID"); TranslationTable.Add("LocationName", "LocationName"); TranslationTable.Add("Address1", "Address1"); TranslationTable.Add("Address2", "Address2"); TranslationTable.Add("CITY", "City"); TranslationTable.Add("STATE", "State"); TranslationTable.Add("ZIP", "Zip"); TranslationTable.Add("PHONE", "Phone"); var recordSet = Db.ExecuteQuery($"SELECT * FROM dbo.vMOTLocation WHERE Touchdate > '{LastTouch.ToString()}'; "); if (ValidTable(recordSet)) { foreach (DataRow record in recordSet.Tables[0].Rows) { if ((long)record["Touchdate"] > LastTouch) { LastTouch = (long)record["Touchdate"]; } // Print the DataType of each column in the table. foreach (DataColumn column in record.Table.Columns) { if (TranslationTable.TryGetValue(column.ColumnName, out var tmp)) { var tag = tmp; var val = record[column.ColumnName].ToString(); switch (column.ColumnName) { default: break; } // Update the local location record _facility.SetField(tag, val, true); } } try { // Write the record to the gateway Mutex.WaitOne(); using (var gw = new TcpClient(GatewayIp, GatewayPort)) { using (var stream = gw.GetStream()) { _facility.Write(stream); } } Mutex.ReleaseMutex(); } catch (Exception ex) { EventLogger.Error($"Error processing prescriptin record: {ex.Message}"); throw; } finally { Mutex.ReleaseMutex(); } _facility.Clear(); } } } catch (Exception ex) { throw new Exception("Failed to get Location Record " + ex.Message); } }
public int ReadPrescriberRecords() { try { _prescriber.Clear(); var tmpPhone = string.Empty; var tmpZip = string.Empty; var tmpDea = string.Empty; int counter = 0; /* * The field names in the database are generally not going to match the field names MOT uses, so we implment a pairwise * list to do the conversion on the fly. This will work for all items except where the contents of the field are incomplete, * require transformation, or are otherwise incorrect, we generate and exception list and handle them one at a time. */ TranslationTable.Add("Prescriber_ID", "RxSys_DocID"); TranslationTable.Add("Last_Name", "LastName"); TranslationTable.Add("First_Name", "FirstName"); TranslationTable.Add("Middle_Initial", "MiddleInitial"); TranslationTable.Add("Address_Line_1", "Address1"); TranslationTable.Add("Address_Line_2", "Address2"); TranslationTable.Add("City", "City"); TranslationTable.Add("State_Code", "State"); TranslationTable.Add("Zip_Code", "Zip"); // Stored as Integer TranslationTable.Add("Zip_Plus_4", "Zip_Plus_4"); // Stored as Integer TranslationTable.Add("Area_Code", "AreaCode"); // Stored as Integer TranslationTable.Add("Telephone_Number", "Phone"); // Stored as Integer TranslationTable.Add("DEA_Number", "DEA_ID"); TranslationTable.Add("DEA_Suffix", "DEA_SUFIX"); TranslationTable.Add("Prescriber_Type ", "Specialty"); TranslationTable.Add("Active_Flag", "Comments"); // 'Y' || 'N' Lookup.Add("DDS", "Dentist"); Lookup.Add("DO", "Osteopath"); Lookup.Add("DPM", "Podiatrist"); Lookup.Add("DVM", "Veterinarian"); Lookup.Add("IN", "Intern"); Lookup.Add("MD", "Medical Doctor"); Lookup.Add("NP", "Nurse Practitioner"); Lookup.Add("OPT", "Optometrist"); Lookup.Add("PA", "Physician Assistant"); Lookup.Add("RN", "Registered Nurse"); Lookup.Add("RPH", "Registered Pharmacist"); /* * Query the database and collect a set of records where a valid set is {1..n} items. This is not a traditional * record set as returned by access or SQL server, but a generic collection of IDataRecords and is usable accross * all database types. If the set of records is {0} an exception will be thrown */ var tag = string.Empty; var val = string.Empty; var tmp = string.Empty; DataSet recordSet = Db.ExecuteQuery($"SELECT * FROM vPrescriber WHERE MSSQLTS > '{LastTouch.ToString()}';"); if (ValidTable(recordSet)) { foreach (DataRow record in recordSet.Tables[0].Rows) { if ((long)record["MSSQLTS"] > LastTouch) { LastTouch = (long)record["MSSQLTS"]; } foreach (DataColumn column in record.Table.Columns) { if (TranslationTable.TryGetValue(column.ColumnName, out tmp)) { tag = tmp; val = record[column.ColumnName].ToString(); switch (column.ColumnName) { // Merge Zip Code case "Zip_Code": tmpZip = val; continue; case "Zip_Plus_4": tmpZip += val; val = tmpZip; break; // Merge Phone Number case "Area_Code": tmpPhone = val; continue; case "Telephone_Number": tmpPhone += val; val = tmpPhone; break; // Merge DEA ID case "DEA_Number": tmpDea = val; continue; case "DEA_Suffix": tmpDea += val; val = tmpDea; break; default: break; } // Update the local Prescriber record _prescriber.SetField(tag, val, true); } } try { // Write the record to the gateway Mutex.WaitOne(); using (var gw = new TcpClient(GatewayIp, GatewayPort)) { using (var stream = gw.GetStream()) { _prescriber.Write(stream); } } Mutex.ReleaseMutex(); } catch (Exception ex) { EventLogger.Error($"Error processing prescriptin record: {ex.Message}"); throw; } finally { Mutex.ReleaseMutex(); } _prescriber.Clear(); } } return(counter); } catch (Exception ex) { throw new Exception($"Failed to add PharmaServe Prescriber Record {ex.Message}"); } }