Skip to content

Commit

Permalink
replace useDispatch in dailyroundslistdetials
Browse files Browse the repository at this point in the history
  • Loading branch information
konavivekramakrishna committed Jan 22, 2024
1 parent 486dd60 commit 595de99
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 50 deletions.
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 />;
Expand Down
2 changes: 2 additions & 0 deletions src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,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/",
Expand Down

0 comments on commit 595de99

Please sign in to comment.