-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[ENG-485] feat: refactor ReportViewer and associated routes to use associatingId and reportType for improved report handling #16440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abhimanyurajeesh
wants to merge
8
commits into
develop
Choose a base branch
from
ENG-485
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+279
−172
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
06ff9f9
feat: refactor ReportViewer and associated routes to use associatingI…
abhimanyurajeesh fdbf065
feat: enhance report querying by including reportType in query keys f…
abhimanyurajeesh eb749aa
feat: implement template loading in AccountShow for dynamic report ge…
abhimanyurajeesh b5c1910
small change
abhimanyurajeesh b53e6bf
route fix
abhimanyurajeesh e63a165
feat: enhance template permissions and loading
abhimanyurajeesh 7387bf9
Merge branch 'develop' into ENG-485
abhimanyurajeesh 35b2dc2
refactor: remove unused encounterId and billingAccountId props from F…
abhimanyurajeesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| import { useQuery } from "@tanstack/react-query"; | ||
| import dayjs from "dayjs"; | ||
| import { SearchIcon } from "lucide-react"; | ||
| import { FileText, Plus, SearchIcon } from "lucide-react"; | ||
| import { navigate } from "raviger"; | ||
| import { useState } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import { toast } from "sonner"; | ||
|
|
||
| import { cn } from "@/lib/utils"; | ||
|
|
||
|
|
@@ -26,30 +29,33 @@ import { | |
| } from "@/components/ui/table"; | ||
| import { TooltipComponent } from "@/components/ui/tooltip"; | ||
|
|
||
| import { PERMISSION_LIST_TEMPLATE } from "@/common/Permissions"; | ||
| import Loading from "@/components/Common/Loading"; | ||
| import { FilterBadges, FilterButton } from "@/components/Files/FileFilters"; | ||
| import { EmptyState } from "@/components/ui/empty-state"; | ||
| import { usePermissions } from "@/context/PermissionContext"; | ||
|
|
||
| import useFilters from "@/hooks/useFilters"; | ||
| import useReportManager from "@/hooks/useReportManager"; | ||
|
|
||
| import query from "@/Utils/request/query"; | ||
| import queryClient from "@/Utils/request/queryClient"; | ||
| import TemplateReportSheet from "@/pages/Encounters/TemplateBuilder/TemplateReportSheet"; | ||
| import NavigationHelper from "@/components/ui/multi-filter/utils/navigation-helper"; | ||
| import { useCurrentFacilitySilently } from "@/pages/Facility/utils/useCurrentFacility"; | ||
| import { | ||
| ReportRead, | ||
| ReportReadList, | ||
| ReportType, | ||
| } from "@/types/emr/report/report"; | ||
| import { navigate } from "raviger"; | ||
| import { toast } from "sonner"; | ||
| import templateApi from "@/types/emr/template/templateApi"; | ||
|
|
||
| interface ReportTabProps { | ||
| associatingId: string; | ||
| reportType?: ReportType; | ||
| facilityId?: string; | ||
| patientId?: string; | ||
| encounterId?: string; | ||
| billingAccountId?: string; | ||
| } | ||
|
|
||
| export function ReportSubTab({ | ||
|
|
@@ -58,6 +64,7 @@ export function ReportSubTab({ | |
| facilityId, | ||
| patientId, | ||
| encounterId, | ||
| billingAccountId, | ||
| }: ReportTabProps) { | ||
| const { t } = useTranslation(); | ||
| const { facility } = useCurrentFacilitySilently(); | ||
|
|
@@ -72,7 +79,6 @@ export function ReportSubTab({ | |
| viewFile, | ||
| downloadFile, | ||
| archiveReport, | ||
| refetch, | ||
| Dialogs, | ||
| } = useReportManager({ | ||
| associatingId, | ||
|
|
@@ -98,13 +104,32 @@ export function ReportSubTab({ | |
| return iconMap[reportType] || "l-file-alt"; | ||
| }; | ||
|
|
||
| const canNavigateToPreview = !!(facilityId && patientId && encounterId); | ||
| const canNavigateToEncounterPreview = !!( | ||
| facilityId && | ||
| patientId && | ||
| encounterId | ||
| ); | ||
| const canNavigateToBillingPreview = !!(facilityId && billingAccountId); | ||
| const canNavigateToPatientPreview = !!(patientId && !encounterId); | ||
|
|
||
| const handleView = (report: ReportReadList) => { | ||
| if (canNavigateToPreview) { | ||
| if (canNavigateToEncounterPreview) { | ||
| navigate( | ||
| `/facility/${facilityId}/patient/${patientId}/encounter/${encounterId}/report/${report.id}`, | ||
| ); | ||
| } else if (canNavigateToBillingPreview) { | ||
| navigate( | ||
| `/facility/${facilityId}/billing/account/${billingAccountId}/report/${report.id}`, | ||
| ); | ||
| } else if (canNavigateToPatientPreview) { | ||
| const effectiveFacilityId = facilityId ?? facility?.id; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can move defining effectiveFacilityId to 116 and use it in other blocks as well; allows to remove the else block in 130.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replacing with switch |
||
| if (effectiveFacilityId) { | ||
| navigate( | ||
| `/facility/${effectiveFacilityId}/patient/${patientId}/report/${report.id}`, | ||
| ); | ||
| } else { | ||
| viewFile(report); | ||
| } | ||
| } else { | ||
| viewFile(report); | ||
| } | ||
|
abhimanyurajeesh marked this conversation as resolved.
|
||
|
|
@@ -374,20 +399,12 @@ export function ReportSubTab({ | |
| </Button> | ||
| </div> | ||
| {facility && ( | ||
| <TemplateReportSheet | ||
| facilityId={facility.id} | ||
| associatingId={associatingId} | ||
| permissions={facility.permissions ?? []} | ||
| <GenerateReportDropdown | ||
| facilityId={facilityId ?? facility.id} | ||
| patientId={patientId} | ||
| encounterId={encounterId} | ||
| billingAccountId={billingAccountId} | ||
| reportType={reportType} | ||
| trigger={ | ||
| <Button variant="outline_primary"> | ||
| <CareIcon icon="l-plus" className="mr-1" /> | ||
| <span>{t("generate_report")}</span> | ||
| </Button> | ||
| } | ||
| onSuccess={() => { | ||
| refetch(); | ||
| }} | ||
| /> | ||
| )} | ||
| </div> | ||
|
|
@@ -426,3 +443,107 @@ export function ReportSubTab({ | |
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function GenerateReportDropdown({ | ||
| facilityId, | ||
| patientId, | ||
| encounterId, | ||
| billingAccountId, | ||
| reportType, | ||
| }: { | ||
| facilityId: string; | ||
| patientId?: string; | ||
| encounterId?: string; | ||
| billingAccountId?: string; | ||
| reportType?: ReportType; | ||
| }) { | ||
| const { t } = useTranslation(); | ||
| const { facility } = useCurrentFacilitySilently(); | ||
| const { hasPermission } = usePermissions(); | ||
|
|
||
| const canListTemplate = hasPermission( | ||
| PERMISSION_LIST_TEMPLATE, | ||
| facility?.permissions, | ||
| ); | ||
|
|
||
| const { data: templatesData, isLoading } = useQuery({ | ||
| queryKey: ["templates", facilityId, reportType], | ||
| queryFn: query(templateApi.listTemplates, { | ||
| queryParams: { | ||
| facility: facilityId, | ||
| template_type: reportType, | ||
| status: "active", | ||
| }, | ||
| }), | ||
| enabled: canListTemplate && !!reportType, | ||
| }); | ||
|
|
||
| const getTemplateUrl = (slug: string) => { | ||
| if (encounterId && patientId) { | ||
| return `/facility/${facilityId}/patient/${patientId}/encounter/${encounterId}/report/template/${slug}`; | ||
| } | ||
| if (billingAccountId) { | ||
| return `/facility/${facilityId}/billing/account/${billingAccountId}/report/template/${slug}`; | ||
| } | ||
| if (patientId) { | ||
| return `/facility/${facilityId}/patient/${patientId}/report/template/${slug}`; | ||
| } | ||
| return null; | ||
| }; | ||
|
|
||
| const templates = (templatesData?.results ?? []).flatMap((template) => { | ||
| const url = getTemplateUrl(template.slug); | ||
| return url ? [{ template, url }] : []; | ||
| }); | ||
|
|
||
| if (!isLoading && templates.length === 0) return null; | ||
|
abhimanyurajeesh marked this conversation as resolved.
|
||
|
|
||
| if (isLoading || templates.length === 1) { | ||
| return ( | ||
| <Button | ||
| variant="outline_primary" | ||
| disabled={isLoading} | ||
| onClick={() => templates[0] && navigate(templates[0].url)} | ||
| > | ||
| {isLoading ? ( | ||
| <CareIcon icon="l-spinner" className="size-4 animate-spin" /> | ||
| ) : ( | ||
| <Plus className="size-4" /> | ||
| )} | ||
| <span>{t("generate_report")}</span> | ||
| </Button> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <DropdownMenu> | ||
| <DropdownMenuTrigger asChild> | ||
| <Button variant="outline_primary"> | ||
| <Plus className="size-4" /> | ||
| <span>{t("generate_report")}</span> | ||
| </Button> | ||
| </DropdownMenuTrigger> | ||
| <DropdownMenuContent | ||
| align="end" | ||
| className="w-full max-w-[calc(100vw-3rem)] sm:max-w-xs p-0" | ||
| > | ||
| <div className="px-2 pt-2"> | ||
| <div className="max-h-[30vh] overflow-y-auto pb-2"> | ||
| {templates.map(({ template, url }) => { | ||
| return ( | ||
| <DropdownMenuItem | ||
| key={template.id} | ||
| onClick={() => navigate(url)} | ||
| > | ||
| <FileText className="size-4 shrink-0" /> | ||
| <span className="truncate">{template.name}</span> | ||
| </DropdownMenuItem> | ||
| ); | ||
| })} | ||
| </div> | ||
| <NavigationHelper hideRightArrow /> | ||
|
abhimanyurajeesh marked this conversation as resolved.
|
||
| </div> | ||
| </DropdownMenuContent> | ||
| </DropdownMenu> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Associating Id is encounterId, patientId or accountId based on report type, so we can derive the url based on that.
Remove patientId, encounterId and billingAccountId props.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cant remove patient id, can remove the encounter id and billingAccountID