示例#1
0
        private void SetupFieldAndUrlFilters(ClinicalTrial trial)
        {
            // Copying the Title & Short Title logic from Advanced Form
            //set the page title as the protocol title
            PageInstruction.AddFieldFilter("long_title", (fieldName, data) =>
            {
                data.Value = trial.BriefTitle;
            });

            PageInstruction.AddFieldFilter("short_title", (fieldName, data) =>
            {
                data.Value = trial.BriefTitle;

                //Eh, When would this happen???
                if (!string.IsNullOrWhiteSpace(trial.NCTID))
                {
                    data.Value += " - " + trial.NCTID;
                }
            });


            PageInstruction.AddFieldFilter("meta_description", (fieldname, data) =>
            {
                data.Value = trial.BriefTitle;
            });



            PageInstruction.AddUrlFilter("CurrentUrl", (name, url) =>
            {
                //Copy the params
                //TODO: Really determine what to do with these params.  If the search is invalid, we probably
                //hsould not show them all.
                foreach (KeyValuePair <string, string> param in this.ParsedReqUrlParams.QueryParameters)
                {
                    url.QueryParameters.Add(param.Key, param.Value);
                }
            });

            PageInstruction.AddUrlFilter("CanonicalUrl", (name, url) =>
            {
                // only the id should be provided for the canonical URL, so clear all query parameters and
                // then add back id
                url.QueryParameters.Clear();
                url.QueryParameters.Add("id", trial.NCIID);
                //url.QueryParameters.Add("id", TrialID);
            });

            // Override the social media URL (og:url)
            PageInstruction.AddFieldFilter("og:url", (fieldName, data) =>
            {
                //Ok, this is weird, but...  The OpenGraph URL is actually a field. It kind of makes sense,
                //and it kind of does not.  Really it should be a field that gets the og:url instead of the
                //pretty URL.
                //BUt here we are, and it is what we have.  So let's replace the og:url with the canonical URL.

                data.Value = PageInstruction.GetUrl(NCI.Web.CDE.PageAssemblyInstructionUrls.CanonicalUrl).ToString();
            });
        }
示例#2
0
        /// <summary>
        /// Goes and fetches the data from the API & Returns the results to base class to be bound to the template.
        /// </summary>
        /// <returns></returns>
        protected override object GetDataForTemplate()
        {
            //TODO: Don't do a search if there are param errors.
            if (SearchParams.HasInvalidParams() == true)
            {
                _results = new ClinicalTrialsCollection();
                _results.TotalResults = 0;
            }

            else
            {
                _results = CTSManager.Search(SearchParams, this.PageNum, this.ItemsPerPage);
            }

            //Let's setup some helpful items for the template, so they do not need to be helper functions
            //The start is either 0 if there are no results, or a 1 based offset based on Page number and items per page.
            int startItemNumber = _results.TotalResults == 0 ? _results.TotalResults : ((this.PageNum - 1) * this.ItemsPerPage) + 1;

            //Determine the last item.
            long lastItemNumber = (this.PageNum * this.ItemsPerPage);

            if (lastItemNumber > _results.TotalResults)
            {
                lastItemNumber = _results.TotalResults;
            }

            //Determine the max page
            int maxPage = (int)Math.Ceiling((double)_results.TotalResults / (double)this.ItemsPerPage);

            // Add URL filters
            PageInstruction.AddUrlFilter("CurrentUrl", (name, url) =>
            {
                //Convert the current search parameters into a NciUrl
                NciUrl paramsUrl = CTSSearchParamFactory.ConvertParamsToUrl(this.SearchParams);

                //Add or replace the currentURL params based on the *validated* query params.
                foreach (KeyValuePair <string, string> qp in paramsUrl.QueryParameters)
                {
                    if (!url.QueryParameters.ContainsKey(qp.Key))
                    {
                        url.QueryParameters.Add(qp.Key, qp.Value);
                    }
                    else
                    {
                        url.QueryParameters[qp.Key] = qp.Value;
                    }
                }

                url.QueryParameters.Add("ni", this.ItemsPerPage.ToString());
            });


            //Return the object for binding.
            return(new
            {
                Results = _results,
                Control = this,
                Parameters = SearchParams,
                PageInfo = new {
                    CurrentPage = this.PageNum,
                    MaxPage = maxPage,
                    ItemsPerPage = this.ItemsPerPage,
                    StartItemNumber = startItemNumber,
                    LastItemNumber = lastItemNumber
                },
                TrialTools = new TrialVelocityTools()
            });
        }