<?php
namespace App\Helper;
use App\Entity\CardiometabolicProfiles;
use App\Entity\CardiovascularScore;
use App\Entity\ScoreRisk;
use Doctrine\ORM\EntityManagerInterface;
class HealthHelper
{
public static function getLdlLimit(CardiometabolicProfiles $profile)
{
$afflictions = [
$profile->getMyocardialInfarction(),
$profile->getAnginaPectoris(),
$profile->getCoronaryArteryBypass(),
$profile->getArthritis(),
$profile->getStroke(),
$profile->getAngioplasty()
];
if ($profile->getDiabetes() && in_array(true, $afflictions, true)) {
return 55;
} elseif ($profile->getDiabetes()) {
return 70;
}
return 100;
}
public static function waterCalculation($weight, $sex)
{
$water = $weight / 32;
if ($sex == 2) {
if ($water < 2.5) {
$water = 2.5;
}
if ($water > 3.7) {
$water = 3.7;
}
} else {
if ($water < 2) {
$water = 2;
}
if ($water > 2.7) {
$water = 2.7;
}
}
return number_format($water, 2, '.', '');
}
public static function imcCalculation($height, $weight)
{
$heightTemp = ($height / 100) * ($height / 100);
$imc = $weight / $heightTemp;
$imc = round($imc * 100) / 100.0;
return number_format($imc, 2, '.', '');
}
public static function weightLoss($height, $weight)
{
$heightTemp = ($height / 100) * ($height / 100);
$optimalWeight = $heightTemp * 24.99;
$weightLoss = round($weight - $optimalWeight);
return max($weightLoss, 0);
}
public static function caloriesCalculation($weight, $height, $sex, $age, $physicalActivity, $imc)
{
$calories = (10 * $weight) + (6.25 * $height) - (5 * $age);
if ($sex == 2) {
$calories = $calories + 5;
} else {
$calories = $calories - 161;
}
switch ($physicalActivity) {
case 0:
$calories = $calories * 1.2;
break;
case 1:
$calories = $calories * 1.375;
break;
case 2:
$calories = $calories * 1.55;
break;
case 3:
$calories = $calories * 1.725;
break;
case 4:
$calories = $calories * 1.9;
break;
}
if ($imc < 10) {
$calories = $calories + 800;
} elseif ($imc >= 10 && $imc < 13) {
$calories = $calories + 600;
} elseif ($imc >= 13 && $imc < 16) {
$calories = $calories + 400;
} elseif ($imc >= 16 && $imc < 17) {
$calories = $calories + 200;
} elseif ($imc >= 17 && $imc < 18.5) {
$calories = $calories + 100;
} elseif ($imc >= 25 && $imc < 30) {
$calories = $calories - 200;
} elseif ($imc >= 30 && $imc < 35) {
$calories = $calories - 400;
} elseif ($imc >= 35 && $imc < 40) {
$calories = $calories - 600;
} elseif ($imc >= 40) {
$calories = $calories - 800;
}
$caloriesInteger = round($calories);
return (int)$caloriesInteger;
}
public static function getSex($gender)
{
if ($gender === 1) {
return 'Female';
} else {
return 'Male';
}
}
public static function getScoreRisk(
CardiometabolicProfiles $profile,
?ScoreRisk $selectedScoreRisk,
EntityManagerInterface $em
) {
if ($profile->getDiabetes() && $profile->getTotalCholesterol() > 0 && $profile->getHdlCholesterol() > 0) {
$scoreRisk = $em->getRepository(ScoreRisk::class)->find(2);
}
if (
$profile->getMyocardialInfarction() ||
$profile->getAnginaPectoris() ||
$profile->getCoronaryArteryBypass() ||
$profile->getArthritis() ||
$profile->getAngioplasty() ||
$profile->getStroke()
) {
$scoreRisk = $em->getRepository(ScoreRisk::class)->find(3);
}
if ($scoreRisk && $selectedScoreRisk)
return $scoreRisk->getId() > $selectedScoreRisk->getId() ?
$scoreRisk : $selectedScoreRisk;
return $scoreRisk ?? $selectedScoreRisk;
}
public static function getScore(CardiometabolicProfiles $profile, ?CardiovascularScore $cvdScore, ?ScoreRisk $risk)
{
return $cvdScore?->getScore();
}
public static function parseScoreToArray($score)
{
return $score ? ['score' => $score] : null;
}
public static function diabetStatus($hba1c, $fasting_blood_sugar)
{
$diabetes_status = 0;
if ($hba1c >= 48 && $fasting_blood_sugar >= 126) {
$diabetes_status = 1;
} else if ($hba1c >= 48 || $fasting_blood_sugar >= 126) {
$diabetes_status = 2;
} else {
$diabetes_status = 3;
}
if ($hba1c >= 39 && $hba1c <= 47) {
$diabetes_status = 4;
}
return $diabetes_status;
}
}