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

change the NIBP display from last 30 mins to current bed assignment date #6479

Merged
merged 19 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Expand Up @@ -113,6 +113,7 @@ export const ConsultationUpdatesTab = (props: ConsultationTabProps) => {
<div className="mx-auto flex w-full flex-col justify-between gap-1 rounded bg-[#020617] lg:w-auto lg:min-w-[1280px] lg:flex-row">
<div className="min-h-[400px] flex-1">
<HL7PatientVitalsMonitor
consultationId={props.consultationId}
patientAssetBed={{
asset: monitorBedData?.asset_object as AssetData,
bed: monitorBedData?.bed_object as BedModel,
Expand Down
21 changes: 21 additions & 0 deletions src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,27 @@ export interface CurrentBed {
meta: Record<string, any>;
}

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<string, any>;
assets_objects?: AssetData[];
}
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved

// Voluntarily made as `type` for it to achieve type-safety when used with
// `useAsyncOptions<ICD11DiagnosisModel>`
export type ICD11DiagnosisModel = {
Expand Down
38 changes: 36 additions & 2 deletions src/Components/VitalsMonitor/HL7PatientVitalsMonitor.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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`;
Expand All @@ -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]);
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
bedsFetch();
}, [bedsFetch]);
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
if (isOnline) {
triggerGoal("Device Viewed", {
Expand All @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions src/Components/VitalsMonitor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface ChannelOptions {
}

export interface IVitalsComponentProps {
consultationId?: string;
patientAssetBed?: PatientAssetBed;
socketUrl: string;
config?: ReturnType<typeof getVitalsCanvasSizeAndDuration>;
Expand Down
8 changes: 7 additions & 1 deletion src/Redux/api.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -299,6 +303,8 @@ const routes = {
listConsultationBeds: {
path: "/api/v1/consultationbed/",
method: "GET",
TRes: Type<consultationBedResponse>(),
TBody: Type<consultationBedRequest>(),
},
createConsultationBed: {
path: "/api/v1/consultationbed/",
Expand Down