navLinks = NavList::LIST; $this->navLinks['case_notes'] = NavList::PRESENT_LINK; } #[Route('/list-notes/{caseId?null}', name: 'app_list_notes')] public function listNotes(string $caseId = null, #[CurrentUser()] User $user, Request $request): Response { $this->msgs = Libs::getMessages($user, $this->entityManager); /** @var UserCase[] $cases */ $cases = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); $caseNotes = null; $case = null; if ($caseId != 'null') { $case = $this->entityManager->getRepository(MemberCase::class)->find($caseId); $params = [ 'case' => $case, 'referral' => null, 'startDate' => null, 'endDate' => null, ]; $caseNotes = array_merge( $this->entityManager->getRepository(VisitNote::class)->filterNotes($user, $params), $this->entityManager->getRepository(StandardNote::class)->filterNotes($user, $params), ); } 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' => $this->msgs, 'cases' => $cases, 'caseNotes' => $caseNotes, 'case' => $case, ] ) ); } #[Route('/add-note/{referralId}', name: 'app_add_note')] public function addNote(#[CurrentUser()] User $user, Request $request, ?string $referralId = null): Response { /** @var Referral $referral */ $referral = $this->entityManager->getRepository(Referral::class)->find($referralId); $this->entityManager->getRepository(Referral::class)->populateNotes($referral); $this->msgs = Libs::getMessages($user, $this->entityManager); $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 ($referralId == 'null') { $referralId = 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' => $this->msgs, 'referral' => $referral, 'form' => $form, 'default_method' => $defaultMethod, 'default_location' => $defaultLocation, ] ) ); } #[Route('/edit-note/{noteType}/{noteId}', name: 'app_edit_note')] public function editNote(string $noteId, string $noteType, #[CurrentUser()] User $user, Request $request): Response { $this->msgs = Libs::getMessages($user, $this->entityManager); $form = null; /** @var VisitNote|StandardNote $note */ if ($noteType == 'visit') { $note = $this->entityManager->getRepository(VisitNote::class)->find($noteId); $members = $this->entityManager->getRepository(Member::class)->findBy(['memberCase' => $note->getReferral()->getMemberCase()]); $form = $this->createForm(VisitNoteFormType::class, $note, ['members' => $members]); } elseif ($noteType == 'standard') { $note = $this->entityManager->getRepository(StandardNote::class)->find($noteId); $members = $this->entityManager->getRepository(Member::class)->findBy(['memberCase' => $note->getReferral()->getMemberCase()]); $form = $this->createForm(StandardNoteFormType::class, $note, ['members' => $members]); } return $this->render( 'internal/cases/notes/edit-note.html.twig', array_merge( $this->navLinks, [ 'breadcrumbs' => [ new Breadcrumb($this->generateUrl('app_list_notes'), 'List Notes') ], 'notifications' => $this->msgs, 'note' => $note, 'referral' => $note->getReferral(), 'form' => $form, 'noteType' => $noteType ] ) ); } #[Route('/api/filter-notes', name: 'api_filter_notes')] public function filterNotes(#[CurrentUser()] User $user, Request $request): Response { $startDate = null; $endDate = null; $referral = null; $case = null; if ($request->getPayload()->get('startDate')) { $startDate = new DateTime($request->getPayload()->get('startDate'), new DateTimeZone($_ENV['COMPANY_TIMEZONE'])); } if ($request->getPayload()->get('endDate')) { $endDate = new DateTime($request->getPayload()->get('endDate'), new DateTimeZone($_ENV['COMPANY_TIMEZONE'])); } if ($request->getPayload()->get('referral')) { $referral = $this->entityManager->getRepository(Referral::class)->find($request->getPayload()->get('referral')); } if ($request->getPayload()->get('case')) { $case = $this->entityManager->getRepository(MemberCase::class)->find($request->getPayload()->get('case')); } $params = [ 'startDate' => $startDate, 'endDate' => $endDate, 'referral' => $referral, 'case' => $case, ]; $notes = array_merge( $this->entityManager->getRepository(VisitNote::class)->filterNotes($user, $params), $this->entityManager->getRepository(StandardNote::class)->filterNotes($user, $params), ); foreach ($notes as $idx => $note) { /** @var VisitNote|StandardNote $note */ /** @var VisitNoteMember[]|StandardNoteMember[] $members */ if ($note instanceof VisitNote) { $members = $this->entityManager->getRepository(VisitNoteMembers::class)->findBy(['note' => $note]); } elseif ($note instanceof StandardNote) { $members = $this->entityManager->getRepository(StandardNoteMember::class)->findBy(['note' => $note]); } else { continue; } $notes[$idx]->setMembers($members); } return new Response(json_encode($notes, 0, 3)); } }