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/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..518121e6e69 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, 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( @@ -48,37 +44,23 @@ 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 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 || []); - } + 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..!", + }); } }, - [consultationId, dispatch] - ); - useAbortableEffect( - (status: statusType) => { - fetchData(status); - }, - [dispatch, fetchData, key] - ); + }); const handleSubmit = async (e: React.SyntheticEvent) => { e.preventDefault(); @@ -88,13 +70,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({ @@ -106,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/DailyRoundsList.tsx b/src/Components/Facility/Consultations/DailyRoundsList.tsx index 0ec84a0cc87..da4b8201495 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,78 @@ 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"> + {(item, items) => { + if (item.rounds_type === "AUTOMATED") { + return ( + + ); + } + 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` + ); + } + }} + /> + ); + }} + +
    + +
    +
    )} -
    + ); }; 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 25b656a0a79..30fcbd19973 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,17 +12,9 @@ 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"; import FeedButton from "./FeedButton"; import Loading from "../../Common/Loading"; import ReactPlayer from "react-player"; @@ -33,11 +26,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.js"; interface IFeedProps { facilityId: string; consultationId: any; } + const PATIENT_DEFAULT_PRESET = "Patient View".trim().toLowerCase(); export const Feed: React.FC = ({ consultationId, facilityId }) => { @@ -51,10 +46,8 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { middleware_address: "", location_middleware: "", }); - const [facilityMiddlewareHostname, setFacilityMiddlewareHostname] = - useState(""); + const [cameraConfig, setCameraConfig] = useState({}); - const [isLoading, setIsLoading] = useState(true); const [bedPresets, setBedPresets] = useState([]); const [bed, setBed] = useState(); const [precision, setPrecision] = useState(1); @@ -64,17 +57,16 @@ 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)); + let facilityMiddlewareHostname = ""; - if (res.status === 200 && res.data) { - setFacilityMiddlewareHostname(res.data.middleware_address); + useQuery(routes.getPermittedFacility, { + pathParams: { id: facilityId || "" }, + onResponse: ({ res, data }) => { + if (res && res.status === 200 && data && data.middleware_address) { + facilityMiddlewareHostname = data.middleware_address; } - }; - - if (facilityId) fetchFacility(); - }, [dispatch, facilityId]); + }, + }); const fallbackMiddleware = cameraAsset.location_middleware || facilityMiddlewareHostname; @@ -106,57 +98,55 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { 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 consultationBedId = consultation.current_bed?.bed_object?.id; + const { loading: getConsultationLoading } = useQuery(routes.getConsultation, { + pathParams: { id: consultationId }, + onResponse: ({ res, data }) => { + if (res && res.status === 200 && data) { + const consultationBedId = data.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 } } }) => { + (async () => { + const { res: listAssetBedsRes, data: listAssetBedsData } = + await request(routes.listAssetBeds, { + query: { + bed: 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] || "", - 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({ - ...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] || "", + 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({ + ...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 @@ -225,8 +215,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.listAssetBeds, { + query: { asset: asset.id, bed }, + }); + setBedPresets(bedAssets?.results); } }; @@ -287,10 +279,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); @@ -374,9 +362,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: assetBedData } = await request( + routes.partialUpdateAssetBed, + { + body: { asset: currentPreset.asset_object.id, bed: currentPreset.bed_object.id, meta: { @@ -384,12 +373,12 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { position: data?.position, }, }, - currentPreset?.id - ) + pathParams: { id: currentPreset?.id }, + } ); - if (response && response.status === 200) { + if (res && assetBedData && res.status === 200) { Notification.Success({ msg: "Preset Updated" }); - getBedPresets(cameraAsset?.id); + await getBedPresets(cameraAsset?.id); getPresets({}); } setLoading(CAMERA_STATES.IDLE); @@ -421,7 +410,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 cd3f055921e..4f6c3391c43 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.listAssetBeds, { + 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 } = 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 (res && res.status === 200) { Notification.Success({ msg: "Preset Updated" }); } else { Notification.Error({ msg: "Something Went Wrong" }); @@ -258,20 +255,19 @@ 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, { + pathParams: { id: currentPreset.id }, + body: { + asset: currentPreset.asset_object.id, + bed: currentPreset.bed_object.id, + meta: { + ...currentPreset.meta, + position: data?.position, }, - currentPreset?.id - ) - ); - if (response && response.status === 200) { + }, + }); + + if (res && res.status === 200) { Notification.Success({ msg: "Preset Updated" }); getBedPresets(cameraAsset?.id); fetchCameraPresets(); @@ -628,5 +624,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..cb3eed92144 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"; @@ -87,7 +88,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); @@ -95,11 +96,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 +120,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) => { @@ -299,9 +294,9 @@ export const NeurologicalTable = (props: any) => { {locData.map((x: any, i: any) => (
    -
    +
    {x.date}
    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..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..bf3f4704114 100644 --- a/src/Components/Facility/Consultations/PressureSoreDiagrams.tsx +++ b/src/Components/Facility/Consultations/PressureSoreDiagrams.tsx @@ -1,15 +1,15 @@ -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"; 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"; +import { PressureSoreDiagramsRes } from "../models"; 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 +19,49 @@ 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( + (key) => + (dailyRounds.results[key] as PressureSoreDiagramsRes).pressure_sore + .length + ); + const data: any = {}; + 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..9dfe0ce8a1e 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,45 @@ 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) { + 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 bd0f4eafeda..fe6c8e3b0d4 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -11,21 +11,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 { is_readmission?: boolean; medico_legal_case?: boolean; } + export interface PatientStatsModel { id?: number; entryDate?: string; @@ -221,3 +226,216 @@ export interface CurrentBed { end_date: string; 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: { + [date: string]: + | PressureSoreDiagramsRes + | ABGPlotsRes + | DialysisPlotsRes + | NeurologicalTablesRes + | NursingPlotRes + | NutritionPlotsRes + | PainDiagramsRes + | PrimaryParametersPlotRes + | VentilatorPlotRes; + }; +} + +export interface CreateBedBody { + start_date: string; + assets: string[]; + consultation: string; + bed: string; +} + +// Voluntarily made as `type` for it to achieve type-safety when used with +// `useAsyncOptions` +export type ICD11DiagnosisModel = { + id: string; + label: string; +}; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 1ff80b55304..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,10 @@ import { } from "../Components/Assets/AssetTypes"; import { ConsultationModel, + CreateBedBody, CurrentBed, + DailyRoundsBody, + DailyRoundsRes, FacilityModel, LocationModel, WardModel, @@ -43,13 +46,16 @@ import { ILocalBodyByDistrict, IPartialUpdateExternalResult, } from "../Components/ExternalResult/models"; + +import { Prescription } from "../Components/Medicine/models"; import { UserModel } from "../Components/Users/models"; +import { DailyRoundsModel, PatientModel } from "../Components/Patient/models"; import { PaginatedResponse } from "../Utils/request/types"; import { NotificationData, PNconfigData, } from "../Components/Notifications/models"; -import { PatientModel } from "../Components/Patient/models"; + import { IComment, IResource } from "../Components/Resource/models"; import { IShift } from "../Components/Shifting/models"; @@ -92,7 +98,9 @@ const routes = { path: "/api/v1/auth/token/refresh/", method: "POST", TRes: Type(), - TBody: Type<{ refresh: string }>(), + TBody: Type<{ + refresh: string; + }>(), }, token_verify: { @@ -105,7 +113,9 @@ const routes = { method: "POST", noAuth: true, TRes: Type>(), - TBody: Type<{ token: string }>(), + TBody: Type<{ + token: string; + }>(), }, resetPassword: { @@ -113,7 +123,10 @@ const routes = { method: "POST", noAuth: true, TRes: Type>(), - TBody: Type<{ password: string; confirm: string }>(), + TBody: Type<{ + password: string; + confirm: string; + }>(), }, forgotPassword: { @@ -121,7 +134,9 @@ const routes = { method: "POST", noAuth: true, TRes: Type>(), - TBody: Type<{ username: string }>(), + TBody: Type<{ + username: string; + }>(), }, updatePassword: { @@ -326,6 +341,9 @@ const routes = { deleteAssetBed: { path: "/api/v1/assetbed/{external_id}/", method: "DELETE", + TRes: Type(), }, operateAsset: { path: "/api/v1/asset/{external_id}/operate_assets/", @@ -370,6 +388,8 @@ const routes = { createConsultationBed: { path: "/api/v1/consultationbed/", method: "POST", + TBody: Type(), + TRes: Type>(), }, getConsultationBed: { path: "/api/v1/consultationbed/{external_id}/", @@ -417,6 +437,8 @@ const routes = { }, getConsultation: { path: "/api/v1/consultation/{id}/", + method: "GET", + TRes: Type(), }, updateConsultation: { path: "/api/v1/consultation/{id}/", @@ -446,6 +468,8 @@ const routes = { }, getDailyReports: { path: "/api/v1/consultation/{consultationId}/daily_rounds/", + method: "GET", + TRes: Type>(), }, getDailyReport: { @@ -454,6 +478,8 @@ const routes = { dailyRoundsAnalyse: { path: "/api/v1/consultation/{consultationId}/daily_rounds/analyse/", method: "POST", + TBody: Type(), + TRes: Type(), }, // Hospital Beds @@ -1143,6 +1169,49 @@ const routes = { method: "GET", }, + // Prescription endpoints + + listPrescriptions: { + path: "/api/v1/consultation/{consultation_external_id}/prescriptions/", + method: "GET", + }, + + createPrescription: { + path: "/api/v1/consultation/{consultation_external_id}/prescriptions/", + method: "POST", + TBody: Type(), + TRes: Type(), + }, + + listAdministrations: { + path: "/api/v1/consultation/{consultation_external_id}/prescription_administration/", + method: "GET", + }, + + getAdministration: { + path: "/api/v1/consultation/{consultation_external_id}/prescription_administration/{external_id}/", + method: "GET", + }, + + getPrescription: { + path: "/api/v1/consultation/{consultation_external_id}/prescriptions/{external_id}/", + method: "GET", + }, + + administerPrescription: { + path: "/api/v1/consultation/{consultation_external_id}/prescriptions/{external_id}/administer/", + method: "POST", + }, + + discontinuePrescription: { + path: "/api/v1/consultation/{consultation_external_id}/prescriptions/{external_id}/discontinue/", + method: "POST", + TBody: Type<{ + discontinued_reason: string; + }>(), + TRes: Type>(), + }, + // HCX Endpoints listPMJYPackages: {