public IEnumerable <FluidBalance> GetFluidBalanceList(int Mrn) { SqlDataReader reader = null; // The SQL query to be sent to the server string query = "SELECT * FROM PatientFluidBalance WHERE MRN = '@Mrn'"; //Replace @Mrn with the requested patient's MRN query = query.Replace("@Mrn", Convert.ToString(Mrn)); // Establish connection with the SQL server SqlConnection connection = new SqlConnection(ConnectionString); connection.Open(); // Open the connection to the server using (SqlCommand command = new SqlCommand(query, connection)) { // Assign the SQL query and connection details to the reader reader = command.ExecuteReader(); // Create a new list of Falls Risk forms that will contain data from server List <FluidBalance> qresults = new List <FluidBalance>(); // Read the data from the server to the List of Falls Risk forms "qresults" // row by row while (reader.Read()) { FluidBalance qr = new FluidBalance(); qr.Mrn = reader["MRN"].ToString(); qr.DateOfScreening = reader["DateAndTimeOfScreening"].ToString(); qr.LineA = reader["LineA"].ToString(); qr.VolA = Convert.ToInt32(reader["VolA"].ToString()); qr.LineB = reader["LineB"].ToString(); qr.VolB = Convert.ToInt32(reader["VolB"].ToString()); qr.LineC = reader["LineC"].ToString(); qr.VolC = Convert.ToInt32(reader["VolC"].ToString()); qr.PTotal = Convert.ToInt32(reader["PTotal"].ToString()); qr.oral = Convert.ToInt32(reader["oral"].ToString()); qr.enteral = Convert.ToInt32(reader["enteral"].ToString()); qr.OEtotal = Convert.ToInt32(reader["OEtotal"].ToString()); qr.XTotal = Convert.ToInt32(reader["XTotal"].ToString()); qr.Urine = Convert.ToInt32(reader["Urine"].ToString()); qr.Vomitus = Convert.ToInt32(reader["Vomitus"].ToString()); qr.Drain1Site = reader["Drain1Site"].ToString(); qr.Drain1 = Convert.ToInt32(reader["Drain1"].ToString()); qr.Drain2Site = reader["Drain2Site"].ToString(); qr.Drain2 = Convert.ToInt32(reader["Drain2"].ToString()); qr.Faecal = Convert.ToInt32(reader["Faecal"].ToString()); qr.Ytotal = Convert.ToInt32(reader["Ytotal"].ToString()); qr.Total = Convert.ToInt32(reader["Total"].ToString()); qr.FallsRiskNurseID = reader["NurseID"].ToString(); qresults.Add(qr); } connection.Close(); // Close the connection to the server return(qresults); } }
public IEnumerable <FluidBalance> Get(int Mrn, string date) { string query = ""; SqlDataReader reader = null; string dateStart = date + "T00:00:00"; string dateEnd = date + "T23:59:00"; // Establish connection with the SQL server SqlConnection connection = new SqlConnection(ConnectionString); connection.Open(); // Open the connection to the server // Return single Falls Risk form for specific date and time // The SQL query to be sent to the server query = "SELECT * FROM PatientFluidBalance " + "WHERE MRN = '@Mrn' AND DateAndTimeOfScreening >= '@dateStart' " + "AND DateAndTimeOfScreening <= '@dateEnd'"; //Replace @Mrn with the requested patient's MRN query = query.Replace("@Mrn", Convert.ToString(Mrn)); //Replace @date with the requested Falls Risk Screening Date query = query.Replace("@dateStart", Convert.ToString(dateStart)); query = query.Replace("@dateEnd", Convert.ToString(dateEnd)); using (SqlCommand command = new SqlCommand(query, connection)) { // Assign the SQL query and connection details to the reader reader = command.ExecuteReader(); // Create a new FluidBalance that will contain data from server List <FluidBalance> qresults = new List <FluidBalance>(); // Read the data from the server to qresults while (reader.Read()) { FluidBalance qr = new FluidBalance(); qr.Mrn = reader["MRN"].ToString(); qr.DateOfScreening = reader["DateAndTimeOfScreening"].ToString().Remove(0, 10); qr.LineA = reader["LineA"].ToString(); qr.VolA = Convert.ToInt32(reader["VolA"].ToString()); qr.LineB = reader["LineB"].ToString(); qr.VolB = Convert.ToInt32(reader["VolB"].ToString()); qr.LineC = reader["LineC"].ToString(); qr.VolC = Convert.ToInt32(reader["VolC"].ToString()); qr.PTotal = Convert.ToInt32(reader["PTotal"].ToString()); qr.oral = Convert.ToInt32(reader["oral"].ToString()); qr.enteral = Convert.ToInt32(reader["enteral"].ToString()); qr.OEtotal = Convert.ToInt32(reader["OEtotal"].ToString()); qr.XTotal = Convert.ToInt32(reader["XTotal"].ToString()); qr.Urine = Convert.ToInt32(reader["Urine"].ToString()); qr.Vomitus = Convert.ToInt32(reader["Vomitus"].ToString()); qr.Drain1Site = reader["Drain1Site"].ToString(); qr.Drain1 = Convert.ToInt32(reader["Drain1"].ToString()); qr.Drain2Site = reader["Drain2Site"].ToString(); qr.Drain2 = Convert.ToInt32(reader["Drain2"].ToString()); qr.Faecal = Convert.ToInt32(reader["Faecal"].ToString()); qr.Ytotal = Convert.ToInt32(reader["Ytotal"].ToString()); qr.Total = Convert.ToInt32(reader["Total"].ToString()); qr.FallsRiskNurseID = reader["NurseID"].ToString(); qresults.Add(qr); } connection.Close(); // Close the connection to the server return(qresults); } }
public bool PostFluidBalance(FluidBalance form) { string query = ""; if (form == null) //Check if the form contains any data { return(false); } else { // The SQL query to be sent to the server query = "INSERT INTO PatientFluidBalance" + "( MRN, DateAndTimeOfScreening, LineA, VolA, LineB, VolB, LineC, VolC, PTotal, oral, enteral, OEtotal, XTotal, " + "Urine, Vomitus, Drain1Site, Drain1, Drain2Site, Drain2, Faecal, Ytotal, Total, NurseID)" + "VALUES " + "(@Mrn,'@DateOfScreening','@LineA',@VolA,'@LineB',@VolB,'@LineC',@VolC,@PTotal,@oral," + "@enteral,@OEtotal,@XTotal,@Urine,@Vomitus,'@Drain1Site',@Drain1,'@Drain2Site',@Drain2,@Faecal," + "@Ytotal,@Total,@FallsRiskNurseID);"; //Replace the values in the SQL query string with the data to be added to the server query = query.Replace("@Mrn", form.Mrn) .Replace("@DateOfScreening", form.DateOfScreening) .Replace("@LineA", form.LineA) .Replace("@VolA", Convert.ToString(form.VolA)) .Replace("@LineB", form.LineB) .Replace("@VolB", Convert.ToString(form.VolB)) .Replace("@LineC", form.LineC) .Replace("@VolC", Convert.ToString(form.VolC)) .Replace("@PTotal", Convert.ToString(form.PTotal)) .Replace("@oral", Convert.ToString(form.oral)) .Replace("@enteral", Convert.ToString(form.enteral)) .Replace("@OEtotal", Convert.ToString(form.OEtotal)) .Replace("@XTotal", Convert.ToString(form.XTotal)) .Replace("@Urine", Convert.ToString(form.Urine)) .Replace("@Vomitus", Convert.ToString(form.Vomitus)) .Replace("@Drain1Site", form.Drain1Site) .Replace("@Drain1", Convert.ToString(form.Drain1)) .Replace("@Drain2Site", form.Drain2Site) .Replace("@Drain2", Convert.ToString(form.Drain2)) .Replace("@Faecal", Convert.ToString(form.Faecal)) .Replace("@Ytotal", Convert.ToString(form.Ytotal)) .Replace("@Total", Convert.ToString(form.Total)) .Replace("@FallsRiskNurseID", form.FallsRiskNurseID); // Establish connection with the SQL server SqlConnection connection = new SqlConnection(ConnectionString); try { connection.Open(); // Open the connection to the server // Create the command to be sent to the server with the query and connection info SqlCommand command = new SqlCommand(query, connection); command.ExecuteNonQuery(); // Execute the command on the server command.Dispose(); connection.Close(); // Close the connection to the server return(true); } catch (Exception) { // If the command fails return false return(false); } } }