diff --git a/src/Repository/ReferralRepository.php b/src/Repository/ReferralRepository.php index 5b5c82b..136a02e 100644 --- a/src/Repository/ReferralRepository.php +++ b/src/Repository/ReferralRepository.php @@ -4,7 +4,9 @@ namespace App\Repository; use App\Entity\MemberCase; use App\Entity\Referral; +use App\Enums\ReferralServiceType; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Persistence\ManagerRegistry; /** @@ -19,7 +21,7 @@ class ReferralRepository extends ServiceEntityRepository public function getActiveReferrals(MemberCase $case): array { - return $this->createQueryBuilder('r') + $referrals = $this->createQueryBuilder('r') ->andWhere('r.dischargeDate IS NULL') ->andWhere('r.memberCase = :case') ->setParameter('case', $case->getId()->toBinary()) @@ -27,11 +29,17 @@ class ReferralRepository extends ServiceEntityRepository ->getQuery() ->getResult() ; + + foreach ($referrals as $idx => $ref) { + $this->populateNotes($referrals[$idx]); + } + + return $referrals; } public function getClosedReferrals(MemberCase $case): array { - return $this->createQueryBuilder('r') + $referrals = $this->createQueryBuilder('r') ->andWhere('r.dischargeDate IS NOT NULL') ->andWhere('r.memberCase = :case') ->setParameter('case', $case->getId()->toBinary()) @@ -39,6 +47,35 @@ class ReferralRepository extends ServiceEntityRepository ->getQuery() ->getResult() ; + + foreach ($referrals as $idx => $ref) { + $this->populateNotes($referrals[$idx]); + } + + return $referrals; + } + + public function populateNotes(Referral &$referral): void + { + $noteType = 'App\Entity\StandardNote'; + + if ($referral->getServiceCode() == ReferralServiceType::VS_THBB) { + $noteType = 'App\Entity\VisitNote'; + } + + $query = $this->getEntityManager()->createQuery(" + SELECT n + FROM $noteType n + WHERE n.referral = :referral + "); + $query->setParameter('referral', $referral->getId()->toBinary()); + $res = $query->getResult(); + + if (!count($res)){ + return; + } + + $referral->setNotes(new ArrayCollection($res)); } // /**