Skip to content

Commit

Permalink
displayed linked camera feed in patient consultaion page
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahendar0701 committed Oct 24, 2024
1 parent 7e15e3c commit 158b07e
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { ConsultationTabProps } from "./index";
import useQuery from "../../../Utils/request/useQuery";
import CameraFeed from "../../CameraFeed/CameraFeed";
Expand All @@ -23,6 +23,7 @@ import {
GetStatusResponse,
} from "../../CameraFeed/routes";
import StillWatching from "../../CameraFeed/StillWatching";
import routes from "@/Redux/api";

export const ConsultationFeedTab = (props: ConsultationTabProps) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -50,7 +51,23 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
}
}, []);

const asset = preset?.asset_bed.asset_object;
const bedObjectId = props.consultationData.current_bed?.bed_object?.id || "";
const bedsQuery = useQuery(routes.listAssetBeds, {
query: {
bed_object: bedObjectId,
limit: 50,
},
});

const bedLocationId = bed?.location_object?.id;

const matchingAsset = useMemo(() => {
return bedsQuery.data?.results.find(
(bedItem) => bedItem.asset_object?.location_object?.id === bedLocationId,
)?.asset_object;
}, [bedsQuery.data, bedLocationId]);

const asset = preset?.asset_bed?.asset_object ?? matchingAsset;

const { key, operate } = useOperateCamera(asset?.id ?? "");

Expand Down Expand Up @@ -149,6 +166,10 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => {
return <Loading />;
}

if (bedsQuery.loading) {
return <div>Loading bed/asset...</div>;
}

if (!bed || !asset) {
return <span>No bed/asset linked allocated</span>;
}
Expand Down

0 comments on commit 158b07e

Please sign in to comment.