diff --git a/src/Components/Common/BloodPressureFormField.tsx b/src/Components/Common/BloodPressureFormField.tsx index 3ff2774b900..ad9fdab1d52 100644 --- a/src/Components/Common/BloodPressureFormField.tsx +++ b/src/Components/Common/BloodPressureFormField.tsx @@ -1,3 +1,4 @@ +import { FieldValidator } from "../Form/FieldValidators"; import FormField from "../Form/FormFields/FormField"; import RangeAutocompleteFormField from "../Form/FormFields/RangeAutocompleteFormField"; import { @@ -5,40 +6,36 @@ import { FormFieldBaseProps, useFormFieldPropsResolver, } from "../Form/FormFields/Utils"; +import { DailyRoundsModel } from "../Patient/models"; -export interface BloodPressure { - systolic: number; - diastolic: number; -} +type BloodPressure = NonNullable; -type Props = FormFieldBaseProps>; +type Props = FormFieldBaseProps; export default function BloodPressureFormField(props: Props) { const field = useFormFieldPropsResolver(props as any); const handleChange = (event: FieldChangeEvent) => { - field.onChange({ - name: field.name, - value: { - ...field.value, - [event.name]: event.value ?? -1, - }, - }); + const value: BloodPressure = { + ...field.value, + [event.name]: event.value, + }; + value.mean = meanArterialPressure(value); + field.onChange({ name: field.name, value }); }; const map = !!props.value?.diastolic && !!props.value.systolic && - meanArterialPressure(props.value as BloodPressure); + meanArterialPressure(props.value); return ( MAP: {map.toFixed(1)} - ) : undefined, + labelSuffix: map ? ( + MAP: {map.toFixed(1)} + ) : undefined, }} >
@@ -108,5 +105,19 @@ export const meanArterialPressure = ({ diastolic, systolic, }: BloodPressure) => { - return (2 * diastolic + systolic) / 3; + if (diastolic != null && systolic != null) { + return (2 * diastolic + systolic) / 3; + } +}; + +export const BPValidator: FieldValidator = (bp) => { + if (Object.values(bp).every((v) => v == null)) { + return; + } + if (bp.diastolic == null) { + return "Diastolic is missing. Either specify both or clear both."; + } + if (bp.systolic == null) { + return "Systolic is missing. Either specify both or clear both."; + } }; diff --git a/src/Components/Facility/Consultations/Mews.tsx b/src/Components/Facility/Consultations/Mews.tsx index 5160e42f9f2..14e7d7f9e63 100644 --- a/src/Components/Facility/Consultations/Mews.tsx +++ b/src/Components/Facility/Consultations/Mews.tsx @@ -26,7 +26,6 @@ const getHeartRateScore = (value?: number) => { const getSystolicBPScore = (value?: number) => { if (typeof value !== "number") return; - if (value === -1) return; if (value <= 70) return 3; if (value <= 80) return 2; @@ -38,7 +37,6 @@ const getSystolicBPScore = (value?: number) => { }; const getTempRange = (value?: number) => { - console.log(value); if (typeof value !== "number") return; if (value < 95) return 2; diff --git a/src/Components/Patient/DailyRoundListDetails.tsx b/src/Components/Patient/DailyRoundListDetails.tsx index 0a73607d688..8f313c0a51d 100644 --- a/src/Components/Patient/DailyRoundListDetails.tsx +++ b/src/Components/Patient/DailyRoundListDetails.tsx @@ -158,20 +158,14 @@ export const DailyRoundListDetails = (props: any) => { Systolic:{" "} - {dailyRoundListDetailsData.bp?.systolic && - dailyRoundListDetailsData.bp?.systolic !== -1 - ? dailyRoundListDetailsData.bp?.systolic - : "-"} + {dailyRoundListDetailsData.bp?.systolic ?? "-"}
{" "} Diastolic: - {dailyRoundListDetailsData.bp?.diastolic && - dailyRoundListDetailsData.bp?.diastolic !== -1 - ? dailyRoundListDetailsData.bp?.diastolic - : "-"} + {dailyRoundListDetailsData.bp?.diastolic ?? "-"}
diff --git a/src/Components/Patient/DailyRounds.tsx b/src/Components/Patient/DailyRounds.tsx index c12aea42bee..e727b03ac97 100644 --- a/src/Components/Patient/DailyRounds.tsx +++ b/src/Components/Patient/DailyRounds.tsx @@ -23,7 +23,7 @@ import { DraftSection, useAutoSaveReducer } from "../../Utils/AutoSave"; import * as Notification from "../../Utils/Notifications"; import { formatDateTime } from "../../Utils/utils"; import BloodPressureFormField, { - meanArterialPressure, + BPValidator, } from "../Common/BloodPressureFormField"; import { SymptomsSelect } from "../Common/SymptomsSelect"; import TemperatureFormField from "../Common/TemperatureFormField"; @@ -63,9 +63,9 @@ const initForm: any = { ventilator_spo2: null, consciousness_level: "UNKNOWN", bp: { - systolic: -1, - diastolic: -1, - mean: -1, + systolic: undefined, + diastolic: undefined, + mean: undefined, }, // bed: null, }; @@ -140,6 +140,8 @@ export const DailyRounds = (props: any) => { "consciousness_level", ]; + console.log(state.form.bp); + const fetchRoundDetails = useCallback( async (status: statusType) => { setIsLoading(true); @@ -247,18 +249,14 @@ export const DailyRounds = (props: any) => { invalidForm = true; } return; - case "bp": - if ( - (state.form.bp?.systolic && - state.form.bp?.diastolic && - state.form.bp.systolic !== -1 && - state.form.bp.diastolic === -1) || - (state.form.bp.systolic === -1 && state.form.bp.diastolic !== -1) - ) { - errors.bp = "Please enter both systolic and diastolic values"; + case "bp": { + const error = BPValidator(state.form.bp); + if (error) { + errors.bp = error; invalidForm = true; } return; + } default: return; } @@ -303,27 +301,7 @@ export const DailyRounds = (props: any) => { if (["NORMAL", "TELEMEDICINE"].includes(state.form.rounds_type)) { data = { ...data, - bp: - state.form.bp?.systolic !== -1 && state.form.bp?.diastolic !== -1 - ? { - systolic: state.form.bp?.systolic - ? Number(state.form.bp?.systolic) - : -1, - diastolic: state.form.bp?.diastolic - ? Number(state.form.bp?.diastolic) - : -1, - mean: - state.form.bp?.systolic && state.form.bp?.diastolic - ? parseFloat( - meanArterialPressure(state.form.bp).toFixed(2) - ) - : -1, - } - : { - systolic: -1, - diastolic: -1, - mean: -1, - }, + bp: state.form.bp ?? {}, pulse: state.form.pulse ?? null, resp: state.form.resp ?? null, temperature: state.form.temperature ?? null, diff --git a/src/Components/Patient/models.tsx b/src/Components/Patient/models.tsx index e1ce5d53050..fc87bedcb14 100644 --- a/src/Components/Patient/models.tsx +++ b/src/Components/Patient/models.tsx @@ -282,9 +282,9 @@ export interface DailyRoundsModel { rhythm?: string; rhythm_detail?: string; bp?: { - diastolic: number; - mean: number; - systolic: number; + diastolic?: number; + mean?: number; + systolic?: number; }; pulse?: number; resp?: number; @@ -297,7 +297,7 @@ export interface DailyRoundsModel { medication_given?: Array; additional_symptoms_text?: string; current_health?: string; - id: string; + id?: string; other_symptoms?: string; admitted_to?: string; patient_category?: PatientCategory; @@ -314,7 +314,7 @@ export interface DailyRoundsModel { | "AGITATED_OR_CONFUSED" | "ONSET_OF_AGITATION_AND_CONFUSION" | "UNKNOWN"; - rounds_type: (typeof DailyRoundTypes)[number]; + rounds_type?: (typeof DailyRoundTypes)[number]; last_updated_by_telemedicine?: boolean; created_by_telemedicine?: boolean; created_by?: {