public ActionResult Create() { var dc = new DropdownManagementController(); var reqContent = new RequestContent { timeOpened = DateTime.Now }; ViewBag.RequestorTypes = new SelectList( dc.getEntries(Constants.DropdownTable.RequestorType), "id", "text"); ViewBag.Regions = new SelectList( dc.getEntries(Constants.DropdownTable.Region), "id", "text"); ViewBag.GenderOptions = new SelectList(Constants.genderOptions); return View(reqContent); }
public ActionResult NewQuestionResponse(String json) { // Don't want to load a partial with a Not Authorized message if (!Roles.IsUserInRole(Constants.Roles.REQUEST_EDITOR)) { return RedirectToAction("Index", "Home", new { status = Constants.URLStatus.NoRequestEditorRole }); } var dc = new DropdownManagementController(); QuestionResponseContent qrContent; if (String.IsNullOrEmpty(json)) { qrContent = new QuestionResponseContent(); } else { qrContent = new JavaScriptSerializer() .Deserialize<QuestionResponseContent>(json); } // Used to set dynamic model binding index ViewBag.Guid = HtmlPrefixScopeExtensions.CreateItemIndex( "questionResponseList"); ViewBag.QuestionTypes = new SelectList( dc.getEntries(Constants.DropdownTable.QuestionType), "id", "text"); ViewBag.TumourGroups = new SelectList( dc.getEntries(Constants.DropdownTable.TumourGroup), "id", "text"); ViewBag.Severitys = new SelectList(Constants.severityOptions); ViewBag.Consequences = new SelectList(Constants.consequenceOptions); return View("Partial/NewQuestionResponse", qrContent); }
public ActionResult GetMatchingKeywords(string id) { var dc = new DropdownManagementController(); return Json(dc.getMatchingKeywords(id), JsonRequestBehavior.AllowGet); }
public ActionResult Create(RequestContent reqContent) { var rmc = new RequestManagementController(); bool valid = ModelState.IsValid; if (reqContent.parentRequestID != null && !rmc.requestExists((long) reqContent.parentRequestID)) { ModelState.AddModelError("NonexistentParentRequest", "Parent Request ID must correspond to an existing request."); valid = false; } if (Request.Form["mark_as_complete"] != null) { foreach ( QuestionResponseContent qrContent in reqContent.questionResponseList) { if (String.IsNullOrEmpty(qrContent.question) || removeNewLinesAndTabs(qrContent.question).Equals("<br />") || String.IsNullOrEmpty(qrContent.response) || removeNewLinesAndTabs(qrContent.response).Equals("<br />") || qrContent.questionTypeID == null || qrContent.tumourGroupID == null || qrContent.timeSpent == null || qrContent.severity == null || qrContent.consequence == null || qrContent.keywords.Count < 1) { ModelState.AddModelError("IncompleteQuestion", "Questions must be completed before marking request as complete."); valid = false; break; } if (qrContent.keywords.Any(keyword => keyword.Length > 128)) { ModelState.AddModelError("KeywordTooLong", "Keywords must be less than 128 characters."); valid = false; } if (qrContent.referenceList.Any(refContent => String.IsNullOrEmpty(refContent.referenceString))) { ModelState.AddModelError("IncompleteReference", "References must be completed before marking request as complete."); valid = false; } } reqContent.timeClosed = DateTime.Now; reqContent.requestStatus = Constants.RequestStatus.Completed; } // Encode HTML in question responses // Replace null references with empty string foreach ( QuestionResponseContent qrContent in reqContent.questionResponseList) { if (!String.IsNullOrEmpty(qrContent.question)) { qrContent.question = HttpUtility.HtmlEncode( removeNewLinesAndTabs(qrContent.question)) .Replace("'", "'"); } if (!String.IsNullOrEmpty(qrContent.response)) { qrContent.response = HttpUtility.HtmlEncode( removeNewLinesAndTabs(qrContent.response)) .Replace("'", "'"); } if (!String.IsNullOrEmpty(qrContent.specialNotes)) { qrContent.specialNotes = HttpUtility.HtmlEncode( removeNewLinesAndTabs(qrContent.specialNotes)) .Replace("'", "'"); } foreach ( ReferenceContent refContent in qrContent.referenceList) { refContent.referenceString = refContent.referenceString == null ? "" : refContent.referenceString.Replace("\\", "\\\\"); } } if (!valid) { var dc = new DropdownManagementController(); ViewBag.RequestorTypes = new SelectList( dc.getEntries(Constants.DropdownTable.RequestorType), "id", "text"); ViewBag.Regions = new SelectList( dc.getEntries(Constants.DropdownTable.Region), "id", "text"); ViewBag.GenderOptions = new SelectList(Constants.genderOptions); return View(reqContent); } long reqId = rmc.create(reqContent); var uc = new UserManagementController(); UserProfile up = uc.getUserProfile(User.Identity.Name); var almc = new AuditLogManagementController(); almc.addEntry(reqId, up.UserId, Constants.AuditType.RequestCreation, reqContent.timeOpened); if (reqContent.requestStatus == Constants.RequestStatus.Completed && reqContent.timeClosed != null) { almc.addEntry(reqId, up.UserId, Constants.AuditType.RequestCompletion, (DateTime) reqContent.timeClosed); } if (Roles.IsUserInRole(Constants.Roles.VIEWER)) { return RedirectToAction("Details", "Request", new { id = reqId }); } return RedirectToAction("Index", "Home", new { status = Constants.URLStatus.SuccessfulCreate }); }
public ActionResult Edit(long id) { var rlc = new RequestLockManagementController(); var uc = new UserManagementController(); UserProfile up = uc.getUserProfile(User.Identity.Name); RequestLock rl = rlc.getRequestLock(id); if (rl == null) { rlc.addLock(id, up.UserId); } else if (rl.UserID != up.UserId) { // Locked to someone else, redirect return RedirectToAction("Index", "Home", new { status = Constants.URLStatus.AccessingLocked }); } var dc = new DropdownManagementController(); var rmc = new RequestManagementController(); RequestContent reqContent = rmc.getRequestDetails(id); if (reqContent.requestStatus == Constants.RequestStatus.Invalid) { // Invalid request, cannot edit return RedirectToAction("Index", "Home", new { status = Constants.URLStatus.EditingInvalid }); } ViewBag.RequestorTypes = new SelectList( dc.getEntries(Constants.DropdownTable.RequestorType), "id", "text"); ViewBag.Regions = new SelectList( dc.getEntries(Constants.DropdownTable.Region), "id", "text"); ViewBag.GenderOptions = new SelectList(Constants.genderOptions); return View(reqContent); }
public void TestViewRequestWorking() { // Add some Dependencies var rt = new RequestorType { Code = _random.Next(1000000) .ToString(CultureInfo.InvariantCulture), Value = "VRInt-" + _random.Next() .ToString(CultureInfo.InvariantCulture), Active = true }; _cdc.RequestorTypes.InsertOnSubmit(rt); var qt = new QuestionType { Code = _random.Next(1000000) .ToString(CultureInfo.InvariantCulture), Value = "VRInt-" + _random.Next() .ToString(CultureInfo.InvariantCulture), Active = true }; _cdc.QuestionTypes.InsertOnSubmit(qt); var tg = new TumourGroup { Code = _random.Next(1000000) .ToString(CultureInfo.InvariantCulture), Value = "VRInt-" + _random.Next() .ToString(CultureInfo.InvariantCulture), Active = true }; _cdc.TumourGroups.InsertOnSubmit(tg); var r = new Region { Code = _random.Next(1000000) .ToString(CultureInfo.InvariantCulture), Value = "VRInt-" + _random.Next() .ToString(CultureInfo.InvariantCulture), Active = true }; _cdc.Regions.InsertOnSubmit(r); var k = new Keyword { KeywordValue = "VRInt-" + _random.Next() .ToString(CultureInfo.InvariantCulture), Active = true }; _cdc.Keywords.InsertOnSubmit(k); // Submit our changes so far. _cdc.SubmitChanges(); // Create a test request in the DB var rc = new RequestContent { patientFName = "VRInt-" + _random.Next() .ToString(CultureInfo.InvariantCulture), patientLName = "VRInt-" + _random.Next() .ToString(CultureInfo.InvariantCulture), patientAgencyID = _random.Next() .ToString(CultureInfo.InvariantCulture), patientGender = Constants.Gender.Female, patientAge = 255, requestorTypeID = rt.RequestorTypeID, regionID = r.RegionID, requestorFirstName = "VRInt-" + _random.Next() .ToString( CultureInfo.InvariantCulture), requestorLastName = "VRInt-" + _random.Next() .ToString( CultureInfo.InvariantCulture), requestorEmail = _random.Next() .ToString(CultureInfo.InvariantCulture) + "@example.com", requestorPhoneNum = _random.Next() .ToString( CultureInfo.InvariantCulture), requestorPhoneExt = _random.Next() .ToString( CultureInfo.InvariantCulture) }; var refCont = new ReferenceContent { referenceType = Constants.ReferenceType.Text, referenceString = "VRInt-" + _random.Next() .ToString( CultureInfo.InvariantCulture) }; var qrc = new QuestionResponseContent { question = "VRInt-" + _random.Next() .ToString( CultureInfo.InvariantCulture), response = "VRInt-" + _random.Next() .ToString( CultureInfo.InvariantCulture), specialNotes = "VRInt-" + _random.Next() .ToString( CultureInfo.InvariantCulture), consequence = Constants.Consequence.Certain, severity = Constants.Severity.Major, keywords = new List<string> {k.KeywordValue}, referenceList = new List<ReferenceContent> {refCont}, timeSpent = 255, questionTypeID = qt.QuestionTypeID, tumourGroupID = tg.TumourGroupID }; rc.addQuestionResponse(qrc); var rmc = new RequestManagementController(); long rid = rmc.create(rc); var dmc = new DropdownManagementController(); // Attempt to go to the appropriate View Request Page Directly _driver.Navigate().GoToUrl(CommonTestingMethods.getURL()); _driver.Navigate() .GoToUrl(CommonTestingMethods.getURL() + "/Request/Details/" + rid.ToString(CultureInfo.InvariantCulture)); // Assert that we're not redirected StringAssert.Contains("/Request/Details", _driver.Url); // Go through fields and check values IWebElement element = _driver.FindElement(By.Id("status")); StringAssert.AreEqualIgnoringCase(rc.requestStatus.ToString(), element.Text); element = _driver.FindElement(By.Id("total-time-spent")); StringAssert.Contains(qrc.timeSpent.ToString(), element.Text); element = _driver.FindElement(By.Id("requestor-name")); StringAssert.Contains(rc.requestorFirstName, element.Text); StringAssert.Contains(rc.requestorLastName, element.Text); element = _driver.FindElement(By.Id("requestor-email")); StringAssert.AreEqualIgnoringCase(rc.requestorEmail, element.Text); element = _driver.FindElement(By.Id("requestor-phone")); StringAssert.Contains(rc.requestorPhoneNum, element.Text); StringAssert.Contains(rc.requestorPhoneExt, element.Text); element = _driver.FindElement(By.Id("caller-type")); StringAssert.Contains(rt.Code, element.Text); StringAssert.Contains(rt.Value, element.Text); element = _driver.FindElement(By.Id("region")); StringAssert.Contains(r.Code, element.Text); StringAssert.Contains(r.Value, element.Text); element = _driver.FindElement(By.Id("patient-name")); StringAssert.Contains(rc.patientFName, element.Text); StringAssert.Contains(rc.patientLName, element.Text); element = _driver.FindElement(By.Id("patient-gender")); StringAssert.AreEqualIgnoringCase(rc.patientGender.ToString(), element.Text); element = _driver.FindElement(By.Id("patient-id")); StringAssert.AreEqualIgnoringCase(rc.patientAgencyID, element.Text); element = _driver.FindElement(By.Id("patient-age")); StringAssert.AreEqualIgnoringCase(rc.patientAge.ToString(), element.Text); element = _driver.FindElement(By.ClassName("question")); StringAssert.AreEqualIgnoringCase(qrc.question, element.Text); element = _driver.FindElement(By.ClassName("response")); StringAssert.AreEqualIgnoringCase(qrc.response, element.Text); element = _driver.FindElement(By.ClassName("special-notes")); StringAssert.AreEqualIgnoringCase(qrc.specialNotes, element.Text); element = _driver.FindElement(By.ClassName("question-type")); StringAssert.Contains(qt.Code, element.Text); StringAssert.Contains(qt.Value, element.Text); element = _driver.FindElement(By.ClassName("tumour-group")); StringAssert.Contains(tg.Code, element.Text); StringAssert.Contains(tg.Value, element.Text); element = _driver.FindElement(By.ClassName("time-spent")); StringAssert.Contains(qrc.timeSpent.ToString(), element.Text); element = _driver.FindElement(By.ClassName("score")); StringAssert.AreEqualIgnoringCase( 1.ToString(CultureInfo.InvariantCulture), element.Text); element = _driver.FindElement(By.ClassName("impact-sev")); StringAssert.AreEqualIgnoringCase(qrc.severity.ToString(), element.Text); element = _driver.FindElement(By.ClassName("impact-cons")); StringAssert.AreEqualIgnoringCase(qrc.consequence.ToString(), element.Text); element = _driver.FindElement(By.ClassName("reference-string")); StringAssert.AreEqualIgnoringCase(refCont.referenceString, element.Text); // Cleanup var cdc2 = new CAIRSDataContext(); IQueryable<KeywordQuestion> kqs = cdc2.KeywordQuestions.Where(kq => kq.RequestID == rid); Assert.IsTrue(kqs.Any()); cdc2.KeywordQuestions.DeleteAllOnSubmit(kqs); IQueryable<AuditLog> als = cdc2.AuditLogs.Where(al => al.RequestID == rid); Assert.IsTrue(als.Any()); cdc2.AuditLogs.DeleteAllOnSubmit(als); IQueryable<QuestionResponse> qrs = cdc2.QuestionResponses.Where(dbQr => dbQr.RequestID == rid); Assert.IsTrue(qrs.Any()); cdc2.QuestionResponses.DeleteAllOnSubmit(qrs); IQueryable<Request> rs = cdc2.Requests.Where(rq => rq.RequestID == rid); Assert.IsTrue(rs.Any()); cdc2.Requests.DeleteAllOnSubmit(rs); IQueryable<Reference> refs = cdc2.References.Where(rf => rf.RequestID == rid); Assert.IsTrue(refs.Any()); cdc2.References.DeleteAllOnSubmit(refs); IQueryable<RequestorType> rqts = cdc2.RequestorTypes.Where( rqt => rqt.RequestorTypeID == rt.RequestorTypeID); Assert.IsTrue(rqts.Any()); cdc2.RequestorTypes.DeleteAllOnSubmit(rqts); IQueryable<QuestionType> qts = cdc2.QuestionTypes.Where( dbQt => dbQt.Value == qt.Value); Assert.IsTrue(qts.Any()); cdc2.QuestionTypes.DeleteAllOnSubmit(qts); IQueryable<TumourGroup> tgs = cdc2.TumourGroups.Where( dbTg => dbTg.TumourGroupID == tg.TumourGroupID); Assert.IsTrue(tgs.Any()); cdc2.TumourGroups.DeleteAllOnSubmit(tgs); IQueryable<Region> regions = cdc2.Regions.Where(dbRg => dbRg.RegionID == r.RegionID); Assert.IsTrue(regions.Any()); cdc2.Regions.DeleteAllOnSubmit(regions); IQueryable<Keyword> keywords = cdc2.Keywords.Where(kw => kw.KeywordID == k.KeywordID); Assert.IsTrue(keywords.Any()); cdc2.Keywords.DeleteAllOnSubmit(keywords); IQueryable<Request> rqs = cdc2.Requests.Where(dbRq => dbRq.RequestID == rid); Assert.IsTrue(rqs.Any()); cdc2.Requests.DeleteAllOnSubmit(rqs); cdc2.SubmitChanges(); }