public void InsertPat(PatBasicInfor pat, string PID, string HID,string User) { try { pat.Id = System.Guid.NewGuid().ToString().Replace("-", ""); pat.DoctorAccountId = 1; PatPhysicalExam pexam = new PatPhysicalExam(); // pexam.Id = 1; //pexam.PatBasicInforId = pat.Id; pat.PatPhysicalExam = pexam; PatDisease pdisease = new PatDisease(); // pdisease.Id = 1; pdisease.PatBasicInforId = pat.Id; pat.PatDisease = pdisease; VisitRecord r = new VisitRecord(); r.PatBasicInforId = pat.Id; r.HospitalID = HID; r.OutpatientID = PID; r.VisitRecordID = "1"; r.VisitDate = DateTime.Now.Date; pat.VisitRecord.Add(r); //context.PatBasicInforSet.Add(pat); var students = from s in context.DoctorAccountSet.ToList() select s; DoctorAccount student = students.Where(s => s.UserName == User).FirstOrDefault(); student.PatBasicInfor.Add(pat); context.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } }
public ActionResult Index(PatBasicInfor pat) { PatOperation pto = new PatOperation(); string HID = Request.Form["住院号"]; string PID = Request.Form["门诊号"]; if (string.IsNullOrEmpty(pat.Name) || string.IsNullOrEmpty(pat.Sex) || string.IsNullOrEmpty(pat.Age) || string.IsNullOrEmpty(pat.Education) || string.IsNullOrEmpty(pat.Phone) || string.IsNullOrEmpty(pat.FamilyMember) || string.IsNullOrEmpty(pat.ChiefDoctor)) { ModelState.AddModelError("", "输入项不能为空"); } else { Regex reg = new Regex("^[0-9]+$"); Match ma1 = reg.Match(pat.Age); Match ma2 = reg.Match(pat.Phone); if (ma1.Success && ma2.Success) { } else { ModelState.AddModelError("", "手机和年龄必须为数字"); } } if (ModelState.IsValid) { string user; user = HttpContext.Request.Cookies["username"].Value.ToString(); pto.InsertPat(pat, HID, PID,user); return RedirectToAction("Index", "Diagnosis", new { ID = pat.Id }); } else { return View(); } // return Redirect("/Diagnosis/Index/"+pat.Id); }