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

change all useDispatch to useQuery and request hooks in Consultations (src/Components/Facility/Consultations/**) #6416

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
73f49f9
Optimize lodash. Fixes #6006
Omkar76 Oct 7, 2023
aaab0f5
change all dispatch to useQuery and request hooks
AshrafMd-1 Oct 7, 2023
cd0ea75
Merge branch 'develop' into Fix#6372
AshrafMd-1 Oct 7, 2023
c78022b
change all dispatch to useQuery and request hooks
AshrafMd-1 Oct 7, 2023
206082c
rebase api.tsx
AshrafMd-1 Oct 7, 2023
9164fbd
Merge branch 'Fix#6372' of https://github.com/AshrafMd-1/care_fe into…
AshrafMd-1 Oct 7, 2023
3f75c86
Merge branch 'develop' into optimize-lodash-es
nihal467 Oct 8, 2023
9bf4233
Merge branch 'develop' into optimize-lodash-es
nihal467 Oct 9, 2023
2590d10
Merge branch 'develop' into Fix#6372
nihal467 Oct 9, 2023
be98542
Replace startCase, camelCase with css capitalize
Omkar76 Oct 12, 2023
14380af
Merge branch 'develop' into Fix#6372
AshrafMd-1 Oct 14, 2023
362003c
fix: add action and recommend discharge data on patient consultation …
aeswibon Oct 17, 2023
dd16bfa
Middleware override feature in asset location (#6368)
Ashesh3 Oct 17, 2023
c776524
Replaced useDispatch with useQuery and request in ExternalResult (src…
konavivekramakrishna Oct 17, 2023
7e29f25
Added cypress test to verify warranty expiry label on an asset (#6428)
GokulramGHV Oct 17, 2023
8ad1353
Replaced export button Icon with relevant Export Icon (#6451)
shyamprakash123 Oct 17, 2023
9b362c1
Replaced dispatch with useQuery and request in Asset module (#6374)
kshitijv256 Oct 18, 2023
a92ad24
Merge pull request #6415 from Omkar76/optimize-lodash-es
mathew-alex Oct 18, 2023
67f5189
Fix CSS unintentended RTL style (#6465)
rithviknishad Oct 18, 2023
d26aba5
Replaced useDispatch with useQuery and request. (#6344)
shyamprakash123 Oct 18, 2023
db52839
Fixes JWT token refresh interval default fallback to 5 mins (instead …
rithviknishad Oct 18, 2023
6ee8422
Daily Rounds: Updated consciousness levels choices to MEWS (#6435)
aeswibon Oct 18, 2023
8011653
Fixed typo in pathParams of ConfigureHealthFacility and replaced useD…
khavinshankar Oct 19, 2023
9eac85c
New Cypress Test | Search using username | User Tab (#6478)
nihal467 Oct 20, 2023
08193ba
Fix loadash-es import (#6477)
Ashesh3 Oct 20, 2023
33f103d
Fix session expiry detection (#6472)
Ashesh3 Oct 20, 2023
e452bb5
Added test of patient_crud.cy.ts (#6135)
ShivamJhaa Oct 20, 2023
e9e2388
change all dispatch to useQuery and request hooks
AshrafMd-1 Oct 7, 2023
e22e639
Merge remote-tracking branch 'origin/Fix#6372' into Fix#6372
AshrafMd-1 Oct 24, 2023
0a1f73c
convert to pagination
AshrafMd-1 Oct 24, 2023
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
71 changes: 30 additions & 41 deletions src/Components/Facility/Consultations/ABGPlots.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,45 @@
import { useCallback, useState } from "react";
import { useDispatch } from "react-redux";
import { statusType, useAbortableEffect } from "../../../Common/utils";
import { dailyRoundsAnalyse } from "../../../Redux/actions";
import { useEffect, useState } from "react";
import { LinePlot } from "./components/LinePlot";
import Pagination from "../../Common/Pagination";
import { PAGINATION_LIMIT } from "../../../Common/constants";
import { formatDateTime } from "../../../Utils/utils";
import routes from "../../../Redux/api";
import request from "../../../Utils/request/request";

export const ABGPlots = (props: any) => {
const { consultationId } = props;
const dispatch: any = useDispatch();
const [results, setResults] = useState({});
const [currentPage, setCurrentPage] = useState(1);
const [totalCount, setTotalCount] = useState(0);

const fetchDailyRounds = useCallback(
async (status: statusType) => {
const res = await dispatch(
dailyRoundsAnalyse(
{
page: currentPage,
fields: [
"ph",
"pco2",
"po2",
"hco3",
"base_excess",
"lactate",
"sodium",
"potassium",
"ventilator_fi02",
],
},
{ consultationId }
)
);
if (!status.aborted) {
if (res?.data) {
setResults(res.data.results);
setTotalCount(res.data.count);
}
useEffect(() => {
const fetchDailyRounds = async (currentPage: number) => {
const { res, data } = await request(routes.dailyRoundsAnalyse, {
body: {
page: currentPage,
fields: [
"ph",
"pco2",
"po2",
"hco3",
"base_excess",
"lactate",
"sodium",
"potassium",
"ventilator_fi02",
],
},
pathParams: {
consultationId,
},
});
if (res?.ok && data) {
setResults(data.results);
setTotalCount(data.count);
}
},
[consultationId, dispatch, currentPage]
);

useAbortableEffect(
(status: statusType) => {
fetchDailyRounds(status);
},
[currentPage]
);
};
fetchDailyRounds(currentPage);
}, [currentPage, consultationId]);

const handlePagination = (page: number, _limit: number) => {
setCurrentPage(page);
Expand Down
80 changes: 37 additions & 43 deletions src/Components/Facility/Consultations/Beds.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as Notification from "../../../Utils/Notifications.js";

import { BedModel, CurrentBed } from "../models";
import { Dispatch, SetStateAction, useCallback, useState } from "react";
import {
createConsultationBed,
listConsultationBeds,
} from "../../../Redux/actions";
import { statusType, useAbortableEffect } from "../../../Common/utils";
import { Dispatch, SetStateAction, useEffect, useState } from "react";
import routes from "../../../Redux/api";
import request from "../../../Utils/request/request";
import useQuery from "../../../Utils/request/useQuery";

import { BedSelect } from "../../Common/BedSelect";
import ButtonV2 from "../../Common/components/ButtonV2";
Expand All @@ -16,15 +14,14 @@ import { FieldLabel } from "../../Form/FormFields/FormField";
import Loading from "../../Common/Loading";
import TextFormField from "../../Form/FormFields/TextFormField";
import { formatDateTime } from "../../../Utils/utils";
import { useDispatch } from "react-redux";
import dayjs from "../../../Utils/dayjs";
import { AssetSelect } from "../../Common/AssetSelect.js";
import DialogModal from "../../Common/Dialog.js";
import { Link } from "raviger";
import {
AssetClass,
AssetData,
assetClassProps,
AssetData,
} from "../../Assets/AssetTypes.js";
import Chip from "../../../CAREUI/display/Chip.js";

Expand All @@ -40,7 +37,6 @@ interface BedsProps {
}

const Beds = (props: BedsProps) => {
const dispatch = useDispatch<any>();
const { facilityId, consultationId, discharged } = props;
const [bed, setBed] = useState<BedModel>({});
const [startDate, setStartDate] = useState<string>(
Expand All @@ -52,33 +48,30 @@ const Beds = (props: BedsProps) => {
const [key, setKey] = useState(0);
const [showBedDetails, setShowBedDetails] = useState<CurrentBed | null>(null);

const fetchData = useCallback(
async (status: statusType) => {
setIsLoading(true);
const [bedsData]: any = await Promise.all([
dispatch(listConsultationBeds({ consultation: consultationId })),
]);
if (!status.aborted) {
setIsLoading(false);
if (!bedsData?.data)
Notification.Error({
msg: "Something went wrong..!",
});
else {
setConsultationBeds(bedsData.data.results);
setBed(bedsData.data.results[0]?.bed_object || {});
setAssets(bedsData.data.results[0]?.assets_objects || []);
}
}
},
[consultationId, dispatch]
);
useAbortableEffect(
(status: statusType) => {
fetchData(status);
},
[dispatch, fetchData, key]
);
const {
res,
data: bedData,
refetch,
} = useQuery(routes.listConsultationBeds, {
pathParams: { consultation: consultationId },
});

useEffect(() => {
setIsLoading(true);
if (!bedData || !res?.ok) {
Notification.Error({
msg: "Something went wrong..!",
});
} else {
setConsultationBeds(bedData.results);
setBed(bedData.results[0]?.bed_object || {});
setAssets(bedData.results[0]?.assets_objects || []);
}
}, [bedData, res]);

useEffect(() => {
refetch();
}, [key, refetch]);

const handleSubmit = async (e: React.SyntheticEvent) => {
e.preventDefault();
Expand All @@ -88,13 +81,14 @@ const Beds = (props: BedsProps) => {
msg: "Please select a bed first..!",
});

const res: any = await dispatch(
createConsultationBed(
{ start_date: startDate, assets: assets.map((asset) => asset.id) },
consultationId,
bed?.id
)
);
const { res } = await request(routes.createConsultationBed, {
body: {
start_date: startDate,
assets: assets.map((asset) => asset.id),
consultation: consultationId,
bed: bed?.id,
},
});

if (res && res.status === 201) {
Notification.Success({
Expand Down
55 changes: 22 additions & 33 deletions src/Components/Facility/Consultations/DailyRoundsList.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { navigate } from "raviger";
import { useCallback, useState } from "react";
import { useDispatch } from "react-redux";
import { statusType, useAbortableEffect } from "../../../Common/utils";
import { getDailyReport } from "../../../Redux/actions";
import { useEffect, useState } from "react";
import Pagination from "../../Common/Pagination";
import { DailyRoundsModel } from "../../Patient/models";
import VirtualNursingAssistantLogUpdateCard from "./DailyRounds/VirtualNursingAssistantLogUpdateCard";
import DefaultLogUpdateCard from "./DailyRounds/DefaultLogUpdateCard";
import { useTranslation } from "react-i18next";
import LoadingLogUpdateCard from "./DailyRounds/LoadingCard";
import routes from "../../../Redux/api";
import useQuery from "../../../Utils/request/useQuery";

export const DailyRoundsList = (props: any) => {
const { t } = useTranslation();
Expand All @@ -19,7 +18,6 @@ export const DailyRoundsList = (props: any) => {
consultationData,
showAutomatedRounds,
} = props;
const dispatch: any = useDispatch();
const [isDailyRoundLoading, setIsDailyRoundLoading] = useState(false);
const [dailyRoundsListData, setDailyRoundsListData] = useState<
Array<DailyRoundsModel>
Expand All @@ -29,36 +27,27 @@ export const DailyRoundsList = (props: any) => {
const [currentPage, setCurrentPage] = useState(1);
const limit = 14;

const fetchDailyRounds = useCallback(
async (status: statusType) => {
setIsDailyRoundLoading(true);
const res = await dispatch(
getDailyReport(
{
limit,
offset,
rounds_type: showAutomatedRounds ? "" : "NORMAL,VENTILATOR,ICU",
},
{ consultationId }
)
);
if (!status.aborted) {
if (res && res.data) {
setDailyRoundsListData(res.data.results);
setTotalCount(res.data.count);
}
setIsDailyRoundLoading(false);
}
const { res, data, refetch } = useQuery(routes.getDailyReports, {
body: {
limit,
offset,
rounds_type: showAutomatedRounds ? "" : "NORMAL,VENTILATOR,ICU",
},
[consultationId, dispatch, offset, showAutomatedRounds]
);
pathParams: { consultationId },
});

useAbortableEffect(
(status: statusType) => {
fetchDailyRounds(status);
},
[currentPage, showAutomatedRounds]
);
useEffect(() => {
setIsDailyRoundLoading(true);
if (res?.ok && data) {
setDailyRoundsListData(data.results);
setTotalCount(data.count);
}
setIsDailyRoundLoading(false);
}, [res, data]);

useEffect(() => {
refetch();
}, [currentPage, showAutomatedRounds, refetch]);

const handlePagination = (page: number, limit: number) => {
const offset = (page - 1) * limit;
Expand Down
51 changes: 20 additions & 31 deletions src/Components/Facility/Consultations/DialysisPlots.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,35 @@
import { useCallback, useState } from "react";
import { useDispatch } from "react-redux";
import { statusType, useAbortableEffect } from "../../../Common/utils";
import { dailyRoundsAnalyse } from "../../../Redux/actions";
import { useEffect, useState } from "react";
import routes from "../../../Redux/api";
import request from "../../../Utils/request/request";
import { LinePlot } from "./components/LinePlot";
import Pagination from "../../Common/Pagination";
import { PAGINATION_LIMIT } from "../../../Common/constants";
import { formatDateTime } from "../../../Utils/utils";

export const DialysisPlots = (props: any) => {
const { consultationId } = props;
const dispatch: any = useDispatch();
const [results, setResults] = useState({});
const [currentPage, setCurrentPage] = useState(1);
const [totalCount, setTotalCount] = useState(0);

const fetchDailyRounds = useCallback(
async (status: statusType) => {
const res = await dispatch(
dailyRoundsAnalyse(
{
page: currentPage,
fields: ["dialysis_fluid_balance", "dialysis_net_balance"],
},
{ consultationId }
)
);
if (!status.aborted) {
if (res?.data) {
setTotalCount(res.data.count);
setResults(res.data.results);
}
useEffect(() => {
const fetchDailyRounds = async (currentPage: number) => {
const { res, data } = await request(routes.dailyRoundsAnalyse, {
body: {
page: currentPage,
fields: ["dialysis_fluid_balance", "dialysis_net_balance"],
},
pathParams: {
consultationId,
},
});
if (res?.ok && data) {
setTotalCount(data.count);
setResults(data.results);
}
},
[consultationId, dispatch, currentPage]
);

useAbortableEffect(
(status: statusType) => {
fetchDailyRounds(status);
},
[consultationId, currentPage]
);
};
fetchDailyRounds(currentPage);
}, [currentPage, consultationId]);

const handlePagination = (page: number, _limit: number) => {
setCurrentPage(page);
Expand Down
Loading