Пример #1
0
        private void ReturnPrintCache(HttpContext context, CTSPrintManager manager)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            //Set our output to be HTML
            response.ContentType     = "text/HTML";
            response.ContentEncoding = Encoding.UTF8;

            Guid printID = new Guid();

            // Validate if the printID passed in through the URL is a valid Guid
            try
            {
                printID = Guid.Parse(request.QueryString["printid"]);
            }
            catch
            {
                // Incorrect parameter for printid (not guid)
                ErrorPageDisplayer.RaisePageByCode(this.GetType().ToString(), 400);
                throw new InvalidPrintIDException("Invalid PrintID parameter for CTS Print");
            }


            // If there is no error, send the printID to the manager to retrieve the cached print content
            string printContent = manager.GetPrintContent(printID);

            printContent = printContent.Replace("${generatePrintURL}", GetEmailUrl(printID));

            response.Write(printContent);
            response.End();
        }
Пример #2
0
        /// <summary>
        /// Connects to the database , and executes the stored proc with the required parameters. The
        /// resulting content is the print page HTML.
        /// </summary>
        /// <param name="printId"></param>
        /// <param name="isLive"></param>
        /// <returns>A string.</returns>
        public static string RetrieveResult(Guid printID, bool isLive)
        {
            string printPageHtml = null;

            try
            {
                string connString = ConfigurationManager.ConnectionStrings["DbConnectionString"].ConnectionString;

                if (!string.IsNullOrEmpty(connString))
                {
                    using (SqlConnection conn = SqlHelper.CreateConnection(connString))
                    {
                        using (SqlDataReader reader =
                                   SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "dbo.ct_getPrintResultCache",
                                                           new SqlParameter("@PrintId ", printID),
                                                           new SqlParameter("@isLive", isLive ? 1 : 0)
                                                           ))
                        {
                            if (reader.Read())
                            {
                                SqlFieldValueReader sqlFVReader = new SqlFieldValueReader(reader);
                                printPageHtml = sqlFVReader.GetString("content");
                            }
                            else
                            {
                                ErrorPageDisplayer.RaisePageByCode("CTSPrintDataManager", 404);
                                throw new PrintIDNotFoundException("The given printID did not match any cache values in the database");
                            }
                        }
                    }
                }
                else
                {
                    ErrorPageDisplayer.RaisePageByCode("CTSPrintDataManager", 500);
                    throw new DbConnectionException("Configuration Missing: Connection string is null, update the web config with connection string");
                }

                if (!string.IsNullOrWhiteSpace(printPageHtml))
                {
                    return(printPageHtml);
                }
                else
                {
                    throw new PrintFetchFailureException("Failed in CTSPrintDataManager - Cannot return null page HTML");
                }
            }
            catch
            {
                throw new PrintFetchFailureException("Failed in CTSPrintDataManager");
            }
        }
Пример #3
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()
        {
            ParseAndValidateID();

            // Get Trial by ID
            ClinicalTrial trial;

            try
            {
                // Retrieve a Clinical Trial based on the Trial ID
                trial = this.CTSManager.Get(TrialID);
            }
            catch (Exception ex)
            {
                // If we hit some other error when getting the trials, redirect to the error page
                string errMessage = "CDE:APICTSDetailsControl.cs:OnLoad" + " Requested trial ID: " + TrialID + "\nException thrown by CTSManager.get(nctid) call.";
                log.Error(errMessage, ex);
                ErrorPageDisplayer.RaisePageError(errMessage);

                //TODO: Make sure RaisePageError stops processing this page
                return(null);
            }

            RedirectIfTrialNotValid(trial);

            SetupFieldAndUrlFilters(trial);

            //TODO: Glossification????

            // Set up NCTID for analytics
            _nctid = trial.NCTID;

            //We did not come from a search, so don't show the criteria.
            //this also applies if we can from a print result.
            if (this.ParsedReqUrlParams.QueryParameters.ContainsKey("rl"))
            {
                _showCriteria = true;
            }

            return(new
            {
                Trial = trial,
                Parameters = SearchParams,
                Control = this,
                TrialTools = new TrialVelocityTools()
            });
        }
Пример #4
0
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;

            CTSPrintManager manager = new CTSPrintManager(_config);

            if (request.HttpMethod == "POST")
            {
                GeneratePrintCacheAndRedirect(context, manager);
            }
            else if (request.HttpMethod == "GET")
            {
                ReturnPrintCache(context, manager);
            }
            else
            {
                ErrorPageDisplayer.RaisePageByCode(this.GetType().ToString(), 400);
            }
        }
Пример #5
0
        public Guid StorePrintContent(List <String> trialIDs, DateTime date, CTSSearchParams searchTerms)
        {
            // Retrieve the collections given the ID's
            //TODO: THese dependencies should be passed in!
            BasicCTSManager manager = new BasicCTSManager(APIClientHelper.GetV1ClientInstance());

            List <ClinicalTrial> results = manager.GetMultipleTrials(trialIDs).ToList();

            // Send results to Velocity template
            var formattedPrintContent = FormatPrintResults(results, date, searchTerms);

            // Save result to cache table
            Guid guid = CTSPrintResultsDataManager.SavePrintResult(formattedPrintContent, trialIDs, searchTerms, Settings.IsLive);

            if (guid == Guid.Empty)
            {
                // Something went wrong with the save/return from the DB
                ErrorPageDisplayer.RaisePageByCode(this.GetType().ToString(), 500);
                throw new DbConnectionException("Unable to connect to the database. ");
            }

            return(guid);
        }
Пример #6
0
        private void GeneratePrintCacheAndRedirect(HttpContext context, CTSPrintManager manager)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            NciUrl parsedReqUrlParams = new NciUrl(true, true, true);  //We need this to be lowercase and collapse duplicate params. (Or not use an NCI URL)

            parsedReqUrlParams.SetUrl(request.Url.Query);


            ClinicalTrialsAPIClient apiClient = APIClientHelper.GetV1ClientInstance();

            CTSSearchParams searchParams = null;

            try
            {
                // Get mapping file names from configuration
                TrialTermLookupConfig mappingConfig = new TrialTermLookupConfig();
                mappingConfig.MappingFiles.AddRange(_config.MappingFiles.Select(fp => HttpContext.Current.Server.MapPath(fp)));

                CTSSearchParamFactory factory = new CTSSearchParamFactory(new TrialTermLookupService(mappingConfig, apiClient), new ZipCodeGeoLookup());
                searchParams = factory.Create(parsedReqUrlParams);
            }
            catch (Exception ex)
            {
                ErrorPageDisplayer.RaisePageByCode(this.GetType().ToString(), 400); //Anything here is just a bad request.
            }

            //Set our output to be JSON
            response.ContentType     = "application/json";
            response.ContentEncoding = Encoding.UTF8;

            //Try and get the request.
            Request req = null;

            try
            {
                req = GetRequestAndValidate(context);
            }
            catch (Exception)
            {
                ErrorPageDisplayer.RaisePageByCode(this.GetType().ToString(), 400); //Anything here is just a bad request.
                return;
            }

            // Store the cached print content
            Guid printCacheID = manager.StorePrintContent(req.TrialIDs, DateTime.Now, searchParams);

            //Add in debugging helper param to make debugging templates easier.
            //TODO: Refactor so get content and render is a single function.
            if (parsedReqUrlParams.QueryParameters.ContainsKey("debug") && parsedReqUrlParams.QueryParameters["debug"] == "true")
            {
                response.ContentType     = "text/HTML";
                response.ContentEncoding = Encoding.UTF8;
                // If there is no error, send the printID to the manager to retrieve the cached print content
                string printContent = manager.GetPrintContent(printCacheID);

                printContent = printContent.Replace("${generatePrintURL}", GetEmailUrl(printCacheID));

                response.Write(printContent);
                response.End();
            }
            else
            {
                // Format our return as JSON
                var resp = JsonConvert.SerializeObject(new
                {
                    printID = printCacheID
                });

                response.Write(resp);
                response.End();
            }
        }
Пример #7
0
 public void ProcessRequest(HttpContext context)
 {
     ErrorPageDisplayer.RaisePageNotFound(this.GetType().ToString());
 }
Пример #8
0
 virtual public void RaiseErrorPage(string messageKey)
 {
     // Use the common ErrorPageDisplayer so we do not duplicate the logic
     ErrorPageDisplayer.RaisePageError(this.GetType().ToString());
 }