Beispiel #1
0
        public void SetCityHasCityGetCity()
        {
            CountryCityStateLocationSearchParams locParams = new CountryCityStateLocationSearchParams();

            locParams.City = "Baltimore";

            Assert.True(locParams.IsFieldSet("City"));
            Assert.False(locParams.IsFieldSet("State"));
            Assert.False(locParams.IsFieldSet("Country"));
            Assert.Equal("Baltimore", locParams.GetFieldAsString("City"));
        }
Beispiel #2
0
        public void SetCountryHasCountryGetCountry()
        {
            CountryCityStateLocationSearchParams locParams = new CountryCityStateLocationSearchParams();

            locParams.Country = "United States";

            Assert.True(locParams.IsFieldSet("Country"));
            Assert.False(locParams.IsFieldSet("City"));
            Assert.False(locParams.IsFieldSet("State"));
            Assert.Equal("United States", locParams.GetFieldAsString("Country"));
        }
Beispiel #3
0
        public void SetStateHasStateGetState()
        {
            CountryCityStateLocationSearchParams locParams = new CountryCityStateLocationSearchParams();

            locParams.State = new LabelledSearchParam[]
            {
                new LabelledSearchParam()
                {
                    Key   = "MD",
                    Label = "Maryland"
                }
            };

            Assert.True(locParams.IsFieldSet("State"));
            Assert.False(locParams.IsFieldSet("City"));
            Assert.False(locParams.IsFieldSet("Country"));
            Assert.Equal("Maryland", locParams.GetFieldAsString("State"));
        }
Beispiel #4
0
        public void SetAllHasAll()
        {
            CountryCityStateLocationSearchParams locParams = new CountryCityStateLocationSearchParams();

            locParams.Country = "United States";
            locParams.City    = "Baltimore";
            locParams.State   = new LabelledSearchParam[]
            {
                new LabelledSearchParam()
                {
                    Key   = "MD",
                    Label = "Maryland"
                }
            };

            Assert.True(locParams.IsFieldSet("State"));
            Assert.True(locParams.IsFieldSet("City"));
            Assert.True(locParams.IsFieldSet("Country"));
        }
Beispiel #5
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());
        }