Add API
This commit is contained in:
79
Modules/Linksehat/Http/Controllers/Api/ArticleController.php
Normal file
79
Modules/Linksehat/Http/Controllers/Api/ArticleController.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
|
||||
class ArticleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('linksehat::index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('linksehat::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @param Request $request
|
||||
* @return Renderable
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('linksehat::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('linksehat::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -14,22 +14,44 @@ class AuthController extends Controller
|
||||
public function otpRequest(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'phone' => 'required'
|
||||
// 'phone' => 'required'
|
||||
'phone_or_email' => 'required'
|
||||
]);
|
||||
|
||||
if(filter_var($request->phone_or_email, FILTER_VALIDATE_EMAIL)) {
|
||||
$user = User::updateOrCreate([
|
||||
'email' => $request->phone_or_email
|
||||
], [
|
||||
'email' => $request->phone_or_email,
|
||||
'otp' => rand(1000, 9999),
|
||||
'otp_created_at' => now()
|
||||
]);
|
||||
}
|
||||
else {
|
||||
$user = User::updateOrCreate([
|
||||
'phone' => $request->phone
|
||||
], [
|
||||
'phone' => $request->phone,
|
||||
'otp' => rand(1000, 9999),
|
||||
'otp_created_at' => now()
|
||||
]);
|
||||
}
|
||||
|
||||
$user = User::updateOrCreate([
|
||||
'phone' => $request->phone
|
||||
], [
|
||||
'phone' => $request->phone,
|
||||
'otp' => rand(1000, 9999),
|
||||
'otp_created_at' => now()
|
||||
]);
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
'message' => "User dengan nomor telepon ".$request->phone." tidak ditemukan"
|
||||
'message' => filter_var($request->phone_or_email, FILTER_VALIDATE_EMAIL) ?
|
||||
"User dengan alamat email ".$request->phone_or_email." tidak ditemukan" :
|
||||
"User dengan nomor telepon ".$request->phone_or_email." tidak ditemukan"
|
||||
], 404);
|
||||
}
|
||||
|
||||
// TODO Send the OTP
|
||||
if (filter_var($request->phone_or_email, FILTER_VALIDATE_EMAIL)) {
|
||||
// Send Email
|
||||
} else {
|
||||
// Send Whatsapp
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'OTP Terkirim',
|
||||
'data' => [
|
||||
@@ -41,10 +63,12 @@ class AuthController extends Controller
|
||||
public function login(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'email',
|
||||
'password' => 'required_with:email',
|
||||
'phone' => '',
|
||||
'otp' => 'required_with:phone',
|
||||
// 'email' => 'email',
|
||||
// 'password' => 'required_with:email',
|
||||
// 'phone' => '',
|
||||
// 'otp' => 'required_with:phone',
|
||||
'phone_or_email' => 'required',
|
||||
'otp' => 'required'
|
||||
]);
|
||||
|
||||
$loginType = null;
|
||||
|
||||
102
Modules/Linksehat/Http/Controllers/Api/DoctorController.php
Normal file
102
Modules/Linksehat/Http/Controllers/Api/DoctorController.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Practitioner;
|
||||
use App\Models\PractitionerRole;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Linksehat\Transformers\PractitionerRoleToDoctorDetailResource;
|
||||
use Modules\Linksehat\Transformers\PractitionerRoleToDoctorResource;
|
||||
|
||||
class DoctorController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$hospitals = PractitionerRole::query()
|
||||
->with(['practitioner.person', 'speciality', 'practitioner.metas', 'metas', 'organization'])
|
||||
->when($request->search ?? null, function($query, $search) {
|
||||
$query->whereHas('practitioner.person', function($person) use ($search) {
|
||||
$person->where('name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
})
|
||||
->paginate(6);
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Sukses mengambil data Dokter',
|
||||
'doctors' => Helper::paginateResources(PractitionerRoleToDoctorResource::collection($hospitals))
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('linksehat::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @param Request $request
|
||||
* @return Renderable
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$doctor = PractitionerRole::query()
|
||||
->with(['practitioner', 'practitioner.person', 'speciality', 'practitioner.metas', 'metas', 'organization'])
|
||||
->where('id', $id)
|
||||
->firstOrFail();
|
||||
|
||||
return response()->json(PractitionerRoleToDoctorDetailResource::make($doctor));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('linksehat::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Organization;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Linksehat\Transformers\HospitalResource;
|
||||
|
||||
class HospitalController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$hospitals = Organization::query()
|
||||
->with(['currentAddress'])
|
||||
->where('type', 'hospital')
|
||||
->when($request->search ?? null, function($query, $search) {
|
||||
$query->where('name', 'LIKE', '%'.$search.'%');
|
||||
})
|
||||
->paginate(6);
|
||||
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Sukses mengambil data Rumah Sakit',
|
||||
'hospitals' => Helper::paginateResources(HospitalResource::collection($hospitals))
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
* @return Renderable
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('linksehat::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
* @param Request $request
|
||||
* @return Renderable
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$hospital = Organization::query()->findOrFail($id);
|
||||
|
||||
return response()->json(HospitalResource::make($hospital));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('linksehat::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
* @param Request $request
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
* @param int $id
|
||||
* @return Renderable
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Linksehat\Http\Controllers\Api\AuthController;
|
||||
use Modules\Linksehat\Http\Controllers\Api\DoctorController;
|
||||
use Modules\Linksehat\Http\Controllers\Api\HospitalController;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -18,6 +20,17 @@ Route::post('otp-request', [AuthController::class, 'otpRequest']);
|
||||
Route::post('login', [AuthController::class, 'login']);
|
||||
Route::post('register', [AuthController::class, 'register']);
|
||||
|
||||
Route::get('articles', [ArticleController::class, 'index']);
|
||||
Route::get('articles/id', [ArticleController::class, 'show']);
|
||||
|
||||
Route::get('hospitals', [HospitalController::class, 'index']);
|
||||
Route::get('hospitals/{id}', [HospitalController::class, 'show']);
|
||||
|
||||
Route::get('doctors/online', [DoctorController::class, 'index']);
|
||||
Route::get('doctors', [DoctorController::class, 'index']);
|
||||
Route::get('doctors/{id}', [DoctorController::class, 'show']);
|
||||
Route::get('doctors/{id}/schedule', [DoctorController::class, 'schedule']);
|
||||
|
||||
Route::middleware('auth:api')->get('/linksehat', function (Request $request) {
|
||||
return $request->user();
|
||||
});
|
||||
19
Modules/Linksehat/Transformers/DoctorResource.php
Normal file
19
Modules/Linksehat/Transformers/DoctorResource.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Transformers;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DoctorResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
37
Modules/Linksehat/Transformers/HospitalResource.php
Normal file
37
Modules/Linksehat/Transformers/HospitalResource.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Transformers;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class HospitalResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'code' => $this->code,
|
||||
'description' => $this->description,
|
||||
'address' => $this->currentAddress->text ?? null,
|
||||
'lat' => $this->currentAddress->lat ?? null,
|
||||
'lng' => $this->currentAddress->lng ?? null,
|
||||
'distance' => '200 m',
|
||||
'city_name' => 'Kota Tangerang',
|
||||
'phone' => $this->meta->phone,
|
||||
'photo_url' => asset('images/default-hospital-image.png'),
|
||||
'photos' => [
|
||||
[
|
||||
'title' => $this->name,
|
||||
'photo_url' => asset('images/default-hospital-image.png'),
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Transformers;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PractitionerRoleToDoctorDetailResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'full_name' => $this->practitioner->person->full_name ?? null,
|
||||
'name_prefix' => $this->practitioner->person->name_prefix ?? null,
|
||||
'name' => $this->practitioner->person->name ?? null,
|
||||
'name_suffix' => $this->practitioner->person->name_suffix ?? null,
|
||||
'gender' => $this->practitioner->person->gender ?? null,
|
||||
'speciality_name' => !empty($this->speciality->name ?? null) ? 'Spesialis '. $this->speciality->name : 'Spesialis Empty',
|
||||
'is_online' => false,
|
||||
'price_range' => 'Rp 100.000 - Rp 350.000',
|
||||
'price_start' => '100000',
|
||||
'price_end' => '350000',
|
||||
'avatar_url' => asset('images/default-doctor-avatar.png'),
|
||||
'education' => $this->meta->education ?? '',
|
||||
'medical_treatment' => $this->meta->medical_treatment ?? '',
|
||||
'award' => $this->meta->award ?? '',
|
||||
'work_experience' => $this->meta->work_experience ?? '',
|
||||
'keilmuan' => $this->meta->keilmuan ?? '',
|
||||
'description' => $this->meta->description ?? ''
|
||||
];
|
||||
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Transformers;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PractitionerRoleToDoctorResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'full_name' => $this->practitioner->person->full_name,
|
||||
'name_prefix' => $this->practitioner->person->name_prefix,
|
||||
'name' => $this->practitioner->person->name,
|
||||
'name_suffix' => $this->practitioner->person->name_suffix,
|
||||
'gender' => $this->practitioner->person->gender,
|
||||
'speciality_name' => !empty($this->speciality->name ?? null) ? 'Spesialis '. $this->speciality->name : 'Spesialis Empty',
|
||||
'is_online' => false,
|
||||
'price_range' => 'Rp 100.000 - Rp 350.000',
|
||||
'price_start' => '100000',
|
||||
'price_end' => '350000',
|
||||
'avatar_url' => asset('images/default-doctor-avatar.png'),
|
||||
];
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,28 @@ use Illuminate\Database\Eloquent\Model;
|
||||
class Address extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'addressable_type',
|
||||
'addressable_id',
|
||||
'use',
|
||||
'type',
|
||||
'text',
|
||||
'line',
|
||||
'province_id',
|
||||
'city_id',
|
||||
'district_id',
|
||||
'village_id',
|
||||
'postal_code',
|
||||
'country',
|
||||
'lat',
|
||||
'lng',
|
||||
'period_start',
|
||||
'period_end',
|
||||
];
|
||||
|
||||
public function addressable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
}
|
||||
|
||||
22
app/Models/Meta.php
Normal file
22
app/Models/Meta.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Meta extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $fillable = [
|
||||
'system',
|
||||
'type',
|
||||
'value'
|
||||
];
|
||||
|
||||
public function metaable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
}
|
||||
@@ -10,15 +10,55 @@ class Organization extends Model
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
'type',
|
||||
'status',
|
||||
'description',
|
||||
'part_of',
|
||||
'main_address_id',
|
||||
];
|
||||
|
||||
public $with = [
|
||||
'metas'
|
||||
];
|
||||
|
||||
public $appends = [
|
||||
'meta'
|
||||
];
|
||||
|
||||
public function getMetaAttribute()
|
||||
{
|
||||
$orgMeta = [];
|
||||
foreach ($this->metas as $meta) {
|
||||
$orgMeta[$meta->type] = $meta->value;
|
||||
}
|
||||
|
||||
return (object) $orgMeta;
|
||||
}
|
||||
|
||||
public function addresses()
|
||||
{
|
||||
return $this->morphMany(Address::class, 'addressable');
|
||||
}
|
||||
|
||||
public function currentAddress()
|
||||
{
|
||||
return $this->belongsTo(Address::class, 'main_address_id');
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(Organization::class, 'part_of', 'id');
|
||||
}
|
||||
|
||||
public function metas()
|
||||
{
|
||||
return $this->morphMany(Meta::class, 'metaable');
|
||||
}
|
||||
|
||||
public function practitionerRoles()
|
||||
{
|
||||
return $this->hasMany(PractitionerRole::class, 'organization_id');
|
||||
}
|
||||
}
|
||||
|
||||
49
app/Models/Person.php
Normal file
49
app/Models/Person.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Person extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'persons';
|
||||
|
||||
protected $fillable = [
|
||||
'nik',
|
||||
'name_prefix',
|
||||
'name',
|
||||
'name_suffix',
|
||||
'gender',
|
||||
'birth_date',
|
||||
'is_deceased',
|
||||
'deceased_at',
|
||||
'marital_status',
|
||||
];
|
||||
|
||||
public function getFullNameAttribute()
|
||||
{
|
||||
$arr = [];
|
||||
if (!empty($this->name_prefix)) {
|
||||
$arr[] = $this->name_prefix;
|
||||
}
|
||||
$arr[] = $this->name;
|
||||
if (!empty($this->name_suffix)) {
|
||||
$arr[] = $this->name_suffix;
|
||||
}
|
||||
|
||||
return implode(' ', $arr);
|
||||
}
|
||||
|
||||
public function addresses()
|
||||
{
|
||||
return $this->morphMany(Address::class, 'addressable');
|
||||
}
|
||||
|
||||
public function metas()
|
||||
{
|
||||
return $this->morphMany(Meta::class, 'metaable');
|
||||
}
|
||||
}
|
||||
39
app/Models/Practitioner.php
Normal file
39
app/Models/Practitioner.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Practitioner extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'person_id'
|
||||
];
|
||||
|
||||
public $appends = [
|
||||
'meta'
|
||||
];
|
||||
|
||||
public function getMetaAttribute()
|
||||
{
|
||||
$orgMeta = [];
|
||||
foreach ($this->metas as $meta) {
|
||||
$orgMeta[$meta->type] = $meta->value;
|
||||
}
|
||||
|
||||
return (object) $orgMeta;
|
||||
}
|
||||
|
||||
public function person()
|
||||
{
|
||||
return $this->belongsTo(Person::class, 'person_id');
|
||||
}
|
||||
|
||||
public function metas()
|
||||
{
|
||||
return $this->morphMany(Meta::class, 'metaable');
|
||||
}
|
||||
}
|
||||
41
app/Models/PractitionerRole.php
Normal file
41
app/Models/PractitionerRole.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PractitionerRole extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'practitioner_id',
|
||||
'organization_id',
|
||||
'speciality_id',
|
||||
'identifier_id',
|
||||
'period_start',
|
||||
'period_end',
|
||||
'active',
|
||||
];
|
||||
|
||||
public function metas()
|
||||
{
|
||||
return $this->morphMany(Meta::class, 'metaable');
|
||||
}
|
||||
|
||||
public function organization()
|
||||
{
|
||||
return $this->belongsTo(Organization::class, 'organization_id');
|
||||
}
|
||||
|
||||
public function practitioner()
|
||||
{
|
||||
return $this->belongsTo(Practitioner::class, 'practitioner_id');
|
||||
}
|
||||
|
||||
public function speciality()
|
||||
{
|
||||
return $this->belongsTo(Speciality::class, 'speciality_id');
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,13 @@ return new class extends Migration
|
||||
{
|
||||
Schema::create('organizations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('code')->unique();
|
||||
$table->string('name');
|
||||
$table->string('type')->nullable();
|
||||
$table->string('status')->nullable()->default('active');
|
||||
$table->text('description')->nullable();
|
||||
$table->foreignId('part_of')->nullable();
|
||||
$table->foreignId('main_address_id')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
@@ -27,7 +27,16 @@ return new class extends Migration
|
||||
$table->string('postal_code')->nullable();
|
||||
$table->string('rt')->nullable();
|
||||
$table->string('rw')->nullable();
|
||||
$table->string('lat')->nullable();
|
||||
$table->string('lng')->nullable();
|
||||
$table->dateTime('period_start')->nullable();
|
||||
$table->dateTime('period_end')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->foreignId('created_by')->nullable();
|
||||
$table->foreignId('updated_by')->nullable();
|
||||
$table->foreignId('deleted_by')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
41
database/migrations/2022_09_16_045129_create_metas_table.php
Normal file
41
database/migrations/2022_09_16_045129_create_metas_table.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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::create('metas', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->morphs('metaable');
|
||||
$table->string('system')->nullable()->index();
|
||||
$table->string('type')->index();
|
||||
$table->text('value')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->foreignId('created_by')->nullable();
|
||||
$table->foreignId('updated_by')->nullable();
|
||||
$table->foreignId('deleted_by')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('metas');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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::create('practitioners', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('person_id');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->foreignId('created_by')->nullable();
|
||||
$table->foreignId('updated_by')->nullable();
|
||||
$table->foreignId('deleted_by')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('practitioners');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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::create('persons', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nik')->nullable();
|
||||
$table->string('name_prefix')->nullable();
|
||||
$table->string('name')->nullable();
|
||||
$table->string('name_suffix')->nullable();
|
||||
$table->string('gender')->nullable();
|
||||
$table->dateTime('birth_date')->nullable();
|
||||
$table->boolean('is_deceased')->default(0);
|
||||
$table->dateTime('deceased_at')->nullable();
|
||||
$table->string('marital_status')->nullable();
|
||||
$table->foreignId('main_address_id')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->foreignId('created_by')->nullable();
|
||||
$table->foreignId('updated_by')->nullable();
|
||||
$table->foreignId('deleted_by')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('persons');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
<?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::create('practitioner_roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('practitioner_id')->index();
|
||||
$table->foreignId('organization_id')->index();
|
||||
$table->foreignId('speciality_id')->nullable()->index();
|
||||
$table->foreignId('identifier_id')->nullable()->index();
|
||||
$table->dateTime('period_start')->nullable();
|
||||
$table->dateTime('period_end')->nullable();
|
||||
$table->boolean('active')->default(true);
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->foreignId('created_by')->nullable()->index();
|
||||
$table->foreignId('updated_by')->nullable()->index();
|
||||
$table->foreignId('deleted_by')->nullable()->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('practitioner_roles');
|
||||
}
|
||||
};
|
||||
65
database/seeders/OrganizationSeeder.php
Normal file
65
database/seeders/OrganizationSeeder.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Organization;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class OrganizationSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$response = Http::get('http://localhost:8001/temp/organizations');
|
||||
|
||||
foreach ($response->json()['organizations'] as $organization) {
|
||||
$newOrganization = Organization::updateOrCreate([
|
||||
'code' => 'ORG000'.$organization['code'],
|
||||
],[
|
||||
'code' => 'ORG000'.$organization['code'],
|
||||
'name' => $organization['name'],
|
||||
'type' => 'hospital',
|
||||
]);
|
||||
|
||||
$newAddress = $newOrganization->addresses()->updateOrCreate([
|
||||
'id' => $newOrganization->main_address_id
|
||||
],[
|
||||
'use' => 'both',
|
||||
'type' => 'physical',
|
||||
'text' => $organization['address'],
|
||||
'lat' => $organization['lat'],
|
||||
'lng' => $organization['lng'],
|
||||
]);
|
||||
|
||||
$newOrganization->main_address_id = $newAddress->id;
|
||||
$newOrganization->save();
|
||||
|
||||
$newOrganization->metas()->updateOrCreate([
|
||||
'type' => 'KodeRS',
|
||||
], [
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'KodeRS',
|
||||
'value' => $organization['code']
|
||||
]);
|
||||
$newOrganization->metas()->updateOrCreate([
|
||||
'type' => 'phone',
|
||||
],[
|
||||
'system' => 'default',
|
||||
'type' => 'phone',
|
||||
'value' => $organization['phone']
|
||||
]);
|
||||
$newOrganization->metas()->updateOrCreate([
|
||||
'type' => 'timezone',
|
||||
],['system' => 'default',
|
||||
'type' => 'timezone',
|
||||
'value' => $organization['timezone']
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
141
database/seeders/PractitionerSeeder.php
Normal file
141
database/seeders/PractitionerSeeder.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\Person;
|
||||
use App\Models\Practitioner;
|
||||
use App\Models\PractitionerRole;
|
||||
use App\Models\Speciality;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class PractitionerSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$organizations = Organization::with(['metas'])->get();
|
||||
$specialities = Speciality::pluck('id', 'name')->toArray();
|
||||
|
||||
foreach ($organizations as $organization) {
|
||||
$response = Http::get('http://localhost:8001/temp/practitioners?code='.$organization->meta->KodeRS);
|
||||
|
||||
foreach ($response->json()['practitioners'] as $practitioner) {
|
||||
$practitioner = json_decode(json_encode($practitioner));
|
||||
if (!empty($practitioner->meta->NIK)) {
|
||||
$newPerson = Person::updateOrCreate([
|
||||
'nik' => $practitioner->meta->NIK
|
||||
], [
|
||||
'nik' => $practitioner->meta->NIK,
|
||||
'name' => $practitioner->doctor->name,
|
||||
'gender' => $practitioner->doctor->gender,
|
||||
'birth_date' => !empty($practitioner->meta->TanggalLahir) && $practitioner->meta->TanggalLahir != '0000-00-00' ? $practitioner->meta->TanggalLahir : null,
|
||||
]);
|
||||
} else {
|
||||
$newPerson = Person::create([
|
||||
'name' => $practitioner->doctor->name,
|
||||
'gender' => $practitioner->doctor->gender,
|
||||
'birth_date' => !empty($practitioner->meta->TanggalLahir) && $practitioner->meta->TanggalLahir != '0000-00-00' ? $practitioner->meta->TanggalLahir : null,
|
||||
]);
|
||||
}
|
||||
$newPerson->addresses()->create([
|
||||
'use' => 'both',
|
||||
'type' => 'physical',
|
||||
'text' => $practitioner->doctor->address,
|
||||
]);
|
||||
|
||||
$newPractitioner = Practitioner::updateOrCreate([
|
||||
'person_id' => $newPerson->id
|
||||
],[
|
||||
'person_id' => $newPerson->id
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'default',
|
||||
'type' => 'medical_treatment',
|
||||
'value' => $practitioner->doctor->meta->MedicalTreatment ?? null,
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'default',
|
||||
'type' => 'education',
|
||||
'value' => $practitioner->doctor->meta->Education ?? null,
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'default',
|
||||
'type' => 'award',
|
||||
'value' => $practitioner->doctor->meta->Award ?? null,
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'default',
|
||||
'type' => 'work_experience',
|
||||
'value' => $practitioner->doctor->meta->WorkExperience ?? null,
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'alias',
|
||||
'value' => $practitioner->meta->Sapaan ?? null,
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'Keilmuan',
|
||||
'value' => $practitioner->meta->Keilmuan ?? null,
|
||||
]);
|
||||
$newPractitioner->metas()->create([
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'description',
|
||||
'value' => $practitioner->doctor->description ?? null,
|
||||
]);
|
||||
|
||||
|
||||
|
||||
|
||||
$newPractitionerRole = PractitionerRole::create([
|
||||
'practitioner_id' => $newPractitioner->id,
|
||||
'organization_id' => $organization->id,
|
||||
'speciality_id' => $practitioner->speciality ? ($specialities[$practitioner->speciality->name] ?? null) : null,
|
||||
'active' => 1,
|
||||
]);
|
||||
|
||||
if (empty($newPractitionerRole->speciality_id)) {
|
||||
$newPractitionerRole->metas()->updateOrCreate([
|
||||
'type' => 'speciality_code',
|
||||
],[
|
||||
'system' => 'default',
|
||||
'type' => 'speciality_code',
|
||||
'value' => $practitioner->speciality->code ?? null,
|
||||
]);
|
||||
|
||||
$newPractitionerRole->metas()->updateOrCreate([
|
||||
'type' => 'speciality',
|
||||
],[
|
||||
'system' => 'default',
|
||||
'type' => 'speciality',
|
||||
'value' => $practitioner->speciality->name ?? null,
|
||||
]);
|
||||
|
||||
$newPractitionerRole->metas()->updateOrCreate([
|
||||
'type' => 'speciality_image',
|
||||
],[
|
||||
'system' => 'default',
|
||||
'type' => 'speciality_image',
|
||||
'value' => $practitioner->speciality->name ?? null,
|
||||
]);
|
||||
}
|
||||
|
||||
$newPractitionerRole->metas()->updateOrCreate([
|
||||
'type' => 'primaya-his',
|
||||
'type' => 'DokterID',
|
||||
],[
|
||||
'system' => 'primaya-his',
|
||||
'type' => 'DokterID',
|
||||
'value' => $practitioner->meta->DokterID ?? null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Autocomplete, TextField, TextFieldProps } from '@mui/material';
|
||||
import { useState } from 'react';
|
||||
import { Controller, useFormContext } from 'react-hook-form';
|
||||
|
||||
interface IProps {
|
||||
options: any[];
|
||||
name: string;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export default function RHFAutocomplete({ name, options, label, ...other }: IProps & TextFieldProps) {
|
||||
const { control } = useFormContext();
|
||||
console.log(control)
|
||||
|
||||
const [value, setValue] = useState<string | null>(options[0]);
|
||||
const [inputValue, setInputValue] = useState('');
|
||||
|
||||
return (
|
||||
<Controller
|
||||
name={name}
|
||||
control={control}
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<Autocomplete
|
||||
{...field}
|
||||
options={options}
|
||||
value={value}
|
||||
onChange={(event: any, newValue: string | null) => {
|
||||
// console.log('fuck', newValue)
|
||||
setValue(newValue.id);
|
||||
}}
|
||||
inputValue={inputValue}
|
||||
onInputChange={(event, newInputValue) => {
|
||||
setInputValue(newInputValue);
|
||||
}}
|
||||
renderInput={(params) => <TextField {...params} label={label ?? name} />}
|
||||
{...other}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
import { Corporate } from '../../@types/corporates';
|
||||
import axios from '../../utils/axios';
|
||||
import { fCurrency } from '../../utils/formatNumber';
|
||||
import RHFAutocomplete from '../../components/hook-form/RHFAutocomplete';
|
||||
|
||||
const LabelStyle = styled(Typography)(({ theme }) => ({
|
||||
...theme.typography.subtitle2,
|
||||
@@ -256,6 +257,22 @@ export default function CorporateForm({ isEdit, currentCorporate }: Props) {
|
||||
"label" : "Sub Corporate"
|
||||
},
|
||||
]
|
||||
|
||||
const options = [
|
||||
{
|
||||
"label" : "Something",
|
||||
"id" : "Something"
|
||||
},
|
||||
{
|
||||
"label" : "Syalalalal",
|
||||
"id" : "Syalalalal"
|
||||
},
|
||||
{
|
||||
"label" : "Lilili",
|
||||
"id" : "Lilili"
|
||||
},
|
||||
]
|
||||
|
||||
const handleTypeChange = (event: SelectChangeEvent) => {
|
||||
setValue('type', event.target.value)
|
||||
}
|
||||
@@ -269,6 +286,10 @@ export default function CorporateForm({ isEdit, currentCorporate }: Props) {
|
||||
<Card sx={{ p: 3 }}>
|
||||
<Stack spacing={3}>
|
||||
<Grid item xs={12}><Typography variant='h5'>Corporate Profile</Typography></Grid>
|
||||
|
||||
{values.name}
|
||||
|
||||
<RHFAutocomplete name='name' label="Labelnya" options={options} />
|
||||
|
||||
<RHFSelect name="type" label="Type" placeholder="Type">
|
||||
<option value="" />
|
||||
|
||||
BIN
public/images/default-doctor-avatar.png
Normal file
BIN
public/images/default-doctor-avatar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 101 KiB |
BIN
public/images/default-hospital-image.png
Normal file
BIN
public/images/default-hospital-image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
@@ -0,0 +1,3 @@
|
||||
[ZoneTransfer]
|
||||
ZoneId=3
|
||||
HostUrl=https://www.figma.com/
|
||||
Reference in New Issue
Block a user