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..9db6348b895 100644 --- a/src/Components/Facility/Consultations/DailyRoundsList.tsx +++ b/src/Components/Facility/Consultations/DailyRoundsList.tsx @@ -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(); @@ -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 @@ -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; 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 75ab72d168c..9b977c2ad31 100644 --- a/src/Components/Facility/Consultations/Feed.tsx +++ b/src/Components/Facility/Consultations/Feed.tsx @@ -11,22 +11,19 @@ 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 { partialUpdateAssetBed } from "../../../Redux/actions"; +import routes from "../../../Redux/api"; +import request from "../../../Utils/request/request"; +import useQuery from "../../../Utils/request/useQuery"; import CareIcon from "../../../CAREUI/icons/CareIcon.js"; import { ConsultationModel } from "../models"; import FeedButton from "./FeedButton"; +import { useDispatch } from "react-redux"; import Loading from "../../Common/Loading"; import ReactPlayer from "react-player"; import { classNames } from "../../../Utils/utils"; -import { useDispatch } from "react-redux"; import { useHLSPLayer } from "../../../Common/hooks/useHLSPlayer"; import useKeyboardShortcut from "use-keyboard-shortcut"; import useFullscreen from "../../../Common/hooks/useFullscreen.js"; @@ -37,12 +34,12 @@ interface IFeedProps { facilityId: string; consultationId: any; } + const PATIENT_DEFAULT_PRESET = "Patient View".trim().toLowerCase(); export const Feed: React.FC = ({ consultationId, facilityId }) => { - const dispatch: any = useDispatch(); - const videoWrapper = useRef(null); + const dispatch: any = useDispatch(); const [cameraAsset, setCameraAsset] = useState({ id: "", @@ -61,15 +58,17 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { useEffect(() => { const fetchFacility = async () => { - const res = await dispatch(getPermittedFacility(facilityId)); + const { res, data } = await request(routes.getPermittedFacility, { + pathParams: { facilityId }, + }); - if (res.status === 200 && res.data) { - setCameraMiddlewareHostname(res.data.middleware_address); + if (res?.status === 200 && data && data.middleware_address) { + setCameraMiddlewareHostname(data.middleware_address); } }; if (facilityId) fetchFacility(); - }, [dispatch, facilityId]); + }, [facilityId]); useEffect(() => { if (cameraState) { @@ -78,7 +77,7 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { precision: precision, }); } - }, [precision]); + }, [precision, cameraState]); useEffect(() => { const timeout = setTimeout(() => { @@ -89,59 +88,66 @@ 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) => { + const { res, data, refetch } = useQuery(routes.getConsultation, { + pathParams: { consultationId }, + }); + + useEffect(() => { + const fetchData = async () => { setIsLoading(true); - const res = await dispatch(getConsultation(consultationId)); - if (!status.aborted && res?.data) { - const consultation = res.data as ConsultationModel; + if (res?.ok && data) { + const consultation = data as ConsultationModel; const consultationBedId = consultation.current_bed?.bed_object?.id; if (consultationBedId) { - let bedAssets = await dispatch( - listAssetBeds({ bed: consultationBedId }) - ); + const { res, data: assetBeds } = await request(routes.listAssetBeds, { + pathParams: { bed: consultationBedId }, + }); setBed(consultationBedId); - bedAssets = { - ...bedAssets, + const bedAssets = { + ...res, 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; - } - ), + ...assetBeds, + results: assetBeds?.results.filter((asset) => { + return ( + (asset?.asset_object?.meta?.asset_type as string) === "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, - }); + 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); + setIsLoading(false); + } } - }, - [consultationId, dispatch] - ); + }; + fetchData(); + }, [consultationId, res, data]); + + useEffect(() => { + refetch(); + }, [refetch, consultationId]); // const [position, setPosition] = useState(); // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -210,8 +216,11 @@ 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 bedAssets = await dispatch(listAssetBeds({ asset: asset.id, bed })); + const { data: bedAssets } = await request(routes.listAssetBeds, { + pathParams: { asset: asset.id, bed }, + }); + setBedPresets(bedAssets?.results); } }; @@ -246,9 +255,9 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { }; }, [startStream, streamStatus]); - useAbortableEffect((status: statusType) => { - fetchData(status); - }, []); + // useAbortableEffect((status: statusType) => { + // fetchData(status); + // }, []); useEffect(() => { if (!currentPreset && streamStatus === StreamStatus.Playing) { diff --git a/src/Components/Facility/Consultations/LiveFeed.tsx b/src/Components/Facility/Consultations/LiveFeed.tsx index c6ba749b471..f3f0dc93a05 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 { useDispatch } from "react-redux"; import useKeyboardShortcut from "use-keyboard-shortcut"; -import { - listAssetBeds, - partialUpdateAssetBed, - deleteAssetBed, -} from "../../../Redux/actions"; +import routes from "../../../Redux/api"; +import request from "../../../Utils/request/request"; import { getCameraPTZ } from "../../../Common/constants"; import { StreamStatus, @@ -101,28 +98,32 @@ const LiveFeed = (props: any) => { }); const getBedPresets = async (id: any) => { - const bedAssets = await dispatch( - listAssetBeds({ + const { data } = await request(routes.listAssetBeds, { + body: { asset: id, limit: page.limit, offset: page.offset, - }) - ); - setBedPresets(bedAssets?.data?.results); + }, + }); + setBedPresets(data?.results); setPage({ ...page, - count: bedAssets?.data?.count, + count: data?.count ? data?.count : 0, }); }; const deletePreset = async (id: any) => { - const res = await dispatch(deleteAssetBed(id)); + const { res, data } = await request(routes.deleteAssetBed, { + pathParams: { + id: 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); @@ -133,20 +134,21 @@ 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 } = await request(routes.partialUpdateAssetBed, { + body: { + asset: currentPreset.asset_object.id, + beds: bed.id ? bed.id : "", + meta: { + ...currentPreset.meta, + ...data, }, - currentPreset?.id - ) - ); - if (response && response.status === 200) { + }, + pathParams: { + id: currentPreset.id, + }, + }); + + if (res && res.status === 200) { Notification.Success({ msg: "Preset Updated" }); } else { Notification.Error({ msg: "Something Went Wrong" }); @@ -239,20 +241,20 @@ const LiveFeed = (props: any) => { if (currentPreset?.asset_object?.id && data?.position) { setLoading(option.loadingLabel); console.log("Updating Preset"); - const response = await dispatch( - partialUpdateAssetBed( - { - asset: currentPreset.asset_object.id, - bed: currentPreset.bed_object.id, - meta: { - ...currentPreset.meta, - position: data?.position, - }, + const { res } = await request(routes.partialUpdateAssetBed, { + body: { + asset: currentPreset.asset_object.id, + beds: currentPreset.bed_object.id, + meta: { + ...currentPreset.meta, + position: data?.position, }, - currentPreset?.id - ) - ); - if (response && response.status === 200) { + }, + pathParams: { + id: currentPreset?.id, + }, + }); + 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 89e9d598604..ce3ba4a15c9 100644 --- a/src/Components/Facility/Consultations/NeurologicalTables.tsx +++ b/src/Components/Facility/Consultations/NeurologicalTables.tsx @@ -1,7 +1,8 @@ -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, @@ -90,7 +91,7 @@ const DataDescription = (props: any) => { 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); @@ -122,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) => { diff --git a/src/Components/Facility/Consultations/NursingPlot.tsx b/src/Components/Facility/Consultations/NursingPlot.tsx index a5d129f68e3..83444b6c50f 100644 --- a/src/Components/Facility/Consultations/NursingPlot.tsx +++ b/src/Components/Facility/Consultations/NursingPlot.tsx @@ -1,48 +1,42 @@ -import { useCallback, useState } from "react"; -import { useDispatch } from "react-redux"; +import { useEffect, useState } from "react"; +import routes from "../../../Redux/api"; +import request from "../../../Utils/request/request"; import { NURSING_CARE_FIELDS, PAGINATION_LIMIT, } from "../../../Common/constants"; -import { statusType, useAbortableEffect } from "../../../Common/utils"; -import { dailyRoundsAnalyse } from "../../../Redux/actions"; + import Pagination from "../../Common/Pagination"; import { formatDateTime } from "../../../Utils/utils"; export const NursingPlot = (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: ["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..a507783fc61 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 { useState, useEffect } 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 de2c6af698a..3cdced3f2b7 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -1,4 +1,4 @@ -import { AssignedToObjectModel } from "../Patient/models"; +import { AssignedToObjectModel, DailyRoundsModel } from "../Patient/models"; import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; import { AssetData } from "../Assets/AssetTypes"; @@ -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; @@ -144,6 +148,7 @@ export interface ConsultationModel { death_confirmed_doctor?: string; is_readmission?: boolean; } + export interface PatientStatsModel { id?: number; entryDate?: string; @@ -218,6 +223,271 @@ 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: { + [key: string]: any; + }; +}; + +export type NutritionPlotsFields = + | "infusions" + | "iv_fluids" + | "feeds" + | "total_intake_calculated" + | "total_output_calculated" + | "output"; + +export type NutritionPlotsRes = { + infusions: { + [key: string]: any; + }; + iv_fluids: { + [key: string]: any; + }; + feeds: { + [key: string]: any; + }; + total_intake_calculated: string; + total_output_calculated: string; + output: { + [key: string]: any; + }; +}; + +export type PainDiagramsFields = "pain_scale_enhanced"; + +export type PainDiagramsRes = { + pain_scale_enhanced: { + [key: string]: any; + }; +}; + +export type PressureSoreDiagramsFields = "pressure_sore"; + +export type PressureSoreDiagramsRes = { + pressure_sore: { + [key: string]: 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: { + [key: string]: any; + }; + 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 { + current_page: number; + fields: + | ABGPlotsFields[] + | DialysisPlotsFields[] + | NeurologicalTablesFields[] + | NursingPlotFields[] + | NutritionPlotsFields[] + | PainDiagramsFields[] + | PressureSoreDiagramsFields[] + | PrimaryParametersPlotFields[] + | VentilatorPlotFields[]; +} + +export interface DailyRoundsRes { + count: 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 GetDailyReportsRes { + count: number; + results: DailyRoundsModel[]; +} + +export interface AssetBedsModel { + id: number; + bed_object: BedModel; + asset_object: AssetData; + created_date: string; + modified_date: string; + meta?: { + [key: string]: any; + }; +} + +export interface GetFeedRes { + count: number; + results: AssetBedsModel[]; +} + +export interface GetFeedBody { + limit?: number; + offset?: number; + asset?: number; +} + +export interface DeleteAssetBedsRes { + detail?: string; +} + +export interface PartialUpdateAssetBedsBody { + asset: string; + beds: string; + meta?: { + [key: string]: any; + }; +} + // Voluntarily made as `type` for it to achieve type-safety when used with // `useAsyncOptions` export type ICD11DiagnosisModel = { diff --git a/src/Redux/actions.tsx b/src/Redux/actions.tsx index 1a5bd7e4fb1..189db8f6ce9 100644 --- a/src/Redux/actions.tsx +++ b/src/Redux/actions.tsx @@ -289,8 +289,7 @@ export const deleteFacilityBed = (external_id: string) => { }; // Consultation Beds -export const listConsultationBeds = (params: object) => - fireRequest("listConsultationBeds", [], params, {}); + export const createConsultationBed = ( params: object, consultation_id: string, @@ -525,9 +524,6 @@ export const getDailyReport = (params: object, pathParam: object) => { export const getConsultationDailyRoundsDetails = (pathParam: object) => { return fireRequest("getDailyReport", [], {}, pathParam); }; -export const dailyRoundsAnalyse = (params: object, pathParam: object) => { - return fireRequest("dailyRoundsAnalyse", [], params, pathParam); -}; // Consultation export const createConsultation = (params: object) => { diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 1aa06c7e1bc..005bc39d03f 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -1,6 +1,21 @@ import { IConfig } from "../Common/hooks/useConfig"; import { AssetData } from "../Components/Assets/AssetTypes"; -import { LocationModel } from "../Components/Facility/models"; +import { + DailyRoundsBody, + DailyRoundsRes, + CreateBedBody, + GetBedsRes, + GetDailyReportsBody, + GetDailyReportsRes, + LocationModel, + FacilityModel, + ConsultationModel, + GetFeedRes, + GetFeedBody, + DeleteAssetBedsRes, + PartialUpdateAssetBedsBody, + AssetBedsModel, +} from "../Components/Facility/models"; import { UserModel } from "../Components/Users/models"; import { PaginatedResponse } from "../Utils/request/types"; @@ -172,6 +187,8 @@ const routes = { getPermittedFacility: { path: "/api/v1/facility/{id}/", + method: "GET", + TRes: Type(), }, getAnyFacility: { @@ -223,6 +240,8 @@ const routes = { listAssetBeds: { path: "/api/v1/assetbed/", method: "GET", + TRes: Type(), + TBody: Type(), }, createAssetBed: { path: "/api/v1/assetbed/", @@ -239,10 +258,13 @@ const routes = { partialUpdateAssetBed: { path: "/api/v1/assetbed/{external_id}/", method: "PATCH", + TBody: Type(), + TRes: Type(), }, deleteAssetBed: { path: "/api/v1/assetbed/{external_id}/", method: "DELETE", + TRes: Type(), }, operateAsset: { path: "/api/v1/asset/{external_id}/operate_assets/", @@ -282,10 +304,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}/", @@ -333,6 +358,8 @@ const routes = { }, getConsultation: { path: "/api/v1/consultation/{id}/", + method: "GET", + TRes: Type(), }, updateConsultation: { path: "/api/v1/consultation/{id}/", @@ -360,6 +387,9 @@ const routes = { }, getDailyReports: { path: "/api/v1/consultation/{consultationId}/daily_rounds/", + method: "GET", + TBody: Type(), + TRes: Type(), }, getDailyReport: { @@ -368,6 +398,8 @@ const routes = { dailyRoundsAnalyse: { path: "/api/v1/consultation/{consultationId}/daily_rounds/analyse/", method: "POST", + TRes: Type(), + Tbody: Type(), }, // Hospital Beds