This commit is contained in:
R
2022-11-07 03:14:52 +07:00
4 changed files with 13 additions and 9 deletions

View File

@@ -43,10 +43,12 @@ class SearchController extends Controller
->when($request->lat && $request->lng, function (EloquentBuilder $query) use ($request) { ->when($request->lat && $request->lng, function (EloquentBuilder $query) use ($request) {
$query->getQuery() $query->getQuery()
->selectRaw("organizations.id, organizations.name, addresses.text AS address, cities.name AS city_name, 6371 * acos (cos ( radians($request->lat) ) * cos( radians( addresses.lat ) ) * cos( radians( addresses.lng ) - radians($request->lng) ) + sin ( radians($request->lat) ) * sin( radians( addresses.lat ) )) as distance") ->selectRaw("organizations.id, organizations.name, addresses.text AS address, cities.name AS city_name, 6371 * acos (cos ( radians($request->lat) ) * cos( radians( addresses.lat ) ) * cos( radians( addresses.lng ) - radians($request->lng) ) + sin ( radians($request->lat) ) * sin( radians( addresses.lat ) )) as distance")
->groupBy(['organizations.id', 'organizations.name', 'addresses.text', 'practitioner_roles.organization_id', 'practitioner_roles.speciality_id', 'addresses.lat', 'addresses.lng', 'cities.name'])
->orderBy('distance', 'ASC'); ->orderBy('distance', 'ASC');
}, function (EloquentBuilder $query) { }, function (EloquentBuilder $query) {
$query->getQuery() $query->getQuery()
->select(['organizations.id', 'organizations.name', 'addresses.text AS address', 'cities.name AS city_name']) ->select(['organizations.id', 'organizations.name', 'addresses.text AS address', 'cities.name AS city_name'])
->groupBy(['organizations.id', 'organizations.name', 'addresses.text', 'practitioner_roles.organization_id', 'practitioner_roles.speciality_id', 'cities.name'])
->orderBy('organizations.name'); ->orderBy('organizations.name');
}) })
->leftJoin('addresses', function (Builder $query) { ->leftJoin('addresses', function (Builder $query) {
@@ -64,7 +66,6 @@ class SearchController extends Controller
->where('specialities.name', 'LIKE', "{$request->value}%") ->where('specialities.name', 'LIKE', "{$request->value}%")
->where('addresses.addressable_type', '=', Organization::class) ->where('addresses.addressable_type', '=', Organization::class)
->whereNot('practitioner_roles.speciality_id') ->whereNot('practitioner_roles.speciality_id')
->groupBy(['practitioner_roles.organization_id', 'practitioner_roles.speciality_id'])
->get(); ->get();
return Helper::responseJson(data: ['hospitals' => HospitalResource::collection($queryHospitals)], message: 'Data rumah sakit berhasil di ambil'); return Helper::responseJson(data: ['hospitals' => HospitalResource::collection($queryHospitals)], message: 'Data rumah sakit berhasil di ambil');

View File

@@ -39,6 +39,8 @@ class SpecialityController extends Controller
->where('speciality_id', $specialityId) ->where('speciality_id', $specialityId)
->get(); ->get();
abort_if(count($doctors) === 0, Response::HTTP_NOT_FOUND, 'Data Doctor tidak ditemukan');
foreach ($doctors as $key => $doctor) { foreach ($doctors as $key => $doctor) {
$specialisName = $doctor->speciality->name; $specialisName = $doctor->speciality->name;
} }

View File

@@ -58,6 +58,6 @@ Route::prefix('linksehat')->group(function () {
Route::middleware('auth:sanctum')->group(function () { Route::middleware('auth:sanctum')->group(function () {
Route::get('profile', [ProfileController::class, 'index'])->name('profile'); Route::get('profile', [ProfileController::class, 'index'])->name('profile');
Route::post('profile', [ProfileController::class, 'update'])->name('profile.update'); Route::post('profile', [ProfileController::class, 'update'])->name('profile.update');
Route::apiResource('persons', PersonController::class)->except(['destroy']); Route::apiResource('families', PersonController::class)->except(['destroy']);
}); });
}); });

View File

@@ -16,20 +16,20 @@ class OrganizationSeeder extends Seeder
*/ */
public function run() public function run()
{ {
$response = Http::get('https://api.primaya.id/temp/organizations'); $response = Http::get('https://app.primaya.id/temp/organizations');
foreach ($response->json()['organizations'] as $organization) { foreach ($response->json()['organizations'] as $organization) {
$newOrganization = Organization::updateOrCreate([ $newOrganization = Organization::updateOrCreate([
'code' => 'ORG000'.$organization['code'], 'code' => 'ORG000' . $organization['code'],
],[ ], [
'code' => 'ORG000'.$organization['code'], 'code' => 'ORG000' . $organization['code'],
'name' => $organization['name'], 'name' => $organization['name'],
'type' => 'hospital', 'type' => 'hospital',
]); ]);
$newAddress = $newOrganization->addresses()->updateOrCreate([ $newAddress = $newOrganization->addresses()->updateOrCreate([
'id' => $newOrganization->main_address_id 'id' => $newOrganization->main_address_id
],[ ], [
'use' => 'both', 'use' => 'both',
'type' => 'physical', 'type' => 'physical',
'text' => $organization['address'], 'text' => $organization['address'],
@@ -49,14 +49,15 @@ class OrganizationSeeder extends Seeder
]); ]);
$newOrganization->metas()->updateOrCreate([ $newOrganization->metas()->updateOrCreate([
'type' => 'phone', 'type' => 'phone',
],[ ], [
'system' => 'default', 'system' => 'default',
'type' => 'phone', 'type' => 'phone',
'value' => $organization['phone'] 'value' => $organization['phone']
]); ]);
$newOrganization->metas()->updateOrCreate([ $newOrganization->metas()->updateOrCreate([
'type' => 'timezone', 'type' => 'timezone',
],['system' => 'default', ], [
'system' => 'default',
'type' => 'timezone', 'type' => 'timezone',
'value' => $organization['timezone'] 'value' => $organization['timezone']
]); ]);