src/Controller/SituationsCliniquesController.php line 150

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Exception;//A voir
  4. use Symfony\Bundle\FrameworkBundle\Controller\Controller;//A voir
  5. use Symfony\Component\HttpFoundation\JsonResponse;//A voir
  6. use App\Entity\Contenu;
  7. use App\Entity\InformationHopital;
  8. use App\Entity\InformationHopitalReferenceHopital;
  9. use App\Entity\Personnalisation;
  10. use App\Entity\PersonnalisationReferenceHopital;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;//A voir
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use Symfony\Component\HttpFoundation\RedirectResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use App\Repository\ATBGRepository;
  16. use App\Repository\AbbreviationLangueRepository;
  17. use App\Repository\AbbreviationRepository;
  18. use App\Repository\ActualiteRepository;
  19. use App\Repository\AntibiotiqueRepository;
  20. use App\Repository\CasCliniquesCategorieRepository;
  21. use App\Repository\CasCliniquesQuestionRepository;
  22. use App\Repository\CasCliniquesReponseRepository;
  23. use App\Repository\CasCliniquesReponseUtilisateurRepository;
  24. use App\Repository\CelluleRepository;
  25. use App\Repository\CelluleTitreCompletRepository;
  26. use App\Repository\CoAntibiotiqueCalculRepository;
  27. use App\Repository\ContenuRepository;
  28. use App\Repository\EtablissementRepository;
  29. use App\Repository\FamilleAntibiotiqueRepository;
  30. use App\Repository\FavorisRepository;
  31. use App\Repository\InformationHopitalRepository;
  32. use App\Repository\InformationReferenceRepository;
  33. use App\Repository\InformationRepository;
  34. use App\Repository\IntervenantSessioneppRepository;
  35. use App\Repository\LangueRepository;
  36. use App\Repository\MicroorganismeRepository;
  37. use App\Repository\NoteRepository;
  38. use App\Repository\ParametreRepository;
  39. use App\Repository\PaysRepository;
  40. use App\Repository\PersonnalisationRepository;
  41. use App\Repository\PersonnalisationSpectreRepository;
  42. use App\Repository\QualiteRepository;
  43. use App\Repository\ReferenceHopitalRepository;
  44. use App\Repository\ReferenceRepository;
  45. use App\Repository\SessioneppRepository;
  46. use App\Repository\SessioneppUrlRepository;
  47. use App\Repository\SpecialiteRepository;
  48. use App\Repository\SpectreRepository;
  49. use App\Repository\TicketPatientRepository;
  50. use App\Repository\TypeInformationRepository;
  51. use App\Repository\UtilisateurRepository;
  52. use App\Repository\VersionRepository;
  53. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  54. use App\Service\EppService;
  55. use App\Service\ContentHandler;
  56. use App\Controller\ReferencesController;
  57. class SituationsCliniquesController extends ATBGController
  58. {
  59.     public function __construct(
  60.         private AbbreviationLangueRepository $abbreviationLangueRepo,
  61.         private AbbreviationRepository $abbreviationRepo,
  62.         private ActualiteRepository $actualiteRepo,
  63.         private AntibiotiqueRepository $antibiotiqueRepo,
  64.         private CasCliniquesCategorieRepository $casCliniquesCategorieRepo,
  65.         private CasCliniquesQuestionRepository $casCliniquesQuestionRepo,
  66.         private CasCliniquesReponseRepository $casCliniquesReponseRepo,
  67.         private CasCliniquesReponseUtilisateurRepository $casCliniquesReponseUtilisateurRepo,
  68.         private CelluleRepository $celluleRepo,
  69.         private CelluleTitreCompletRepository $celluleTitreCompletRepo,
  70.         private CoAntibiotiqueCalculRepository $coAntibiotiqueCalculRepo,
  71.         private ContenuRepository $contenuRepo,
  72.         private EtablissementRepository $etablissementRepo,
  73.         private FamilleAntibiotiqueRepository $familleAntibiotiqueRepository,
  74.         private FavorisRepository $favorisRepo,
  75.         private InformationHopitalRepository $informationHopitalRepo,
  76.         private InformationReferenceRepository $informationReferenceRepo,
  77.         private InformationRepository $informationRepo,
  78.         private IntervenantSessioneppRepository $intervenantSessioneppRepo,
  79.         private LangueRepository $langueRepo,
  80.         private MicroorganismeRepository $microorganismeRepo,
  81.         private NoteRepository $noteRepo,
  82.         private ParametreRepository $parametreRepo,
  83.         private PaysRepository $paysRepo,
  84.         private PersonnalisationRepository $personnalisationRepo,
  85.         private PersonnalisationSpectreRepository $personnalisationSpectreRepo,
  86.         private QualiteRepository $qualiteRepo,
  87.         private ReferenceHopitalRepository $referenceHopitalRepo,
  88.         private ReferenceRepository $referenceRepo,
  89.         private SessioneppRepository $sessioneppRepo,
  90.         private SessioneppUrlRepository $sessioneppUrlRepo,
  91.         private SpecialiteRepository $specialiteRepo,
  92.         private SpectreRepository $spectreRepo,
  93.         private TicketPatientRepository $ticketPatientRepo,
  94.         private TypeInformationRepository $typeInformationRepo,
  95.         private UtilisateurRepository $utilisateurRepo,
  96.         private VersionRepository $versionRepo,
  97.         private TranslatorInterface $translator,
  98.         private ContentHandler $gestionBalises,
  99.         private ReferencesController $referenceService,
  100.         private EppService $eppService,
  101.     ){}
  102.     
  103.     /**
  104.      * Require ROLE_AUTHENTICATED only for this action
  105.      * 
  106.      * @IsGranted("ROLE_AUTHENTICATED")
  107.      */
  108.     public function redirectSituationsCliniques($pathRequest $request) : RedirectResponse
  109.     {
  110.         switch ($this->getTypeCategorieCellule($request)) {
  111.             case $this->getParameter('categorie_situations_cliniques'):
  112.                 return $this->redirect($this->get('router')->generate('situations_cliniques_home') . '#/' $path);
  113.                 break;
  114.             case $this->getParameter('categorie_prophylaxie'):
  115.                 return $this->redirect($this->get('router')->generate('prophylaxie_home') . '#/' $path);
  116.                 break;
  117.             case $this->getParameter('categorie_informations_pratiques'):
  118.                 return $this->redirect($this->get('router')->generate('informations_pratiques_home') . '#/' $path);
  119.                 break;
  120.             case $this->getParameter('categorie_elements_de_gravite'):
  121.                 return $this->redirect($this->get('router')->generate('elements_de_gravite_home') . '#/' $path);
  122.                 break;
  123.             case $this->getParameter('categorie_spectres'):
  124.                 return $this->redirect($this->get('router')->generate('spectres_home') . '#/' $path);
  125.                 break;
  126.             case $this->getParameter('categorie_therapeutique'):
  127.                 return $this->redirect($this->get('router')->generate('therapeutique_home') . '#/' $path);
  128.                 break;
  129.             case $this->getParameter('categorie_prevention_vaccins'):
  130.                 return $this->redirect($this->get('router')->generate('prevention_vaccins_home') . '#/' $path);
  131.                 break;
  132.             case $this->getParameter('categorie_outils_prescriptions'):
  133.                 return $this->redirect($this->get('router')->generate('outils_prescriptions_home') . '#/' $path);
  134.                 break;
  135.         }
  136.     }
  137.     /**
  138.      * Require ROLE_AUTHENTICATED only for this action
  139.      * 
  140.      * @IsGranted("ROLE_AUTHENTICATED")
  141.      */
  142.     public function index(Request $request)
  143.     {
  144.         $returned parent::suppression_parametres_get($request);
  145.         if ($returned != null
  146.         {
  147.             return $returned;
  148.         }
  149.         $type_contenu $this->getTypeCategorieCellule($request);
  150.         return $this->render('SituationsCliniques/index.html.twig', array('type_contenu' => $type_contenu));
  151.     }
  152.     private function getTypeCategorieCellule(Request $request)
  153.     {
  154.         $routeName $request->get('_route');
  155.         $idCategorie 0;
  156.         switch ($routeName
  157.         {
  158.             case 'therapeutique_home':
  159.             case 'therapeutique_home_redirect':
  160.             case 'therapeutique_sommaire_block':
  161.                 $idCategorie $this->getParameter('categorie_therapeutique');
  162.                 break;
  163.             case 'situations_cliniques_node_block':
  164.             case 'situations_cliniques_home':
  165.             case 'situations_cliniques_home_redirect':
  166.             case 'situations_cliniques_sommaire_block':
  167.                 $idCategorie $this->getParameter('categorie_situations_cliniques');
  168.                 break;
  169.             
  170.             case 'prophylaxie_node_block':
  171.             case 'prophylaxie_home':
  172.             case 'prophylaxie_home_redirect':
  173.             case 'prophylaxie_sommaire_block':
  174.                 $idCategorie $this->getParameter('categorie_prophylaxie');
  175.                 break;
  176.             case 'prevention_vaccins_node_block':
  177.             case 'prevention_vaccins_home':
  178.             case 'prevention_vaccins_home_redirect':
  179.             case 'prevention_vaccins_sommaire_block':
  180.                 $idCategorie $this->getParameter('categorie_prevention_vaccins');
  181.                 break;
  182.             case 'outils_prescriptions_node_block':
  183.             case 'outils_prescriptions_home':
  184.             case 'outils_prescriptions_home_redirect':
  185.             case 'outils_prescriptions_sommaire_block':
  186.                 $idCategorie $this->getParameter('categorie_outils_prescriptions');
  187.                 break;
  188.             
  189.             case 'informations_pratiques_node_block':
  190.             case 'informations_pratiques_home':
  191.             case 'informations_pratiques_home_redirect':
  192.             case 'informations_pratiques_sommaire_block':
  193.                 $idCategorie $this->getParameter('categorie_informations_pratiques');
  194.                 break;
  195.             case 'elements_de_gravite_node_block':
  196.             case 'elements_de_gravite_home':
  197.             case 'elements_de_gravite_home_redirect':
  198.             case 'elements_de_gravite_sommaire_block':
  199.                 $idCategorie $this->getParameter('categorie_elements_de_gravite');
  200.                 break;
  201.             default:
  202.                 # code...
  203.                 break;
  204.         }
  205.         return $idCategorie;
  206.     }
  207.     /**
  208.      * Require ROLE_AUTHENTICATED only for this action
  209.      * 
  210.      * @IsGranted("ROLE_AUTHENTICATED")
  211.      */
  212.     public function detailsInformation($informationId$typeRequest $request)
  213.     {
  214.         if ($request->isXmlHttpRequest())
  215.         {
  216.             $em $this->getDoctrine()->getManager();
  217.             if ($type == 'info')
  218.                 $information $this->informationRepo->findInformationWithId($informationId);
  219.             else
  220.                 $information $this->informationHopitalRepo->find($informationId);
  221.             $session $request->getSession();
  222.             if ($type == 'info')
  223.                 $informationsReferences $this->informationReferenceRepo->findInformationReferenceFromInformation($information);
  224.             else
  225.                 $informationsReferences $information->getReferencesHopital();
  226.             $references = array();
  227.             foreach ($informationsReferences as $infoRef)
  228.             {
  229.                 if ($type == 'info')
  230.                     $references[] = $infoRef->getReference();
  231.                 else
  232.                     $references[] = $infoRef->getReferenceHopital();
  233.             }
  234.             $personnalisation null;
  235.             if ($type == 'info')
  236.             {
  237.                 $personnalisation $this->personnalisationRepo->findOneBy(array('clientIdAdada' => $session->get('client_id_adada'),'Information' => $information));
  238.                 if ($personnalisation != null)
  239.                 {
  240.                     $references = array();
  241.                     foreach ($personnalisation->getReferencesHopital() as $infoRef)
  242.                     {
  243.                         $references[] = $infoRef->getReferenceHopital();
  244.                     }
  245.                 }
  246.             }
  247.             return $this->render('SituationsCliniques/detail-informations.html.twig',array('personnalisation' => $personnalisation,
  248.                 'information'=>$information,
  249.                 'references'=>$references,
  250.                 'type' => $type));
  251.         } else throw $this->createNotFoundException();
  252.     }
  253.     /**
  254.      * Require ROLE_AUTHENTICATED only for this action
  255.      * 
  256.      * @IsGranted("ROLE_AUTHENTICATED")
  257.      */
  258.     public function displayNode($nodeIdRequest $request)
  259.     {
  260.         if ($request->isXmlHttpRequest())
  261.         {
  262.             $idCategorie $this->getTypeCategorieCellule($request);
  263.             $em $this->getDoctrine()->getManager();
  264.             $session $request->getSession();
  265.             $client_id_adada $session->get('client_id_adada');
  266.             $pays_code $this->parametreRepo->findParametrePaysCode($client_id_adada);
  267.             if($client_id_adada == null && $this->getParameter('version_antibiogarde') == 'web_edition') { 
  268.                 $pays $this->paysRepo->findPaysWithLocale($session->get('_locale'));
  269.                 if($pays != null$pays_code $pays->getCodePays();
  270.             }
  271.             
  272.             $antibiotiques null;
  273.             // $antibiotiques = null;
  274.             $cellule $this->celluleRepo->findCelluleWithIdCelluleAndCategorie($nodeId,$idCategorie,$pays_code);
  275.             if($cellule != NULL) {
  276.                 if($cellule->getOrdre() == '999' || $cellule->getOrdre() == '998') {
  277.                     try{
  278.                         $antibiotiques $this->familleAntibiotiqueRepository->findAntibiotiqueGpr(null,$session->get('_locale'));
  279.                     }
  280.                     catch(Exception $e){
  281.                         $antibiotiques $e->getMessage();
  282.                     }
  283.                 }
  284.                 elseif($cellule->getOrdre() == '996') {
  285.                     $boutique_adada $this->container->get('doctrine')->getConnection('adada');
  286.                     $stmt $boutique_adada->prepare("SELECT client_vidal as connexion_vidal, client_cbip as connexion_cbip FROM ADADA_CLIENT WHERE client_id = :client_id");
  287.                     $stmt->bindValue('client_id'$client_id_adada);
  288.                     $stmt $stmt->execute();
  289.                     $result $stmt->fetchAll();
  290.                     if (count($result) == 1){
  291.                         $vidal = (bool) $result[0]['connexion_vidal'];
  292.                         $cbip = (bool) $result[0]['connexion_cbip'];
  293.                     }
  294.                     try{
  295.                         $antibiotiques $this->familleAntibiotiqueRepository->findAntibiotiqueCbipVidal(null,$session->get('_locale'), $vidal$cbip$pays_code);
  296.                     }
  297.                     catch(Exception $e){
  298.                         $antibiotiques $e->getMessage();
  299.                     }
  300.                 }
  301.             }
  302.             $parents = array();
  303.             $content '';
  304.             $isTrueNode true;
  305.             if ($cellule != null /*&& $cellule->getOrdre() != '999'*/
  306.             {
  307.                 foreach ($cellule->getCellulesPeres() as $cellule_pere
  308.                 {
  309.                     if ($cellule_pere->getCategorieCellule() == $cellule->getCategorieCellule()) 
  310.                     {
  311.                         $parents[] = $cellule_pere->getIdCellule();
  312.                     }
  313.                     if($cellule_pere->getAfficherFils() == 1)
  314.                     {
  315.                         foreach ($cellule_pere->getCellulesPeres() as $cellule_pere_pere
  316.                         {
  317.                             if ($cellule_pere_pere->getCategorieCellule() == $cellule->getCategorieCellule()) 
  318.                             {
  319.                                 $parents[] = $cellule_pere_pere->getIdCellule();
  320.                             }
  321.                         }
  322.                     }
  323.                 }
  324.                 $pays $this->paysRepo->findPaysWithCodePays($pays_code);
  325.                 $content $this->render('SituationsCliniques/situation-clinique.html.twig', array('antibiotiques' => $antibiotiques'situation' => $cellule'pays' => $pays))->getContent();
  326.             }
  327.             else
  328.             {
  329.                 $isTrueNode false;
  330.             }
  331.             
  332.             return new JsonResponse( array ( 
  333.                 'responseCode' => 0,
  334.                 'nodeId' => $nodeId*1,
  335.                 'content' => $content,
  336.                 'isTrueNode' => $isTrueNode,
  337.                 'parentNodes' => $parents
  338.              ));
  339.         } else throw $this->createNotFoundException();
  340.     }
  341.     /**
  342.      * Require ROLE_AUTHENTICATED only for this action
  343.      * 
  344.      * @IsGranted("ROLE_AUTHENTICATED")
  345.      */
  346.     public function displayReferences($nodeIdRequest $request)
  347.     {
  348.         if ($request->isXmlHttpRequest())
  349.         {
  350.             $session $request->getSession();
  351.             $client_id_adada $session->get('client_id_adada');
  352.             $em $this->getDoctrine()->getManager();
  353.             $pays_code $this->parametreRepo->findParametrePaysCode($client_id_adada);
  354.             if($client_id_adada == null && $this->getParameter('version_antibiogarde') == 'web_edition') { 
  355.                 $pays $this->paysRepo->findPaysWithLocale($session->get('_locale'));
  356.                 if($pays != null$pays_code $pays->getCodePays();
  357.             }
  358.             $references $this->referenceRepo->findReferencesWithNodeId($nodeId,$pays_code);
  359.             $references_locales $this->referenceRepo->findReferencesHopitalWithNodeId($nodeId,$client_id_adada);
  360.             $content $this->render('SituationsCliniques/references.html.twig', array('idcellule' => $nodeId'references' => $references,'references_locales' => $references_locales))->getContent();
  361.             
  362.             return new JsonResponse( array ( 
  363.                 'responseCode' => 0,
  364.                 'nodeId' => $nodeId*1,
  365.                 'content' => $content,
  366.              ));
  367.         } else throw $this->createNotFoundException();
  368.     }
  369.     /**
  370.      * Require ROLE_AUTHENTICATED only for this action
  371.      * 
  372.      * @IsGranted("ROLE_AUTHENTICATED")
  373.      */
  374.     public function displaySommaire(Request $request$selectedId)
  375.     {
  376.         if ($request->isXmlHttpRequest())
  377.         {
  378.             $session $request->getSession();
  379.             $client_id_adada $session->get('client_id_adada');
  380.             $em $this->getDoctrine()->getManager();
  381.             $pays_code $this->parametreRepo->findParametrePaysCode($client_id_adada);
  382.             if($client_id_adada == null && $this->getParameter('version_antibiogarde') == 'web_edition') { 
  383.                 $pays $this->paysRepo->findPaysWithLocale($session->get('_locale'));
  384.                 if($pays != null$pays_code $pays->getCodePays();
  385.             }
  386.             $idCategorie $this->getTypeCategorieCellule($request);
  387.             $parents $this->celluleRepo->getSommaire($idCategorie,$session->get("_locale"),$pays_code);
  388.             $content $this->render('SituationsCliniques/situation-clinique-sommaire-titre.html.twig', array('type_contenu' => $idCategorie))->getContent();
  389.             foreach ($parents as $cellule) {
  390.                 if($cellule->getOrdre() == 997 || $cellule->getOrdre() == 995){
  391.                     $contentFictif = new Contenu();
  392.                     $cellule->addContenus($contentFictif);
  393.                     $content .= $this->render('SituationsCliniques/situation-clinique-sommaire.html.twig', array('cellule' => $cellule'selectedId' => $selectedId))->getContent();
  394.                 }
  395.                 // Pour la cellule BASE DE DONNEES RCP dans le menu "outils de prescription", si le client Ã  cocher connexion vidal ou cbip, on lui affiche le menu
  396.                 elseif($cellule->getOrdre() == 996) {
  397.                     //if ($this->container->getParameter('version_antibiogarde') == 'web_hopital')                 
  398.                     $boutique_adada $this->container->get('doctrine')->getConnection('adada');
  399.                     $stmt $boutique_adada->prepare("SELECT client_vidal as connexion_vidal, client_cbip as connexion_cbip FROM ADADA_CLIENT WHERE client_id = :client_id");
  400.                     $stmt->bindValue('client_id'$client_id_adada);
  401.                     $stmt $stmt->execute();
  402.                     $result $stmt->fetchAll();
  403.                     if (count($result) == 1){
  404.                         $vidal = (bool) $result[0]['connexion_vidal'];
  405.                         $cbip = (bool) $result[0]['connexion_cbip'];
  406.                         if($vidal == true || $cbip == true) {
  407.                             $content .= $this->render('SituationsCliniques/situation-clinique-sommaire.html.twig', array('cellule' => $cellule'selectedId' => $selectedId))->getContent();
  408.                         }
  409.                     }
  410.                 }
  411.                 else{
  412.                     $content .= $this->render('SituationsCliniques/situation-clinique-sommaire.html.twig', array('cellule' => $cellule'selectedId' => $selectedId))->getContent();
  413.                 }
  414.             }
  415.             return new JsonResponse( array ( 
  416.                 'responseCode' => 0,
  417.                 'content' => $content
  418.             ));
  419.         } else throw $this->createNotFoundException();
  420.     }
  421.     /**
  422.      * Require ROLE_AUTHENTICATED only for this action
  423.      * 
  424.      * @IsGranted("ROLE_AUTHENTICATED")
  425.      */
  426.     public function contenuAntibiotique(Request $request$id$parentId)
  427.     {
  428.         if ($request->isXmlHttpRequest())
  429.         {
  430.             // $idCategorie = $this->getTypeCategorieCellule($request);
  431.             $session $request->getSession();
  432.             $client_id_adada $session->get('client_id_adada');
  433.             $em $this->getDoctrine()->getManager();
  434.             $pays_code $this->parametreRepo->findParametrePaysCode($client_id_adada);
  435.             if($client_id_adada == null && $this->getParameter('version_antibiogarde') == 'web_edition') { 
  436.                 $pays $this->paysRepo->findPaysWithLocale($session->get('_locale'));
  437.                 if($pays != null$pays_code $pays->getCodePays();
  438.             }
  439.             $antibiotique $this->antibiotiqueRepo->find($id);
  440.             // foreach($antibiotique->getFamillesAntibiotiques() as $famille){
  441.             //     dump($famille);
  442.             //     die();
  443.             // }
  444.             $famille $antibiotique->getFamillesAntibiotiques()[0];
  445.             $cellulePere $this->celluleRepo->findCelluleWithIdCellule($parentId);
  446.             if($cellulePere->getOrdre() == 996){                    
  447.                 $correspondancesVidal $this->antibiotiqueRepo->findCorrespondanceVidal($id,$pays_code);                
  448.                 $correspondancesCBIP $this->antibiotiqueRepo->findCorrespondanceCBIP($id,$pays_code);
  449.                 $contentParam = array('famille' => $famille'antibiotique' => $antibiotique'correspondancesVidal' => $correspondancesVidal'correspondancesCBIP' => $correspondancesCBIP);
  450.                 $content $this->render('SituationsCliniques/base-rcp.html.twig'$contentParam)->getContent();
  451.             }else{
  452.                 $correspondancesGPR $this->antibiotiqueRepo->findCorrespondanceGPR($id,$pays_code);
  453.                 $contentParam = array('correspondancesGPR' => $correspondancesGPR'famille' => $famille'antibiotique' => $antibiotique);
  454.                 $content $this->render('SituationsCliniques/calcul-poso.html.twig'$contentParam)->getContent();
  455.             }
  456.             return new JsonResponse( array ( 
  457.                 'responseCode' => 0,
  458.                 'content' => $content
  459.             ));
  460.             #region
  461.         //     $cellule = $this->celluleRepo->findCelluleWithIdCelluleAndCategorie($idCellule,$idCategorie);
  462.         //     $celluleParent = $this->celluleRepo->findCelluleWithIdCelluleAndCategorie($idCelluleParent,$idCategorie);
  463.         //     $titresComplets = $this->celluleTitreCompletRepo->findAllTitresCompletsWithIdCellule($idCellule,$cellule->getCategorieCellule()->getIdCategorieCellule());
  464.         //     $contenus = $this->contenuRepo->findContenusWithIdCellule($idCellule,null,$pays_code);
  465.         //     $personnalisations = array();
  466.         //     if ($this->container->getParameter('version_antibiogarde') != 'web_edition') 
  467.         //     {
  468.         //         foreach ($contenus as $contenu) {
  469.         //             $personnalisation = $this->personnalisationRepo->findOneBy(array(
  470.         //                 'clientIdAdada' => $client_id_adada,
  471.         //                 'Contenu' => $contenu));
  472.         //             if ($personnalisation == null)
  473.         //                 $personnalisation = new Personnalisation();
  474.         //             $personnalisations[] = $personnalisation;
  475.         //         }
  476.         //     }
  477.         //     $affPerso = $this->parametreRepo->findParametreAffichagePersonnalisations($client_id_adada);
  478.         //     //Epp collective
  479.         //     $sessionepp = $this->sessioneppRepo->findOneby(array('etatSession' => 0,'clientIdAdada' => $client_id_adada));
  480.         //     $sessionurl = null;
  481.         //     if ($sessionepp != null) 
  482.         //     {
  483.         //         $sessionurl = $this->sessioneppUrlRepo->getSessioneppUrlForIdCellule($idCellule,$client_id_adada);
  484.         //     }
  485.         //     $content = $this->render('SituationsCliniques/situation-clinique-contenus.html.twig',
  486.         //                         array(  'cellule'=>$cellule,
  487.         //                                 'celluleParent'=>$celluleParent,
  488.         //                                 'contenus'=>$contenus, 
  489.         //                                 'titresComplets'=>$titresComplets, 
  490.         //                                 'personnalisations' => $personnalisations,
  491.         //                                 'affichage_personnalisation' => $affPerso->getValeur(),
  492.         //                                 'sessionurl' => $sessionurl
  493.         //                             ));
  494.         //     return new JsonResponse( array ( 
  495.         //         'responseCode' => 0,
  496.         //         'content' => $content
  497.         //     ));
  498.         #endregion
  499.         } else throw $this->createNotFoundException();
  500.     }
  501.     /**
  502.      * Require ROLE_AUTHENTICATED only for this action
  503.      * 
  504.      * @IsGranted("ROLE_AUTHENTICATED")
  505.      */
  506.     public function contenu($idCellule$idCelluleParentRequest $request)
  507.     {
  508.         if ($request->isXmlHttpRequest())
  509.         {
  510.             $idCategorie $this->getTypeCategorieCellule($request);
  511.             $session $request->getSession();
  512.             $client_id_adada $session->get('client_id_adada');
  513.             $em $this->getDoctrine()->getManager();
  514.             $pays_code $this->parametreRepo->findParametrePaysCode($client_id_adada);
  515.             if($client_id_adada == null && $this->getParameter('version_antibiogarde') == 'web_edition') { 
  516.                 $pays $this->paysRepo->findPaysWithLocale($session->get('_locale'));
  517.                 if($pays != null$pays_code $pays->getCodePays();
  518.             }
  519.             $cellule $this->celluleRepo->findCelluleWithIdCelluleAndCategorie($idCellule,$idCategorie);
  520.             $celluleParent $this->celluleRepo->findCelluleWithIdCelluleAndCategorie($idCelluleParent,$idCategorie);
  521.             $titresComplets $this->celluleTitreCompletRepo->findAllTitresCompletsWithIdCellule($idCellule,$cellule->getCategorieCellule()->getIdCategorieCellule());
  522.             $contenus $this->contenuRepo->findContenusWithIdCellule($idCellule,null,$pays_code);
  523.             $personnalisations = array();
  524.             if ($this->getParameter('version_antibiogarde') != 'web_edition'
  525.             {
  526.                 foreach ($contenus as $contenu) {
  527.                     $personnalisation $this->personnalisationRepo->findOneBy(array(
  528.                         'clientIdAdada' => $client_id_adada,
  529.                         'Contenu' => $contenu));
  530.                     if ($personnalisation == null)
  531.                         $personnalisation = new Personnalisation();
  532.                     $personnalisations[] = $personnalisation;
  533.                 }
  534.             }
  535.             $affPerso $this->parametreRepo->findParametreAffichagePersonnalisations($client_id_adada);
  536.             //Epp collective
  537.             $sessionepp $this->sessioneppRepo->findOneby(array('etatSession' => 0,'clientIdAdada' => $client_id_adada));
  538.             $sessionurl null;
  539.             if ($sessionepp != null
  540.             {
  541.                 $sessionurl $this->sessioneppUrlRepo->getSessioneppUrlForIdCellule($idCellule,$client_id_adada);
  542.             }
  543.             if($cellule->getOrdre() == 997){
  544.                 $content $this->render('SituationsCliniques/calcul-poso-obesite.html.twig')->getContent();
  545.             }
  546.             else if(count($contenus) == && $contenus[0]->getTypeContenu() != NULL)
  547.             {
  548.                 if($contenus[0]->getTypeContenu()->getLibelleTypeContenuFR() == "Lien"){
  549.                     foreach($contenus[0]->getContenulangues() as $contenulangue){
  550.                         if($contenulangue->getLangue()->getCode() == $session->get("_locale")){
  551.                             $url $contenulangue->getContenuhtml();
  552.                         }
  553.                     }
  554.                     $content $this->render('SituationsCliniques/redirect.html.twig', array('url'=> $url))->getContent();
  555.                 }
  556.                 else {
  557.                     $content $this->render('SituationsCliniques/situation-clinique-contenus.html.twig',
  558.                                 array(  'cellule'=>$cellule,
  559.                                         'celluleParent'=>$celluleParent,
  560.                                         'contenus'=>$contenus
  561.                                         'titresComplets'=>$titresComplets
  562.                                         'personnalisations' => $personnalisations,
  563.                                         'affichage_personnalisation' => $affPerso->getValeur(),
  564.                                         'sessionurl' => $sessionurl
  565.                                     ))->getContent();
  566.                 }
  567.             }
  568.             else{
  569.                 $content $this->render('SituationsCliniques/situation-clinique-contenus.html.twig',
  570.                                 array(  'cellule'=>$cellule,
  571.                                         'celluleParent'=>$celluleParent,
  572.                                         'contenus'=>$contenus
  573.                                         'titresComplets'=>$titresComplets
  574.                                         'personnalisations' => $personnalisations,
  575.                                         'affichage_personnalisation' => $affPerso->getValeur(),
  576.                                         'sessionurl' => $sessionurl
  577.                                     ))->getContent();
  578.             }
  579.             
  580.             return new JsonResponse( array ( 
  581.                 'responseCode' => 0,
  582.                 'content' => $content
  583.             ));
  584.         } else throw $this->createNotFoundException();    
  585.     }
  586.     /**
  587.      * Require ROLE_AUTHENTICATED only for this action
  588.      * 
  589.      * @IsGranted("ROLE_AUTHENTICATED")
  590.      */
  591.     public function recherche(Request $request)
  592.     {
  593.         if ($request->isXmlHttpRequest())
  594.         {
  595.             $content $this->render('SituationsCliniques/recherche.html.twig');
  596.             return new JsonResponse( array ( 
  597.                 'responseCode' => 0,
  598.                 'content' => $content->getContent()
  599.             ));
  600.         } else throw $this->createNotFoundException();
  601.     }
  602.     //Utiliser uniquement pour rechercher
  603.     private function recursiveTitle(Request $request, &$objs, &$cell$cellForId$cellForTitre$prefixe ''$path = array())
  604.     {
  605.         $em $this->getDoctrine()->getManager();
  606.         $session $request->getSession();
  607.         $prefixe_initial $prefixe;
  608.         if ($this->gestionBalises->checkValiditeArborescenceCellule($cell)) 
  609.         {
  610.             foreach ($cell->getCellulesPeres() as $pere
  611.             {
  612.                 $path_next $path;
  613.                 $prefixe = ($pere->getTitrelong($session->get("_locale")) != '' $pere->getTitrelong($session->get("_locale")) : $pere->getTitrecourt($session->get("_locale"))) . ($prefixe_initial != '' ' Â» ' $prefixe_initial '');
  614.                 if ($pere->getAfficherFils() == 0)
  615.                     $path_next[] = $pere->getIdCellule();
  616.                 $this->recursiveTitle($request$objs$pere$cellForId$cellForTitre$prefixe$path_next);
  617.             }
  618.             // on arrive au sommaire
  619.             if (count($cell->getCellulesPeres()) == && $this->gestionBalises->checkValiditeArborescenceCellule($cell))
  620.             {
  621.                 $path array_reverse($path);
  622.                 // Le sommaire est une redite du premier bloc. Il ne faut donc pas le remettre.
  623.                 $name = (($prefixe != '') ? $prefixe ' Â» ' "") . ($cellForTitre->getTitrelong($session->get("_locale")) != '' $cellForTitre->getTitrelong($session->get("_locale")) : $cellForTitre->getTitrecourt($session->get("_locale")));
  624.                 switch ($cell->getCategorieCellule()->getIdCategorieCellule()) {
  625.                     case $this->getParameter("categorie_situations_cliniques"):
  626.                         $name $this->translator->trans("sc_sc")." Â» ".$name;
  627.                         break;
  628.                     case $this->getParameter("categorie_prophylaxie"):
  629.                         $name $this->translator->trans("sc_prophylaxie")." Â» ".$name;
  630.                         break;
  631.                     case $this->getParameter("categorie_informations_pratiques"):
  632.                         $name $this->translator->trans("sc_informations_pratiques")." Â» ".$name;
  633.                         break;
  634.                     case $this->getParameter("categorie_elements_de_gravite"):
  635.                         $name $this->translator->trans("sc_elements_de_gravite")." Â» ".$name;
  636.                         break;
  637.                 }
  638.                 $new = array('balise' => 'cell''id' => $cellForId->getIdCellule(), 'name' => $name'path' => implode('/'$path));
  639.                 $objs[] = $new;
  640.             }
  641.         }
  642.     }
  643.     static function cmp($a$b)
  644.     {
  645.         if ($a['name'] == $b['name']) {
  646.             return 0;
  647.         }
  648.         return ($a['name'] < $b['name']) ? -1;
  649.     }
  650.     /**
  651.      * Require ROLE_AUTHENTICATED only for this action
  652.      * 
  653.      * @IsGranted("ROLE_AUTHENTICATED")
  654.      */
  655.     public function rechercher(Request $request)
  656.     {
  657.         if ($request->isXmlHttpRequest())
  658.         {
  659.             $term $request->get('term');
  660.             $session $request->getSession();
  661.             $client_id_adada $session->get('client_id_adada');
  662.             $em $this->getDoctrine()->getManager();
  663.             $pays_code $this->parametreRepo->findParametrePaysCode($client_id_adada);
  664.             if($client_id_adada == null && $this->getParameter('version_antibiogarde') == 'web_edition') { 
  665.                 $pays $this->paysRepo->findPaysWithLocale($session->get('_locale'));
  666.                 if($pays != null$pays_code $pays->getCodePays();
  667.             }
  668.             $cellules $this->celluleRepo->findCelluleFromName($term,$session->get("_locale"),$pays_code);
  669.             $objs = array();
  670.             foreach ($cellules as $obj
  671.             {
  672.                 $this->recursiveTitle($request$objs$obj$obj$obj);
  673.             }
  674.             usort($objs, array("App\Controller\SituationsCliniquesController""cmp"));
  675.             return new JsonResponse($objs);
  676.         } else throw $this->createNotFoundException();
  677.     }
  678.     /**
  679.      * Require ROLE_REFERENT only for this action
  680.      * 
  681.      * @IsGranted("ROLE_REFERENT")
  682.      */
  683.     public function information_personnalisation_delete($idRequest $request)
  684.     {
  685.         $session $request->getSession();
  686.         $client_id_adada $session->get('client_id_adada');
  687.         $em $this->getDoctrine()->getManager();
  688.         $information $this->informationRepo->findInformationWithId($id);
  689.         if ($information != null)
  690.         {
  691.             $personnalisation $this->personnalisationRepo->findOneBy(array(
  692.                     'clientIdAdada' => $client_id_adada,
  693.                     'Information' => $information));
  694.             if ($personnalisation != null)
  695.             {
  696.                 foreach ($personnalisation->getReferencesHopital() as $reference) {
  697.                     $em->remove($reference);
  698.                 }
  699.                 $em->remove($personnalisation);
  700.                 $em->flush();
  701.             }
  702.         }
  703.         return $this->redirectToRoute('information_personnalisation_form', array( 'id' => $id'delete' => 1));
  704.     }
  705.     /**
  706.      * Require ROLE_REFERENT only for this action
  707.      * 
  708.      * @IsGranted("ROLE_REFERENT")
  709.      */
  710.     public function information_personnalisation_form($id$deleteRequest $request)
  711.     {
  712.         $session $request->getSession();
  713.         $client_id_adada $session->get('client_id_adada');
  714.         $em $this->getDoctrine()->getManager();
  715.         $errors = array();
  716.         $message '';
  717.         if ($delete
  718.         {
  719.             $message $this->translator->trans("sc_suppression_enregistree");
  720.         }
  721.         $balise null;
  722.         $personnalisation null;
  723.         $information $this->informationRepo->findInformationWithId($id);
  724.         if ($information != null)
  725.         {
  726.             $personnalisation $this->personnalisationRepo->findOneBy(array(
  727.                 'clientIdAdada' => $client_id_adada,
  728.                 'Information' => $information));
  729.         } else throw $this->createNotFoundException();
  730.         $references = Array();
  731.         if ($personnalisation == null)
  732.         {
  733.             $personnalisation = new Personnalisation();
  734.             $personnalisation->setClientIdAdada($client_id_adada);
  735.             $personnalisation->setInformation($information);
  736.             $personnalisation->setContenuhtml($information->getContenuhtml($session->get('_locale')));
  737.             foreach ($information->getReferences() as $informationreference) {
  738.                 $references[] = clone $informationreference->getReference();
  739.             }
  740.         }
  741.         else
  742.         {
  743.             foreach ($personnalisation->getReferencesHopital() as $personnalisationReference) {
  744.                 $references[] = $personnalisationReference->getReferenceHopital();
  745.             }
  746.         }
  747.         if ($request->isMethod('POST')) {
  748.             $personnalisation->setContenuhtml($request->request->get('contenuHtml'));
  749.             $errors_references = array();
  750.             $references $this->referenceService->parseReferences($request$this->container$em$errors_references);
  751.             if (count($errors_references) == && count($errors) == 0)
  752.             {
  753.                 if ($personnalisation->getIdPersonnalisation() == null)
  754.                     $em->persist($personnalisation);
  755.                 $indice_ref 1;
  756.                 foreach ($references as $reference) {
  757.                     if ($reference->getIdReference() == null)
  758.                     {
  759.                         $em->persist($reference);
  760.                         $ref = new PersonnalisationReferenceHopital();
  761.                         $ref->setOrdre($indice_ref);
  762.                         $ref->setPersonnalisation($personnalisation);
  763.                         $ref->setReferenceHopital($reference);
  764.                         $em->persist($ref);
  765.                         $indice_ref++;
  766.                     }
  767.                 }
  768.                 $em->flush();
  769.                 $this->referenceService->validateUpload($request$this->container);
  770.                 $balise $this->render('Blocnotes/info.html.twig', array('information' => $information));
  771.                 $balise addslashes($balise);
  772.                 $message $this->translator->trans("sc_modifications_enregistrees");
  773.             }
  774.             $errors['references'] = $errors_references;
  775.         }
  776.         $render_references $this->referenceService->renderReferences($this->container$em$references$errors_references);
  777.         return $this->render('SituationsCliniques/information-personnalisation-form.html.twig', array('balise' => $balise'references' => $render_references'personnalisation' => $personnalisation'information' => $information'errors' => $errors'message' => $message));
  778.     }
  779.     /**
  780.      * Require ROLE_REFERENT only for this action
  781.      * 
  782.      * @IsGranted("ROLE_REFERENT")
  783.      */
  784.     public function information_hopital_form($id$newRequest $request)
  785.     {
  786.         $errors = array();
  787.         $message '';
  788.         $balise null;
  789.         $session $request->getSession();
  790.         $client_id_adada $session->get('client_id_adada');
  791.         $em $this->getDoctrine()->getManager();
  792.         if ($id 0)
  793.             $informationHopital $this->informationHopitalRepo->find($id);
  794.         else
  795.             $informationHopital = new InformationHopital();  
  796.         $informationHopitalReferences $informationHopital->getReferencesHopital();
  797.         $references = Array();
  798.         foreach ($informationHopitalReferences as $informationHopitalReference) {
  799.             $references[] = $informationHopitalReference->getReferenceHopital();
  800.         }
  801.         $sortType 'libelleTypeInformation'.strtoupper($session->get('_locale'));
  802.         $typesInformation $this->typeInformationRepo->findBy(array(), array($sortType => 'ASC'));
  803.         if ($request->isMethod('POST')) {
  804.             if ($request->request->get('typeInformation') == '')
  805.             {
  806.                 $errors['typeInformation'] = $this->translator->trans("sc_selectionner_type_informations");
  807.                 $references $this->referenceService->parseReferences($request$this->container$em$errors_references);
  808.             }
  809.             else
  810.             {
  811.                 $typeInformation $this->typeInformationRepo->findOneByIdTypeInformation($request->request->get('typeInformation'));
  812.                 if ($typeInformation == null)
  813.                     $errors['typeInformation'] = $this->translator->trans("sc_selectionner_type_informations");
  814.                 $informationHopital->setTypeInformation($typeInformation);
  815.                 $errors_references = array();
  816.                 $references $this->referenceService->parseReferences($request$this->container$em$errors_references);
  817.                 if (count($errors_references) == && count($errors) == 0)
  818.                 {
  819.                     $informationHopital->setClientIdAdada($client_id_adada);
  820.                     // form is valid
  821.                     $informationHopital->setContenuhtml($request->request->get('contenuHtml'));
  822.                     if ($informationHopital->getIdInformation() == null
  823.                         $em->persist($informationHopital);
  824.                     $indice_ref 1;
  825.                     foreach ($references as $reference) {
  826.                         if ($reference->getIdReference() == null)
  827.                         {
  828.                             $em->persist($reference);
  829.                             $ref = new InformationHopitalReferenceHopital();
  830.                             $ref->setOrdre($indice_ref);
  831.                             $ref->setInformationHopital($informationHopital);
  832.                             $ref->setReferenceHopital($reference);
  833.                             $em->persist($ref);
  834.                             $indice_ref++;
  835.                         }
  836.                     }
  837.                     $em->flush();
  838.                     $this->referenceService->validateUpload($request$this->container);
  839.                     $balise $this->render('Blocnotes/infohopital.html.twig', array('informationHopital' => $informationHopital));
  840.                     $balise addslashes($balise->getContent());
  841.                     $message $this->translator->trans("sc_modifications_enregistrees");
  842.                 }
  843.                 $errors['references'] = $errors_references;
  844.             }
  845.         }
  846.         $render_references $this->referenceService->renderReferences($this->container$em$references$errors_references);
  847.         return $this->render('SituationsCliniques/information-hopital-form.html.twig', array('new' => $new'balise' => $balise'typesInformation' => $typesInformation'informationHopital' => $informationHopital'errors' => $errors'references' => $render_references'message' => $message));
  848.     }
  849.     public function reload_references(Request $request)
  850.     {
  851.         $em $this->getDoctrine()->getManager();
  852.         $errors_references = array();
  853.         $references $this->referenceService->parseReferences($request$this->container$em$errors_references);
  854.         $render_references = array();
  855.         $errors = array();
  856.         $indice 1;
  857.         foreach ($references as $ref
  858.         {
  859.             $idTypeReference $ref->getTypeReference()->getIdTypeReference();
  860.             switch ($idTypeReference
  861.             {
  862.                 case $this->getParameter('type_reference_lien'):
  863.                     $render_references[$indice] = $this->container->get('twig')->render('References/lien.html.twig', array( 'indice' => $indice'onCreation' => true'reference' => $ref'errors' => null));
  864.                     break;
  865.                 
  866.                 case $this->getParameter('type_reference_note'):
  867.                     $render_references[$indice] = $this->container->get('twig')->render('References/note.html.twig', array( 'indice' => $indice'onCreation' => true'reference' => $ref'errors' => null));
  868.                     break;
  869.                 case $this->getParameter('type_reference_fichier'):
  870.                     $render_references[$indice] = $this->container->get('twig')->render('References/fichier.html.twig', array( 'indice' => $indice'onCreation' => true'reference' => $ref'errors' => null));
  871.                     break;
  872.                 
  873.                 case $this->getParameter('type_reference_image'):
  874.                     $render_references[$indice] = $this->container->get('twig')->render('References/image.html.twig', array( 'indice' => $indice'onCreation' => true'reference' => $ref'errors' => null));
  875.                     break;
  876.                 case $this->getParameter('type_reference_texte'):
  877.                     $render_references[$indice] = $this->container->get('twig')->render('References/texte.html.twig', array( 'indice' => $indice'onCreation' => true'reference' => $ref'errors' => null));
  878.                     break;
  879.                 default:
  880.                     # code...
  881.                     break;
  882.             }
  883.             if (array_key_exists($indice$errors_references)) 
  884.             {
  885.                 $errors[$indice] = '<div class="alert alert-danger">'.$errors_references[$indice].'</div>';
  886.             }
  887.             else
  888.             {
  889.                 $errors[$indice] = '';
  890.             }
  891.             $indice++;
  892.         }
  893.         // $render_references = $this->referenceService->renderReferences($this->container, $em, $references, $errors_references,0,true);
  894.         return new JsonResponse( array ( 
  895.             'responseCode' => 0,
  896.             'content' => $render_references,
  897.             'errors' => $errors
  898.         ));
  899.     }
  900.     /**
  901.      * Require ROLE_REFERENT only for this action
  902.      * 
  903.      * @IsGranted("ROLE_REFERENT")
  904.      */
  905.     public function contenu_personnalisation_delete($id,$pathPageRequest $request)
  906.     {
  907.         $session $request->getSession();
  908.         $client_id_adada $session->get('client_id_adada');
  909.         $em $this->getDoctrine()->getManager();
  910.         $contenu $this->contenuRepo->findContenuWithId($id,true);
  911.         if ($contenu != null)
  912.         {
  913.             $personnalisation $this->personnalisationRepo->findOneBy(array(
  914.                     'clientIdAdada' => $client_id_adada,
  915.                     'Contenu' => $contenu));
  916.             if ($personnalisation != null)
  917.             {
  918.                 foreach ($personnalisation->getReferencesHopital() as $reference) {
  919.                     $em->remove($reference);
  920.                 }
  921.                 $em->remove($personnalisation);
  922.                 $em->flush();
  923.                 $this->eppService->majSessionEppURL($pathPage,$contenu->getCellule()->getCategorieCellule()->getIdCategorieCellule(),$contenu->getCellule(),true);
  924.             }
  925.         }
  926.         return $this->redirectToRoute('contenu_personnalisation_form', array( 'id' => $id,'pathPage' => $pathPage'delete' => 1));
  927.     }
  928.     /**
  929.      * Require ROLE_REFERENT only for this action
  930.      * 
  931.      * @IsGranted("ROLE_REFERENT")
  932.      */
  933.     public function contenu_personnalisation_form($id,$pathPage,$deleteRequest $request)
  934.     {
  935.         $session $request->getSession();
  936.         $client_id_adada $session->get('client_id_adada');
  937.         $em $this->getDoctrine()->getManager();
  938.         $errors = array();
  939.         $message '';
  940.         if ($delete
  941.         {
  942.             $message $this->translator->trans("sc_suppression_enregistree");
  943.         }
  944.         $balise null;
  945.         $personnalisation null;
  946.         $contenu $this->contenuRepo->findContenuWithId($id,true);
  947.         if ($contenu != null)
  948.         {
  949.             $personnalisation $this->personnalisationRepo->findOneBy(array(
  950.                 'clientIdAdada' => $client_id_adada,
  951.                 'Contenu' => $contenu));
  952.         } else throw $this->createNotFoundException();
  953.         if ($personnalisation == null)
  954.         {
  955.             $personnalisation = new Personnalisation();
  956.             $personnalisation->setClientIdAdada($client_id_adada);
  957.             $personnalisation->setContenu($contenu);
  958.             $personnalisation->setContenuhtml($contenu->getContenuhtml($session->get('_locale')));
  959.         }
  960.         if ($request->isMethod('POST')) {
  961.             $personnalisation->setContenuhtml($this->gestionBalises->format_from_tinymce_to_bdd(trim($request->request->get('contenuHtml'))));
  962.             
  963.             if ($personnalisation->getIdPersonnalisation() == null)
  964.                 $em->persist($personnalisation);
  965.             $em->flush();
  966.             $this->eppService->majSessionEppURL($pathPage,$contenu->getCellule()->getCategorieCellule()->getIdCategorieCellule(),$contenu->getCellule(),false);
  967.             $message $this->translator->trans("sc_modifications_enregistrees");
  968.            
  969.         }
  970.         return $this->render('SituationsCliniques/contenu-personnalisation-form.html.twig', array('personnalisation' => $personnalisation,'pathPage' => $pathPage,'contenu' => $contenu'errors' => $errors'message' => $message));
  971.     }
  972. }