From 4b639e090e91df146bf2168b1e4febe29c8a0c49 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Wed, 3 Jan 2024 14:33:37 +0530 Subject: [PATCH 1/4] Remove Legacy HL7Monitor Components --- src/Components/Facility/LegacyFacilityCNS.tsx | 313 ------------------ src/Components/Facility/LegacyMonitorCard.tsx | 47 --- .../Patient/LegacyPatientVitalsCard.tsx | 288 ---------------- 3 files changed, 648 deletions(-) delete mode 100644 src/Components/Facility/LegacyFacilityCNS.tsx delete mode 100644 src/Components/Facility/LegacyMonitorCard.tsx delete mode 100644 src/Components/Patient/LegacyPatientVitalsCard.tsx diff --git a/src/Components/Facility/LegacyFacilityCNS.tsx b/src/Components/Facility/LegacyFacilityCNS.tsx deleted file mode 100644 index 5b0005c9daf..00000000000 --- a/src/Components/Facility/LegacyFacilityCNS.tsx +++ /dev/null @@ -1,313 +0,0 @@ -import { navigate } from "raviger"; -import { useEffect, useState } from "react"; -import { useDispatch } from "react-redux"; -import CareIcon from "../../CAREUI/icons/CareIcon"; -import { - getAllPatient, - getPermittedFacility, - listAssetBeds, -} from "../../Redux/actions"; -import { classNames } from "../../Utils/utils"; -import { AssetData, AssetLocationObject } from "../Assets/AssetTypes"; -import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2"; -import Page from "../Common/components/Page"; -import Loading from "../Common/Loading"; -import Pagination from "../Common/Pagination"; -import { PatientModel } from "../Patient/models"; -import { FacilityModel } from "./models"; -import AutocompleteFormField from "../Form/FormFields/Autocomplete"; -import { uniqBy } from "lodash-es"; -import DialogModal from "../Common/Dialog"; -import { LegacyMonitorCard } from "./LegacyMonitorCard"; - -interface Monitor { - patient: PatientModel; - asset: AssetData; - socketUrl: string; -} - -const PER_PAGE_LIMIT = 6; -const CNS_REFRESH_INTERVAL = 0.5 * 60e3; - -export default function LegacyFacilityCNS({ - facilityId, -}: { - facilityId: string; -}) { - const dispatch = useDispatch(); - const [isFullscreen, setIsFullscreen] = useState(false); - const [monitors, setMonitors] = useState(); - const [facility, setFacility] = useState(); - const [currentPage, setCurrentPage] = useState(1); - const [defaultShowAllLocation, setDefaultShowAllLocation] = useState(true); - const searchParams = new URLSearchParams(window.location.search); - - // this wil set ?page=1 param in url if it is not present - useEffect(() => { - if (!searchParams.get("page")) { - navigate(`/facility/${facilityId}/cns?page=1`); - } - }, []); - const [location, setLocation] = useState(); - const [showSelectLocation, setShowSelectLocation] = useState(false); - - useEffect(() => { - const onFullscreenChange = () => - setIsFullscreen(!!document.fullscreenElement); - document.addEventListener("fullscreenchange", onFullscreenChange); - return () => - document.removeEventListener("fullscreenchange", onFullscreenChange); - }, []); - - useEffect(() => { - async function fetchFacility() { - const res = await dispatch(getPermittedFacility(facilityId || "")); - if (res.status === 200) setFacility(res.data); - } - fetchFacility(); - }, [facilityId, dispatch]); - - useEffect(() => { - if (!facility) return; - const middlewareHostname = facility.middleware_address; - - async function fetchPatients() { - const res = await dispatch( - getAllPatient( - { facility: facilityId, is_active: "True" }, - "cns-patient-list" - ) - ); - if (res.status === 200) { - const patients = res.data.results as PatientModel[]; - return patients.filter( - (patient) => !!patient.last_consultation?.current_bed?.bed_object.id - ); - } - } - - async function fetchPatientMonitorAsset(patient: PatientModel) { - const res = await dispatch( - listAssetBeds( - { - bed: patient.last_consultation?.current_bed?.bed_object?.id, - }, - `asset-bed-${patient.id}` - ) - ); - - if (res.status !== 200) return; - - const asset = res.data.results.find( - (assetBed: any) => - assetBed.asset_object.meta?.asset_type === "HL7MONITOR" - )?.asset_object as AssetData | undefined; - - if (!asset) return; - - const socketUrl = `wss://${middlewareHostname}/observations/${asset.meta?.local_ip_address}`; - - return { patient, asset, socketUrl } as Monitor; - } - - async function fetchMonitors() { - const patients = await fetchPatients(); - if (!patients) return; - - const monitors = await Promise.all( - patients.map((patient) => fetchPatientMonitorAsset(patient)) - ); - return monitors.filter((monitor) => !!monitor) as Monitor[]; - } - - fetchMonitors().then((monitors) => { - setCurrentPage(Number(searchParams.get("page"))); - setMonitors(monitors); - }); - - const interval = setInterval(() => { - fetchMonitors().then(setMonitors); - }, CNS_REFRESH_INTERVAL); - - return () => clearInterval(interval); - }, [dispatch, facility, facilityId]); - - if (!monitors) return ; - return ( - - {monitors?.length > 0 ? ( - <> - setShowSelectLocation(true)} - > - - Change Location - - { - if (isFullscreen) { - document.exitFullscreen(); - } else { - document.documentElement.requestFullscreen(); - } - }} - className="tooltip !h-11" - > - - - {isFullscreen ? "Exit Fullscreen" : "Fullscreen"} - - - - ) : ( - <> - history.go(-2)} - > - Go Back - - - )} - - { - setCurrentPage(page); - navigate(`/facility/${facilityId}/cns?page=${page}`); - }} - data={{ - totalCount: defaultShowAllLocation - ? monitors.length - : monitors.filter( - (m) => m.asset.location_object.id === location?.id - ).length, - }} - defaultPerPage={PER_PAGE_LIMIT} - /> - - } - > - setShowSelectLocation(false)} - className="w-full max-w-md" - > - {!monitors && } -
- setLocation(value)} - options={ - monitors - ? uniqBy( - monitors.map((m) => m.asset.location_object), - "id" - ) - : [] - } - isLoading={!monitors} - optionLabel={(location) => location.name} - optionDescription={(location) => - location.description + - " (" + - monitors.filter((m) => m.asset.location_object.id === location.id) - .length + - " patients)" - } - optionValue={(location) => location} - disabled={!monitors} - /> -
- { - setDefaultShowAllLocation(true); - setShowSelectLocation(false); - }} - > - Show All Locations - - { - setDefaultShowAllLocation(false); - setShowSelectLocation(false); - }} - className="my-2 mr-2" - label="Confirm" - /> - setShowSelectLocation(false)} - className="my-2 mr-2" - /> -
-
-
- {monitors.length === 0 && ( -
- No patients are currently monitored -
- )} -
- {defaultShowAllLocation - ? monitors - ?.slice( - (currentPage - 1) * PER_PAGE_LIMIT, - currentPage * PER_PAGE_LIMIT - ) - .map(({ patient, socketUrl, asset }) => ( - - )) - : monitors - ?.filter((m) => m.asset.location_object.id === location?.id) - ?.slice( - (currentPage - 1) * PER_PAGE_LIMIT, - currentPage * PER_PAGE_LIMIT - ) - .map(({ patient, socketUrl, asset }) => ( - - ))} -
-
- ); -} diff --git a/src/Components/Facility/LegacyMonitorCard.tsx b/src/Components/Facility/LegacyMonitorCard.tsx deleted file mode 100644 index 61bff3d607b..00000000000 --- a/src/Components/Facility/LegacyMonitorCard.tsx +++ /dev/null @@ -1,47 +0,0 @@ -import { GENDER_TYPES } from "../../Common/constants"; -import { Link } from "raviger"; -import CareIcon from "../../CAREUI/icons/CareIcon"; -import { PatientModel } from "../Patient/models"; -import LegacyPatientVitalsCard from "../Patient/LegacyPatientVitalsCard"; -import { AssetLocationObject } from "../Assets/AssetTypes"; -import { formatAge } from "../../Utils/utils"; - -interface MonitorCardProps { - facilityId: string; - patient: PatientModel; - socketUrl: string; - location: AssetLocationObject; -} - -export const LegacyMonitorCard = ({ - facilityId, - patient, - socketUrl, - location, -}: MonitorCardProps) => { - return ( -
-
- - {patient.name} - - - {formatAge(patient.age, patient.date_of_birth)} |{" "} - {GENDER_TYPES.find((g) => g.id === patient.gender)?.icon} - - - - {patient.last_consultation?.current_bed?.bed_object?.name} - - - - {location.name} - -
- -
- ); -}; diff --git a/src/Components/Patient/LegacyPatientVitalsCard.tsx b/src/Components/Patient/LegacyPatientVitalsCard.tsx deleted file mode 100644 index 6577e4920d4..00000000000 --- a/src/Components/Patient/LegacyPatientVitalsCard.tsx +++ /dev/null @@ -1,288 +0,0 @@ -import { ReactNode, useEffect, useRef, useState } from "react"; -import { useDispatch } from "react-redux"; -import { listAssetBeds, getPermittedFacility } from "../../Redux/actions"; -import { classNames } from "../../Utils/utils"; -import { AssetData } from "../Assets/AssetTypes"; -import ToolTip from "../Common/utils/Tooltip"; -import { PatientModel } from "./models"; -import Waveform, { WaveformType } from "./Waveform"; - -export interface IPatientVitalsCardProps { - facilityId?: string; - patient?: PatientModel; - socketUrl?: string; - shrinked?: boolean; -} - -const getVital = ( - patientObservations: any, - vital: string, - fallbackValue?: any -) => { - if (patientObservations) { - const vitalValues = patientObservations[vital]; - if (vitalValues) { - const returnValue = vitalValues?.value; - - if (returnValue !== undefined && returnValue !== null) { - return returnValue; - } - } - } - if (fallbackValue) { - return fallbackValue; - } - return ""; -}; - -export default function LegacyPatientVitalsCard({ - patient, - socketUrl, - facilityId, - shrinked, -}: IPatientVitalsCardProps) { - const wsClient = useRef(); - const [waveforms, setWaveForms] = useState(null); - const dispatch: any = useDispatch(); - const [middlewareHostname, setMiddlewareHostname] = useState(""); - const [wsUrl, setWsUrl] = useState(""); - const [patientObservations, setPatientObservations] = useState(); - const [stats, setStats] = useState(false); - - useEffect(() => { - const fetchFacility = async () => { - const res = await dispatch(getPermittedFacility(facilityId || "")); - - if (res.status === 200 && res.data) { - setMiddlewareHostname(res.data.middleware_address); - } - }; - - if (facilityId) fetchFacility(); - }, [dispatch, facilityId]); - - useEffect(() => { - const fetchAssetData = async () => { - let bedAssets = await dispatch( - listAssetBeds({ - bed: patient?.last_consultation?.current_bed?.bed_object?.id, - }) - ); - bedAssets = { - ...bedAssets, - data: { - ...bedAssets.data, - results: bedAssets.data.results.filter((assetBed: any) => - assetBed.asset_object.meta?.asset_type === "HL7MONITOR" - ? true - : false - ), - }, - }; - - if (bedAssets.data.results.length > 0) { - const asset: AssetData = bedAssets.data.results[0].asset_object; - if (asset?.meta?.local_ip_address) { - setWsUrl( - `wss://${middlewareHostname}/observations/${asset?.meta?.local_ip_address}` - ); - } - } - }; - - if (patient?.last_consultation?.current_bed?.bed_object?.id) - fetchAssetData(); - }, [ - dispatch, - middlewareHostname, - patient?.last_consultation?.current_bed?.bed_object?.id, - ]); - - const connectWs = (url: string) => { - wsClient.current = new WebSocket(url); - wsClient.current.addEventListener("message", (e) => { - const newObservations = JSON.parse(e.data || "{}"); - if (newObservations.length > 0) { - setWaveForms( - newObservations.filter((o: any) => o.observation_id === "waveform") - ); - const newObservationsMap = newObservations.reduce( - (acc: any, curr: { observation_id: any }) => ({ - ...acc, - [curr.observation_id]: curr, - }), - {} - ); - setPatientObservations(newObservationsMap); - } - }); - }; - - useEffect(() => { - if (socketUrl || wsUrl) connectWs(socketUrl || wsUrl); - - return () => { - wsClient.current?.close(); - }; - }, [wsUrl, socketUrl]); - - useEffect(() => { - return () => { - wsClient.current?.close(); - setWaveForms(null); - }; - }, [socketUrl, patient]); - - type VitalType = { - label: ReactNode; - liveKey: string; - vitalKey: string; - waveformKey?: string; - waveformColor?: string; - waveformName?: string; - waveformDefaultSpace?: boolean; - wavetype?: "STREAM" | "REFRESH"; - }; - - const vitals: VitalType[] = [ - { - label: shrinked ? "Pulse" : "Pulse Rate", - liveKey: "pulse-rate", - vitalKey: "pulse", - waveformKey: "II", - waveformColor: "limegreen", - waveformName: "ECG", - wavetype: "REFRESH", - }, - { - label: shrinked ? "BP" : "Blood Pressure", - liveKey: "bp", - vitalKey: "bp", - }, - { - label: ( - <> - SpO2 - - ), - liveKey: "SpO2", - vitalKey: "ventilator_spo2", - waveformKey: "Pleth", - waveformColor: "yellow", - }, - { - label: <>R. Rate, - liveKey: "respiratory-rate", - vitalKey: "resp", - waveformKey: "Respiration", - waveformColor: "cyan", - //waveformDefaultSpace: true - }, - { - label: shrinked ? "Temp. (°F)" : "Temperature (°F)", - liveKey: "body-temperature1", - vitalKey: "temperature", - }, - ]; - - return ( -
-
-
- {waveforms ? ( - <> - {vitals.map((v, i) => { - const waveform: any = waveforms.filter( - (w) => w["wave-name"] === v.waveformKey - )[0]; - return v.waveformKey && waveform ? ( - w["wave-name"] === v.waveformKey) - .map((w) => w.data) - .join(" "), - }} - title={v.waveformName || v.waveformKey} - color={v.waveformColor} - metrics={stats} - classes={"h-[150px]"} - defaultSpace={v.waveformDefaultSpace} - wavetype={v.wavetype || "STREAM"} - /> - ) : ( -
- ); - })} -
- - - -
- - ) : ( -
-
- -
No Live data at the moment!
-
-
- )} -
-
- {vitals.map((vital, i) => { - const liveReading = getVital(patientObservations, vital.liveKey); - return ( -
-

- {liveReading || - (vital.vitalKey === "bp" - ? `${ - patient?.last_consultation?.last_daily_round?.bp - .systolic || "--" - }/${ - patient?.last_consultation?.last_daily_round?.bp - .diastolic || "--" - }` - : patient?.last_consultation?.last_daily_round?.[ - vital.vitalKey || "" - ]) || - "--"} -

-
-
- {vital.label} -
-
- ); - })} -
-
-
- ); -} From 05b78eb0f32b95ea80fdcb6448a1239d28224098 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Wed, 3 Jan 2024 14:34:47 +0530 Subject: [PATCH 2/4] Use `resolved_middleware` in ConsultationUpdates Tab --- src/Components/CameraFeed/utils.ts | 6 ++- .../ConsultationUpdatesTab.tsx | 52 ++++++------------- 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/src/Components/CameraFeed/utils.ts b/src/Components/CameraFeed/utils.ts index e2793d76b41..fc940558aa0 100644 --- a/src/Components/CameraFeed/utils.ts +++ b/src/Components/CameraFeed/utils.ts @@ -1,5 +1,5 @@ import { MutableRefObject } from "react"; -import { AssetData } from "../Assets/AssetTypes"; +import { AssetClass, AssetData } from "../Assets/AssetTypes"; import { getCameraConfig } from "../../Utils/transformUtils"; import { isIOS } from "../../Utils/utils"; @@ -18,6 +18,10 @@ export const calculateVideoDelay = ( }; export const getStreamUrl = (asset: AssetData) => { + if (asset.asset_class !== AssetClass.ONVIF) { + throw "getStreamUrl can be invoked only for ONVIF Assets"; + } + const config = getCameraConfig(asset); const host = asset.resolved_middleware?.hostname; const uuid = config.accessKey; diff --git a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx index beac7f595a8..ed2d4277c54 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx @@ -2,8 +2,8 @@ import { lazy, useEffect, useState } from "react"; import { ConsultationTabProps } from "./index"; import { AssetBedModel, AssetClass, AssetData } from "../../Assets/AssetTypes"; import { useDispatch } from "react-redux"; -import { getPermittedFacility, listAssetBeds } from "../../../Redux/actions"; -import { BedModel, FacilityModel } from "../models"; +import { listAssetBeds } from "../../../Redux/actions"; +import { BedModel } from "../models"; import HL7PatientVitalsMonitor from "../../VitalsMonitor/HL7PatientVitalsMonitor"; import VentilatorPatientVitalsMonitor from "../../VitalsMonitor/VentilatorPatientVitalsMonitor"; import useVitalsAspectRatioConfig from "../../VitalsMonitor/useVitalsAspectRatioConfig"; @@ -13,6 +13,7 @@ import Chip from "../../../CAREUI/display/Chip"; import { formatAge, formatDate, formatDateTime } from "../../../Utils/utils"; import ReadMore from "../../Common/components/Readmore"; import DailyRoundsList from "../Consultations/DailyRoundsList"; +import { getVitalsMonitorSocketUrl } from "../../VitalsMonitor/utils"; const PageTitle = lazy(() => import("../../Common/PageTitle")); @@ -40,32 +41,22 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { return; const fetchData = async () => { - const [facilityRes, assetBedRes] = await Promise.all([ - dispatch(getPermittedFacility(props.consultationData.facility as any)), - dispatch( - listAssetBeds({ - facility: props.consultationData.facility as any, - bed: props.consultationData.current_bed?.bed_object.id, - }) - ), - ]); - - const { middleware_address } = facilityRes.data as FacilityModel; + const assetBedRes = await dispatch( + listAssetBeds({ + facility: props.consultationData.facility as any, + bed: props.consultationData.current_bed?.bed_object.id, + }) + ); const assetBeds = assetBedRes?.data?.results as AssetBedModel[]; const monitorBedData = assetBeds?.find( (i) => i.asset_object?.asset_class === AssetClass.HL7MONITOR ); + setMonitorBedData(monitorBedData); - const assetDataForMonitor = monitorBedData?.asset_object; - const hl7Meta = assetDataForMonitor?.meta; - const hl7Middleware = - hl7Meta?.middleware_hostname || - assetDataForMonitor?.location_object?.middleware_address || - middleware_address; - if (hl7Middleware && hl7Meta?.local_ip_address) { + if (monitorBedData?.asset_object) { setHL7SocketUrl( - `wss://${hl7Middleware}/observations/${hl7Meta.local_ip_address}` + getVitalsMonitorSocketUrl(monitorBedData?.asset_object) ); } @@ -73,6 +64,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { props.consultationData?.current_bed?.assets_objects?.find( (i) => i.asset_class === AssetClass.VENTILATOR ); + let ventilatorBedData; if (consultationBedVentilator) { ventilatorBedData = { @@ -84,25 +76,13 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { (i) => i.asset_object.asset_class === AssetClass.VENTILATOR ); } + setVentilatorBedData(ventilatorBedData); - const ventilatorMeta = ventilatorBedData?.asset_object?.meta; - const ventilatorMiddleware = - ventilatorMeta?.middleware_hostname || - consultationBedVentilator?.location_object.middleware_address || - middleware_address; - if (ventilatorMiddleware && ventilatorMeta?.local_ip_address) { + if (ventilatorBedData?.asset_object) { setVentilatorSocketUrl( - `wss://${ventilatorMiddleware}/observations/${ventilatorMeta?.local_ip_address}` + getVitalsMonitorSocketUrl(ventilatorBedData?.asset_object) ); } - - if ( - !(hl7Middleware && hl7Meta?.local_ip_address) && - !(ventilatorMiddleware && ventilatorMeta?.local_ip_address) - ) { - setHL7SocketUrl(undefined); - setVentilatorSocketUrl(undefined); - } }; fetchData(); From 72bdeb7528b5976560479eb9b5f0543b9f693037 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Wed, 3 Jan 2024 14:35:59 +0530 Subject: [PATCH 3/4] CNS: Migrate to `useQuery` and use `resolved_middleware` --- .../Facility/CentralNursingStation.tsx | 90 +++++-------------- src/Components/VitalsMonitor/utils.ts | 17 ++++ 2 files changed, 38 insertions(+), 69 deletions(-) diff --git a/src/Components/Facility/CentralNursingStation.tsx b/src/Components/Facility/CentralNursingStation.tsx index 9e8febe88fd..75214b5506c 100644 --- a/src/Components/Facility/CentralNursingStation.tsx +++ b/src/Components/Facility/CentralNursingStation.tsx @@ -1,13 +1,7 @@ -import { useDispatch } from "react-redux"; import useFullscreen from "../../Common/hooks/useFullscreen"; -import { Fragment, useEffect, useState } from "react"; -import { - getPermittedFacility, - listPatientAssetBeds, -} from "../../Redux/actions"; +import { Fragment } from "react"; import HL7PatientVitalsMonitor from "../VitalsMonitor/HL7PatientVitalsMonitor"; import useFilters from "../../Common/hooks/useFilters"; -import { FacilityModel } from "./models"; import Loading from "../Common/Loading"; import Page from "../Common/components/Page"; import ButtonV2 from "../Common/components/ButtonV2"; @@ -15,7 +9,6 @@ import CareIcon from "../../CAREUI/icons/CareIcon"; import { classNames } from "../../Utils/utils"; import { LocationSelect } from "../Common/LocationSelect"; import Pagination from "../Common/Pagination"; -import { PatientAssetBed } from "../Assets/AssetTypes"; import { Popover, Transition } from "@headlessui/react"; import { FieldLabel } from "../Form/FormFields/FormField"; import CheckBoxFormField from "../Form/FormFields/CheckBoxFormField"; @@ -23,6 +16,9 @@ import { useTranslation } from "react-i18next"; import { SortOption } from "../Common/SortDropdown"; import { SelectFormField } from "../Form/FormFields/SelectFormField"; import useVitalsAspectRatioConfig from "../VitalsMonitor/useVitalsAspectRatioConfig"; +import useQuery from "../../Utils/request/useQuery"; +import routes from "../../Redux/api"; +import { getVitalsMonitorSocketUrl } from "../VitalsMonitor/utils"; const PER_PAGE_LIMIT = 6; @@ -39,72 +35,28 @@ interface Props { export default function CentralNursingStation({ facilityId }: Props) { const { t } = useTranslation(); - const dispatch = useDispatch(); const [isFullscreen, setFullscreen] = useFullscreen(); - - const [facilityObject, setFacilityObject] = useState(); - const [data, setData] = - useState[0][]>(); - const [totalCount, setTotalCount] = useState(0); const { qParams, updateQuery, removeFilter, updatePage } = useFilters({ limit: PER_PAGE_LIMIT, }); + const query = useQuery(routes.listPatientAssetBeds, { + pathParams: { facility_external_id: facilityId }, + query: { + ...qParams, + page: qParams.page || 1, + limit: PER_PAGE_LIMIT, + offset: (qParams.page ? qParams.page - 1 : 0) * PER_PAGE_LIMIT, + asset_class: "HL7MONITOR", + ordering: qParams.ordering || "bed__name", + bed_is_occupied: qParams.bed_is_occupied ?? true, + }, + }); - useEffect(() => { - async function fetchFacilityOrObject() { - if (facilityObject) return facilityObject; - const res = await dispatch(getPermittedFacility(facilityId)); - if (res.status !== 200) return; - setFacilityObject(res.data); - return res.data as FacilityModel; - } - - async function fetchData() { - setData(undefined); - - const filters = { - ...qParams, - page: qParams.page || 1, - limit: PER_PAGE_LIMIT, - offset: (qParams.page ? qParams.page - 1 : 0) * PER_PAGE_LIMIT, - asset_class: "HL7MONITOR", - ordering: qParams.ordering || "bed__name", - bed_is_occupied: qParams.bed_is_occupied ?? true, - }; - - const [facilityObj, res] = await Promise.all([ - fetchFacilityOrObject(), - dispatch(listPatientAssetBeds(facilityId, filters)), - ]); - - if (!facilityObj || res.status !== 200) { - return; - } - - const entries = res.data.results as PatientAssetBed[]; - - setTotalCount(res.data.count); - setData( - entries.map(({ patient, asset, bed }) => { - const middleware = asset.resolved_middleware?.hostname; - const local_ip_address = asset.meta?.local_ip_address; - - return { - patientAssetBed: { patient, asset, bed }, - socketUrl: `wss://${middleware}/observations/${local_ip_address}`, - }; - }) - ); - } - fetchData(); - }, [ - dispatch, - facilityId, - qParams.page, - qParams.location, - qParams.ordering, - qParams.bed_is_occupied, - ]); + const totalCount = query.data?.count ?? 0; + const data = query.data?.results.map((obj) => ({ + patientAssetBed: obj, + socketUrl: getVitalsMonitorSocketUrl(obj.asset), + })); const { config, hash } = useVitalsAspectRatioConfig({ default: 6 / 11, diff --git a/src/Components/VitalsMonitor/utils.ts b/src/Components/VitalsMonitor/utils.ts index 2e38f83b65b..21ba769dc83 100644 --- a/src/Components/VitalsMonitor/utils.ts +++ b/src/Components/VitalsMonitor/utils.ts @@ -1,3 +1,4 @@ +import { AssetClass, AssetData } from "../Assets/AssetTypes"; import { ChannelOptions, VitalsWaveformBase } from "./types"; /** @@ -73,3 +74,19 @@ export const getVitalsCanvasSizeAndDuration = ( duration: DEFAULT_DURATION * (ratio / DEFAULT_RATIO), }; }; + +export const getVitalsMonitorSocketUrl = (asset: AssetData) => { + if ( + asset.asset_class !== AssetClass.HL7MONITOR && + asset.asset_class !== AssetClass.VENTILATOR + ) { + throw "getVitalsMonitorSocketUrl can be invoked only for HL7MONITOR or VENTILATOR assets"; + } + + const middleware = asset.resolved_middleware?.hostname; + const ipAddress = asset.meta?.local_ip_address; + + if (middleware && ipAddress) { + return `wss://${middleware}/observations/${ipAddress}`; + } +}; From 45a6fbb63032c9fffe637dc781f902d7fb92705b Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Wed, 3 Jan 2024 14:36:16 +0530 Subject: [PATCH 4/4] remove unused redux actions --- src/Redux/actions.tsx | 9 --------- src/Redux/api.tsx | 2 ++ 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Redux/actions.tsx b/src/Redux/actions.tsx index 32af9609263..d280d6c3db1 100644 --- a/src/Redux/actions.tsx +++ b/src/Redux/actions.tsx @@ -28,10 +28,6 @@ export const getAllSkills = (params: object) => { return fireRequest("getAllSkills", [], params); }; -export const getPermittedFacility = (id: number | string, key?: string) => { - return fireRequest("getPermittedFacility", [], {}, { id: id }, key); -}; - export const getAnyFacility = (id: number | string, key?: string) => { return fireRequest("getAnyFacility", [], {}, { id: id }, key); }; @@ -109,11 +105,6 @@ export const deleteAssetBed = (asset_id: string) => } ); -export const listPatientAssetBeds = ( - facility_external_id: string, - params: object -) => fireRequest("listPatientAssetBeds", [], params, { facility_external_id }); - // Facility Beds export const listFacilityBeds = (params: object) => fireRequest("listFacilityBeds", [], params, {}); diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 2b8d4f8f51b..45392c046af 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -27,6 +27,7 @@ import { AssetServiceUpdate, AssetTransaction, AssetUpdate, + PatientAssetBed, } from "../Components/Assets/AssetTypes"; import { CapacityModal, @@ -394,6 +395,7 @@ const routes = { listPatientAssetBeds: { path: "/api/v1/facility/{facility_external_id}/patient_asset_beds/", method: "GET", + TRes: Type>(), }, // Facility Beds