API Home dan Linking
This commit is contained in:
75
Modules/Linksehat/Http/Controllers/Api/HomeController.php
Normal file
75
Modules/Linksehat/Http/Controllers/Api/HomeController.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Organization;
|
||||
use App\Models\PractitionerRole;
|
||||
use App\Models\OLDLMS\User;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Modules\Linksehat\Transformers\Article\ArticleResource;
|
||||
use Modules\Linksehat\Transformers\Home\HomeResource;
|
||||
use Modules\Linksehat\Transformers\Doctor\DoctorResource;
|
||||
use Modules\Linksehat\Transformers\Hospital\HospitalResource;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = User::with('detail')
|
||||
->where('nId', $request->id)
|
||||
->first();
|
||||
return Helper::responseJson([
|
||||
'home' => HomeResource::make($user, $request),
|
||||
]);
|
||||
}
|
||||
|
||||
public function listHospital(Request $request){
|
||||
// Hospital List
|
||||
$hospitalList = [];
|
||||
$hospitals = Organization::where([
|
||||
'type' => 'hospital',
|
||||
'status' => 'active',
|
||||
])
|
||||
->with('currentAddress')
|
||||
->get()->toArray();
|
||||
foreach($hospitals as $hospital){
|
||||
$lat = 0;
|
||||
$lang = 0;
|
||||
if ($hospital['current_address']['lat']){
|
||||
$lat = $hospital['current_address']['lat'];
|
||||
}
|
||||
if ($hospital['current_address']['lng']){
|
||||
$lang = $hospital['current_address']['lng'];
|
||||
}
|
||||
|
||||
$address = '';
|
||||
if ($hospital['current_address']['text']){
|
||||
$address = $hospital['current_address']['text'];
|
||||
}
|
||||
|
||||
$radius = 0;
|
||||
if ($lat && $lang && $request->longitude && $request->latitude){
|
||||
$radius = round(Helper::calculateDistance($lat, $lang, $request->latitude, $request->longitude), 2);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => $hospital['name'],
|
||||
'radius' => $radius,
|
||||
'image' => '',
|
||||
'address' => $address
|
||||
];
|
||||
|
||||
array_push($hospitalList, $data);
|
||||
}
|
||||
usort($hospitalList, function($a, $b) {
|
||||
return $a['radius'] <=> $b['radius'];
|
||||
});
|
||||
return Helper::responseJson([
|
||||
'hospital' => $hospitalList
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user