Add populateNotes method to populate the appropriate notes within a referral

This commit is contained in:
Ryan Prather 2024-12-17 12:03:25 -05:00
parent de08885e0b
commit f6addcc199

View File

@ -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));
}
// /**