diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx index 593afdb137c..8c19928fbee 100644 --- a/src/Components/Assets/AssetsList.tsx +++ b/src/Components/Assets/AssetsList.tsx @@ -65,7 +65,7 @@ const AssetsList = () => { status: qParams.status || "", }; - useQuery(routes.listAssets, { + const { loading } = useQuery(routes.listAssets, { query: params, onResponse: ({ res, data }) => { if (res?.status === 200 && data) { @@ -176,7 +176,13 @@ const AssetsList = () => { ); let manageAssets = null; - if (assetsExist) { + if (loading) { + manageAssets = ( +
+ +
+ ); + } else if (assetsExist) { manageAssets = (
{assets.map((asset: AssetData) => ( @@ -309,7 +315,7 @@ const AssetsList = () => { diff --git a/src/Components/Facility/ConsultationDetails/index.tsx b/src/Components/Facility/ConsultationDetails/index.tsx index 6fda874e3b3..f2ef13fa833 100644 --- a/src/Components/Facility/ConsultationDetails/index.tsx +++ b/src/Components/Facility/ConsultationDetails/index.tsx @@ -8,6 +8,7 @@ import { ConsultationModel, ICD11DiagnosisModel } from "../models"; import { getConsultation, getPatient, + listAssetBeds, listShiftRequests, } from "../../../Redux/actions"; import { statusType, useAbortableEffect } from "../../../Common/utils"; @@ -88,6 +89,7 @@ export const ConsultationDetails = (props: any) => { const [openDischargeSummaryDialog, setOpenDischargeSummaryDialog] = useState(false); const [openDischargeDialog, setOpenDischargeDialog] = useState(false); + const [isCameraAttached, setIsCameraAttached] = useState(false); const getPatientGender = (patientData: any) => GENDER_TYPES.find((i) => i.id === patientData.gender)?.text; @@ -126,6 +128,17 @@ export const ConsultationDetails = (props: any) => { data.symptoms_text = symptoms.join(", "); } setConsultationData(data); + const assetRes = await dispatch( + listAssetBeds({ + bed: data?.current_bed?.bed_object?.id, + }) + ); + const isCameraAttachedRes = assetRes.data.results.some( + (asset: { asset_object: { asset_class: string } }) => { + return asset?.asset_object?.asset_class === "ONVIF"; + } + ); + setIsCameraAttached(isCameraAttachedRes); const id = res.data.patient; const patientRes = await dispatch(getPatient({ id })); if (patientRes?.data) { @@ -336,6 +349,7 @@ export const ConsultationDetails = (props: any) => { Doctor Connect {patientData.last_consultation?.id && + isCameraAttached && ["DistrictAdmin", "StateAdmin", "Doctor"].includes( authUser.user_type ) && ( @@ -507,6 +521,7 @@ export const ConsultationDetails = (props: any) => { {CONSULTATION_TABS.map((p: OptionsType) => { if (p.text === "FEED") { if ( + isCameraAttached === false || // No camera attached consultationData?.discharge_date || // Discharged !consultationData?.current_bed?.bed_object?.id || // Not admitted to bed !["DistrictAdmin", "StateAdmin", "Doctor"].includes( diff --git a/src/Components/Facility/Consultations/Feed.tsx b/src/Components/Facility/Consultations/Feed.tsx index 3448d85a6a2..ac39be325e9 100644 --- a/src/Components/Facility/Consultations/Feed.tsx +++ b/src/Components/Facility/Consultations/Feed.tsx @@ -124,9 +124,7 @@ export const Feed: React.FC = ({ consultationId, facilityId }) => { ...bedAssets.data, results: bedAssets.data.results.filter( (asset: { asset_object: { meta: { asset_type: string } } }) => { - return asset?.asset_object?.meta?.asset_type === "CAMERA" - ? true - : false; + return asset?.asset_object?.meta?.asset_type === "CAMERA"; } ), }, diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 7a78d94582e..24762d10279 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -49,6 +49,8 @@ import Page from "../Common/components/Page.js"; import dayjs from "dayjs"; import { triggerGoal } from "../../Integrations/Plausible.js"; import useAuthUser from "../../Common/hooks/useAuthUser.js"; +import useQuery from "../../Utils/request/useQuery.js"; +import routes from "../../Redux/api.js"; const Loading = lazy(() => import("../Common/Loading")); @@ -477,6 +479,11 @@ export const PatientManager = () => { [fetchFacilityBadgeName, fetchLocationBadgeName] ); + const { data: permittedFacilities } = useQuery( + routes.getPermittedFacilities, + {} + ); + const LastAdmittedToTypeBadges = () => { const badge = (key: string, value: any, id: string) => { return ( @@ -781,9 +788,13 @@ export const PatientManager = () => { { - qParams.facility - ? navigate(`/facility/${qParams.facility}/patient`) - : setShowDialog(true); + if (qParams.facility) + navigate(`/facility/${qParams.facility}/patient`); + else if (permittedFacilities?.results.length === 1) + navigate( + `/facility/${permittedFacilities?.results[0].id}/patient` + ); + else setShowDialog(true); }} className="w-full lg:w-fit" > diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 43a202e8d04..0e3fabf0bff 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -221,6 +221,7 @@ const routes = { getPermittedFacilities: { path: "/api/v1/facility/", + TRes: Type>(), }, getAllFacilities: {