Example #1
0
 public static function batchGeocode($max_records_to_geocode)
 {
     $count = 0;
     $cached_count = 0;
     $hcps = DB::table(static::$table)->where('geo_cache_id', null)->take(5000)->get();
     $hcps_not_geocoded = [];
     foreach ($hcps as $hcp) {
         Log::debug("HCP ID:" . $hcp->hcp_id);
         list($geo, $cached, $status) = GeoCache::findByAddressOrCreateWithNewnessIndicator(Hcp::getGeocodeAddress($hcp));
         if ($status == 'OK' || $status == 'LOCALLY_CACHED') {
             HcpImport::update($hcp->hcp_id, ['lat' => $geo->lat, 'lng' => $geo->lng, 'geo_cache_id' => $geo->id, 'geo_address' => $geo->address]);
             Log::debug("Geocode OK:", ['hcp_id' => $hcp->hcp_id, 'status' => $status]);
         } else {
             Log::error("Geocode Error:", ['hcp_id' => $hcp->hcp_id, 'address' => Hcp::getGeocodeAddress($hcp), 'status' => $status]);
             $hcps_not_geocoded[] = $hcp;
         }
         if (!$cached) {
             Log::debug("{$count} new geocodes");
             $count++;
         } else {
             Log::debug("{$cached_count} cached geocodes");
             $cached_count++;
         }
         if ($count > $max_records_to_geocode) {
             break;
         }
     }
     return $hcps_not_geocoded;
 }
Example #2
0
 public static function findByAddressOrCreateWithNewnessIndicator($address)
 {
     $geo = GeoCache::getByAddress($address);
     $cached = false;
     Log::debug("Found Geocode Object", ["geo_cache" => $geo]);
     if (!$geo) {
         Log::debug('Address NOT found in geo_cache');
         $resp = Geocode::geocode($address);
         $status = $resp['status'];
         if ($status == 'OK') {
             $id = GeoCache::create(new GeoCache(['address' => $address, 'geocoded_address' => $address, 'lat' => $resp['results'][0]['geometry']['location']['lat'], 'lng' => $resp['results'][0]['geometry']['location']['lng'], 'formatted_address' => $resp['results'][0]['formatted_address'], 'location_type' => $resp['results'][0]['geometry']['location_type'], 'partial_match' => Geocode::getPartialMatchFromResponse($resp)]));
             $geo = GeoCache::get($id);
         } else {
             Log::error('geocoding failed', ['address' => $address, 'response' => $resp]);
         }
     } else {
         Log::debug('Address found in geo_cache');
         $cached = true;
         $status = "LOCALLY_CACHED";
     }
     return [$geo, $cached, $status];
 }
Example #3
0
 public function view_by_location_type($selected_type = 'APPROXIMATE')
 {
     $types = GeoCache::getLocationTypes();
     $types_select = [];
     foreach ($types as $type) {
         $types_select[$type] = $type;
     }
     $hcps = HcpImport::getHcpByLocationType($selected_type, $this->page_size);
     return view('data.view_list', ['hcps' => $hcps, 'types' => $types_select, 'selected_type' => $selected_type]);
 }
Example #4
0
 public static function getHcpByLocationType($location_type, $page_size)
 {
     return DB::table(static::$table)->join(GeoCache::getTable(), GeoCache::getTable() . '.id', '=', static::$table . '.geo_cache_id')->where(GeoCache::getTable() . '.location_type', $location_type)->paginate($page_size);
 }