src/Controller/Registry/RegistryController.php line 126

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: vad
  5.  * Date: 8/29/18
  6.  * Time: 8:28 PM
  7.  */
  8. namespace App\Controller\Registry;
  9. use App\Entity\Institution;
  10. use App\Repository\AppointmentRepository;
  11. use App\Repository\DepartmentRepository;
  12. use App\Repository\DoctorRepository;
  13. use App\Repository\InstitutionRepository;
  14. use App\Repository\PlaceRepository;
  15. use DateTimeImmutable;
  16. use Exception;
  17. use Mpdf\Mpdf;
  18. use Mpdf\MpdfException;
  19. use Mpdf\Output\Destination;
  20. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  21. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  25. use Symfony\Component\Routing\Annotation\Route;
  26. class RegistryController extends AbstractController
  27. {
  28.     /**
  29.      * @Route("", methods={"GET"}, name="homepage")
  30.      * @Template("registry/patient-appointment.html.twig")
  31.      */
  32.     public function showAction(Request               $request,
  33.                                DoctorRepository      $doctorRepository,
  34.                                DepartmentRepository  $departmentRepository,
  35.                                InstitutionRepository $institutionRepository,
  36.                                PlaceRepository       $placeRepository,
  37.                                SessionInterface      $session): array
  38.     {
  39.         $doctorId $request->query->get('doctor-id');
  40.         $departmentId $request->query->get('department-id');
  41.         $institutionId $request->query->get('institution-id');
  42.         $placeId $request->query->get('place-id');
  43.         $appointmentDate $request->query->get('appointment-date');
  44.         if ($session->has('doctor-id')) {
  45.             if (is_null($doctorId)) {
  46.                 $doctorId $session->get('doctor-id');
  47.             }
  48.             $session->remove('doctor-id');
  49.         }
  50.         if ($session->has('appointment-date')) {
  51.             if (is_null($appointmentDate)) {
  52.                 $appointmentDate $session->get('appointment-date');
  53.             }
  54.             $session->remove('appointment-date');
  55.         }
  56.         if (!is_null($doctorId)) {
  57.             $doctor $doctorRepository->find($doctorId);
  58.             if (!is_null($doctor)) {
  59.                 $department $doctor->getDepartment();
  60.                 $departmentId $department->getId();
  61.                 $institution $department->getInstitution();
  62.                 $institutionId $institution->getId();
  63.                 $placeId $institution->getPlace()->getId();
  64.             } else {
  65.                 $doctorId null;
  66.             }
  67.         } else if (!is_null($departmentId)) {
  68.             $department $departmentRepository->find($departmentId);
  69.             if (!is_null($department)) {
  70.                 $institution $department->getInstitution();
  71.                 $institutionId $institution->getId();
  72.                 $placeId $institution->getPlace()->getId();
  73.             } else {
  74.                 $departmentId null;
  75.             }
  76.         } else if (!is_null($institutionId)) {
  77.             $institution $institutionRepository->find($institutionId);
  78.             if (!is_null($institution)) {
  79.                 $placeId $institution->getPlace()->getId();
  80.             } else {
  81.                 $institutionId null;
  82.             }
  83.         } else if (!is_null($placeId)) {
  84.             $place $placeRepository->find($placeId);
  85.             if (is_null($place)) {
  86.                 $placeId null;
  87.             }
  88.         }
  89.         if ((!is_null($appointmentDate)) &&
  90.             (is_null($doctorId) || ($appointmentDate !== DateTimeImmutable::createFromFormat('!Y-m-d'$appointmentDate)->format('Y-m-d')))) {
  91.             $appointmentDate null;
  92.         }
  93.         return [
  94.             'placeId' => $placeId,
  95.             'institutionId' => $institutionId,
  96.             'departmentId' => $departmentId,
  97.             'doctorId' => $doctorId,
  98.             'appointmentDate' => $appointmentDate,
  99.         ];
  100.     }
  101.     /**
  102.      * @Route("appointment-by-institution/{id}", methods={"GET"}, name="patient-appointment-by-institution")
  103.      * @Template("registry/patient-appointment.html.twig")
  104.      */
  105.     public function appointmentByInstitutionAction(Institution $institution): array
  106.     {
  107.         return [
  108.             'placeId' => $institution->getPlace()->getId(),
  109.             'institutionId' => $institution->getId(),
  110.         ];
  111.     }
  112.     /**
  113.      * @Route("/sign-up", methods={"GET"}, name="sign-up")
  114.      * @Template("registry/sign-up.html.twig")
  115.      */
  116.     public function signUpAction(Request $request,
  117.                                  SessionInterface $session): array
  118.     {
  119.         if ($request->query->has('doctor-id')) {
  120.             $session->set('doctor-id'$request->query->get('doctor-id'));
  121.         }
  122.         if ($request->query->has('appointment-date')) {
  123.             $session->set('appointment-date'$request->query->get('appointment-date'));
  124.         }
  125.         return [];
  126.     }
  127.     /**
  128.      * @Route("/appointment-info-pdf/{appointmentId}", methods={"GET"}, name="appointment-info-pdf")
  129.      * @throws MpdfException
  130.      * @throws \Doctrine\DBAL\Driver\Exception
  131.      * @throws \Doctrine\DBAL\Exception
  132.      * @throws Exception
  133.      */
  134.     public function getAppointmentInfoPdfAction($appointmentIdAppointmentRepository $appointmentRepository): Response
  135.     {
  136.         $appointmentInfo $appointmentRepository->getAppointmentInfo($appointmentId);
  137.         $pdf = new Mpdf(['tempDir' => $this->getParameter('kernel.project_dir') . '/var/temp/mpdf']);
  138.         $pdf->AddPage();
  139.         $pdf->SetFont('Arial''B'16);
  140.         $pdf->Cell(010'Запис на прийом'01);
  141.         $pdf->SetFont('Arial'''12);
  142.         $pdf->Cell(010,
  143.             'Лікар: ' .
  144.             $appointmentInfo['doctor_last_name'] . ' ' .
  145.             $appointmentInfo['doctor_first_name'] . ' ' .
  146.             $appointmentInfo['doctor_second_name'],
  147.             01);
  148.         $appointmentDate = new DateTimeImmutable($appointmentInfo['appointment_date']);
  149.         $appointmentTime = new DateTimeImmutable($appointmentInfo['appointment_time']);
  150.         $pdf->Cell(010,
  151.             'Дата: ' $appointmentDate->format('d.m.Y') . ',  ' .
  152.             'Час: ' $appointmentTime->format('H:i') . ',  ' .
  153.             'Кабінет: ' $appointmentInfo['cabinet_number'],
  154.             01);
  155.         if ($appointmentInfo['registry_phone_number']) {
  156.             $pdf->Cell(010'Телефон реєстратури: ' .
  157.                 $appointmentInfo['registry_phone_number'], 01);
  158.         }
  159.         return new Response(
  160.             $pdf->Output('appointment.pdf'Destination::INLINE),
  161.             Response::HTTP_OK,
  162.             array('content-type' => 'application/pdf')
  163.         );
  164.     }
  165.     /**
  166.      * @Route("/restore-password", methods={"GET"}, name="restore-password")
  167.      * @Template("registry/restore-password.html.twig")
  168.      */
  169.     public function restorePasswordAction(): array
  170.     {
  171.         return [];
  172.     }
  173. }