public ActionResult Index(int? id)
        {
            var viewModel = new CreatePostViewModel();

            if(id.HasValue)
            {
                var post = db.Events.Single(x => x.ID == id.Value);
                viewModel = Mapper.Map<CreatePostViewModel>(post);

                var anesthetics = post.AnestheticRegime.Split(',').ToDictionary(x => x.Split(':')[0], x => x.Split(':')[1]);
                foreach(var anes in anesthetics)
                {
                    switch(anes.Key)
                    {
                        case "TIVA":
                            viewModel.TIVA = true;
                            viewModel.TIVATypeRate = anes.Value;
                            break;
                        case "Inhalational Agent":
                            viewModel.InhalationalAgent = true;
                            viewModel.InhalAgentTypeAmt = anes.Value;
                            break;
                        case "Infusion":
                            viewModel.Infusion = true;
                            viewModel.InfusionTypeRate = anes.Value;
                            break;
                        case "NMB":
                            viewModel.NMB = true;
                            viewModel.NMBTypeAmt = anes.Value;
                            break;
                        case "Other":
                            viewModel.Other = true;
                            viewModel.OtherExplanation = anes.Value;
                            break;
                    }
                }
            }
            var procedures = db.Procedures.ToList();
            ViewData["ProcedureList"] = procedures.Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.Procedure }).ToList();

            var interpphysicians = db.InterpretingPhysicians.ToList();
            ViewData["InterpPhysicianList"] = interpphysicians.Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.InterpPhysician1 }).ToList();

            var technologists = db.Techs.ToList();
            ViewData["TechList"] = technologists.Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.Technician }).ToList();

            var equipment = db.Equipment.ToList();
            ViewData["EquipmentList"] = equipment.Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.Equipment1 }).ToList();
            return View(viewModel);

        }
        public JsonResult Submit(CreatePostViewModel patient)
        {

            if (patient != null)
            {
                var e = new Events();

                e.PatientID = patient.PatientID;
                e.PtLastName = patient.PtLastName;
                e.PtFirstName = patient.PtFirstName;
                e.Sex = patient.Sex;
                e.Age = patient.Age;
                e.DateofSurgery = patient.DateofSurgery;
                e.Region = patient.Region;
                e.Hospital = patient.Hospital;
                e.Surgeon = patient.Surgeon;
                e.Procedure = patient.Procedure;
                e.InterpPhysician = patient.InterpPhysician;
                e.Technologist = patient.Technologist;
                e.Equipment = patient.Equipment;
                e.Diagnosis = patient.Diagnosis;
                e.PreopSymptoms = patient.PreopSymptoms;
                e.Anesthesiologist = patient.Anesthesiologist;
                e.AnestheticRegime = CreateAnestheticRegime(patient);
                e.PostType = patient.PostType;
                e.SurgicalEvent = patient.SurgicalEvent;
                e.EventDetails = patient.EventDetails;
                e.EventModality1 = patient.EventModality1;
                e.EventModality2 = patient.EventModality2;
                e.IntraopFindings = patient.IntraopFindings;
                e.Troubleshooting = patient.Troubleshooting;
                e.IntraopInterven = patient.IntraopInterven;
                e.Outcome = patient.Outcome;
                e.PostOpFindings = patient.PostOpFindings;
                e.Status = (int)Status.Submitted;
                db.Events.Add(e);
                db.SaveChanges();
            }

            return Json(patient);

        }
        private string CreateAnestheticRegime(CreatePostViewModel patient)
        {
            var anesregime = string.Empty;
            var delimter = string.Empty;

            if (patient.TIVA)
            {
                anesregime += "TIVA";

                if (!string.IsNullOrEmpty(patient.TIVATypeRate))

                    anesregime += ": " + patient.TIVATypeRate;

                delimter = ",";      
            }

            if (patient.InhalationalAgent)
            {
                anesregime += delimter + "Inhalational Agent";

                if (!string.IsNullOrEmpty(patient.InhalAgentTypeAmt))

                    anesregime += ": " + patient.InhalAgentTypeAmt;

                delimter = ",";
            }

            if (patient.Infusion)
            {
                anesregime += delimter + "Infusion";

                if (!string.IsNullOrEmpty(patient.InfusionTypeRate))

                    anesregime += ": " + patient.InfusionTypeRate;

                delimter = ",";
            }

            if (patient.NMB)
            {
                anesregime += delimter + "NMB";

                if (!string.IsNullOrEmpty(patient.NMBTypeAmt))

                    anesregime += ": " + patient.NMBTypeAmt;

                delimter = ",";
            }

            if (patient.Other)
            {
                anesregime += delimter + "Other";

                if (!string.IsNullOrEmpty(patient.OtherExplanation))

                    anesregime += ": " + patient.OtherExplanation;

                delimter = ",";
            }

            return anesregime;

        }