Beispiel #1
0
        /// <summary>
        /// Search For MedicalPlaces that have careUnits
        /// </summary>
        /// <param name="latitude">a double precision number</param>
        /// <param name="longitude">a double precision number</param>
        /// <param name="serviceType">a string value</param>
        /// <param name="placeType">a string value</param>
        /// <param name="distance">a boolean value</param>
        /// <param name="cost">a boolean value</param>
        /// <param name="rate">a boolean value</param>
        /// <param name="popularity">a boolean value</param>
        /// <returns>list of medical places that have a careUnit</returns>
        public ICollection <MedicalPlace> SearchCareUnitsPlace(double latitude, double longitude, string serviceType, string placeType, bool distance, bool cost, bool rate, bool popularity)
        {
            List <CareUnit> careUnits             = new List <CareUnit>();
            List <CareUnit> sortedDistance        = new List <CareUnit>();
            List <CareUnit> sortedPopularity      = new List <CareUnit>();
            List <CareUnit> sortedCost            = new List <CareUnit>();
            List <CareUnit> sortedRate            = new List <CareUnit>();
            Dictionary <MedicalPlace, int> result = new Dictionary <MedicalPlace, int>();

            careUnits = DBEntities.CareUnits.Where(careUnit => careUnit.Name == serviceType || careUnit.ProviderID == (DBEntities.MedicalPlaces.SingleOrDefault(medicalPlace => medicalPlace.Name == placeType)).ID).ToList();
            if (distance)
            {
                string point = string.Format("POINT({0} {1})", longitude, latitude);
                sortedDistance = careUnits.OrderBy(careUnit => (DBEntities.MedicalPlaces.SingleOrDefault(place => place.ID == careUnit.ProviderID)).Location.Distance(DbGeography.FromText(point, 4326))).ToList();
            }
            if (rate)
            {
                sortedRate = careUnits.OrderBy(careUnit => careUnit.CareUnitRatings.Average(care => care.Rating)).ToList();
            }
            if (cost)
            {
                sortedCost = careUnits.OrderByDescending(careUnit => careUnit.Cost).ToList();
            }
            int Rate = 0, Cost = 0, Distance = 0, Popularity = 0;

            foreach (CareUnit careUnit in careUnits)
            {
                Distance = sortedDistance.IndexOf(careUnit) == -1 ? 1 : sortedDistance.IndexOf(careUnit) + 1;
                Rate     = sortedRate.IndexOf(careUnit) + 1;
                //Popularity = sortedPopularity.IndexOf(careUnit) + 1;
                Cost = sortedCost.IndexOf(careUnit) + 1;
                MedicalPlace m = (DBEntities.MedicalPlaces.SingleOrDefault(medical => medical.ID == careUnit.ID));
                if (!result.ContainsKey(m))
                {
                    result.Add(m, (int)((1 / Distance * 1.0) + 2 * Cost + 2 * Rate + Popularity));
                }
            }
            return(result.OrderByDescending(res => res.Value).Select(res => res.Key).ToList());
        }
Beispiel #2
0
 /// <summary>
 /// Add new medicalPlace to database in table MedicalPlaces
 /// </summary>
 /// <param name="medicalPlace">A MedicalPlace object</param>
 public void AddMedicalPlace(MedicalPlace medicalPlace)
 {
     DBEntities.MedicalPlaces.Add(medicalPlace);
     DBEntities.SaveChanges();
 }