navLinks = NavList::LIST; $this->navLinks['case_notes'] = NavList::PRESENT_LINK; } #[Route('/list-notes/{id?null}', name: 'app_list_notes')] public function listNotes(#[CurrentUser()] User $user, ?string $id = null): Response { /** @var UserCase[] $cases */ $cases = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); $referrals = []; $notes = []; if ($id == 'null') { $id = null; } if ($id) { $referrals[] = $this->entityManager->getRepository(Referral::class)->find($id); } else { foreach ($cases as $case) { $referrals = array_merge( $referrals, $this->entityManager->getRepository(Referral::class)->findBy(['memberCase' => $case->getMemberCase()]) ); } } foreach ($referrals as $referral) { $notes = array_merge( $notes, $this->entityManager->getRepository(VisitNote::class)->getOrderedNotes($referral), $this->entityManager->getRepository(StandardNote::class)->getOrderedNotes($referral), ); } return $this->render( 'internal/cases/notes/list-notes.html.twig', array_merge( $this->navLinks, [ 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_notes'), 'List Notes') ], 'notifications' => $user->retrieveUnreadNotifications(), 'cases' => $cases, 'notes' => $notes, ] ) ); } #[Route('/add-note/{id?null}', name: 'app_add_note')] public function addNote(#[CurrentUser()] User $user, Request $request, ?string $id = null): Response { /** @var Referral $referral */ $referral = $this->entityManager->getRepository(Referral::class)->find($id); $this->entityManager->getRepository(Referral::class)->populateNotes($referral); //dd($referral); $members = $this->entityManager->getRepository(Member::class)->findBy(['caseId' => $referral->getMemberCase()]); $defaultMethod = NoteMethod::BILLABLE; $defaultLocation = NoteLocation::COMMUNITY_OUTING; $form = $this->createForm(StandardNoteFormType::class, null, ['members' => $members]); $template = 'internal/cases/notes/add-standard-note.html.twig'; if ($id == 'null') { $id = null; } if ($referral->getServiceCode() == ReferralServiceType::VS_THBB) { $form = $this->createForm(VisitNoteFormType::class, null, ['members' => $members]); $template = 'internal/cases/notes/add-visit-note.html.twig'; $defaultMethod = NoteMethod::BILLABLE_SUPERVISED_VISIT; } elseif ($referral->getServiceCode() == ReferralServiceType::VS_THBBT) { $defaultMethod = NoteMethod::BILLABLE; $defaultLocation = NoteLocation::VEHICLE_TRANSPORTATION; } $form = $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { /** @var VisitNote|StandardNote $note */ $note = $form->getData(); $note->setReferral($referral); $this->entityManager->persist($note); $this->entityManager->flush(); return $this->redirectToRoute('app_list_notes'); } return $this->render( $template, array_merge( $this->navLinks, [ 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_notes'), 'List Notes') ], 'notifications' => $user->retrieveUnreadNotifications(), 'referral' => $referral, 'form' => $form, 'default_method' => $defaultMethod, 'default_location' => $defaultLocation, ] ) ); } #[Route('/edit-note', name: 'app_edit_note')] public function editNote(): Response { return $this->render( 'internal/cases/notes/edit-note.html.twig', array_merge( $this->navLinks, ) ); } #[Route('/api/filter-notes', name: 'api_filter_notes')] public function filterNotes(#[CurrentUser()] User $user, Request $request): Response { $startDate = $request->get('startDate'); $endDate = $request->get('endDate'); $referralId = $request->get('referralId'); $referral = null; if ($referralId) { $referral = $this->entityManager->getRepository(Referral::class)->find($referralId); } return $this->json(array_merge( $this->entityManager->getRepository(VisitNote::class)->filterNotes($user, $referral, $startDate, $endDate), $this->entityManager->getRepository(StandardNote::class)->filterNotes($user, $referral, $startDate, $endDate), )); } }