forked from ohcnetwork/care_fe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
209628d
commit fb7f38f
Showing
4 changed files
with
124 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,191 +1,171 @@ | ||
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 ( | ||
<> | ||
<div className="tooltip mt-2 text-gray-800"> | ||
<p className="my-auto text-center text-2xl font-bold">N/A</p> | ||
<div className="tooltip-text tooltip-left translate-x-1/2 translate-y-1/4 text-xs font-medium"> | ||
<p>Missing : </p> | ||
<div className="flex flex-col items-center justify-center"> | ||
{typeof data !== "number" && | ||
data.map((x, id) => <span key={id}>{x}</span>)} | ||
</div> | ||
<div className="tooltip-text tooltip-bottom w-48 -translate-x-1/2 translate-y-3 whitespace-pre-wrap text-xs font-medium lg:w-64"> | ||
<span className="font-bold">{(data as string[]).join(", ")}</span>{" "} | ||
data is missing from the last log update. | ||
</div> | ||
</div> | ||
<div> | ||
<RecordMeta | ||
time={props.lastDailyRound.modified_date} | ||
time={dailyRound.modified_date} | ||
prefix={"Updated"} | ||
className="mx-auto mt-2 w-10/12 text-xs font-medium text-gray-800" | ||
className="mx-auto mt-2 w-10/12 text-xs font-medium leading-none text-gray-800" | ||
inlineClassName="flex flex-wrap items-center justify-center" | ||
/> | ||
<div className="mt-1 flex h-2 w-full flex-col items-center justify-center rounded-b-lg bg-gray-500"></div> | ||
</div> | ||
</> | ||
); | ||
} else { | ||
const value = Number(data); | ||
return ( | ||
<> | ||
<div className="tooltip mt-2"> | ||
<p className="my-auto text-center text-2xl font-bold">{data}</p> | ||
<div className="tooltip-text tooltip-left translate-x-1/2 translate-y-1/4 text-xs font-medium"> | ||
<p>Resp Rate : {props.lastDailyRound.resp}</p> | ||
<p>Pulse : {props.lastDailyRound.pulse}</p> | ||
<p>Sys BP : {props.lastDailyRound.bp?.systolic}</p> | ||
<p>Temp : {props.lastDailyRound.temperature}</p> | ||
<p>Conscious : </p> | ||
<div className="tooltip-text tooltip-bottom w-48 -translate-x-1/2 translate-y-3 whitespace-pre-wrap text-xs font-medium lg:w-64"> | ||
<p> | ||
Resp. Rate: <span className="font-bold">{dailyRound.resp}</span> | ||
</p> | ||
<p> | ||
Heart Rate:{" "} | ||
<span className="font-bold">{dailyRound.pulse}</span> | ||
</p> | ||
<p> | ||
{props.lastDailyRound.consciousness_level | ||
?.split("_") | ||
.map((x) => x[0] + x.slice(1).toLowerCase()) | ||
.join(" ")} | ||
Systolic BP:{" "} | ||
<span className="font-bold">{dailyRound.bp?.systolic}</span> | ||
</p> | ||
<p> | ||
Temperature:{" "} | ||
<span className="font-bold">{dailyRound.temperature}</span> | ||
</p> | ||
<p> | ||
Consciousness:{" "} | ||
<span className="font-bold capitalize"> | ||
{dailyRound.consciousness_level | ||
?.replaceAll("_", " ") | ||
.toLowerCase()} | ||
</span> | ||
</p> | ||
</div> | ||
</div> | ||
<div> | ||
<RecordMeta | ||
time={props.lastDailyRound.modified_date} | ||
time={dailyRound.modified_date} | ||
prefix={"Updated"} | ||
className="mx-auto mt-2 w-10/12 text-xs font-medium text-gray-800" | ||
className="mx-auto mt-2 w-10/12 text-xs font-medium leading-none text-gray-800" | ||
inlineClassName="flex flex-wrap items-center justify-center" | ||
/> | ||
<div | ||
className={`mt-1 flex h-2 w-full flex-col items-center justify-center rounded-b-lg ${getIndividualScore( | ||
Number(data), | ||
mewsColorRange | ||
)}`} | ||
className={classNames( | ||
"mt-1 flex h-2 w-full flex-col items-center justify-center rounded-b-lg", | ||
value <= 2 && "bg-primary-500", | ||
value <= 3 && "bg-yellow-300", | ||
value <= 5 && "bg-warning-600", | ||
value > 6 && "bg-danger-500" | ||
)} | ||
></div> | ||
</div> | ||
</> | ||
); | ||
} | ||
}; | ||
|
||
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 ( | ||
<div className="flex h-fit flex-col justify-start rounded-lg border border-black"> | ||
<p className="pt-1 text-center font-bold text-gray-900">MEWS Score</p> | ||
{mewsCard( | ||
true, | ||
Object.entries(scores) | ||
.filter(([_, value]) => value === undefined) | ||
.map(([key]) => key) | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex h-fit flex-col justify-start rounded-lg border border-black"> | ||
<p className="pt-1 text-center font-bold text-gray-900">Mews Score</p> | ||
{mewsScore()} | ||
<p className="pt-1 text-center font-bold text-gray-900">MEWS Score</p> | ||
{mewsCard( | ||
false, | ||
Object.values(scores as Record<string, number>).reduce((p, v) => p + v) | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters