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; }