From 065b1ac403310c6721804920e49fe8206779ea84 Mon Sep 17 00:00:00 2001 From: Ryan Prather Date: Sun, 8 Dec 2024 18:37:45 -0500 Subject: [PATCH] Completed Referral functionality --- src/Controller/ReferralController.php | 122 ++++++++++++++++ src/Entity/MemberCase.php | 37 +++++ src/Entity/Referral.php | 132 ++++++++++++++++++ src/Enums/DischargeReason.php | 27 ++++ src/Enums/ReferralServiceType.php | 10 ++ src/Form/ReferralFormType.php | 44 ++++++ src/Repository/ReferralRepository.php | 68 +++++++++ templates/internal/cases/list-cases.html.twig | 6 +- .../cases/referrals/add-referral.html.twig | 73 ++++++++++ .../cases/referrals/edit-referral.html.twig | 73 ++++++++++ .../cases/referrals/list-referrals.html.twig | 123 ++++++++++++++++ 11 files changed, 714 insertions(+), 1 deletion(-) create mode 100644 src/Controller/ReferralController.php create mode 100644 src/Entity/Referral.php create mode 100644 src/Enums/DischargeReason.php create mode 100644 src/Enums/ReferralServiceType.php create mode 100644 src/Form/ReferralFormType.php create mode 100644 src/Repository/ReferralRepository.php create mode 100644 templates/internal/cases/referrals/add-referral.html.twig create mode 100644 templates/internal/cases/referrals/edit-referral.html.twig create mode 100644 templates/internal/cases/referrals/list-referrals.html.twig diff --git a/src/Controller/ReferralController.php b/src/Controller/ReferralController.php new file mode 100644 index 0000000..182ab24 --- /dev/null +++ b/src/Controller/ReferralController.php @@ -0,0 +1,122 @@ +navLinks = NavList::LIST; + } + + #[Route('/list-referrals/{id}', name: 'app_list_referrals')] + public function listReferrals(Request $request, #[CurrentUser()] User $user, string $id): Response + { + $case = $this->entityManager->getRepository(MemberCase::class)->find($id); + $openReferrals = $this->entityManager->getRepository(Referral::class)->getActiveReferrals($case); + $closedReferrals = $this->entityManager->getRepository(Referral::class)->getClosedReferrals($case); + + return $this->render( + 'internal/cases/referrals/list-referrals.html.twig', + array_merge( + $this->navLinks, + [ + 'breadcrumbs' => [ + 'Case', + 'Referrals' + ], + 'notifications' => $user->retrieveUnreadNotifications(), + 'case' => $case, + 'openReferrals' => $openReferrals, + 'closedReferrals' => $closedReferrals, + ] + ) + ); + } + + #[Route('/add-referral/{id}', name: 'app_case_add_referral')] + public function addReferral(Request $request, #[CurrentUser()] User $user, string $id): Response + { + $case = $this->entityManager->getRepository(MemberCase::class)->find($id); + + $referral = new Referral(); + $form = $this->createForm(ReferralFormType::class, $referral); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $referral = $form->getData(); + $referral->setMemberCase($case); + + $this->entityManager->persist($referral); + $this->entityManager->flush(); + + return $this->redirectToRoute('app_list_referrals', ['id' => $case->getId()]); + } + + return $this->render( + 'internal/cases/referrals/add-referral.html.twig', + array_merge( + $this->navLinks, + [ + 'breadcrumbs' => [ + 'Case', + 'Add Referral' + ], + 'notifications' => $user->retrieveUnreadNotifications(), + 'case' => $case, + 'form' => $form, + ] + ) + ); + } + + #[Route('/case/{caseId}/edit-referral/{referralId}', name: 'app_case_edit_referral')] + public function editReferral(Request $request, #[CurrentUser()] User $user, string $caseId, string $referralId): Response + { + $referral = $this->entityManager->getRepository(Referral::class)->find($referralId); + $case = $this->entityManager->getRepository(MemberCase::class)->find($caseId); + + $form = $this->createForm(ReferralFormType::class, $referral); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $referral = $form->getData(); + + $this->entityManager->flush(); + + return $this->redirectToRoute('app_list_referrals', ['id' => $case->getId()]); + } + + return $this->render( + 'internal/cases/referrals/edit-referral.html.twig', + array_merge( + $this->navLinks, + [ + 'breadcrumbs' => [ + 'Case', + 'Edit Referral' + ], + 'notifications' => $user->retrieveUnreadNotifications(), + 'case' => $case, + 'form' => $form, + 'referral' => $referral, + ] + ) + ); + } +} diff --git a/src/Entity/MemberCase.php b/src/Entity/MemberCase.php index 4b1870e..90445c9 100644 --- a/src/Entity/MemberCase.php +++ b/src/Entity/MemberCase.php @@ -85,9 +85,16 @@ class MemberCase #[ORM\OneToMany(targetEntity: UserCase::class, mappedBy: 'memberCase')] private Collection $userCases; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Referral::class, mappedBy: 'memberCase', orphanRemoval: true)] + private Collection $referrals; + public function __construct() { $this->userCases = new ArrayCollection(); + $this->referrals = new ArrayCollection(); } public function getId(): ?Uuid @@ -357,4 +364,34 @@ class MemberCase return $this; } + + /** + * @return Collection + */ + public function getReferrals(): Collection + { + return $this->referrals; + } + + public function addReferral(Referral $referral): static + { + if (!$this->referrals->contains($referral)) { + $this->referrals->add($referral); + $referral->setMemberCase($this); + } + + return $this; + } + + public function removeReferral(Referral $referral): static + { + if ($this->referrals->removeElement($referral)) { + // set the owning side to null (unless already changed) + if ($referral->getMemberCase() === $this) { + $referral->setMemberCase(null); + } + } + + return $this; + } } diff --git a/src/Entity/Referral.php b/src/Entity/Referral.php new file mode 100644 index 0000000..bdc3cbe --- /dev/null +++ b/src/Entity/Referral.php @@ -0,0 +1,132 @@ +id; + } + + public function getMemberCase(): ?MemberCase + { + return $this->memberCase; + } + + public function setMemberCase(?MemberCase $memberCase): static + { + $this->memberCase = $memberCase; + + return $this; + } + + public function getReferralId(): ?string + { + return $this->referralId; + } + + public function setReferralId(string $referralId): static + { + $this->referralId = $referralId; + + return $this; + } + + public function getServiceCode(): ?ReferralServiceType + { + return $this->serviceCode; + } + + public function setServiceCode(ReferralServiceType $serviceCode): static + { + $this->serviceCode = $serviceCode; + + return $this; + } + + public function getHours(): ?int + { + return $this->hours; + } + + public function setHours(int $hours): static + { + $this->hours = $hours; + + return $this; + } + + public function getEndDate(): ?\DateTimeInterface + { + return $this->endDate; + } + + public function setEndDate(\DateTimeInterface $endDate): static + { + $this->endDate = $endDate; + + return $this; + } + + public function getDischargeReason(): ?DischargeReason + { + return $this->dischargeReason; + } + + public function setDischargeReason(?DischargeReason $dischargeReason): static + { + $this->dischargeReason = $dischargeReason; + + return $this; + } + + public function getDischargeDate(): ?\DateTimeInterface + { + return $this->dischargeDate; + } + + public function setDischargeDate(?\DateTimeInterface $dischargeDate): static + { + $this->dischargeDate = $dischargeDate; + + return $this; + } +} diff --git a/src/Enums/DischargeReason.php b/src/Enums/DischargeReason.php new file mode 100644 index 0000000..6cdba5d --- /dev/null +++ b/src/Enums/DischargeReason.php @@ -0,0 +1,27 @@ +add('referralId') + ->add('serviceCode', EnumType::class, [ + 'class' => ReferralServiceType::class, + 'label' => 'Service Type' + ]) + ->add('hours') + ->add('endDate', null, [ + 'widget' => 'single_text', + ]) + ->add('dischargeReason', EnumType::class, [ + 'class' => DischargeReason::class + ]) + ->add('dischargeDate', null, [ + 'widget' => 'single_text', + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Referral::class, + ]); + } +} diff --git a/src/Repository/ReferralRepository.php b/src/Repository/ReferralRepository.php new file mode 100644 index 0000000..5b5c82b --- /dev/null +++ b/src/Repository/ReferralRepository.php @@ -0,0 +1,68 @@ + + */ +class ReferralRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Referral::class); + } + + public function getActiveReferrals(MemberCase $case): array + { + return $this->createQueryBuilder('r') + ->andWhere('r.dischargeDate IS NULL') + ->andWhere('r.memberCase = :case') + ->setParameter('case', $case->getId()->toBinary()) + ->orderBy('r.hours', 'ASC') + ->getQuery() + ->getResult() + ; + } + + public function getClosedReferrals(MemberCase $case): array + { + return $this->createQueryBuilder('r') + ->andWhere('r.dischargeDate IS NOT NULL') + ->andWhere('r.memberCase = :case') + ->setParameter('case', $case->getId()->toBinary()) + ->orderBy('r.dischargeDate', 'DESC') + ->getQuery() + ->getResult() + ; + } + + // /** + // * @return Referral[] Returns an array of Referral objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('r') + // ->andWhere('r.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('r.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Referral + // { + // return $this->createQueryBuilder('r') + // ->andWhere('r.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/templates/internal/cases/list-cases.html.twig b/templates/internal/cases/list-cases.html.twig index 77a2880..d7066b4 100644 --- a/templates/internal/cases/list-cases.html.twig +++ b/templates/internal/cases/list-cases.html.twig @@ -40,6 +40,7 @@ DCS Case ID Type/Source County + Referral Count Case Worker @@ -69,6 +70,9 @@

{{ c.county.value }}

+ +

{{ c.referrals|length }}

+

{% if c.userCases|length > 0 %} @@ -83,7 +87,7 @@ badge - + create_new_folder diff --git a/templates/internal/cases/referrals/add-referral.html.twig b/templates/internal/cases/referrals/add-referral.html.twig new file mode 100644 index 0000000..d7cf58c --- /dev/null +++ b/templates/internal/cases/referrals/add-referral.html.twig @@ -0,0 +1,73 @@ +{% extends 'base.html.twig' %} + +{% block body %} + {{ block('nav', 'internal/libs/nav.html.twig') }} + +

+ {{ block('topnav', 'internal/libs/top-nav.html.twig') }} + +
+ +
+
+

Add Referral

+

{{ case.caseName }}

+
+
+
+ {{ form_errors(form) }} + + {{ form_start(form) }} + +
+ + +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ + +
+ +
+
+ +
+
+ {{ form_end(form) }} +
+
+
+
+
+{% endblock %} diff --git a/templates/internal/cases/referrals/edit-referral.html.twig b/templates/internal/cases/referrals/edit-referral.html.twig new file mode 100644 index 0000000..e0b81e2 --- /dev/null +++ b/templates/internal/cases/referrals/edit-referral.html.twig @@ -0,0 +1,73 @@ +{% extends 'base.html.twig' %} + +{% block body %} + {{ block('nav', 'internal/libs/nav.html.twig') }} + +
+ {{ block('topnav', 'internal/libs/top-nav.html.twig') }} + +
+ +
+
+

Add Referral

+

{{ case.caseName }}

+
+
+
+ {{ form_errors(form) }} + + {{ form_start(form) }} + +
+ + +
+ +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ + +
+ +
+
+ +
+
+ {{ form_end(form) }} +
+
+
+
+
+{% endblock %} diff --git a/templates/internal/cases/referrals/list-referrals.html.twig b/templates/internal/cases/referrals/list-referrals.html.twig new file mode 100644 index 0000000..e73680e --- /dev/null +++ b/templates/internal/cases/referrals/list-referrals.html.twig @@ -0,0 +1,123 @@ +{% extends 'base.html.twig' %} + +{% block body %} + {{ block('nav', 'internal/libs/nav.html.twig') }} + +
+ {{ block('topnav', 'internal/libs/top-nav.html.twig') }} + +
+
+
+
+
+
+
+
Referral List
+
+
+ +
+
+
+
+
+ Filter: +
+
+ + + + + + + + + + + + {% for r in openReferrals %} + + + + + + + + + + + {% endfor %} + +
Referral IDServiceHours RemEnd Date
+
{{ r.referralId }}
+
+

{{ r.serviceCode.value }}

+
+

{{ r.hours }}

+
+

{{ r.endDate|date("F j, Y") }}

+
+ + edit + + + edit_note + + + close + +
+
+
+
+
+
+
+
+
+
Closed Referrals
+
+
+
+
+
+ + + + + + + + + + + + {% for r in closedReferrals %} + + + + + + + + + + + {% endfor %} + +
Referral IDServiceDischarge ReasonDischarge Date
+
{{ r.referralId }}
+
+

{{ r.serviceCode.value }}

+
+

{{ r.dischargeReason.value }}

+
+

{{ r.dischargeDate|date("F j, Y") }}

+
+
+
+ +
+
+{% endblock %}