From 8c5f324fe762d25a0d20bbffd52089bb68c17b67 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Fri, 20 Oct 2023 22:42:35 +0530 Subject: [PATCH 01/14] change the NIBP display from last 30 mins to currect bed assignment date --- .../ConsultationUpdatesTab.tsx | 1 + src/Components/Facility/models.tsx | 21 ++++++++++ .../VitalsMonitor/HL7PatientVitalsMonitor.tsx | 38 ++++++++++++++++++- src/Components/VitalsMonitor/types.ts | 1 + src/Redux/api.tsx | 8 +++- 5 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx index 1b89f3980e1..4154521e128 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx @@ -113,6 +113,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
; } +export interface consultationBedRequest { + bed?: string; + consultation: string; + limit?: number; + offset?: number; +} + +export interface consultationBedResponse { + count: number; + next: string; + previous: string; + results: CurrentBed[]; + is_occuiped?: boolean; + created_date?: string; + modified_date?: string; + name?: string; + description?: string; + meta?: Record; + assets_objects?: AssetData[]; +} + // Voluntarily made as `type` for it to achieve type-safety when used with // `useAsyncOptions` export type ICD11DiagnosisModel = { diff --git a/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx b/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx index 44cadd8263c..020829515ee 100644 --- a/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx +++ b/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx @@ -1,4 +1,4 @@ -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import useHL7VitalsMonitor from "./useHL7VitalsMonitor"; import { Link } from "raviger"; import { GENDER_TYPES } from "../../Common/constants"; @@ -9,6 +9,8 @@ import { IVitalsComponentProps, VitalsValueBase } from "./types"; import { triggerGoal } from "../../Integrations/Plausible"; import useAuthUser from "../../Common/hooks/useAuthUser"; import dayjs from "dayjs"; +import useQuery from "../../Utils/request/useQuery"; +import routes from "../../Redux/api"; const minutesAgo = (timestamp: string) => { return `${dayjs().diff(dayjs(timestamp), "minute")}m ago`; @@ -25,6 +27,32 @@ export default function HL7PatientVitalsMonitor(props: IVitalsComponentProps) { const { patient, bed, asset } = props.patientAssetBed ?? {}; const authUser = useAuthUser(); + const [bedAssignmentStartDate, setBedAssignmentStartDate] = useState( + new Date() + ); + + const { + res: bedsRes, + data: bedsData, + refetch: bedsFetch, + } = useQuery(routes.listConsultationBeds, { + query: { + consultation: props.consultationId, + }, + }); + + useEffect(() => { + if (!bedsData) console.log("error"); + else { + const startDate = new Date(bedsData.results[0].created_date); + setBedAssignmentStartDate(startDate); + } + }, [props.consultationId, bedsRes, bedsData]); + + useEffect(() => { + bedsFetch(); + }, [bedsFetch]); + useEffect(() => { if (isOnline) { triggerGoal("Device Viewed", { @@ -39,8 +67,14 @@ export default function HL7PatientVitalsMonitor(props: IVitalsComponentProps) { connect(props.socketUrl); }, [props.socketUrl]); + const currentDate = new Date(); + const timeDifferenceInMinutes = + (currentDate.getTime() - bedAssignmentStartDate.getTime()) / (1000 * 60); + console.log("Time difference in minutes: ", timeDifferenceInMinutes); + // Check if the time difference is within the specified maximum persistence time const bpWithinMaxPersistence = !!( - (data.bp?.["date-time"] && isWithinMinutes(data.bp?.["date-time"], 30)) // Max blood pressure persistence is 30 minutes + data.bp?.["date-time"] && + isWithinMinutes(data.bp?.["date-time"], timeDifferenceInMinutes) ); return ( diff --git a/src/Components/VitalsMonitor/types.ts b/src/Components/VitalsMonitor/types.ts index 60979a6f9b0..dc102788354 100644 --- a/src/Components/VitalsMonitor/types.ts +++ b/src/Components/VitalsMonitor/types.ts @@ -46,6 +46,7 @@ export interface ChannelOptions { } export interface IVitalsComponentProps { + consultationId?: string; patientAssetBed?: PatientAssetBed; socketUrl: string; config?: ReturnType; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 8a4ca5cf1df..0f7a7425356 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -1,6 +1,10 @@ import { IConfig } from "../Common/hooks/useConfig"; import { AssetData } from "../Components/Assets/AssetTypes"; -import { LocationModel } from "../Components/Facility/models"; +import { + LocationModel, + consultationBedRequest, + consultationBedResponse, +} from "../Components/Facility/models"; import { Prescription } from "../Components/Medicine/models"; import { UserModel } from "../Components/Users/models"; import { PaginatedResponse } from "../Utils/request/types"; @@ -299,6 +303,8 @@ const routes = { listConsultationBeds: { path: "/api/v1/consultationbed/", method: "GET", + TRes: Type(), + TBody: Type(), }, createConsultationBed: { path: "/api/v1/consultationbed/", From 5315c821908e972fcefaedccdf1faa7803247a1a Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sun, 22 Oct 2023 12:23:27 +0530 Subject: [PATCH 02/14] change model name to PascalCase and used PaginatedResponse to wrap the model --- src/Components/Facility/models.tsx | 9 +++------ src/Redux/api.tsx | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index 72a9fd5c8b1..04e4fdc677c 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -3,6 +3,7 @@ import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; import { AssetData } from "../Assets/AssetTypes"; import { UserBareMinimum } from "../Users/models"; +import { PaginatedResponse } from "../../Utils/request/types"; export interface LocalBodyModel { name: string; @@ -218,18 +219,14 @@ export interface CurrentBed { meta: Record; } -export interface consultationBedRequest { +export interface ConsultationBedRequest { bed?: string; consultation: string; limit?: number; offset?: number; } -export interface consultationBedResponse { - count: number; - next: string; - previous: string; - results: CurrentBed[]; +export interface ConsultationBedResponse extends PaginatedResponse { is_occuiped?: boolean; created_date?: string; modified_date?: string; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 0f7a7425356..961fcc91639 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -2,8 +2,8 @@ import { IConfig } from "../Common/hooks/useConfig"; import { AssetData } from "../Components/Assets/AssetTypes"; import { LocationModel, - consultationBedRequest, - consultationBedResponse, + ConsultationBedRequest, + ConsultationBedResponse, } from "../Components/Facility/models"; import { Prescription } from "../Components/Medicine/models"; import { UserModel } from "../Components/Users/models"; @@ -303,8 +303,8 @@ const routes = { listConsultationBeds: { path: "/api/v1/consultationbed/", method: "GET", - TRes: Type(), - TBody: Type(), + TRes: Type(), + TBody: Type(), }, createConsultationBed: { path: "/api/v1/consultationbed/", From acbe0c35966fbd93f4e65b7462034820a824c644 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sun, 22 Oct 2023 12:54:51 +0530 Subject: [PATCH 03/14] use onResponse for useQuery --- .../VitalsMonitor/HL7PatientVitalsMonitor.tsx | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx b/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx index 020829515ee..9413165c7ca 100644 --- a/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx +++ b/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx @@ -31,28 +31,20 @@ export default function HL7PatientVitalsMonitor(props: IVitalsComponentProps) { new Date() ); - const { - res: bedsRes, - data: bedsData, - refetch: bedsFetch, - } = useQuery(routes.listConsultationBeds, { + useQuery(routes.listConsultationBeds, { query: { consultation: props.consultationId, }, + onResponse: ({ res, data }) => { + if (res?.ok && data) { + const startDate = new Date(data.results[0].created_date); + setBedAssignmentStartDate(startDate); + } else { + console.log("No beds found for this consultation"); + } + }, }); - useEffect(() => { - if (!bedsData) console.log("error"); - else { - const startDate = new Date(bedsData.results[0].created_date); - setBedAssignmentStartDate(startDate); - } - }, [props.consultationId, bedsRes, bedsData]); - - useEffect(() => { - bedsFetch(); - }, [bedsFetch]); - useEffect(() => { if (isOnline) { triggerGoal("Device Viewed", { From 25e04a425c061e3102e350832e882f68f3dc9d70 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sun, 22 Oct 2023 13:01:56 +0530 Subject: [PATCH 04/14] resolved merge conflict --- src/Redux/api.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index c8620352629..9304101ed6a 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -29,6 +29,8 @@ import { AssetUpdate, } from "../Components/Assets/AssetTypes"; import { + ConsultationBedRequest, + ConsultationBedResponse, FacilityModel, LocationModel, WardModel, From 2d2a6f4421250af52f003938be26957d3e9b5307 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sun, 22 Oct 2023 15:26:26 +0530 Subject: [PATCH 05/14] move bed assignment date fetch logic to parent component --- .../ConsultationUpdatesTab.tsx | 25 +++++++++++++++- .../VitalsMonitor/HL7PatientVitalsMonitor.tsx | 30 +++---------------- src/Components/VitalsMonitor/types.ts | 2 +- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx index 4154521e128..e35c2b84a0d 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx @@ -13,6 +13,8 @@ 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 useQuery from "../../../Utils/request/useQuery"; +import routes from "../../../Redux/api"; const PageTitle = lazy(() => import("../../Common/PageTitle")); @@ -23,6 +25,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { const [ventilatorSocketUrl, setVentilatorSocketUrl] = useState(); const [monitorBedData, setMonitorBedData] = useState(); const [ventilatorBedData, setVentilatorBedData] = useState(); + const [bedAssignmentStartDate, setBedAssignmentStartDate] = useState( + new Date() + ); const vitals = useVitalsAspectRatioConfig({ default: undefined, @@ -104,6 +109,24 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { fetchData(); }, [props.consultationData]); + useQuery(routes.listConsultationBeds, { + query: { + consultation: props.consultationId, + }, + onResponse: ({ res, data }) => { + if (res?.ok && data) { + const startDate = new Date(data.results[0].created_date); + setBedAssignmentStartDate(startDate); + } else { + console.log("No beds found for this consultation"); + } + }, + }); + + const currentDate = new Date(); + const timeDifferenceInMinutes = + (currentDate.getTime() - bedAssignmentStartDate.getTime()) / (1000 * 60); + return (
{!props.consultationData.discharge_date && @@ -113,7 +136,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
{ return `${dayjs().diff(dayjs(timestamp), "minute")}m ago`; @@ -27,24 +25,6 @@ export default function HL7PatientVitalsMonitor(props: IVitalsComponentProps) { const { patient, bed, asset } = props.patientAssetBed ?? {}; const authUser = useAuthUser(); - const [bedAssignmentStartDate, setBedAssignmentStartDate] = useState( - new Date() - ); - - useQuery(routes.listConsultationBeds, { - query: { - consultation: props.consultationId, - }, - onResponse: ({ res, data }) => { - if (res?.ok && data) { - const startDate = new Date(data.results[0].created_date); - setBedAssignmentStartDate(startDate); - } else { - console.log("No beds found for this consultation"); - } - }, - }); - useEffect(() => { if (isOnline) { triggerGoal("Device Viewed", { @@ -59,14 +39,12 @@ export default function HL7PatientVitalsMonitor(props: IVitalsComponentProps) { connect(props.socketUrl); }, [props.socketUrl]); - const currentDate = new Date(); - const timeDifferenceInMinutes = - (currentDate.getTime() - bedAssignmentStartDate.getTime()) / (1000 * 60); - console.log("Time difference in minutes: ", timeDifferenceInMinutes); // Check if the time difference is within the specified maximum persistence time + console.log("Time difference in minutes: ", props.minutesSinceAssignment); const bpWithinMaxPersistence = !!( data.bp?.["date-time"] && - isWithinMinutes(data.bp?.["date-time"], timeDifferenceInMinutes) + props.minutesSinceAssignment && + isWithinMinutes(data.bp?.["date-time"], props.minutesSinceAssignment) ); return ( diff --git a/src/Components/VitalsMonitor/types.ts b/src/Components/VitalsMonitor/types.ts index dc102788354..471f7af9585 100644 --- a/src/Components/VitalsMonitor/types.ts +++ b/src/Components/VitalsMonitor/types.ts @@ -46,7 +46,7 @@ export interface ChannelOptions { } export interface IVitalsComponentProps { - consultationId?: string; + minutesSinceAssignment?: number; patientAssetBed?: PatientAssetBed; socketUrl: string; config?: ReturnType; From 6378a4ac7643f59694477b449dec3aef94a67381 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sun, 22 Oct 2023 18:29:41 +0530 Subject: [PATCH 06/14] replaced console log with notification for error --- .../Facility/ConsultationDetails/ConsultationUpdatesTab.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx index e35c2b84a0d..1c589db863f 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx @@ -15,6 +15,7 @@ import ReadMore from "../../Common/components/Readmore"; import { DailyRoundsList } from "../Consultations/DailyRoundsList"; import useQuery from "../../../Utils/request/useQuery"; import routes from "../../../Redux/api"; +import * as Notification from "../../../Utils/Notifications.js"; const PageTitle = lazy(() => import("../../Common/PageTitle")); @@ -118,7 +119,9 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { const startDate = new Date(data.results[0].created_date); setBedAssignmentStartDate(startDate); } else { - console.log("No beds found for this consultation"); + Notification.Error({ + msg: "Something went wrong: ", + }); } }, }); From 75addd7262a3d310d4cd7539f226fcf53d949a1d Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Mon, 23 Oct 2023 13:11:49 +0530 Subject: [PATCH 07/14] change logic by passing date to VitalsMonitor and change models --- .../ConsultationUpdatesTab.tsx | 13 +++---------- src/Components/Facility/models.tsx | 10 +--------- .../VitalsMonitor/HL7PatientVitalsMonitor.tsx | 17 ++++++++++++++--- src/Components/VitalsMonitor/types.ts | 2 +- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx index 1c589db863f..935e0931f69 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx @@ -26,9 +26,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { const [ventilatorSocketUrl, setVentilatorSocketUrl] = useState(); const [monitorBedData, setMonitorBedData] = useState(); const [ventilatorBedData, setVentilatorBedData] = useState(); - const [bedAssignmentStartDate, setBedAssignmentStartDate] = useState( - new Date() - ); + const [bedAssignmentStartDate, setBedAssignmentStartDate] = useState(""); const vitals = useVitalsAspectRatioConfig({ default: undefined, @@ -116,8 +114,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { }, onResponse: ({ res, data }) => { if (res?.ok && data) { - const startDate = new Date(data.results[0].created_date); - setBedAssignmentStartDate(startDate); + setBedAssignmentStartDate(data.results[0].created_date); } else { Notification.Error({ msg: "Something went wrong: ", @@ -126,10 +123,6 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { }, }); - const currentDate = new Date(); - const timeDifferenceInMinutes = - (currentDate.getTime() - bedAssignmentStartDate.getTime()) / (1000 * 60); - return (
{!props.consultationData.discharge_date && @@ -139,7 +132,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
{ - is_occuiped?: boolean; - created_date?: string; - modified_date?: string; - name?: string; - description?: string; - meta?: Record; - assets_objects?: AssetData[]; -} +export type ConsultationBedResponse = PaginatedResponse; // Voluntarily made as `type` for it to achieve type-safety when used with // `useAsyncOptions` diff --git a/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx b/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx index caefa1949c6..6f3c2570a13 100644 --- a/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx +++ b/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx @@ -40,11 +40,22 @@ export default function HL7PatientVitalsMonitor(props: IVitalsComponentProps) { }, [props.socketUrl]); // Check if the time difference is within the specified maximum persistence time - console.log("Time difference in minutes: ", props.minutesSinceAssignment); + const currentDate = new Date(); + const bedAssignmentStartDate = props.patientCurrentBedAssignmentDate + ? new Date(props.patientCurrentBedAssignmentDate) + : undefined; + + const minutesSinceCurrentBedAssignment = + bedAssignmentStartDate && + (currentDate.getTime() - bedAssignmentStartDate.getTime()) / (1000 * 60); + console.log( + "minutesSinceCurrentBedAssignment", + minutesSinceCurrentBedAssignment + ); const bpWithinMaxPersistence = !!( data.bp?.["date-time"] && - props.minutesSinceAssignment && - isWithinMinutes(data.bp?.["date-time"], props.minutesSinceAssignment) + minutesSinceCurrentBedAssignment !== undefined && // Check if minutesSinceCurrentBedAssignment is defined + isWithinMinutes(data.bp?.["date-time"], minutesSinceCurrentBedAssignment) ); return ( diff --git a/src/Components/VitalsMonitor/types.ts b/src/Components/VitalsMonitor/types.ts index 471f7af9585..c73d7399b59 100644 --- a/src/Components/VitalsMonitor/types.ts +++ b/src/Components/VitalsMonitor/types.ts @@ -46,7 +46,7 @@ export interface ChannelOptions { } export interface IVitalsComponentProps { - minutesSinceAssignment?: number; + patientCurrentBedAssignmentDate?: string; patientAssetBed?: PatientAssetBed; socketUrl: string; config?: ReturnType; From e52c1ee4145fdc7a53ce8bbcac34e3088b3c11bd Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Wed, 25 Oct 2023 22:17:02 +0530 Subject: [PATCH 08/14] remove unused models and useState variables --- .../ConsultationUpdatesTab.tsx | 18 +++--------------- src/Components/Facility/models.tsx | 10 ---------- .../VitalsMonitor/HL7PatientVitalsMonitor.tsx | 4 ---- src/Redux/api.tsx | 6 ++---- 4 files changed, 5 insertions(+), 33 deletions(-) diff --git a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx index 935e0931f69..e9f91fd21e4 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx @@ -15,7 +15,6 @@ import ReadMore from "../../Common/components/Readmore"; import { DailyRoundsList } from "../Consultations/DailyRoundsList"; import useQuery from "../../../Utils/request/useQuery"; import routes from "../../../Redux/api"; -import * as Notification from "../../../Utils/Notifications.js"; const PageTitle = lazy(() => import("../../Common/PageTitle")); @@ -26,7 +25,6 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { const [ventilatorSocketUrl, setVentilatorSocketUrl] = useState(); const [monitorBedData, setMonitorBedData] = useState(); const [ventilatorBedData, setVentilatorBedData] = useState(); - const [bedAssignmentStartDate, setBedAssignmentStartDate] = useState(""); const vitals = useVitalsAspectRatioConfig({ default: undefined, @@ -108,20 +106,10 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { fetchData(); }, [props.consultationData]); - useQuery(routes.listConsultationBeds, { - query: { - consultation: props.consultationId, - }, - onResponse: ({ res, data }) => { - if (res?.ok && data) { - setBedAssignmentStartDate(data.results[0].created_date); - } else { - Notification.Error({ - msg: "Something went wrong: ", - }); - } - }, + const { data } = useQuery(routes.listConsultationBeds, { + query: { consultation: props.consultationId }, }); + const bedAssignmentStartDate = data?.results[0].created_date ?? ""; return (
diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index 31b4b7fabb1..a9861a4869c 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -3,7 +3,6 @@ import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; import { AssetData } from "../Assets/AssetTypes"; import { UserBareMinimum } from "../Users/models"; -import { PaginatedResponse } from "../../Utils/request/types"; export interface LocalBodyModel { name: string; @@ -223,15 +222,6 @@ export interface CurrentBed { meta: Record; } -export interface ConsultationBedRequest { - bed?: string; - consultation: string; - limit?: number; - offset?: number; -} - -export type ConsultationBedResponse = PaginatedResponse; - // Voluntarily made as `type` for it to achieve type-safety when used with // `useAsyncOptions` export type ICD11DiagnosisModel = { diff --git a/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx b/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx index 6f3c2570a13..fee3588c333 100644 --- a/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx +++ b/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx @@ -48,10 +48,6 @@ export default function HL7PatientVitalsMonitor(props: IVitalsComponentProps) { const minutesSinceCurrentBedAssignment = bedAssignmentStartDate && (currentDate.getTime() - bedAssignmentStartDate.getTime()) / (1000 * 60); - console.log( - "minutesSinceCurrentBedAssignment", - minutesSinceCurrentBedAssignment - ); const bpWithinMaxPersistence = !!( data.bp?.["date-time"] && minutesSinceCurrentBedAssignment !== undefined && // Check if minutesSinceCurrentBedAssignment is defined diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 9304101ed6a..ea9a7be2752 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -29,8 +29,7 @@ import { AssetUpdate, } from "../Components/Assets/AssetTypes"; import { - ConsultationBedRequest, - ConsultationBedResponse, + CurrentBed, FacilityModel, LocationModel, WardModel, @@ -353,8 +352,7 @@ const routes = { listConsultationBeds: { path: "/api/v1/consultationbed/", method: "GET", - TRes: Type(), - TBody: Type(), + TRes: Type>(), }, createConsultationBed: { path: "/api/v1/consultationbed/", From 5371c69f92100adaee5e416250474724de13bf59 Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Fri, 27 Oct 2023 13:07:47 +0530 Subject: [PATCH 09/14] 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/", From f0d0c98ab0a13ff1df89367c4b91803bd8a5bb4f Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sat, 28 Oct 2023 20:15:59 +0530 Subject: [PATCH 10/14] Reverted last commit --- .../Facility/CentralNursingStation.tsx | 34 +------------------ src/Redux/api.tsx | 2 -- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/src/Components/Facility/CentralNursingStation.tsx b/src/Components/Facility/CentralNursingStation.tsx index d0296e3cdd6..0d510d8459e 100644 --- a/src/Components/Facility/CentralNursingStation.tsx +++ b/src/Components/Facility/CentralNursingStation.tsx @@ -24,8 +24,6 @@ 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; @@ -53,9 +51,6 @@ 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(() => { @@ -123,32 +118,6 @@ 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, @@ -301,10 +270,9 @@ export default function CentralNursingStation({ facilityId }: Props) {
) : (
- {data.map((props, idx) => ( + {data.map((props) => (
>(), }, createConsultation: { path: "/api/v1/consultation/", From d6889c614f798582c5f5c94ad9802bede513ac0d Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Sat, 28 Oct 2023 21:22:04 +0530 Subject: [PATCH 11/14] update the CNS to pass the correct bedAssignmentStartDate to the VitalsMonitor component --- src/Components/Facility/CentralNursingStation.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Components/Facility/CentralNursingStation.tsx b/src/Components/Facility/CentralNursingStation.tsx index 0d510d8459e..26bed83635b 100644 --- a/src/Components/Facility/CentralNursingStation.tsx +++ b/src/Components/Facility/CentralNursingStation.tsx @@ -273,6 +273,10 @@ export default function CentralNursingStation({ facilityId }: Props) { {data.map((props) => (
Date: Sat, 28 Oct 2023 22:19:32 +0530 Subject: [PATCH 12/14] remove usage of useQuery and replaced the prop with existing data --- .../ConsultationDetails/ConsultationUpdatesTab.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx index e9f91fd21e4..4b3b5527bb8 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx @@ -13,8 +13,6 @@ 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 useQuery from "../../../Utils/request/useQuery"; -import routes from "../../../Redux/api"; const PageTitle = lazy(() => import("../../Common/PageTitle")); @@ -106,11 +104,6 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => { fetchData(); }, [props.consultationData]); - const { data } = useQuery(routes.listConsultationBeds, { - query: { consultation: props.consultationId }, - }); - const bedAssignmentStartDate = data?.results[0].created_date ?? ""; - return (
{!props.consultationData.discharge_date && @@ -120,7 +113,10 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
Date: Wed, 1 Nov 2023 15:17:13 +0530 Subject: [PATCH 13/14] fix NIBP visibility bug in Vitals Monitor --- .../ConsultationUpdatesTab.tsx | 4 ++++ .../VitalsMonitor/HL7PatientVitalsMonitor.tsx | 23 ++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx index 4b3b5527bb8..259e8aca622 100644 --- a/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx +++ b/src/Components/Facility/ConsultationDetails/ConsultationUpdatesTab.tsx @@ -154,6 +154,10 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
{ return `${dayjs().diff(dayjs(timestamp), "minute")}m ago`; }; -const isWithinMinutes = (timestamp: string, minutes: number) => { - return dayjs().diff(dayjs(timestamp), "minute") < minutes; +const isWithinMinutes = (timestamp: string, bedAssignmentStartDate: string) => { + return ( + dayjs().diff(dayjs(timestamp), "minute") < + dayjs().diff(dayjs(bedAssignmentStartDate), "minute") + ); }; export default function HL7PatientVitalsMonitor(props: IVitalsComponentProps) { @@ -39,19 +42,13 @@ export default function HL7PatientVitalsMonitor(props: IVitalsComponentProps) { connect(props.socketUrl); }, [props.socketUrl]); - // Check if the time difference is within the specified maximum persistence time - const currentDate = new Date(); - const bedAssignmentStartDate = props.patientCurrentBedAssignmentDate - ? new Date(props.patientCurrentBedAssignmentDate) - : undefined; - - const minutesSinceCurrentBedAssignment = - bedAssignmentStartDate && - (currentDate.getTime() - bedAssignmentStartDate.getTime()) / (1000 * 60); const bpWithinMaxPersistence = !!( data.bp?.["date-time"] && - minutesSinceCurrentBedAssignment !== undefined && // Check if minutesSinceCurrentBedAssignment is defined - isWithinMinutes(data.bp?.["date-time"], minutesSinceCurrentBedAssignment) + props.patientCurrentBedAssignmentDate && + isWithinMinutes( + data.bp?.["date-time"], + props.patientCurrentBedAssignmentDate + ) ); return ( From 4a34fb34999077c47c4fd31abf4d857c8ff2a23b Mon Sep 17 00:00:00 2001 From: sriharsh05 Date: Mon, 6 Nov 2023 19:35:39 +0530 Subject: [PATCH 14/14] delete unused function --- .../VitalsMonitor/HL7PatientVitalsMonitor.tsx | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx b/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx index 5eec6aca4b5..071da764676 100644 --- a/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx +++ b/src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx @@ -14,13 +14,6 @@ const minutesAgo = (timestamp: string) => { return `${dayjs().diff(dayjs(timestamp), "minute")}m ago`; }; -const isWithinMinutes = (timestamp: string, bedAssignmentStartDate: string) => { - return ( - dayjs().diff(dayjs(timestamp), "minute") < - dayjs().diff(dayjs(bedAssignmentStartDate), "minute") - ); -}; - export default function HL7PatientVitalsMonitor(props: IVitalsComponentProps) { const { connect, waveformCanvas, data, isOnline } = useHL7VitalsMonitor( props.config @@ -42,13 +35,8 @@ export default function HL7PatientVitalsMonitor(props: IVitalsComponentProps) { connect(props.socketUrl); }, [props.socketUrl]); - const bpWithinMaxPersistence = !!( - data.bp?.["date-time"] && - props.patientCurrentBedAssignmentDate && - isWithinMinutes( - data.bp?.["date-time"], - props.patientCurrentBedAssignmentDate - ) + const bpWithinMaxPersistence = dayjs(data.bp?.["date-time"]).isAfter( + props.patientCurrentBedAssignmentDate ); return (