public async Task <IActionResult> Create([Bind("ClaimID,PatientID,InsProviderID,AmountOwed,ClaimStatus")] Claim claim) { try { if (ModelState.IsValid) { _context.Add(claim); await _context.SaveChangesAsync(); //return RedirectToAction(nameof(Index)); return(RedirectToAction("Details", "Patients", new { id = claim.PatientID })); } } //ViewData["InsProviderID"] = new SelectList(_context.InsProviders, "InsProviderID", "InsProviderID", claim.InsProviderID); //ViewData["PatientID"] = new SelectList(_context.Patients, "ID", "FirstMidName", claim.PatientID); catch (DbUpdateException /* ex */) { Console.Write(claim); //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(claim)); //return RedirectToAction("Details", "Patients", new { id = 3 }); }
// SECURITY: Bind limits the properties that can be set to prevent hacks from adding their own. public async Task <IActionResult> Create([Bind("LastName,FirstMidName,CreatedDate")] Patient patient) { try { if (ModelState.IsValid) { _context.Add(patient); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(patient)); }
public async Task <IActionResult> Upload(string p) { List <Patient> patt = new List <Patient>(); List <string> Id = new List <string>(); List <string> FirstName = new List <string>(); List <string> LastName = new List <string>(); List <string> Address = new List <string>(); List <string> City = new List <string>(); List <string> State = new List <string>(); List <string> ZipCode = new List <string>(); List <string> DateOfBirth = new List <string>(); List <string> Gender = new List <string>(); var path = @"" + p; // PatientContext context = new PatientContext(); // patientsController pC = new patientsController(context); try { using (var reader = new StreamReader(path)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); var values = line.Split(','); Id.Add(values[0]); FirstName.Add(values[1]); LastName.Add(values[2]); DateOfBirth.Add(values[3]); Gender.Add(values[4]); Address.Add(values[5]); City.Add(values[6]); State.Add(values[7]); ZipCode.Add(values[8]); } } for (int i = 1; i < Id.Count; i++) { int alpha = Convert.ToInt32(Id[i]); Patient nP = new Patient(alpha, FirstName[i], LastName[i], DateOfBirth[i], Gender[i], Address[i], City[i], State[i], ZipCode[i]); patt.Add(nP); //_context.Add(nP); //_context.SaveChanges(); } } catch { //return NotFound("Path Failure"); return(NotFound(path)); } if (patt.Count() > 0) { for (int i = 0; i < patt.Count; i++) { _context.Add(patt[i]); } await _context.SaveChangesAsync(); return(NotFound("Finished")); } else { return(NotFound("Failure")); } }
public IActionResult Post([FromBody] AddPatientReq addPatientReq) { // Validate user var user = patientContext.User.Where(u => u.Name == addPatientReq.User).FirstOrDefault(); if (user == null) { return(BadRequest(string.Format("Invalid user-{0}", addPatientReq.User))); } // Basic validations on request bool basicValidationFlag = true; String basicErrors = ""; basicValidationFlag &= Validate.ForenameValid(addPatientReq.ForeName, ref basicErrors); basicValidationFlag &= Validate.SurnameValid(addPatientReq.Surname, ref basicErrors); basicValidationFlag &= Validate.PhoneValid(addPatientReq.PrimaryContactNumber, ref basicErrors); basicValidationFlag &= Validate.AddressLine1Valid(addPatientReq.PrimaryAddressLine1, ref basicErrors); basicValidationFlag &= Validate.PostcodeValid(addPatientReq.PostCode, ref basicErrors); if (basicValidationFlag == false) { return(BadRequest(basicErrors)); } // Validate patient is not in the DB. For the purpose of the exercise assume that Forname, Surname and DateOfBirth is all that is needed to uniquely identify a patient. // Clearly not var checkPatient = patientContext.Patient.Where(p => p.Forename == addPatientReq.ForeName && p.Surname == addPatientReq.Surname && p.DateOfBirth == addPatientReq.DateOfBirth).FirstOrDefault(); if (checkPatient != null) { return(BadRequest(string.Format("Patient already in database. Forename: {0}, Surname: {1}, DOB: {2:yyyy-MM-dd}", addPatientReq.ForeName, addPatientReq.Surname, addPatientReq.DateOfBirth))); } var address = patientContext.Address.Where(adr => adr.Line1 == addPatientReq.PrimaryAddressLine1 && adr.PostCode == addPatientReq.PostCode).FirstOrDefault(); bool addAddress = false; if (address == null) { address = new Address { Id = Guid.NewGuid(), Line1 = addPatientReq.PrimaryAddressLine1, Line2 = addPatientReq.PrimaryAddressLine2, Line3 = addPatientReq.PrimaryAddressLine3, PostCode = addPatientReq.PostCode }; addAddress = true; } var phone = patientContext.Phone.Where(ph => ph.Number == addPatientReq.PrimaryContactNumber).FirstOrDefault(); bool addPhone = false; if (phone == null) { phone = new Phone { Id = Guid.NewGuid(), Number = addPatientReq.PrimaryContactNumber }; addPhone = true; } // Now add the database rows as required var newPatient = new Patient { Id = Guid.NewGuid(), Forename = addPatientReq.ForeName, Surname = addPatientReq.Surname, DateOfBirth = addPatientReq.DateOfBirth, PrimaryContactPhoneID = phone.Id, PrimaryAddressId = address.Id }; patientContext.Add <Patient>(newPatient); if (addAddress == true) { patientContext.Add <Address>(address); } if (addPhone == true) { patientContext.Add <Phone>(phone); } // Audit Log record AuditLog auditRecord = new AuditLog { UserId = user.Id, PatientID = newPatient.Id, DateTime = DateTimeOffset.Now, Type = "Add", Notes = string.Format("Forename: {0}, Surname: {1}, DOB: {2:yyyy-MM-dd}", newPatient.Forename, newPatient.Surname, newPatient.DateOfBirth) }; patientContext.Add <AuditLog>(auditRecord); // Finally commit the changes patientContext.SaveChanges(); return(Ok(string.Format("Added - Forename: {0}, Surname: {1}, DOB: {2:yyyy-MM-dd}", newPatient.Forename, newPatient.Surname, newPatient.DateOfBirth))); }