convert list-notes to not show anything by default but have a few filter fields to display what is needed, change add notes to use different member collection and tables, add filter method

This commit is contained in:
Ryan Prather 2025-01-05 06:00:40 +00:00
parent 6dc478d0b3
commit 758a439187

View File

@ -3,12 +3,15 @@
namespace App\Controller; namespace App\Controller;
use App\Entity\Member; use App\Entity\Member;
use App\Entity\MemberCase;
use App\Entity\Messages; use App\Entity\Messages;
use App\Entity\Referral; use App\Entity\Referral;
use App\Entity\StandardNote; use App\Entity\StandardNote;
use App\Entity\StandardNoteMember;
use App\Entity\User; use App\Entity\User;
use App\Entity\UserCase; use App\Entity\UserCase;
use App\Entity\VisitNote; use App\Entity\VisitNote;
use App\Entity\VisitNoteMembers;
use App\Enums\NoteLocation; use App\Enums\NoteLocation;
use App\Enums\NoteMethod; use App\Enums\NoteMethod;
use App\Enums\ReferralServiceType; use App\Enums\ReferralServiceType;
@ -16,6 +19,8 @@ use App\Form\StandardNoteFormType;
use App\Form\VisitNoteFormType; use App\Form\VisitNoteFormType;
use App\Libs\Breadcrumb; use App\Libs\Breadcrumb;
use App\Libs\NavList; use App\Libs\NavList;
use DateTime;
use DateTimeZone;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -42,39 +47,14 @@ class NoteController extends AbstractController
$this->navLinks['case_notes'] = NavList::PRESENT_LINK; $this->navLinks['case_notes'] = NavList::PRESENT_LINK;
} }
#[Route('/list-notes/{id?null}', name: 'app_list_notes')] #[Route('/list-notes/', name: 'app_list_notes')]
public function listNotes(#[CurrentUser()] User $user, ?string $id = null): Response public function listNotes(#[CurrentUser()] User $user, Request $request): Response
{ {
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
/** @var UserCase[] $cases */ /** @var UserCase[] $cases */
$cases = $this->entityManager->getRepository(UserCase::class)->findBy(['user' => $user]); $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( return $this->render(
'internal/cases/notes/list-notes.html.twig', 'internal/cases/notes/list-notes.html.twig',
@ -86,18 +66,17 @@ class NoteController extends AbstractController
], ],
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'cases' => $cases, 'cases' => $cases,
'notes' => $notes,
'notificationCount' => $this->notificationCount, 'notificationCount' => $this->notificationCount,
] ]
) )
); );
} }
#[Route('/add-note/{id?null}', name: 'app_add_note')] #[Route('/add-note/{referralId}', name: 'app_add_note')]
public function addNote(#[CurrentUser()] User $user, Request $request, ?string $id = null): Response public function addNote(#[CurrentUser()] User $user, Request $request, ?string $referralId = null): Response
{ {
/** @var Referral $referral */ /** @var Referral $referral */
$referral = $this->entityManager->getRepository(Referral::class)->find($id); $referral = $this->entityManager->getRepository(Referral::class)->find($referralId);
$this->entityManager->getRepository(Referral::class)->populateNotes($referral); $this->entityManager->getRepository(Referral::class)->populateNotes($referral);
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
@ -108,8 +87,8 @@ class NoteController extends AbstractController
$form = $this->createForm(StandardNoteFormType::class, null, ['members' => $members]); $form = $this->createForm(StandardNoteFormType::class, null, ['members' => $members]);
$template = 'internal/cases/notes/add-standard-note.html.twig'; $template = 'internal/cases/notes/add-standard-note.html.twig';
if ($id == 'null') { if ($referralId == 'null') {
$id = null; $referralId = null;
} }
if ($referral->getServiceCode() == ReferralServiceType::VS_THBB) { if ($referral->getServiceCode() == ReferralServiceType::VS_THBB) {
@ -153,19 +132,38 @@ class NoteController extends AbstractController
); );
} }
#[Route('/edit-note/{noteId}', name: 'app_edit_note')] #[Route('/edit-note/{noteType}/{noteId}', name: 'app_edit_note')]
public function editNote(string $noteId, #[CurrentUser()] User $user, Request $request): Response public function editNote(string $noteId, string $noteType, #[CurrentUser()] User $user, Request $request): Response
{ {
$this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user); $this->msgs = $this->entityManager->getRepository(Messages::class)->getUnreadMessages($user);
$this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user); $this->notificationCount = $this->entityManager->getRepository(Messages::class)->getUnreadMessageCount($user);
$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( return $this->render(
'internal/cases/notes/edit-note.html.twig', 'internal/cases/notes/edit-note.html.twig',
array_merge( array_merge(
$this->navLinks, $this->navLinks,
[ [
'breadcrumbs' => [
new Breadcrumb($this->generateUrl('app_list_notes'), 'List Notes')
],
'notifications' => $this->msgs, 'notifications' => $this->msgs,
'notificationCount' => $this->notificationCount, 'notificationCount' => $this->notificationCount,
'note' => $note,
'referral' => $note->getReferral(),
'form' => $form,
'noteType' => $noteType
] ]
) )
); );
@ -174,17 +172,54 @@ class NoteController extends AbstractController
#[Route('/api/filter-notes', name: 'api_filter_notes')] #[Route('/api/filter-notes', name: 'api_filter_notes')]
public function filterNotes(#[CurrentUser()] User $user, Request $request): Response public function filterNotes(#[CurrentUser()] User $user, Request $request): Response
{ {
$startDate = $request->get('startDate'); $startDate = null;
$endDate = $request->get('endDate'); $endDate = null;
$referralId = $request->get('referralId');
$referral = null; $referral = null;
if ($referralId) { $case = null;
$referral = $this->entityManager->getRepository(Referral::class)->find($referralId);
if ($request->getPayload()->get('startDate')) {
$startDate = new DateTime($request->getPayload()->get('startDate'), new DateTimeZone('America/Indiana/Indianapolis'));
} }
return $this->json(array_merge( if ($request->getPayload()->get('endDate')) {
$this->entityManager->getRepository(VisitNote::class)->filterNotes($user, $referral, $startDate, $endDate), $endDate = new DateTime($request->getPayload()->get('endDate'), new DateTimeZone('America/Indiana/Indianapolis'));
$this->entityManager->getRepository(StandardNote::class)->filterNotes($user, $referral, $startDate, $endDate), }
));
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));
} }
} }