public void ForceIdOverflowWithGuid() { // This will force a record rejection bu issuing a Guid as an ID // Note that the motNext gatewaty returns a 6 (success) even though it fails var patientId1 = Guid.NewGuid().ToString(); var patientId2 = Guid.NewGuid().ToString(); var prescriberId = Guid.NewGuid().ToString(); var facilityId = Guid.NewGuid().ToString(); using (var localTcpClient = new TcpClient("localhost", 24042)) { using (var stream = localTcpClient.GetStream()) { try { var facility = new MotFacilityRecord("Add"); facility.LocationName = "Banzai Institute"; facility.LocationID = facilityId; facility.logRecords = logRecords; facility.Write(stream); var doc = new MotPrescriberRecord("Add") { PrescriberID = prescriberId, DEA_ID = "AD1234567", LastName = "Lizardo", FirstName = "Emillio" }; doc.Write(stream); using (var AddBuckaroo = new MotPatientRecord("Add")) { AddBuckaroo.PatientID = patientId1; AddBuckaroo.FirstName = "Buckaroo"; AddBuckaroo.LastName = "Banzai"; AddBuckaroo.PrimaryPrescriberID = prescriberId; AddBuckaroo.DOB = DateTime.Now; AddBuckaroo.CycleDate = DateTime.Now; AddBuckaroo.CycleDays = 30; AddBuckaroo.LocationID = facilityId; AddBuckaroo.logRecords = logRecords; AddBuckaroo.Write(stream); } var AddPenny = new MotPatientRecord("Add") { PatientID = patientId2, FirstName = "Penny", LastName = "Priddy", PrimaryPrescriberID = prescriberId, DOB = DateTime.Now, CycleDate = DateTime.Now, CycleDays = 30, LocationID = facilityId, logRecords = logRecords }; AddPenny.Write(stream); using (var deletePenny = new MotPatientRecord("Delete")) { deletePenny.PatientID = patientId2; deletePenny.Write(stream); } using (var deleteBuckaroo = new MotPatientRecord("Delete")) { deleteBuckaroo.PatientID = patientId1; deleteBuckaroo.Write(stream); } using (var deleteLizardo = new MotPrescriberRecord("Delete")) { deleteLizardo.PrescriberID = prescriberId; deleteLizardo.Write(stream); } using (var deleteFacility = new MotFacilityRecord("Delete")) { deleteFacility.LocationID = facilityId; deleteFacility.Write(stream); } } catch (Exception ex) { Assert.Fail(ex.Message); } } } }
public void CleanDatabase() { if (!StartCleaning) { Thread.Yield(); while (!StartCleaning) { Thread.Sleep(10000); } } try { OpenTestLogDb(); using (var gateway = new TcpClient(GatewayAddress, GatewayPort)) { using (var stream = gateway.GetStream()) { // Delete Rxs var RxList = GetTestLogRecords(RecordType.Prescription); foreach (var rx in RxList) { var RxToDelete = new MotPrescriptionRecord("Delete") { RxSys_RxNum = rx.Name }; RxToDelete.Write(stream); } // Delete Drugs var DrugList = GetTestLogRecords(RecordType.Drug); foreach (var drug in DrugList) { var DrugToDelete = new MotDrugRecord("Delete") { DrugID = drug.RecordId.ToString() }; DrugToDelete.Write(stream); } // Delete Patients var PatientList = GetTestLogRecords(RecordType.Patient); foreach (var patient in PatientList) { var PatientToDelete = new MotPatientRecord("Delete") { PatientID = patient.RecordId.ToString() }; PatientToDelete.Write(stream); } // Delete Facilities var FacilityList = GetTestLogRecords(RecordType.Facility); foreach (var facility in FacilityList) { var FacilityToDelete = new MotFacilityRecord("Delete") { LocationID = facility.RecordId.ToString() }; FacilityToDelete.Write(stream); } // Delete Prescribers var PrescriberList = GetTestLogRecords(RecordType.Prescriber); foreach (var prescriber in PrescriberList) { var PrescriberToDelete = new MotPrescriberRecord("Delete") { PrescriberID = prescriber.RecordId.ToString() }; PrescriberToDelete.Write(stream); } // Delete Stores if (!useLegacy) { var StoreList = GetTestLogRecords(RecordType.Store); foreach (var store in StoreList) { var StoreToDelete = new MotStoreRecord("Delete") { StoreID = store.RecordId.ToString() }; StoreToDelete.Write(stream); } } } } } catch (Exception ex) { Assert.Fail($"Failed to clean database: {ex.Message}"); } }
public void RandomDataCycle() { try { string StoreId = "1081"; OpenTestLogDb(); using (var gateway = new TcpClient(GatewayAddress, GatewayPort)) { using (var stream = gateway.GetStream()) { for (var s = 0; s < 3; s++) { if (!useLegacy) { var Store = new MotStoreRecord("Add") { AutoTruncate = AutoTruncate, logRecords = true, UseAscii = UseAscii, StoreID = Guid.NewGuid().ToString(), StoreName = $"{DateTime.Now.ToLongTimeString()}{RandomData.String()}", Address1 = RandomData.TrimString(), Address2 = RandomData.TrimString(), City = RandomData.TrimString(), State = "NH", Zipcode = $"{RandomData.Integer(0, 100000).ToString("D5")}-{RandomData.Integer(0, 100000).ToString("D4")}", DEANum = RandomData.ShortDEA(), Phone = RandomData.USPhoneNumber(), Fax = RandomData.USPhoneNumber() }; Store.Write(stream); WriteTestLogRecord(new TestRecord() { Id = Guid.NewGuid().ToString(), RecordId = new Guid(Store.StoreID).ToString(), RecordType = RecordType.Store, Name = Store.StoreName, TimeStamp = DateTime.UtcNow }); StoreId = Store.StoreID; } for (var i = 0; i < MaxLoops; i++) { var Facility = new MotFacilityRecord("Add") { AutoTruncate = AutoTruncate, logRecords = true, UseAscii = UseAscii, LocationID = Guid.NewGuid().ToString(), StoreID = StoreId, LocationName = RandomData.String(), Address1 = RandomData.TrimString(), Address2 = RandomData.TrimString(), City = RandomData.TrimString(), State = "NH", Zipcode = $"0{RandomData.Integer(1000, 10000)}", Phone = RandomData.USPhoneNumber(), CycleDays = RandomData.Integer(1, 32), CycleType = RandomData.Bit(), Comments = RandomData.String(2048) }; Facility.Write(stream); WriteTestLogRecord(new TestRecord() { Id = Guid.NewGuid().ToString(), RecordId = new Guid(Facility.LocationID).ToString(), RecordType = RecordType.Facility, Name = Facility.LocationName, TimeStamp = DateTime.UtcNow }); var Prescriber = new MotPrescriberRecord("Add") { AutoTruncate = AutoTruncate, logRecords = true, UseAscii = UseAscii, RxSys_DocID = Guid.NewGuid().ToString(), LastName = RandomData.TrimString(), FirstName = RandomData.TrimString(), MiddleInitial = RandomData.TrimString(1), Address1 = RandomData.TrimString(), Address2 = RandomData.TrimString(), City = RandomData.TrimString(), State = "NH", Zipcode = $"0{RandomData.Integer(1000, 10000)}", DEA_ID = RandomData.ShortDEA(), TPID = RandomData.Integer(100000).ToString(), Phone = RandomData.USPhoneNumber(), Comments = RandomData.String(2048), Fax = RandomData.USPhoneNumber() }; Prescriber.Write(stream); WriteTestLogRecord(new TestRecord() { Id = Guid.NewGuid().ToString(), RecordId = new Guid(Prescriber.PrescriberID).ToString(), RecordType = RecordType.Prescriber, Name = $"{Prescriber.LastName}, {Prescriber.FirstName}, {Prescriber.MiddleInitial}", TimeStamp = DateTime.UtcNow }); for (var f = 0; f < MaxLoops; f++) { var rxId = Guid.NewGuid().ToString(); var drugId = Guid.NewGuid().ToString(); var Patient = new MotPatientRecord("Add") { AutoTruncate = AutoTruncate, logRecords = true, UseAscii = UseAscii, PatientID = Guid.NewGuid().ToString(), LocationID = Facility.LocationID, PrimaryPrescriberID = Prescriber.PrescriberID, LastName = RandomData.TrimString(), FirstName = RandomData.TrimString(), MiddleInitial = RandomData.TrimString(1), Address1 = RandomData.TrimString(), Address2 = RandomData.TrimString(), City = RandomData.TrimString(), State = "NH", Zipcode = $"0{RandomData.Integer(1000, 10000)}", Gender = RandomData.TrimString(1), CycleDate = RandomData.Date(DateTime.Now.Year), CycleDays = RandomData.Integer(0, 32), CycleType = RandomData.Bit(), AdmitDate = RandomData.Date(), ChartOnly = RandomData.Bit().ToString(), Phone1 = RandomData.USPhoneNumber(), Phone2 = RandomData.USPhoneNumber(), WorkPhone = RandomData.USPhoneNumber(), DOB = RandomData.Date(), SSN = RandomData.SSN(), Allergies = RandomData.String(1024), Diet = RandomData.String(1024), DxNotes = RandomData.String(1024), InsName = RandomData.String(), InsPNo = RandomData.Integer().ToString(), AltInsName = RandomData.String(), AltInsPNo = RandomData.Integer().ToString() }; Patient.Write(stream); WriteTestLogRecord(new TestRecord() { Id = Guid.NewGuid().ToString(), RecordId = new Guid(Patient.PatientID).ToString(), RecordType = RecordType.Patient, Name = $"{Patient.LastName}, {Patient.FirstName}, {Patient.MiddleInitial}", TimeStamp = DateTime.UtcNow }); for (var rx = 0; rx < 8; rx++) { var Drug = new MotDrugRecord("Add") { AutoTruncate = AutoTruncate, logRecords = true, UseAscii = UseAscii, DrugID = Guid.NewGuid().ToString(), DrugName = RandomData.TrimString(), NDCNum = RandomData.TrimString().ToUpper(), ProductCode = RandomData.TrimString().ToUpper(), LabelCode = RandomData.TrimString().ToUpper(), TradeName = RandomData.TrimString(), DrugSchedule = RandomData.Integer(2, 8), Strength = RandomData.Double(100), Route = RandomData.TrimString(), RxOTC = RandomData.Bit() == 1 ? "R" : "O", VisualDescription = $"{RandomData.TrimString(3)}/{RandomData.TrimString(3)}/{RandomData.TrimString(3)}", DoseForm = RandomData.TrimString(), DefaultIsolate = RandomData.Bit(), ShortName = RandomData.TrimString(), ConsultMsg = RandomData.String() }; WriteTestLogRecord(new TestRecord() { Id = Guid.NewGuid().ToString(), RecordId = new Guid(Drug.DrugID).ToString(), RecordType = RecordType.Drug, Name = $"{Drug.TradeName}", TimeStamp = DateTime.UtcNow }); Drug.Write(stream); var Rx = new MotPrescriptionRecord("Add") { AutoTruncate = AutoTruncate, logRecords = true, UseAscii = UseAscii, PatientID = Patient.PatientID, PrescriberID = Prescriber.PrescriberID, DrugID = Drug.DrugID, RxSys_RxNum = RandomData.Integer(1, 1000000000).ToString(), RxStartDate = RandomData.Date(DateTime.Now.Year), RxStopDate = RandomData.Date(DateTime.Now.Year), DoseScheduleName = RandomData.TrimString().ToUpper(), QtyPerDose = RandomData.Double(10), QtyDispensed = RandomData.Integer(1, 120), RxType = RandomData.Integer(1, 21), DoseTimesQtys = RandomData.DoseTimes(RandomData.Integer(1, 25)), Isolate = RandomData.Bit().ToString(), Refills = RandomData.Integer(1, 100), Sig = RandomData.String() }; WriteTestLogRecord(new TestRecord() { Id = Guid.NewGuid().ToString(), RecordId = Guid.NewGuid().ToString(), RecordType = RecordType.Prescription, Name = $"{Rx.RxSys_RxNum}", TimeStamp = DateTime.UtcNow }); Rx.Write(stream); } } } } } } CloseTestLogDb(); } catch (Exception ex) { Assert.Fail(ex.Message); } finally { StartCleaning = true; } }
public void ReadPatientRecords() { try { // Load the translaton table -- Database Column Name to Gateway Tag Name TranslationTable.Add("Patient_ID", "RxSys_PatID"); TranslationTable.Add("Patient_Location_Code", "RxSys_LocID"); TranslationTable.Add("Primary_Prescriber_ID", "RxSys_PrimaryDoc"); 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", "Address1"); TranslationTable.Add("City", "City"); TranslationTable.Add("State_Code", "State"); TranslationTable.Add("Zip_Code", "Zip"); TranslationTable.Add("Zip_Plus_4", "Zip_Plus_4"); TranslationTable.Add("Telephone_Number", "Phone1"); TranslationTable.Add("Area_Code", "AreaCode"); TranslationTable.Add("Extension", "WorkPhone"); TranslationTable.Add("SSN", "SSN"); TranslationTable.Add("Birth_Date", "DOB"); // SqlDateTime TranslationTable.Add("Deceased_Date", "Comments"); // SqlDateTime TranslationTable.Add("Sex", "Gender"); // Search for the patient // Load Patient Record // Search for vPatientAlergyc by Patient_ID - returns {0...1} records // Update Patient Record // Search for vPatientDiagnosis by Patient_ID - returns {0...1} records // Update Patient Record // Search for vPatientNote by Patient_ID - returns {0...1} records // Update Patient Record // Write Patient Record var tmpPhone = string.Empty; var tmpZip = string.Empty; var patientId = string.Empty; var recordSet = Db.ExecuteQuery($"SELECT * FROM vPatient WHERE MSSQLTS > '{LastTouch}';"); 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 "Patient_ID": patientId = val; break; // 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; case "Birth_Date": val = NormalizeDate(val); break; default: break; } _patient.SetField(tag, val, true); } // Now get the note fields GetAllergies(patientId); GetDiagnosis(patientId); GetNotes(patientId); // Finally, write the recort to the Gateway try { Mutex.WaitOne(); using (var gw = new TcpClient(GatewayIp, GatewayPort)) { using (var stream = gw.GetStream()) { _patient.Write(stream); } } Mutex.ReleaseMutex(); } catch (Exception ex) { EventLogger.Error($"Failed reading patient record: {ex.Message}"); throw; } finally { Mutex.ReleaseMutex(); } _patient.Clear(); } } } } catch (Exception ex) { throw new Exception($"Failed to get Patient Record {ex.Message}"); } }