<?php
namespace App\Repository;
use App\Entity\PrimaryHip;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\DBAL\Connection;
/**
* @method PrimaryHip|null find($id, $lockMode = null, $lockVersion = null)
* @method PrimaryHip|null findOneBy(array $criteria, array $orderBy = null)
* @method PrimaryHip[] findAll()
* @method PrimaryHip[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class PrimaryHipRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, PrimaryHip::class);
}
// /**
// * @return PrimaryHip[] Returns an array of PrimaryHip objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('p')
->andWhere('p.exampleField = :val')
->setParameter('val', $value)
->orderBy('p.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?PrimaryHip
{
return $this->createQueryBuilder('p')
->andWhere('p.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
//Ieškome tarp visų įrašų (Registro administratorius)
public function findByString($value, $offset = null, $limit = null)
{
$values = explode(" ", $value);
$values = array_map("trim", $values);
$values = array_filter($values);
foreach ($values as $val) {
if($val !== ""){
$val1 = addslashes($val);
$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."%')";
}
}
$sql = implode(" AND ", $sql);
return $this->createQueryBuilder('o')
->select('o')
->leftJoin('o.patientRightHip','pr')
->leftJoin('o.patientLeftHip','pl')
->andWhere($sql)
->setFirstResult( $offset )
->setMaxResults( $limit )
->orderBy('o.Date', 'DESC')
->getQuery()
->getResult()
;
}
public function findByStringCount($value)
{
$values = explode(" ", $value);
$values = array_map("trim", $values);
$values = array_filter($values);
foreach ($values as $val) {
if($val !== ""){
$val1 = addslashes($val);
$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."%')";
}
}
$sql = implode(" AND ", $sql);
return $this->createQueryBuilder('o')
->select('count(o.id)')
->leftJoin('o.patientRightHip','pr')
->leftJoin('o.patientLeftHip','pl')
->andWhere($sql)
->getQuery()
->getSingleScalarResult()
;
}
//Ieškome tarp operavusio gydytojo įrašų (Operatorius)
public function findOfDoctorByString($value, $doctor, $offset = null, $limit = null)
{
$values = explode(" ", $value);
$values = array_map("trim", $values);
$values = array_filter($values);
foreach ($values as $val) {
if($val !== ""){
$val1 = addslashes($val);
$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."%')";
}
}
$sql = implode(" AND ", $sql);
return $this->createQueryBuilder('o')
->select('o')
->leftJoin('o.patientRightHip','pr')
->leftJoin('o.patientLeftHip','pl')
->andWhere($sql)
->andWhere('o.Doctor = :doctor')
->setParameter('doctor', $doctor)
->setFirstResult( $offset )
->setMaxResults( $limit )
->orderBy('o.Date', 'DESC')
->getQuery()
->getResult()
;
}
public function findOfDoctorByStringCount($value, $doctor)
{
$values = explode(" ", $value);
$values = array_map("trim", $values);
$values = array_filter($values);
foreach ($values as $val) {
if($val !== ""){
$val1 = addslashes($val);
$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."%')";
}
}
$sql = implode(" AND ", $sql);
return $this->createQueryBuilder('o')
->select('count(o.id)')
->leftJoin('o.patientRightHip','pr')
->leftJoin('o.patientLeftHip','pl')
->andWhere($sql)
->andWhere('o.Doctor = :doctor')
->setParameter('doctor', $doctor)
->getQuery()
->getSingleScalarResult()
;
}
//Ieškome tarp ligoninės įrašų (Operatorius, Ligoninės adminas)
public function findOfHospitalByString($value, $hospital, $offset = null, $limit = null)
{
$values = explode(" ", $value);
$values = array_map("trim", $values);
$values = array_filter($values);
foreach ($values as $val) {
if($val !== ""){
$val1 = addslashes($val);
$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."%')";
}
}
$sql = implode(" AND ", $sql);
return $this->createQueryBuilder('o')
->select('o')
->leftJoin('o.patientRightHip','pr')
->leftJoin('o.patientLeftHip','pl')
->andWhere($sql)
->andWhere('o.Hospital = :hospital')
->setParameter('hospital', $hospital)
->setFirstResult( $offset )
->setMaxResults( $limit )
->orderBy('o.Date', 'DESC')
->getQuery()
->getResult()
;
}
public function findOfHospitalByStringCount($value, $hospital)
{
$values = explode(" ", $value);
$values = array_map("trim", $values);
$values = array_filter($values);
foreach ($values as $val) {
if($val !== ""){
$val1 = addslashes($val);
$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."%')";
}
}
$sql = implode(" AND ", $sql);
return $this->createQueryBuilder('o')
->select('count(o.id)')
->leftJoin('o.patientRightHip','pr')
->leftJoin('o.patientLeftHip','pl')
->andWhere($sql)
->andWhere('o.Hospital = :hospital')
->setParameter('hospital', $hospital)
->getQuery()
->getSingleScalarResult()
;
}
public function countAll()
{
return $this->createQueryBuilder('p')
->select('count(p.id)')
->getQuery()
->getSingleScalarResult()
;
}
public function countByDoctor($value)
{
return $this->createQueryBuilder('p')
->andWhere('p.Doctor = :val')
->setParameter('val', $value)
->select('count(p.id)')
->getQuery()
->getSingleScalarResult()
;
}
public function countByDoctors($value)
{
//dd($value);
return $this->createQueryBuilder('p')
->where('p.Doctor IN (:val)')
->setParameter('val', $value)
->select('count(p.id)')
->getQuery()
->getSingleScalarResult()
;
}
public function countByHospital($value)
{
return $this->createQueryBuilder('o')
->select('count(o.id)')
->leftJoin('o.patientRightHip','pr')
->leftJoin('o.patientLeftHip','pl')
->andWhere('o.Hospital = :hospital')
->setParameter('hospital', $value)
->getQuery()
->getSingleScalarResult()
;
}
public function mapAgeByDoctor($value, $gender = [1,2,3,4,5,6,7,8,9])
{
return $this->createQueryBuilder('o')
->select('o.Date', 'p.identifier', 'o.Diagnosis')
->leftJoin('o.patientRightHip','pr')
->innerJoin('o.patientLeftHip','p')
->andWhere('o.Doctor = :doctor')
->andWhere('SUBSTRING(p.identifier, 1, 1) IN (:gender)')
->setParameter('doctor', $value)
->setParameter('gender', $gender)
->getQuery()
->getResult()
;
}
public function mapAgeByHospital($value, $gender = [1,2,3,4,5,6,7,8,9])
{
return $this->createQueryBuilder('o')
->select('o.Date', 'p.identifier', 'o.Diagnosis')
->leftJoin('o.patientRightHip','pr')
->innerJoin('o.patientLeftHip','p')
->andWhere('o.Hospital = :Hospital')
->andWhere('SUBSTRING(p.identifier, 1, 1) IN (:gender)')
->setParameter('Hospital', $value)
->setParameter('gender', $gender)
->getQuery()
->getResult()
;
}
public function mapAllAge($gender = [1,2,3,4,5,6,7,8,9])
{
return $this->createQueryBuilder('o')
->select('o.Date', 'p.identifier', 'o.Diagnosis')
->leftJoin('o.patientRightHip','pr')
->innerJoin('o.patientLeftHip','p')
->andWhere('SUBSTRING(p.identifier, 1, 1) IN (:gender)')
->setParameter('gender', $gender)
->getQuery()
->getResult()
;
}
public function findFromTo($dateFrom, $dateTo)
{
return $this->createQueryBuilder('o')
->select('o')
->leftJoin('o.patientRightHip','pr')
->leftJoin('o.patientLeftHip','pl')
->andWhere('o.Date >= :dateFrom')
->andWhere('o.Date <= :dateTo')
->setParameter('dateFrom', $dateFrom)
->setParameter('dateTo', $dateTo)
->orderBy('o.Date', 'DESC')
->getQuery()
->getResult()
;
}
public function findPrimaryByString($value, $offset = null, $limit = null)
{
$values = explode(" ", $value);
$values = array_map("trim", $values);
$values = array_filter($values);
foreach ($values as $val) {
if($val !== ""){
$val1 = addslashes($val);
$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."%')";
}
}
$sql = implode(" AND ", $sql);
return $this->createQueryBuilder('o')
->select('o')
->leftJoin('o.patientLeftHip','l')
->leftJoin('o.patientRightHip','r')
->andWhere($sql)
->setFirstResult( $offset )
->setMaxResults( $limit )
->orderBy('o.Date', 'DESC')
->getQuery()
->getResult()
;
}
}