Add NoteController and associated templates, entities, repository.

This commit is contained in:
2024-12-17 11:56:14 -05:00
parent 803ce84996
commit db756d83e4
17 changed files with 1408 additions and 0 deletions

View File

@ -0,0 +1,168 @@
<?php
namespace App\Controller;
use App\Entity\Member;
use App\Entity\Referral;
use App\Entity\StandardNote;
use App\Entity\User;
use App\Entity\UserCase;
use App\Entity\VisitNote;
use App\Enums\NoteLocation;
use App\Enums\NoteMethod;
use App\Enums\ReferralServiceType;
use App\Form\StandardNoteFormType;
use App\Form\VisitNoteFormType;
use App\Libs\Breadcrumb;
use App\Libs\NavList;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\CurrentUser;
class NoteController extends AbstractController
{
public function __construct(
private EntityManagerInterface $entityManager,
private array $navLinks = [],
) {
$this->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),
));
}
}