private void button1_Click(object sender, EventArgs e) { string username = textBox2.Text.ToString().Trim(); string password = textBox3.Text.ToString().Trim(); string server = ComboBox1.Text.ToString().Trim(); string keyspace = "demo"; this.Cluster = null; if (!String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(password) && !String.IsNullOrEmpty(server) && !String.IsNullOrEmpty(keyspace)) { this.Cluster = new ClusterInfo(username, password, server, keyspace); this.DialogResult = DialogResult.OK; } }
public static Dictionary <string, PatientRecord> GetRecordFromCluster(ClusterInfo cluster) { Dictionary <string, PatientRecord> result = new Dictionary <string, PatientRecord>(); Comm comm = new Comm(cluster.username, cluster.password, cluster.server, cluster.keyspace); comm.Connect(); ISession session = comm.GetSession(); string queryString = "SELECT key, firstName, lastName, gender, date_of_birth, phone_no, address, xray_image_len, mri_image_len, diagnosis_pdf_len, date, comment FROM patient_record"; PreparedStatement preparedStatement = session.Prepare(queryString); BoundStatement boundStatement = preparedStatement.Bind(); RowSet cursors = session.Execute(boundStatement); string key = ""; PatientRecord record = new PatientRecord(); foreach (Row row in cursors) { key = row[0].ToString(); record.FirstName = row[1].ToString(); record.LastName = row[2].ToString(); record.Gender = (GenderType)row[3]; record.DateOfBirth = DateTime.Parse(row[4].ToString()); record.Telephone = row[5].ToString(); record.Address = row[6].ToString(); record.XrayImageContentLen = (int)row[7]; record.MRIImageContentLen = (int)row[8]; record.DiagnosisPDFContentLen = (int)row[9]; record.Date = DateTime.Parse(row[10].ToString()); record.Comments = row[11].ToString(); result.Add(key, record); } comm.Close(); return(result); }
public void GenerateRecords(ClusterInfo cluster, int numebrOfRecords, System.Windows.Forms.ToolStripProgressBar bar) { Initialization(); int iteration = 0; int mc = 0; int fc = 0; Random rand = new Random(); PatientRecord record = new PatientRecord(); Comm comm = new Comm(cluster.username, cluster.password, cluster.server, cluster.keyspace); comm.Connect(); ISession session = comm.GetSession(); //Deleting existing data in the patient_record string truncateString = "truncate patient_record"; PreparedStatement ps = session.Prepare(truncateString); BoundStatement bs = ps.Bind(); session.Execute(bs); string basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); while (iteration < numebrOfRecords) { if ((fc >= 500) || (rand.Next(0, 2) == 0 && mc < 500)) { record.FirstName = MaleNames.ElementAt(mc).Item1; record.LastName = MaleNames.ElementAt(mc).Item2; record.Gender = GenderType.Male; mc++; } else { record.FirstName = FemaleNames.ElementAt(fc).Item1; record.LastName = FemaleNames.ElementAt(fc).Item2; record.Gender = GenderType.Femal; fc++; } record.DateOfBirth = GetRandomDOB(new DateTime(1950, 1, 1), DateTime.Today); record.Telephone = GetRandomTelNo(); record.Address = GetRandomAddress(); record.Date = DateTime.Now; record.Comments = "This is for future use."; string xray_path = Path.Combine(basePath, @"Resources\" + record.LastName + "_" + record.Telephone + "_xray" + ".png"); string mri_path = Path.Combine(basePath, @"Resources\" + record.LastName + "_" + record.Telephone + "_mri" + ".png"); string diagnosis_path = Path.Combine(basePath, @"Resources\" + record.LastName + "_" + record.Telephone + "_diagnosis" + ".pdf"); //Creating xray image DynamicImage(xray_path, record.GetString()); //Creating mri image DynamicImage(mri_path, record.GetString()); //Creating diagnosis pdf file var writer = new PdfWriter(diagnosis_path); var pdf = new PdfDocument(writer); var document = new Document(pdf); for (int k = 0; k < 5; k++) { document.Add(new Paragraph(record.GetString())); } document.Close(); record.XrayImageContent = ReadFile(xray_path); record.MRIImageContent = ReadFile(mri_path); record.DiagnosisPDFContent = ReadFile(diagnosis_path); string queryString = "INSERT INTO Patient_Record(key, firstName, lastName, gender, date_of_birth, phone_no, address, xray_image, xray_image_len, mri_image, mri_image_len, diagnosis_pdf, diagnosis_pdf_len, date, comment)" + " VALUES(now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; PreparedStatement preparedStatement = session.Prepare(queryString); BoundStatement boundStatement = preparedStatement.Bind( record.FirstName, record.LastName, (int)record.Gender, record.DateOfBirth.ToShortDateString(), record.Telephone, record.Address, record.XrayImageContent, record.XrayImageContent.Length, record.MRIImageContent, record.MRIImageContent.Length, record.DiagnosisPDFContent, record.DiagnosisPDFContent.Length, DateTime.Now.ToShortDateString(), record.Comments ); session.Execute(boundStatement); //delete creating files after storing in the database File.Delete(xray_path); File.Delete(mri_path); File.Delete(diagnosis_path); iteration++; bar.PerformStep(); } comm.Close(); bar.Visible = false; }
public static bool CompareRecords(ClusterInfo cluster1, ClusterInfo cluster2, ClusterInfo cluster3, System.Windows.Forms.ToolStripProgressBar bar) { if (cluster1 == null || cluster2 == null || cluster3 == null) { return(false); } bar.Value = 0; bar.Maximum = 4; bar.Step = 1; bar.Visible = true; bar.PerformStep(); Dictionary <string, PatientRecord> recordsCluster1 = GetRecordFromCluster(cluster1); bar.PerformStep(); Dictionary <string, PatientRecord> recordsCluster2 = GetRecordFromCluster(cluster2); bar.PerformStep(); Dictionary <string, PatientRecord> recordsCluster3 = GetRecordFromCluster(cluster3); if (recordsCluster1.Count() != recordsCluster2.Count() || recordsCluster2.Count() != recordsCluster3.Count()) { return(false); } string key = ""; PatientRecord record1, record2, record3; foreach (var item in recordsCluster1) { key = item.Key; record1 = item.Value; record2 = recordsCluster2[key]; record3 = recordsCluster3[key]; if (record2 == null || record3 == null) { return(false); } if (record1.Compare(record2) && record2.Compare(record3)) { continue; } else { bar.Visible = false; return(false); } } bar.PerformStep(); bar.Visible = false; return(true); }