Merge remote-tracking branch 'origin/master' into mhmfajar
@@ -44,8 +44,15 @@ class DoctorController extends Controller
|
|||||||
$query->whereHas('practitioner.person', function ($person) use ($search) {
|
$query->whereHas('practitioner.person', function ($person) use ($search) {
|
||||||
$person->where('name', 'LIKE', '%' . $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')) {
|
if ($request->has('hospital_id_in')) {
|
||||||
$hospital_ids = explode(',', $request->hospital_id_in);
|
$hospital_ids = explode(',', $request->hospital_id_in);
|
||||||
$doctors->whereIn('organization_id', $hospital_ids);
|
$doctors->whereIn('organization_id', $hospital_ids);
|
||||||
|
|||||||
@@ -38,10 +38,8 @@ class PersonController extends Controller
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Renderable
|
* @return Renderable
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(PersonRequest $request)
|
||||||
{
|
{
|
||||||
$request->validate([]);
|
|
||||||
|
|
||||||
$personData = $request->only([
|
$personData = $request->only([
|
||||||
'owner_user_id',
|
'owner_user_id',
|
||||||
'nik',
|
'nik',
|
||||||
@@ -64,13 +62,18 @@ class PersonController extends Controller
|
|||||||
'main_address_id',
|
'main_address_id',
|
||||||
'domicile_address_id',
|
'domicile_address_id',
|
||||||
]);
|
]);
|
||||||
|
$personData['last_weight_kg'] = $request->weight ?? null;
|
||||||
|
$personData['last_height_cm'] = $request->height ?? null;
|
||||||
$personData = array_merge($personData, [
|
$personData = array_merge($personData, [
|
||||||
'owner_user_id' => auth()->user()->id,
|
'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',
|
'name_suffix',
|
||||||
'phone',
|
'phone',
|
||||||
'email',
|
'email',
|
||||||
'gender',
|
|
||||||
'birth_date',
|
'birth_date',
|
||||||
'birth_place',
|
'birth_place',
|
||||||
'citizenship',
|
'citizenship',
|
||||||
@@ -114,8 +116,12 @@ class PersonController extends Controller
|
|||||||
'main_address_id',
|
'main_address_id',
|
||||||
'domicile_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')) {
|
if ($request->hasFile('user_avatar')) {
|
||||||
$pathFileAvatar = File::storeFile('avatar', $family->id, $request->file('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([
|
$family->familyOwner()->updateOrCreate([
|
||||||
'owner_id' => auth()->user()->person_id,
|
'owner_id' => auth()->user()->person_id,
|
||||||
'person_id' => $family->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)) {
|
} elseif (Gate::forUser(auth()->user())->denies('update-person', $family)) {
|
||||||
abort(Response::HTTP_FORBIDDEN, 'Tidak bisa update karena bukan pemilik!');
|
abort(Response::HTTP_FORBIDDEN, 'Tidak bisa update karena bukan pemilik!');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,43 +18,43 @@ class SpecialityController extends Controller
|
|||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
* @return Renderable
|
* @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;
|
$specialities = Speciality::query()->get();
|
||||||
$specialityId = $request->speciality_id;
|
|
||||||
|
|
||||||
if (empty($organizationId) || empty($specialityId)) {
|
return Helper::responseJson(['specialities' => $specialities]);
|
||||||
$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)]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ class PersonRequest extends FormRequest
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'name_prefix' => 'string',
|
||||||
'name' => 'string',
|
'name' => 'string',
|
||||||
|
'name_suffix' => 'string',
|
||||||
'birth_place' => 'string',
|
'birth_place' => 'string',
|
||||||
'birth_date' => 'date',
|
'birth_date' => 'date',
|
||||||
'gender' => 'string',
|
'gender' => 'string',
|
||||||
@@ -44,22 +46,8 @@ class PersonRequest extends FormRequest
|
|||||||
'verification_file' => 'file', // relasi file table
|
'verification_file' => 'file', // relasi file table
|
||||||
'is_ktp' => 'boolean',
|
'is_ktp' => 'boolean',
|
||||||
'citizenship' => 'string',
|
'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
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,21 +17,30 @@ class PersonResource extends JsonResource
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
|
'name_prefix' => $this->name_prefix,
|
||||||
'name' => $this->name,
|
'name' => $this->name,
|
||||||
|
'name_suffix' => $this->name_suffix,
|
||||||
|
'full_name' => $this->full_name,
|
||||||
'birth_place' => $this->birth_place,
|
'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,
|
'phone' => $this->phone,
|
||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
'blood_type' => $this->blood_type,
|
'blood_type' => $this->blood_type,
|
||||||
'weight' => $this->weight,
|
'weight' => !empty($this->last_weight_kg) ? (float) $this->last_weight_kg : null,
|
||||||
'height' => $this->height,
|
'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,
|
'relation_with_owner' => ($this->user && $this->user->person_id == $this->id) ? 'Self' : $this->pivot->relation_with_owner ?? null,
|
||||||
'marital_status' => $this->marital_status,
|
'marital_status' => $this->marital_status,
|
||||||
'last_education' => $this->last_education,
|
'last_education' => $this->last_education,
|
||||||
'current_employment' => $this->current_employment,
|
'current_employment' => $this->current_employment,
|
||||||
'nik' => $this->nik,
|
'nik' => $this->nik,
|
||||||
'religion' => $this->religion,
|
'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'),
|
'avatar_url' => $this->avatar->url ?? asset('images/default-doctor-avatar.png'),
|
||||||
|
'main_address' => $this->current_address,
|
||||||
|
'domicile_address' => $this->domicile_address,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class File extends Model
|
|||||||
|
|
||||||
public function getUrlAttribute()
|
public function getUrlAttribute()
|
||||||
{
|
{
|
||||||
return url($this->path);
|
return url(Storage::url($this->path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function storeFile($type, $id, $file)
|
public static function storeFile($type, $id, $file)
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ class Person extends Model
|
|||||||
'last_education',
|
'last_education',
|
||||||
'religion',
|
'religion',
|
||||||
'blood_type',
|
'blood_type',
|
||||||
'weight',
|
'last_weight_kg',
|
||||||
'height',
|
'last_height_cm',
|
||||||
'is_deceased',
|
'is_deceased',
|
||||||
'deceased_at',
|
'deceased_at',
|
||||||
'marital_status',
|
'marital_status',
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use App\Traits\Blameable;
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class Speciality extends Model
|
class Speciality extends Model
|
||||||
{
|
{
|
||||||
@@ -20,4 +21,22 @@ class Speciality extends Model
|
|||||||
'code',
|
'code',
|
||||||
'name'
|
'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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |