Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
Doctors page (#43)
Browse files Browse the repository at this point in the history
* added slug

* filter doctors by speciality or search

* simple doctor profile page.

* update test

* remove unneded file

* Apply fixes from StyleCI
  • Loading branch information
davidhsianturi committed Feb 23, 2018
1 parent 597ea69 commit 6ef1dbb
Show file tree
Hide file tree
Showing 17 changed files with 181 additions and 224 deletions.
8 changes: 3 additions & 5 deletions app/Filters/DoctorFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

class DoctorFilters extends Filters
{
protected $filters = ['polyclinic'];
protected $filters = ['name'];

protected function polyclinic($polyclinic)
protected function name($full_name)
{
return $this->builder->whereHas('polyclinic', function ($query) use ($polyclinic) {
$query->where('name', $polyclinic);
});
return $this->builder->where('full_name', 'LIKE', "%$full_name%");
}
}
28 changes: 27 additions & 1 deletion app/Http/Controllers/Doctors/DoctorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Doctors;

use App\Models\Doctor\Doctor;
use App\Filters\DoctorFilters;
use App\Http\Controllers\Controller;
use App\Http\Requests\DoctorRequest;
use Illuminate\Support\Facades\Auth;
Expand All @@ -12,7 +13,21 @@ class DoctorController extends Controller
{
public function __construct()
{
$this->middleware(['role:doctor']);
$this->middleware(['role:doctor'])->except(['index', 'show']);
}

public function index(Speciality $speciality, DoctorFilters $filters)
{
$doctors = $this->getDoctors($speciality, $filters);

$specialities = Speciality::all();

return view('doctors.index', compact('doctors', 'specialities'));
}

public function show(Speciality $speciality, Doctor $doctor)
{
return view('doctors.show', compact('doctor'));
}

public function edit()
Expand All @@ -38,4 +53,15 @@ public function update(DoctorRequest $request, Doctor $doctor)

return redirect()->back();
}

protected function getDoctors(Speciality $speciality, DoctorFilters $filters)
{
$doctors = Doctor::with('speciality', 'group')->latest()->filter($filters);

if ($speciality->exists) {
$doctors->where('speciality_id', $speciality->id);
}

return $doctors->paginate(12);
}
}
21 changes: 0 additions & 21 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers;

use App\Models\Doctor\Doctor;
use App\Models\Setting\Group\Group;
use App\Models\Setting\Speciality\Speciality;

Expand All @@ -15,24 +14,4 @@ public function home()
'locations' => Group::all(),
]);
}

public function explore()
{
return view('explore', [
'doctors' => Doctor::with('speciality')->get(),
'groups' => Group::all(),
'specialities' => Speciality::all(),
]);
}

public function search()
{
$search = request('q');

$doctors = Doctor::with('group')
->where('full_name', 'LIKE', "%$search%")
->paginate(10);

return view('search.index', compact('doctors'));
}
}
2 changes: 1 addition & 1 deletion app/Http/Requests/DoctorRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function authorize()
public function rules()
{
return [
'speciality_id' => 'required',
'speciality_id' => 'required|exists:specialities,id',
'full_name' => 'required|string|max:255',
'years_of_experience' => 'required|numeric',
'qualification' => 'required|string|max:25',
Expand Down
26 changes: 18 additions & 8 deletions app/Models/Doctor/Doctor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ class Doctor extends Model
'group_id',
'speciality_id',
'full_name',
'slug',
'years_of_experience',
'qualification',
'bio',
'is_active',
];

// public function getRouteKeyName()
// {
// return 'name';
// }
public function getRouteKeyName()
{
return 'slug';
}

public function user()
{
Expand Down Expand Up @@ -54,8 +55,17 @@ public function healthHistory()
return $this->hasMany('App\Models\Patient\HealthHistory');
}

// public function scopeFilter($query, $filters)
// {
// return $filters->apply($query);
// }
public function setSlugAttribute($value)
{
if (static::whereSlug($slug = str_slug($value))->exists()) {
$slug = "{$slug}-{$this->id}";
}

$this->attributes['slug'] = $slug;
}

public function scopeFilter($query, $filters)
{
return $filters->apply($query);
}
}
7 changes: 5 additions & 2 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

// doctors
$factory->define(App\Models\Doctor\Doctor::class, function (Faker $faker) {
$full_name = $faker->name;

return [
'user_id' => function () {
return factory('App\User')->create()->id;
Expand All @@ -26,10 +28,11 @@
'speciality_id' => function () {
return factory('App\Models\Setting\Speciality\Speciality')->create()->id;
},
'full_name' => $faker->name,
'full_name' => $full_name,
'slug' => str_slug($full_name),
'years_of_experience' => '10',
'qualification' => 'MBBS, MS',
'bio' => $faker->word,
'bio' => $faker->sentence,
'is_active' => true,
];
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function up()
$table->unsignedInteger('group_id');
$table->unsignedInteger('speciality_id')->nullable();
$table->string('full_name')->nullable();
$table->string('slug')->unique()->nullable();
$table->smallInteger('years_of_experience')->nullable();
$table->string('qualification')->nullable();
$table->string('bio')->nullable();
Expand Down
42 changes: 42 additions & 0 deletions resources/views/doctors/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@extends('layouts.master')

@section('title', 'All doctors')

@section('content')
<div class="page-header border-bottom box-shadow-nav">
<div class="container text-secondary">
<a href="/doctors" class="badge badge-info">All</a>
@foreach ($specialities as $speciality)
<a href="/doctors/{{$speciality->slug}}" class="badge badge-info">{{ $speciality->name }}</a>
@endforeach
</div>
</div>

<main class="container">
<div class="row my-3 p-3">

@forelse ($doctors as $doctor)
<div class="col-md-4">
<div class="media">
<img src="{{ asset('img/example-avatar.png') }}" alt="avatar" class="img-responsive mr-2" width="50" height="50">
<p class="media-body pb-3 mb-3">
<a href="/doctors/{{$doctor->speciality->slug}}/{{$doctor->slug}}" class="d-block font-weight-bold">
{{ $doctor->full_name }}
</a>
<a href="/{{$doctor->group->slug}}" class="text-secondary font-weight-light">
{{ $doctor->group->name }}
</a>
</p>
</div>
</div>
@empty
<div class="col-md-12">
<h4 class="text-center">There are no relevant results at this time</h4>
</div>
@endforelse

{{ $doctors->links('vendor.pagination.bootstrap-4') }}

</div>
</main>
@endsection
20 changes: 20 additions & 0 deletions resources/views/doctors/show.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@extends('layouts.master')

@section('title', $doctor->full_name)

@section('content')
<div class="page-header border-bottom box-shadow-nav pb-1">
<div class="container">
<div class="text-center">
<img src="{{ asset('img/example-avatar.png') }}" alt="avatar" class="img-responsive mr-2" width="50" height="50">
<h5 class="pt-2 text-dark">{{$doctor->full_name}}</h5>
</div>
</div>
</div>

<main class="container">
<div class="row my-3 p-3">

</div>
</main>
@endsection
55 changes: 0 additions & 55 deletions resources/views/explore.blade.php

This file was deleted.

7 changes: 2 additions & 5 deletions resources/views/partials/master/navbar.blade.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<div class="navbar-collapse offcanvas-collapse" id="navbarMenu">

<form action="{{ route('search') }}" method="get" class="form-inline mr-auto">
<form action="/doctors" method="get" class="form-inline mr-auto">
<div class="input-group">
<input class="search-input" type="search" name="q" placeholder="find a doctor...">
<input class="search-input" type="search" name="name" placeholder="find a doctor...">
</div>
</form>

<ul class="navbar-nav my-2 my-lg-0">
<li class="nav-item">
<a href="/explore" class="nav-link @yield('explore')">Explore</a>
</li>
@guest
<li class="nav-item">
<a href="/login" class="nav-link">My Account</a>
Expand Down
37 changes: 0 additions & 37 deletions resources/views/search/index.blade.php

This file was deleted.

9 changes: 7 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

// home
Route::get('/', 'HomeController@home');
Route::get('/search', 'HomeController@search')->name('search');
Route::get('/explore', 'HomeController@explore');

// doctor's profile
Route::get('/doctors', 'Doctors\DoctorController@index');
Route::get('/doctors/{speciality}', 'Doctors\DoctorController@index');
Route::get('/doctors/{speciality}/{doctor}', 'Doctors\DoctorController@show');

// schedule an appointment
Route::get('/scheduling/physical-appointment', 'Schedulings\PhysicalAppointmentController@index');

// Authentication default
Expand Down
Loading

0 comments on commit 6ef1dbb

Please sign in to comment.