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

Replace useDispatch in Patient Files (src/Components/Patient/) #7078

Merged
merged 57 commits into from
Feb 14, 2024
Merged
Changes from 4 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d565e1d
replaced useDispatch in patientHome
konavivekramakrishna Jan 22, 2024
e7c51d4
Merge branch 'develop' of https://github.com/coronasafe/care_fe into …
konavivekramakrishna Jan 22, 2024
4ef2da5
replace usedispatch in patientfiler and managepatinet
konavivekramakrishna Jan 22, 2024
486dd60
add patientfilter
konavivekramakrishna Jan 22, 2024
595de99
replace useDispatch in dailyroundslistdetials
konavivekramakrishna Jan 22, 2024
8ad1857
Merge branch 'develop' of https://github.com/konavivekramakrishna/car…
konavivekramakrishna Jan 22, 2024
e780d36
Merge branch 'develop' into fix#6546
konavivekramakrishna Jan 22, 2024
390e340
replaced useDispatch in sampleDetails
konavivekramakrishna Jan 23, 2024
afb3b7a
Merge branch 'fix#6546' of https://github.com/konavivekramakrishna/ca…
konavivekramakrishna Jan 23, 2024
acfc8a7
replace useDispatch in sampleFilters
konavivekramakrishna Jan 23, 2024
72db334
replace useDispatch in samplePreview
konavivekramakrishna Jan 23, 2024
dc3ff5e
sampleTestCard
konavivekramakrishna Jan 23, 2024
8962075
replace useDispatch in sampleTest
konavivekramakrishna Jan 23, 2024
78d87df
replace useDispatch in sampleViewAdmin
konavivekramakrishna Jan 23, 2024
67aca82
replace useDispatch in shiftCreate
konavivekramakrishna Jan 23, 2024
d043709
fix
konavivekramakrishna Jan 23, 2024
706de33
fix
konavivekramakrishna Jan 23, 2024
f906dfa
Merge branch 'develop' into fix#6546
konavivekramakrishna Jan 25, 2024
a885971
revert managePatients and patientFilter useDispatch
konavivekramakrishna Jan 25, 2024
5814d0a
Merge branch 'develop' into fix#6546
konavivekramakrishna Jan 25, 2024
c27f35f
replace useDispatch in managePatients
konavivekramakrishna Jan 25, 2024
590ac63
Merge branch 'fix#6546' of https://github.com/konavivekramakrishna/ca…
konavivekramakrishna Jan 25, 2024
e8231f2
fix
konavivekramakrishna Jan 25, 2024
43f4ace
fix
konavivekramakrishna Jan 25, 2024
a6e7d24
replace useDispatch in PatientFilter
konavivekramakrishna Jan 25, 2024
eddaf24
fix prefetch
konavivekramakrishna Jan 26, 2024
e8384aa
minor fix
konavivekramakrishna Jan 27, 2024
668b40c
add trailing slashes to api's
konavivekramakrishna Jan 27, 2024
c6289fb
fix based on review
konavivekramakrishna Jan 27, 2024
625846d
Update package-lock.json
konavivekramakrishna Jan 27, 2024
0ff3bb8
Update package-lock.json
konavivekramakrishna Jan 27, 2024
f416531
replace reload
konavivekramakrishna Jan 29, 2024
087d460
implement paginated list
konavivekramakrishna Jan 29, 2024
5e59631
fix types
konavivekramakrishna Jan 29, 2024
59321fd
Merge branch 'develop' into fix#6546
konavivekramakrishna Jan 30, 2024
a8d895f
rm Timeline from paginatedList
konavivekramakrishna Jan 30, 2024
922d015
Update button styling in CommentsSection component
konavivekramakrishna Jan 30, 2024
65a56c7
Fix API paths in Redux file
konavivekramakrishna Jan 30, 2024
d1ae751
Update API paths
konavivekramakrishna Jan 30, 2024
20ee185
Merge branch 'develop' into fix#6546
konavivekramakrishna Jan 31, 2024
574f899
Merge branch 'develop' into fix#6546
rithviknishad Feb 5, 2024
d4dead8
remove unused actions
rithviknishad Feb 5, 2024
3d70518
Merge branch 'develop' into fix#6546
konavivekramakrishna Feb 5, 2024
27453dd
Merge branch 'develop' into fix#6546
nihal467 Feb 6, 2024
aa1a722
Merge branch 'develop' into fix#6546
konavivekramakrishna Feb 7, 2024
2650e60
fix eslint
konavivekramakrishna Feb 7, 2024
e61ecfc
Merge branch 'develop' into fix#6546
konavivekramakrishna Feb 7, 2024
14cb574
fix daily rounds and filters
konavivekramakrishna Feb 7, 2024
4bf5832
Merge branch 'develop' into fix#6546
konavivekramakrishna Feb 7, 2024
3512d22
fix sample view admin
konavivekramakrishna Feb 8, 2024
bbd616f
fix shifting
konavivekramakrishna Feb 8, 2024
c285c99
fix based on review
konavivekramakrishna Feb 11, 2024
fb87fbd
Merge branch 'develop' into fix#6546
konavivekramakrishna Feb 11, 2024
604426e
Merge branch 'develop' into fix#6546
konavivekramakrishna Feb 13, 2024
0664487
minor fix
konavivekramakrishna Feb 13, 2024
9a09d57
fix lint
konavivekramakrishna Feb 13, 2024
3334cfc
Merge branch 'develop' into fix#6546
nihal467 Feb 14, 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
78 changes: 28 additions & 50 deletions src/Components/Patient/DailyRoundListDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,75 +1,53 @@
import { lazy, useCallback, useState } from "react";
import { useDispatch } from "react-redux";
import { lazy, useState } from "react";
import {
CONSCIOUSNESS_LEVEL,
CURRENT_HEALTH_CHANGE,
SYMPTOM_CHOICES,
} from "../../Common/constants";
import { statusType, useAbortableEffect } from "../../Common/utils";
import { getConsultationDailyRoundsDetails } from "../../Redux/actions";
import { DailyRoundsModel } from "./models";
import Page from "../Common/components/Page";
import ButtonV2 from "../Common/components/ButtonV2";
import { formatDateTime } from "../../Utils/utils";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";
const Loading = lazy(() => import("../Common/Loading"));
const symptomChoices = [...SYMPTOM_CHOICES];
const currentHealthChoices = [...CURRENT_HEALTH_CHANGE];

export const DailyRoundListDetails = (props: any) => {
const { facilityId, patientId, consultationId, id } = props;
const dispatch: any = useDispatch();
const [dailyRoundListDetailsData, setDailyRoundListDetails] =
useState<DailyRoundsModel>({});
const [isLoading, setIsLoading] = useState(false);

const fetchpatient = useCallback(
async (status: statusType) => {
setIsLoading(true);
const res = await dispatch(
getConsultationDailyRoundsDetails({ consultationId, id })
);
if (!status.aborted) {
if (res && res.data) {
const currentHealth = currentHealthChoices.find(
(i) => i.text === res.data.current_health
);
const { loading: isLoading } = useQuery(routes.getDailyReport, {
pathParams: { consultationId, id },
onResponse: ({ res, data }) => {
if (res && data) {
const currentHealth = currentHealthChoices.find(
(i) => i.text === data.current_health
);

const data: DailyRoundsModel = {
...res.data,
temperature: Number(res.data.temperature)
? res.data.temperature
: "",
additional_symptoms_text: "",
medication_given:
Object.keys(res.data.medication_given).length === 0
? []
: res.data.medication_given,
current_health: currentHealth
? currentHealth.desc
: res.data.current_health,
};
if (res.data.additional_symptoms?.length) {
const symptoms = res.data.additional_symptoms.map(
(symptom: number) => {
const option = symptomChoices.find((i) => i.id === symptom);
return option ? option.text.toLowerCase() : symptom;
}
);
data.additional_symptoms_text = symptoms.join(", ");
}
setDailyRoundListDetails(data);
const tdata: DailyRoundsModel = {
...data,
temperature: Number(data.temperature) ? data.temperature : "",
additional_symptoms_text: "",
medication_given: data.medication_given ?? [],

current_health: currentHealth
? currentHealth.desc
: data.current_health,
};
if (data.additional_symptoms?.length) {
const symptoms = data.additional_symptoms.map((symptom: number) => {
const option = symptomChoices.find((i) => i.id === symptom);
return option ? option.text.toLowerCase() : symptom;
});
tdata.additional_symptoms_text = symptoms.join(", ");
}
setIsLoading(false);
setDailyRoundListDetails(tdata);
}
},
[consultationId, dispatch, id]
);
useAbortableEffect(
(status: statusType) => {
fetchpatient(status);
},
[dispatch, fetchpatient]
);
});

if (isLoading) {
return <Loading />;
212 changes: 51 additions & 161 deletions src/Components/Patient/ManagePatients.tsx
Original file line number Diff line number Diff line change
@@ -11,19 +11,9 @@ import {
} from "../../Common/constants";
import { FacilityModel, PatientCategory } from "../Facility/models";
import { Link, navigate } from "raviger";
import { ReactNode, lazy, useCallback, useEffect, useState } from "react";
import {
getAllPatient,
getAnyFacility,
getDistrict,
getFacilityAssetLocation,
getLocalBody,
} from "../../Redux/actions";
import {
statusType,
useAbortableEffect,
parseOptionId,
} from "../../Common/utils";
import { ReactNode, lazy, useEffect, useState } from "react";
import { getAllPatient } from "../../Redux/actions";
import { parseOptionId } from "../../Common/utils";

import { AdvancedFilterButton } from "../../CAREUI/interactive/FiltersSlideover";
import ButtonV2 from "../Common/components/ButtonV2";
@@ -42,7 +32,6 @@ import SearchInput from "../Form/SearchInput";
import SortDropdownMenu from "../Common/SortDropdown";
import SwitchTabs from "../Common/components/SwitchTabs";
import { formatAge, parsePhoneNumber } from "../../Utils/utils.js";
import { useDispatch } from "react-redux";
import useFilters from "../../Common/hooks/useFilters";
import { useTranslation } from "react-i18next";
import Page from "../Common/components/Page.js";
@@ -86,10 +75,6 @@ const PatientCategoryDisplayText: Record<PatientCategory, string> = {

export const PatientManager = () => {
const { t } = useTranslation();
const dispatch: any = useDispatch();
const [data, setData] = useState<any[]>();
const [isLoading, setIsLoading] = useState(false);
const [totalCount, setTotalCount] = useState(0);
const {
qParams,
updateQuery,
@@ -113,10 +98,6 @@ export const PatientManager = () => {
const [showDialog, setShowDialog] = useState(false);
const [showDoctors, setShowDoctors] = useState(false);
const [showDoctorConnect, setShowDoctorConnect] = useState(false);
const [districtName, setDistrictName] = useState("");
const [localbodyName, setLocalbodyName] = useState("");
const [facilityBadgeName, setFacilityBadge] = useState("");
const [locationBadgeName, setLocationBadge] = useState("");
const [phone_number, setPhoneNumber] = useState("");
const [phoneNumberError, setPhoneNumberError] = useState("");
const [emergency_phone_number, setEmergencyPhoneNumber] = useState("");
@@ -334,68 +315,17 @@ export const PatientManager = () => {
return cleanedData;
};

useEffect(() => {
setIsLoading(true);
if (!params.phone_number) {
setPhoneNumber("+91");
}
if (!params.emergency_phone_number) {
setEmergencyPhoneNumber("+91");
}
dispatch(getAllPatient(params, "listPatients")).then((res: any) => {
if (res && res.data) {
setData(res.data.results);
setTotalCount(res.data.count);
setIsLoading(false);
const { data, loading: isLoading } = useQuery(routes.patientList, {
query: params,
onResponse: () => {
if (!params.phone_number) {
setPhoneNumber("+91");
}
});
}, [
dispatch,
qParams.last_consultation_medico_legal_case,
qParams.last_consultation_encounter_date_before,
qParams.last_consultation_encounter_date_after,
qParams.last_consultation_discharge_date_before,
qParams.last_consultation_discharge_date_after,
qParams.age_max,
qParams.age_min,
qParams.last_consultation_admitted_bed_type_list,
qParams.last_consultation__new_discharge_reason,
qParams.last_consultation_current_bed__location,
qParams.facility,
qParams.facility_type,
qParams.district,
qParams.category,
qParams.gender,
qParams.ordering,
qParams.created_date_before,
qParams.created_date_after,
qParams.modified_date_before,
qParams.modified_date_after,
qParams.is_active,
qParams.disease_status,
qParams.name,
qParams.patient_no,
qParams.page,
qParams.phone_number,
qParams.emergency_phone_number,
qParams.srf_id,
qParams.covin_id,
qParams.number_of_doses,
qParams.lsgBody,
qParams.is_kasp,
qParams.is_declared_positive,
qParams.date_declared_positive_before,
qParams.date_declared_positive_after,
qParams.date_of_result_before,
qParams.date_of_result_after,
qParams.last_consultation_symptoms_onset_date_before,
qParams.last_consultation_symptoms_onset_date_after,
qParams.last_vaccinated_date_before,
qParams.last_vaccinated_date_after,
qParams.last_consultation_is_telemedicine,
qParams.is_antenatal,
qParams.ventilator_interface,
]);
if (!params.emergency_phone_number) {
setEmergencyPhoneNumber("+91");
}
},
});

const getTheCategoryFromId = () => {
let category_name;
@@ -410,80 +340,36 @@ export const PatientManager = () => {
}
};

const fetchDistrictName = useCallback(
async (status: statusType) => {
const res =
Number(qParams.district) &&
(await dispatch(getDistrict(qParams.district)));
if (!status.aborted) {
setDistrictName(res?.data?.name);
}
},
[dispatch, qParams.district]
);

useAbortableEffect(
(status: statusType) => {
fetchDistrictName(status);
},
[fetchDistrictName]
);

const fetchLocalbodyName = useCallback(
async (status: statusType) => {
const res =
Number(qParams.lsgBody) &&
(await dispatch(getLocalBody({ id: qParams.lsgBody })));
if (!status.aborted) {
setLocalbodyName(res?.data?.name);
}
},
[dispatch, qParams.lsgBody]
);

useAbortableEffect(
(status: statusType) => {
fetchLocalbodyName(status);
const { data: districtName } = useQuery(routes.getDistrict, {
pathParams: {
id: qParams.district,
},
[fetchLocalbodyName]
);

const fetchFacilityBadgeName = useCallback(
async (status: statusType) => {
const res =
qParams.facility && (await dispatch(getAnyFacility(qParams.facility)));
prefetch: !!Number(qParams.district),
});

if (!status.aborted) {
setFacilityBadge(res?.data?.name);
}
const { data: localbodyName } = useQuery(routes.getLocalBody, {
pathParams: {
id: qParams.lsgBody,
},
[dispatch, qParams.facility]
);

const fetchLocationBadgeName = useCallback(
async (status: statusType) => {
const res =
qParams.last_consultation_current_bed__location &&
(await dispatch(
getFacilityAssetLocation(
qParams.facility,
qParams.last_consultation_current_bed__location
)
));
prefetch: !!Number(qParams.lsgBody),
});

if (!status.aborted) {
setLocationBadge(res?.data?.name);
}
const { data: facilityBadgeName } = useQuery(routes.getAnyFacility, {
pathParams: {
id: qParams.facility,
},
[dispatch, qParams.last_consultation_current_bed__location]
);
prefetch: !!qParams.facility,
});

useAbortableEffect(
(status: statusType) => {
fetchFacilityBadgeName(status);
fetchLocationBadgeName(status);
},
[fetchFacilityBadgeName, fetchLocationBadgeName]
const { data: locationBadgeName } = useQuery(
routes.getFacilityAssetLocation,
{
pathParams: {
facility_external_id: qParams.facility,
external_id: qParams.last_consultation_current_bed__location,
},
prefetch: !!qParams.last_consultation_current_bed__location,
}
);

const { data: permittedFacilities } = useQuery(
@@ -521,8 +407,8 @@ export const PatientManager = () => {
};

let patientList: ReactNode[] = [];
if (data && data.length) {
patientList = data.map((patient: any) => {
if (data && data.count) {
konavivekramakrishna marked this conversation as resolved.
Show resolved Hide resolved
patientList = data.results.map((patient: any) => {
let patientUrl = "";
if (
patient.last_consultation &&
@@ -771,16 +657,16 @@ export const PatientManager = () => {
<Loading />
</div>
);
} else if (data?.length) {
} else if (data?.count) {
managePatients = (
<>
<div className="mt-4 grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3">
{patientList}
</div>
<Pagination totalCount={totalCount} />
<Pagination totalCount={data?.count} />
</>
);
} else if (data && data.length === 0) {
} else if (data && data.count === 0) {
managePatients = (
<div className="col-span-3 w-full rounded-lg bg-white p-2 py-8 pt-4 text-center">
<p className="text-2xl font-bold text-gray-600">No Patients Found</p>
@@ -924,7 +810,7 @@ export const PatientManager = () => {
<div className="flex-1">
<CountBlock
text="Total Patients"
count={totalCount}
count={data?.count || 0}
loading={isLoading}
icon="l-user-injured"
className="pb-12"
@@ -995,14 +881,14 @@ export const PatientManager = () => {
"Is Medico-Legal Case",
"last_consultation_medico_legal_case"
),
value("Facility", "facility", facilityBadgeName),
value("Facility", "facility", facilityBadgeName?.name || ""),
value(
"Location",
"last_consultation_current_bed__location",
locationBadgeName
locationBadgeName?.name || ""
),
badge("Facility Type", "facility_type"),
value("District", "district", districtName),
value("District", "district", districtName?.name || ""),
ordering(),
value("Category", "category", getTheCategoryFromId()),
badge("Disease Status", "disease_status"),
@@ -1024,7 +910,11 @@ export const PatientManager = () => {
},
...range("Age", "age"),
badge("SRF ID", "srf_id"),
{ name: "LSG Body", value: localbodyName, paramKey: "lsgBody" },
{
name: "LSG Body",
value: localbodyName?.name || "",
paramKey: "lsgBody",
},
badge("Declared Status", "is_declared_positive"),
...dateRange("Result", "date_of_result"),
...dateRange("Declared positive", "date_declared_positive"),
73 changes: 40 additions & 33 deletions src/Components/Patient/PatientFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dayjs from "dayjs";
import { useCallback, useEffect } from "react";
import { useCallback } from "react";
import CareIcon from "../../CAREUI/icons/CareIcon";
import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover";
import {
@@ -12,11 +12,6 @@ import {
} from "../../Common/constants";
import useConfig from "../../Common/hooks/useConfig";
import useMergeState from "../../Common/hooks/useMergeState";
import {
getAllLocalBody,
getAnyFacility,
getDistrict,
} from "../../Redux/actions";
import { useDispatch } from "react-redux";
import { dateQueryString } from "../../Utils/utils";
import { DateRange } from "../Common/DateRangeInputV2";
@@ -34,6 +29,9 @@ import {
} from "../Form/FormFields/Utils";
import MultiSelectMenuV2 from "../Form/MultiSelectMenuV2";
import SelectMenuV2 from "../Form/SelectMenuV2";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";
import request from "../../Utils/request/request";

const getDate = (value: any) =>
value && dayjs(value).isValid() && dayjs(value).toDate();
@@ -145,35 +143,40 @@ export default function PatientFilter(props: any) {
ventilator_interface: null,
};

useEffect(() => {
async function fetchData() {
if (filter.facility) {
const { data: facilityData } = await dispatch(
getAnyFacility(filter.facility, "facility")
);
setFilterState({ facility_ref: facilityData });
}
useQuery(routes.getAnyFacility, {
pathParams: {
facilityId: filter.facility,
},
prefetch: !!filter.facility,
onResponse: ({ data }) => {
setFilterState({ facility_ref: data });
},
});

if (filter.district) {
const { data: districtData } = await dispatch(
getDistrict(filter.district, "district")
);
setFilterState({ district_ref: districtData });
}
useQuery(routes.getDistrict, {
pathParams: {
facilityId: filter.facility,
},
prefetch: !!filter.district,
onResponse: ({ data }) => {
setFilterState({ district_ref: data });
},
});

if (filter.lsgBody) {
const { data: lsgRes } = await dispatch(getAllLocalBody({}));
const lsgBodyData = lsgRes.results;
useQuery(routes.getAllLocalBody, {
pathParams: {
facilityId: filter.facility,
},

setFilterState({
lsgBody_ref: lsgBodyData.filter(
(obj: any) => obj.id.toString() === filter.lsgBody.toString()
)[0],
});
}
}
fetchData();
}, [dispatch]);
prefetch: !!filter.lsgBody,
onResponse: ({ data }) => {
setFilterState({
lsgBody_ref: data?.results.filter(
(obj: any) => obj.id.toString() === filter.lsgBody.toString()
)[0],
});
},
});

const VACCINATED_FILTER = [
{ id: "0", text: "Unvaccinated" },
@@ -209,7 +212,11 @@ export default function PatientFilter(props: any) {

const lsgSearch = useCallback(
async (search: string) => {
const res = await dispatch(getAllLocalBody({ local_body_name: search }));
const res = await request(routes.getAllLocalBody, {
query: {
local_body_name: search,
},
});
return res?.data?.results;
},
[dispatch]
6 changes: 6 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
@@ -537,6 +537,8 @@ const routes = {

getDailyReport: {
path: "/api/v1/consultation/{consultationId}/daily_rounds/{id}/",
method: "GET",
TRes: Type<DailyRoundsModel>(),
},
dailyRoundsAnalyse: {
path: "/api/v1/consultation/{consultationId}/daily_rounds/analyse/",
@@ -624,6 +626,8 @@ const routes = {
},
patientList: {
path: "/api/v1/patient/",
method: "GET",
TRes: Type<PaginatedResponse<PatientModel>>(),
},
addPatient: {
path: "/api/v1/patient/",
@@ -753,6 +757,8 @@ const routes = {
},
getAllLocalBody: {
path: "/api/v1/local_body/",
method: "GET",
TRes: Type<PaginatedResponse<LocalBodyModel>>(),
},
getLocalbodyByName: {
path: "/api/v1/local_body/",