src/Controller/PacienteController.php line 162

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Paciente;
  4. use App\Form\BuscarPacienteType;
  5. use App\Form\PacienteType;
  6. use App\Form\PacienteTypeEdit;
  7. use App\Repository\PacienteRepository;
  8. use App\Repository\PreparacionRepository;
  9. use App\Repository\AgendaRepository;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Knp\Component\Pager\PaginatorInterface;
  15. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  16. /**
  17.  * @Route("/paciente")
  18.  */
  19. class PacienteController extends AbstractController
  20. {
  21.     /**
  22.      * @Route("/", name="paciente_index", methods={"GET","POST"})
  23.      */
  24.     public function index(PacienteRepository $pacienteRepositoryRequest $requestPaginatorInterface $paginatorSessionInterface $session): Response
  25.     {
  26.         $form $this->createForm(BuscarPacienteType::class);
  27.         $form->handleRequest($request);
  28.         $cedula null;$apellidos null;$nombres null;
  29.         if ($form->isSubmitted() && $form->isValid()) {
  30.             $cedula $form->get('cedula')->getData();
  31.             $apellidos $form->get('apellidos')->getData();
  32.             $nombres $form->get('nombres')->getData();
  33.         }
  34.         
  35.         // Obtén la URL actual
  36.         $currentUrl $request->getRequestUri();
  37.         // Guarda la URL actual en la sesión
  38.         $session->set('previous_url'$currentUrl);
  39.         $q_pacientes $pacienteRepository->BuscarPaciente($cedula,$apellidos,$nombres);
  40.         //dd($q_pacientes);
  41.         $pacientes $paginator->paginate(
  42.             $q_pacientes/* query NOT result */
  43.             $request->query->getInt('page'1), /*page number*/
  44.             50 /*limit per page*/
  45.         );
  46.         //dd($pacientes);
  47.         return $this->render('paciente/index.html.twig', [
  48.             'pacientes' => $pacientes,
  49.             'form' => $form->createView(),
  50.         ]);
  51.     }
  52.     /**
  53.      * @Route("/new", name="paciente_new", methods={"GET","POST"})
  54.      */
  55.     public function new(Request $request): Response
  56.     {
  57.         $paciente = new Paciente();
  58.         $form $this->createForm(PacienteType::class, $paciente);
  59.         $form->handleRequest($request);
  60.         if ($form->isSubmitted() && $form->isValid()) {
  61.             $entityManager $this->getDoctrine()->getManager();
  62.             $entityManager->persist($paciente);
  63.             $paciente->setApellido1(strtoupper($paciente->getApellido1()));
  64.             $paciente->setApellido2(strtoupper($paciente->getApellido2()));
  65.             $paciente->setNombre1(strtoupper($paciente->getNombre1()));
  66.             $paciente->setNombre2(strtoupper($paciente->getNombre2()));
  67.             $entityManager->flush();
  68.             return $this->redirectToRoute('paciente_index');
  69.         }
  70.         return $this->render('paciente/new.html.twig', [
  71.             'paciente' => $paciente,
  72.             'form' => $form->createView(),
  73.         ]);
  74.     }
  75.     /**
  76.      * @Route("/{id}", name="paciente_show", methods={"GET"})
  77.      */
  78.     public function show(Paciente $paciente): Response
  79.     {
  80.         return $this->render('paciente/show.html.twig', [
  81.             'paciente' => $paciente,
  82.         ]);
  83.     }
  84.     /**
  85.      * @Route("/filiacion/{id}", name="paciente_show", methods={"GET"})
  86.      */
  87.     public function show_filiacion(Paciente $pacientePreparacionRepository $preparacionRepository)
  88.     {
  89.         $preparaciones $preparacionRepository->buscaPreparacionxPaciente($paciente->getId());//dd($preparaciones);
  90.         return $this->render('paciente/show_filiacion.html.twig', [
  91.             'paciente' => $paciente,
  92.             'preparaciones' => $preparaciones->getResult()
  93.         ]);
  94.     }
  95.     /**
  96.      * @Route("/{id}/edit", name="paciente_edit", methods={"GET","POST"})
  97.      */
  98.     public function edit(Request $requestPaciente $pacienteSessionInterface $sessionAgendaRepository $agendaRepository): Response
  99.     {
  100.         $form $this->createForm(PacienteTypeEdit::class, $paciente);
  101.         $form->handleRequest($request);
  102.         $mensaje "";
  103.         
  104.         $previousUrl $session->get('previous_url');//dd($previousUrl);
  105.         if ($form->isSubmitted() && $form->isValid()) {
  106.             $paciente->setApellido1(strtoupper($paciente->getApellido1()));
  107.             $paciente->setApellido2(strtoupper($paciente->getApellido2()));
  108.             $paciente->setNombre1(strtoupper($paciente->getNombre1()));
  109.             $paciente->setNombre2(strtoupper($paciente->getNombre2()));
  110.             $this->getDoctrine()->getManager()->flush();
  111.             $mensaje "PACIENTE ACTUALIZADO";
  112.             //return $this->redirectToRoute('paciente_index');
  113.         }else{
  114.             $pais $paciente->getPais();
  115.             
  116.             if($pais == null){
  117.                 $pais 'ECUADOR';
  118.             }   
  119.             
  120.            
  121.             
  122.             $form->get('pais')->setData($pais);
  123.             
  124.         }
  125.         
  126.         $agendas $agendaRepository->findByPaciente($paciente->getId())->getResult();
  127.         return $this->render('paciente/edit.html.twig', [
  128.             'paciente'    => $paciente,
  129.             'form'        => $form->createView(),
  130.             'mensaje'     => $mensaje,
  131.             'previousUrl' => $previousUrl,
  132.             'agendas'     => $agendas,
  133.         ]);
  134.     }
  135.     /**
  136.      * @Route("/{id}/buscar/cedula", name="paciente_buscar_cedula", methods={"GET","POST"})
  137.      */
  138.     public function busca_paciente($idPacienteRepository $pacienteRepositoryRequest $request): Response
  139.     {
  140.         $dbpaciente $pacienteRepository->findOneByCedula($id);
  141.         //dd($dbpaciente->getId());
  142.         if(!is_null($dbpaciente)){
  143.             $session $request->getSession();
  144.             $session->set('id_paciente',$dbpaciente->getId());
  145.             return $this->json([
  146.                 // Query is not required as of version 1.2.5
  147.                 "estado"        => "ok",
  148.                 "paciente"      => $dbpaciente->getId(),
  149.                 "nombres"       => $dbpaciente->getApellido1().' '.$dbpaciente->getApellido2().' '.$dbpaciente->getNombre1().' '.$dbpaciente->getNombre2(),
  150.             ]);
  151.         }
  152.         return $this->json([
  153.             // Query is not required as of version 1.2.5
  154.             "estado"=> "no",
  155.             "paciente"=> "",
  156.         ]);
  157.     
  158.         
  159.     }
  160.     
  161.        /**
  162.      * @Route("/{id}/buscar/cedula2", name="paciente_buscar_cedula2", methods={"GET","POST"})
  163.      */
  164.     public function busca_paciente2 ($idPacienteRepository $pacienteRepositoryRequest $request): Response
  165.     {
  166.         $dbpaciente $pacienteRepository->findOneByCedula($id);
  167.         //dd($dbpaciente->getId());
  168.         if(!is_null($dbpaciente)){
  169.             $session $request->getSession();
  170.             $session->set('id_paciente',$dbpaciente->getId());
  171.             return $this->json([
  172.                 // Query is not required as of version 1.2.5
  173.                 "estado"        => "ok",
  174.                 "paciente"      => $dbpaciente->getId(),
  175.                 "nombres"       => $dbpaciente->getApellido1().' '.$dbpaciente->getApellido2().' '.$dbpaciente->getNombre1().' '.$dbpaciente->getNombre2(),
  176.             ]);
  177.         }
  178.         return $this->json([
  179.             // Query is not required as of version 1.2.5
  180.             "estado"=> "no",
  181.             "paciente"=> "",
  182.         ]);
  183.     
  184.         
  185.     }
  186.     /**
  187.      * @Route("/{id}", name="paciente_delete", methods={"DELETE"})
  188.      */
  189.     public function delete(Request $requestPaciente $paciente): Response
  190.     {
  191.         if ($this->isCsrfTokenValid('delete'.$paciente->getId(), $request->request->get('_token'))) {
  192.             $entityManager $this->getDoctrine()->getManager();
  193.             $entityManager->remove($paciente);
  194.             $entityManager->flush();
  195.         }
  196.         return $this->redirectToRoute('paciente_index');
  197.     }
  198.     /**
  199.      * @Route("/cedula/buscar/cedula/autocomplete", name="paciente_buscar_cedula_autocomplete", methods={"GET"})
  200.      */
  201.     public function buscar_paciente_autocomplete_cedula(Request $request,PacienteRepository $pacienteRepository): Response
  202.     {
  203.         $query $request->query->get('query');
  204.         $pacientes $pacienteRepository->BuscarPacientesxCedula($query);
  205.         $arr = [];$i=0;
  206.         //dd($items);
  207.         foreach ($pacientes as $value) {
  208.             //dd($value->gettarifario());
  209.             $arr[$i]=[ "value"=> $value['cedula'], "data"=> $value['id'] ];
  210.             $i++;
  211.         }
  212.         //dd($arr);
  213.         return $this->json([
  214.             // Query is not required as of version 1.2.5
  215.             "query"=> "Unit",
  216.             "suggestions"=> $arr,
  217.         ]);
  218.     }
  219.     /**
  220.      * @Route("/cedula/buscar/nombres/autocomplete", name="paciente_buscar_nombres_autocomplete", methods={"GET"})
  221.      */
  222.     public function buscar_paciente_autocomplete_nombres(Request $request,PacienteRepository $pacienteRepository): Response
  223.     {
  224.         $query $request->query->get('query');
  225.         $pacientes $pacienteRepository->BuscarPacientesxNombres($query);
  226.         $arr = [];$i=0;
  227.         //dd($items);
  228.         foreach ($pacientes as $value) {
  229.             //dd($value->gettarifario());
  230.             $arr[$i]=[ "value"=> $value['nombres'], "data"=> $value['id'], "cedula"=> $value['cedula'] ];
  231.             $i++;
  232.         }
  233.         //dd($arr);
  234.         return $this->json([
  235.             // Query is not required as of version 1.2.5
  236.             "query"=> "Unit",
  237.             "suggestions"=> $arr,
  238.         ]);
  239.     }
  240.     /**
  241.      * @Route("/agenda/new", name="paciente_agenda_new", methods={"GET"})
  242.      */
  243.     public function paciente_agenda_new(Request $request): Response
  244.     {
  245.         $paciente = new Paciente();
  246.         $form $this->createForm(PacienteType::class, $paciente);
  247.         $form->handleRequest($request);
  248.         /*if ($form->isSubmitted() && $form->isValid()) {
  249.             $entityManager = $this->getDoctrine()->getManager();
  250.             $entityManager->persist($paciente);
  251.             $paciente->setApellido1(strtoupper($paciente->getApellido1()));
  252.             $paciente->setApellido2(strtoupper($paciente->getApellido2()));
  253.             $paciente->setNombre1(strtoupper($paciente->getNombre1()));
  254.             $paciente->setNombre2(strtoupper($paciente->getNombre2()));
  255.             $entityManager->flush();
  256.             return ['estado' => 'save', 'cedula' => $paciente->getCedula()];
  257.         }*/
  258.         return $this->render('paciente/modal_new.html.twig', [
  259.             'paciente' => $paciente,
  260.             'form' => $form->createView(),
  261.         ]);
  262.     }
  263.     /**
  264.      * @Route("/agenda/new/storage", name="paciente_agenda_storage", methods={"POST"})
  265.      */
  266.     public function paciente_agenda_storage(Request $requestPacienteRepository $pacienteRepository): Response
  267.     {
  268.         
  269.         $paciente = new Paciente();
  270.         $form $this->createForm(PacienteType::class, $paciente);
  271.         $fecha_nacimiento $form->get('fecha_nacimiento')->getData();
  272.         
  273.         //dd($fecha_nacimiento);
  274.         $form->handleRequest($request);
  275.         
  276.         $dbpaciente $pacienteRepository->findOneByCedula($paciente->getCedula());
  277.         if(!is_null($dbpaciente)){
  278.             $session $request->getSession();
  279.             $session->set('id_paciente',$dbpaciente->getId());
  280.             return $this->json([
  281.                 // Query is not required as of version 1.2.5
  282.                 "estado"  => "existe",
  283.                 "cedula"  => $dbpaciente->getCedula(),
  284.                 "nombres" => $paciente->getApellido1().' '.$paciente->getApellido2().' '.$paciente->getNombre1().' '.$paciente->getNombre2()
  285.             ]);
  286.         }
  287.         
  288.         /*if($existe['estado']=='ok'){
  289.             return $this->json(['estado' => 'existe', 'cedula' => $paciente->getCedula()]);    
  290.         }*/
  291.         if ($form->isSubmitted() && $form->isValid()) {
  292.             $entityManager $this->getDoctrine()->getManager();
  293.             $entityManager->persist($paciente);
  294.             $paciente->setApellido1(strtoupper($paciente->getApellido1()));
  295.             $paciente->setApellido2(strtoupper($paciente->getApellido2()));
  296.             $paciente->setNombre1(strtoupper($paciente->getNombre1()));
  297.             $paciente->setNombre2(strtoupper($paciente->getNombre2()));
  298.             $entityManager->flush();
  299.             $paciente $pacienteRepository->findOneByCedula($paciente->getCedula());
  300.             $session $request->getSession();
  301.             $session->set('id_paciente',$paciente->getId());
  302.             
  303.             return $this->json([
  304.                 'estado'  => 'ok'
  305.                 'cedula'  => $paciente->getCedula(), 
  306.                 'nombres' => $paciente->getApellido1().' '.$paciente->getApellido2().' '.$paciente->getNombre1().' '.$paciente->getNombre2()
  307.             ]);
  308.         }
  309.         return $this->json([
  310.             'estado'  => 'no'
  311.             'cedula'  => $paciente->getCedula(), 
  312.             'nombres' => $paciente->getApellido1().' '.$paciente->getApellido2().' '.$paciente->getNombre1().' '.$paciente->getNombre2()
  313.         ]);
  314.     }
  315.     /**
  316.      * @Route("/buscar/antecedentes/personales/familiares/qx/{id}", name="paciente_antecedente_ajax", methods={"GET"})
  317.      */
  318.     public function obtener_antecedente(Paciente $paciente): Response
  319.     {
  320.         //dd($paciente);
  321.         $antecedentes_personales  =  $paciente->getMasAntecedentesPersonales();
  322.         $antecedentes_quirurgicos $paciente->getAntecedentesQuirurgicos();
  323.         $antecedentes_familiares  =  $paciente->getAntecedentesFamiliares();
  324.         $alcohol    $paciente->getAlcohol();
  325.         $tabaco     $paciente->getTabaco();
  326.         $drogas     $paciente->getDrogas();
  327.         $alergias   $paciente->getAlergias();
  328.         $medicacion $paciente->getMedicacion();
  329.         $ago        $paciente->getAgo();
  330.         $fum        $paciente->getFum();
  331.         $gesta      $paciente->getGesta();
  332.         $abo        $paciente->getAbo();
  333.         $para       $paciente->getpara();
  334.         $cesa       $paciente->getCesa();
  335.         if($antecedentes_personales==null){  $antecedentes_personales  ''; } 
  336.         if($antecedentes_quirurgicos==null){ $antecedentes_quirurgicos ''; } 
  337.         if($antecedentes_familiares==null){  $antecedentes_familiares  ''; } 
  338.         if($alcohol==null){    $alcohol    ''; } 
  339.         if($tabaco==null){     $tabaco     ''; } 
  340.         if($drogas==null){     $drogas     ''; } 
  341.         if($alergias==null){   $alergias   ''; } 
  342.         if($medicacion==null){ $medicacion ''; } 
  343.         if($ago==null){        $ago        ''; } 
  344.         if($fum==null){        $fum        ''; } 
  345.         if($gesta==null){      $gesta      ''; } 
  346.         if($abo==null){        $abo        ''; } 
  347.         if($para==null){       $para       ''; } 
  348.         if($cesa==null){       $cesa       ''; } 
  349.         return $this->json([
  350.             "id"     => $paciente->getId(),
  351.             "cedula" => $paciente->getCedula(),
  352.             "antecedentes_personales"  => $antecedentes_personales,
  353.             "antecedentes_quirurgicos" => $antecedentes_quirurgicos,
  354.             "antecedentes_familiares"  => $antecedentes_familiares,
  355.             "alcohol"    => $alcohol,
  356.             "tabaco"     => $tabaco,
  357.             "drogas"     => $drogas,
  358.             "alergias"   => $alergias,
  359.             "medicacion" => $medicacion,
  360.             "ago"        => $ago,
  361.             "fum"        => $fum,
  362.             "gesta"      => $gesta,
  363.             "abo"        => $abo,
  364.             "para"       => $para,
  365.             "cesa"       => $cesa,  
  366.         ]);
  367.     }
  368.     /**
  369.      * @Route("/topaz/firmar/{id}", name="paciente_topaz_firmar", methods={"GET","POST"})
  370.      */
  371.     public function topaz_firmar(Request $requestPaciente $paciente): Response
  372.     {
  373.         $base64Image $request->request->get('sigRawData');
  374.         
  375.         if($base64Image=='Base64 String: '){
  376.             return $this->json(['result' => 'error']);    
  377.         }
  378.         $base        base64_decode($base64Image); 
  379.         file_put_contents($this->getParameter('brochures_directory').'/firma_'.$paciente->getCedula().'.png',$base);
  380.         
  381.         return $this->json(['result' => 'ok']);
  382.     }
  383.     
  384.     /**
  385.      * @Route("/guardar/{id}", name="paciente_hc_guardar", methods={"POST"})
  386.      */
  387.     public function hc_guardar(Paciente $pacienteRequest $request): Response
  388.     {
  389.         $brochureFile $request->files->get('res_lab');
  390.             
  391.         if ($brochureFile) {
  392.             $originalFilename pathinfo($brochureFile->getClientOriginalName(), PATHINFO_FILENAME);
  393.                 
  394.             // this is needed to safely include the file name as part of the URL
  395.             $safeFilename ='hc_'.$paciente->getId().date("YmdHis");
  396.             //$newFilename = $safeFilename.'-'.uniqid().'.'.$brochureFile->guessExtension();
  397.             $newFilename $safeFilename.'.'.$brochureFile->guessExtension();
  398.             // Move the file to the directory where brochures are stored
  399.             try {
  400.                 $brochureFile->move(
  401.                     $this->getParameter('brochures_directory'),
  402.                     $newFilename
  403.                 );
  404.                 $paciente->setCopiaCedula($newFilename);
  405.                 $entityManager $this->getDoctrine()->getManager();
  406.                 $entityManager->persist($paciente);
  407.                 $entityManager->flush();
  408.             } catch (FileException $e) {
  409.             // ... handle exception if something happens during file upload
  410.             }
  411.             return $this->json(['estado' => 'ok']);
  412.         }
  413.         
  414.         return $this->json(['estado' => 'no']);
  415.     }
  416.     
  417.     /**
  418.      * @Route("/eliminar/{id}", name="paciente_hc_eliminar", methods={"GET"})
  419.      */
  420.     public function hc_eliminar(Paciente $pacienteRequest $request): Response
  421.     {
  422.         /*$filename = './uploads/laboratorio_externo/le_'.$agenda->getId().'.pdf';
  423.         $file_exists = file_exists($filename);//dd($file_exists);
  424.         
  425.         if($file_exists){
  426.             unlink($filename);    
  427.         }*/
  428.         
  429.         $paciente->setCopiaCedula(null);
  430.         $entityManager $this->getDoctrine()->getManager();
  431.         $entityManager->persist($paciente);
  432.         $entityManager->flush();
  433.         
  434.         return $this->json(['estado' => 'ok']);
  435.     }
  436. }