Exemplo n.º 1
0
 /**
  * Search for a specialty. Returns an array representation of the
  * Specialty model, or false if it's not found.
  *
  * @param string
  * @return instance of Specialty, or false
  */
 private function getSpecialty($query)
 {
     $query = trim(strtolower($query));
     $specialty = Specialty::where('full', 'like', $query)->get()->first();
     if (!empty($specialty)) {
         return $specialty;
     }
     return false;
 }
Exemplo n.º 2
0
 public function index()
 {
     $specialties = \App\Specialty::all();
     return $this->respond(['data' => $this->specialtyTransformer->transformCollection($specialties->all())]);
 }
Exemplo n.º 3
0
 public function search(Request $request)
 {
     $searchDistance = $request->distance ? $request->distance : 0;
     $physicians = null;
     $specialty = null;
     $query = null;
     if ($request->has('code')) {
         $specialty = Specialty::where('code', '=', $request->code)->first();
     } elseif ($request->has('q') && !$request->has('code')) {
         //$physicians = $this->searchWithSpecialty
         $query = $request->q;
     }
     // if we don't have a requested distance, we'll cycle through
     // our fallback distances until we get at least 1 result;
     // if we don't have anything by our max distance, we'll return 0.
     if (!$request->has('distance')) {
         while (empty($physicians) || $physicians->isEmpty()) {
             $searchDistance = $this->getNextDistance($searchDistance);
             if ($specialty) {
                 $physicians = $this->searchWithSpecialty($request, $specialty, $searchDistance);
             } elseif ($query) {
                 $physicians = $this->searchWithQuery($request, $searchDistance);
             } else {
                 // General search
                 $orderBy = $request->has('order_by') ? $request->order_by : 'distance';
                 $sort = $request->has('sort') ? $request->sort : 'asc';
                 $limit = $request->has('per_page') ? $request->per_page : '25';
                 $physicians = Physician::withinRadius($request->lat, $request->lon, $searchDistance)->where('last_name', 'like', $request->name . '%')->orWhere('first_name', 'like', $request->name . '%')->orderBy($orderBy, $sort)->paginate($limit);
             }
             if ($searchDistance == $this->maxDistance) {
                 break;
             }
         }
     } else {
         // We have a distance, so use it
         if ($specialty) {
             $physicians = $this->searchWithSpecialty($request, $specialty, $request->distance);
         } elseif ($query) {
             $physicians = $this->searchWithQuery($request, $request->distance);
         } else {
             //$haversineSelectStmt =
             //$this->haversineSelect($request->lat, $request->lon);
             // General search, with distance
             $orderBy = $request->has('order_by') ? $request->order_by : 'distance';
             $sort = $request->has('sort') ? $request->sort : 'asc';
             $limit = $request->has('per_page') ? $request->per_page : '25';
             $physicians = Physician::withinRadius($request->lat, $request->lon, $searchDistance)->where('last_name', 'like', $request->name . '%')->orWhere('first_name', 'like', $request->name . '%')->orderBy($orderBy, $sort)->paginate($limit);
         }
     }
     $queryMeta = ['city' => urldecode($request->city), 'state' => $request->state, 'zip' => $request->zip ? $request->zip : null, 'specialty' => !empty($specialty) ? $specialty->full : null, 'q' => $request->q, 'count' => $physicians ? count($physicians) : 0, 'radius' => $searchDistance];
     if (!empty($physicians)) {
         return $this->response->withPaginator($physicians, new PhysicianTransformer(), null, $queryMeta);
     }
     $errorMeta = ['meta' => $meta, 'error' => ['code' => 'GEN-NOT-FOUND', 'http_code' => 404, 'message' => 'Physician not found']];
     return $this->response->withArray($errorMeta);
 }
Exemplo n.º 4
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     return Specialty::all();
 }
Exemplo n.º 5
0
 public function index()
 {
     $specialties = Specialty::all();
     return $this->response->withCollection($specialties, new SpecialtyTransformer());
 }