public void FilterByHospital(ClinicalTrial trial, CTSSearchParams searchParams, IEnumerable <ClinicalTrial.StudySite> expectedSites)
        {
            SnippetControls.TrialVelocityTools    tvt    = new SnippetControls.TrialVelocityTools();
            IEnumerable <ClinicalTrial.StudySite> actual = tvt.GetFilteredLocations(trial, searchParams);

            Assert.Equal(expectedSites, actual, new ClinicalTrialsAPI.Test.StudySiteComparer());
        }
        public void FieldAsString_Phrase()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                Phrase = "Keyword"
            };

            Assert.Equal("Keyword", searchParams.GetFieldAsString("Phrase"));
        }
        public void SerializeParams(CTSSearchParams searchParams, NciUrl expected)
        {
            //Get the results of parsing the URL
            NciUrl actual = CTSSearchParamFactory.ConvertParamsToUrl(searchParams);

            //Test the actual result to the expected.  NOTE: If you add fields to the CTSSearchParams, you need
            //to also modify the comparer
            Assert.Equal(expected.QueryParameters, actual.QueryParameters);
        }
        public void FieldAsString_TrialIDsX2()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                TrialIDs = new string[] { "NCT12345", "SWOG" }
            };

            Assert.Equal("NCT12345, SWOG", searchParams.GetFieldAsString("TrialIDs"));
        }
        public void FieldAsString_LeadOrg()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                LeadOrg = "The Lead Org"
            };

            Assert.Equal("The Lead Org", searchParams.GetFieldAsString("LeadOrg"));
        }
        public void FieldAsString_HealthyVolunteer_Unhealthy()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                HealthyVolunteer = HealthyVolunteerType.Infirmed
            };

            Assert.Equal("Not Accepting Healthy Volunteers", searchParams.GetFieldAsString("HealthyVolunteers"));
        }
        public void FieldAsString_Gender()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                Gender = "female"
            };

            Assert.Equal("female", searchParams.GetFieldAsString("Gender"));
        }
        public void FieldAsString_HealthyVolunteer_Healthy()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                HealthyVolunteer = HealthyVolunteerType.Healthy
            };

            Assert.Equal("Only Accepting Healthy Volunteers", searchParams.GetFieldAsString("HealthyVolunteers"));
        }
        public void FieldAsString_Investigator()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                Investigator = "The Investigator"
            };

            Assert.Equal("The Investigator", searchParams.GetFieldAsString("Investigator"));
        }
        public void FieldAsString_Age()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                Age = 29
            };

            Assert.Equal("29", searchParams.GetFieldAsString("Age"));
        }
        public void FieldAsString_City()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                Location       = LocationType.CountryCityState,
                LocationParams = new CountryCityStateLocationSearchParams()
                {
                    City = "Baltimore"
                }
            };

            Assert.Equal("Baltimore", searchParams.GetFieldAsString("City"));
        }
        public void FieldAsString_Country()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                Location       = LocationType.CountryCityState,
                LocationParams = new CountryCityStateLocationSearchParams()
                {
                    Country = "United States"
                }
            };

            Assert.Equal("United States", searchParams.GetFieldAsString("Country"));
        }
        public void FieldAsString_Hospital()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                Location       = LocationType.Hospital,
                LocationParams = new HospitalLocationSearchParams()
                {
                    Hospital = "Mayo Clinic"
                }
            };

            Assert.Equal("Mayo Clinic", searchParams.GetFieldAsString("Hospital"));
        }
        public void FieldAsString_MainTypeX1()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                MainType = new TerminologyFieldSearchParam()
                {
                    Codes = new string[] { "C12345" },
                    Label = "Maintype 1"
                }
            };

            Assert.Equal("Maintype 1", searchParams.GetFieldAsString("MainType"));
        }
        public void FieldAsString_DrugX1()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                Drugs = new TerminologyFieldSearchParam[] {
                    new TerminologyFieldSearchParam()
                    {
                        Codes = new string[] { "C12345" },
                        Label = "Test Drug 1"
                    }
                }
            };

            Assert.Equal("Test Drug 1", searchParams.GetFieldAsString("Drugs"));
        }
        public void FieldAsString_PhasesX1()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                TrialPhases = new LabelledSearchParam[] {
                    new LabelledSearchParam()
                    {
                        Key   = "I",
                        Label = "Phase I"
                    }
                }
            };

            Assert.Equal("Phase I", searchParams.GetFieldAsString("TrialPhases"));
        }
        public void FieldAsString_SubTypesX1()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                SubTypes = new TerminologyFieldSearchParam[] {
                    new TerminologyFieldSearchParam()
                    {
                        Codes = new string[] { "C12345" },
                        Label = "Subtype 1"
                    }
                }
            };

            Assert.Equal("Subtype 1", searchParams.GetFieldAsString("SubTypes"));
        }
        public void FieldAsString_TrialTypesX1()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                TrialTypes = new LabelledSearchParam[] {
                    new LabelledSearchParam()
                    {
                        Key   = "basic_science",
                        Label = "Basic Science"
                    }
                }
            };

            Assert.Equal("Basic Science", searchParams.GetFieldAsString("TrialTypes"));
        }
        public void Create(string url, CTSSearchParams expected)
        {
            TrialTermLookupService lookupSvc = GetMappingService(new string[] { "EVSWithMultiple.txt", "Other.txt" });
            var mockZipLookupSvc             = GetZipLookupMock();

            // Create a new instance of the factory, passing in the loaded lookup service and
            // the mock zip lookup service.
            CTSSearchParamFactory factory = new CTSSearchParamFactory(lookupSvc, mockZipLookupSvc.Object);

            //Get the results of parsing the URL.
            CTSSearchParams actual = factory.Create(url);

            //Test the actual result to the expected.
            Assert.Equal(expected, actual, new CTSSearchParamsComparer());
        }
        public void FieldAsString_FindingsX1()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                Findings = new TerminologyFieldSearchParam[] {
                    new TerminologyFieldSearchParam()
                    {
                        Codes = new string[] { "C12345" },
                        Label = "Finding 1"
                    }
                }
            };

            Assert.Equal("Finding 1", searchParams.GetFieldAsString("Findings"));
        }
        public void FieldAsString_OtherX1()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                OtherTreatments = new TerminologyFieldSearchParam[] {
                    new TerminologyFieldSearchParam()
                    {
                        Codes = new string[] { "C12345" },
                        Label = "Test Other Treatment 1"
                    }
                }
            };

            Assert.Equal("Test Other Treatment 1", searchParams.GetFieldAsString("OtherTreatments"));
        }
        /// <summary>
        /// Check search params to determine whether this is an avanced, basic, or other search.
        /// </summary>
        /// <returns></returns>
        protected String GetSearchType(CTSSearchParams searchParams)
        {
            string ctsType = string.Empty;

            // Get page type from 'rl' param
            if (!string.IsNullOrWhiteSpace(searchParams.ResultsLinkFlag.ToString()))
            {
                switch (searchParams.ResultsLinkFlag)
                {
                case ResultsLinkType.Advanced:
                {
                    ctsType = "Advanced";
                    break;
                }

                case ResultsLinkType.Basic:
                {
                    ctsType = "Basic";
                    break;
                }

                case ResultsLinkType.Unknown:
                {
                    ctsType = "Unknown";
                    break;
                }

                default:
                {
                    ctsType = "Basic";
                    break;
                }
                }
            }

            // If this is redirect/non-form search, set type as "Custom"
            if (searchParams.RedirectFlag == true)
            {
                ctsType = "Custom";
            }

            return(ctsType);
        }
        public void FieldAsString_StatesX1()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                Location       = LocationType.CountryCityState,
                LocationParams = new CountryCityStateLocationSearchParams()
                {
                    State = new LabelledSearchParam[] {
                        new LabelledSearchParam()
                        {
                            Key   = "MD",
                            Label = "Maryland"
                        }
                    }
                }
            };

            Assert.Equal("Maryland", searchParams.GetFieldAsString("State"));
        }
        public void FieldAsString_StagesX2()
        {
            CTSSearchParams searchParams = new CTSSearchParams()
            {
                Stages = new TerminologyFieldSearchParam[] {
                    new TerminologyFieldSearchParam()
                    {
                        Codes = new string[] { "C12345" },
                        Label = "Stage 1"
                    },
                    new TerminologyFieldSearchParam()
                    {
                        Codes = new string[] { "C12345" },
                        Label = "Stage 2"
                    }
                }
            };

            Assert.Equal("Stage 1, Stage 2", searchParams.GetFieldAsString("Stages"));
        }
        /// <summary>
        /// CTSSearchParams -> filterCriterea mapping tests
        /// </summary>
        /// <param name="searchParams">An instance of a CTSSearchParams object</param>
        /// <param name="expectedCriteria">The expected criteria for the search</param>
        private void MappingTest(CTSSearchParams searchParams, Dictionary <string, object> expectedCriteria)
        {
            Dictionary <string, object> actualCriteria = null;

            //When search gets called trap the criteria and set the actualCriteria
            var mockClient = GetClientMock(
                (filterCriteria, size, from, include, exclude) => actualCriteria = filterCriteria,
                new ClinicalTrialsCollection()
            {
                TotalResults = 0, Trials = new ClinicalTrial[] { }
            }
                );

            //Create a new instance of the factory, passing in the Mock's version of an implementation
            //of our IClinicalTrialsAPIClient interface.
            BasicCTSManager manager = new BasicCTSManager(mockClient.Object);

            //Get the results of parsing the URL
            ClinicalTrialsCollection returnedCol = manager.Search(searchParams);

            //Test the actual result to the expected.  NOTE: If you add fields to the CTSSearchParams, you need
            //to also modify the comparer
            Assert.Equal(expectedCriteria, actualCriteria);
        }
Example #26
0
 public void MappingEmptyArrayFields(CTSSearchParams searchParams, Dictionary <string, object> expectedCriteria)
 {
     this.MappingTest(searchParams, expectedCriteria);
 }
Example #27
0
 /// <summary>
 /// Get all Locations, but filtered by location parameters.
 /// NOTE: LocationTypes for Hospital and None will not be filtered, but will be sorted.
 /// </summary>
 /// <returns></returns>
 public ClinicalTrial.StudySite[] GetFilteredLocations(ClinicalTrial trial, CTSSearchParams searchParams)
 {
     return(GetFilteredLocations(trial.Sites, searchParams));
 }
Example #28
0
        /// <summary>
        /// Get all Locations, but filtered by location parameters.
        /// NOTE: LocationTypes for Hospital and None will not be filtered, but will be sorted.
        /// </summary>
        /// <returns></returns>
        public ClinicalTrial.StudySite[] GetFilteredLocations(IEnumerable <ClinicalTrial.StudySite> sites, CTSSearchParams searchParams)
        {
            IEnumerable <ClinicalTrial.StudySite> rtnSites = sites;

            switch (searchParams.Location)
            {
            case LocationType.AtNIH:
            {
                rtnSites = rtnSites.Where(s => s.PostalCode == "20892");
                break;
            }

            case LocationType.CountryCityState:
            {
                CountryCityStateLocationSearchParams locParams = (CountryCityStateLocationSearchParams)searchParams.LocationParams;

                if (locParams.IsFieldSet(FormFields.Country))
                {
                    rtnSites = rtnSites.Where(s => StringComparer.CurrentCultureIgnoreCase.Equals(s.Country, locParams.Country));
                }

                if (locParams.IsFieldSet(FormFields.City))
                {
                    rtnSites = rtnSites.Where(s => StringComparer.CurrentCultureIgnoreCase.Equals(s.City, locParams.City));
                }

                if (locParams.IsFieldSet(FormFields.State))
                {
                    var states = locParams.State.Select(s => s.Key);         //Get Abbreviations
                    rtnSites = rtnSites.Where(s => states.Contains(s.StateOrProvinceAbbreviation));
                }

                break;
            }

            case LocationType.Zip:
            {
                ZipCodeLocationSearchParams locParams = (ZipCodeLocationSearchParams)searchParams.LocationParams;

                rtnSites = rtnSites.Where(site =>
                                          site.Coordinates != null &&
                                          locParams.GeoLocation.DistanceBetween(new GeoLocation(site.Coordinates.Latitude, site.Coordinates.Longitude)) <= locParams.ZipRadius &&
                                          site.Country == "United States"
                                          );

                break;
            }

            default:
            {
                //Basically we can't/shouldn't filter.
                break;
            }
            }

            //Filter out non-va sites if this is a VA only search
            if (searchParams.IsVAOnly && searchParams.Location != LocationType.Hospital)
            {
                rtnSites = rtnSites.Where(site => site.IsVA);
            }

            //Now that we have the sites filtered, now we need to sort.
            return(rtnSites.ToArray());
        }
Example #29
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();
            }
        }
Example #30
0
        /// <summary>
        /// Connects to the database, and executes the stored proc with the required parameters. The
        /// resulting content is the guid associated with the cached print content.
        /// </summary>
        /// <param name="content"></param>
        /// <param name="searchParams"></param>
        /// <param name="isLive"></param>
        /// <returns>A guid.</returns>
        public static Guid SavePrintResult(string content, IEnumerable <String> trialIDs, CTSSearchParams searchParams, bool isLive)
        {
            DataTable dt = new DataTable();

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DbConnectionString"].ConnectionString))
            {
                Guid printResultGuid = Guid.Empty;

                SqlParameter[] parameters =
                {
                    new SqlParameter("@printid",      SqlDbType.UniqueIdentifier),
                    new SqlParameter("@content",      SqlDbType.NVarChar,         content.Length),
                    new SqlParameter("@searchparams", SqlDbType.NVarChar),
                    new SqlParameter("@isLive",       SqlDbType.Bit),
                    new SqlParameter("@trialids",     SqlDbType.Structured)
                };
                parameters[0].Direction = ParameterDirection.Output;
                parameters[1].Value     = content;
                parameters[2].Value     = new JavaScriptSerializer().Serialize(searchParams);
                parameters[3].Value     = isLive;
                parameters[4].Value     = CreatePrintIdDataTable(trialIDs);

                try
                {
                    SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "dbo.ct_insertPrintresultcache", parameters);
                    printResultGuid = (Guid)parameters[0].Value;
                }
                catch (SqlException ex)
                {
                    CancerGovError.LogError("Unable to save data. Search Params: " + searchParams + "isLive: " + isLive, 2, ex);
                }

                return(printResultGuid);
            }
        }