From 961be7568d842e883f791448c9c05655f06fd0a4 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 15 Nov 2022 09:02:36 +0700 Subject: [PATCH 1/8] Fix Create Relation to self --- Modules/Linksehat/Http/Controllers/Api/PersonController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Linksehat/Http/Controllers/Api/PersonController.php b/Modules/Linksehat/Http/Controllers/Api/PersonController.php index d6f566bb..d64f8d66 100755 --- a/Modules/Linksehat/Http/Controllers/Api/PersonController.php +++ b/Modules/Linksehat/Http/Controllers/Api/PersonController.php @@ -141,7 +141,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, From 897a531326631339c2dc19cc936165a58b3243be Mon Sep 17 00:00:00 2001 From: R Date: Tue, 15 Nov 2022 10:43:30 +0700 Subject: [PATCH 2/8] Fix Person --- .../Http/Controllers/Api/PersonController.php | 11 ++++-- .../Transformers/Person/PersonResource.php | 15 ++++++-- app/Models/Person.php | 4 +-- ...019_add_height_weight_to_persons_table.php | 34 +++++++++++++++++++ 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 database/migrations/2022_11_15_102019_add_height_weight_to_persons_table.php diff --git a/Modules/Linksehat/Http/Controllers/Api/PersonController.php b/Modules/Linksehat/Http/Controllers/Api/PersonController.php index d64f8d66..28d8abc8 100755 --- a/Modules/Linksehat/Http/Controllers/Api/PersonController.php +++ b/Modules/Linksehat/Http/Controllers/Api/PersonController.php @@ -64,13 +64,15 @@ 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); - return Helper::responseJson(['persons' => $personModel], Response::HTTP_CREATED, 'Data berhasil di buat'); + return Helper::responseJson(['persons' => new PersonResource($personModel)], Response::HTTP_CREATED, 'Data berhasil di buat'); } /** @@ -114,8 +116,11 @@ class PersonController extends Controller 'main_address_id', 'domicile_address_id', ]); + $personData['last_weight_kg'] = $request->weight ?? null; + $personData['last_height_cm'] = $request->height ?? null; - $family->update($personData); + $family->fill($personData); + $family->save(); if ($request->hasFile('user_avatar')) { $pathFileAvatar = File::storeFile('avatar', $family->id, $request->file('user_avatar')); @@ -154,7 +159,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!'); } diff --git a/Modules/Linksehat/Transformers/Person/PersonResource.php b/Modules/Linksehat/Transformers/Person/PersonResource.php index 98fd686e..18acd361 100755 --- a/Modules/Linksehat/Transformers/Person/PersonResource.php +++ b/Modules/Linksehat/Transformers/Person/PersonResource.php @@ -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' => (float) $this->last_weight_kg, + 'height' => (float) $this->last_height_cm, '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, ]; } } diff --git a/app/Models/Person.php b/app/Models/Person.php index dce3ef27..d95d7cc2 100755 --- a/app/Models/Person.php +++ b/app/Models/Person.php @@ -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', diff --git a/database/migrations/2022_11_15_102019_add_height_weight_to_persons_table.php b/database/migrations/2022_11_15_102019_add_height_weight_to_persons_table.php new file mode 100644 index 00000000..c9cfc9ec --- /dev/null +++ b/database/migrations/2022_11_15_102019_add_height_weight_to_persons_table.php @@ -0,0 +1,34 @@ +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'); + }); + } +}; From f71eb71cfc6ef4e8776d7da54cb5f0ecf967b0f0 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 15 Nov 2022 11:07:43 +0700 Subject: [PATCH 3/8] Fix Create --- .../Http/Controllers/Api/PersonController.php | 11 ++++++----- .../Linksehat/Transformers/Person/PersonResource.php | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Modules/Linksehat/Http/Controllers/Api/PersonController.php b/Modules/Linksehat/Http/Controllers/Api/PersonController.php index 28d8abc8..f7fcb33a 100755 --- a/Modules/Linksehat/Http/Controllers/Api/PersonController.php +++ b/Modules/Linksehat/Http/Controllers/Api/PersonController.php @@ -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', @@ -70,9 +68,12 @@ class PersonController extends Controller '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' => new PersonResource($personModel)], Response::HTTP_CREATED, 'Data berhasil di buat'); + return Helper::responseJson(['persons' => new PersonResource($person)], Response::HTTP_CREATED, 'Data berhasil di buat'); } /** diff --git a/Modules/Linksehat/Transformers/Person/PersonResource.php b/Modules/Linksehat/Transformers/Person/PersonResource.php index 18acd361..afd2ddca 100755 --- a/Modules/Linksehat/Transformers/Person/PersonResource.php +++ b/Modules/Linksehat/Transformers/Person/PersonResource.php @@ -28,8 +28,8 @@ class PersonResource extends JsonResource 'phone' => $this->phone, 'email' => $this->email, 'blood_type' => $this->blood_type, - 'weight' => (float) $this->last_weight_kg, - 'height' => (float) $this->last_height_cm, + '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, From 81f25f31de4bd66798ab534addeaf8b7d32f81e1 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 15 Nov 2022 14:05:12 +0700 Subject: [PATCH 4/8] Fix Gender --- Modules/Linksehat/Http/Controllers/Api/PersonController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Linksehat/Http/Controllers/Api/PersonController.php b/Modules/Linksehat/Http/Controllers/Api/PersonController.php index f7fcb33a..271afa66 100755 --- a/Modules/Linksehat/Http/Controllers/Api/PersonController.php +++ b/Modules/Linksehat/Http/Controllers/Api/PersonController.php @@ -103,7 +103,6 @@ class PersonController extends Controller 'name_suffix', 'phone', 'email', - 'gender', 'birth_date', 'birth_place', 'citizenship', @@ -119,6 +118,7 @@ class PersonController extends Controller ]); $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->fill($personData); $family->save(); From cf32be8dd5cf1aa3f382e26d0fb562d08f6ba834 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 15 Nov 2022 16:06:09 +0700 Subject: [PATCH 5/8] Fix Missing Data --- .../Http/Controllers/Api/PersonController.php | 1 + .../Linksehat/Http/Requests/PersonRequest.php | 20 ++++--------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Modules/Linksehat/Http/Controllers/Api/PersonController.php b/Modules/Linksehat/Http/Controllers/Api/PersonController.php index 271afa66..f6da176d 100755 --- a/Modules/Linksehat/Http/Controllers/Api/PersonController.php +++ b/Modules/Linksehat/Http/Controllers/Api/PersonController.php @@ -94,6 +94,7 @@ class PersonController extends Controller */ public function update(PersonRequest $request, Person $family) { + dd($request->toArray()); if (Gate::forUser(auth()->user())->allows('update-person', $family)) { $personData = $request->only([ 'owner_user_id', diff --git a/Modules/Linksehat/Http/Requests/PersonRequest.php b/Modules/Linksehat/Http/Requests/PersonRequest.php index 6e5aec53..67fa9a32 100755 --- a/Modules/Linksehat/Http/Requests/PersonRequest.php +++ b/Modules/Linksehat/Http/Requests/PersonRequest.php @@ -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 - ]); - } } From ca0f7e2fe04e20c9ddad200de308ab7dec8591bf Mon Sep 17 00:00:00 2001 From: R Date: Tue, 15 Nov 2022 16:12:08 +0700 Subject: [PATCH 6/8] Remove Devug --- Modules/Linksehat/Http/Controllers/Api/PersonController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/Linksehat/Http/Controllers/Api/PersonController.php b/Modules/Linksehat/Http/Controllers/Api/PersonController.php index f6da176d..271afa66 100755 --- a/Modules/Linksehat/Http/Controllers/Api/PersonController.php +++ b/Modules/Linksehat/Http/Controllers/Api/PersonController.php @@ -94,7 +94,6 @@ class PersonController extends Controller */ public function update(PersonRequest $request, Person $family) { - dd($request->toArray()); if (Gate::forUser(auth()->user())->allows('update-person', $family)) { $personData = $request->only([ 'owner_user_id', From 9a869968dc11e2fc25f9c71e36f39d2be95c4429 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 15 Nov 2022 16:31:37 +0700 Subject: [PATCH 7/8] Update Storage Url --- app/Models/File.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/File.php b/app/Models/File.php index 44f7207b..86a23473 100755 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -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) From 52e5cdb779c1d022c37ed9f7a19a3c4c19c344f9 Mon Sep 17 00:00:00 2001 From: R Date: Thu, 17 Nov 2022 13:43:40 +0700 Subject: [PATCH 8/8] Fix Doctor By Speciality --- .../Http/Controllers/Api/DoctorController.php | 11 ++- .../Controllers/Api/SpecialityController.php | 72 +++++++++--------- app/Models/Speciality.php | 19 +++++ .../{akupuntur-medik.png => akupunktur.png} | Bin .../specialities/{kids.png => anak.png} | Bin .../{anesthesia.png => anestesi.png} | Bin .../{lungs.png => jantung-pembuluh-darah.png} | Bin .../{cardiologist.png => kardio-vaskuler.png} | Bin .../{obgyn.png => kebidanan-kandungan.png} | Bin ...ulit-dan-kelamin.png => kulit-kelamin.png} | Bin ...krobiologi-klinik.png => laboratorium.png} | Bin .../{ophthalmologist.png => mata.png} | Bin 12 files changed, 64 insertions(+), 38 deletions(-) rename public/images/specialities/{akupuntur-medik.png => akupunktur.png} (100%) rename public/images/specialities/{kids.png => anak.png} (100%) rename public/images/specialities/{anesthesia.png => anestesi.png} (100%) rename public/images/specialities/{lungs.png => jantung-pembuluh-darah.png} (100%) rename public/images/specialities/{cardiologist.png => kardio-vaskuler.png} (100%) rename public/images/specialities/{obgyn.png => kebidanan-kandungan.png} (100%) rename public/images/specialities/{kulit-dan-kelamin.png => kulit-kelamin.png} (100%) rename public/images/specialities/{mikrobiologi-klinik.png => laboratorium.png} (100%) rename public/images/specialities/{ophthalmologist.png => mata.png} (100%) diff --git a/Modules/Linksehat/Http/Controllers/Api/DoctorController.php b/Modules/Linksehat/Http/Controllers/Api/DoctorController.php index 9a483998..405f02d0 100755 --- a/Modules/Linksehat/Http/Controllers/Api/DoctorController.php +++ b/Modules/Linksehat/Http/Controllers/Api/DoctorController.php @@ -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); diff --git a/Modules/Linksehat/Http/Controllers/Api/SpecialityController.php b/Modules/Linksehat/Http/Controllers/Api/SpecialityController.php index 1740cd9d..adf1d8cb 100755 --- a/Modules/Linksehat/Http/Controllers/Api/SpecialityController.php +++ b/Modules/Linksehat/Http/Controllers/Api/SpecialityController.php @@ -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]); } } diff --git a/app/Models/Speciality.php b/app/Models/Speciality.php index 45ae5c39..0e8951eb 100755 --- a/app/Models/Speciality.php +++ b/app/Models/Speciality.php @@ -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'); + } } diff --git a/public/images/specialities/akupuntur-medik.png b/public/images/specialities/akupunktur.png similarity index 100% rename from public/images/specialities/akupuntur-medik.png rename to public/images/specialities/akupunktur.png diff --git a/public/images/specialities/kids.png b/public/images/specialities/anak.png similarity index 100% rename from public/images/specialities/kids.png rename to public/images/specialities/anak.png diff --git a/public/images/specialities/anesthesia.png b/public/images/specialities/anestesi.png similarity index 100% rename from public/images/specialities/anesthesia.png rename to public/images/specialities/anestesi.png diff --git a/public/images/specialities/lungs.png b/public/images/specialities/jantung-pembuluh-darah.png similarity index 100% rename from public/images/specialities/lungs.png rename to public/images/specialities/jantung-pembuluh-darah.png diff --git a/public/images/specialities/cardiologist.png b/public/images/specialities/kardio-vaskuler.png similarity index 100% rename from public/images/specialities/cardiologist.png rename to public/images/specialities/kardio-vaskuler.png diff --git a/public/images/specialities/obgyn.png b/public/images/specialities/kebidanan-kandungan.png similarity index 100% rename from public/images/specialities/obgyn.png rename to public/images/specialities/kebidanan-kandungan.png diff --git a/public/images/specialities/kulit-dan-kelamin.png b/public/images/specialities/kulit-kelamin.png similarity index 100% rename from public/images/specialities/kulit-dan-kelamin.png rename to public/images/specialities/kulit-kelamin.png diff --git a/public/images/specialities/mikrobiologi-klinik.png b/public/images/specialities/laboratorium.png similarity index 100% rename from public/images/specialities/mikrobiologi-klinik.png rename to public/images/specialities/laboratorium.png diff --git a/public/images/specialities/ophthalmologist.png b/public/images/specialities/mata.png similarity index 100% rename from public/images/specialities/ophthalmologist.png rename to public/images/specialities/mata.png