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

Fix: Improper Error handling on shifting patient #9561

Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"DOMESTIC_HEALTHCARE_SUPPORT__FAMILY_MEMBER": "Family member",
"DOMESTIC_HEALTHCARE_SUPPORT__NO_SUPPORT": "No support",
"DOMESTIC_HEALTHCARE_SUPPORT__PAID_CAREGIVER": "Paid caregiver",
"ERROR_FETCHING_CONSULTATION": "Error while retrieving consultation data",
"GENDER__1": "Male",
"GENDER__2": "Female",
"GENDER__3": "Non-binary",
Expand Down
26 changes: 18 additions & 8 deletions src/components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useQuery } from "@tanstack/react-query";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";

Expand Down Expand Up @@ -28,8 +29,8 @@ import { PLUGIN_Component } from "@/PluginEngine";
import * as Notification from "@/Utils/Notifications";
import dayjs from "@/Utils/dayjs";
import routes from "@/Utils/request/api";
import query from "@/Utils/request/query";
import request from "@/Utils/request/request";
import useTanStackQueryInstead from "@/Utils/request/useQuery";

interface PreDischargeFormInterface {
new_discharge_reason: number | null;
Expand Down Expand Up @@ -92,10 +93,20 @@ const DischargeModal = ({
setFacility(referred_to);
}, [referred_to]);

const initialDiagnoses = useTanStackQueryInstead(routes.getConsultation, {
pathParams: { id: consultationData.id ?? "" },
prefetch: !!consultationData.id,
}).data?.diagnoses;
const { data, isLoading, error } = useQuery({
queryKey: [routes.getConsultation.path, consultationData.id],
queryFn: query(routes.getConsultation, {
pathParams: { id: consultationData.id },
silent: true,
}),
enabled: consultationData.id !== undefined,
});
AdityaJ2305 marked this conversation as resolved.
Show resolved Hide resolved

if (error) {
Notification.Error({ msg: t("ERROR_FETCHING_CONSULTATION") });
}
AdityaJ2305 marked this conversation as resolved.
Show resolved Hide resolved

const initialDiagnoses = data?.diagnoses ?? [];
AdityaJ2305 marked this conversation as resolved.
Show resolved Hide resolved

const discharge_reason =
new_discharge_reason ?? preDischargeForm.new_discharge_reason;
Expand Down Expand Up @@ -177,9 +188,8 @@ const DischargeModal = ({
? "death_datetime"
: "discharge_date"
];
if (initialDiagnoses == null) {
return <Loading />;
}

if (isLoading) return <Loading />;

return (
<>
Expand Down
Loading