Merge remote-tracking branch 'origin/master' into mhmfajar

This commit is contained in:
Muhammad Fajar
2022-11-17 16:15:30 +07:00
18 changed files with 132 additions and 69 deletions

View File

@@ -44,8 +44,15 @@ class DoctorController extends Controller
$query->whereHas('practitioner.person', function ($person) use ($search) {
$person->where('name', 'LIKE', '%' . $search . '%');
});
})
->whereHas('speciality');
});
if ($request->has('speciality_id_in')) {
$speciality_ids = explode(',', $request->speciality_id_in);
$doctors->whereIn('speciality_id', $speciality_ids);
} else if ($request->has('speciality_id')) {
$doctors->where('speciality_id', $request->speciality_id);
}
if ($request->has('hospital_id_in')) {
$hospital_ids = explode(',', $request->hospital_id_in);
$doctors->whereIn('organization_id', $hospital_ids);

View File

@@ -38,10 +38,8 @@ class PersonController extends Controller
* @param Request $request
* @return Renderable
*/
public function store(Request $request)
public function store(PersonRequest $request)
{
$request->validate([]);
$personData = $request->only([
'owner_user_id',
'nik',
@@ -64,13 +62,18 @@ class PersonController extends Controller
'main_address_id',
'domicile_address_id',
]);
$personData['last_weight_kg'] = $request->weight ?? null;
$personData['last_height_cm'] = $request->height ?? null;
$personData = array_merge($personData, [
'owner_user_id' => auth()->user()->id,
]);
$personModel = Person::query()->create($personData);
$person = Person::query()->create($personData);
auth()->user()->person->families()->attach($person, [
'relation_with_owner' => $request->relation_with_owner
]);
return Helper::responseJson(['persons' => $personModel], Response::HTTP_CREATED, 'Data berhasil di buat');
return Helper::responseJson(['persons' => new PersonResource($person)], Response::HTTP_CREATED, 'Data berhasil di buat');
}
/**
@@ -100,7 +103,6 @@ class PersonController extends Controller
'name_suffix',
'phone',
'email',
'gender',
'birth_date',
'birth_place',
'citizenship',
@@ -114,8 +116,12 @@ class PersonController extends Controller
'main_address_id',
'domicile_address_id',
]);
$personData['last_weight_kg'] = $request->weight ?? null;
$personData['last_height_cm'] = $request->height ?? null;
$personData['gender'] = $request->has('gender') ? ($request->gender == 'P' ? 'M' : ($request->gender == 'W' ? 'F' : null)) : null;
$family->update($personData);
$family->fill($personData);
$family->save();
if ($request->hasFile('user_avatar')) {
$pathFileAvatar = File::storeFile('avatar', $family->id, $request->file('user_avatar'));
@@ -141,7 +147,7 @@ class PersonController extends Controller
]);
}
if ($request->has('relation_with_owner')) {
if ($request->has('relation_with_owner') && auth()->user()->person_id != $family->id) {
$family->familyOwner()->updateOrCreate([
'owner_id' => auth()->user()->person_id,
'person_id' => $family->id,
@@ -154,7 +160,7 @@ class PersonController extends Controller
]);
}
return Helper::responseJson(data: ['persons' => $family], message: 'Data Berhasil di update');
return Helper::responseJson(data: ['persons' => PersonResource::make($family)], message: 'Data Berhasil di update');
} elseif (Gate::forUser(auth()->user())->denies('update-person', $family)) {
abort(Response::HTTP_FORBIDDEN, 'Tidak bisa update karena bukan pemilik!');
}

View File

@@ -18,43 +18,43 @@ class SpecialityController extends Controller
* Display a listing of the resource.
* @return Renderable
*/
public function index(Request $request)
// public function index(Request $request)
// {
// $organizationId = $request->organization_id;
// $specialityId = $request->speciality_id;
// if (empty($organizationId) || empty($specialityId)) {
// $messageorganizationId = !empty($organizationId) ? ' ' : ' organization_id or ';
// $messageSpecialityId = !empty($specialityId) ? ' ' : 'speciality_id';
// abort(Response::HTTP_BAD_REQUEST, 'Missing Parameter' . $messageorganizationId . $messageSpecialityId);
// }
// $doctors = PractitionerRole::query()
// ->with(['practitioner.person', 'speciality', 'prices'])
// ->whereHas('prices', function ($query) {
// $query->where('priceable_type', Practice::class);
// })
// ->where('organization_id', $organizationId)
// ->where('speciality_id', $specialityId)
// ->get();
// abort_if(count($doctors) === 0, Response::HTTP_NOT_FOUND, 'Data Doctor tidak ditemukan');
// foreach ($doctors as $key => $doctor) {
// $specialisName = $doctor->speciality->name;
// }
// return Helper::responseJson([
// 'title' => 'Spesialis ' . $specialisName,
// 'doctors' => SpecialityResource::collection($doctors)
// ]);
// }
public function index()
{
$organizationId = $request->organization_id;
$specialityId = $request->speciality_id;
$specialities = Speciality::query()->get();
if (empty($organizationId) || empty($specialityId)) {
$messageorganizationId = !empty($organizationId) ? ' ' : ' organization_id or ';
$messageSpecialityId = !empty($specialityId) ? ' ' : 'speciality_id';
abort(Response::HTTP_BAD_REQUEST, 'Missing Parameter' . $messageorganizationId . $messageSpecialityId);
}
$doctors = PractitionerRole::query()
->with(['practitioner.person', 'speciality', 'prices'])
->whereHas('prices', function ($query) {
$query->where('priceable_type', Practice::class);
})
->where('organization_id', $organizationId)
->where('speciality_id', $specialityId)
->get();
abort_if(count($doctors) === 0, Response::HTTP_NOT_FOUND, 'Data Doctor tidak ditemukan');
foreach ($doctors as $key => $doctor) {
$specialisName = $doctor->speciality->name;
}
return Helper::responseJson([
'title' => 'Spesialis ' . $specialisName,
'doctors' => SpecialityResource::collection($doctors)
]);
}
public function listSpeciality()
{
$querySpecialities = Speciality::query()->get(['name']);
return Helper::responseJson(['specialities' => SpecialityResource::collection($querySpecialities)]);
return Helper::responseJson(['specialities' => $specialities]);
}
}

View File

@@ -24,7 +24,9 @@ class PersonRequest extends FormRequest
public function rules()
{
return [
'name_prefix' => 'string',
'name' => 'string',
'name_suffix' => 'string',
'birth_place' => 'string',
'birth_date' => 'date',
'gender' => 'string',
@@ -44,22 +46,8 @@ class PersonRequest extends FormRequest
'verification_file' => 'file', // relasi file table
'is_ktp' => 'boolean',
'citizenship' => 'string',
'main_address_id' => 'numeric',
'domicile_address_id' => 'numeric',
];
}
/**
* Prepare the data for validation.
*
* @return void
*/
protected function prepareForValidation()
{
$citizenship = $this->is_ktp ? 'wni' : 'wna';
$this->merge([
'birth_date' => empty($this->birth_date) ? $this->birth_date . " 00:00:00" : $this->birth_date,
'updated_by' => auth()->user()->id,
'citizenship' => $citizenship ? $citizenship : NULL
]);
}
}

View File

@@ -17,21 +17,30 @@ class PersonResource extends JsonResource
{
return [
'id' => $this->id,
'name_prefix' => $this->name_prefix,
'name' => $this->name,
'name_suffix' => $this->name_suffix,
'full_name' => $this->full_name,
'birth_place' => $this->birth_place,
'gender' => $this->gender,
'birth_date' => $this->birth_date,
'gender' => !empty($this->gender) ? ($this->gender == 'M' ? 'P' : 'W') : null, // For App
'citizenship' => $this->citizenship,
'phone' => $this->phone,
'email' => $this->email,
'blood_type' => $this->blood_type,
'weight' => $this->weight,
'height' => $this->height,
'weight' => !empty($this->last_weight_kg) ? (float) $this->last_weight_kg : null,
'height' => !empty($this->last_weight_kg) ? (float) $this->last_height_cm : null,
'relation_with_owner' => ($this->user && $this->user->person_id == $this->id) ? 'Self' : $this->pivot->relation_with_owner ?? null,
'marital_status' => $this->marital_status,
'last_education' => $this->last_education,
'current_employment' => $this->current_employment,
'nik' => $this->nik,
'religion' => $this->religion,
'is_deceased' => $this->is_deceased == 1,
'deceased_at' => $this->deceased_at,
'avatar_url' => $this->avatar->url ?? asset('images/default-doctor-avatar.png'),
'main_address' => $this->current_address,
'domicile_address' => $this->domicile_address,
];
}
}

View File

@@ -47,7 +47,7 @@ class File extends Model
public function getUrlAttribute()
{
return url($this->path);
return url(Storage::url($this->path));
}
public static function storeFile($type, $id, $file)

View File

@@ -27,8 +27,8 @@ class Person extends Model
'last_education',
'religion',
'blood_type',
'weight',
'height',
'last_weight_kg',
'last_height_cm',
'is_deceased',
'deceased_at',
'marital_status',

View File

@@ -6,6 +6,7 @@ use App\Traits\Blameable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
class Speciality extends Model
{
@@ -20,4 +21,22 @@ class Speciality extends Model
'code',
'name'
];
protected $hidden = [
'created_at',
'updated_at',
'deleted_at',
'created_by',
'updated_by',
'deleted_by',
];
protected $appends = [
'image_url'
];
public function getImageUrlAttribute()
{
return asset('images/specialities/'.Str::slug($this->name, '-').'.png');
}
}

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('persons', function (Blueprint $table) {
$table->float('last_weight_kg', 5, 2, true)->nullable()->after('blood_type');
$table->float('last_height_cm', 5, 2, true)->nullable()->after('blood_type');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('persons', function (Blueprint $table) {
$table->dropColumn('last_weight_kg');
$table->dropColumn('last_height_cm');
});
}
};

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB