src/Controller/BlocnotesController.php line 168

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\Controller;//A voir
  4. use App\Entity\Note;
  5. use Symfony\Component\HttpFoundation\JsonResponse;//A voir
  6. use Symfony\Contracts\Translation\TranslatorInterface;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;//A voir
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Knp\Component\Pager\PaginatorInterface;
  10. use App\Repository\ATBGRepository;
  11. use App\Repository\AbbreviationLangueRepository;
  12. use App\Repository\AbbreviationRepository;
  13. use App\Repository\ActualiteRepository;
  14. use App\Repository\AntibiotiqueRepository;
  15. use App\Repository\CasCliniquesCategorieRepository;
  16. use App\Repository\CasCliniquesQuestionRepository;
  17. use App\Repository\CasCliniquesReponseRepository;
  18. use App\Repository\CasCliniquesReponseUtilisateurRepository;
  19. use App\Repository\CelluleRepository;
  20. use App\Repository\CelluleTitreCompletRepository;
  21. use App\Repository\CoAntibiotiqueCalculRepository;
  22. use App\Repository\ContenuRepository;
  23. use App\Repository\EtablissementRepository;
  24. use App\Repository\FamilleAntibiotiqueRepository;
  25. use App\Repository\FavorisRepository;
  26. use App\Repository\InformationHopitalRepository;
  27. use App\Repository\InformationReferenceRepository;
  28. use App\Repository\InformationRepository;
  29. use App\Repository\IntervenantSessioneppRepository;
  30. use App\Repository\LangueRepository;
  31. use App\Repository\MicroorganismeRepository;
  32. use App\Repository\NoteRepository;
  33. use App\Repository\ParametreRepository;
  34. use App\Repository\PaysRepository;
  35. use App\Repository\PersonnalisationRepository;
  36. use App\Repository\PersonnalisationSpectreRepository;
  37. use App\Repository\QualiteRepository;
  38. use App\Repository\ReferenceHopitalRepository;
  39. use App\Repository\ReferenceRepository;
  40. use App\Repository\SessioneppRepository;
  41. use App\Repository\SessioneppUrlRepository;
  42. use App\Repository\SpecialiteRepository;
  43. use App\Repository\SpectreRepository;
  44. use App\Repository\TicketPatientRepository;
  45. use App\Repository\TypeInformationRepository;
  46. use App\Repository\UtilisateurRepository;
  47. use App\Repository\VersionRepository;
  48. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  49. use Psr\Container\ContainerInterface;
  50. use App\Controller\ReferencesController;
  51. use App\Service\ContentHandler;
  52. use App\Service\StatistiquesService;
  53. class BlocnotesController extends ATBGController
  54. {
  55.      /**
  56.      * @var ContainerHandler
  57.      */
  58.     private $gestionBalises;
  59.     
  60.      /**
  61.      * @var StatistiquesService
  62.      */
  63.     private $statService;
  64.      /**
  65.      * @var Container
  66.      */
  67.     protected $container;
  68.     public function __construct(
  69.         private AbbreviationLangueRepository $abbreviationLangueRepo,
  70.         private AbbreviationRepository $abbreviationRepo,
  71.         private ActualiteRepository $actualiteRepo,
  72.         private AntibiotiqueRepository $antibiotiqueRepo,
  73.         private CasCliniquesCategorieRepository $casCliniquesCategorieRepo,
  74.         private CasCliniquesQuestionRepository $casCliniquesQuestionRepo,
  75.         private CasCliniquesReponseRepository $casCliniquesReponseRepo,
  76.         private CasCliniquesReponseUtilisateurRepository $casCliniquesReponseUtilisateurRepo,
  77.         private CelluleRepository $celluleRepo,
  78.         private CelluleTitreCompletRepository $celluleTitreCompletRepo,
  79.         private CoAntibiotiqueCalculRepository $coAntibiotiqueCalculRepo,
  80.         private ContenuRepository $contenuRepo,
  81.         private EtablissementRepository $etablissementRepo,
  82.         private FamilleAntibiotiqueRepository $familleAntibiotiqueRepository,
  83.         private FavorisRepository $favorisRepo,
  84.         private InformationHopitalRepository $informationHopitalRepo,
  85.         private InformationReferenceRepository $informationReferenceRepo,
  86.         private InformationRepository $informationRepo,
  87.         private IntervenantSessioneppRepository $intervenantSessioneppRepo,
  88.         private LangueRepository $langueRepo,
  89.         private MicroorganismeRepository $microorganismeRepo,
  90.         private NoteRepository $noteRepo,
  91.         private ParametreRepository $parametreRepo,
  92.         private PaysRepository $paysRepo,
  93.         private PersonnalisationRepository $personnalisationRepo,
  94.         private PersonnalisationSpectreRepository $personnalisationSpectreRepo,
  95.         private QualiteRepository $qualiteRepo,
  96.         private ReferenceHopitalRepository $referenceHopitalRepo,
  97.         private ReferenceRepository $referenceRepo,
  98.         private SessioneppRepository $sessioneppRepo,
  99.         private SessioneppUrlRepository $sessioneppUrlRepo,
  100.         private SpecialiteRepository $specialiteRepo,
  101.         private SpectreRepository $spectreRepo,
  102.         private TicketPatientRepository $ticketPatientRepo,
  103.         private TypeInformationRepository $typeInformationRepo,
  104.         private UtilisateurRepository $utilisateurRepo,
  105.         private VersionRepository $versionRepo,
  106.         private TranslatorInterface $translator,
  107.         private ReferencesController $referenceService,
  108.         ContainerInterface $container,
  109.         StatistiquesService $statService,
  110.         ContentHandler $gestionBalises
  111.     ){
  112.         $this->container $container;
  113.         $this->gestionBalises $gestionBalises;
  114.         $this->statService $statService;
  115.     }
  116.     private function listeNotes($id$twig_nameRequest $requestPaginatorInterface $paginator)
  117.     {
  118.         // en version webedition, pas de bloc notes
  119.         if ($this->getParameter('version_antibiogarde') == 'web_edition')
  120.         {
  121.             return $this->redirectToRoute('situations_cliniques_home');
  122.         }
  123.         $em $this->getDoctrine()->getManager();
  124.         $session $request->getSession();
  125.         $client_id_adada $session->get('client_id_adada');
  126.         $query $this->noteRepo->findBy(['clientIdAdada' => $client_id_adada],['dateNote' => 'desc']);
  127.         //$query = $em->createQuery('SELECT n FROM Note n WHERE n.clientIdAdada = '.$client_id_adada.' ORDER BY n.dateNote DESC');
  128.         //$paginator  = $this->get('knp_paginator');
  129.         $pagination $paginator->paginate(
  130.             $query,
  131.             $request->query->getInt('page'1),
  132.             15
  133.         );
  134.         $currentnote false;
  135.         if ($id == 0)
  136.         {
  137.             if ($pagination->getTotalItemCount() > 0)
  138.             {
  139.                 $items $pagination->getItems();
  140.                 $currentnote $items[0];
  141.             }
  142.         }
  143.         else
  144.         {
  145.             $currentnote $this->noteRepo->findNoteWithIdNote($id,$client_id_adada);
  146.             if ($currentnote == null
  147.             {
  148.                return $this->redirect($this->get('router')->generate('bloc_notes_home'));
  149.             }
  150.         }
  151.         return $this->render('Blocnotes/' $twig_name, array('pagination' => $pagination'currentnote' => $currentnote));
  152.     }
  153.     /**
  154.      * Require ROLE_AUTHENTICATED only for this action
  155.      * 
  156.      * @IsGranted("ROLE_AUTHENTICATED")
  157.      */
  158.     public function index(Request $requestPaginatorInterface $paginator)
  159.     {
  160.         return $this->listeNotes(0'home.html.twig'$request$paginator);
  161.     }
  162.     /**
  163.      * Require ROLE_AUTHENTICATED only for this action
  164.      * 
  165.      * @IsGranted("ROLE_AUTHENTICATED")
  166.      */
  167.     public function display($idRequest $requestPaginatorInterface $paginator)
  168.     {
  169.         $returned parent::suppression_parametres_get($request);
  170.         if ($returned != null
  171.         {
  172.             return $returned;
  173.         }
  174.         $path $request->getUri();
  175.         $libelle_page $this->gestionBalises->full_title_with_url($path);
  176.         $this->statService->addStatistique($id,$path,$libelle_page);
  177.         return $this->listeNotes($id'index.html.twig'$request$paginator);
  178.     }
  179.     /**
  180.      * Require ROLE_REFERENT only for this action
  181.      * 
  182.      * @IsGranted("ROLE_REFERENT")
  183.      */
  184.     public function edit(Request $request$id$submit false)
  185.     {
  186.         $errors = array();
  187.         $em $this->getDoctrine()->getManager();
  188.         $session $request->getSession();
  189.         $client_id_adada $session->get('client_id_adada');
  190.         if ($id 0)
  191.             $note $this->noteRepo->findNoteWithIdNote($id,$client_id_adada);
  192.         else
  193.             $note = new Note();
  194.         $render_references '';
  195.         $references $note->getReferencesHopital();
  196.         $message '';
  197.         if ($submit)
  198.         {
  199.             $note->setTitreNote(trim($request->request->get('titreNote')));
  200.             $note->setTexteNote($this->gestionBalises->format_from_tinymce_to_bdd(trim($request->request->get('texteNote'))));
  201.             if ($note->getDateNote() == null)
  202.                 $note->setDateNote(new \DateTime('now'));
  203.             if ( $note->getTitreNote() == '')
  204.                 $errors['titreNote'] = $this->translator->trans("bloc_note_titre_obligatoire");
  205.             else if (strlen($note->getTitreNote()) > 255)
  206.                 $errors['titreNote'] = $this->translator->trans("bloc_note_titre_max255");
  207.             if ($note->getTexteNote() == '')
  208.                 $errors['texteNote'] = $this->translator->trans("bloc_note_texte_obligatoire");
  209.             $errors_references = array();
  210.             $references $this->referenceService->parseReferences($request$this->container$em$errors_references);
  211.             if (count($errors_references) == && count($errors) == 0)
  212.             {
  213.                 $session $request->getSession();
  214.                 $client_id_adada $session->get('client_id_adada');
  215.                 $note->setClientIdAdada($client_id_adada);
  216.                 foreach ($references as $reference) {
  217.                     if ($reference->getIdReference() == null)
  218.                         $note->addReferenceHopital($reference);
  219.                 }
  220.                 if ($note->getIdNote() == null)
  221.                 {
  222.                     $note->setAuteurNote($session->get('nom_auteur_utilisateur'));
  223.                     $em->persist($note);
  224.                 }
  225.                 $em->flush();
  226.                 $this->referenceService->validateUpload($request$this->container);
  227.                 // $stmt = $em->getConnection()->prepare('call purgeInfoHopitalOrphan();');
  228.                 // $stmt->execute();
  229.                 $message $this->translator->trans("bloc_note_modifications_ok");
  230.             }
  231.             $errors['references'] = $errors_references;
  232.         }
  233.         $render_references $this->referenceService->renderReferences($this->container$em$references$errors_references$note->getIdNote());
  234.         
  235.         return $this->render('Blocnotes/form.html.twig', array('note' => $note'errors' => $errors'references' => $render_references'message' => $message));
  236.     }
  237.     /**
  238.      * Require ROLE_REFERENT only for this action
  239.      * 
  240.      * @IsGranted("ROLE_REFERENT")
  241.      */
  242.     public function delete($idRequest $request)
  243.     {
  244.         $em $this->getDoctrine()->getManager();
  245.         $em $this->getDoctrine()->getManager();
  246.         $session $request->getSession();
  247.         $client_id_adada $session->get('client_id_adada');
  248.         $responseCode 0;
  249.         //$references = $this->referenceHopitalRepo->findReferenceWithIdBlocNote($id,$client_id_adada);
  250.         $references $this->referenceHopitalRepo->findBy(['clientIdAdada' => $client_id_adada'Note' => $id]);
  251.         
  252.         if (count($references) > 0
  253.         {
  254.             $responseCode 1;
  255.         }
  256.         else
  257.         {
  258.             $note $this->noteRepo->findNoteWithIdNote($id,$client_id_adada);
  259.             if ($note != null)
  260.             {
  261.                 $note->emptyReferencesHopital();
  262.                 $em->flush();
  263.                 
  264.                 $em->remove($note);
  265.                 $em->flush();
  266.             }
  267.         }
  268.         return new JsonResponse( array ( 
  269.             'responseCode' => $responseCode,
  270.             'content' => ''
  271.         ));
  272.     }
  273.     /**
  274.      * Require ROLE_REFERENT only for this action
  275.      * 
  276.      * @IsGranted("ROLE_REFERENT")
  277.      */
  278.     public function add(Request $request)
  279.     {
  280.         return $this->edit($request0);
  281.     }
  282.     /**
  283.      * Require ROLE_REFERENT only for this action
  284.      * 
  285.      * @IsGranted("ROLE_REFERENT")
  286.      */
  287.     public function form(Request $request$id)
  288.     { 
  289.         return $this->edit($request$idtrue);
  290.     }
  291. }