From 5371c69f92100adaee5e416250474724de13bf59 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Fri, 27 Oct 2023 13:07:47 +0530 Subject: [PATCH] update the CNS to pass the bedAssignmentStartDate prop to HL7PatientVitalsMonitor component --- .../Facility/CentralNursingStation.tsx | 34 ++++++++++++++++++- src/Redux/api.tsx | 2 ++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/Components/Facility/CentralNursingStation.tsx b/src/Components/Facility/CentralNursingStation.tsx index 0d510d8459e..d0296e3cdd6 100644 --- a/src/Components/Facility/CentralNursingStation.tsx +++ b/src/Components/Facility/CentralNursingStation.tsx @@ -24,6 +24,8 @@ import { useTranslation } from "react-i18next"; import { SortOption } from "../Common/SortDropdown"; import { SelectFormField } from "../Form/FormFields/SelectFormField"; import useVitalsAspectRatioConfig from "../VitalsMonitor/useVitalsAspectRatioConfig"; +import routes from "../../Redux/api"; +import request from "../../Utils/request/request"; const PER_PAGE_LIMIT = 6; @@ -51,6 +53,9 @@ export default function CentralNursingStation({ facilityId }: Props) { const { qParams, updateQuery, removeFilter, updatePage } = useFilters({ limit: PER_PAGE_LIMIT, }); + const [bedAssignmentStartDate, setBedAssignmentStartDate] = useState< + string[] + >([]); // To automatically collapse sidebar. useEffect(() => { @@ -118,6 +123,32 @@ export default function CentralNursingStation({ facilityId }: Props) { qParams.bed_is_occupied, ]); + useEffect(() => { + const fetchDataAndBedAssignmentStartDate = async () => { + if (data && data.length > 0) { + const updatedBedAssignmentStartDate = await Promise.all( + data.map(async (item) => { + const { data: consultationData } = await request( + routes.getConsultationList, + { + query: { patient: item.patientAssetBed?.patient?.id }, + } + ); + const { data: bedData } = await request( + routes.listConsultationBeds, + { + query: { consultation: consultationData?.results[0].id }, + } + ); + return bedData?.results[0].created_date ?? ""; + }) + ); + setBedAssignmentStartDate(updatedBedAssignmentStartDate); + } + }; + fetchDataAndBedAssignmentStartDate(); + }, [data]); + const { config, hash } = useVitalsAspectRatioConfig({ default: 6 / 11, vs: 10 / 11, @@ -270,9 +301,10 @@ export default function CentralNursingStation({ facilityId }: Props) { ) : (
- {data.map((props) => ( + {data.map((props, idx) => (
>(), }, createConsultation: { path: "/api/v1/consultation/",