From fb7f38fdfbf122319de67b5dcf3c30a4f7057e84 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Tue, 12 Dec 2023 16:33:39 +0530 Subject: [PATCH] fix issues during QA --- .../Facility/Consultations/Mews.tsx | 246 ++++++++---------- src/Components/Facility/models.tsx | 4 +- src/Components/Patient/PatientInfoCard.tsx | 2 +- src/Components/Patient/models.tsx | 9 +- 4 files changed, 124 insertions(+), 137 deletions(-) diff --git a/src/Components/Facility/Consultations/Mews.tsx b/src/Components/Facility/Consultations/Mews.tsx index 7ad31d97961..b932c18c9cd 100644 --- a/src/Components/Facility/Consultations/Mews.tsx +++ b/src/Components/Facility/Consultations/Mews.tsx @@ -1,95 +1,82 @@ import { DailyRoundsModel } from "../../Patient/models"; import RecordMeta from "../../../CAREUI/display/RecordMeta"; +import { classNames } from "../../../Utils/utils"; -const respRange = [ - [-Infinity, 7, 2], - [8, 8, 1], - [9, 17, 0], - [18, 20, 1], - [21, 29, 2], - [30, Infinity, 3], -]; +const getRespScore = (value?: number) => { + if (typeof value !== "number") return; -const heartRateRange = [ - [-Infinity, 39, 2], - [40, 50, 1], - [51, 100, 0], - [101, 110, 1], - [111, 129, 2], - [130, Infinity, 3], -]; + if (value < 8) return 2; + if (value <= 8) return 1; + if (value <= 17) return 0; + if (value <= 20) return 1; + if (value <= 29) return 2; + return 3; +}; + +const getHeartRateScore = (value?: number) => { + if (typeof value !== "number") return; -const systolicBloodPressureRange = [ - [-Infinity, 70, 3], - [71, 80, 2], - [81, 100, 1], - [101, 159, 0], - [160, 199, 1], - [200, 220, 2], - [221, Infinity, 3], -]; + if (value < 40) return 2; + if (value <= 50) return 1; + if (value <= 100) return 0; + if (value <= 110) return 1; + if (value <= 129) return 2; + return 3; +}; -const temperatureRange = [ - [-Infinity, 94.9, 2], - [95, 96.8, 1], - [96.9, 100.4, 0], - [100.5, 101.3, 1], - [101.4, Infinity, 2], -]; +const getSystolicBPScore = (value?: number) => { + if (typeof value !== "number") return; -const consciousnessCalculator = (value: string | undefined) => { - switch (value) { - case "ALERT": - return 0; - case "RESPONDS_TO_VOICE": - case "AGITATED_OR_CONFUSED": - return 1; - case "RESPONDS_TO_PAIN": - case "ONSET_OF_AGITATION_AND_CONFUSION": - return 2; - case "UNRESPONSIVE": - return 3; - default: - return undefined; - } + if (value <= 70) return 3; + if (value <= 80) return 2; + if (value <= 100) return 1; + if (value <= 159) return 0; + if (value <= 199) return 1; + if (value <= 220) return 2; + return 3; }; -const mewsColorRange = [ - [0, 2, "bg-primary-500"], - [3, 3, "bg-yellow-300"], - [4, 5, "bg-warning-500"], - [6, Infinity, "bg-danger-500"], -]; +const getTempRange = (value?: number) => { + if (typeof value !== "number") return; -const getIndividualScore = (value: number | undefined, ranges: any[][]) => { - if (value === undefined || value === null) return undefined; - for (const [min, max, score] of ranges) { - if (value >= min && value <= max) { - return score; - } - } + if (value < 95) return 2; + if (value <= 96.8) return 1; + if (value <= 100.4) return 0; + if (value <= 101.3) return 1; + return 2; }; -export const Mews = (props: { lastDailyRound: DailyRoundsModel }) => { +const getLOCRange = (value?: DailyRoundsModel["consciousness_level"]) => { + if (!value) return; + + return { + UNRESPONSIVE: 3, + RESPONDS_TO_PAIN: 2, + RESPONDS_TO_VOICE: 1, + ALERT: 0, + AGITATED_OR_CONFUSED: 1, + ONSET_OF_AGITATION_AND_CONFUSION: 2, + UNKNOWN: undefined, + }[value]; +}; + +export const Mews = ({ dailyRound }: { dailyRound: DailyRoundsModel }) => { const mewsCard = (isMissing: boolean, data: string[] | number) => { if (isMissing) { return ( <>

N/A

-
-

Missing :

-
- {typeof data !== "number" && - data.map((x, id) => {x})} -
+
+ {(data as string[]).join(", ")}{" "} + data is missing from the last log update.
@@ -97,36 +84,52 @@ export const Mews = (props: { lastDailyRound: DailyRoundsModel }) => { ); } else { + const value = Number(data); return ( <>

{data}

-
-

Resp Rate : {props.lastDailyRound.resp}

-

Pulse : {props.lastDailyRound.pulse}

-

Sys BP : {props.lastDailyRound.bp?.systolic}

-

Temp : {props.lastDailyRound.temperature}

-

Conscious :

+
+

+ Resp. Rate: {dailyRound.resp} +

+

+ Heart Rate:{" "} + {dailyRound.pulse} +

- {props.lastDailyRound.consciousness_level - ?.split("_") - .map((x) => x[0] + x.slice(1).toLowerCase()) - .join(" ")} + Systolic BP:{" "} + {dailyRound.bp?.systolic} +

+

+ Temperature:{" "} + {dailyRound.temperature} +

+

+ Consciousness:{" "} + + {dailyRound.consciousness_level + ?.replaceAll("_", " ") + .toLowerCase()} +

6 && "bg-danger-500" + )} >
@@ -134,58 +137,35 @@ export const Mews = (props: { lastDailyRound: DailyRoundsModel }) => { } }; - const mewsScore = () => { - const lastDailyRound = props.lastDailyRound; - - const score = { - resp: getIndividualScore(lastDailyRound?.resp, respRange), - heartRate: getIndividualScore(lastDailyRound?.pulse, heartRateRange), - systolicBloodPressure: getIndividualScore( - lastDailyRound?.bp?.systolic, - systolicBloodPressureRange - ), - temperature: getIndividualScore( - Number(lastDailyRound?.temperature), - temperatureRange - ), - consciousnessLevel: consciousnessCalculator( - lastDailyRound?.consciousness_level - ), - }; - - if ( - score.resp === undefined || - score.heartRate === undefined || - score.systolicBloodPressure === undefined || - score.temperature === undefined || - score.consciousnessLevel === undefined - ) { - return mewsCard( - true, - [ - score.resp === undefined ? "Respiratory rate" : "", - score.heartRate === undefined ? "Heart rate" : "", - score.systolicBloodPressure === undefined ? "Systolic BP" : "", - score.temperature === undefined ? "Temperature" : "", - score.consciousnessLevel === undefined ? "Consciousness" : "", - ].filter((x) => x !== "") - ); - } - - const totalScore = - score.resp + - score.heartRate + - score.systolicBloodPressure + - score.temperature + - score.consciousnessLevel; - - return mewsCard(false, totalScore); + const scores = { + "Respiratory rate": getRespScore(dailyRound.resp), + "Heart rate": getHeartRateScore(dailyRound.pulse), + "Systolic BP": getSystolicBPScore(dailyRound.bp?.systolic), + Temperature: getTempRange(Number(dailyRound.temperature)), + "Level of Consciousness": getLOCRange(dailyRound.consciousness_level), }; + if (Object.values(scores).some((value) => value === undefined)) { + return ( +
+

MEWS Score

+ {mewsCard( + true, + Object.entries(scores) + .filter(([_, value]) => value === undefined) + .map(([key]) => key) + )} +
+ ); + } + return (
-

Mews Score

- {mewsScore()} +

MEWS Score

+ {mewsCard( + false, + Object.values(scores as Record).reduce((p, v) => p + v) + )}
); }; diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index 0d8a112e021..64f79198cf9 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -1,4 +1,4 @@ -import { AssignedToObjectModel } from "../Patient/models"; +import { AssignedToObjectModel, DailyRoundsModel } from "../Patient/models"; import { ProcedureType } from "../Common/prescription-builder/ProcedureBuilder"; import { NormalPrescription, PRNPrescription } from "../Medicine/models"; import { AssetData } from "../Assets/AssetTypes"; @@ -151,7 +151,7 @@ export interface ConsultationModel { ett_tt?: number; cuff_pressure?: number; lines?: any; - last_daily_round?: any; + last_daily_round?: DailyRoundsModel; current_bed?: CurrentBed; review_interval?: number; cause_of_death?: string; diff --git a/src/Components/Patient/PatientInfoCard.tsx b/src/Components/Patient/PatientInfoCard.tsx index d2d4615de9b..adcdcb1a98d 100644 --- a/src/Components/Patient/PatientInfoCard.tsx +++ b/src/Components/Patient/PatientInfoCard.tsx @@ -344,7 +344,7 @@ export default function PatientInfoCard(props: {
{consultation?.last_daily_round && (
- +
)} diff --git a/src/Components/Patient/models.tsx b/src/Components/Patient/models.tsx index ef5a3a01b95..3a856a04765 100644 --- a/src/Components/Patient/models.tsx +++ b/src/Components/Patient/models.tsx @@ -301,7 +301,14 @@ export interface DailyRoundsModel { created_date?: string; modified_date?: string; taken_at?: string; - consciousness_level?: string; + consciousness_level?: + | "UNRESPONSIVE" + | "RESPONDS_TO_PAIN" + | "RESPONDS_TO_VOICE" + | "ALERT" + | "AGITATED_OR_CONFUSED" + | "ONSET_OF_AGITATION_AND_CONFUSION" + | "UNKNOWN"; rounds_type: (typeof DailyRoundTypes)[number]; last_updated_by_telemedicine?: boolean; created_by_telemedicine?: boolean;