////Parameter lst (State) && Parameter lcty (City) && Parameter lcnty (Country)
        private static void AddAnalyticsCountryCityState(List <string> waList, CTSSearchParams searchParams)
        {
            CountryCityStateLocationSearchParams locParams = (CountryCityStateLocationSearchParams)searchParams.LocationParams;
            string valCountry = "none";
            string valState   = "none";
            string valCity    = "none";

            if (locParams.IsFieldSet(FormFields.State))
            {
                valState = string.Join(",", locParams.State.Select(lst => lst.Key));
            }
            if (locParams.IsFieldSet(FormFields.City))
            {
                valCity = locParams.City;
            }
            if (locParams.IsFieldSet(FormFields.Country))
            {
                valCountry = locParams.Country;
            }

            waList.Add(valCountry);
            waList.Add(valState);
            waList.Add(valCity);

            //TODO: add logic to draw state only if USA?
        }
Exemple #2
0
        /// <summary>
        /// Gets a location field value as a string suitable for things like, oh, a velocity template
        /// </summary>
        /// <param name="field">A FormFields enum value</param>
        /// <returns>The value of the field, OR, and error message</returns>
        private string GetLocFieldAsString(FormFields field)
        {
            CountryCityStateLocationSearchParams cLoc = LocationParams as CountryCityStateLocationSearchParams;
            HospitalLocationSearchParams         hLoc = LocationParams as HospitalLocationSearchParams;
            ZipCodeLocationSearchParams          zLoc = LocationParams as ZipCodeLocationSearchParams;

            switch (field)
            {
            case FormFields.AtNIH:
            {
                if (Location == LocationType.AtNIH)
                {
                    return("Yes");
                }
                else
                {
                    throw new Exception();
                }
            }

            case FormFields.City:
            {
                return(cLoc.City);
            }

            case FormFields.Country:
            {
                return(cLoc.Country);
            }

            case FormFields.State:
            {
                return(String.Join(", ", cLoc.State.Select(st => st.Label)));
            }

            case FormFields.Hospital:
            {
                return(hLoc.Hospital);
            }

            case FormFields.ZipCode:
            {
                return(zLoc.ZipCode);
            }

            case FormFields.ZipRadius:
            {
                return(zLoc.ZipRadius.ToString());
            }

            default:
            {
                throw new Exception();
            }
            }
        }
Exemple #3
0
        //Parameter lst (State) && Parameter lcty (City) && Parameter lcnty (Country)
        private static void SerializeCountryCityState(NciUrl url, CTSSearchParams searchParams)
        {
            CountryCityStateLocationSearchParams locParams = (CountryCityStateLocationSearchParams)searchParams.LocationParams;

            if (locParams.IsFieldSet(FormFields.State))
            {
                //TODO: do we need to encode the state?
                url.QueryParameters.Add(
                    "lst",
                    string.Join(",", locParams.State.Select(lst => lst.Key))
                    );
            }

            if (locParams.IsFieldSet(FormFields.City))
            {
                url.QueryParameters.Add("lcty", HttpUtility.UrlEncode(locParams.City));
            }

            if (locParams.IsFieldSet(FormFields.Country))
            {
                url.QueryParameters.Add("lcnty", HttpUtility.UrlEncode(locParams.Country));
            }
        }
Exemple #4
0
        //Parameter lst (State) && Parameter lcty (City) && Parameter lcnty (Country)
        private void ParseCountryCityState(NciUrl url, CTSSearchParams searchParams)
        {
            CountryCityStateLocationSearchParams locParams = new CountryCityStateLocationSearchParams();
            bool hasInvalidParam = false;

            if (IsInUrl(url, "lst"))
            {
                locParams.State = GetLabelledFieldFromParam(url.QueryParameters["lst"], FormFields.State, searchParams);
                if (locParams.State.Length == 0)
                {
                    hasInvalidParam = true;
                }
            }

            if (IsInUrl(url, "lcty"))
            {
                if (!IsInUrl(url, "lcnty"))
                {
                    hasInvalidParam = true;
                    LogParseError(FormFields.Country, "Please enter a country parameter if entering a city parameter.", searchParams);
                }
                else
                {
                    string city = url.CTSParamAsStr("lcty");
                    if (!string.IsNullOrWhiteSpace(city))
                    {
                        locParams.City = city;
                    }
                    else
                    {
                        hasInvalidParam = true;
                        LogParseError(FormFields.City, "Please enter a valid city parameter.", searchParams);
                    }
                }
            }

            if (IsInUrl(url, "lcnty"))
            {
                string country = url.CTSParamAsStr("lcnty");
                if (!string.IsNullOrWhiteSpace(country))
                {
                    locParams.Country = country;
                }
                else
                {
                    hasInvalidParam = true;
                    LogParseError(FormFields.Country, "Please enter a valid country parameter.", searchParams);
                }
            }

            if (!IsInUrl(url, "lcty") && !IsInUrl(url, "lst") && !IsInUrl(url, "lcnty"))
            {
                hasInvalidParam = true;
                LogParseError(FormFields.Location, "You must enter either a valid country, city, or state parameter.", searchParams);
            }

            if (!hasInvalidParam)
            {
                searchParams.LocationParams = locParams;
            }
            else
            {
                searchParams.LocationParams = new CountryCityStateLocationSearchParams();
            }
        }
        // TODO: refactor and clean up names

        /// <summary>
        /// Build the list of query abbreviations from completed search fields.
        /// </summary>
        /// <param name="waList"></param>
        /// <param name="searchParams"></param>
        private static void AddAllUsedParams(List <string> waList, CTSSearchParams searchParams)
        {
            //Parameter t (Main Cancer Type)
            if (searchParams.IsFieldSet(FormFields.MainType))
            {
                waList.Add("t");
            }

            //Parameter st (SubTypes)
            if (searchParams.IsFieldSet(FormFields.SubTypes))
            {
                waList.Add("st");
            }

            //Parameter stg (Stages)
            if (searchParams.IsFieldSet(FormFields.Stages))
            {
                waList.Add("stg");
            }

            //Parameter fin (Findings)
            if (searchParams.IsFieldSet(FormFields.Findings))
            {
                waList.Add("fin");
            }

            // Parameter a (Age)
            if (searchParams.IsFieldSet(FormFields.Age))
            {
                waList.Add("a");
            }

            //Parameter q (Keyword/Phrase)
            if (searchParams.IsFieldSet(FormFields.Phrase))
            {
                waList.Add("q");
            }

            // Parameter g (Gender)
            if (searchParams.IsFieldSet(FormFields.Gender))
            {
                waList.Add("g");
            }

            // Parameter loc (Location, and AtNIH if loc=nih)
            if (searchParams.IsFieldSet(FormFields.Location) || searchParams.IsFieldSet(FormFields.IsVAOnly))
            {
                waList.Add("loc");

                if (searchParams.IsVAOnly)
                {
                    waList.Add("va");
                }

                switch (searchParams.Location)
                {
                case LocationType.Zip:
                {
                    ZipCodeLocationSearchParams locParams = (ZipCodeLocationSearchParams)searchParams.LocationParams;
                    if (locParams.IsFieldSet(FormFields.ZipCode))
                    {
                        waList.Add("z");
                    }
                    if (locParams.IsFieldSet(FormFields.ZipRadius))
                    {
                        waList.Add("zp");
                    }
                    break;
                }

                case LocationType.CountryCityState:
                {
                    CountryCityStateLocationSearchParams locParams = (CountryCityStateLocationSearchParams)searchParams.LocationParams;
                    if (locParams.IsFieldSet(FormFields.Country))
                    {
                        waList.Add("lcnty");
                    }
                    if (locParams.IsFieldSet(FormFields.State))
                    {
                        waList.Add("lst");
                    }
                    if (locParams.IsFieldSet(FormFields.City))
                    {
                        waList.Add("lcty");
                    }
                    break;
                }

                case LocationType.Hospital:
                {
                    HospitalLocationSearchParams locParams = (HospitalLocationSearchParams)searchParams.LocationParams;
                    if (locParams.IsFieldSet(FormFields.Hospital))
                    {
                        waList.Add("hos");
                    }
                    break;
                }

                case LocationType.None:
                {
                    //If the user performed a VA search, then leave loc in place.
                    if (!searchParams.IsVAOnly)
                    {
                        waList.Remove("loc");
                    }
                    break;
                }
                } // End switch
            }     // End if

            // Parameter tt (Trial Type)
            if (searchParams.IsFieldSet(FormFields.TrialTypes))
            {
                waList.Add("tt");
            }

            //Parameter d (Drugs)
            if (searchParams.IsFieldSet(FormFields.Drugs))
            {
                waList.Add("d");
            }

            //Parameter i (Other treatments / interventions)
            if (searchParams.IsFieldSet(FormFields.OtherTreatments))
            {
                waList.Add("i");
            }

            //Parameter i (Other treatments / interventions)
            if (searchParams.IsFieldSet(FormFields.HealthyVolunteers))
            {
                waList.Add("hv");
            }

            // Parameter tp (Trial Phase)
            if (searchParams.IsFieldSet(FormFields.TrialPhases))
            {
                waList.Add("tp");
            }

            // Parameter tid (Trial IDs)
            if (searchParams.IsFieldSet(FormFields.TrialIDs))
            {
                waList.Add("tid");
            }

            // Parameter in (Investigator)
            if (searchParams.IsFieldSet(FormFields.Investigator))
            {
                waList.Add("in");
            }

            // Parameter lo (Lead Org)
            if (searchParams.IsFieldSet(FormFields.LeadOrg))
            {
                waList.Add("lo");
            }
        }
Exemple #6
0
        /// <summary>
        /// Helper function to convert between CTSSearchParams and filter criteria for the API
        /// </summary>
        /// <param name="searchParams">The search parameters</param>
        /// <returns>Filter criteria to perform that search</returns>
        public static Dictionary <string, object> ToFilterCriteria(this CTSSearchParams searchParams)
        {
            Dictionary <string, object> filterCriteria = new Dictionary <string, object>();

            //Diseases
            if (searchParams.IsFieldSet(FormFields.MainType))
            {
                filterCriteria.Add("_maintypes", searchParams.MainType.Codes);
            }

            if (searchParams.IsFieldSet(FormFields.SubTypes) && searchParams.SubTypes.Length > 0)
            {
                filterCriteria.Add("_subtypes", searchParams.SubTypes.SelectMany(st => st.Codes).ToArray());
            }

            if (searchParams.IsFieldSet(FormFields.Stages) && searchParams.Stages.Length > 0)
            {
                filterCriteria.Add("_stages", searchParams.Stages.SelectMany(st => st.Codes).ToArray());
            }

            if (searchParams.IsFieldSet(FormFields.Findings) && searchParams.Findings.Length > 0)
            {
                filterCriteria.Add("_findings", searchParams.Findings.SelectMany(st => st.Codes).ToArray());
            }

            //For Sept 2017 SDS release we will combine drug and other using an OR query.  Future releases should
            //use AND between Drugs and Other.
            if (searchParams.IsFieldSet(FormFields.Drugs) || searchParams.IsFieldSet(FormFields.OtherTreatments))
            {
                // Drug and Trial ID's are sent under the same key and should be grouped.
                List <string> drugAndTrialIds = new List <string>();

                if (searchParams.IsFieldSet(FormFields.Drugs) && searchParams.Drugs.Length > 0)
                {
                    drugAndTrialIds.AddRange(searchParams.Drugs.SelectMany(d => d.Codes));
                }
                if (searchParams.IsFieldSet(FormFields.OtherTreatments) && searchParams.OtherTreatments.Length > 0)
                {
                    drugAndTrialIds.AddRange(searchParams.OtherTreatments.SelectMany(ot => ot.Codes));
                }

                if (drugAndTrialIds.Count > 0)
                {
                    filterCriteria.Add("arms.interventions.intervention_code", drugAndTrialIds.ToArray());
                }
            }

            //Add Age Filter
            //<field>_gte, <field>_lte
            if (searchParams.IsFieldSet(FormFields.Age))
            {
                filterCriteria.Add("eligibility.structured.max_age_in_years_gte", searchParams.Age);
                filterCriteria.Add("eligibility.structured.min_age_in_years_lte", searchParams.Age);
            }

            if (searchParams.IsFieldSet(FormFields.Phrase))
            {
                filterCriteria.Add("_fulltext", searchParams.Phrase);
            }

            if (searchParams.IsFieldSet(FormFields.TrialTypes) && searchParams.TrialTypes.Length > 0)
            {
                filterCriteria.Add("primary_purpose.primary_purpose_code", searchParams.TrialTypes.Select(tt => tt.Key).ToArray());
            }

            // Array of strings
            if (searchParams.IsFieldSet(FormFields.TrialPhases) && searchParams.TrialPhases.Length > 0)
            {
                //We must expand the phases into the i_ii and ii_iii trials.
                List <string> phases = new List <string>();

                foreach (string phase in searchParams.TrialPhases.Select(tp => tp.Key))
                {
                    phases.Add(phase.ToLower());

                    switch (phase.ToLower())
                    {
                    case "i":
                    {
                        if (!phases.Contains("i_ii"))
                        {
                            phases.Add("i_ii");
                        }
                        break;
                    }

                    case "ii":
                    {
                        if (!phases.Contains("i_ii"))
                        {
                            phases.Add("i_ii");
                        }
                        if (!phases.Contains("ii_iii"))
                        {
                            phases.Add("ii_iii");
                        }
                        break;
                    }

                    case "iii":
                    {
                        if (!phases.Contains("ii_iii"))
                        {
                            phases.Add("ii_iii");
                        }
                        break;
                    }
                    }
                }

                filterCriteria.Add("phase.phase", phases.ToArray());
            }

            if (searchParams.IsFieldSet(FormFields.Investigator))
            {
                filterCriteria.Add("principal_investigator_fulltext", searchParams.Investigator);
            }

            if (searchParams.IsFieldSet(FormFields.LeadOrg))
            {
                filterCriteria.Add("lead_org_fulltext", searchParams.LeadOrg);
            }

            //Add Healthy Volunteers Filter
            if (searchParams.IsFieldSet(FormFields.HealthyVolunteers) && (searchParams.HealthyVolunteer != HealthyVolunteerType.Any))
            {
                if (searchParams.HealthyVolunteer == HealthyVolunteerType.Healthy)
                {
                    filterCriteria.Add("accepts_healthy_volunteers_indicator", "YES");
                }
                else if (searchParams.HealthyVolunteer == HealthyVolunteerType.Infirmed)
                {
                    filterCriteria.Add("accepts_healthy_volunteers_indicator", "NO");
                }
                //Else there is probably an issue, but we will assume not.
            }

            //Add Gender Filter
            if (searchParams.IsFieldSet(FormFields.Gender))
            {
                filterCriteria.Add("eligibility.structured.gender", searchParams.Gender);
            }

            if (searchParams.IsFieldSet(FormFields.TrialIDs) && searchParams.TrialIDs.Length > 0)
            {
                filterCriteria.Add("_trialids", searchParams.TrialIDs);
            }

            //Add VA Only Filter
            if (searchParams.IsFieldSet(FormFields.IsVAOnly) && searchParams.IsVAOnly)
            {
                filterCriteria.Add("sites.org_va", true);

                //All locations need filtering of active sites.
                //If any other location parameters are being set, it won't add this twice (based on the logic in FilterActiveSites).
                FilterActiveSites(filterCriteria);
            }

            if (searchParams.IsFieldSet(FormFields.Location) && searchParams.Location != LocationType.None)
            {
                switch (searchParams.Location)
                {
                case LocationType.AtNIH:
                {
                    //NIH has their own postal code, so this means @NIH
                    filterCriteria.Add("sites.org_postal_code", "20892");
                    break;
                }

                case LocationType.Hospital:
                {
                    filterCriteria.Add("sites.org_name_fulltext", ((HospitalLocationSearchParams)searchParams.LocationParams).Hospital);
                    break;
                }

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

                    if (locParams.IsFieldSet(FormFields.Country))
                    {
                        filterCriteria.Add("sites.org_country", locParams.Country);
                    }

                    if (locParams.IsFieldSet(FormFields.City))
                    {
                        filterCriteria.Add("sites.org_city", locParams.City);
                    }
                    if (locParams.IsFieldSet(FormFields.State) && locParams.State.Length > 0)
                    {
                        filterCriteria.Add("sites.org_state_or_province", locParams.State.Select(lst => lst.Key).ToArray());
                    }
                    break;
                }

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

                    if (locParams.IsFieldSet(FormFields.ZipCode))
                    {
                        filterCriteria.Add("sites.org_coordinates_lat", locParams.GeoLocation.Lat);
                        filterCriteria.Add("sites.org_coordinates_lon", locParams.GeoLocation.Lon);
                        filterCriteria.Add("sites.org_coordinates_dist", locParams.ZipRadius.ToString() + "mi");
                    }
                    break;
                }

                default:
                {
                    throw new Exception(String.Format("Location type, {0} not supported.", searchParams.Location));
                }
                }
                //All locations need filtering of active sites.
                FilterActiveSites(filterCriteria);
            }

            //This is for only searching open trials.
            filterCriteria.Add("current_trial_status", CTSConstants.ActiveTrialStatuses);

            return(filterCriteria);
        }