From b3fea0a2f9a05f134fdce8d5b065b920cb2e6028 Mon Sep 17 00:00:00 2001 From: Krushna Date: Thu, 23 Nov 2023 20:02:55 +0530 Subject: [PATCH 1/3] Replaced useDispatch with useQuerry on DailyRoundListDetails --- .../Patient/DailyRoundListDetails.tsx | 26 ++++++++++++------- src/Redux/api.tsx | 4 ++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Components/Patient/DailyRoundListDetails.tsx b/src/Components/Patient/DailyRoundListDetails.tsx index 9ac68a20ca7..02e259e9c12 100644 --- a/src/Components/Patient/DailyRoundListDetails.tsx +++ b/src/Components/Patient/DailyRoundListDetails.tsx @@ -1,8 +1,8 @@ import { lazy, useCallback, useState } from "react"; -import { useDispatch } from "react-redux"; +import routes from "../../Redux/api"; +import useQuery from "../../Utils/request/useQuery"; import { 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"; @@ -11,23 +11,29 @@ const Loading = lazy(() => import("../Common/Loading")); const symptomChoices = [...SYMPTOM_CHOICES]; const currentHealthChoices = [...CURRENT_HEALTH_CHANGE]; +function useConsultationQuery(consultationId: any, id: any) { + return useQuery(routes.getDailyReport, { + pathParams: { + consultationId, + id, + }, + }); +} + export const DailyRoundListDetails = (props: any) => { const { facilityId, patientId, consultationId, id } = props; - const dispatch: any = useDispatch(); const [dailyRoundListDetailsData, setDailyRoundListDetails] = useState({}); const [isLoading, setIsLoading] = useState(false); + const res = useConsultationQuery(consultationId, id); 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 + (i) => i.text === res.data?.current_health ); const data: DailyRoundsModel = { @@ -37,7 +43,7 @@ export const DailyRoundListDetails = (props: any) => { : "", additional_symptoms_text: "", medication_given: - Object.keys(res.data.medication_given).length === 0 + Object.keys(res.data.medication_given ?? {}).length === 0 ? [] : res.data.medication_given, current_health: currentHealth @@ -58,13 +64,13 @@ export const DailyRoundListDetails = (props: any) => { setIsLoading(false); } }, - [consultationId, dispatch, id] + [consultationId, id] ); useAbortableEffect( (status: statusType) => { fetchpatient(status); }, - [dispatch, fetchpatient] + [fetchpatient] ); if (isLoading) { diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 01c356f6603..5d73149e342 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -46,7 +46,7 @@ import { Prescription } from "../Components/Medicine/models"; import { UserModel } from "../Components/Users/models"; import { PaginatedResponse } from "../Utils/request/types"; -import { PatientModel } from "../Components/Patient/models"; +import { PatientModel, DailyRoundsModel } from "../Components/Patient/models"; import { IComment, IResource } from "../Components/Resource/models"; /** @@ -441,6 +441,8 @@ const routes = { getDailyReport: { path: "/api/v1/consultation/{consultationId}/daily_rounds/{id}/", + method: "GET", + TRes: Type(), }, dailyRoundsAnalyse: { path: "/api/v1/consultation/{consultationId}/daily_rounds/analyse/", From fd943f079076c84592fda6782a4d5a74ccbba6fa Mon Sep 17 00:00:00 2001 From: Krushna Date: Mon, 27 Nov 2023 00:40:33 +0530 Subject: [PATCH 2/3] Updated DailyRoundListDetails --- .../Patient/DailyRoundListDetails.tsx | 124 +++++++----------- 1 file changed, 47 insertions(+), 77 deletions(-) diff --git a/src/Components/Patient/DailyRoundListDetails.tsx b/src/Components/Patient/DailyRoundListDetails.tsx index 02e259e9c12..008aeb4d86a 100644 --- a/src/Components/Patient/DailyRoundListDetails.tsx +++ b/src/Components/Patient/DailyRoundListDetails.tsx @@ -1,8 +1,7 @@ -import { lazy, useCallback, useState } from "react"; +import { lazy } from "react"; import routes from "../../Redux/api"; import useQuery from "../../Utils/request/useQuery"; import { CURRENT_HEALTH_CHANGE, SYMPTOM_CHOICES } from "../../Common/constants"; -import { statusType, useAbortableEffect } from "../../Common/utils"; import { DailyRoundsModel } from "./models"; import Page from "../Common/components/Page"; import ButtonV2 from "../Common/components/ButtonV2"; @@ -11,72 +10,45 @@ const Loading = lazy(() => import("../Common/Loading")); const symptomChoices = [...SYMPTOM_CHOICES]; const currentHealthChoices = [...CURRENT_HEALTH_CHANGE]; -function useConsultationQuery(consultationId: any, id: any) { - return useQuery(routes.getDailyReport, { +export const DailyRoundListDetails = (props: any) => { + const { facilityId, patientId, consultationId, id } = props; + const { res, data, loading } = useQuery(routes.getDailyReport, { pathParams: { consultationId, id, }, }); -} - -export const DailyRoundListDetails = (props: any) => { - const { facilityId, patientId, consultationId, id } = props; - const [dailyRoundListDetailsData, setDailyRoundListDetails] = - useState({}); - const [isLoading, setIsLoading] = useState(false); - - const res = useConsultationQuery(consultationId, id); - const fetchpatient = useCallback( - async (status: statusType) => { - setIsLoading(true); - if (!status.aborted) { - if (res && res.data) { - const currentHealth = currentHealthChoices.find( - (i) => i.text === res.data?.current_health - ); + const fetchpatient = async () => { + 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); - } - setIsLoading(false); + const Data: DailyRoundsModel = { + ...data, + temperature: Number(data?.temperature) ? data.temperature : "", + additional_symptoms_text: "", + medication_given: + Object.keys(data.medication_given ?? {}).length === 0 + ? [] + : 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; + }); + Data.additional_symptoms_text = symptoms.join(", "); } - }, - [consultationId, id] - ); - useAbortableEffect( - (status: statusType) => { - fetchpatient(status); - }, - [fetchpatient] - ); - - if (isLoading) { + } + }; + fetchpatient(); + if (loading) { return ; } - return ( { Patient Category:{" "} - {dailyRoundListDetailsData.patient_category ?? "-"} + {data?.patient_category ?? "-"} @@ -107,51 +79,49 @@ export const DailyRoundListDetails = (props: any) => {
Temperature: - {dailyRoundListDetailsData.temperature ?? "-"} + {data?.temperature ?? "-"}
Taken at: - {dailyRoundListDetailsData.taken_at - ? formatDateTime(dailyRoundListDetailsData.taken_at) - : "-"} + {data?.taken_at ? formatDateTime(data?.taken_at) : "-"}
SpO2: - {dailyRoundListDetailsData.ventilator_spo2 ?? "-"} + {data?.ventilator_spo2 ?? "-"}
Additional Symptoms:{" "} - {dailyRoundListDetailsData.additional_symptoms_text ?? "-"} + {data?.additional_symptoms_text ?? "-"}
Admitted To *:{" "} - {dailyRoundListDetailsData.admitted_to ?? "-"} + {data?.admitted_to ?? "-"}
Physical Examination Info:{" "} - {dailyRoundListDetailsData.physical_examination_info ?? "-"} + {data?.physical_examination_info ?? "-"}
Other Symptoms:{" "} - {dailyRoundListDetailsData.other_symptoms ?? "-"} + {data?.other_symptoms ?? "-"}
Other Details:{" "} - {dailyRoundListDetailsData.other_details ?? "-"} + {data?.other_details ?? "-"}
Pulse(bpm): - {dailyRoundListDetailsData.pulse ?? "-"} + {data?.pulse ?? "-"}
BP @@ -160,14 +130,14 @@ export const DailyRoundListDetails = (props: any) => { Systolic:{" "} - {dailyRoundListDetailsData.bp?.systolic ?? "-"} + {data?.bp?.systolic ?? "-"}
{" "} Diastolic: - {dailyRoundListDetailsData.bp?.diastolic ?? "-"} + {data?.bp?.diastolic ?? "-"}
@@ -177,23 +147,23 @@ export const DailyRoundListDetails = (props: any) => { Respiratory Rate (bpm): - {dailyRoundListDetailsData.resp ?? "-"} + {data?.resp ?? "-"}
Rhythm: - {dailyRoundListDetailsData.rhythm ?? "-"} + {data?.rhythm ?? "-"}
Rhythm Description:{" "} - {dailyRoundListDetailsData.rhythm_detail ?? "-"} + {data?.rhythm_detail ?? "-"}
Recommend Discharge:{" "} - {dailyRoundListDetailsData.recommend_discharge ? ( + {data?.recommend_discharge ? ( Yes ) : ( No From 9b99a5ea5d73317903664e651aab4d610663659c Mon Sep 17 00:00:00 2001 From: Krushna Date: Mon, 4 Dec 2023 15:09:05 +0530 Subject: [PATCH 3/3] Updated-2 DailyRoundListDetails --- .../Patient/DailyRoundListDetails.tsx | 86 ++++++++++--------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/src/Components/Patient/DailyRoundListDetails.tsx b/src/Components/Patient/DailyRoundListDetails.tsx index 008aeb4d86a..85a3cf8115a 100644 --- a/src/Components/Patient/DailyRoundListDetails.tsx +++ b/src/Components/Patient/DailyRoundListDetails.tsx @@ -18,34 +18,36 @@ export const DailyRoundListDetails = (props: any) => { id, }, }); - const fetchpatient = async () => { - if (res && data) { - const currentHealth = currentHealthChoices.find( - (i) => i.text === data?.current_health - ); - - const Data: DailyRoundsModel = { - ...data, - temperature: Number(data?.temperature) ? data.temperature : "", - additional_symptoms_text: "", - medication_given: - Object.keys(data.medication_given ?? {}).length === 0 - ? [] - : 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; - }); - Data.additional_symptoms_text = symptoms.join(", "); + let currentHealth: + | { + id: number; + text: string; + desc: string; } - } + | undefined; + if (res && data) { + currentHealth = currentHealthChoices.find( + (i) => i.text === data?.current_health + ); + } + + const Data: DailyRoundsModel = { + ...data, + temperature: Number(data?.temperature) ? data?.temperature : "", + additional_symptoms_text: "", + medication_given: + Object.keys(data?.medication_given ?? {}).length === 0 + ? [] + : data?.medication_given, + current_health: currentHealth ? currentHealth.desc : data?.current_health, }; - fetchpatient(); + 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; + }); + data.additional_symptoms_text = symptoms.join(", "); + } if (loading) { return ; } @@ -61,7 +63,7 @@ export const DailyRoundListDetails = (props: any) => { Patient Category:{" "} - {data?.patient_category ?? "-"} + {Data.patient_category ?? "-"}
@@ -79,49 +81,49 @@ export const DailyRoundListDetails = (props: any) => {
Temperature: - {data?.temperature ?? "-"} + {Data.temperature ?? "-"}
Taken at: - {data?.taken_at ? formatDateTime(data?.taken_at) : "-"} + {Data.taken_at ? formatDateTime(data?.taken_at) : "-"}
SpO2: - {data?.ventilator_spo2 ?? "-"} + {Data.ventilator_spo2 ?? "-"}
Additional Symptoms:{" "} - {data?.additional_symptoms_text ?? "-"} + {Data.additional_symptoms_text ?? "-"}
Admitted To *:{" "} - {data?.admitted_to ?? "-"} + {Data.admitted_to ?? "-"}
Physical Examination Info:{" "} - {data?.physical_examination_info ?? "-"} + {Data.physical_examination_info ?? "-"}
Other Symptoms:{" "} - {data?.other_symptoms ?? "-"} + {Data.other_symptoms ?? "-"}
Other Details:{" "} - {data?.other_details ?? "-"} + {Data.other_details ?? "-"}
Pulse(bpm): - {data?.pulse ?? "-"} + {Data.pulse ?? "-"}
BP @@ -130,14 +132,14 @@ export const DailyRoundListDetails = (props: any) => { Systolic:{" "} - {data?.bp?.systolic ?? "-"} + {Data.bp?.systolic ?? "-"}
{" "} Diastolic: - {data?.bp?.diastolic ?? "-"} + {Data.bp?.diastolic ?? "-"}
@@ -147,23 +149,23 @@ export const DailyRoundListDetails = (props: any) => { Respiratory Rate (bpm): - {data?.resp ?? "-"} + {Data.resp ?? "-"}
Rhythm: - {data?.rhythm ?? "-"} + {Data.rhythm ?? "-"}
Rhythm Description:{" "} - {data?.rhythm_detail ?? "-"} + {Data.rhythm_detail ?? "-"}
Recommend Discharge:{" "} - {data?.recommend_discharge ? ( + {Data.recommend_discharge ? ( Yes ) : ( No