protected MotSqlServerPollerBase(MotSqlServer db, Mutex mutex, string gatewayIp, int gatewayPort) { type = typeof(T); if (db == null || mutex == null) { throw new ArgumentNullException(type.Name); } Db = db; Mutex = mutex; TranslationTable = new Dictionary <string, string>(); Lookup = new Dictionary <string, string>(); EventLogger = LogManager.GetLogger(type.Name); try { var appSettings = ConfigurationManager.AppSettings; LastTouch = Convert.ToInt64(appSettings[type.Name]); } catch { EventLogger.Warn("Failed to get Last Touch Time, defaulting to .Now"); LastTouch = 0L; } }
public void CreateObjects() { try { if (!CreatedRecords) { CreateSqlRecords(); } var mutex = new Mutex(); var gatewayIp = targetIp; var gatewayPort = targetPort; SetupSqlServer(); using (var motSqlServer = new MotSqlServer($"Data Source={dataSource};Initial Catalog=McKessonTestDb;User ID=sa;Password=$MOT2018")) { var patient = new PollPatient(motSqlServer, mutex, gatewayIp, gatewayPort); var doc = new PollPrescriber(motSqlServer, mutex, gatewayIp, gatewayPort); var facility = new PollFacility(motSqlServer, mutex, gatewayIp, gatewayPort); var scrip = new PollPrescription(motSqlServer, mutex, gatewayIp, gatewayPort); var drug = new PollDrug(motSqlServer, mutex, gatewayIp, gatewayPort); } } catch (Exception ex) { Console.WriteLine(ex.Message); Assert.Fail(ex.Message); } }
public Pharmaserve(MotSqlServer motSqlServer, string gatewayIp, int gatewayPort) { try { this.MotSqlServer = motSqlServer; _mutex = new Mutex(); EventLogger = LogManager.GetLogger("PharmaserveSql"); GatewayIp = gatewayIp; GatewayPort = gatewayPort; _waitForPrescriber = new Thread(Start => WaitForPrescriberRecord); _waitForPrescription = new Thread(WaitForPrescriptionRecord); _waitForPatient = new Thread(WaitForPatientRecord); _waitForFacility = new Thread(WaitForFacilityRecord); _waitForStore = new Thread(WaitForStoreRecord); _waitForTq = new Thread(WaitForTqRecord); _waitForDrug = new Thread(WaitForDrugRecord); } catch (Exception ex) { Console.WriteLine($"Failed to construct Pharmaserve object: {ex.Message}"); throw; } }
public Pharmaserve(MotSqlServer motSqlServer, string gatewayIp, int gatewayPort) { try { MotSqlServer = motSqlServer; _mutex = new Mutex(); EventLogger = LogManager.GetLogger("PharmaserveSql"); GatewayIp = gatewayIp; GatewayPort = gatewayPort; } catch (Exception ex) { EventLogger.Error($"Failed to construct Pharmaserve object: {ex.Message}"); throw; } }
public void StartPharmaserve() { var mutex = new Mutex(); var gatewayIp = targetIp; var gatewayPort = targetPort; SetupSqlServer(); using (var motSqlServer = new MotSqlServer($"Data Source={dataSource};Initial Catalog=McKessonTestDb;User ID=sa;Password=$MOT2018")) { using (var ps = new Pharmaserve(motSqlServer, gatewayIp, gatewayPort)) { ps.RefreshRate = 1000; ps.Go(); Thread.Sleep(10000); ps.Stop(); } } }
protected MotSqlServerPollerBase(MotSqlServer db, Mutex mutex, string gatewayIp, int gatewayPort, bool useAscii = true) { type = typeof(T); if (db == null || mutex == null) { throw new ArgumentNullException(type.Name); } Db = db; Mutex = mutex; GatewayIp = gatewayIp; GatewayPort = gatewayPort; UseAscii = useAscii; TranslationTable = new Dictionary <string, string>(); Lookup = new Dictionary <string, string>(); EventLogger = LogManager.GetLogger(type.Name); try { var appSettings = ConfigurationManager.AppSettings; LastTouch = appSettings[type.Name].ToString(); if (!string.IsNullOrEmpty(appSettings["RefreshRate"])) { RefreshRate = Convert.ToInt32(appSettings["RefreshRate"]) * 1000; } if (!string.IsNullOrEmpty(appSettings["RefreshRate"])) { UseAscii = appSettings["UseAscii"].ToLower() == "true"; } } catch { EventLogger.Warn("Failed to get Last Touch Time, defaulting to .Now"); LastTouch = "0x0000000000000000"; } }
public void QueryDrug() { try { if (!CreatedRecords) { CreateSqlRecords(); } var mutex = new Mutex(); var gatewayIp = targetIp; var gatewayPort = targetPort; SetupSqlServer(); using (var motSqlServer = new MotSqlServer($"Data Source={dataSource};Initial Catalog=McKessonTestDb;User ID=sa;Password=$MOT2018")) { using (var drug = new PollDrug(motSqlServer, mutex, gatewayIp, gatewayPort)) { drug.UseAscii = useAscii; try { drug.ReadDrugRecords(); } catch (Exception e) { Console.WriteLine(e); throw; } } } } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void Start() { try { LoadConfiguration(); // "Data Source=PROXYPLAYGROUND;Initial Catalog=McKessonTestDb;User ID=sa;Password=$MOT2018" _connectString = $"Data Source={DbServer};Initial Catalog={DbName};User ID={DbUser};Password={DbPassword};"; _motDatabaseServer = new MotSqlServer(_connectString); _pharmaserve = new Pharmaserve(_motDatabaseServer, GatewayIp, GatewayPort); _pharmaserve.RefreshRate = RefreshRate; _pharmaserve.Go(); EventLogger.Info("Service started"); } catch (Exception ex) { Console.WriteLine(ex); EventLogger.Error($"Failed to start service: {ex.Message}"); throw; } }
public PollPatient(MotSqlServer db, Mutex mutex, string gatewayIp, int gatewayPort) : base(db, mutex, gatewayIp, gatewayPort) { _patient = new MotPatientRecord("Add"); _patient.UseAscii = UseAscii; }
public PollPrescription(MotSqlServer db, Mutex mutex, string gatewayIp, int gatewayPort) : base(db, mutex, gatewayIp, gatewayPort) { _scrip = new MotPrescriptionRecord("Add"); }
public PollTQ(MotSqlServer db, Mutex mutex, string gatewayIp, int gatewayPort) : base(db, mutex, gatewayIp, gatewayPort) { _tq = new MotTimesQtysRecord("Add"); _tq.UseAscii = UseAscii; }
public PollFacility(MotSqlServer db, Mutex mutex, string gatewayIp, int gatewayPort) : base(db, mutex, gatewayIp, gatewayPort) { _facility = new MotFacilityRecord("Add"); }
// ---- Real Work public void CreateSqlRecords() { SetupSqlServer(); if (CreatedRecords == true) { return; } try { using (var motSqlServer = new MotSqlServer( $"Data Source={dataSource};Initial Catalog=McKessonTestDb;User ID=sa;Password=$MOT2018")) { for (var i = 0; i < 16; i++) { CreatedRecords = true; var docId = RandomData.Integer(); var patId = RandomData.Integer(); var facId = RandomData.TrimString(2).ToUpper(); var storeId = "PHARMASERVE1"; var scripId = RandomData.Integer(); var drugId = RandomData.Integer(); // Prescriber var sql = $"INSERT INTO dbo.vPrescriber VALUES(" + $"'{docId}', " + // Prescriber_ID $"'{RandomData.TrimString(25).ToUpper()}', " + // Last_Name $"'{RandomData.TrimString(15).ToUpper()}', " + // First_Name $"'{RandomData.TrimString(1).ToUpper()}', " + // Middle_Initial $"'{RandomData.TrimString(25).ToUpper()}', " + // Address_Line_1 $"'{RandomData.TrimString(25).ToUpper()}', " + // Address_Line_2 $"'{RandomData.TrimString(20).ToUpper()}', " + // City $"'MA', " + // State_Code $"'0{RandomData.Integer(1000, 10000)}', " + // Zip_Code $"'{RandomData.Integer(1000, 10000)}', " + // Zip_Plus_4 $"'{RandomData.Integer(100, 1000)}', " + // Area_Code $"'{RandomData.Integer(1000000, 10000000)}', " + // Telephone_Number $"'{RandomData.Integer(1, 100)}', " + // Exchange $"'{RandomData.TrimString(2).ToUpper()}{RandomData.Integer(1000000, 10000000)}', " + // DEA_Number $"'{RandomData.Integer(100000, 1000000)}', " + // DEA_Suffix $"'{RandomData.TrimString(4).ToUpper()}', " + // Prescriber_Type// $"'{RandomData.Bit()}', " + // Active_Flag $"DEFAULT);"; // MSSQLTS motSqlServer.ExecuteNonQuery(sql); // Prescriber Note sql = $"INSERT INTO dbo.vPrescriberNote VALUES(" + $"'{docId}', " + $"'{RandomData.Integer()}', " + $"'{RandomData.TrimString(10).ToUpper()}', " + $"'{RandomData.TrimString(30).ToUpper()}', " + $"'{DateTime.Now}', " + $"'{RandomData.String()}');"; motSqlServer.ExecuteNonQuery(sql); sql = $"INSERT INTO dbo.vMOTLocation VALUES(" + $"'{facId}', " + $"'{storeId}', " + $"'{RandomData.TrimString(64).ToUpper()}', " + $"'{RandomData.TrimString(40).ToUpper()}', " + $"'{RandomData.TrimString(40).ToUpper()}', " + $"'{RandomData.TrimString(25).ToUpper()}', " + $"'NH', " + $"'0{RandomData.Integer(1000, 10000)}', " + $"'{RandomData.USPhoneNumber()}', " + $"DEFAULT);"; motSqlServer.ExecuteNonQuery(sql); var ndc = RandomData.TrimString(11).ToUpper(); // Drug sql = $"INSERT INTO dbo.vItem " + $"VALUES('{drugId}', " + //[ITEM_ID] $"{RandomData.Integer(1, short.MaxValue)}, " + //[ITEM_VERSION] $"'{ndc}', " + //[NDC_CODE] $"'{RandomData.TrimString(2).ToUpper()}', " + //[PACKAGE_CODE] $"'{RandomData.Double(100)}', " + //[PACKAGE_SIZE] $"{RandomData.Integer(1, 10)}, " + //[CURRENT_ITEM_VERSION] $"'{RandomData.TrimString(3).ToUpper()}', " + //[ITEM_TYPE] $"'{RandomData.TrimString(40)}', " + //[ITEM_NAME] $"'{RandomData.Integer()}', " + //[KDC_NUMBER] $"'{RandomData.Integer(1, byte.MaxValue)}', " + //[GPI_GROUP_CODE] $"'{RandomData.Integer(1, byte.MaxValue)}', " + //[GPI_CLASS_CODE] $"'{RandomData.Integer(1, byte.MaxValue)}', " + //[GPI_SUBCLASS_CODE] $"'{RandomData.Integer(1, byte.MaxValue)}', " + //[GPI_NAME_CODE] $"'{RandomData.Integer(1, byte.MaxValue)}', " + //[GPI_NAME_EXTENSION_CODE] $"'{RandomData.Integer(1, byte.MaxValue)}', " + //[GPI_DOSAGE_FORM_CODE] $"'{RandomData.Integer(1, byte.MaxValue)}', " + //[GPI_STRENGTH_CODE] $"'{RandomData.Integer()}', " + //[HRI_NUMBER] $"'{RandomData.TrimString(7).ToUpper()}', " + //[DOSAGE_SIGNA_CODE] $"'{RandomData.TrimString(80).ToUpper()}', " + //[INSTRUCTION_SIGNA_STRING] $"'{RandomData.TrimString(4).ToUpper()}', " + //[FORM_TYPE] $"'{RandomData.TrimString(3).ToUpper()}', " + //[ROUTE_OF_ADMINISTRATION] $"'{RandomData.Integer()}', " + //[ALTERNATE_MANUFACTURER_ID] $"'{RandomData.TrimString(13).ToUpper()}', " + //[UPC] $"'{RandomData.Double(10).ToString(CultureInfo.InvariantCulture).Substring(0, 15)}', " + //[STRENGTH] $"'{RandomData.TrimString(4).ToUpper()}', " + //[COLOR_CODE] $"'{RandomData.TrimString(4).ToUpper()}', " + //[FLAVOR_CODE] $"'{RandomData.TrimString(4).ToUpper()}', " + //[SHAPE_CODE] $"'{RandomData.TrimString(10).ToUpper()}', " + //[PRODUCT_MARKING] $"'{RandomData.Integer(1, 8)}', " + //[NARCOTIC_CODE] $"'{RandomData.Double(100)}', " + //[UNIT_SIZE] $"'{RandomData.TrimString(2).ToUpper()}', " + //[UNIT_OF_MEASURE] $"'{RandomData.TrimString(5).ToUpper()}', " + //[NDC_Manufacturer_Number] $"'{RandomData.TrimString(10).ToUpper()}', " + //[Manufacturer_Abbreviation] $"DEFAULT);"; //[MSSQLTS] motSqlServer.ExecuteNonQuery(sql); // Drug Caution sql = $"INSERT INTO dbo.vItemCaution VALUES(" + $"'{RandomData.Integer()}', " + $"'{RandomData.Integer(1, 10000)}', " + $"'{RandomData.TrimString(255)}');"; motSqlServer.ExecuteNonQuery(sql); var mf = new[] { "M", "F" }; // Patient sql = $"INSERT INTO dbo.vPatient VALUES(" + $"'{patId}', " + // Patient_ID $"'{RandomData.TrimString(25).ToUpper()}', " + // Last_Name $"'{RandomData.TrimString(15).ToUpper()}', " + // First_Name $"'{RandomData.TrimString(1).ToUpper()}', " + // Middle_Initial $"'{RandomData.TrimString(25).ToUpper()}', " + // Address_Line_1 $"'{RandomData.TrimString(25).ToUpper()}', " + // Address_Line_2 $"'{RandomData.TrimString(20).ToUpper()}', " + // City $"'NH', " + // State_Code $"'0{RandomData.Integer(1000, 10000)}', " + // Zip_Code $"'{RandomData.Integer(1000, 10000)}', " + // Zip_Plus_4 $"'{facId}', " + // Patient_Location_Code $"'{docId}', " + // Primary_Prescriber_ID $"'{RandomData.Integer(100000000, 1000000000)}', " + // SSN $"'{DateTime.Now.ToString(CultureInfo.InvariantCulture)}', " + // BirthDate $"'{DateTime.Now.ToString(CultureInfo.InvariantCulture)}', " + // Deceased_Date $"'{mf[RandomData.Bit()]}', " + // Sex $"DEFAULT, " + // MSSQLTS $"'{RandomData.Integer(100, 1000)}', " + // Area_Code $"'{RandomData.Integer(1000000, 10000000)}', " + // Telephone_Number $"'{RandomData.Integer(1, 100)}');"; // Extension motSqlServer.ExecuteNonQuery(sql); // Patient Note sql = $"INSERT INTO dbo.vPatientNote VALUES(" + $"'{patId}', " + $"'{RandomData.Integer()}', " + $"'{RandomData.TrimString(10).ToUpper()}', " + $"'{RandomData.TrimString(30).ToUpper()}', " + $"'{DateTime.Now}', " + $"'{RandomData.String()}');"; motSqlServer.ExecuteNonQuery(sql); // Patient Allergy sql = $"INSERT INTO dbo.vPatientAllergy VALUES(" + $"'{patId}', " + $"'{RandomData.Integer()}', " + $"'{RandomData.TrimString(3).ToUpper()}', " + $"'{RandomData.TrimString(80)}', " + $"'{RandomData.TrimString(70)}', " + $"'{RandomData.Integer()}', " + $"'{DateTime.Now}');"; motSqlServer.ExecuteNonQuery(sql); // Patient Diagnosis sql = $"INSERT INTO dbo.vPatientDiagnosis VALUES(" + $"'{patId}', " + $"'{RandomData.TrimString(70)}', " + $"'{RandomData.TrimString(80)}', " + $"'{DateTime.Now}', " + $"'{DateTime.Now}');"; motSqlServer.ExecuteNonQuery(sql); var refills = RandomData.Integer(1, 100); var refillsRemaining = RandomData.Integer(1, refills); var daysSupply = RandomData.Integer(1, 366); var daysRemaining = RandomData.Integer(1, daysSupply); /* * sql = $"INSERT INTO dbo.vRx VALUES(" + * $"'{patId}', " + // Patient_ID * $"'{scripId}', " + // Rx_ID * $"{RandomData.Integer()}, " + // External_Rx_ID * $"'{docId}', " + // Prescriber_ID * $"'{RandomData.TrimString(7).ToUpper()}', " + // Dosage_Signa_Code * $"'{RandomData.TrimString(255)}', " + // Decoded_Dosage_Signa * $"'{RandomData.TrimString(80)}', " + // Signa_String * $"'{RandomData.TrimString(255)}', " + // Instruction_Signa_Text * $"'{DateTime.Now.ToString(CultureInfo.InvariantCulture)}', " + // Date_Written * $"'{DateTime.Now.ToString(CultureInfo.InvariantCulture)}', " + // Dispense_Date * $"'{DateTime.Now.ToString(CultureInfo.InvariantCulture)}', " + // Last_Dispense_Stop_Date * $"'{refills}', " + // Total_Refiles_Authorized * $"'{refillsRemaining}', " + // Total_Refills_Used * $"'{RandomData.Integer()}', " + // Dispensed_Item_ID * $"'{RandomData.Integer(1, short.MaxValue)}', " + // Dispensed_Item_Version * $"'{ndc}', " + // NDC_Code * $"'{RandomData.Double(100)}', " + // Quantity_Dispensed * $"'{RandomData.Integer()}', " + // Writen_For_Item_ID * $"'{RandomData.Integer(1, short.MaxValue)}', " + // Written_For_Item_Version * $"'{RandomData.Bit()}', " + // Script_Status * $"'{DateTime.Now.ToString(CultureInfo.InvariantCulture)}', " + // Prescription_Expiration_Date * $"'{docId}', " + // Responsible_Prescriber_ID * $"'{DateTime.Now.ToString(CultureInfo.InvariantCulture)}', " + // Discontinue_Date * $"'{RandomData.Double(10)}', " + // Quantity_Written * $"'{RandomData.Double(10)}', " + // Total_Qty_Used * $"'{RandomData.Double(10)}', " + // Total_Qty_Authorized * $"'{daysSupply}', " + // Days_Supply_Written * $"'{daysRemaining}', " + // Days_Supply_Remaining * $"'{RandomData.TrimString(3).ToUpper()}', " + // Script_Origin_Indicater * $"DEFAULT);"; // MSSQLTS */ sql = $"INSERT INTO dbo.vRx VALUES(" + $"'{patId}', " + // Patient_ID $"'{scripId}', " + // Rx_ID $"{RandomData.Integer()}, " + // External_Rx_ID $"'{docId}', " + // Prescriber_ID $"'{RandomData.TrimString(7).ToUpper()}', " + // Dosage_Signa_Code $"'{RandomData.TrimString(255)}', " + // Decoded_Dosage_Signa $"'{RandomData.TrimString(80)}', " + // Signa_String $"'{RandomData.TrimString(255)}', " + // Instruction_Signa_Text $"'{DateTime.Now.ToString(CultureInfo.InvariantCulture)}', " + // Date_Written $"'{DateTime.Now.ToString(CultureInfo.InvariantCulture)}', " + // Dispense_Date $"NULL, " + // Last_Dispense_Stop_Date $"'{refills}', " + // Total_Refiles_Authorized $"'{refillsRemaining}', " + // Total_Refills_Used $"'{RandomData.Integer()}', " + // Dispensed_Item_ID $"'{RandomData.Integer(1, short.MaxValue)}', " + // Dispensed_Item_Version $"'{ndc}', " + // NDC_Code $"'{RandomData.Double(100)}', " + // Quantity_Dispensed $"'{RandomData.Integer()}', " + // Writen_For_Item_ID $"'{RandomData.Integer(1, short.MaxValue)}', " + // Written_For_Item_Version $"'{RandomData.Bit()}', " + // Script_Status $"'{RandomData.Date(2019)}', " + // Prescription_Expiration_Date $"'{docId}', " + // Responsible_Prescriber_ID $"NULL, " + // Discontinue_Date $"'{RandomData.Double(10)}', " + // Quantity_Written $"'{RandomData.Double(10)}', " + // Total_Qty_Used $"'{RandomData.Double(10)}', " + // Total_Qty_Authorized $"'{daysSupply}', " + // Days_Supply_Written $"'{daysRemaining}', " + // Days_Supply_Remaining $"'{RandomData.TrimString(3).ToUpper()}', " + // Script_Origin_Indicater $"DEFAULT);"; // MSSQLTS motSqlServer.ExecuteNonQuery(sql); // Rx Note sql = $"INSERT INTO dbo.vRxNote VALUES(" + $"'{scripId}', " + $"'{RandomData.Integer()}', " + $"'{RandomData.TrimString(10).ToUpper()}', " + $"'{RandomData.TrimString(30).ToUpper()}', " + $"'{DateTime.Now}', " + $"'{RandomData.String(512)}');"; motSqlServer.ExecuteNonQuery(sql); } } } catch (Exception ex) { Console.WriteLine(ex.Message); throw; } }
public PollDrug(MotSqlServer db, Mutex mutex, string gatewayIp, int gatewayPort) : base(db, mutex, gatewayIp, gatewayPort) { _drug = new MotDrugRecord("Add"); _drug.UseAscii = UseAscii; }
public PollPrescriber(MotSqlServer db, Mutex mutex, string gatewayIp, int gatewayPort) : base(db, mutex, gatewayIp, gatewayPort) { _prescriber = new MotPrescriberRecord("Add"); _prescriber.UseAscii = UseAscii; }
public PollStore(MotSqlServer db, Mutex mutex, string gatewayIp, int gatewayPort) : base(db, mutex, gatewayIp, gatewayPort) { _store = new MotStoreRecord("Add"); }