Example #1
0
        private async Task StartProcessingProvidersData(List <PEntity> providers, string networkName, string fileName)
        {
            try
            {
                providerCategories = _importService.GetAllProviderCategories().Result;
                loggers.Debug($"Successfully got the List of Provider categories from DB.");

                specialities = _importService.GetAllSpecialities().Result;
                loggers.Debug($"Successfully got the List of Specialities from DB.");

                for (int i = 0; i < providers.Count; i++)
                {
                    try
                    {
                        DoesProviderHasAllMandatoryFields(providers[i]);
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }
                loggers.Debug($"The file has all mandatory fields data.");
                int counter = 1;
                foreach (var provider in providers)
                {
                    counter = counter + 1;
                    var address = provider.ServiceAddress1 + " " + (string.IsNullOrEmpty(provider.ServiceAddress2) ? " " : provider.ServiceAddress2) +
                                  " " + provider.ServiceCity + " " + provider.ServiceState + " " + provider.ServiceZip.Substring(0, 5);
                    var locationEntity = GeoCoordinateTool.GetLocation(address, System.Configuration.ConfigurationManager.AppSettings["Google_Map_Api_Url"], System.Configuration.ConfigurationManager.AppSettings["Google_Map_Api_Key"]).Result;
                    if (locationEntity != null && string.IsNullOrEmpty(locationEntity.ErrorMessage_GoogleMapAPI) && string.IsNullOrEmpty(locationEntity.Status_GoogleMapAPI))
                    {
                        provider.Latitude  = locationEntity.Latitude.ToString();
                        provider.Longitude = locationEntity.Longitude.ToString();
                    }
                    else
                    {
                        provider.Latitude  = "0";
                        provider.Longitude = "0";
                        loggers.Debug($"Latitude: 0 Longitude: 0 Address:{address} for the ProviderFullName: {provider.ProviderFullName} ProviderFirstName: {provider.ProviderFirstName} ProviderLastName:{provider.ProviderLastName} API_ErrorMessage:{locationEntity.ErrorMessage_GoogleMapAPI} API_Status:{locationEntity.Status_GoogleMapAPI} ");
                    }
                }
                loggers.Debug($"Succesfully updated the latitude and longitude for each provider.");

                int bulkInsertRecordsCount = 0;
                if (System.Configuration.ConfigurationManager.AppSettings["BulkInsertRecordsCount"] != null)
                {
                    bulkInsertRecordsCount = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["BulkInsertRecordsCount"]);
                }

                await _importService.SaveProviderCollection(providers, networkName, fileName, bulkInsertRecordsCount);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public async Task <List <ProviderResultDetails> > GetFilteredOrganizationDetails(string networkCode, string zipCode, int miles, int pageNumber, string specialization, string facility, string providerOrFacilityName, int providerId)
        {
            try
            {
                string collectionName = await _organizationRepository.GetCollectionName(networkCode);

                if (collectionName != null)
                {
                    List <PEntity> providerList = await _providerRepository.GetAllOrganizationDetails(false, collectionName);

                    if (!string.IsNullOrEmpty(facility))
                    {
                        providerList = providerList.Where(provider => provider.ProviderCategory != null && provider.ProviderCategory.ToLower().Equals(facility.ToLower())).ToList();
                    }

                    if (!string.IsNullOrEmpty(specialization))
                    {
                        providerList = providerList.Where(provider => provider.ProviderSpecialityCode != null && provider.ProviderSpecialityCode.ToLower().Equals(specialization.ToLower())).ToList();
                    }

                    if (!string.IsNullOrEmpty(providerOrFacilityName))
                    {
                        providerList = providerList.Where(provider => (provider.ProviderFirstName.ToLower().Contains(providerOrFacilityName.ToLower()) || provider.ProviderLastName.ToLower().Contains(providerOrFacilityName.ToLower()) || provider.ProviderFullName.ToLower().Contains(providerOrFacilityName.ToLower()))).ToList();
                    }

                    List <ProviderResultDetails> ProviderTopSliceList = (from pl in providerList
                                                                         select(new ProviderResultDetails
                    {
                        Id = pl.IdGeneratedNumber,
                        ProviderFirstName = pl.ProviderFirstName,
                        ProviderLastName = pl.ProviderLastName,
                        ProviderFullName = pl.ProviderFullName,
                        LocationPracticeAddress = pl.ServiceAddress1 + " " + (string.IsNullOrEmpty(pl.ServiceAddress2) ? " " : pl.ServiceAddress2) +
                                                  " " + pl.ServiceCity + " " + pl.ServiceState + " " + pl.ServiceZip.Substring(0, 5),
                        ServiceAddress1 = pl.ServiceAddress1,
                        ServiceAddress2 = pl.ServiceAddress2,
                        ServiceCity = pl.ServiceCity,
                        ServiceState = pl.ServiceState,
                        ServiceZip = pl.ServiceZip,
                        Specialization = _providerRepository.GetSpecialityById(pl.ProviderSpecialityCode).Speciality,
                        Facility = string.IsNullOrEmpty(pl.ProviderCategory) ? string.Empty : _providerRepository.GetFacilityById(pl.ProviderCategory).ProviderCategory,
                        PhoneAreaCode = string.IsNullOrEmpty(pl.PhoneAreaCode) ? string.Empty : pl.PhoneAreaCode,
                        PhoneNumber = string.IsNullOrEmpty(pl.PhoneNumber) ? string.Empty : pl.PhoneNumber,
                        PhoneExtension = string.IsNullOrEmpty(pl.PhoneExtension) ? string.Empty : "(" + pl.PhoneExtension + ")",
                        Latitude = string.IsNullOrEmpty(pl.Latitude) ? 0 : Convert.ToDouble(pl.Latitude),
                        Longitude = string.IsNullOrEmpty(pl.Longitude) ? 0 : Convert.ToDouble(pl.Longitude),
                        ProviderType = string.IsNullOrEmpty(pl.ProviderCategory) ? Constants.Ind : _providerRepository.GetFacilityById(pl.ProviderCategory).Type,
                        ProviderCategory = pl.ProviderCategory
                    })).ToList().Where(item => item.Id > providerId).OrderBy(item => item.Id).ToList();

                    var sourceLocation = (dynamic)null;
                    if (!string.IsNullOrEmpty(zipCode))
                    {
                        //Request the Google API when the zipcode has value
                        sourceLocation = await GeoCoordinateTool.GetLocation(zipCode, _configurationKeys.Value.Google_Map_Api_Url, _configurationKeys.Value.Google_Map_Api_Key);
                    }
                    List <ProviderResultDetails> providerResults = new List <ProviderResultDetails>();

                    int counter = 0;
                    foreach (var location in ProviderTopSliceList)
                    {
                        if (counter == _configurationKeys.Value.PaginationLimit)
                        {
                            break;
                        }

                        if (!string.IsNullOrEmpty(zipCode))
                        {
                            Tuple <bool, string> getLocationValues = IsLocationWithInRange(miles, sourceLocation, new LocationEntity()
                            {
                                Latitude = Convert.ToDouble(location.Latitude), Longitude = Convert.ToDouble(location.Longitude)
                            });
                            if (getLocationValues.Item1 == true && getLocationValues != null)
                            {
                                location.RadiusDistance = getLocationValues.Item2;
                                providerResults.Add(location);
                                counter++;
                            }
                        }
                        else
                        {
                            providerResults.Add(location);
                            counter++;
                        }
                    }

                    return(providerResults);
                }
                return(null);
            }
            catch (Exception ex)
            {
                loggers.Error($"{Constants.PWeb} failed to get all filtered organization details.");
                return(null);
            }
        }