Skip to content

Commit

Permalink
Populate encounter edit options based on questionnaire tags (#9927)
Browse files Browse the repository at this point in the history
Co-authored-by: Gigin George <[email protected]>
  • Loading branch information
Jacobjeevan and gigincg authored Jan 13, 2025
1 parent 0e6f7ba commit dcd59bd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
9 changes: 0 additions & 9 deletions src/Routers/routes/ConsultationRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ const consultationRoutes: AppRoutes = {
questionnaireSlug="encounter"
/>
),
"/facility/:facilityId/patient/:patientId/encounter/:encounterId/edit_encounter":
({ facilityId, encounterId, patientId }) => (
<EncounterQuestionnaire
facilityId={facilityId}
encounterId={encounterId}
questionnaireSlug="encounter"
patientId={patientId}
/>
),
"/facility/:facilityId/patient/:patientId/questionnaire": ({
facilityId,
patientId,
Expand Down
20 changes: 4 additions & 16 deletions src/components/Patient/PatientInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {

import { Avatar } from "@/components/Common/Avatar";

import useQuestionnaireOptions from "@/hooks/useQuestionnaireOptions";

import { PLUGIN_Component } from "@/PluginEngine";
import routes from "@/Utils/request/api";
import mutate from "@/Utils/request/mutate";
Expand All @@ -39,21 +41,6 @@ import { Patient } from "@/types/emr/newPatient";

import ManageEncounterOrganizations from "./ManageEncounterOrganizations";

const QUESTIONNAIRE_OPTIONS = [
{
slug: "encounter",
title: "Update Encounter",
},
{
slug: "community-nurse",
title: "Community Nurse Form",
},
{
slug: "recommend_discharge_v2",
title: "Recommend Discharge",
},
] as const;

export interface PatientInfoCardProps {
patient: Patient;
encounter: Encounter;
Expand All @@ -64,6 +51,7 @@ export default function PatientInfoCard(props: PatientInfoCardProps) {
const { patient, encounter } = props;
const { t } = useTranslation();
const queryClient = useQueryClient();
const questionnaireOptions = useQuestionnaireOptions("encounter_actions");

const { mutate: updateEncounter } = useMutation({
mutationFn: mutate(routes.encounter.update, {
Expand Down Expand Up @@ -328,7 +316,7 @@ export default function PatientInfoCard(props: PatientInfoCardProps) {
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{QUESTIONNAIRE_OPTIONS.map((option) => (
{questionnaireOptions.map((option) => (
<DropdownMenuItem key={option.slug} asChild>
<Link
href={`/facility/${encounter.facility.id}/patient/${patient.id}/encounter/${encounter.id}/questionnaire/${option.slug}`}
Expand Down
35 changes: 35 additions & 0 deletions src/hooks/useQuestionnaireOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useQuery } from "@tanstack/react-query";

import query from "@/Utils/request/query";
import questionnaireApi from "@/types/questionnaire/questionnaireApi";

interface EditQuestionnaireOption {
slug: string;
title: string;
}

const DEFAULT_OPTIONS: EditQuestionnaireOption[] = [
{
slug: "encounter",
title: "Update Encounter",
},
];

export default function useQuestionnaireOptions(slug: string) {
const { data } = useQuery({
queryKey: ["questionnaire", slug] as const,
queryFn: query(questionnaireApi.list, {
queryParams: {
tag_slug: slug,
},
}),
});

const questionnaireOptions =
data?.results?.map((q) => ({
slug: q.slug,
title: q.title,
})) ?? [];

return [...DEFAULT_OPTIONS, ...questionnaireOptions];
}

0 comments on commit dcd59bd

Please sign in to comment.