Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displaying camera feed without preset in Patient consultation page#8901 #8922

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
});

Comment on lines +55 to +60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use proper names to avoid confusions. You are using the Asset Beds list API and not Beds list API.

Suggested change
const bedsQuery = useQuery(routes.listAssetBeds, {
query: {
bed_object: bedObjectId,
limit: 50,
},
});
const assetBedsQuery = useQuery(routes.listAssetBeds, {
query: {
bed_object: bedObjectId,
limit: 50,
},
});

Comment on lines +54 to +60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const bedObjectId = props.consultationData.current_bed?.bed_object?.id || "";
const bedsQuery = useQuery(routes.listAssetBeds, {
query: {
bed_object: bedObjectId,
limit: 50,
},
});
const bedId = props.consultationData.current_bed?.bed_object?.id;
const bedsQuery = useQuery(routes.listAssetBeds, {
query: {
bed_object: bedId ?? "",
limit: 50,
},
prefetch: !!bedId,
});

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]);

Comment on lines +62 to +68
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if bedsQuery (better known as assetBedsQuery) is already filtered by a bed, why filter by location? We do not allow linking an asset with a bed with different locations anyhow in the first place.

Suggested change
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]);

Copy link
Contributor Author

@Mahendar0701 Mahendar0701 Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rithviknishad
Now i found that assetBedsQuery is not filtering by bed.

I need to filter the fetched values by bedId and asset_class.

const filteredAssets = useMemo(() => {
  return assetBedsQuery.data?.results.filter(
    (bedItem) =>
      bedItem.bed_object?.id === bedId &&
      bedItem.asset_object?.asset_class === "ONVIF"
  );
}, [assetBedsQuery.data, bedId]);

However, I have a question: if a bed has multiple cameras, should I display all camera assets? I am getting multiple camera assets.

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>;
}

Comment on lines +169 to +171
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add it as an or condition in line 165 along with presetsQuery.loading.

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

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