public JsonResult AddLocation() { try { Location loc = new Location(); loc.Department = Request.Form["Department"]; loc.RoomNumber = Request.Form["RoomNumber"]; loc.IsActive = true; LocationRepository locationRepo = new LocationRepository(); locationRepo.Add(loc); return Json(new { error = false, Id = loc.Id, Name = loc.Department }); } catch { return Json(new { error = true }); } }
/// <summary> /// Check in a patient /// </summary> /// <returns></returns> public JsonResult AddCheckIn() { try { //Get patient object int patientID = int.Parse(Request.Form["patientID"]); PatientRepository patientRepo = new PatientRepository(); var patient = patientRepo.Get(patientID); //Get Staff Object int staffId = int.Parse(Request.Form["staffID"]); UserRepository userRepo = new UserRepository(); var staff = userRepo.Get(staffId); //Get Location Object int locationId = int.Parse(Request.Form["locationID"]); LocationRepository locationRepo = new LocationRepository(); var location = locationRepo.Get(locationId); //Build Check In Object PatientCheckIn checkin = new PatientCheckIn(); checkin.Patient = patient; checkin.CheckInTime = DateTime.Now; checkin.PatientType = (PatientCheckinType)Enum.Parse(typeof(PatientCheckinType), Request.Form["patientType"]); checkin.AttendingStaff = staff; checkin.Location = location; checkin.IsActive = true; //Build Invoice Object Invoice invoice = new Invoice(); invoice.PatientCheckIn = checkin; checkin.Invoice = invoice; patient.PatientCheckIns.Add(checkin); new InvoiceRepository().Add(invoice); return Json(new { error = "false" }); } catch (Exception e) { return Json(new { error = "true", status = e.Message }); } }
public JsonResult AddSurgery() { try { //Repositories PatientRepository patientRepo = new PatientRepository(); UserRepository userRepo = new UserRepository(); LocationRepository locationRepo = new LocationRepository(); SurgeryStaffRepository ssRepo = new SurgeryStaffRepository(); //Build new objects Surgery surgery = new Surgery(); Note note = new Note(); //Get patient object int patientID = int.Parse(Request.Form["patientID"]); Patient patient = patientRepo.Get(patientID); //Get current open patient checkin var query = from checkin in patient.PatientCheckIns where checkin.CheckOutTime == DateTime.MinValue select checkin; PatientCheckIn openCheckIn = query.First<PatientCheckIn>(); surgery.Location = locationRepo.Get(int.Parse(Request.Form["theatreNumber"])); surgery.StartTime = DateTime.Parse(Request.Form["startTime"]); surgery.EndTime = DateTime.Parse(Request.Form["endTime"]); //Add to checkin openCheckIn.Surgeries.Add(surgery); surgery.CheckIn = openCheckIn; surgery.CaseType = (CaseType)Enum.Parse(typeof(CaseType), Request.Form["caseType"]); //Build Note User author = userRepo.Get(int.Parse(Request.Form["staffID"])); note.Author = author; note.Body = Request.Form["NoteBody"]; note.PatientCheckIns = openCheckIn; note.Title = ""; note.Type = NoteType.Surgery; note.IsActive = true; note.DateCreated = DateTime.Now; openCheckIn.Notes.Add(note); UnitOfWork.CurrentSession.Flush(); //Surgeon if (Request.Form["surgeon"] != "") { SurgeryStaff surgeon = new SurgeryStaff(); surgeon.Staff = userRepo.Get(int.Parse(Request.Form["surgeon"])); surgeon.Surgery = surgery; surgeon.Role = StaffRole.Surgeon; ssRepo.Add(surgeon); } //Surgeon Assistant if (Request.Form["surgeonAssistant"] != "") { SurgeryStaff surgeonAssistant = new SurgeryStaff(); surgeonAssistant.Staff = userRepo.Get(int.Parse(Request.Form["surgeonAssistant"])); surgeonAssistant.Surgery = surgery; surgeonAssistant.Role = StaffRole.SurgeonAssistant; ssRepo.Add(surgeonAssistant); } //Anaesthetist if (Request.Form["anaesthetist"] != "") { SurgeryStaff anaesthetist = new SurgeryStaff(); anaesthetist.Staff = userRepo.Get(int.Parse(Request.Form["anaesthetist"])); anaesthetist.Role = StaffRole.Anaesthetist; anaesthetist.Surgery = surgery; ssRepo.Add(anaesthetist); } //Anaesthetist Assistant if (Request.Form["anaesthetistAssistant"] != "") { SurgeryStaff anaesthetistAssistant = new SurgeryStaff(); anaesthetistAssistant.Staff = userRepo.Get(int.Parse(Request.Form["anaesthetistAssistant"])); anaesthetistAssistant.Role = StaffRole.AnaesthetistAssistant; anaesthetistAssistant.Surgery = surgery; ssRepo.Add(anaesthetistAssistant); } //Nurse if (Request.Form["nurse"] != "") { SurgeryStaff nurse = new SurgeryStaff(); nurse.Staff = userRepo.Get(int.Parse(Request.Form["nurse"])); nurse.Role = StaffRole.Nurse; nurse.Surgery = surgery; ssRepo.Add(nurse); } //Consultant if (Request.Form["consultant"] != "") { SurgeryStaff consultant = new SurgeryStaff(); consultant.Staff = userRepo.Get(int.Parse(Request.Form["consultant"])); consultant.Role = StaffRole.Consultant; consultant.Surgery = surgery; ssRepo.Add(consultant); } //Save Template if (Request.Form["NoteTitle"] != null) { TemplateRepository templateRepo = new TemplateRepository(); NoteTemplateRepository noteRepo = new NoteTemplateRepository(); NoteTemplateCategory noteCat = noteRepo.Get(2); Template template = new Template(); template.Title = Request.Form["NoteTitle"]; template.Staff = author; template.Body = note.Body; template.IsActive = true; template.NoteTemplateCategory = noteCat; templateRepo.Add(template); return Json(new { Id = template.Id, Name = template.Title, NoteBody = note.Body, error = "false" }); } return Json(new { error = "false" }); } catch (Exception e) { return Json(new { error = "true", status = e.Message }); } }
public JsonResult DeleteLocation() { try { LocationRepository locationRepo = new LocationRepository(); Location location = locationRepo.Get(int.Parse(Request.Form["Department"])); location.IsActive = false; return Json(new { error = false }); } catch { return Json(new { error = true }); } }