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 :
-{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()} +
MEWS Score
+ {mewsCard( + true, + Object.entries(scores) + .filter(([_, value]) => value === undefined) + .map(([key]) => key) + )} +Mews Score
- {mewsScore()} +MEWS Score
+ {mewsCard( + false, + Object.values(scores as Record