src/Repository/PrimaryHipRepository.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\PrimaryHip;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use Doctrine\DBAL\Connection;
  7. /**
  8.  * @method PrimaryHip|null find($id, $lockMode = null, $lockVersion = null)
  9.  * @method PrimaryHip|null findOneBy(array $criteria, array $orderBy = null)
  10.  * @method PrimaryHip[]    findAll()
  11.  * @method PrimaryHip[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  12.  */
  13. class PrimaryHipRepository extends ServiceEntityRepository
  14. {
  15.     public function __construct(ManagerRegistry $registry)
  16.     {
  17.         parent::__construct($registryPrimaryHip::class);
  18.     }
  19.     // /**
  20.     //  * @return PrimaryHip[] Returns an array of PrimaryHip objects
  21.     //  */
  22.     /*
  23.     public function findByExampleField($value)
  24.     {
  25.         return $this->createQueryBuilder('p')
  26.             ->andWhere('p.exampleField = :val')
  27.             ->setParameter('val', $value)
  28.             ->orderBy('p.id', 'ASC')
  29.             ->setMaxResults(10)
  30.             ->getQuery()
  31.             ->getResult()
  32.         ;
  33.     }
  34.     */
  35.     /*
  36.     public function findOneBySomeField($value): ?PrimaryHip
  37.     {
  38.         return $this->createQueryBuilder('p')
  39.             ->andWhere('p.exampleField = :val')
  40.             ->setParameter('val', $value)
  41.             ->getQuery()
  42.             ->getOneOrNullResult()
  43.         ;
  44.     }
  45.     */
  46.     //Ieškome tarp visų įrašų (Registro administratorius)
  47.     public function findByString($value$offset null$limit null)
  48.     {
  49.         $values explode(" "$value);
  50.         $values array_map("trim"$values);
  51.         $values array_filter($values);
  52.      
  53.         foreach ($values as $val) {
  54.             if($val !== ""){
  55.                 $val1 addslashes($val);
  56.                 $sql[] = "(pr.firstName LIKE '%".$val1."%' OR pr.lastName LIKE '%".$val1."%' OR pr.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%' OR pl.firstName LIKE '%".$val1."%' OR pl.lastName LIKE '%".$val1."%' OR pl.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%')";
  57.             }
  58.         }
  59.         
  60.         $sql implode(" AND "$sql);
  61.         return $this->createQueryBuilder('o')
  62.             ->select('o')
  63.             ->leftJoin('o.patientRightHip','pr')
  64.             ->leftJoin('o.patientLeftHip','pl')
  65.             ->andWhere($sql)
  66.             ->setFirstResult$offset )
  67.             ->setMaxResults$limit )
  68.             ->orderBy('o.Date''DESC')
  69.             ->getQuery()
  70.             ->getResult()
  71.         ;
  72.     }
  73.     public function findByStringCount($value)
  74.     {
  75.         $values explode(" "$value);
  76.         $values array_map("trim"$values);
  77.         $values array_filter($values);
  78.         
  79.         foreach ($values as $val) {
  80.             if($val !== ""){
  81.                 $val1 addslashes($val);
  82.                 $sql[] = "(pr.firstName LIKE '%".$val1."%' OR pr.lastName LIKE '%".$val1."%' OR pr.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%' OR pl.firstName LIKE '%".$val1."%' OR pl.lastName LIKE '%".$val1."%' OR pl.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%')";
  83.             }
  84.         }
  85.     
  86.         $sql implode(" AND "$sql);
  87.         return $this->createQueryBuilder('o')
  88.             ->select('count(o.id)')
  89.             ->leftJoin('o.patientRightHip','pr')
  90.             ->leftJoin('o.patientLeftHip','pl')
  91.             ->andWhere($sql)
  92.             ->getQuery()
  93.             ->getSingleScalarResult()
  94.         ;
  95.     }
  96.     //Ieškome tarp operavusio gydytojo įrašų (Operatorius)
  97.     public function findOfDoctorByString($value$doctor$offset null$limit null)
  98.     {
  99.         $values explode(" "$value);
  100.         $values array_map("trim"$values);
  101.         $values array_filter($values);
  102.      
  103.         foreach ($values as $val) {
  104.             if($val !== ""){
  105.                 $val1 addslashes($val);
  106.                 $sql[] = "(pr.firstName LIKE '%".$val1."%' OR pr.lastName LIKE '%".$val1."%' OR pr.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%' OR pl.firstName LIKE '%".$val1."%' OR pl.lastName LIKE '%".$val1."%' OR pl.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%')";
  107.             }
  108.         }
  109.         
  110.         $sql implode(" AND "$sql);
  111.         return $this->createQueryBuilder('o')
  112.             ->select('o')
  113.             ->leftJoin('o.patientRightHip','pr')
  114.             ->leftJoin('o.patientLeftHip','pl')
  115.             ->andWhere($sql)
  116.             ->andWhere('o.Doctor = :doctor')
  117.             ->setParameter('doctor'$doctor)
  118.             ->setFirstResult$offset )
  119.             ->setMaxResults$limit )
  120.             ->orderBy('o.Date''DESC')
  121.             ->getQuery()
  122.             ->getResult()
  123.         ;
  124.     }
  125.     public function findOfDoctorByStringCount($value$doctor)
  126.     {
  127.         $values explode(" "$value);
  128.         $values array_map("trim"$values);
  129.         $values array_filter($values);
  130.         
  131.         foreach ($values as $val) {
  132.             if($val !== ""){
  133.                 $val1 addslashes($val);
  134.                 $sql[] = "(pr.firstName LIKE '%".$val1."%' OR pr.lastName LIKE '%".$val1."%' OR pr.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%' OR pl.firstName LIKE '%".$val1."%' OR pl.lastName LIKE '%".$val1."%' OR pl.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%')";
  135.             }
  136.         }
  137.     
  138.         $sql implode(" AND "$sql);
  139.         return $this->createQueryBuilder('o')
  140.             ->select('count(o.id)')
  141.             ->leftJoin('o.patientRightHip','pr')
  142.             ->leftJoin('o.patientLeftHip','pl')
  143.             ->andWhere($sql)
  144.             ->andWhere('o.Doctor = :doctor')
  145.             ->setParameter('doctor'$doctor)
  146.             ->getQuery()
  147.             ->getSingleScalarResult()
  148.         ;
  149.     }
  150.     //Ieškome tarp ligoninės įrašų (Operatorius, Ligoninės adminas)
  151.     public function findOfHospitalByString($value$hospital$offset null$limit null)
  152.     {
  153.         $values explode(" "$value);
  154.         $values array_map("trim"$values);
  155.         $values array_filter($values);
  156.     
  157.         foreach ($values as $val) {
  158.             if($val !== ""){
  159.                 $val1 addslashes($val);
  160.                 $sql[] = "(pr.firstName LIKE '%".$val1."%' OR pr.lastName LIKE '%".$val1."%' OR pr.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%' OR pl.firstName LIKE '%".$val1."%' OR pl.lastName LIKE '%".$val1."%' OR pl.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%')";
  161.             }
  162.         }
  163.         
  164.         $sql implode(" AND "$sql);
  165.         return $this->createQueryBuilder('o')
  166.             ->select('o')
  167.             ->leftJoin('o.patientRightHip','pr')
  168.             ->leftJoin('o.patientLeftHip','pl')
  169.             ->andWhere($sql)
  170.             ->andWhere('o.Hospital = :hospital')
  171.             ->setParameter('hospital'$hospital)
  172.             ->setFirstResult$offset )
  173.             ->setMaxResults$limit )
  174.             ->orderBy('o.Date''DESC')
  175.             ->getQuery()
  176.             ->getResult()
  177.         ;
  178.     }
  179.     public function findOfHospitalByStringCount($value$hospital)
  180.     {
  181.         $values explode(" "$value);
  182.         $values array_map("trim"$values);
  183.         $values array_filter($values);
  184.         
  185.         foreach ($values as $val) {
  186.             if($val !== ""){
  187.                 $val1 addslashes($val);
  188.                 $sql[] = "(pr.firstName LIKE '%".$val1."%' OR pr.lastName LIKE '%".$val1."%' OR pr.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%' OR pl.firstName LIKE '%".$val1."%' OR pl.lastName LIKE '%".$val1."%' OR pl.identifier LIKE '%".$val1."%' OR o.Date LIKE '%".$val1."%')";
  189.             }
  190.         }
  191.         $sql implode(" AND "$sql);
  192.         return $this->createQueryBuilder('o')
  193.             ->select('count(o.id)')
  194.             ->leftJoin('o.patientRightHip','pr')
  195.             ->leftJoin('o.patientLeftHip','pl')
  196.             ->andWhere($sql)
  197.             ->andWhere('o.Hospital = :hospital')
  198.             ->setParameter('hospital'$hospital)
  199.             ->getQuery()
  200.             ->getSingleScalarResult()
  201.         ;
  202.     }
  203.      
  204.      public function countAll()
  205.      {
  206.          return $this->createQueryBuilder('p')
  207.              ->select('count(p.id)')
  208.              ->getQuery()
  209.              ->getSingleScalarResult()
  210.          ;
  211.      }
  212.     public function countByDoctor($value)
  213.     {
  214.         return $this->createQueryBuilder('p')
  215.             ->andWhere('p.Doctor = :val')
  216.             ->setParameter('val'$value)
  217.             ->select('count(p.id)')
  218.             ->getQuery()
  219.             ->getSingleScalarResult()
  220.         ;
  221.     }
  222.     public function countByDoctors($value)
  223.     {
  224.         //dd($value);
  225.         return $this->createQueryBuilder('p')
  226.             ->where('p.Doctor IN (:val)')
  227.             ->setParameter('val'$value)
  228.             ->select('count(p.id)')
  229.             ->getQuery()
  230.             ->getSingleScalarResult()
  231.         ;
  232.     }
  233.     public function countByHospital($value)
  234.     {
  235.         return $this->createQueryBuilder('o')
  236.             ->select('count(o.id)')
  237.             ->leftJoin('o.patientRightHip','pr')
  238.             ->leftJoin('o.patientLeftHip','pl')
  239.             ->andWhere('o.Hospital = :hospital')
  240.             ->setParameter('hospital'$value)
  241.             ->getQuery()
  242.             ->getSingleScalarResult()
  243.         ;
  244.     }
  245.     public function mapAgeByDoctor($value$gender = [1,2,3,4,5,6,7,8,9])
  246.     {
  247.         return $this->createQueryBuilder('o')
  248.             ->select('o.Date''p.identifier''o.Diagnosis')
  249.             ->leftJoin('o.patientRightHip','pr')
  250.             ->innerJoin('o.patientLeftHip','p')
  251.             ->andWhere('o.Doctor = :doctor')
  252.             ->andWhere('SUBSTRING(p.identifier, 1, 1) IN (:gender)')
  253.             ->setParameter('doctor'$value)
  254.             ->setParameter('gender'$gender)
  255.             ->getQuery()
  256.             ->getResult()
  257.         ;
  258.     }
  259.     public function mapAgeByHospital($value$gender = [1,2,3,4,5,6,7,8,9])
  260.     {
  261.         return $this->createQueryBuilder('o')
  262.             ->select('o.Date''p.identifier''o.Diagnosis')
  263.             ->leftJoin('o.patientRightHip','pr')
  264.             ->innerJoin('o.patientLeftHip','p')
  265.             ->andWhere('o.Hospital = :Hospital')
  266.             ->andWhere('SUBSTRING(p.identifier, 1, 1) IN (:gender)')
  267.             ->setParameter('Hospital'$value)
  268.             ->setParameter('gender'$gender)
  269.             ->getQuery()
  270.             ->getResult()
  271.         ;
  272.     }
  273.     public function mapAllAge($gender = [1,2,3,4,5,6,7,8,9])
  274.     {
  275.         return $this->createQueryBuilder('o')
  276.             ->select('o.Date''p.identifier''o.Diagnosis')
  277.             ->leftJoin('o.patientRightHip','pr')
  278.             ->innerJoin('o.patientLeftHip','p')
  279.             ->andWhere('SUBSTRING(p.identifier, 1, 1) IN (:gender)')
  280.             ->setParameter('gender'$gender)
  281.             ->getQuery()
  282.             ->getResult()
  283.         ;
  284.     }
  285.     public function findFromTo($dateFrom$dateTo)
  286.     {
  287.         return $this->createQueryBuilder('o')
  288.             ->select('o')
  289.             ->leftJoin('o.patientRightHip','pr')
  290.             ->leftJoin('o.patientLeftHip','pl')
  291.             ->andWhere('o.Date >= :dateFrom')
  292.             ->andWhere('o.Date <= :dateTo')
  293.             ->setParameter('dateFrom'$dateFrom)
  294.             ->setParameter('dateTo'$dateTo)
  295.             ->orderBy('o.Date''DESC')
  296.             ->getQuery()
  297.             ->getResult()
  298.         ;
  299.     }
  300.     public function findPrimaryByString($value$offset null$limit null)
  301.     {
  302.         $values explode(" "$value);
  303.         $values array_map("trim"$values);
  304.         $values array_filter($values);
  305.        
  306.         foreach ($values as $val) {
  307.             if($val !== ""){
  308.                 $val1 addslashes($val);
  309.                 $sql[] = "(l.firstName LIKE '%".$val1."%' OR l.lastName LIKE '%".$val1."%' OR l.identifier LIKE '%".$val1."%' OR r.firstName LIKE '%".$val1."%' OR r.lastName LIKE '%".$val1."%' OR r.identifier LIKE '%".$val1."%')";
  310.             }
  311.         }
  312.     
  313.         $sql implode(" AND "$sql);
  314.         return $this->createQueryBuilder('o')
  315.             ->select('o')
  316.             ->leftJoin('o.patientLeftHip','l')
  317.             ->leftJoin('o.patientRightHip','r')
  318.             ->andWhere($sql)
  319.             ->setFirstResult$offset )
  320.             ->setMaxResults$limit )
  321.             ->orderBy('o.Date''DESC')
  322.             ->getQuery()
  323.             ->getResult()
  324.         ;
  325.     }
  326. }