Skip to content
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

Clean up encounter routes #11084

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Routers/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default function AppRouter() {
const appPages = useRoutes(routes);
const adminPages = useRoutes(AdminRouter);

const sidebarFor = appPages ? SidebarFor.FACILITY : SidebarFor.ADMIN;
const sidebarFor = adminPages ? SidebarFor.ADMIN : SidebarFor.FACILITY;

const pages = appPages || adminPages || <ErrorPage />;

Expand Down
35 changes: 18 additions & 17 deletions src/Routers/routes/ConsultationRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,34 @@ const consultationRoutes: AppRoutes = {
patientId={patientId}
/>
),

"/facility/:facilityId/patient/:patientId/encounter/:encounterId/questionnaire_response/:id":
({ patientId, id }) => (
<QuestionnaireResponseView responseId={id} patientId={patientId} />
),
"/facility/:facilityId/patient/:patientId/encounter/:encounterId/:tab": ({
facilityId,
patientId,
encounterId,
tab,
}) => (
<EncounterShow
facilityId={facilityId}
patientId={patientId}
encounterId={encounterId}
tab={tab}
/>
),
"/facility/:facilityId/patient/:patientId/encounter/:encounterId/:tab/:subPage":
({ facilityId, encounterId, patientId, tab, subPage }) => (
...["facility", "organization"].reduce((acc: AppRoutes, identifier) => {
acc[`/${identifier}/:id/patient/:patientId/encounter/:encounterId/:tab`] =
({ id, encounterId, tab, patientId }) => (
<EncounterShow
patientId={patientId}
encounterId={encounterId}
tab={tab}
facilityId={identifier === "facility" ? id : undefined}
/>
);
acc[
`/${identifier}/:id/patient/:patientId/encounter/:encounterId/:tab/:subPage`
] = ({ id, encounterId, patientId, tab, subPage }) => (
<EncounterShow
facilityId={facilityId}
patientId={patientId}
encounterId={encounterId}
tab={tab}
facilityId={identifier === "facility" ? id : undefined}
subPage={subPage}
/>
),
);
return acc;
}, {}),
"/facility/:facilityId/patient/:patientId/consultation": ({
facilityId,
patientId,
Expand Down
7 changes: 2 additions & 5 deletions src/Routers/routes/PatientRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
facilityPatientTabs,
patientTabs,
} from "@/components/Patient/PatientDetailsTab";
import { patientTabs } from "@/components/Patient/PatientDetailsTab";
import { PatientHome } from "@/components/Patient/PatientHome";
import PatientIndex from "@/components/Patient/PatientIndex";
import PatientRegistration from "@/components/Patient/PatientRegistration";
Expand Down Expand Up @@ -34,7 +31,7 @@ const PatientRoutes: AppRoutes = {
"/facility/:facilityId/patient/:id": ({ facilityId, id }) => (
<PatientHome facilityId={facilityId} id={id} page="demography" />
),
...facilityPatientTabs.reduce((acc: AppRoutes, tab) => {
...patientTabs.reduce((acc: AppRoutes, tab) => {
acc["/facility/:facilityId/patient/:id/" + tab.route] = ({
facilityId,
id,
Expand Down
9 changes: 7 additions & 2 deletions src/components/Facility/EncounterCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import { Encounter, completedEncounterStatus } from "@/types/emr/encounter";

interface EncounterCardProps {
encounter: Encounter;
facilityId?: string;
}

export const EncounterCard = (props: EncounterCardProps) => {
const { encounter } = props;
const { encounter, facilityId } = props;

const Icon = encounterIcons[encounter.encounter_class];

Expand Down Expand Up @@ -118,7 +119,11 @@ export const EncounterCard = (props: EncounterCardProps) => {
<div className="w-full py-2 bg-gray-100 px-2">
<Button variant="outline" className="p-2 border border-black">
<Link
href={`/facility/${encounter.facility.id}/patient/${encounter.patient.id}/encounter/${encounter.id}/updates`}
href={
facilityId
? `/facility/${facilityId}/patient/${encounter.patient.id}/encounter/${encounter.id}/updates`
: `/organization/organizationId/patient/${encounter.patient.id}/encounter/${encounter.id}/updates`
}
Comment on lines +122 to +126
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Check the fallback URL logic.

The conditional URL generation is a good enhancement, but there's a potential issue with the fallback case.

When facilityId is not provided, the URL contains a hardcoded string "organizationId" which appears to be a placeholder. Is this intentional, or should it be dynamically populated with the actual organization ID?


🏁 Script executed:

#!/bin/bash
# Check if "organizationId" is used as a placeholder in other components
rg "organizationId" --type tsx --type jsx

Length of output: 69


Please run the above command to check if "organizationId" is used elsewhere in the codebase as a placeholder. Once confirmed, verify if the fallback URL in src/components/Facility/EncounterCard.tsx (lines 122-126) is meant to use a static string or if it should dynamically include the actual organization ID.

Action Required: Verify Fallback URL Logic

  • In the fallback case (when facilityId is not provided), the URL currently uses the literal "organizationId".
  • Confirm whether this is an intentional placeholder or if it requires dynamic population with the actual organization ID.
  • Please review the usage (if any) of "organizationId" in the codebase to ensure consistency and correctness in URL generation.

🏁 Script executed:

#!/bin/bash
# Searching for "organizationId" in all files to verify if it's used as a placeholder elsewhere
rg "organizationId"

Length of output: 6866


Action Required: Update Fallback URL Logic in EncounterCard

The current fallback URL in src/components/Facility/EncounterCard.tsx (lines 122–126) is using the literal "organizationId" instead of a dynamic value. Given that other parts of the codebase (for example, in src/Utils/request/api.tsx and various components) make use of a dynamically provided organizationId, this appears to be an oversight.

  • Update Required: Replace the hardcoded "organizationId" string in the fallback case with the appropriate dynamic organization ID.
  • Verification: Ensure that the dynamic organization ID is correctly obtained from the relevant context or props, so the generated URL reflects the actual organization rather than a placeholder.

className="flex items-center gap-2"
>
<Eye className="w-4 h-4" />
Expand Down
10 changes: 2 additions & 8 deletions src/components/Medicine/MedicationRequestTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ export const EmptyState = ({

interface Props {
readonly?: boolean;
facilityId: string;
patientId: string;
encounterId: string;
}

export default function MedicationRequestTable({
patientId,
encounterId,
facilityId,
}: Props) {
const [searchQuery, setSearchQuery] = useState("");
const [showStopped, setShowStopped] = useState(false);
Expand Down Expand Up @@ -161,9 +159,7 @@ export default function MedicationRequestTable({
size="sm"
className="text-gray-950 hover:text-gray-700 h-9"
>
<Link
href={`/facility/${facilityId}/patient/${patientId}/encounter/${encounterId}/questionnaire/medication_request`}
>
<Link href={`questionnaire/medication_request`}>
<PencilIcon className="mr-2 h-4 w-4" />
{t("edit")}
</Link>
Expand All @@ -174,9 +170,7 @@ export default function MedicationRequestTable({
size="sm"
className="text-gray-950 hover:text-gray-700 h-9"
>
<Link
href={`/facility/${facilityId}/patient/${patientId}/encounter/${encounterId}/prescriptions/print`}
>
<Link href={`prescriptions/print`}>
<CareIcon icon="l-print" className="mr-2" />
{t("print")}
</Link>
Expand Down
43 changes: 26 additions & 17 deletions src/components/Patient/PatientDetailsTab/Appointments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@ export const Appointments = (props: PatientProps) => {
const { patientData, facilityId, patientId } = props;
const { t } = useTranslation();

const { data } = useQuery({
const { data, isLoading } = useQuery({
queryKey: ["patient-appointments", patientId],
queryFn: query(scheduleApis.appointments.list, {
pathParams: { facility_id: facilityId ?? "" },
queryParams: { patient: patientId, limit: 100 },
}),
enabled: !!facilityId,
queryFn: query(
facilityId
? scheduleApis.appointments.list
: scheduleApis.appointments.getAppointments,
{
pathParams: {
facility_id: facilityId ?? "",
patient_id: patientId,
},
queryParams: { patient: patientId, limit: 100 },
},
),
});

const appointments = data?.results;
Expand Down Expand Up @@ -64,15 +71,17 @@ export const Appointments = (props: PatientProps) => {
<h2 className="text-2xl font-semibold leading-tight text-center sm:text-left">
{t("appointments")}
</h2>
<Button variant="outline_primary" asChild>
<Link
href={`/facility/${facilityId}/patient/${patientId}/book-appointment`}
className="flex items-center justify-center w-full sm:w-auto"
>
<CareIcon icon="l-plus" className="mr-2" />
{t("schedule_appointment")}
</Link>
</Button>
{facilityId && (
<Button variant="outline_primary" asChild>
<Link
href={`/facility/${facilityId}/patient/${patientId}/book-appointment`}
className="flex items-center justify-center w-full sm:w-auto"
>
<CareIcon icon="l-plus" className="mr-2" />
{t("schedule_appointment")}
</Link>
</Button>
)}
</div>

<div className="rounded-lg border bg-white">
Expand All @@ -87,13 +96,13 @@ export const Appointments = (props: PatientProps) => {
</TableRow>
</TableHeader>
<TableBody>
{!appointments ? (
{isLoading ? (
<TableRow>
<TableCell colSpan={5} className="text-center py-4">
{t("loading")}
</TableCell>
</TableRow>
) : appointments.length ? (
) : appointments && appointments.length ? (
appointments.map((appointment) => (
<TableRow key={appointment.id}>
<TableCell className="font-medium">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ const EncounterHistory = (props: PatientProps) => {
<ul className="grid gap-4">
{encounterData?.results?.map((encounter) => (
<li key={encounter.id} className="w-full">
<EncounterCard key={encounter.id} encounter={encounter} />
<EncounterCard
key={encounter.id}
encounter={encounter}
facilityId={facilityId}
/>
</li>
))}
<div className="flex w-full items-center justify-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export const HealthProfileSummary = (props: PatientProps) => {
</div>

<div className="md:col-span-2">
<AllergyList patientId={patientId} />
<AllergyList patientId={patientId} readOnly={true} />
</div>

<div className="md:col-span-2">
<SymptomsList patientId={patientId} />
<SymptomsList patientId={patientId} readOnly={true} />
</div>

<div className="md:col-span-2">
<DiagnosisList patientId={patientId} />
<DiagnosisList patientId={patientId} readOnly={true} />
</div>
</div>
</div>
Expand Down
34 changes: 1 addition & 33 deletions src/components/Patient/PatientDetailsTab/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import QuestionnaireResponsesList from "@/components/Facility/ConsultationDetails/QuestionnaireResponsesList";
import EncounterHistory from "@/components/Patient/PatientDetailsTab//EncounterHistory";
import { HealthProfileSummary } from "@/components/Patient/PatientDetailsTab//HealthProfileSummary";
import { Demography } from "@/components/Patient/PatientDetailsTab/Demography";
Expand All @@ -18,37 +17,6 @@ export interface PatientProps {
}

export const patientTabs = [
{
route: "demography",
component: Demography,
},
{
route: "encounters",
component: EncounterHistory,
},
{
route: "health-profile",
component: HealthProfileSummary,
},
{
route: "updates",
component: Updates,
},
{
route: "resource_requests",
component: ResourceRequests,
},
{
route: "users",
component: PatientUsers,
},
{
route: "files",
component: PatientFilesTab,
},
];

export const facilityPatientTabs = [
{
route: "demography",
component: Demography,
Expand All @@ -67,7 +35,7 @@ export const facilityPatientTabs = [
},
{
route: "updates",
component: QuestionnaireResponsesList,
component: Updates,
},
{
route: "resource_requests",
Expand Down
Loading
Loading