public ActionResult DeleteConfirmed(int id) { BloodSample bloodSample = db.BloodSamples.Find(id); db.BloodSamples.Remove(bloodSample); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "BloodSampleId,BloodGroups,BloodQuentity,DonorId")] BloodSample bloodSample) { if (ModelState.IsValid) { db.Entry(bloodSample).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DonorId = new SelectList(db.Donors, "DonorId", "DonorName", bloodSample.DonorId); return(View(bloodSample)); }
// GET: BloodSamples/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BloodSample bloodSample = db.BloodSamples.Find(id); if (bloodSample == null) { return(HttpNotFound()); } return(View(bloodSample)); }
// GET: BloodSamples/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BloodSample bloodSample = db.BloodSamples.Find(id); if (bloodSample == null) { return(HttpNotFound()); } ViewBag.DonorId = new SelectList(db.Donors, "DonorId", "DonorName", bloodSample.DonorId); return(View(bloodSample)); }
public ActionResult Submit() { WorkOrderDataViewModel wodvm = (WorkOrderDataViewModel)Session["SavedWorkOrder"]; Employee employee = DB.Employees.FirstOrDefault(x => x.EmployeeId == wodvm.SupervisorId); Contractor contractor = employee.Contractor; WorkOrder workOrder = new WorkOrder(); workOrder.Contractor = contractor; workOrder.Issuer = employee; workOrder.Service = DB.Services.FirstOrDefault(x => x.ServiceId == wodvm.SelectedServiceId); workOrder.Name = workOrder.Service.ServiceTitle; workOrder.Nurse = DB.Employees.FirstOrDefault(x => x.EmployeeId == wodvm.SelectedNurseId); //workOrder.NurseReplacement = null; workOrder.Patient = DB.Patients.FirstOrDefault(x => x.PatientId == wodvm.PatientId); workOrder.DateCreated = wodvm.DateCreated; Visit visit = new Visit(); visit.Date = wodvm.DateTimeOfFirstVisit; visit.DateConfirmed = wodvm.DateTimeOfFirstVisit; visit.Mandatory = wodvm.MandatoryFirstVisit; visit.WorkOrder = workOrder; visit.Done = false; // Check for single or multiple visits. if (wodvm.MultipleVisits && wodvm.NumberOfVisits > 1) { int timeFrame = 1; bool mandatoryvisit = wodvm.MandatoryFirstVisit; if (wodvm.TimeType == WorkOrderViewModel.VisitTimeType.TimeFrame) { timeFrame = (wodvm.TimeFrame - wodvm.DateTimeOfFirstVisit).Days / (wodvm.NumberOfVisits - 1); mandatoryvisit = false; } else if (wodvm.TimeType == WorkOrderViewModel.VisitTimeType.TimeInterval) { timeFrame = wodvm.TimeInterval; } for (int i = 1; i < wodvm.NumberOfVisits; i++) { Visit vis = new Visit(); vis.Date = wodvm.DateTimeOfFirstVisit.AddDays(timeFrame * i); vis.DateConfirmed = wodvm.DateTimeOfFirstVisit.AddDays(timeFrame * i); vis.Mandatory = mandatoryvisit; vis.WorkOrder = workOrder; DB.Visits.Add(vis); } } // Get all used medicine if (wodvm.EnterMedicine) { List <Medicine> medicines = DB.Medicines.Where(x => wodvm.MedicineIds.Contains(x.MedicineId)).ToList(); foreach (var medicine in medicines) { MedicineWorkOrder medicineWorkOrder = new MedicineWorkOrder(); medicineWorkOrder.Medicine = medicine; medicineWorkOrder.WorkOrder = workOrder; DB.MedicineWorkOrders.Add(medicineWorkOrder); } } if (wodvm.EnterBloodSample) { BloodSample bloodSample = new BloodSample(); bloodSample.BloodVialBlueCount = wodvm.BloodVialBlueCount; bloodSample.BloodVialGreenCount = wodvm.BloodVialGreenCount; bloodSample.BloodVialRedCount = wodvm.BloodVialRedCount; bloodSample.BloodVialYellowCount = wodvm.BloodVialYellowCount; bloodSample.WorkOrder = workOrder; DB.BloodSamples.Add(bloodSample); } if (wodvm.EnterPatients) { foreach (var id in wodvm.PatientIds) { Patient patient = DB.Patients.FirstOrDefault(x => x.PatientId == id); if (patient != null) { PatientWorkOrder patientWorkOrder = new PatientWorkOrder(); patientWorkOrder.WorkOrder = workOrder; patientWorkOrder.Patient = patient; DB.PatientWorkOrders.Add(patientWorkOrder); } } } DB.WorkOrders.Add(workOrder); DB.Visits.Add(visit); DB.SaveChanges(); Session["SavedWorkOrder"] = null; Session["SavedWorkOrderSummary"] = null; return(RedirectToAction("Index", "Home")); }
public bool SubmitWorkOrder(WorkOrderViewModel wovm, int employeeId, ParsekPublicHealthNurseInformationSystem.Models.EntityDataModel DB) { int[] temp = Globals.GetIdsFromString(wovm.PatientId); Patient selectedPatient = temp.Length == 1 ? DB.Patients.FirstOrDefault(x => x.PatientId == temp.FirstOrDefault()) : null; if (selectedPatient == null || wovm.EnterPatients && wovm.PatientIds.IsNullOrWhiteSpace() || wovm.MultipleVisits && ( wovm.TimeType == 0 || wovm.NumberOfVisits < 1 || wovm.NumberOfVisits > 10 || wovm.TimeType == WorkOrderViewModel.VisitTimeType.TimeFrame && (wovm.TimeFrame > DateTime.Now.AddMonths(6) || wovm.TimeFrame < DateTime.Now || wovm.TimeFrame < wovm.DateTimeOfFirstVisit || (wovm.TimeFrame - wovm.DateTimeOfFirstVisit).Days < (wovm.NumberOfVisits - 1) ) || wovm.TimeType == WorkOrderViewModel.VisitTimeType.TimeInterval && (wovm.TimeInterval > 30 || wovm.TimeInterval < 1)) || wovm.EnterMedicine && wovm.MedicineIds.IsNullOrWhiteSpace() || wovm.EnterBloodSample && (wovm.BloodVialBlueCount < 0 || wovm.BloodVialBlueCount > 30 || wovm.BloodVialGreenCount < 0 || wovm.BloodVialGreenCount > 30 || wovm.BloodVialRedCount < 0 || wovm.BloodVialRedCount > 30 || wovm.BloodVialYellowCount < 0 || wovm.BloodVialYellowCount > 30) ) { return(false); } else { WorkOrderDataViewModel wodvm = new WorkOrderDataViewModel(); wodvm.SupervisorId = employeeId; wodvm.PatientId = selectedPatient.PatientId; wodvm.SelectedServiceId = wovm.SelectedServiceId; wodvm.DateTimeOfFirstVisit = wovm.DateTimeOfFirstVisit; wodvm.MandatoryFirstVisit = wovm.MandatoryFirstVisit; wodvm.NumberOfVisits = wovm.NumberOfVisits; wodvm.MultipleVisits = wovm.MultipleVisits; wodvm.TimeFrame = wovm.TimeFrame; wodvm.TimeInterval = wovm.TimeInterval; wodvm.TimeType = wovm.TimeType; wodvm.EnterMedicine = wovm.EnterMedicine; wodvm.EnterBloodSample = wovm.EnterBloodSample; wodvm.BloodVialBlueCount = wovm.EnterBloodSample ? wovm.BloodVialBlueCount : 0; wodvm.BloodVialGreenCount = wovm.EnterBloodSample ? wovm.BloodVialGreenCount : 0; wodvm.BloodVialRedCount = wovm.EnterBloodSample ? wovm.BloodVialRedCount : 0; wodvm.BloodVialYellowCount = wovm.EnterBloodSample ? wovm.BloodVialYellowCount : 0; wodvm.EnterPatients = wovm.EnterPatients; wodvm.DateCreated = wovm.DateCreated != DateTime.MinValue ? wovm.DateCreated : DateTime.Now; WorkOrderSummaryViewModel wosvm = new WorkOrderSummaryViewModel(); wosvm.Patient = selectedPatient.FullName; wosvm.Supervisor = DB.Employees.Find(employeeId).FullName; wosvm.ServiceTitle = DB.Services.FirstOrDefault(x => x.ServiceId == wovm.SelectedServiceId).ServiceTitle; wosvm.DateTimeOfFirstVisit = wovm.DateTimeOfFirstVisit; wosvm.MandatoryFirstVisit = wovm.MandatoryFirstVisit; wosvm.NumberOfVisits = wovm.NumberOfVisits; wosvm.MultipleVisits = wovm.MultipleVisits; wosvm.TimeFrame = wovm.TimeFrame; wosvm.TimeInterval = wovm.TimeInterval; wosvm.TimeType = wovm.TimeType; wosvm.EnterBloodSample = wovm.EnterBloodSample; wosvm.EnterMedicine = wovm.EnterMedicine; wosvm.EnterPatients = wovm.EnterPatients; wosvm.DateCreated = wodvm.DateCreated; if (wovm.EnterMedicine) { wodvm.MedicineIds = new List <int>(); wosvm.Medicine = new List <string>(); int[] medicineIds = Globals.GetIdsFromString(wovm.MedicineIds); foreach (var medicine in DB.Medicines.Where(x => medicineIds.Contains(x.MedicineId)).ToList()) { if (medicine != null) { wodvm.MedicineIds.Add(medicine.MedicineId); wosvm.Medicine.Add(medicine.FullName); } } } if (wovm.EnterBloodSample) { wosvm.BloodVialBlueCount = wovm.BloodVialBlueCount; wosvm.BloodVialGreenCount = wovm.BloodVialGreenCount; wosvm.BloodVialRedCount = wovm.BloodVialRedCount; wosvm.BloodVialYellowCount = wovm.BloodVialYellowCount; } if (wovm.EnterPatients) { wodvm.PatientIds = new List <int>(); wosvm.Patients = new List <string>(); int[] ids = Globals.GetIdsFromString(wovm.PatientIds); foreach (var id in ids) { Patient patient = DB.Patients.FirstOrDefault(x => x.PatientId == id); if (patient != null) { wodvm.PatientIds.Add(patient.PatientId); wosvm.Patients.Add(patient.FullName); } } } Employee selectedNurse = DB.Employees.FirstOrDefault(x => x.JobTitle.Title == JobTitle.HealthNurse && x.District.DistrictId == selectedPatient.District.DistrictId); if (selectedNurse == null) { wovm.ViewMessage = "Pacientov okoliš nima dodeljene patronažne sestre!"; return(false); } wodvm.SelectedNurseId = selectedNurse.EmployeeId; wosvm.Nurse = selectedNurse.FullName; Employee employee = DB.Employees.FirstOrDefault(x => x.EmployeeId == wodvm.SupervisorId); Contractor contractor = employee.Contractor; WorkOrder workOrder = new WorkOrder(); workOrder.Contractor = contractor; workOrder.Issuer = employee; workOrder.Service = DB.Services.FirstOrDefault(x => x.ServiceId == wodvm.SelectedServiceId); workOrder.Name = workOrder.Service.ServiceTitle; workOrder.Nurse = DB.Employees.FirstOrDefault(x => x.EmployeeId == wodvm.SelectedNurseId); //workOrder.NurseReplacement = null; workOrder.Patient = DB.Patients.FirstOrDefault(x => x.PatientId == wodvm.PatientId); workOrder.DateCreated = wodvm.DateCreated; Visit visit = new Visit(); visit.Date = wodvm.DateTimeOfFirstVisit; visit.DateConfirmed = wodvm.DateTimeOfFirstVisit; visit.Mandatory = wodvm.MandatoryFirstVisit; visit.WorkOrder = workOrder; visit.Done = false; // Check for single or multiple visits. if (wodvm.MultipleVisits && wodvm.NumberOfVisits > 1) { int timeFrame = 1; bool mandatoryvisit = wodvm.MandatoryFirstVisit; if (wodvm.TimeType == WorkOrderViewModel.VisitTimeType.TimeFrame) { timeFrame = (wodvm.TimeFrame - wodvm.DateTimeOfFirstVisit).Days / (wodvm.NumberOfVisits - 1); mandatoryvisit = false; } else if (wodvm.TimeType == WorkOrderViewModel.VisitTimeType.TimeInterval) { timeFrame = wodvm.TimeInterval; } for (int i = 1; i < wodvm.NumberOfVisits; i++) { Visit vis = new Visit(); vis.Date = wodvm.DateTimeOfFirstVisit.AddDays(timeFrame * i); vis.DateConfirmed = wodvm.DateTimeOfFirstVisit.AddDays(timeFrame * i); vis.Mandatory = mandatoryvisit; vis.WorkOrder = workOrder; DB.Visits.Add(vis); } } // Get all used medicine if (wodvm.EnterMedicine) { List <Medicine> medicines = DB.Medicines.Where(x => wodvm.MedicineIds.Contains(x.MedicineId)).ToList(); foreach (var medicine in medicines) { MedicineWorkOrder medicineWorkOrder = new MedicineWorkOrder(); medicineWorkOrder.Medicine = medicine; medicineWorkOrder.WorkOrder = workOrder; DB.MedicineWorkOrders.Add(medicineWorkOrder); } } if (wodvm.EnterBloodSample) { BloodSample bloodSample = new BloodSample(); bloodSample.BloodVialBlueCount = wodvm.BloodVialBlueCount; bloodSample.BloodVialGreenCount = wodvm.BloodVialGreenCount; bloodSample.BloodVialRedCount = wodvm.BloodVialRedCount; bloodSample.BloodVialYellowCount = wodvm.BloodVialYellowCount; bloodSample.WorkOrder = workOrder; DB.BloodSamples.Add(bloodSample); } if (wodvm.EnterPatients) { foreach (var id in wodvm.PatientIds) { Patient patient = DB.Patients.FirstOrDefault(x => x.PatientId == id); if (patient != null) { PatientWorkOrder patientWorkOrder = new PatientWorkOrder(); patientWorkOrder.WorkOrder = workOrder; patientWorkOrder.Patient = patient; DB.PatientWorkOrders.Add(patientWorkOrder); } } } DB.WorkOrders.Add(workOrder); DB.Visits.Add(visit); //DB.SaveChanges(); return(true); } }
public IHttpActionResult PutBloodSample(string userName, int id, BloodSample bloodSample) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != bloodSample.Id) { return BadRequest(); } _bloodSamplesRepository.UpdateBloodSample(bloodSample); try { _bloodSamplesRepository.Save(); } catch (DbUpdateConcurrencyException) { if (!BloodSampleExists(id)) { return NotFound(); } throw; } return StatusCode(HttpStatusCode.NoContent); }
public HttpResponseMessage PostListBloodSamples(string userName, List<ApiDto> bloodSamples) { if (!ModelState.IsValid) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } var user = _db.Users.SingleOrDefault(u => u.UserName == userName); foreach (var bloodSample in bloodSamples) { var actualBloodSample = new BloodSample { Data = bloodSample.Data, PinchDateTime = bloodSample.PinchDateTime, Tag = bloodSample.Tag, User = user }; _bloodSamplesRepository.InsertBloodSample(actualBloodSample); _bloodSamplesRepository.Save(); _bloodSamplesRepository.UpdateBloodSample(actualBloodSample); } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, $"Blood Samples added successfully into User {user.UserName}'s repository!"); return response; }
public void UpdateBloodSample(BloodSample bloodsample) { _context.Entry(bloodsample).State = EntityState.Modified; }
public void InsertBloodSample(BloodSample bloodSample) { _context.BloodSamples.Add(bloodSample); }