API Home dan Linking

This commit is contained in:
2024-04-18 08:46:49 +07:00
parent 666712f015
commit 1f26289b7a
11 changed files with 601 additions and 0 deletions

View File

@@ -11,6 +11,7 @@ use Illuminate\Support\Facades\DB;
use App\Models\Member;
use App\Models\User;
use App\Models\Service;
use App\Models\Icd;
use DateTime;
class Helper
@@ -117,6 +118,16 @@ class Helper
}
}
public static function diagnosisName($code)
{
$icd = Icd::where('code', $code)->get()->first();
if ($icd){
return $icd->name;
} else {
return '-';
}
}
public static function paginateResources($resource)
{
return [
@@ -443,4 +454,23 @@ class Helper
}
}
public static function calculateDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371) {
// Convert degrees to radians
$latFrom = deg2rad($latitudeFrom);
$lonFrom = deg2rad($longitudeFrom);
$latTo = deg2rad($latitudeTo);
$lonTo = deg2rad($longitudeTo);
// Calculate the change in coordinates
$deltaLat = $latTo - $latFrom;
$deltaLon = $lonTo - $lonFrom;
// Apply Haversine formula
$a = sin($deltaLat / 2) * sin($deltaLat / 2) + cos($latFrom) * cos($latTo) * sin($deltaLon / 2) * sin($deltaLon / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
$distance = $earthRadius * $c;
return $distance;
}
}