From 330c7d9f2f8150067a7ad13e9bda9b65104913af Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Wed, 18 Oct 2023 08:21:34 +0530 Subject: [PATCH 1/9] PaginatedList: fix `offset` not included in qParams --- src/CAREUI/misc/PaginatedList.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CAREUI/misc/PaginatedList.tsx b/src/CAREUI/misc/PaginatedList.tsx index 3b699177d9e..899febdaaf3 100644 --- a/src/CAREUI/misc/PaginatedList.tsx +++ b/src/CAREUI/misc/PaginatedList.tsx @@ -42,11 +42,15 @@ export default function PaginatedList({ perPage = DEFAULT_PER_PAGE_LIMIT, ...queryOptions }: Props) { + const [currentPage, setPage] = useState(1); const query = useQuery(route, { ...queryOptions, - query: { ...queryOptions.query, limit: perPage }, + query: { + ...queryOptions.query, + limit: perPage, + offset: (currentPage - 1) * perPage, + }, }); - const [currentPage, setPage] = useState(1); const items = query.data?.results ?? []; From 730279812488356767d58d498ce7e345aa6a8bfe Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Wed, 18 Oct 2023 08:26:24 +0530 Subject: [PATCH 2/9] fix error message --- src/CAREUI/misc/PaginatedList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CAREUI/misc/PaginatedList.tsx b/src/CAREUI/misc/PaginatedList.tsx index 899febdaaf3..3521807154e 100644 --- a/src/CAREUI/misc/PaginatedList.tsx +++ b/src/CAREUI/misc/PaginatedList.tsx @@ -24,7 +24,7 @@ function useContextualized() { const ctx = useContext(context); if (ctx === null) { - throw new Error("PaginatedList must be used within a PaginatedList"); + throw new Error("Component must be used within a PaginatedList"); } return ctx as PaginatedListContext; From 48aff69d5d854fb7a3bd4862cd70dfec0bdf3885 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Tue, 24 Oct 2023 15:39:35 +0530 Subject: [PATCH 3/9] convert dispatch to useQuery and request --- .../Facility/Consultations/ABGPlots.tsx | 71 +++--- .../Facility/Consultations/Beds.tsx | 80 +++--- .../Consultations/DailyRoundsList.tsx | 194 ++++++--------- .../Facility/Consultations/DialysisPlots.tsx | 51 ++-- .../Facility/Consultations/Feed.tsx | 142 +++++------ .../Facility/Consultations/LiveFeed.tsx | 68 +++--- .../Consultations/NeurologicalTables.tsx | 128 +++++----- .../Facility/Consultations/NursingPlot.tsx | 54 ++-- .../Facility/Consultations/NutritionPlots.tsx | 68 +++--- .../Facility/Consultations/PainDiagrams.tsx | 67 +++-- .../Consultations/PressureSoreDiagrams.tsx | 71 +++--- .../Consultations/PrimaryParametersPlot.tsx | 77 +++--- .../Facility/Consultations/VentilatorPlot.tsx | 82 +++---- src/Components/Facility/models.tsx | 231 +++++++++++++++++- src/Redux/api.tsx | 21 ++ 15 files changed, 771 insertions(+), 634 deletions(-) diff --git a/src/Components/Facility/Consultations/ABGPlots.tsx b/src/Components/Facility/Consultations/ABGPlots.tsx index 3cb4daa981c..9b5e6fa38c6 100644 --- a/src/Components/Facility/Consultations/ABGPlots.tsx +++ b/src/Components/Facility/Consultations/ABGPlots.tsx @@ -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); diff --git a/src/Components/Facility/Consultations/Beds.tsx b/src/Components/Facility/Consultations/Beds.tsx index 757c19c788a..8d08b92d370 100644 --- a/src/Components/Facility/Consultations/Beds.tsx +++ b/src/Components/Facility/Consultations/Beds.tsx @@ -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"; @@ -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"; @@ -40,7 +37,6 @@ interface BedsProps { } const Beds = (props: BedsProps) => { - const dispatch = useDispatch(); const { facilityId, consultationId, discharged } = props; const [bed, setBed] = useState({}); const [startDate, setStartDate] = useState( @@ -52,33 +48,30 @@ const Beds = (props: BedsProps) => { const [key, setKey] = useState(0); const [showBedDetails, setShowBedDetails] = useState(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(); @@ -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({ diff --git a/src/Components/Facility/Consultations/DailyRoundsList.tsx b/src/Components/Facility/Consultations/DailyRoundsList.tsx index 0ec84a0cc87..c5daae95958 100644 --- a/src/Components/Facility/Consultations/DailyRoundsList.tsx +++ b/src/Components/Facility/Consultations/DailyRoundsList.tsx @@ -1,14 +1,11 @@ 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 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 PaginatedList from "../../../CAREUI/misc/PaginatedList"; export const DailyRoundsList = (props: any) => { const { t } = useTranslation(); @@ -19,126 +16,79 @@ export const DailyRoundsList = (props: any) => { consultationData, showAutomatedRounds, } = props; - const dispatch: any = useDispatch(); - const [isDailyRoundLoading, setIsDailyRoundLoading] = useState(false); - const [dailyRoundsListData, setDailyRoundsListData] = useState< - Array - >([]); - const [totalCount, setTotalCount] = useState(0); - const [offset, setOffset] = useState(0); - 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); - } - }, - [consultationId, dispatch, offset, showAutomatedRounds] - ); - - useAbortableEffect( - (status: statusType) => { - fetchDailyRounds(status); - }, - [currentPage, showAutomatedRounds] - ); - - const handlePagination = (page: number, limit: number) => { - const offset = (page - 1) * limit; - setCurrentPage(page); - setOffset(offset); - }; - - let roundsList: any; - - if (isDailyRoundLoading) { - roundsList = ( - <> - {Array.from({ length: 3 }).map((_, i) => ( - - ))} - - ); - } else if (dailyRoundsListData.length === 0) { - roundsList = ( - - {t("no_consultation_updates")} - - ); - } else if (dailyRoundsListData.length) { - roundsList = dailyRoundsListData.map((itemData, idx) => { - if (itemData.rounds_type === "AUTOMATED") { - return ( - - ); - } - - return ( - { - if (itemData.rounds_type === "NORMAL") { - navigate( - `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily-rounds/${itemData.id}` - ); - } else { - navigate( - `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily_rounds/${itemData.id}` - ); - } - }} - onUpdateLog={() => { - if (itemData.rounds_type === "NORMAL") { - navigate( - `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily-rounds/${itemData.id}/update` - ); - } else { - navigate( - `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily_rounds/${itemData.id}/update` - ); - } - }} - /> - ); - }); - } return ( -
-
- {roundsList} -
- {!isDailyRoundLoading && totalCount > limit && ( -
- + + {() => ( +
+
+ + + {t("no_consultation_updates")} + + + + <> + {Array.from({ length: 3 }).map((_, i) => ( + + ))} + + + className="my-8 flex grow flex-col gap-3 lg:mx-8"> + {(items) => { + return items.map((itemData, idx) => { + if (itemData.rounds_type === "AUTOMATED") { + return ( + + ); + } + return ( + { + if (itemData.rounds_type === "NORMAL") { + navigate( + `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily-rounds/${itemData.id}` + ); + } else { + navigate( + `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily_rounds/${itemData.id}` + ); + } + }} + onUpdateLog={() => { + if (itemData.rounds_type === "NORMAL") { + navigate( + `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily-rounds/${itemData.id}/update` + ); + } else { + navigate( + `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily_rounds/${itemData.id}/update` + ); + } + }} + /> + ); + }); + }} + +
+ +
+
)} -
+ ); }; diff --git a/src/Components/Facility/Consultations/DialysisPlots.tsx b/src/Components/Facility/Consultations/DialysisPlots.tsx index 4830af3abf0..50bbf911208 100644 --- a/src/Components/Facility/Consultations/DialysisPlots.tsx +++ b/src/Components/Facility/Consultations/DialysisPlots.tsx @@ -1,7 +1,6 @@ -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"; @@ -9,38 +8,28 @@ 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); diff --git a/src/Components/Facility/Consultations/Feed.tsx b/src/Components/Facility/Consultations/Feed.tsx index 31691c736f4..02874aed8f1 100644 --- a/src/Components/Facility/Consultations/Feed.tsx +++ b/src/Components/Facility/Consultations/Feed.tsx @@ -1,5 +1,6 @@ import * as Notification from "../../../Utils/Notifications.js"; - +import routes from "../../../Redux/api"; +import request from "../../../Utils/request/request"; import { CAMERA_STATES, CameraPTZ, @@ -11,14 +12,7 @@ import { useMSEMediaPlayer, } from "../../../Common/hooks/useMSEplayer"; import { PTZState, useFeedPTZ } from "../../../Common/hooks/useFeedPTZ"; -import { useCallback, useEffect, useRef, useState } from "react"; -import { - getConsultation, - getPermittedFacility, - listAssetBeds, - partialUpdateAssetBed, -} from "../../../Redux/actions"; -import { statusType, useAbortableEffect } from "../../../Common/utils"; +import { useEffect, useRef, useState } from "react"; import CareIcon from "../../../CAREUI/icons/CareIcon.js"; import { ConsultationModel } from "../models"; @@ -33,11 +27,13 @@ import useFullscreen from "../../../Common/hooks/useFullscreen.js"; import { triggerGoal } from "../../../Integrations/Plausible.js"; import useAuthUser from "../../../Common/hooks/useAuthUser.js"; import Spinner from "../../Common/Spinner.js"; +import useQuery from "../../../Utils/request/useQuery"; interface IFeedProps { facilityId: string; consultationId: any; } + const PATIENT_DEFAULT_PRESET = "Patient View".trim().toLowerCase(); export const Feed: React.FC = ({ consultationId, facilityId }) => { @@ -51,7 +47,6 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { }); const [cameraMiddlewareHostname, setCameraMiddlewareHostname] = useState(""); const [cameraConfig, setCameraConfig] = useState({}); - const [isLoading, setIsLoading] = useState(true); const [bedPresets, setBedPresets] = useState([]); const [bed, setBed] = useState(); const [precision, setPrecision] = useState(1); @@ -61,17 +56,14 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { const [statusReported, setStatusReported] = useState(false); const authUser = useAuthUser(); - useEffect(() => { - const fetchFacility = async () => { - const res = await dispatch(getPermittedFacility(facilityId)); - - if (res.status === 200 && res.data) { - setCameraMiddlewareHostname(res.data.middleware_address); + useQuery(routes.getPermittedFacility, { + pathParams: { id: facilityId || "" }, + onResponse: ({ res, data }) => { + if (res && res.status === 200 && data && data.middleware_address) { + setCameraMiddlewareHostname(data.middleware_address); } - }; - - if (facilityId) fetchFacility(); - }, [dispatch, facilityId]); + }, + }); useEffect(() => { if (cameraState) { @@ -80,7 +72,7 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { precision: precision, }); } - }, [precision]); + }, [precision, cameraState]); useEffect(() => { const timeout = setTimeout(() => { @@ -91,59 +83,54 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { setCamTimeout(0); }, 5000); return () => clearTimeout(timeout); - }, [cameraState]); + }, [cameraState, cameraConfig]); const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent); const liveFeedPlayerRef = useRef(null); - const fetchData = useCallback( - async (status: statusType) => { - setIsLoading(true); - const res = await dispatch(getConsultation(consultationId)); - if (!status.aborted && res?.data) { - const consultation = res.data as ConsultationModel; + const { loading: getConsultationLoading } = useQuery(routes.getConsultation, { + pathParams: { id: consultationId }, + onResponse: ({ res, data }) => { + if (res && res.status === 200 && data) { + const consultation = data as ConsultationModel; const consultationBedId = consultation.current_bed?.bed_object?.id; if (consultationBedId) { - let bedAssets = await dispatch( - listAssetBeds({ bed: consultationBedId }) - ); - setBed(consultationBedId); - bedAssets = { - ...bedAssets, - data: { - ...bedAssets.data, - results: bedAssets.data.results.filter( - (asset: { asset_object: { meta: { asset_type: string } } }) => { - return asset?.asset_object?.meta?.asset_type === "CAMERA" - ? true - : false; - } - ), - }, - }; - - if (bedAssets?.data?.results?.length) { - const { camera_access_key } = - bedAssets.data.results[0].asset_object.meta; - const config = camera_access_key.split(":"); - setCameraAsset({ - id: bedAssets.data.results[0].asset_object.id, - accessKey: config[2] || "", - }); - setCameraConfig(bedAssets.data.results[0].meta); - setCameraState({ - ...bedAssets.data.results[0].meta.position, - precision: 1, - }); - } + (async () => { + const { res: listAssetBedsRes, data: listAssetBedsData } = + await request(routes.getAssetBed, { + pathParams: { external_id: consultationBedId }, + }); + setBed(consultationBedId); + const bedAssets: any = { + ...listAssetBedsRes, + data: { + ...listAssetBedsData, + results: listAssetBedsData?.results.filter((asset) => { + return asset?.asset_object?.meta?.asset_type === "CAMERA"; + }), + }, + }; + + if (bedAssets?.data?.results?.length) { + const { camera_access_key } = + bedAssets.data.results[0].asset_object.meta; + const config = camera_access_key.split(":"); + setCameraAsset({ + id: bedAssets.data.results[0].asset_object.id, + accessKey: config[2] || "", + }); + setCameraConfig(bedAssets.data.results[0].meta); + setCameraState({ + ...bedAssets.data.results[0].meta.position, + precision: 1, + }); + } + })(); } - - setIsLoading(false); } }, - [consultationId, dispatch] - ); + }); // const [position, setPosition] = useState(); // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -212,8 +199,10 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { const getBedPresets = async (asset: any) => { if (asset.id && bed) { - const bedAssets = await dispatch(listAssetBeds({ asset: asset.id, bed })); - setBedPresets(bedAssets?.data?.results); + const { data: bedAssets } = await request(routes.getAssetBed, { + pathParams: { external_id: asset.id, bed }, + }); + setBedPresets(bedAssets?.results); } }; @@ -267,10 +256,6 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { }; }, [startStream, streamStatus]); - useAbortableEffect((status: statusType) => { - fetchData(status); - }, []); - useEffect(() => { if (!currentPreset && streamStatus === StreamStatus.Playing) { setLoading(CAMERA_STATES.MOVING.GENERIC); @@ -354,9 +339,10 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { onSuccess: async (data) => { if (currentPreset?.asset_object?.id && data?.position) { setLoading(option.loadingLabel); - const response = await dispatch( - partialUpdateAssetBed( - { + const { res, data: ResponseData } = await request( + routes.partialUpdateAssetBed, + { + body: { asset: currentPreset.asset_object.id, bed: currentPreset.bed_object.id, meta: { @@ -364,12 +350,12 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { position: data?.position, }, }, - currentPreset?.id - ) + pathParams: { id: currentPreset?.id }, + } ); - if (response && response.status === 200) { + if (res && ResponseData && res.status === 200) { Notification.Success({ msg: "Preset Updated" }); - getBedPresets(cameraAsset?.id); + await getBedPresets(cameraAsset?.id); getPresets({}); } setLoading(CAMERA_STATES.IDLE); @@ -401,7 +387,7 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { useKeyboardShortcut(option.shortcutKey, option.callback); } - if (isLoading) return ; + if (getConsultationLoading) return ; return (
diff --git a/src/Components/Facility/Consultations/LiveFeed.tsx b/src/Components/Facility/Consultations/LiveFeed.tsx index aba473e958d..38fd8d60cb3 100644 --- a/src/Components/Facility/Consultations/LiveFeed.tsx +++ b/src/Components/Facility/Consultations/LiveFeed.tsx @@ -1,11 +1,8 @@ -import { useEffect, useState, useRef } from "react"; +import { useEffect, useRef, useState } from "react"; import { useDispatch } from "react-redux"; +import routes from "../../../Redux/api"; +import request from "../../../Utils/request/request"; import useKeyboardShortcut from "use-keyboard-shortcut"; -import { - listAssetBeds, - partialUpdateAssetBed, - deleteAssetBed, -} from "../../../Redux/actions"; import { getCameraPTZ } from "../../../Common/constants"; import { StreamStatus, @@ -112,28 +109,30 @@ const LiveFeed = (props: any) => { }; const getBedPresets = async (id: any) => { - const bedAssets = await dispatch( - listAssetBeds({ - asset: id, + const { data } = await request(routes.getAssetBed, { + pathParams: { asset: id }, + body: { limit: page.limit, offset: page.offset, - }) - ); - setBedPresets(bedAssets?.data?.results); + }, + }); + setBedPresets(data?.results); setPage({ ...page, - count: bedAssets?.data?.count, + count: data?.count || 0, }); }; const deletePreset = async (id: any) => { - const res = await dispatch(deleteAssetBed(id)); + const { res, data } = await request(routes.deleteAssetBed, { + pathParams: { id }, + }); if (res?.status === 204) { Notification.Success({ msg: "Preset deleted successfully" }); getBedPresets(cameraAsset.id); } else { Notification.Error({ - msg: "Error while deleting Preset: " + (res?.data?.detail || ""), + msg: "Error while deleting Preset: " + (data?.detail || ""), }); } setToDelete(null); @@ -144,20 +143,18 @@ const LiveFeed = (props: any) => { bed_id: bed.id, preset_name: preset, }; - const response = await dispatch( - partialUpdateAssetBed( - { - asset: currentPreset.asset_object.id, - bed: bed.id, - meta: { - ...currentPreset.meta, - ...data, - }, + const { res: responseRes } = await request(routes.partialUpdateAssetBed, { + pathParams: { id: currentPreset.id }, + body: { + asset: currentPreset.asset_object.id, + bed: bed.id, + meta: { + ...currentPreset.meta, + ...data, }, - currentPreset?.id - ) - ); - if (response && response.status === 200) { + }, + }); + if (responseRes && responseRes.status === 200) { Notification.Success({ msg: "Preset Updated" }); } else { Notification.Error({ msg: "Something Went Wrong" }); @@ -251,9 +248,11 @@ const LiveFeed = (props: any) => { if (currentPreset?.asset_object?.id && data?.position) { setLoading(option.loadingLabel); console.log("Updating Preset"); - const response = await dispatch( - partialUpdateAssetBed( - { + const { res: responseRes } = await request( + routes.partialUpdateAssetBed, + { + pathParams: { id: currentPreset.id }, + body: { asset: currentPreset.asset_object.id, bed: currentPreset.bed_object.id, meta: { @@ -261,10 +260,10 @@ const LiveFeed = (props: any) => { position: data?.position, }, }, - currentPreset?.id - ) + } ); - if (response && response.status === 200) { + + if (responseRes && responseRes.status === 200) { Notification.Success({ msg: "Preset Updated" }); getBedPresets(cameraAsset?.id); fetchCameraPresets(); @@ -621,5 +620,4 @@ const LiveFeed = (props: any) => { ); }; - export default LiveFeed; diff --git a/src/Components/Facility/Consultations/NeurologicalTables.tsx b/src/Components/Facility/Consultations/NeurologicalTables.tsx index 36fae175480..c39207d8ce3 100644 --- a/src/Components/Facility/Consultations/NeurologicalTables.tsx +++ b/src/Components/Facility/Consultations/NeurologicalTables.tsx @@ -1,13 +1,14 @@ -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 Pagination from "../../Common/Pagination"; import { - PAGINATION_LIMIT, EYE_OPEN_SCALE, - VERBAL_RESPONSE_SCALE, MOTOR_RESPONSE_SCALE, + PAGINATION_LIMIT, + VERBAL_RESPONSE_SCALE, } from "../../../Common/constants"; import { formatDateTime } from "../../../Utils/utils"; @@ -28,7 +29,10 @@ const DataTable = (props: any) => { Right
-
+
{data.map((x: any, i: any) => { return (
{ export const NeurologicalTable = (props: any) => { const { consultationId } = props; - const dispatch: any = useDispatch(); + // const dispatch: any = useDispatch(); const [results, setResults] = useState({}); const [currentPage, setCurrentPage] = useState(1); const [totalCount, setTotalCount] = useState(0); @@ -95,11 +99,10 @@ export const NeurologicalTable = (props: any) => { const LOC_OPTIONS = [ { id: 0, value: "Unknown" }, { id: 5, value: "Alert" }, - { id: 10, value: "Responds to Voice" }, - { id: 15, value: "Responds to Pain" }, - { id: 20, value: "Unresponsive" }, - { id: 25, value: "Agitated or Confused" }, - { id: 30, value: "Onset of Agitation and Confusion" }, + { id: 10, value: "Drowsy" }, + { id: 15, value: "Stuporous" }, + { id: 20, value: "Comatose" }, + { id: 25, value: "Cannot Be Assessed" }, ]; const REACTION_OPTIONS = [ @@ -120,52 +123,47 @@ export const NeurologicalTable = (props: any) => { { id: 30, value: "None" }, ]; - const fetchDailyRounds = useCallback( - async (status: statusType) => { - const res = await dispatch( - dailyRoundsAnalyse( - { - page: currentPage, - fields: [ - "consciousness_level", - "consciousness_level_detail", - "left_pupil_size", - "left_pupil_size_detail", - "right_pupil_size", - "right_pupil_size_detail", - "left_pupil_light_reaction", - "left_pupil_light_reaction_detail", - "right_pupil_light_reaction", - "right_pupil_light_reaction_detail", - "limb_response_upper_extremity_right", - "limb_response_upper_extremity_left", - "limb_response_lower_extremity_left", - "limb_response_lower_extremity_right", - "glasgow_eye_open", - "glasgow_verbal_response", - "glasgow_motor_response", - "glasgow_total_calculated", - ], - }, - { consultationId } - ) - ); - if (!status.aborted) { - if (res && res.data && res.data.results) { - setResults(res.data.results); - setTotalCount(res.data.count); - } - } - }, - [consultationId, dispatch, currentPage] - ); + useEffect(() => { + const fetchDailyRounds = async ( + currentPage: number, + consultationId: string + ) => { + const { res, data } = await request(routes.dailyRoundsAnalyse, { + body: { + page: currentPage, + fields: [ + "consciousness_level", + "consciousness_level_detail", + "left_pupil_size", + "left_pupil_size_detail", + "right_pupil_size", + "right_pupil_size_detail", + "left_pupil_light_reaction", + "left_pupil_light_reaction_detail", + "right_pupil_light_reaction", + "right_pupil_light_reaction_detail", + "limb_response_upper_extremity_right", + "limb_response_upper_extremity_left", + "limb_response_lower_extremity_left", + "limb_response_lower_extremity_right", + "glasgow_eye_open", + "glasgow_verbal_response", + "glasgow_motor_response", + "glasgow_total_calculated", + ], + }, + pathParams: { + consultationId, + }, + }); - useAbortableEffect( - (status: statusType) => { - fetchDailyRounds(status); - }, - [currentPage] - ); + if (res && res.ok && data?.results) { + setResults(data.results); + setTotalCount(data.count); + } + }; + fetchDailyRounds(currentPage, consultationId); + }, [currentPage, consultationId]); // eslint-disable-next-line @typescript-eslint/no-unused-vars const handlePagination = (page: number, limit: number) => { @@ -295,13 +293,16 @@ export const NeurologicalTable = (props: any) => {
Level Of Consciousness
-
+
{locData.map((x: any, i: any) => (
-
+
{x.date}
@@ -371,7 +372,10 @@ export const NeurologicalTable = (props: any) => { Total
-
+
{glasgowData.map((x: any, i: any) => { return (
{ 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: ["nursing"], - }, - { consultationId } - ) - ); - if (!status.aborted) { - if (res?.data) { - setResults(res.data.results); - setTotalCount(res.data.count); - } + useEffect(() => { + const fetchDailyRounds = async ( + currentPage: number, + consultationId: string + ) => { + const { res, data } = await request(routes.dailyRoundsAnalyse, { + body: { + page: currentPage, + fields: ["nursing"], + }, + pathParams: { + consultationId, + }, + }); + if (res && res.ok && data) { + setResults(data.results); + setTotalCount(data.count); } - }, - [consultationId, dispatch, currentPage] - ); + }; - useAbortableEffect( - (status: statusType) => { - fetchDailyRounds(status); - }, - [currentPage] - ); + fetchDailyRounds(currentPage, consultationId); + }, [consultationId, currentPage]); const handlePagination = (page: number) => { setCurrentPage(page); diff --git a/src/Components/Facility/Consultations/NutritionPlots.tsx b/src/Components/Facility/Consultations/NutritionPlots.tsx index 07dd6422555..93d7ba09010 100644 --- a/src/Components/Facility/Consultations/NutritionPlots.tsx +++ b/src/Components/Facility/Consultations/NutritionPlots.tsx @@ -1,7 +1,7 @@ -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 { StackedLinePlot } from "./components/StackedLinePlot"; import Pagination from "../../Common/Pagination"; @@ -11,7 +11,6 @@ import CareIcon from "../../../CAREUI/icons/CareIcon"; export const NutritionPlots = (props: any) => { const { consultationId } = props; - const dispatch: any = useDispatch(); const [results, setResults] = useState({}); const [showIO, setShowIO] = useState(true); const [showIntake, setShowIntake] = useState(false); @@ -19,40 +18,35 @@ export const NutritionPlots = (props: any) => { const [currentPage, setCurrentPage] = useState(1); const [totalCount, setTotalCount] = useState(0); - const fetchDailyRounds = useCallback( - async (status: statusType) => { - const res = await dispatch( - dailyRoundsAnalyse( - { - page: currentPage, - fields: [ - "infusions", - "iv_fluids", - "feeds", - "total_intake_calculated", - "total_output_calculated", - "output", - ], - }, - { consultationId } - ) - ); - if (!status.aborted) { - if (res && res.data) { - setResults(res.data.results); - setTotalCount(res.data.count); - } + useEffect(() => { + const fetchDailyRounds = async ( + currentPage: number, + consultationId: string + ) => { + const { res, data } = await request(routes.dailyRoundsAnalyse, { + body: { + page: currentPage, + fields: [ + "infusions", + "iv_fluids", + "feeds", + "total_intake_calculated", + "total_output_calculated", + "output", + ], + }, + pathParams: { + consultationId, + }, + }); + if (res && res.ok && data) { + setResults(data.results); + setTotalCount(data.count); } - }, - [consultationId, dispatch, currentPage] - ); + }; - useAbortableEffect( - (status: statusType) => { - fetchDailyRounds(status); - }, - [currentPage] - ); + fetchDailyRounds(currentPage, consultationId); + }, [consultationId, currentPage]); const handlePagination = (page: number) => { setCurrentPage(page); diff --git a/src/Components/Facility/Consultations/PainDiagrams.tsx b/src/Components/Facility/Consultations/PainDiagrams.tsx index afb070ba14a..183fd6066b3 100644 --- a/src/Components/Facility/Consultations/PainDiagrams.tsx +++ b/src/Components/Facility/Consultations/PainDiagrams.tsx @@ -1,13 +1,13 @@ -import { useCallback, useState, useEffect } 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"; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore import { make as CriticalCare__PainViewer } from "../../CriticalCareRecording/Pain/CriticalCare__PainViewer.bs"; import { formatDateTime } from "../../../Utils/utils"; export const PainDiagrams = (props: any) => { const { consultationId } = props; - const dispatch: any = useDispatch(); const [isLoading, setIsLoading] = useState(false); const [results, setResults] = useState({}); const [selectedData, setData] = useState({ @@ -15,48 +15,47 @@ export const PainDiagrams = (props: any) => { id: "", }); - const fetchDailyRounds = useCallback( - async (status: statusType) => { + useEffect(() => { + const fetchDailyRounds = async (consultationId: string) => { setIsLoading(true); - const res = await dispatch( - dailyRoundsAnalyse( - { + const { res, data: dailyRound } = await request( + routes.dailyRoundsAnalyse, + { + body: { fields: ["pain_scale_enhanced"], }, - { consultationId } - ) + pathParams: { + consultationId, + }, + } ); - if (!status.aborted) { - if (res && res.data) { - const keys = Object.keys(res.data.results || {}).filter( - (key) => res.data.results[key].pain_scale_enhanced.length - ); - const data: any = {}; - keys.forEach((key) => (data[key] = res.data.results[key])); + if (res && res.ok && dailyRound?.results) { + const keys = Object.keys(dailyRound.results || {}).filter( + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + (key) => dailyRound.results[key].pain_scale_enhanced.length + ); + const data: any = {}; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + keys.forEach((key) => (data[key] = dailyRound.results[key])); - setResults(data); - if (keys.length > 0) { - setSelectedDateData(data, keys[0]); - } + setResults(data); + if (keys.length > 0) { + setSelectedDateData(data, keys[0]); } - setIsLoading(false); } - }, - [consultationId, dispatch] - ); + setIsLoading(false); + }; + + fetchDailyRounds(consultationId); + }, [consultationId]); useEffect(() => { if (Object.keys(results).length > 0) setSelectedDateData(results, Object.keys(results)[0]); }, [results]); - useAbortableEffect( - (status: statusType) => { - fetchDailyRounds(status); - }, - [consultationId] - ); - useEffect(() => { if (Object.keys(results).length > 0) setSelectedDateData(results, Object.keys(results)[0]); diff --git a/src/Components/Facility/Consultations/PressureSoreDiagrams.tsx b/src/Components/Facility/Consultations/PressureSoreDiagrams.tsx index 84be0fc827a..cec4b9dae4c 100644 --- a/src/Components/Facility/Consultations/PressureSoreDiagrams.tsx +++ b/src/Components/Facility/Consultations/PressureSoreDiagrams.tsx @@ -1,15 +1,16 @@ -import { useCallback, useState, useEffect } 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"; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore import { make as CriticalCare__PressureScoreViewer } from "../../CriticalCareRecording/PressureSore/CriticalCare__PressureSoreViewer.bs"; import Pagination from "../../Common/Pagination"; import { PAGINATION_LIMIT } from "../../../Common/constants"; + import { formatDateTime } from "../../../Utils/utils"; export const PressureSoreDiagrams = (props: any) => { const { consultationId } = props; - const dispatch: any = useDispatch(); const [isLoading, setIsLoading] = useState(false); const [results, setResults] = useState({}); const [selectedData, setData] = useState({ @@ -19,49 +20,51 @@ export const PressureSoreDiagrams = (props: any) => { const [currentPage, setCurrentPage] = useState(1); const [totalCount, _setTotalCount] = useState(0); - const fetchDailyRounds = useCallback( - async (status: statusType) => { + useEffect(() => { + const fetchDailyRounds = async ( + currentPage: number, + consultationId: string + ) => { setIsLoading(true); - const res = await dispatch( - dailyRoundsAnalyse( - { + const { res, data: dailyRounds } = await request( + routes.dailyRoundsAnalyse, + { + body: { page: currentPage, fields: ["pressure_sore"], }, - { consultationId } - ) + pathParams: { + consultationId, + }, + } ); - if (!status.aborted) { - if (res && res.data) { - const keys = Object.keys(res.data.results || {}).filter( - (key) => res.data.results[key].pressure_sore.length - ); - const data: any = {}; - keys.forEach((key) => (data[key] = res.data.results[key])); + if (res && res.ok && dailyRounds) { + const keys = Object.keys(dailyRounds.results || {}).filter( + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + (key) => dailyRounds.results[key].pressure_sore.length + ); + const data: any = {}; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + keys.forEach((key) => (data[key] = dailyRounds.results[key])); - setResults(data); - if (keys.length > 0) { - setSelectedDateData(data, keys[0]); - } + setResults(data); + if (keys.length > 0) { + setSelectedDateData(data, keys[0]); } - setIsLoading(false); } - }, - [consultationId, dispatch, currentPage] - ); + setIsLoading(false); + }; + + fetchDailyRounds(currentPage, consultationId); + }, [consultationId, currentPage]); useEffect(() => { if (Object.keys(results).length > 0) setSelectedDateData(results, Object.keys(results)[0]); }, [results]); - useAbortableEffect( - (status: statusType) => { - fetchDailyRounds(status); - }, - [consultationId, currentPage] - ); - const handlePagination = (page: number, _limit: number) => { setCurrentPage(page); }; diff --git a/src/Components/Facility/Consultations/PrimaryParametersPlot.tsx b/src/Components/Facility/Consultations/PrimaryParametersPlot.tsx index f7d74a024a1..4ff81acf868 100644 --- a/src/Components/Facility/Consultations/PrimaryParametersPlot.tsx +++ b/src/Components/Facility/Consultations/PrimaryParametersPlot.tsx @@ -1,7 +1,6 @@ -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 { StackedLinePlot } from "./components/StackedLinePlot"; import Pagination from "../../Common/Pagination"; @@ -21,50 +20,44 @@ interface PrimaryParametersPlotProps { export const PrimaryParametersPlot = ({ consultationId, }: PrimaryParametersPlotProps) => { - 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: [ - "bp", - "pulse", - "temperature", - "resp", - "blood_sugar_level", - "insulin_intake_frequency", - "insulin_intake_dose", - "ventilator_spo2", - "ventilator_fi02", - "rhythm", - "rhythm_detail", - ], - }, - { consultationId } - ) - ); - if (!status.aborted) { - if (res && res.data) { - setResults(res.data.results); - setTotalCount(res.data.count); - } + useEffect(() => { + const fetchDailyRounds = async ( + currentPage: number, + consultationId: string + ) => { + const { res, data } = await request(routes.dailyRoundsAnalyse, { + body: { + page: currentPage, + fields: [ + "bp", + "pulse", + "temperature", + "resp", + "blood_sugar_level", + "insulin_intake_frequency", + "insulin_intake_dose", + "ventilator_spo2", + "ventilator_fi02", + "rhythm", + "rhythm_detail", + ], + }, + pathParams: { + consultationId, + }, + }); + if (res && res.ok && data) { + setResults(data.results); + setTotalCount(data.count); } - }, - [consultationId, dispatch, currentPage] - ); + }; - useAbortableEffect( - (status: statusType) => { - fetchDailyRounds(status); - }, - [consultationId, currentPage] - ); + fetchDailyRounds(currentPage, consultationId); + }, [consultationId, currentPage]); const handlePagination = (page: number) => { setCurrentPage(page); diff --git a/src/Components/Facility/Consultations/VentilatorPlot.tsx b/src/Components/Facility/Consultations/VentilatorPlot.tsx index c1800823b66..d752358e90d 100644 --- a/src/Components/Facility/Consultations/VentilatorPlot.tsx +++ b/src/Components/Facility/Consultations/VentilatorPlot.tsx @@ -1,7 +1,6 @@ -import { useCallback, useEffect, 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"; @@ -30,52 +29,47 @@ const modality: Array = [ export const VentilatorPlot = (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: [ - "ventilator_pip", - "ventilator_mean_airway_pressure", - "ventilator_resp_rate", - "ventilator_pressure_support", - "ventilator_tidal_volume", - "ventilator_peep", - "ventilator_fi02", - "ventilator_spo2", - "etco2", - "bilateral_air_entry", - "ventilator_oxygen_modality_oxygen_rate", - "ventilator_oxygen_modality_flow_rate", - ], - }, - { consultationId } - ) - ); - if (!status.aborted) { - if (res && res.data) { - console.log(res); - setResults(res.data.results); - setTotalCount(res.data.count); - } + useEffect(() => { + const fetchDailyRounds = async ( + currentPage: number, + consultationId: string + ) => { + const { res, data } = await request(routes.dailyRoundsAnalyse, { + body: { + page: currentPage, + fields: [ + "ventilator_pip", + "ventilator_mean_airway_pressure", + "ventilator_resp_rate", + "ventilator_pressure_support", + "ventilator_tidal_volume", + "ventilator_peep", + "ventilator_fi02", + "ventilator_spo2", + "etco2", + "bilateral_air_entry", + "ventilator_oxygen_modality_oxygen_rate", + "ventilator_oxygen_modality_flow_rate", + ], + }, + pathParams: { + consultationId, + }, + }); + if (res && res.ok && data) { + console.log(res); + console.log(data); + setResults(data.results); + setTotalCount(data.count); } - }, - [consultationId, dispatch, currentPage] - ); + }; - useAbortableEffect( - (status: statusType) => { - fetchDailyRounds(status); - }, - [currentPage] - ); + fetchDailyRounds(currentPage, consultationId); + }, [consultationId, currentPage]); const handlePagination = (page: number) => { setCurrentPage(page); diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index a9861a4869c..78670f32c6f 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -1,7 +1,7 @@ import { AssignedToObjectModel } from "../Patient/models"; import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; -import { AssetData } from "../Assets/AssetTypes"; +import { AssetBedModel, AssetData } from "../Assets/AssetTypes"; import { UserBareMinimum } from "../Users/models"; export interface LocalBodyModel { @@ -10,21 +10,25 @@ export interface LocalBodyModel { localbody_code: string; district: number; } + export interface DistrictModel { id: number; name: string; state: number; } + export interface StateModel { id: number; name: string; } + export interface WardModel { id: number; name: string; number: number; local_body: number; } + export interface FacilityModel { id?: number; name?: string; @@ -147,6 +151,7 @@ export interface ConsultationModel { death_confirmed_doctor?: string; is_readmission?: boolean; } + export interface PatientStatsModel { id?: number; entryDate?: string; @@ -222,6 +227,230 @@ export interface CurrentBed { meta: Record; } +export type ABGPlotsFields = + | "ph" + | "pco2" + | "po2" + | "hco3" + | "base_excess" + | "lactate" + | "sodium" + | "potassium" + | "ventilator_fi02"; + +export type ABGPlotsRes = { + ph: string; + pco2: number; + po2: number; + hco3: string; + base_excess: number; + lactate: string; + sodium: string; + potassium: string; + ventilator_fi02: number; +}; + +export type DialysisPlotsFields = + | "dialysis_fluid_balance" + | "dialysis_net_balance"; + +export type DialysisPlotsRes = { + dialysis_fluid_balance: number; + dialysis_net_balance: number; +}; + +export type NeurologicalTablesFields = + | "consciousness_level" + | "consciousness_level_detail" + | "left_pupil_size" + | "left_pupil_size_detail" + | "right_pupil_size" + | "right_pupil_size_detail" + | "left_pupil_light_reaction" + | "left_pupil_light_reaction_detail" + | "right_pupil_light_reaction" + | "right_pupil_light_reaction_detail" + | "limb_response_upper_extremity_right" + | "limb_response_upper_extremity_left" + | "limb_response_lower_extremity_left" + | "limb_response_lower_extremity_right" + | "glasgow_eye_open" + | "glasgow_verbal_response" + | "glasgow_motor_response" + | "glasgow_total_calculated"; + +export type NeurologicalTablesRes = { + consciousness_level: number; + consciousness_level_detail: string; + left_pupil_size: number; + left_pupil_size_detail: string; + right_pupil_size: number; + right_pupil_size_detail: string; + left_pupil_light_reaction: number; + left_pupil_light_reaction_detail: string; + right_pupil_light_reaction: number; + right_pupil_light_reaction_detail: string; + limb_response_upper_extremity_right: number; + limb_response_upper_extremity_left: number; + limb_response_lower_extremity_left: number; + limb_response_lower_extremity_right: number; + glasgow_eye_open: number; + glasgow_verbal_response: number; + glasgow_motor_response: number; + glasgow_total_calculated: number; +}; + +export type NursingPlotFields = "nursing"; + +export type NursingPlotRes = { + nursing: [any]; +}; + +export type NutritionPlotsFields = + | "infusions" + | "iv_fluids" + | "feeds" + | "total_intake_calculated" + | "total_output_calculated" + | "output"; + +export type NutritionPlotsRes = { + infusions: [any]; + iv_fluids: [any]; + feeds: [any]; + total_intake_calculated: string; + total_output_calculated: string; + output: [any]; +}; + +export type PainDiagramsFields = "pain_scale_enhanced"; + +export type PainDiagramsRes = { + pain_scale_enhanced: [any]; +}; + +export type PressureSoreDiagramsFields = "pressure_sore"; + +export type PressureSoreDiagramsRes = { + pressure_sore: [any]; +}; + +export type PrimaryParametersPlotFields = + | "bp" + | "pulse" + | "temperature" + | "resp" + | "blood_sugar_level" + | "insulin_intake_frequency" + | "insulin_intake_dose" + | "ventilator_spo2" + | "ventilator_fi02" + | "rhythm" + | "rhythm_detail"; + +export type PrimaryParametersPlotRes = { + bp: { + mean?: number; + systolic?: number; + diastolic?: number; + }; + pulse: number; + temperature: string; + resp: number; + blood_sugar_level: number; + insulin_intake_frequency: number; + insulin_intake_dose: string; + ventilator_spo2: number; + ventilator_fi02: number; + rhythm: number; + rhythm_detail: string; +}; + +export type VentilatorPlotFields = + | "ventilator_pip" + | "ventilator_mean_airway_pressure" + | "ventilator_resp_rate" + | "ventilator_pressure_support" + | "ventilator_tidal_volume" + | "ventilator_peep" + | "ventilator_fi02" + | "ventilator_spo2" + | "etco2" + | "bilateral_air_entry" + | "ventilator_oxygen_modality_oxygen_rate" + | "ventilator_oxygen_modality_flow_rate"; + +export type VentilatorPlotRes = { + ventilator_pip: number; + ventilator_mean_airway_pressure: number; + ventilator_resp_rate: number; + ventilator_pressure_support: number; + ventilator_tidal_volume: number; + ventilator_peep: string; + ventilator_fi02: number; + ventilator_spo2: number; + etco2: number; + bilateral_air_entry: boolean; + ventilator_oxygen_modality_oxygen_rate: number; + ventilator_oxygen_modality_flow_rate: number; +}; + +export interface DailyRoundsBody { + page?: number; + fields: + | ABGPlotsFields[] + | DialysisPlotsFields[] + | NeurologicalTablesFields[] + | NursingPlotFields[] + | NutritionPlotsFields[] + | PainDiagramsFields[] + | PressureSoreDiagramsFields[] + | PrimaryParametersPlotFields[] + | VentilatorPlotFields[]; +} + +export interface DailyRoundsRes { + count: number; + page_size: number; + results: + | ABGPlotsRes + | DialysisPlotsRes + | NeurologicalTablesRes + | NursingPlotRes + | NutritionPlotsRes + | PainDiagramsRes + | PressureSoreDiagramsRes + | PrimaryParametersPlotRes + | VentilatorPlotRes; +} + +export interface GetBedsRes { + count: number; + results: CurrentBed[]; +} + +export interface CreateBedBody { + start_date: string; + assets: string[]; + consultation: string; + bed: string; +} + +export interface GetDailyReportsBody { + limit: number; + offset: number; + rounds_type: "" | "NORMAL,VENTILATOR,ICU"; +} + +export interface GetAssetBedsData { + count: number; + results: AssetBedModel[]; +} + +export type DeleteAssetBedData = null | { + detail: string; +}; + // Voluntarily made as `type` for it to achieve type-safety when used with // `useAsyncOptions` export type ICD11DiagnosisModel = { diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index d775c970a2d..c392aa083f2 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -28,7 +28,15 @@ import { AssetUpdate, } from "../Components/Assets/AssetTypes"; import { + ConsultationModel, + CreateBedBody, + DailyRoundsBody, + DailyRoundsRes, + DeleteAssetBedData, FacilityModel, + GetAssetBedsData, + GetBedsRes, + GetDailyReportsBody, LocationModel, WardModel, } from "../Components/Facility/models"; @@ -43,6 +51,7 @@ import { import { Prescription } from "../Components/Medicine/models"; import { UserModel } from "../Components/Users/models"; import { PaginatedResponse } from "../Utils/request/types"; +import { DailyRoundsModel } from "../Components/Patient/models"; /** * A fake function that returns an empty object casted to type T @@ -297,6 +306,7 @@ const routes = { getAssetBed: { path: "/api/v1/assetbed/{external_id}/", method: "GET", + TRes: Type(), }, updateAssetBed: { path: "/api/v1/assetbed/{external_id}/", @@ -311,6 +321,7 @@ const routes = { deleteAssetBed: { path: "/api/v1/assetbed/{external_id}/", method: "DELETE", + TRes: Type(), }, operateAsset: { path: "/api/v1/asset/{external_id}/operate_assets/", @@ -350,10 +361,13 @@ const routes = { listConsultationBeds: { path: "/api/v1/consultationbed/", method: "GET", + TRes: Type(), }, createConsultationBed: { path: "/api/v1/consultationbed/", method: "POST", + TBody: Type(), + TRes: Type(), }, getConsultationBed: { path: "/api/v1/consultationbed/{external_id}/", @@ -401,6 +415,8 @@ const routes = { }, getConsultation: { path: "/api/v1/consultation/{id}/", + method: "GET", + TRes: Type(), }, updateConsultation: { path: "/api/v1/consultation/{id}/", @@ -428,6 +444,9 @@ const routes = { }, getDailyReports: { path: "/api/v1/consultation/{consultationId}/daily_rounds/", + method: "GET", + TBody: Type(), + TRes: Type>(), }, getDailyReport: { @@ -436,6 +455,8 @@ const routes = { dailyRoundsAnalyse: { path: "/api/v1/consultation/{consultationId}/daily_rounds/analyse/", method: "POST", + TBody: Type(), + TRes: Type>(), }, // Hospital Beds From 2aeaad27e4f65312c474d6d8c7df4d452ab3af3c Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Mon, 6 Nov 2023 18:57:24 +0530 Subject: [PATCH 4/9] change components based on suggestions --- .../Facility/Consultations/Beds.tsx | 41 ++++++-------- .../Facility/Consultations/Feed.tsx | 13 +++-- .../Facility/Consultations/LiveFeed.tsx | 31 +++++------ .../Consultations/NeurologicalTables.tsx | 15 ++---- .../Consultations/PressureSoreDiagrams.tsx | 11 ++-- .../Facility/Consultations/VentilatorPlot.tsx | 2 - src/Components/Facility/models.tsx | 53 +++++++------------ src/Redux/api.tsx | 14 +++-- 8 files changed, 68 insertions(+), 112 deletions(-) diff --git a/src/Components/Facility/Consultations/Beds.tsx b/src/Components/Facility/Consultations/Beds.tsx index 8d08b92d370..518121e6e69 100644 --- a/src/Components/Facility/Consultations/Beds.tsx +++ b/src/Components/Facility/Consultations/Beds.tsx @@ -1,7 +1,7 @@ import * as Notification from "../../../Utils/Notifications.js"; import { BedModel, CurrentBed } from "../models"; -import { Dispatch, SetStateAction, useEffect, useState } from "react"; +import { Dispatch, SetStateAction, useState } from "react"; import routes from "../../../Redux/api"; import request from "../../../Utils/request/request"; import useQuery from "../../../Utils/request/useQuery"; @@ -44,35 +44,24 @@ const Beds = (props: BedsProps) => { ); const [assets, setAssets] = useState([]); const [consultationBeds, setConsultationBeds] = useState([]); - const [isLoading, setIsLoading] = useState(false); const [key, setKey] = useState(0); const [showBedDetails, setShowBedDetails] = useState(null); - const { - res, - data: bedData, - refetch, - } = useQuery(routes.listConsultationBeds, { - pathParams: { consultation: consultationId }, + const { loading } = useQuery(routes.listConsultationBeds, { + query: { consultation: consultationId }, + onResponse: ({ res, data }) => { + if (res && res.status === 200 && data?.results) { + setConsultationBeds(data.results); + setBed(data?.results[0]?.bed_object || {}); + setAssets(data?.results[0]?.assets_objects || []); + } else { + Notification.Error({ + msg: "Something went wrong..!", + }); + } + }, }); - 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(); @@ -100,7 +89,7 @@ const Beds = (props: BedsProps) => { } }; - if (isLoading) { + if (loading) { if (props.smallLoader && props.smallLoader === true) { return (
diff --git a/src/Components/Facility/Consultations/Feed.tsx b/src/Components/Facility/Consultations/Feed.tsx index 02874aed8f1..34f599278b1 100644 --- a/src/Components/Facility/Consultations/Feed.tsx +++ b/src/Components/Facility/Consultations/Feed.tsx @@ -15,7 +15,6 @@ import { PTZState, useFeedPTZ } from "../../../Common/hooks/useFeedPTZ"; import { useEffect, useRef, useState } from "react"; import CareIcon from "../../../CAREUI/icons/CareIcon.js"; -import { ConsultationModel } from "../models"; import FeedButton from "./FeedButton"; import Loading from "../../Common/Loading"; import ReactPlayer from "react-player"; @@ -45,7 +44,6 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { id: "", accessKey: "", }); - const [cameraMiddlewareHostname, setCameraMiddlewareHostname] = useState(""); const [cameraConfig, setCameraConfig] = useState({}); const [bedPresets, setBedPresets] = useState([]); const [bed, setBed] = useState(); @@ -56,11 +54,13 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { const [statusReported, setStatusReported] = useState(false); const authUser = useAuthUser(); + let cameraMiddlewareHostname = ""; + useQuery(routes.getPermittedFacility, { pathParams: { id: facilityId || "" }, onResponse: ({ res, data }) => { if (res && res.status === 200 && data && data.middleware_address) { - setCameraMiddlewareHostname(data.middleware_address); + cameraMiddlewareHostname = data.middleware_address; } }, }); @@ -93,8 +93,7 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { pathParams: { id: consultationId }, onResponse: ({ res, data }) => { if (res && res.status === 200 && data) { - const consultation = data as ConsultationModel; - const consultationBedId = consultation.current_bed?.bed_object?.id; + const consultationBedId = data.current_bed?.bed_object?.id; if (consultationBedId) { (async () => { const { res: listAssetBedsRes, data: listAssetBedsData } = @@ -339,7 +338,7 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { onSuccess: async (data) => { if (currentPreset?.asset_object?.id && data?.position) { setLoading(option.loadingLabel); - const { res, data: ResponseData } = await request( + const { res, data: assetBedData } = await request( routes.partialUpdateAssetBed, { body: { @@ -353,7 +352,7 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { pathParams: { id: currentPreset?.id }, } ); - if (res && ResponseData && res.status === 200) { + if (res && assetBedData && res.status === 200) { Notification.Success({ msg: "Preset Updated" }); await getBedPresets(cameraAsset?.id); getPresets({}); diff --git a/src/Components/Facility/Consultations/LiveFeed.tsx b/src/Components/Facility/Consultations/LiveFeed.tsx index 38fd8d60cb3..3953a9f8e81 100644 --- a/src/Components/Facility/Consultations/LiveFeed.tsx +++ b/src/Components/Facility/Consultations/LiveFeed.tsx @@ -109,7 +109,7 @@ const LiveFeed = (props: any) => { }; const getBedPresets = async (id: any) => { - const { data } = await request(routes.getAssetBed, { + const { data } = await request(routes.listAssetBeds, { pathParams: { asset: id }, body: { limit: page.limit, @@ -143,7 +143,7 @@ const LiveFeed = (props: any) => { bed_id: bed.id, preset_name: preset, }; - const { res: responseRes } = await request(routes.partialUpdateAssetBed, { + const { res } = await request(routes.partialUpdateAssetBed, { pathParams: { id: currentPreset.id }, body: { asset: currentPreset.asset_object.id, @@ -154,7 +154,7 @@ const LiveFeed = (props: any) => { }, }, }); - if (responseRes && responseRes.status === 200) { + if (res && res.status === 200) { Notification.Success({ msg: "Preset Updated" }); } else { Notification.Error({ msg: "Something Went Wrong" }); @@ -248,22 +248,19 @@ const LiveFeed = (props: any) => { if (currentPreset?.asset_object?.id && data?.position) { setLoading(option.loadingLabel); console.log("Updating Preset"); - const { res: responseRes } = await request( - routes.partialUpdateAssetBed, - { - pathParams: { id: currentPreset.id }, - body: { - asset: currentPreset.asset_object.id, - bed: currentPreset.bed_object.id, - meta: { - ...currentPreset.meta, - position: data?.position, - }, + const { res } = await request(routes.partialUpdateAssetBed, { + pathParams: { id: currentPreset.id }, + body: { + asset: currentPreset.asset_object.id, + bed: currentPreset.bed_object.id, + meta: { + ...currentPreset.meta, + position: data?.position, }, - } - ); + }, + }); - if (responseRes && responseRes.status === 200) { + if (res && res.status === 200) { Notification.Success({ msg: "Preset Updated" }); getBedPresets(cameraAsset?.id); fetchCameraPresets(); diff --git a/src/Components/Facility/Consultations/NeurologicalTables.tsx b/src/Components/Facility/Consultations/NeurologicalTables.tsx index c39207d8ce3..cb3eed92144 100644 --- a/src/Components/Facility/Consultations/NeurologicalTables.tsx +++ b/src/Components/Facility/Consultations/NeurologicalTables.tsx @@ -29,10 +29,7 @@ const DataTable = (props: any) => { Right
-
+
{data.map((x: any, i: any) => { return (
{
Level Of Consciousness
-
+
{locData.map((x: any, i: any) => (
{ Total
-
+
{glasgowData.map((x: any, i: any) => { return (
{ const { consultationId } = props; @@ -40,13 +39,11 @@ export const PressureSoreDiagrams = (props: any) => { ); if (res && res.ok && dailyRounds) { const keys = Object.keys(dailyRounds.results || {}).filter( - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - (key) => dailyRounds.results[key].pressure_sore.length + (key) => + (dailyRounds.results[key] as PressureSoreDiagramsRes).pressure_sore + .length ); const data: any = {}; - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore keys.forEach((key) => (data[key] = dailyRounds.results[key])); setResults(data); diff --git a/src/Components/Facility/Consultations/VentilatorPlot.tsx b/src/Components/Facility/Consultations/VentilatorPlot.tsx index d752358e90d..9dfe0ce8a1e 100644 --- a/src/Components/Facility/Consultations/VentilatorPlot.tsx +++ b/src/Components/Facility/Consultations/VentilatorPlot.tsx @@ -61,8 +61,6 @@ export const VentilatorPlot = (props: any) => { }, }); if (res && res.ok && data) { - console.log(res); - console.log(data); setResults(data.results); setTotalCount(data.count); } diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index ce2def8a92a..dad533815b7 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -1,7 +1,7 @@ import { AssignedToObjectModel } from "../Patient/models"; import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; -import { AssetBedModel, AssetData } from "../Assets/AssetTypes"; +import { AssetData } from "../Assets/AssetTypes"; import { UserBareMinimum } from "../Users/models"; export interface LocalBodyModel { @@ -304,7 +304,7 @@ export type NeurologicalTablesRes = { export type NursingPlotFields = "nursing"; export type NursingPlotRes = { - nursing: [any]; + nursing: any[]; }; export type NutritionPlotsFields = @@ -316,24 +316,24 @@ export type NutritionPlotsFields = | "output"; export type NutritionPlotsRes = { - infusions: [any]; - iv_fluids: [any]; - feeds: [any]; + infusions: any[]; + iv_fluids: any[]; + feeds: any[]; total_intake_calculated: string; total_output_calculated: string; - output: [any]; + output: any[]; }; export type PainDiagramsFields = "pain_scale_enhanced"; export type PainDiagramsRes = { - pain_scale_enhanced: [any]; + pain_scale_enhanced: any[]; }; export type PressureSoreDiagramsFields = "pressure_sore"; export type PressureSoreDiagramsRes = { - pressure_sore: [any]; + pressure_sore: any[]; }; export type PrimaryParametersPlotFields = @@ -413,16 +413,18 @@ export interface DailyRoundsBody { export interface DailyRoundsRes { count: number; page_size: number; - results: - | ABGPlotsRes - | DialysisPlotsRes - | NeurologicalTablesRes - | NursingPlotRes - | NutritionPlotsRes - | PainDiagramsRes - | PressureSoreDiagramsRes - | PrimaryParametersPlotRes - | VentilatorPlotRes; + results: { + [date: string]: + | PressureSoreDiagramsRes + | ABGPlotsRes + | DialysisPlotsRes + | NeurologicalTablesRes + | NursingPlotRes + | NutritionPlotsRes + | PainDiagramsRes + | PrimaryParametersPlotRes + | VentilatorPlotRes; + }; } export interface GetBedsRes { @@ -437,21 +439,6 @@ export interface CreateBedBody { bed: string; } -export interface GetDailyReportsBody { - limit: number; - offset: number; - rounds_type: "" | "NORMAL,VENTILATOR,ICU"; -} - -export interface GetAssetBedsData { - count: number; - results: AssetBedModel[]; -} - -export type DeleteAssetBedData = null | { - detail: string; -}; - // Voluntarily made as `type` for it to achieve type-safety when used with // `useAsyncOptions` export type ICD11DiagnosisModel = { diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index aa788c8b10f..2817d5a6775 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -32,11 +32,8 @@ import { CreateBedBody, DailyRoundsBody, DailyRoundsRes, - DeleteAssetBedData, FacilityModel, - GetAssetBedsData, GetBedsRes, - GetDailyReportsBody, LocationModel, WardModel, } from "../Components/Facility/models"; @@ -318,7 +315,7 @@ const routes = { getAssetBed: { path: "/api/v1/assetbed/{external_id}/", method: "GET", - TRes: Type(), + TRes: Type>(), }, updateAssetBed: { path: "/api/v1/assetbed/{external_id}/", @@ -333,7 +330,9 @@ const routes = { deleteAssetBed: { path: "/api/v1/assetbed/{external_id}/", method: "DELETE", - TRes: Type(), + TRes: Type(), }, operateAsset: { path: "/api/v1/asset/{external_id}/operate_assets/", @@ -459,8 +458,7 @@ const routes = { getDailyReports: { path: "/api/v1/consultation/{consultationId}/daily_rounds/", method: "GET", - TBody: Type(), - TRes: Type>(), + TRes: Type>(), }, getDailyReport: { @@ -470,7 +468,7 @@ const routes = { path: "/api/v1/consultation/{consultationId}/daily_rounds/analyse/", method: "POST", TBody: Type(), - TRes: Type>(), + TRes: Type(), }, // Hospital Beds From 4c9c27a87b2d5a25471976d0e68c967f195bc6cf Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Mon, 6 Nov 2023 19:05:25 +0530 Subject: [PATCH 5/9] change api model to paginated api --- src/Components/Facility/models.tsx | 5 ----- src/Redux/api.tsx | 6 +++--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index dad533815b7..c19d920f644 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -427,11 +427,6 @@ export interface DailyRoundsRes { }; } -export interface GetBedsRes { - count: number; - results: CurrentBed[]; -} - export interface CreateBedBody { start_date: string; assets: string[]; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 2817d5a6775..6525219c8d1 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -30,10 +30,10 @@ import { import { ConsultationModel, CreateBedBody, + CurrentBed, DailyRoundsBody, DailyRoundsRes, FacilityModel, - GetBedsRes, LocationModel, WardModel, } from "../Components/Facility/models"; @@ -372,13 +372,13 @@ const routes = { listConsultationBeds: { path: "/api/v1/consultationbed/", method: "GET", - TRes: Type(), + TRes: Type>(), }, createConsultationBed: { path: "/api/v1/consultationbed/", method: "POST", TBody: Type(), - TRes: Type(), + TRes: Type>(), }, getConsultationBed: { path: "/api/v1/consultationbed/{external_id}/", From 70fca2fb166bd502582cf05b99e355123e227b56 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Thu, 9 Nov 2023 21:23:07 +0530 Subject: [PATCH 6/9] resolve merge conflict --- .../Consultations/DailyRoundsList.tsx | 2 +- .../Facility/Consultations/Feed.tsx | 29 ++++++++++++------- src/Redux/api.tsx | 1 - 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Components/Facility/Consultations/DailyRoundsList.tsx b/src/Components/Facility/Consultations/DailyRoundsList.tsx index c5daae95958..bcd3270220e 100644 --- a/src/Components/Facility/Consultations/DailyRoundsList.tsx +++ b/src/Components/Facility/Consultations/DailyRoundsList.tsx @@ -24,7 +24,7 @@ export const DailyRoundsList = (props: any) => { rounds_type: showAutomatedRounds ? "" : "NORMAL,VENTILATOR,ICU", }} > - {() => ( + {(_) => (
diff --git a/src/Components/Facility/Consultations/Feed.tsx b/src/Components/Facility/Consultations/Feed.tsx index e2e6eb2ea87..ffacb4af04d 100644 --- a/src/Components/Facility/Consultations/Feed.tsx +++ b/src/Components/Facility/Consultations/Feed.tsx @@ -26,7 +26,7 @@ import useFullscreen from "../../../Common/hooks/useFullscreen.js"; import { triggerGoal } from "../../../Integrations/Plausible.js"; import useAuthUser from "../../../Common/hooks/useAuthUser.js"; import Spinner from "../../Common/Spinner.js"; -import useQuery from "../../../Utils/request/useQuery"; +import useQuery from "../../../Utils/request/useQuery.js"; interface IFeedProps { facilityId: string; @@ -46,6 +46,7 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { middleware_address: "", location_middleware: "", }); + const [cameraConfig, setCameraConfig] = useState({}); const [bedPresets, setBedPresets] = useState([]); const [bed, setBed] = useState(); @@ -56,15 +57,13 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { const [statusReported, setStatusReported] = useState(false); const authUser = useAuthUser(); - let cameraMiddlewareHostname = ""; - + let facilityMiddlewareHostname = ""; useQuery(routes.getPermittedFacility, { pathParams: { id: facilityId || "" }, onResponse: ({ res, data }) => { if (res && res.status === 200 && data && data.middleware_address) { - cameraMiddlewareHostname = data.middleware_address; - + facilityMiddlewareHostname = data.middleware_address; } }, }); @@ -82,7 +81,7 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { precision: precision, }); } - }, [precision, cameraState]); + }, [precision]); useEffect(() => { const timeout = setTimeout(() => { @@ -93,7 +92,7 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { setCamTimeout(0); }, 5000); return () => clearTimeout(timeout); - }, [cameraState, cameraConfig]); + }, [cameraState]); const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent); @@ -107,8 +106,10 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { if (consultationBedId) { (async () => { const { res: listAssetBedsRes, data: listAssetBedsData } = - await request(routes.getAssetBed, { - pathParams: { external_id: consultationBedId }, + await request(routes.listAssetBeds, { + query: { + bed: consultationBedId, + }, }); setBed(consultationBedId); const bedAssets: any = { @@ -128,6 +129,12 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { setCameraAsset({ id: bedAssets.data.results[0].asset_object.id, accessKey: config[2] || "", + middleware_address: + bedAssets.data.results[0].asset_object?.meta + ?.middleware_hostname, + location_middleware: + bedAssets.data.results[0].asset_object.location_object + ?.middleware_address, }); setCameraConfig(bedAssets.data.results[0].meta); setCameraState({ @@ -208,8 +215,8 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { const getBedPresets = async (asset: any) => { if (asset.id && bed) { - const { data: bedAssets } = await request(routes.getAssetBed, { - pathParams: { external_id: asset.id, bed }, + const { data: bedAssets } = await request(routes.listAssetBeds, { + query: { asset: asset.id, bed }, }); setBedPresets(bedAssets?.results); } diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 6525219c8d1..4f7b70f2c96 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -315,7 +315,6 @@ const routes = { getAssetBed: { path: "/api/v1/assetbed/{external_id}/", method: "GET", - TRes: Type>(), }, updateAssetBed: { path: "/api/v1/assetbed/{external_id}/", From 9c2fdf3e7caed6cfe17570d32f66929220a28c95 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Thu, 9 Nov 2023 21:29:58 +0530 Subject: [PATCH 7/9] format code with prettier --- src/Components/Facility/Consultations/Feed.tsx | 1 - src/Components/Facility/models.tsx | 2 -- src/Redux/api.tsx | 11 ++++------- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Components/Facility/Consultations/Feed.tsx b/src/Components/Facility/Consultations/Feed.tsx index 7211e03819b..ffacb4af04d 100644 --- a/src/Components/Facility/Consultations/Feed.tsx +++ b/src/Components/Facility/Consultations/Feed.tsx @@ -104,7 +104,6 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { if (res && res.status === 200 && data) { const consultationBedId = data.current_bed?.bed_object?.id; if (consultationBedId) { - (async () => { const { res: listAssetBedsRes, data: listAssetBedsData } = await request(routes.listAssetBeds, { diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index 353eb89f7a2..fe6c8e3b0d4 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -227,7 +227,6 @@ export interface CurrentBed { meta: Record; } - export type ABGPlotsFields = | "ph" | "pco2" @@ -440,4 +439,3 @@ export type ICD11DiagnosisModel = { id: string; label: string; }; - diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 9797e842c69..8217c3ab14c 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -5,18 +5,18 @@ import { IAadhaarOtpTBody, ICheckAndGenerateMobileOtp, IConfirmMobileOtp, + IcreateHealthFacilityTBody, ICreateHealthIdRequest, ICreateHealthIdResponse, IGenerateMobileOtpTBody, + IgetAbhaCardTBody, IHealthFacility, IHealthId, + IinitiateAbdmAuthenticationTBody, ILinkABHANumber, + IpartialUpdateHealthFacilityTBody, ISearchByHealthIdTBody, IVerifyAadhaarOtpTBody, - IcreateHealthFacilityTBody, - IgetAbhaCardTBody, - IinitiateAbdmAuthenticationTBody, - IpartialUpdateHealthFacilityTBody, } from "../Components/ABDM/models"; import { AssetBedBody, @@ -30,7 +30,6 @@ import { } from "../Components/Assets/AssetTypes"; import { ConsultationModel, - CreateBedBody, CurrentBed, DailyRoundsBody, @@ -1170,7 +1169,6 @@ const routes = { method: "GET", }, - // Prescription endpoints listPrescriptions: { @@ -1214,7 +1212,6 @@ const routes = { TRes: Type>(), }, - // HCX Endpoints listPMJYPackages: { From 1b678ff851142e48004ca57c3ce82b46399fbf1d Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Sun, 12 Nov 2023 18:32:54 +0530 Subject: [PATCH 8/9] fix paginatedlist --- .../Consultations/DailyRoundsList.tsx | 77 +++++++++---------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/src/Components/Facility/Consultations/DailyRoundsList.tsx b/src/Components/Facility/Consultations/DailyRoundsList.tsx index bcd3270220e..26cc6529ec7 100644 --- a/src/Components/Facility/Consultations/DailyRoundsList.tsx +++ b/src/Components/Facility/Consultations/DailyRoundsList.tsx @@ -20,6 +20,9 @@ export const DailyRoundsList = (props: any) => { return ( { ))} - className="my-8 flex grow flex-col gap-3 lg:mx-8"> - {(items) => { - return items.map((itemData, idx) => { - if (itemData.rounds_type === "AUTOMATED") { - return ( - - ); - } + className="my-8 flex grow flex-col gap-3 lg:mx-8"> + {(item) => { + if (item.rounds_type === "AUTOMATED") { return ( - { - if (itemData.rounds_type === "NORMAL") { - navigate( - `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily-rounds/${itemData.id}` - ); - } else { - navigate( - `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily_rounds/${itemData.id}` - ); - } - }} - onUpdateLog={() => { - if (itemData.rounds_type === "NORMAL") { - navigate( - `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily-rounds/${itemData.id}/update` - ); - } else { - navigate( - `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily_rounds/${itemData.id}/update` - ); - } - }} + ); - }); + } + return ( + { + if (item.rounds_type === "NORMAL") { + navigate( + `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily-rounds/${item.id}` + ); + } else { + navigate( + `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily_rounds/${item.id}` + ); + } + }} + onUpdateLog={() => { + if (item.rounds_type === "NORMAL") { + navigate( + `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily-rounds/${item.id}/update` + ); + } else { + navigate( + `/facility/${facilityId}/patient/${patientId}/consultation/${consultationId}/daily_rounds/${item.id}/update` + ); + } + }} + /> + ); }}
From 0c0fb5cd34c331f56e09f95411b830f24261a664 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Mon, 13 Nov 2023 11:58:36 +0530 Subject: [PATCH 9/9] edit previous round --- src/CAREUI/misc/PaginatedList.tsx | 6 +++--- src/Components/Facility/Consultations/DailyRoundsList.tsx | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CAREUI/misc/PaginatedList.tsx b/src/CAREUI/misc/PaginatedList.tsx index 0d2445ffbc9..02ee0e3d90e 100644 --- a/src/CAREUI/misc/PaginatedList.tsx +++ b/src/CAREUI/misc/PaginatedList.tsx @@ -121,7 +121,7 @@ PaginatedList.Refresh = Refresh; interface ItemsProps { className?: string; - children: (item: TItem) => JSX.Element | JSX.Element[]; + children: (item: TItem, items: TItem[]) => JSX.Element | JSX.Element[]; shimmer?: JSX.Element; shimmerCount?: number; } @@ -137,9 +137,9 @@ const Items = (props: ItemsProps) => { {props.shimmer} )) - : items.map((item, index) => ( + : items.map((item, index, items) => (
  • - {props.children(item)} + {props.children(item, items)}
  • ))} diff --git a/src/Components/Facility/Consultations/DailyRoundsList.tsx b/src/Components/Facility/Consultations/DailyRoundsList.tsx index 26cc6529ec7..da4b8201495 100644 --- a/src/Components/Facility/Consultations/DailyRoundsList.tsx +++ b/src/Components/Facility/Consultations/DailyRoundsList.tsx @@ -43,12 +43,12 @@ export const DailyRoundsList = (props: any) => { className="my-8 flex grow flex-col gap-3 lg:mx-8"> - {(item) => { + {(item, items) => { if (item.rounds_type === "AUTOMATED") { return ( ); }