public void TestAddNewTreatmentRecord() { // arrange bool isValidTreatmentRecord = false; ITreatmentRecordManager treatmentRecordManager = new TreatmentRecordManager(_treatmentRecordAccessor); // act TreatmentRecord treatmentRecord1 = new TreatmentRecord() { TreatmentRecordID = 5, VetID = "vet120", AnimalID = 6, FormName = "Form Name", TreatmentDate = DateTime.Now.Date, TreatmentDescription = "This is a treatment description.", Notes = "These are notes. Blah Blah.", Reason = "Reason", Urgency = 2 }; isValidTreatmentRecord = treatmentRecordManager.AddNewTreatmentRecord(treatmentRecord1); // assert Assert.IsTrue(isValidTreatmentRecord); }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: Timothy Lickteig /// /// A data access method that uses a stored procedure to add a treatment record to the database. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="treatmentRecord"></param> /// <returns></returns> public int InsertTreatmentRecord(TreatmentRecord treatmentRecord) { int TreatmentRecordID = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_insert_treatment_record", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@VetID", treatmentRecord.VetID); cmd.Parameters.AddWithValue("@AnimalID", treatmentRecord.AnimalID); cmd.Parameters.AddWithValue("@FormName", treatmentRecord.FormName); cmd.Parameters.AddWithValue("@TreatmentDate", treatmentRecord.TreatmentDate); cmd.Parameters.AddWithValue("@TreatmentDescription", treatmentRecord.TreatmentDescription); cmd.Parameters.AddWithValue("@Notes", treatmentRecord.Notes); cmd.Parameters.AddWithValue("@Reason", treatmentRecord.Reason); cmd.Parameters.AddWithValue("@Urgency", treatmentRecord.Urgency); try { conn.Open(); TreatmentRecordID = cmd.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(TreatmentRecordID); }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: /// /// Fake to get a treatment record by name. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="treatmentRecordName"></param> /// <returns></returns> public TreatmentRecord GetTreatmentRecordByName(string treatmentRecordName) { TreatmentRecord _fakeReturnTreatmentRecord = new TreatmentRecord(); if (treatmentRecordName != null && treatmentRecordName != "") { _fakeReturnTreatmentRecord.VetID = "Valid VetID"; _fakeReturnTreatmentRecord.AnimalID = 3; _fakeReturnTreatmentRecord.FormName = "Valid Form Name"; _fakeReturnTreatmentRecord.TreatmentDate = DateTime.Parse("03/13/2021"); _fakeReturnTreatmentRecord.TreatmentDescription = "Valid Description"; _fakeReturnTreatmentRecord.Notes = "Valid Notes"; _fakeReturnTreatmentRecord.Reason = "Valid Reason"; _fakeReturnTreatmentRecord.Urgency = 2; return(_fakeReturnTreatmentRecord); } else { _fakeReturnTreatmentRecord.VetID = "Invalid VetID"; _fakeReturnTreatmentRecord.AnimalID = 3; _fakeReturnTreatmentRecord.FormName = "Invalid Form Name"; _fakeReturnTreatmentRecord.TreatmentDate = DateTime.Parse("03/13/2021"); _fakeReturnTreatmentRecord.TreatmentDescription = "Invalid Description"; _fakeReturnTreatmentRecord.Notes = "Invalid Notes"; _fakeReturnTreatmentRecord.Reason = "Invalid Reason"; _fakeReturnTreatmentRecord.Urgency = 2; return(_fakeReturnTreatmentRecord); } }
public ActionResult PatientSchedule(TreatmentViewModel record) { p_id += 1; TreatmentRecord tr = new TreatmentRecord(); tr.DoctorId = TempData["currentDoctorId"].ToString(); tr.PatientId = TempData["currentPatientId"].ToString(); tr.TreatmentPlanned = record.TreatmentRecord.TreatmentPlanned; tr.DiagnosisDetails = record.TreatmentRecord.DiagnosisDetails; tr.MedicinesPrescribed = record.TreatmentRecord.MedicinesPrescribed; tr.RevisitDate = record.TreatmentRecord.RevisitDate; string hospitalName = TempData["currentDoctorHospital"].ToString(); /*record.DoctorId = TempData["currentDoctorId"].ToString(); * record.PatientId = TempData["currentPatientId"].ToString();*/ tr.P_Id = hospitalName.Substring(0, 3).ToUpper() + p_id.ToString("0000"); db.TreatmentRecords.Add(tr); try { db.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); } return(View("AppointmentSuccess")); }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: /// /// Makes sure the data is deleted when clicked. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> private void btnRemoveTreatmentRecord_Click(object sender, RoutedEventArgs e) { TreatmentRecordVM selectedTreatmentRecordVM = (TreatmentRecordVM)dgTreatmentRecords.SelectedItem; TreatmentRecord selectedTreatmentRecord = _treatmentRecordManager.GetTreatmentRecordByName(selectedTreatmentRecordVM.FormName.ToString()); dgTreatmentRecords.ItemsSource = null; dgTreatmentRecords.ItemsSource = _treatmentRecordManager.RetrieveTreatmentRecords(); }
public TreatmentRecord Delete(int id) { TreatmentRecord treatmentRecord = _context.TreatmentRecords.Find(id); if (treatmentRecord != null) { _context.TreatmentRecords.Remove(treatmentRecord); _context.SaveChanges(); } return(treatmentRecord); }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: Timothy Lickteig /// /// Makes sure the data is submited when clicked. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> private void BtnSubmitTreatmentRecordAdd_Click(object sender, RoutedEventArgs e) { string treatmentDate = cndTreatmentDate.SelectedDate.ToString(); if (String.IsNullOrEmpty(txtFormName.Text)) { MessageBox.Show("Please enter the form name"); return; } if (String.IsNullOrEmpty(txtTreatmentDescription.Text)) { MessageBox.Show("Please enter the treatment description"); return; } if (String.IsNullOrEmpty(txtReason.Text)) { MessageBox.Show("Please enter the reason for the animal's treatment"); return; } if (String.IsNullOrEmpty(txtUrgency.Text)) { MessageBox.Show("Please enter the urgency for the animal's treatment"); return; } TreatmentRecord newTreatmentRecord = new TreatmentRecord(); newTreatmentRecord.VetID = txtVetID.Text; newTreatmentRecord.FormName = txtFormName.Text; newTreatmentRecord.TreatmentDescription = txtTreatmentDescription.Text; newTreatmentRecord.Notes = txtNotes.Text; newTreatmentRecord.Reason = txtReason.Text; newTreatmentRecord.TreatmentDate = cndTreatmentDate.DisplayDate; try { if (_treatmentRecordManager.AddNewTreatmentRecord(newTreatmentRecord)) { WPFErrorHandler.SuccessMessage("Animal Successfully Added"); canViewTreatmentRecords.Visibility = Visibility.Visible; canAddTreatmentRecord.Visibility = Visibility.Hidden; dgTreatmentRecords.Visibility = Visibility.Visible; refreshTreatmentRecordData(); } } catch (Exception ex) { WPFErrorHandler.ErrorMessage(ex.Message + "\n\n" + ex.InnerException.Message); canViewTreatmentRecords.Visibility = Visibility.Visible; canAddTreatmentRecord.Visibility = Visibility.Hidden; } }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: Timothy Lickteig /// /// Treatment Records to use in tests instead of real data. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="treatmentRecord"></param> /// <returns></returns> public int InsertTreatmentRecord(TreatmentRecord treatmentRecord) { try { treatmentRecords.Add(treatmentRecord); return(1); } catch { return(0); } }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: Timothy Lickteig /// /// A data access method that uses a stored procedure to select all treatment records in the database. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> public List <TreatmentRecord> SelectTreatmentRecords() { List <TreatmentRecord> treatmentRecords = new List <TreatmentRecord>(); var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_treatment_records"); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { var treatmentRecord = new TreatmentRecord(); treatmentRecord.TreatmentRecordID = reader.GetInt32(0); treatmentRecord.VetID = reader.GetString(1); treatmentRecord.AnimalID = reader.GetInt32(2); treatmentRecord.FormName = reader.GetString(3); if (reader.IsDBNull(4)) { treatmentRecord.TreatmentDate = DateTime.Parse("01/01/2020"); } else { treatmentRecord.TreatmentDate = reader.GetDateTime(4); } treatmentRecord.TreatmentDescription = reader.GetString(5); treatmentRecord.Notes = reader.GetString(6); treatmentRecord.Reason = reader.GetString(7); treatmentRecord.Urgency = reader.GetInt32(8); treatmentRecords.Add(treatmentRecord); } } reader.Close(); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(treatmentRecords); }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: Timothy Lickteig /// /// Logic method passes a treatment record object to the accessor method /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="treatmentRecord"></param> /// <returns></returns> public bool AddNewTreatmentRecord(TreatmentRecord treatmentRecord) { bool result = true; try { result = _treatmentRecordAccessor.InsertTreatmentRecord(treatmentRecord) > 0; } catch (Exception ex) { throw new ApplicationException("Treatment record not added.", ex); } return(result); }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: Timothy Lickteig /// /// Logic method that uses a TreatmentRecordAccessor method to get a treatment record. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> public TreatmentRecord GetTreatmentRecordByName(string treatmentRecordName) { TreatmentRecord result = null; try { result = _treatmentRecordAccessor.GetTreatmentRecordByName(treatmentRecordName); } catch (Exception ex) { throw ex; } return(result); }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: Timothy Lickteig /// /// A data access method that uses a stored procedure to update a treatment record in the database. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="newTreatmentRecord">Updated treatment record</param> /// <param name="oldTreatmentRecord">Record to be updated</param> public int UpdateTreatmentRecord(TreatmentRecord oldTreatmentRecord, TreatmentRecord newTreatmentRecord) { // Declare the variables int rows = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_update_treatment_record"); // Setup cmd object cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; // Add Parameters cmd.Parameters.Add("@TreatmentRecordID", SqlDbType.NVarChar); cmd.Parameters.Add("@VetID", SqlDbType.NVarChar); cmd.Parameters.Add("@AnimalID", SqlDbType.Int); cmd.Parameters.Add("@FormName", SqlDbType.NVarChar); cmd.Parameters.Add("@TreatmentDate", SqlDbType.Date); cmd.Parameters.Add("@TreatmentDescription", SqlDbType.NVarChar); cmd.Parameters.Add("@Notes", SqlDbType.NVarChar); cmd.Parameters.Add("@Reason", SqlDbType.NVarChar); cmd.Parameters.Add("@Urgency", SqlDbType.Int); // Set param values cmd.Parameters["@TreatmentRecordID"].Value = oldTreatmentRecord.TreatmentRecordID; cmd.Parameters["@VetID"].Value = newTreatmentRecord.VetID; cmd.Parameters["@AnimalID"].Value = newTreatmentRecord.AnimalID; cmd.Parameters["@FormName"].Value = newTreatmentRecord.FormName; cmd.Parameters["@TreatmentDate"].Value = newTreatmentRecord.TreatmentDate; cmd.Parameters["@TreatmentDescription"].Value = newTreatmentRecord.TreatmentDescription; cmd.Parameters["@Notes"].Value = newTreatmentRecord.Notes; cmd.Parameters["@Reason"].Value = newTreatmentRecord.Reason; cmd.Parameters["@Urgency"].Value = newTreatmentRecord.Urgency; // Try to execute query try { conn.Open(); rows = Convert.ToInt32(cmd.ExecuteScalar()); } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: /// /// Logic method edits a treatment record object from the accessor method /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="oldTreatmentRecord"></param> /// <param name="newTreatmentRecord"></param> /// <returns></returns> public int EditTreatmentRecord(TreatmentRecord oldTreatmentRecord, TreatmentRecord newTreatmentRecord) { int rows = 0; try { rows = _treatmentRecordAccessor.UpdateTreatmentRecord(oldTreatmentRecord, newTreatmentRecord); } catch (Exception ex) { throw ex; } return(rows); }
//public int GetCount() //{ // var details = (from record in _context.TreatmentRecords // select record.RecordId); // return details.Count(); //} public TreatmentRecordDTO AddTreatmentRecord(TreatmentRecordDTO treatmentRecordDTO) { var records = new TreatmentRecord() { PatientId = treatmentRecordDTO.PatientId, Hospitalid = treatmentRecordDTO.Hospitalid, Diseaseid = treatmentRecordDTO.Diseaseid, Treatmentid = treatmentRecordDTO.Treatmentid }; _context.TreatmentRecords.Add(records); _context.SaveChanges(); return(treatmentRecordDTO); }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: /// /// Makes sure the data can be edited when clicked. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> private void btnEditTreatmentRecord_Click(object sender, RoutedEventArgs e) { TreatmentRecord selectedTreatmentRecordVM = (TreatmentRecord)dgTreatmentRecords.SelectedItem; TreatmentRecord selectedTreatmentRecord = _treatmentRecordManager.GetTreatmentRecordByName(selectedTreatmentRecordVM.FormName.ToString()); canAddTreatmentRecord.Visibility = Visibility.Visible; txtVetID.Text = selectedTreatmentRecord.VetID.ToString(); txtAnimalID.Text = selectedTreatmentRecord.AnimalID.ToString(); txtFormName.Text = selectedTreatmentRecord.FormName.ToString(); cndTreatmentDate.DisplayDate = selectedTreatmentRecord.TreatmentDate; txtTreatmentDescription.Text = selectedTreatmentRecord.TreatmentDescription.ToString(); txtNotes.Text = selectedTreatmentRecord.Notes.ToString(); txtReason.Text = selectedTreatmentRecord.Reason.ToString(); txtUrgency.Text = selectedTreatmentRecord.Urgency.ToString(); BtnSubmitTreatmentRecordAdd.Visibility = Visibility.Hidden; btnAddTreatmentRecord.Visibility = Visibility.Hidden; dgTreatmentRecords.Visibility = Visibility.Hidden; btnRemoveTreatmentRecord.Visibility = Visibility.Hidden; btnEditTreatmentRecord.Visibility = Visibility.Hidden; }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: /// /// Update a Treatment Record in fake data. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> /// <param name="newTreatmentRecord"></param> /// <param name="oldTreatmentRecord"></param> public int UpdateTreatmentRecord(TreatmentRecord oldTreatmentRecord, TreatmentRecord newTreatmentRecord) { int rows = 0; int index = 0; foreach (TreatmentRecord tmpTreatmentRecord in treatmentRecords) { if (tmpTreatmentRecord.TreatmentRecordID == oldTreatmentRecord.TreatmentRecordID) { rows = 1; break; } index++; } if (rows == 1) { treatmentRecords[index] = newTreatmentRecord; } return(rows); }
/// <summary> /// Creator: Zoey McDonald /// Created: 3/2/2020 /// Approver: /// /// A data access method that uses a stored procedure to get a treatment record by name from the database. /// </summary> /// <remarks> /// Updater: /// Updated: /// Update: /// </remarks> public TreatmentRecord GetTreatmentRecordByName(string treatmentRecordName) { TreatmentRecord _treatmentRecord = null; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_select_treatment_record_by_name", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@FormName", treatmentRecordName); try { conn.Open(); var reader = cmd.ExecuteReader(); if (reader.Read()) { _treatmentRecord = new TreatmentRecord(); _treatmentRecord.FormName = treatmentRecordName; _treatmentRecord.VetID = reader.GetString(1); _treatmentRecord.AnimalID = reader.GetInt32(2); _treatmentRecord.TreatmentDate = reader.GetDateTime(4); _treatmentRecord.TreatmentDescription = reader.GetString(5); _treatmentRecord.Notes = reader.GetString(6); _treatmentRecord.Reason = reader.GetString(7); _treatmentRecord.Urgency = reader.GetInt32(8); } else { throw new ApplicationException("Volunteer Task Not found."); } reader.Close(); } catch (Exception ex) { throw ex; } return(_treatmentRecord); }