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: Duplicate network requests in Patient Details page #9297

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f4ea6de
removed duplicate network calls
Mahendar0701 Dec 4, 2024
dd6ac7c
Merge branch 'develop' into duplicate-network-requests
Mahendar0701 Dec 4, 2024
840bf17
policy api after getpatientapi
Mahendar0701 Dec 4, 2024
bdcdc06
Merge branch 'develop' into duplicate-network-requests
Mahendar0701 Dec 4, 2024
226d59a
updated path
Mahendar0701 Dec 4, 2024
fd59300
Merge branch 'develop' into duplicate-network-requests
Mahendar0701 Dec 4, 2024
bd24fa2
Merge branch 'develop' into duplicate-network-requests
Mahendar0701 Dec 5, 2024
fd32a75
Merge branch 'develop' into duplicate-network-requests
Mahendar0701 Dec 7, 2024
50b364a
Merge branch 'develop' into duplicate-network-requests
Mahendar0701 Dec 9, 2024
cdbf6f8
updated prefetch and added absolute imports
Mahendar0701 Dec 9, 2024
e533aad
Merge branch 'develop' into duplicate-network-requests
Mahendar0701 Dec 9, 2024
f4a9851
added absolute imports
Mahendar0701 Dec 9, 2024
18d9bbd
added absolute imports
Mahendar0701 Dec 9, 2024
5fd96c3
added absolute imports
Mahendar0701 Dec 9, 2024
d8d900e
added absolute imports
Mahendar0701 Dec 9, 2024
a229ddc
Merge branch 'develop' into duplicate-network-requests
Mahendar0701 Dec 10, 2024
9f430f4
Merge branch 'develop' into duplicate-network-requests
Mahendar0701 Dec 11, 2024
ec25eea
Merge branch 'develop' into duplicate-network-requests
Mahendar0701 Dec 11, 2024
3d49cc2
Merge branch 'develop' into duplicate-network-requests
Mahendar0701 Dec 11, 2024
7a278ba
resolved merge conflicts
Mahendar0701 Dec 12, 2024
be36557
demography tab api
Mahendar0701 Dec 12, 2024
7c87e18
updated imports
Mahendar0701 Dec 12, 2024
a3f5353
updated encounter history
Mahendar0701 Dec 13, 2024
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
12 changes: 2 additions & 10 deletions src/components/Facility/PatientNotesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,10 @@ const PatientNotesList = (props: PatientNotesProps) => {
};

useEffect(() => {
if (reload) {
if (reload || thread) {
fetchNotes();
}
}, [reload]);

useEffect(() => {
fetchNotes();
}, [thread]);

useEffect(() => {
setReload(true);
}, []);
}, [reload, thread]);

const handleNext = () => {
if (state.cPage < state.totalPages) {
Expand Down
17 changes: 8 additions & 9 deletions src/components/Patient/PatientDetailsTab/Demography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import AuthorizedChild from "@/CAREUI/misc/AuthorizedChild";

import { Button } from "@/components/ui/button";

import { InsuranceDetailsCard } from "@/components/Patient/InsuranceDetailsCard";
import { PatientProps } from "@/components/Patient/PatientDetailsTab";
import { parseOccupation } from "@/components/Patient/PatientHome";
import { AssignedToObjectModel } from "@/components/Patient/models";

import useAuthUser from "@/hooks/useAuthUser";

import { GENDER_TYPES } from "@/common/constants";

import { NonReadOnlyUsers } from "@/Utils/AuthorizeFor";
import * as Notification from "@/Utils/Notifications";
import routes from "@/Utils/request/api";
import useQuery from "@/Utils/request/useQuery";
import { formatName, formatPatientAge } from "@/Utils/utils";

import { PatientProps } from ".";
import * as Notification from "../../../Utils/Notifications";
import { InsuranceDetailsCard } from "../InsuranceDetailsCard";
import { parseOccupation } from "../PatientHome";
import { AssignedToObjectModel } from "../models";

export const Demography = (props: PatientProps) => {
const { patientData, facilityId, id } = props;
const authUser = useAuthUser();
Expand Down Expand Up @@ -62,9 +62,8 @@ export const Demography = (props: PatientProps) => {
}, [patientData.assigned_to_object]);

const { data: insuranceDetials } = useQuery(routes.hcx.policies.list, {
query: {
patient: id,
},
query: { patient: id },
prefetch: !!patientData.id,
});

const patientGender = GENDER_TYPES.find(
Expand Down
32 changes: 3 additions & 29 deletions src/components/Patient/PatientDetailsTab/EncounterHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,24 @@ import { useTranslation } from "react-i18next";
import PaginatedList from "@/CAREUI/misc/PaginatedList";

import CircularProgress from "@/components/Common/CircularProgress";
import Loading from "@/components/Common/Loading";
import { ConsultationCard } from "@/components/Facility/ConsultationCard";
import { ConsultationModel } from "@/components/Facility/models";
import { PatientProps } from "@/components/Patient/PatientDetailsTab";
import { PatientModel } from "@/components/Patient/models";

import useAuthUser from "@/hooks/useAuthUser";

import { triggerGoal } from "@/Integrations/Plausible";
import routes from "@/Utils/request/api";
import useQuery from "@/Utils/request/useQuery";

import { PatientProps } from ".";
import { PatientModel } from "../models";

const EncounterHistory = (props: PatientProps) => {
const { patientData: initialPatientData, facilityId, id } = props;
const { patientData: initialPatientData, id, refetch } = props;
const [patientData, setPatientData] =
useState<PatientModel>(initialPatientData);
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
const authUser = useAuthUser();

useEffect(() => {
setPatientData(initialPatientData);
}, [initialPatientData]);
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved

const { t } = useTranslation();

const { loading: isLoading, refetch } = useQuery(routes.getPatient, {
pathParams: {
id,
},
onResponse: ({ res, data }) => {
if (res?.ok && data) {
setPatientData(data);
}
triggerGoal("Patient Profile Viewed", {
facilityId: facilityId,
userId: authUser.id,
});
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
},
});

if (isLoading) {
return <Loading />;
}

return (
<PaginatedList
route={routes.getConsultationList}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import CareIcon from "@/CAREUI/icons/CareIcon";

import { Button } from "@/components/ui/button";

import { PatientProps } from "@/components/Patient/PatientDetailsTab";
import { PatientModel } from "@/components/Patient/models";
import { UserModel } from "@/components/Users/models";

import useAuthUser from "@/hooks/useAuthUser";

import { ADMIN_USER_TYPES } from "@/common/constants";

import { PatientProps } from ".";
import * as Notification from "../../../Utils/Notifications";
import { PatientModel } from "../models";
import * as Notification from "@/Utils/Notifications";

export const HealthProfileSummary = (props: PatientProps) => {
const { patientData, facilityId, id } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ import CareIcon from "@/CAREUI/icons/CareIcon";

import { Button } from "@/components/ui/button";

import { PatientProps } from "@/components/Patient/PatientDetailsTab";
import { PatientModel } from "@/components/Patient/models";
import { UserModel } from "@/components/Users/models";

import useAuthUser from "@/hooks/useAuthUser";

import { ADMIN_USER_TYPES } from "@/common/constants";

import * as Notification from "@/Utils/Notifications";
import { formatDateTime } from "@/Utils/utils";

import { PatientProps } from ".";
import * as Notification from "../../../Utils/Notifications";
import { PatientModel } from "../models";

export const ImmunisationRecords = (props: PatientProps) => {
const { patientData, facilityId, id } = props;

Expand Down
40 changes: 7 additions & 33 deletions src/components/Patient/PatientDetailsTab/Notes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { t } from "i18next";
import { useEffect, useState } from "react";
import { useState } from "react";

import CareIcon from "@/CAREUI/icons/CareIcon";

Expand All @@ -11,26 +11,21 @@ import {
PatientNotesModel,
} from "@/components/Facility/models";
import AutoExpandingTextInputFormField from "@/components/Form/FormFields/AutoExpandingTextInputFormField";
import { PatientProps } from "@/components/Patient/PatientDetailsTab";

import useAuthUser from "@/hooks/useAuthUser";
import { useMessageListener } from "@/hooks/useMessageListener";

import { PATIENT_NOTES_THREADS } from "@/common/constants";

import { NonReadOnlyUsers } from "@/Utils/AuthorizeFor";
import * as Notification from "@/Utils/Notifications";
import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
import { classNames, keysOf } from "@/Utils/utils";

import * as Notification from "../../../Utils/Notifications";

interface PatientNotesProps {
id: string;
facilityId: string;
}

const PatientNotes = (props: PatientNotesProps) => {
const { id: patientId, facilityId } = props;
const PatientNotes = (props: PatientProps) => {
const { patientData, id: patientId, facilityId } = props;

const authUser = useAuthUser();
const [thread, setThread] = useState(
Expand All @@ -39,7 +34,6 @@ const PatientNotes = (props: PatientNotesProps) => {
: PATIENT_NOTES_THREADS.Doctors,
);

const [patientActive, setPatientActive] = useState(true);
const [noteField, setNoteField] = useState("");
const [reload, setReload] = useState(false);
const [reply_to, setReplyTo] = useState<PatientNotesModel | undefined>(
Expand Down Expand Up @@ -84,26 +78,6 @@ const PatientNotes = (props: PatientNotesProps) => {
}
};

useEffect(() => {
async function fetchPatientName() {
if (patientId) {
try {
const { data } = await request(routes.getPatient, {
pathParams: { id: patientId },
});
if (data) {
setPatientActive(data.is_active ?? true);
}
} catch (error) {
Notification.Error({
msg: "Failed to fetch patient status",
});
}
}
}
fetchPatientName();
}, [patientId]);

useMessageListener((data) => {
const message = data?.message;
if (
Expand Down Expand Up @@ -161,15 +135,15 @@ const PatientNotes = (props: PatientNotesProps) => {
errorClassName="hidden"
innerClassName="pr-10"
placeholder={t("notes_placeholder")}
disabled={!patientActive}
disabled={!patientData.is_active}
/>
<ButtonV2
onClick={onAddNote}
border={false}
className="absolute right-2"
ghost
size="small"
disabled={!patientActive}
disabled={!patientData.is_active}
authorizeFor={NonReadOnlyUsers}
>
<CareIcon icon="l-message" className="text-lg" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import PaginatedList from "@/CAREUI/misc/PaginatedList";

import ButtonV2 from "@/components/Common/ButtonV2";
import CircularProgress from "@/components/Common/CircularProgress";
import { PatientProps } from "@/components/Patient/PatientDetailsTab/";
import { SampleTestCard } from "@/components/Patient/SampleTestCard";
import { PatientModel, SampleTestModel } from "@/components/Patient/models";

import { NonReadOnlyUsers } from "@/Utils/AuthorizeFor";
import routes from "@/Utils/request/api";

import { PatientProps } from ".";
import { SampleTestCard } from "../SampleTestCard";
import { PatientModel, SampleTestModel } from "../models";

export const SampleTestHistory = (props: PatientProps) => {
const { patientData, facilityId, id } = props;
const [_selectedStatus, setSelectedStatus] = useState<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useTranslation } from "react-i18next";
import CareIcon from "@/CAREUI/icons/CareIcon";

import ButtonV2 from "@/components/Common/ButtonV2";
import { PatientProps } from "@/components/Patient/PatientDetailsTab";
import { PatientModel } from "@/components/Patient/models";
import { formatFilter } from "@/components/Resource/ResourceCommons";
import ShiftingTable from "@/components/Shifting/ShiftingTable";

Expand All @@ -13,9 +15,6 @@ import { NonReadOnlyUsers } from "@/Utils/AuthorizeFor";
import routes from "@/Utils/request/api";
import useQuery from "@/Utils/request/useQuery";

import { PatientProps } from ".";
import { PatientModel } from "../models";

const ShiftingHistory = (props: PatientProps) => {
const { patientData, facilityId, id } = props;
const { t } = useTranslation();
Expand Down
17 changes: 9 additions & 8 deletions src/components/Patient/PatientDetailsTab/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { PatientModel } from "../models";
import { Demography } from "./Demography";
import EncounterHistory from "./EncounterHistory";
import { HealthProfileSummary } from "./HealthProfileSummary";
import { ImmunisationRecords } from "./ImmunisationRecords";
import PatientNotes from "./Notes";
import { SampleTestHistory } from "./SampleTestHistory";
import ShiftingHistory from "./ShiftingHistory";
import EncounterHistory from "@/components/Patient/PatientDetailsTab//EncounterHistory";
import { HealthProfileSummary } from "@/components/Patient/PatientDetailsTab//HealthProfileSummary";
import { ImmunisationRecords } from "@/components/Patient/PatientDetailsTab//ImmunisationRecords";
import PatientNotes from "@/components/Patient/PatientDetailsTab//Notes";
import { SampleTestHistory } from "@/components/Patient/PatientDetailsTab//SampleTestHistory";
import ShiftingHistory from "@/components/Patient/PatientDetailsTab//ShiftingHistory";
import { Demography } from "@/components/Patient/PatientDetailsTab/Demography";
import { PatientModel } from "@/components/Patient/models";

export interface PatientProps {
facilityId: string;
id: string;
patientData: PatientModel;
refetch: () => void;
}
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved

export const patientTabs = [
Expand Down
39 changes: 22 additions & 17 deletions src/components/Patient/PatientHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,23 @@ import { Link, navigate } from "raviger";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";

import Chip from "@/CAREUI/display/Chip";
import CareIcon from "@/CAREUI/icons/CareIcon";

import { Avatar } from "@/components/Common/Avatar";
import ButtonV2 from "@/components/Common/ButtonV2";
import ConfirmDialog from "@/components/Common/ConfirmDialog";
import Loading from "@/components/Common/Loading";
import Page from "@/components/Common/Page";
import UserAutocomplete from "@/components/Common/UserAutocompleteFormField";
import { patientTabs } from "@/components/Patient/PatientDetailsTab";
import { isPatientMandatoryDataFilled } from "@/components/Patient/Utils";
import {
AssignedToObjectModel,
PatientModel,
SampleTestModel,
} from "@/components/Patient/models";
import { SkillModel, UserBareMinimum } from "@/components/Users/models";

import useAuthUser from "@/hooks/useAuthUser";

Expand All @@ -14,16 +29,13 @@ import {
SAMPLE_TEST_STATUS,
} from "@/common/constants";

import { triggerGoal } from "@/Integrations/Plausible";
import { NonReadOnlyUsers } from "@/Utils/AuthorizeFor";
import * as Notification from "@/Utils/Notifications";
import dayjs from "@/Utils/dayjs";
import routes from "@/Utils/request/api";

import Chip from "../../CAREUI/display/Chip";
import CareIcon from "../../CAREUI/icons/CareIcon";
import { triggerGoal } from "../../Integrations/Plausible";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import * as Notification from "../../Utils/Notifications";
import request from "../../Utils/request/request";
import useQuery from "../../Utils/request/useQuery";
import request from "@/Utils/request/request";
import useQuery from "@/Utils/request/useQuery";
import {
formatDateTime,
formatName,
Expand All @@ -32,15 +44,7 @@ import {
isAntenatal,
isPostPartum,
relativeDate,
} from "../../Utils/utils";
import { Avatar } from "../Common/Avatar";
import ButtonV2 from "../Common/ButtonV2";
import Loading from "../Common/Loading";
import Page from "../Common/Page";
import { SkillModel, UserBareMinimum } from "../Users/models";
import { patientTabs } from "./PatientDetailsTab";
import { isPatientMandatoryDataFilled } from "./Utils";
import { AssignedToObjectModel, PatientModel, SampleTestModel } from "./models";
} from "@/Utils/utils";

export const parseOccupation = (occupation: string | undefined) => {
return OCCUPATION_TYPES.find((i) => i.value === occupation)?.text;
Expand Down Expand Up @@ -468,6 +472,7 @@ export const PatientHome = (props: {
facilityId={facilityId || ""}
id={id}
patientData={patientData}
refetch={refetch}
/>
)}
</div>
Expand Down
Loading