예제 #1
0
        public ActionResult Advanced()
        {
            var criteria = new SearchCriteria();

            setDropdownViewbags();

            return View(criteria);
        }
        public List<Request> searchCriteriaQueryRoles(SearchCriteria criteria)
        {
            // Set Criteria based on Users Role(s)
            if (Roles.IsUserInRole(Constants.Roles.ADMINISTRATOR)) {} else if (String.IsNullOrEmpty(criteria.requestStatus) &&
                                                                               Roles.IsUserInRole(Constants.Roles.REQUEST_EDITOR)) {
                criteria.requestStatus = Enum.GetName(
                    typeof (Constants.RequestStatus),
                    Constants.RequestStatus.Completed)
                                         + "," +
                                         Enum.GetName(
                                             typeof (Constants.RequestStatus
                                                 ),
                                             Constants.RequestStatus.Open);
            } else if (String.IsNullOrEmpty(criteria.requestStatus) &&
                       Roles.IsUserInRole(Constants.Roles.VIEWER)) {
                criteria.requestStatus =
                    Enum.GetName(typeof (Constants.RequestStatus),
                                 Constants.RequestStatus.Completed);
            }

            return searchCriteriaQuery(criteria);
        }
        /// <summary>
        ///     Given a SearchCriteria object, this generates a list of strings used to represent all of the fields being filtered on
        /// </summary>
        /// <param name="sc">The SearchCriteria object used to filter on Requests</param>
        /// <returns>A list of strings which represents the values of the SearchCriteria object</returns>
        public List<string> constructCriteriaString(SearchCriteria sc)
        {
            var result = new List<string>();
            if (!String.IsNullOrEmpty(sc.anyKeywordString)) {
                result.Add(Constants.UIString.FieldLabel.ANY_KEYWORDS + ": " +
                           sc.anyKeywordString.TrimEnd(" ,".ToCharArray()));
            }
            if (!String.IsNullOrEmpty(sc.allKeywordString)) {
                result.Add(Constants.UIString.FieldLabel.ALL_KEYWORDS + ": " +
                           sc.allKeywordString.TrimEnd(" ,".ToCharArray()));
            }
            if (!String.IsNullOrEmpty(sc.noneKeywordString)) {
                result.Add(Constants.UIString.FieldLabel.NONE_KEYWORDS + ": " +
                           sc.noneKeywordString.TrimEnd(" ,".ToCharArray()));
            }
            if (sc.startTime.CompareTo(new DateTime()) != 0) {
                result.Add(Constants.UIString.FieldLabel.START_TIME + ": " +
                           sc.startTime.ToShortDateString());
            }
            if (sc.completionTime.CompareTo(new DateTime()) != 0) {
                result.Add(Constants.UIString.FieldLabel.COMPLETED_TIME + ": " +
                           sc.completionTime.ToShortDateString());
            }
            if (!String.IsNullOrEmpty(sc.requestStatus)) {
                result.Add(Constants.UIString.FieldLabel.STATUS + ": " +
                           sc.requestStatus);
            }
            if (!String.IsNullOrEmpty(sc.requestorFirstName)) {
                result.Add(Constants.UIString.FieldLabel.CALLER_FNAME + ": " +
                           sc.requestorFirstName);
            }
            if (!String.IsNullOrEmpty(sc.requestorLastName)) {
                result.Add(Constants.UIString.FieldLabel.CALLER_LNAME + ": " +
                           sc.requestorLastName);
            }
            if (!String.IsNullOrEmpty(sc.patientFirstName)) {
                result.Add(Constants.UIString.FieldLabel.PATIENT_FNAME + ": " +
                           sc.patientFirstName);
            }
            if (!String.IsNullOrEmpty(sc.patientLastName)) {
                result.Add(Constants.UIString.FieldLabel.PATIENT_LNAME + ": " +
                           sc.patientLastName);
            }
            if (!String.IsNullOrEmpty(sc.tumorGroup)) {
                List<int> ids = typeIdStringtoList(sc.tumorGroup, ",");
                string tumorGroups = String.Join(", ",
                                                 (from tg in _db.TumourGroups
                                                  where
                                                      ids.Contains(
                                                          tg.TumourGroupID)
                                                  select tg.Value));

                result.Add(Constants.UIString.FieldLabel.TUMOUR_GROUP + ": " +
                           tumorGroups);
            }
            if (!String.IsNullOrEmpty(sc.questionType)) {
                List<int> ids = typeIdStringtoList(sc.questionType, ",");
                string questionTypes = String.Join(", ",
                                                   (from qt in _db.QuestionTypes
                                                    where
                                                        ids.Contains(
                                                            qt.QuestionTypeID)
                                                    select qt.Value));

                result.Add(Constants.UIString.FieldLabel.QUESTION_TYPE + ": " +
                           questionTypes);
            }
            if (!String.IsNullOrEmpty(sc.severity)) {
                result.Add(Constants.UIString.FieldLabel.SEVERITY + ": " +
                           sc.severity);
            }
            if (!String.IsNullOrEmpty(sc.consequence)) {
                result.Add(Constants.UIString.FieldLabel.CONSEQUENCE + ": " +
                           sc.consequence);
            }
            return result;
        }
        /// <summary>
        ///     Get Requests in Database based on SearchCriteria
        /// </summary>
        /// <param name="criteria">Search criteria that user inputs</param>
        /// <returns>List of Requests that match the input </returns>
        public List<Request> searchCriteriaQuery(SearchCriteria criteria)
        {
            IQueryable<Request> requests = _db.Requests;

            // Filter on patient first name
            if (!String.IsNullOrEmpty(criteria.patientFirstName)) {
                requests =
                    requests.Where(
                        r => r.PatientFName == criteria.patientFirstName);
            }

            // Filter on patient last name
            if (!String.IsNullOrEmpty(criteria.patientLastName)) {
                requests =
                    requests.Where(
                        r => r.PatientLName == criteria.patientLastName);
            }

            // Filter on requestor first name
            if (!String.IsNullOrEmpty(criteria.requestorFirstName)) {
                requests =
                    requests.Where(
                        r => r.RequestorFName == criteria.requestorFirstName);
            }

            // Filter on requestor last name
            if (!String.IsNullOrEmpty(criteria.requestorLastName)) {
                requests =
                    requests.Where(
                        r => r.RequestorLName == criteria.requestorLastName);
            }

            // Filter on start time
            if (criteria.startTime != DateTime.Parse(Constants.EMPTY_DATE)) {
                requests =
                    requests.Where(
                        r => r.TimeOpened.CompareTo(criteria.startTime) >= 0);
            }

            // Filter on end time
            if (criteria.completionTime != DateTime.Parse(Constants.EMPTY_DATE)) {
                requests =
                    requests.Where(
                        r =>
                        r.TimeClosed != null &&
                        (criteria.completionTime.CompareTo(r.TimeClosed) <= 0));
            }

            // Set Criteria based on Users Role(s)
            if (Roles.IsUserInRole(Constants.Roles.ADMINISTRATOR)) {}
            else if (String.IsNullOrEmpty(criteria.requestStatus) &&
                                                                               Roles.IsUserInRole(Constants.Roles.REQUEST_EDITOR)) {
                criteria.requestStatus = Enum.GetName(
                    typeof (Constants.RequestStatus),
                    Constants.RequestStatus.Completed)
                                         + "," +
                                         Enum.GetName(
                                             typeof (Constants.RequestStatus
                                                 ),
                                             Constants.RequestStatus.Open);
            } else if (String.IsNullOrEmpty(criteria.requestStatus) &&
                       Roles.IsUserInRole(Constants.Roles.VIEWER)) {
                criteria.requestStatus =
                    Enum.GetName(typeof (Constants.RequestStatus),
                                 Constants.RequestStatus.Completed);
            }

            // Filter on request status
            if (!String.IsNullOrEmpty(criteria.requestStatus)) {
                requests =
                    requests.Where(
                        r =>
                        enumToIDs(criteria.requestStatus,
                                  typeof (Constants.RequestStatus))
                            .Contains(r.RequestStatus));
            }

            // Filter on Question/Response tuples
            IQueryable<QuestionResponse> questionResponses =
                _db.QuestionResponses;

            // Filter on QR's Severity
            if (!String.IsNullOrEmpty(criteria.severity)) {
                questionResponses =
                    questionResponses.Where(
                        qr =>
                        enumToIDs(criteria.severity, typeof (Constants.Severity))
                            .Contains((int) qr.Severity));
            }

            // Filter on QR's Consequence
            if (!String.IsNullOrEmpty(criteria.consequence)) {
                questionResponses =
                    questionResponses.Where(
                        qr =>
                        enumToIDs(criteria.consequence,
                                  typeof (Constants.Consequence))
                            .Contains((int) qr.Consequence));
            }

            // Filter on QR's Tumor Group
            if (!String.IsNullOrEmpty(criteria.tumorGroup)) {
                questionResponses =
                    questionResponses.Where(
                        qr =>
                        typeIdStringtoList(criteria.tumorGroup, ",")
                            .Contains(qr.TumourGroup.TumourGroupID));
            }

            // Filter on QR's Question Type
            if (!String.IsNullOrEmpty(criteria.questionType)) {
                questionResponses =
                    questionResponses.Where(
                        qr =>
                        typeIdStringtoList(criteria.questionType, ",")
                            .Contains(qr.QuestionType.QuestionTypeID));
            }

            List<int> any = getKeywords(criteria.anyKeywordString);
            List<int> none = getKeywords(criteria.noneKeywordString);
            List<int> all = getKeywords(criteria.allKeywordString);

            // Filter QRs based on keywords
            if (none.Any() || any.Any() || all.Any()) {
                IQueryable<KeywordQuestion> results = _db.KeywordQuestions;

                if (none.Any()) {
                    List<long> toRemove =
                        (from kq in results
                         where none.Contains(kq.KeywordID)
                         select kq.RequestID).ToList();

                    results = (from r in results
                               where !toRemove.Contains(r.RequestID)
                               select r);
                }
                if (all.Any()) {
                    IQueryable<long> acc = null;
                    foreach (int id in all) {
                        if (acc == null) {
                            acc = (from r in results
                                   where r.KeywordID == id
                                   select r.RequestID);
                        } else {
                            acc = acc.Intersect(from r in results
                                                where r.KeywordID == id
                                                select r.RequestID);
                        }
                    }
                    results = (from r in results
                               where acc.ToList().Contains(r.RequestID)
                               select r);
                }
                if (any.Any()) {
                    results = (from kq in results
                               where any.Contains(kq.KeywordID)
                               select kq);
                }

                // Then we intersect Keywords with QuestionResponses through the use of a join
                questionResponses = (from kq in results
                                     join qr in questionResponses
                                         on kq.QuestionResponseID equals
                                         qr.QuestionResponseID
                                     select qr);
            }

            return (from r in requests
                    join qr in questionResponses
                        on r.RequestID equals qr.RequestID
                    select r).Distinct()
                             .OrderByDescending(r => r.RequestID)
                             .ToList();
        }
 /// <summary>
 ///     Checks if SearchCriteria objects are empty/set to default values
 /// </summary>
 /// <param name="sc">The SearchCriteria to be checked for not-null values</param>
 /// <returns>True if the SearchCriteria is empty, false otherwise</returns>
 public bool isEmptySearchCriteria(SearchCriteria sc)
 {
     if (!String.IsNullOrEmpty(sc.allKeywordString) ||
         !String.IsNullOrEmpty(sc.noneKeywordString)
         || !String.IsNullOrEmpty(sc.anyKeywordString) ||
         !String.IsNullOrEmpty(sc.consequence)
         || !String.IsNullOrEmpty(sc.patientFirstName) ||
         !String.IsNullOrEmpty(sc.patientLastName)
         || !String.IsNullOrEmpty(sc.questionType) ||
         !String.IsNullOrEmpty(sc.requestStatus)
         || !String.IsNullOrEmpty(sc.requestorFirstName) ||
         !String.IsNullOrEmpty(sc.requestorLastName)
         || !String.IsNullOrEmpty(sc.severity) ||
         !String.IsNullOrEmpty(sc.tumorGroup)
         || sc.startTime.CompareTo(new DateTime()) != 0 ||
         sc.completionTime.CompareTo(new DateTime()) != 0) {
         return false;
     }
     return true;
 }
예제 #6
0
        public ActionResult Results(SearchCriteria criteria, FormCollection form)
        {
            DateTime temp;

            if (DateTime.TryParse(form["startTime"], out temp)) {
                criteria.startTime = temp;
            }
            if (DateTime.TryParse(form["completionTime"], out temp)) {
                criteria.completionTime = temp;
            }

            criteria.anyKeywordString = form["anyKeywordString"];
            criteria.allKeywordString = form["allKeywords"];
            criteria.noneKeywordString = form["noneKeywords"];
            criteria.requestStatus = form["status"];
            criteria.severity = form["severity"];
            criteria.consequence = form["consequence"];
            criteria.tumorGroup = form["tumorGroup"];
            criteria.questionType = form["questionType"];
            criteria.requestorFirstName = form["requestorFirst"];
            criteria.requestorLastName = form["requestorLast"];
            criteria.patientFirstName = form["patientFirst"];
            criteria.patientLastName = form["patientLast"];

            if (form["startTime"].Length != 0 && !DateTime.TryParseExact(form["startTime"], "MM/dd/yyyy",
                                    CultureInfo.InvariantCulture,
                                    DateTimeStyles.None,
                                    out temp)) {
                ViewBag.invalidDateFormat = true;
                setDropdownViewbags();
                return View("Advanced", criteria);
            }
            if (form["completionTime"].Length != 0 && !DateTime.TryParseExact(form["completionTime"], "MM/dd/yyyy",
                                        CultureInfo.InvariantCulture,
                                        DateTimeStyles.None,
                                        out temp)) {
                ViewBag.invalidDateFormat = true;
                setDropdownViewbags();
                return View("Advanced", criteria);
            }

            if (criteria.startTime > criteria.completionTime) {
                ViewBag.invalidDate = true;
                setDropdownViewbags();
                return View("Advanced", criteria);

            }
            if (_smc.isEmptySearchCriteria(criteria)) {
                ViewBag.emptyForm = true;
                setDropdownViewbags();
                return View("Advanced", criteria);
            }

            Session["criteria"] = criteria;
            ViewBag.startIndex = 0;
            ViewBag.criteria = _smc.constructCriteriaString(criteria);
            if (_smc.emptyButValidKeywords(criteria)) {
                ViewBag.ResultSetSize = 0;
                return View("Results", new List<Request>());
            }

            _results = _smc.searchCriteriaQueryRoles(criteria);
            fillUpKeywordDict(_results);
            ViewBag.ResultSetSize = _results.Count;

            return View(_results.Take(Constants.PAGE_SIZE));
        }
예제 #7
0
        public ActionResult Search(String keywords)
        {
            Session["criteria"] = new SearchCriteria();
            ViewBag.keywords = keywords;
            var sc = new SearchCriteria();
            sc.anyKeywordString = keywords;

            long requestId;
            if (long.TryParse(keywords, out requestId)) {
                return RedirectToAction("Details", "Request", new {
                    id = requestId
                });
            }

            ViewBag.criteria = _smc.constructCriteriaString(sc);
            _startIndex = 0;
            ViewBag.startIndex = _startIndex;
            Session["criteria"] = sc;

            if (!_smc.getKeywords(sc.anyKeywordString).Any()) {
                ViewBag.ResultSetSize = 0;
                return View("Results", new List<Request>());
            }

            _results = _smc.searchCriteriaQueryRoles(sc);
            fillUpKeywordDict(_results);
            ViewBag.ResultSetSize = _results.Count;

            return View("Results", _results.Take(Constants.PAGE_SIZE));
        }
예제 #8
0
        public void Test_searchCriteriaQueryCombineKeywords()
        {
            SearchManagementController searchCon = new SearchManagementController();

            SearchCriteria s = new SearchCriteria

            {
                anyKeywordString = null,
                allKeywordString = _randomKeyword.KeywordValue + "," + _randomKeyword2.KeywordValue,
                noneKeywordString = _randomKeyword4.KeywordValue,
                patientFirstName = null,
                patientLastName = null,
                questionType = null,
                requestorFirstName = null,
                requestorLastName = null,
                requestStatus = null,
                tumorGroup = null,
                severity = null,
                consequence = null,
            };
            List<Request> results = searchCon.searchCriteriaQuery(s);
            Assert.AreEqual(results.Count, 1);
            Assert.AreEqual(results[0].PatientFName, "TSMC Test");
            Assert.AreEqual(results[0].RequestorFName, "10");
            Assert.AreEqual(results[0].RequestorLName, "100");
        }
예제 #9
0
        public void Test_searchCriteriaQuerySeverity()
        {
            SearchManagementController searchCon = new SearchManagementController();

            SearchCriteria s = new SearchCriteria

            {
                anyKeywordString = null,
                allKeywordString = null,
                noneKeywordString = null,
                patientFirstName = null,
                patientLastName = null,
                questionType = null,
                requestorFirstName = null,
                requestorLastName = "100",
                requestStatus = null,
                tumorGroup = null,
                severity = "Moderate",
                consequence = null,
            };
            List<Request> results = searchCon.searchCriteriaQuery(s);
            //  Assert.AreEqual(results.Count, 1);
            Assert.AreEqual(results[0].PatientFName, "TSMC Test2");
            Assert.AreEqual(results[0].RequestorFName, "20");
            Assert.AreEqual(results[0].RequestorLName, "100");
            Assert.AreEqual(results[0].QuestionResponses[0].Severity, 1);
        }
예제 #10
0
        public void Test_isEmptySearchCriteriaNotEmpty()
        {
            SearchManagementController searchCon = new SearchManagementController();

            SearchCriteria s = new SearchCriteria
            {
                anyKeywordString = "Chemotherapy",
                allKeywordString = null,
                noneKeywordString = null,
                patientFirstName = null,
                patientLastName = null,
                questionType = null,
                requestorFirstName = null,
                requestorLastName = null,
                requestStatus = null,
                tumorGroup = null,
                severity = null,
                consequence = null,
            };

            bool criteriaEmpty = searchCon.isEmptySearchCriteria(s);
            Assert.IsFalse(criteriaEmpty);
        }
예제 #11
0
        public void Test_emptyButValidKeywordWithOneValid()
        {
            SearchManagementController searchCon = new SearchManagementController();
            SearchCriteria oneKeyInvalid = new SearchCriteria
            {
                anyKeywordString = _randomKeyword.KeywordValue,
                allKeywordString = "3-09258340598!@#$",
                noneKeywordString = null,
                patientFirstName = null,
                patientLastName = null,
                questionType = null,
                requestorFirstName = null,
                requestorLastName = null,
                requestStatus = null,
                tumorGroup = null,
                severity = null,
                consequence = null,
            };

            bool oneKeywordInvalid =
                searchCon.emptyButValidKeywords(oneKeyInvalid);
            Assert.IsFalse(oneKeywordInvalid);
        }
예제 #12
0
        public void Test_emptyButValidKeywordsValidKw()
        {
            SearchManagementController searchCon = new SearchManagementController();

            SearchCriteria validKey = new SearchCriteria
            {
                anyKeywordString = _randomKeyword.KeywordValue,
                allKeywordString = null,
                noneKeywordString = null,
                patientFirstName = null,
                patientLastName = null,
                questionType = null,
                requestorFirstName = null,
                requestorLastName = null,
                requestStatus = null,
                tumorGroup = null,
                severity = null,
                consequence = null,
            };

            bool keywordValid = searchCon.emptyButValidKeywords(validKey);
            Assert.IsFalse(keywordValid);
        }
예제 #13
0
        public void Test_emptyButValidKeywordsInvalidKw()
        {
            SearchManagementController searchCon = new SearchManagementController();
            SearchCriteria invalidKey = new SearchCriteria
            {
                anyKeywordString = null,
                allKeywordString = "239048230-948!@#",
                noneKeywordString = null,
                patientFirstName = null,
                patientLastName = null,
                questionType = null,
                requestorFirstName = null,
                requestorLastName = null,
                requestStatus = null,
                tumorGroup = null,
                severity = null,
                consequence = null,
            };

            bool keywordInvalid = searchCon.emptyButValidKeywords(invalidKey);
            Assert.IsTrue(keywordInvalid);
        }
예제 #14
0
        public void Test_constructCriteriaString()
        {
            SearchManagementController searchCon = new SearchManagementController();
            SearchCriteria sc = new SearchCriteria
            {
                anyKeywordString = "Chemotherapy, Drug Interaction",
                allKeywordString = "Advil",
                noneKeywordString = "Pain",
                patientFirstName = "Kurt",
                patientLastName = "Eiselt",
                startTime = new DateTime(2013, 2, 1),
                completionTime = new DateTime(2013, 4, 1),
                requestorFirstName = "Jing",
                requestorLastName = "Zhu",
                requestStatus = "Open",
                severity = "Major",
                consequence = "Possible",
            };
            List<string> cs = searchCon.constructCriteriaString(sc);
            Assert.IsNotNull(cs);
            Assert.AreEqual(cs.Count, 12);
            List<string> temp = new List<string>();
            temp.Add("Any of These Keywords: Chemotherapy, Drug Interaction");
            temp.Add("All of These Keywords: Advil");
            temp.Add("None of These Keywords: Pain");
            temp.Add("Start Time: 2/1/2013");
            temp.Add("Completed Time: 4/1/2013");
            temp.Add("Status: Open");
            temp.Add("First Name: Jing");
            temp.Add("Last Name: Zhu");
            temp.Add("First Name: Kurt");
            temp.Add("Last Name: Eiselt");
            temp.Add("Severity: Major");
            temp.Add("Probability of Consequence: Possible");

            Assert.AreEqual(cs.Count, temp.Count);
            for (int i = 0; i < temp.Count; i++)
            {
                Assert.AreEqual(cs[i], temp[i]);
            }
        }