src/Controller/DefaultController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\AntibiotiqueRepository;
  4. use App\Repository\CoAntibiotiqueCalculRepository;
  5. use App\Repository\LangueRepository;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. class DefaultController extends AbstractController
  11. {
  12.     private $antibiotiqueRepo;
  13.     private $coAntibiotiqueCalculRepo;
  14.     private $langueRepo;
  15.     public function __construct(
  16.         AntibiotiqueRepository $antibiotiqueRepo,
  17.         CoAntibiotiqueCalculRepository $coAntibiotiqueCalculRepo,
  18.         LangueRepository $langueRepo
  19.     ){
  20.         $this->coAntibiotiqueCalculRepo $coAntibiotiqueCalculRepo;
  21.         $this->antibiotiqueRepo $antibiotiqueRepo;
  22.         $this->langueRepo $langueRepo;
  23.     }
  24.     public function abx_bmi_aide_ios(Request $request)
  25.     {
  26.         return $this->render('aide-ios.html.twig');
  27.     }
  28.     public function abx_bmi_aide(Request $request)
  29.     {
  30.         return $this->render('aide.html.twig');
  31.     }
  32.     public function welcome(Request $request)
  33.     {
  34.         return $this->redirectToRoute('index');
  35.     }
  36.     public function index(Request $request)
  37.     {
  38.         $locale $this->langueRepo->findByCodeLangue($request->getLocale())->getIdLangue();
  39.         $antibiosLangue $this->antibiotiqueRepo->findAllAntibiotiquesActif();
  40.         $antibios = [];
  41.         foreach($antibiosLangue as $atb){
  42.             $atb $this->antibiotiqueRepo->findLibById($locale$atb->getIdAntibiotique());
  43.             array_push($antibios, (!empty($atb))?$atb[0]['libelleAntibiotique']:'');
  44.         }
  45.         sort($antibios);
  46.         
  47.         $antibiogarde null;
  48.         if ($request->get('antibiogarde') != null){
  49.             $antibiogarde $request->get('antibiogarde');
  50.         }
  51.         
  52.         return $this->render('base.html.twig', array('antibiotiques' => $antibios'antibiogarde' => $antibiogarde));
  53.     }
  54.     public function calculDosageModule(Request $requestTranslatorInterface $translator)
  55.     {
  56.         $locale $this->langueRepo->findByCodeLangue($request->getLocale())->getIdLangue();
  57.         $antibiotiqueLib null;
  58.         $antibiotiqueLib $request->get('antibiotique');
  59.         $antibiotiqueId $this->antibiotiqueRepo->findIdAtbByLib($locale$antibiotiqueLib);
  60.         $familleId null;
  61.         $idsFamille $this->antibiotiqueRepo->findIdFamilleByIdAtb($antibiotiqueId);
  62.         if(count($idsFamille) > ){
  63.             foreach($idsFamille as $id){
  64.                 if($this->antibiotiqueRepo->findDoseStandardByIdAtbAndIdFamAtb($locale$antibiotiqueId$id) != []){
  65.                     $familleId $id['idFamilleAntibiotique'];
  66.                 }
  67.             }
  68.         }else {
  69.             $familleId $this->antibiotiqueRepo->findIdFamilleByIdAtb($antibiotiqueId)[0]['idFamilleAntibiotique'];
  70.         }
  71.         $sexe null;
  72.         $sexe $request->get('sexe');
  73.         $poids null;
  74.         $poids $request->get('poids');
  75.         $taille null;
  76.         $taille $request->get('taille');
  77.         $dose null;
  78.         $dose $request->get('dose');
  79.         foreach ($request->request as $key => $value
  80.         {
  81.             switch ($key) {
  82.                 case 'antibiotique':
  83.                     $antibiotiqueId $this->antibiotiqueRepo->findIdAtbByLib($locale$value);
  84.                     $idsFamille $this->antibiotiqueRepo->findIdFamilleByIdAtb($antibiotiqueId);
  85.                     if(count($idsFamille) > ){
  86.                         foreach($idsFamille as $id){
  87.                             if($this->antibiotiqueRepo->findDoseStandardByIdAtbAndIdFamAtb($locale$antibiotiqueId$id) != []){
  88.                                 $familleId $id['idFamilleAntibiotique'];
  89.                             }
  90.                         }
  91.                     }else {
  92.                         $familleId $this->antibiotiqueRepo->findIdFamilleByIdAtb($antibiotiqueId)[0]['idFamilleAntibiotique'];
  93.                     }
  94.                     break;
  95.                 case 'sexe':
  96.                     $sexe $value;
  97.                     break;
  98.                 case 'poids':
  99.                     $poids $value;
  100.                     break;
  101.                 case 'taille':
  102.                     $taille $value;
  103.                     break;
  104.                 case 'dose':
  105.                     $dose $value;
  106.                     break;
  107.                 default:
  108.                     break;
  109.             }
  110.         }
  111.         
  112.         $erreurPoids null;
  113.         $erreurTaille null;
  114.         $erreurDose null;
  115.         $resultat null;
  116.         $erreurPoids = ($poids == '' || $poids == null || $poids == 0) ? ;
  117.         $erreurTaille = ($taille == '' || $taille == null || $taille == 0) ? ;
  118.         $erreurDose = ($dose == '' || $dose == null || $dose == 0) ? ;
  119.         if (!$erreurDose && !$erreurPoids && !$erreurTaille
  120.         {
  121.             $datas $this->algorithmeCalculDosage($antibiotiqueId[0]['idAntibiotique'],$familleId,$sexe,$poids,$taille,$dose$request$translator);
  122.             if ($datas != null
  123.             {
  124.                 $resultat = ['antibiotique' => $antibiotiqueId[0]['idAntibiotique'],'famille' => $familleId'sexe' => $sexe'poids' => $poids'taille' => $taille,'dose' => $dose'datas' => $datas];    
  125.             }
  126.             else
  127.             {
  128.                 $resultat "Aucun calcul pour cet antibiotique.";
  129.             }
  130.     
  131.         }
  132.         return new JsonResponse( array ( 
  133.             'responseCode' => 1,
  134.             'content' => $resultat
  135.         ));
  136.     }
  137.     private function algorithmeCalculDosage($idDci,$idFamille,$sexe,$poids,$taille,$dose,Request $requestTranslatorInterface $translator)
  138.     {
  139.         $em $this->getDoctrine()->getManager();
  140.         $calcul $this->coAntibiotiqueCalculRepo->findAntibiotiqueCalculWithAntibiotiqueAndFamille($idDci,$idFamille); //ex dci:112 - fa:26
  141.         $resultat = array();
  142.         if ($calcul != null
  143.         {
  144.             $situation $calcul->getSituation();
  145.             $libelleAntibiotique $calcul->getAntibiotique()->getlibelleAntibiotique($request->getLocale());
  146.             $libelleFamilleAntibiotique $calcul->getFamilleAntibiotique()->getLibelleFamilleAntibiotique($request->getLocale());
  147.             $resultat["libelleAntibiotique"] = $libelleAntibiotique;
  148.             $resultat["libelleFamilleAntibiotique"] = $libelleFamilleAntibiotique;
  149.             $resultat["dose"] = $dose;
  150.             $resultat["poids"] = $poids;
  151.             $resultat["sexe"] = $sexe;
  152.             $resultat["taille"] = $taille;
  153.             $resultat["situation"] = $situation;
  154.             $references $this->coAntibiotiqueCalculRepo->finReferenceWithIdAntibiotiqueCalcul($calcul->getIdAntibiotiqueCalcul(),$request->getLocale());
  155.             // dd($references);
  156.             $resultat["reference"] = "";
  157.             foreach ($references as $reference
  158.             {
  159.                 if ($reference["documentPDF"] != null && $reference["documentPDF"] != "") {
  160.                     if (preg_match("/https?:\/\//"$reference["documentPDF"],$match)) 
  161.                     {
  162.                         $resultat["reference"] .= '- <a href="'.$reference["documentPDF"].'" target="_blank">'.$reference["texte"].'</a><br/>';
  163.                     }
  164.                     else
  165.                     {
  166.                         $resultat["reference"] .= '- <a href="'.$this->get('router')->generate('abx_bmi_references',array('reference' => $reference["documentPDF"])).'" target="_blank">'.$reference["texte"].'</a><br/>';
  167.                     }
  168.                 }
  169.                 elseif ($reference["texte"] != "") {
  170.                      $resultat["reference"] .= '- '.$reference["texte"].'<br/>';
  171.                 }
  172.             }
  173.             if ($resultat["reference"] == ""
  174.             {
  175.                 $resultat["reference"] = $translator->trans('algorithmeDosage.noReference');
  176.             }
  177.             //******************************
  178.             // Determination de valeur_x_abw
  179.             //******************************
  180.             $valeur_x_abw 0;
  181.             if (is_numeric($calcul->getYDrogue())) {
  182.                 $valeur_x_abw $calcul->getYDrogue();
  183.             }
  184.             $resultat["x_abw"] = $valeur_x_abw;
  185.             //***************************
  186.             // Determination de BMI (kg/m²)
  187.             //***************************
  188.             $bmi = ($poids)/(($taille/100)*($taille/100));
  189.             $bmi $bmi*1;
  190.             $resultat["bmi"] = round($bmi,1);
  191.             //*****************
  192.             // Interprétation BMI
  193.             //*****************
  194.             if (round($bmi,1) < 18.5) {
  195.                 $interpretation_bmi $translator->trans('algorithmeDosage.underweight');
  196.             }
  197.             elseif (round($bmi,1) < 25) {
  198.                 $interpretation_bmi $translator->trans('algorithmeDosage.normalWeight');
  199.             }
  200.             elseif (round($bmi,1) < 30) {
  201.                 $interpretation_bmi $translator->trans('algorithmeDosage.overweight');
  202.             }
  203.             elseif (round($bmi,1) < 35) {
  204.                 $interpretation_bmi $translator->trans('algorithmeDosage.moderateObesityI');
  205.             }
  206.             elseif (round($bmi,1) < 40) {
  207.                 $interpretation_bmi $translator->trans('algorithmeDosage.severeObesityII');
  208.             }
  209.             elseif (round($bmi,1) < 50) {
  210.                 $interpretation_bmi $translator->trans('algorithmeDosage.massiveObesityIII');
  211.             }
  212.             elseif (round($bmi,1) < 60) {
  213.                 $interpretation_bmi $translator->trans('algorithmeDosage.morbidObesity');
  214.             }
  215.             else $interpretation_bmi $translator->trans('algorithmeDosage.superObesity');
  216.             $resultat["interpretation_bmi"] = $interpretation_bmi;
  217.             //******************
  218.             // Poids idéal (IBW)
  219.             //******************
  220.             // homme
  221.             // ARRONDI(2,2*RéglagesHomme +3,5*RéglagesHomme * ((taille/100)-1,5);1)
  222.             // femme
  223.             // ARRONDI(2,2*RéglageFemme  +3,5*RéglagesFemme * ((taille/100)-1,5);1)
  224.             $ibw 0;
  225.             // homme
  226.             if ($sexe == 1) {
  227.                 $ibw round(2.2*22.8+3.5*22.8*(($taille/100)-1.5),1);
  228.                // $ibw = 49.9+(0.89*($taille-152.4));
  229.             }
  230.             // femme
  231.             elseif ($sexe == 2) {
  232.                 $ibw round(2.2*21.3+3.5*21.3*(($taille/100)-1.5),1);
  233.                 // $ibw = 45.4+(0.89*($taille-152.4));
  234.             }    
  235.             $resultat["ibw"] = $ibw;
  236.             
  237.             //*******************
  238.             // Poids ajusté (ABW)
  239.             //*******************
  240.             $abw 0;
  241.             $abw $ibw+$valeur_x_abw*($poids-$ibw);
  242.             $resultat["abw"] = round($abw,1);
  243.             //*******************
  244.             // Poids Maigre (LBW)
  245.             //*******************
  246.             // Homme
  247.             // ARRONDI(9270*poids/(6680+(216*bmi));1)
  248.             // Femme
  249.             // ARRONDI(9270*poids/(8780+(244*bmi));1)
  250.             $lbw 0;
  251.             // homme
  252.             if ($sexe == 1) {
  253.                 $lbw round(9270*$poids/(6680+(216*$bmi)),1);
  254.                // $lbw = (1.1*$poids)-(128*(($poids*$poids)/($taille*$taille)));
  255.             }
  256.             // femme
  257.             elseif ($sexe == 2) {
  258.                 $lbw round(9270*$poids/(8780+(244*$bmi)),1);
  259.                 // $lbw = (1.07*$poids)-(148*(($poids*$poids)/($taille*$taille)));
  260.             }    
  261.             $resultat["lbw"] = $lbw;
  262.             //*******************
  263.             // Recommandation
  264.             //*******************
  265.             $resultat["situation_bmi"] = $translator->trans('algorithmeDosage.BMI') . round($bmi,1) . " ("$interpretation_bmi .")</b>.";
  266.             $resultat["recommandation"] = preg_replace('/<poso ?\/?>(.*?)<\/poso>?/s''$1'$calcul->getAlgorithme($request->getLocale()));
  267.         }
  268.         return $resultat;
  269.     }
  270.     public function checkatb(Request $requestTranslatorInterface $translator)
  271.     {
  272.         $locale $this->langueRepo->findByCodeLangue($request->getLocale())->getIdLangue();
  273.         $antibiotiqueLib $request->get('antibiotique');
  274.         $antibiotiqueId $this->antibiotiqueRepo->findIdAtbByLib($locale$antibiotiqueLib)[0]['idAntibiotique'];
  275.         $idsFamille $this->antibiotiqueRepo->findIdFamilleByIdAtb($antibiotiqueId);
  276.         if(count($idsFamille) > ){
  277.             foreach($idsFamille as $id){
  278.                 if($this->antibiotiqueRepo->findDoseStandardByIdAtbAndIdFamAtb($locale$antibiotiqueId$id) != []){
  279.                     $familleId $id['idFamilleAntibiotique'];
  280.                 }
  281.             }
  282.         }else {
  283.             $familleId $this->antibiotiqueRepo->findIdFamilleByIdAtb($antibiotiqueId)[0]['idFamilleAntibiotique'];
  284.         }
  285.         $datas $this->antibiotiqueRepo->findDoseStandardByIdAtbAndIdFamAtb($locale$antibiotiqueId$familleId);
  286.         if ($datas && $datas!=[] && $datas[0]['doseStandard'] != null
  287.         {
  288.             $resultat $datas[0]['doseStandard'];
  289.         }
  290.         else
  291.         {
  292.             $resultat $translator->trans('checkATB.noStandardDose');
  293.         }
  294.         return new JsonResponse( array ( 
  295.             'responseCode' => 1,
  296.             'content' => $resultat
  297.         ));
  298.     }
  299.     public function mentions_legales(Request $request){        
  300.         return $this->render('mentions-legales.html.twig');
  301.     }
  302.     public function comite_editorial(Request $request){        
  303.         return $this->render('comite-editorial.html.twig');
  304.     }
  305.     public function abx_bmi_comite_editorial(Request $request){        
  306.         return $this->render('abx-bmi-comite-editorial.html.twig');
  307.     }
  308. }