From fe92b7a54c15314159934e82eff41e65754f3db6 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Sun, 6 Oct 2024 13:43:31 +0530 Subject: [PATCH 01/15] Fix: Updating temp dropdown to textfield --- .../pageobject/Patient/PatientLogupdate.ts | 2 +- src/Components/Patient/DailyRounds.tsx | 83 +++++++++++++++++-- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/cypress/pageobject/Patient/PatientLogupdate.ts b/cypress/pageobject/Patient/PatientLogupdate.ts index add3fbb0590..a5146916b7c 100644 --- a/cypress/pageobject/Patient/PatientLogupdate.ts +++ b/cypress/pageobject/Patient/PatientLogupdate.ts @@ -55,7 +55,7 @@ class PatientLogupdate { } typeTemperature(temperature: string) { - cy.searchAndSelectOption("#temperature", temperature); + cy.get("#temperature").click().type(temperature); } typeRespiratory(respiratory: string) { diff --git a/src/Components/Patient/DailyRounds.tsx b/src/Components/Patient/DailyRounds.tsx index ef1281fb62b..f719ded1c05 100644 --- a/src/Components/Patient/DailyRounds.tsx +++ b/src/Components/Patient/DailyRounds.tsx @@ -1,5 +1,14 @@ import { navigate } from "raviger"; +import { FormFieldBaseProps } from "../Form/FormFields/Utils"; +// import RangeAutocompleteFormField from "../Form/FormFields/RangeAutocompleteFormField"; +import CareIcon from "../../CAREUI/icons/CareIcon"; +// import ButtonV2 from "./components/ButtonV2"; +import { + celsiusToFahrenheit, + classNames, + fahrenheitToCelsius, +} from "../../Utils/utils"; import dayjs from "dayjs"; import { lazy, useCallback, useEffect, useState } from "react"; import { @@ -25,7 +34,7 @@ import BloodPressureFormField, { BloodPressureValidator, } from "../Common/BloodPressureFormField"; import TemperatureFormField from "../Common/TemperatureFormField"; -import { Cancel, Submit } from "../Common/components/ButtonV2"; +import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2"; import Page from "../Common/components/Page"; import RangeAutocompleteFormField from "../Form/FormFields/RangeAutocompleteFormField"; import { SelectFormField } from "../Form/FormFields/SelectFormField"; @@ -60,12 +69,32 @@ import NursingCare from "../LogUpdate/Sections/NursingCare"; const Loading = lazy(() => import("../Common/Loading")); +export const validateRule = ( + condition: boolean, + content: JSX.Element | string, +) => { + return ( +
+ {condition ? ( + + ) : ( + + )}{" "} + + {content} + +
+ ); +}; export const DailyRounds = (props: any) => { const { t } = useTranslation(); const authUser = useAuthUser(); const { goBack } = useAppHistory(); const { facilityId, patientId, consultationId, id } = props; const [symptomsSeed, setSymptomsSeed] = useState(1); + const [tempInputFocus, setTempInputFocus] = useState(false); const [diagnosisSuggestions, setDiagnosisSuggestions] = useState< ICD11DiagnosisModel[] >([]); @@ -127,7 +156,8 @@ export const DailyRounds = (props: any) => { return state; } }; - + type TemperatureUnit = "celsius" | "fahrenheit"; + const [unit, setUnit] = useState("fahrenheit"); const [state, dispatch] = useAutoSaveReducer( DailyRoundsFormReducer, initialState, @@ -251,6 +281,8 @@ export const DailyRounds = (props: any) => { return; case "bp": { const error = state.form.bp && BloodPressureValidator(state.form.bp); + console.log(error); + if (error) { errors.bp = error; invalidForm = true; @@ -259,6 +291,19 @@ export const DailyRounds = (props: any) => { return; } + case "temperature": + // console.log('fsdfdsfdsf'); + // console.log(state.form["temperature"]); + const value = state.form["temperature"]; + const val = unit === "celsius" ? celsiusToFahrenheit(value) : value; + // console.log("dfasf " +val); + if (val && (val < 95 || val > 106)) { + errors[field] = "temrepwrewr"; + invalidForm = true; + break; + } + return; + case "investigations": { for (const investigation of state.form.investigations) { if (!investigation.type?.length) { @@ -349,7 +394,10 @@ export const DailyRounds = (props: any) => { bp: state.form.bp, pulse: state.form.pulse ?? null, resp: state.form.resp ?? null, - temperature: state.form.temperature ?? null, + temperature: + (unit == "celsius" + ? celsiusToFahrenheit(state.form.temperature) + : state.form.temperature) ?? null, rhythm: state.form.rhythm || undefined, rhythm_detail: state.form.rhythm_detail, ventilator_spo2: state.form.ventilator_spo2 ?? null, @@ -774,12 +822,37 @@ export const DailyRounds = (props: any) => { /> )} - {["NORMAL", "TELEMEDICINE", "DOCTORS_LOG"].includes( state.form.rounds_type, ) && ( <> - +
+ + + + setUnit(unit === "celsius" ? "fahrenheit" : "celsius") + } + > + + +
Date: Sun, 6 Oct 2024 14:23:38 +0530 Subject: [PATCH 02/15] removed unnecessary --- src/Components/Patient/DailyRounds.tsx | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/Components/Patient/DailyRounds.tsx b/src/Components/Patient/DailyRounds.tsx index f719ded1c05..282d379f9f6 100644 --- a/src/Components/Patient/DailyRounds.tsx +++ b/src/Components/Patient/DailyRounds.tsx @@ -69,25 +69,6 @@ import NursingCare from "../LogUpdate/Sections/NursingCare"; const Loading = lazy(() => import("../Common/Loading")); -export const validateRule = ( - condition: boolean, - content: JSX.Element | string, -) => { - return ( -
- {condition ? ( - - ) : ( - - )}{" "} - - {content} - -
- ); -}; export const DailyRounds = (props: any) => { const { t } = useTranslation(); const authUser = useAuthUser(); @@ -281,7 +262,6 @@ export const DailyRounds = (props: any) => { return; case "bp": { const error = state.form.bp && BloodPressureValidator(state.form.bp); - console.log(error); if (error) { errors.bp = error; @@ -292,11 +272,8 @@ export const DailyRounds = (props: any) => { } case "temperature": - // console.log('fsdfdsfdsf'); - // console.log(state.form["temperature"]); const value = state.form["temperature"]; const val = unit === "celsius" ? celsiusToFahrenheit(value) : value; - // console.log("dfasf " +val); if (val && (val < 95 || val > 106)) { errors[field] = "temrepwrewr"; invalidForm = true; From 908fb1167943a99abcc5c180dbfd0000cf5da951 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Mon, 7 Oct 2024 00:09:46 +0530 Subject: [PATCH 03/15] moved to temperatureformfield --- .../Common/TemperatureFormField.tsx | 112 +++++++----------- src/Components/Patient/DailyRounds.tsx | 57 +++------ 2 files changed, 60 insertions(+), 109 deletions(-) diff --git a/src/Components/Common/TemperatureFormField.tsx b/src/Components/Common/TemperatureFormField.tsx index 236d87826e9..b835d2bf3b4 100644 --- a/src/Components/Common/TemperatureFormField.tsx +++ b/src/Components/Common/TemperatureFormField.tsx @@ -1,77 +1,53 @@ -import { useState } from "react"; import { FormFieldBaseProps } from "../Form/FormFields/Utils"; -import RangeAutocompleteFormField from "../Form/FormFields/RangeAutocompleteFormField"; + import CareIcon from "../../CAREUI/icons/CareIcon"; import ButtonV2 from "./components/ButtonV2"; -import { fahrenheitToCelsius } from "../../Utils/utils"; -type TemperatureUnit = "celsius" | "fahrenheit"; +import TextFormField from "../Form/FormFields/TextFormField"; -type Props = FormFieldBaseProps & { - placeholder?: string; +type TemperatureFormFieldProps = FormFieldBaseProps & { + unit: "celsius" | "fahrenheit"; + setUnit: (unit: "celsius" | "fahrenheit") => void; }; - -export default function TemperatureFormField(props: Props) { - const [unit, setUnit] = useState("fahrenheit"); - +export default function TemperatureFormField({ + onChange, + unit, + setUnit, + id, + label, + error, + value, +}: TemperatureFormFieldProps) { return ( - , - className: "text-danger-500", - }, - { - value: 96.6, - label: "Low", - icon: , - className: "text-warning-500", - }, - { - value: 97.6, - label: "Normal", - icon: , - className: "text-primary-500", - }, - { - value: 99.6, - label: "High", - icon: , - className: "text-warning-500", - }, - { - value: 101.6, - label: "High", - icon: , - className: "text-danger-500", - }, - ]} - optionLabel={(value) => { - const val = unit === "celsius" ? fahrenheitToCelsius(value) : value; - return val.toFixed(1); - }} - labelSuffix={ - setUnit(unit === "celsius" ? "fahrenheit" : "celsius")} - > - - - } - /> +
+ + + setUnit(unit === "celsius" ? "fahrenheit" : "celsius")} + > + + +
); } diff --git a/src/Components/Patient/DailyRounds.tsx b/src/Components/Patient/DailyRounds.tsx index 282d379f9f6..9c8d8a553f0 100644 --- a/src/Components/Patient/DailyRounds.tsx +++ b/src/Components/Patient/DailyRounds.tsx @@ -1,14 +1,5 @@ import { navigate } from "raviger"; - -import { FormFieldBaseProps } from "../Form/FormFields/Utils"; -// import RangeAutocompleteFormField from "../Form/FormFields/RangeAutocompleteFormField"; -import CareIcon from "../../CAREUI/icons/CareIcon"; -// import ButtonV2 from "./components/ButtonV2"; -import { - celsiusToFahrenheit, - classNames, - fahrenheitToCelsius, -} from "../../Utils/utils"; +import { celsiusToFahrenheit } from "../../Utils/utils"; import dayjs from "dayjs"; import { lazy, useCallback, useEffect, useState } from "react"; import { @@ -34,7 +25,7 @@ import BloodPressureFormField, { BloodPressureValidator, } from "../Common/BloodPressureFormField"; import TemperatureFormField from "../Common/TemperatureFormField"; -import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2"; +import { Cancel, Submit } from "../Common/components/ButtonV2"; import Page from "../Common/components/Page"; import RangeAutocompleteFormField from "../Form/FormFields/RangeAutocompleteFormField"; import { SelectFormField } from "../Form/FormFields/SelectFormField"; @@ -75,7 +66,6 @@ export const DailyRounds = (props: any) => { const { goBack } = useAppHistory(); const { facilityId, patientId, consultationId, id } = props; const [symptomsSeed, setSymptomsSeed] = useState(1); - const [tempInputFocus, setTempInputFocus] = useState(false); const [diagnosisSuggestions, setDiagnosisSuggestions] = useState< ICD11DiagnosisModel[] >([]); @@ -274,10 +264,15 @@ export const DailyRounds = (props: any) => { case "temperature": const value = state.form["temperature"]; const val = unit === "celsius" ? celsiusToFahrenheit(value) : value; + if (val && (val < 95 || val > 106)) { - errors[field] = "temrepwrewr"; + const tempRange = + unit === "celsius" ? "35°C to 41.1°C" : "95°F to 106°F"; + + errors[field] = `Temperature must be between ${tempRange}.`; + invalidForm = true; - break; + scrollTo("temperature"); } return; @@ -803,33 +798,13 @@ export const DailyRounds = (props: any) => { state.form.rounds_type, ) && ( <> -
- - - - setUnit(unit === "celsius" ? "fahrenheit" : "celsius") - } - > - - -
+ Date: Mon, 7 Oct 2024 00:34:12 +0530 Subject: [PATCH 04/15] eslint fix --- src/Components/Patient/DailyRounds.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Components/Patient/DailyRounds.tsx b/src/Components/Patient/DailyRounds.tsx index 9c8d8a553f0..41e317bbaeb 100644 --- a/src/Components/Patient/DailyRounds.tsx +++ b/src/Components/Patient/DailyRounds.tsx @@ -262,10 +262,16 @@ export const DailyRounds = (props: any) => { } case "temperature": - const value = state.form["temperature"]; - const val = unit === "celsius" ? celsiusToFahrenheit(value) : value; + const temperatureInputValue = state.form["temperature"]; + const convertedTemperature = + unit === "celsius" + ? celsiusToFahrenheit(temperatureInputValue) + : temperatureInputValue; - if (val && (val < 95 || val > 106)) { + if ( + convertedTemperature && + (convertedTemperature < 95 || convertedTemperature > 106) + ) { const tempRange = unit === "celsius" ? "35°C to 41.1°C" : "95°F to 106°F"; From 871b00ba795236d1ba7d1ad7379fc18abb8fa8c5 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Mon, 7 Oct 2024 00:38:12 +0530 Subject: [PATCH 05/15] eslint fix --- src/Components/Patient/DailyRounds.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Components/Patient/DailyRounds.tsx b/src/Components/Patient/DailyRounds.tsx index 41e317bbaeb..f6f7265cd72 100644 --- a/src/Components/Patient/DailyRounds.tsx +++ b/src/Components/Patient/DailyRounds.tsx @@ -261,7 +261,7 @@ export const DailyRounds = (props: any) => { return; } - case "temperature": + case "temperature": { const temperatureInputValue = state.form["temperature"]; const convertedTemperature = unit === "celsius" @@ -281,6 +281,7 @@ export const DailyRounds = (props: any) => { scrollTo("temperature"); } return; + } case "investigations": { for (const investigation of state.form.investigations) { From 381d15a5f94bf7118d63122238665a6fd3f0b116 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Tue, 8 Oct 2024 14:14:40 +0530 Subject: [PATCH 06/15] Implementend required bp changes --- .../pageobject/Patient/PatientLogupdate.ts | 4 +- .../Common/BloodPressureFormField.tsx | 81 ++++++++----------- .../Common/TemperatureFormField.tsx | 2 +- src/Components/Patient/DailyRounds.tsx | 2 +- 4 files changed, 36 insertions(+), 53 deletions(-) diff --git a/cypress/pageobject/Patient/PatientLogupdate.ts b/cypress/pageobject/Patient/PatientLogupdate.ts index a5146916b7c..0fbf6705939 100644 --- a/cypress/pageobject/Patient/PatientLogupdate.ts +++ b/cypress/pageobject/Patient/PatientLogupdate.ts @@ -43,11 +43,11 @@ class PatientLogupdate { } typeSystolic(systolic: string) { - cy.searchAndSelectOption("#systolic", systolic); + cy.get("#systolic").click().type(systolic); } typeDiastolic(diastolic: string) { - cy.searchAndSelectOption("#diastolic", diastolic); + cy.get("#diastolic").click().type(diastolic); } typePulse(pulse: string) { diff --git a/src/Components/Common/BloodPressureFormField.tsx b/src/Components/Common/BloodPressureFormField.tsx index e6fff756d0f..5a13670af79 100644 --- a/src/Components/Common/BloodPressureFormField.tsx +++ b/src/Components/Common/BloodPressureFormField.tsx @@ -1,13 +1,13 @@ import { useTranslation } from "react-i18next"; import { FieldValidator } from "../Form/FieldValidators"; import FormField from "../Form/FormFields/FormField"; -import RangeAutocompleteFormField from "../Form/FormFields/RangeAutocompleteFormField"; import { FieldChangeEvent, FormFieldBaseProps, useFormFieldPropsResolver, } from "../Form/FormFields/Utils"; import { BloodPressure } from "../Patient/models"; +import TextFormField from "../Form/FormFields/TextFormField"; type Props = FormFieldBaseProps; @@ -16,12 +16,13 @@ export default function BloodPressureFormField(props: Props) { const field = useFormFieldPropsResolver(props); const map = meanArterialPressure(props.value)?.toFixed(); - const handleChange = (event: FieldChangeEvent) => { + const handleChange = (event: FieldChangeEvent) => { + const value = event.value ? parseInt(event.value, 10) : ""; const bp = { systolic: field.value?.systolic, diastolic: field.value?.diastolic, }; - bp[event.name as keyof BloodPressure] = event.value; + bp[event.name as keyof BloodPressure] = value || undefined; field.handleChange(Object.values(bp).filter(Boolean).length ? bp : null); }; @@ -32,63 +33,35 @@ export default function BloodPressureFormField(props: Props) { labelSuffix: map && MAP: {map}, }} > -
- + - / - / +
@@ -112,4 +85,14 @@ export const BloodPressureValidator: FieldValidator = (bp) => { if (bp.systolic == null) { return "Systolic is missing. Either specify both or clear both."; } + if (bp.systolic > 250) { + return "Systolic value cannot exceed 250."; + } + + if (bp.diastolic > 250) { + return "Diastolic value cannot exceed 250."; + } + if (bp.systolic < bp.diastolic) { + return "Blood Pressure - Systolic must be greater than diastolic"; + } }; diff --git a/src/Components/Common/TemperatureFormField.tsx b/src/Components/Common/TemperatureFormField.tsx index b835d2bf3b4..671166032cd 100644 --- a/src/Components/Common/TemperatureFormField.tsx +++ b/src/Components/Common/TemperatureFormField.tsx @@ -37,7 +37,7 @@ export default function TemperatureFormField({ Date: Tue, 8 Oct 2024 14:40:12 +0530 Subject: [PATCH 07/15] i18n --- src/Components/Patient/DailyRounds.tsx | 2 +- src/Locale/en.json | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Components/Patient/DailyRounds.tsx b/src/Components/Patient/DailyRounds.tsx index 7bb9462ad8a..0ee9b910bf8 100644 --- a/src/Components/Patient/DailyRounds.tsx +++ b/src/Components/Patient/DailyRounds.tsx @@ -273,7 +273,7 @@ export const DailyRounds = (props: any) => { (convertedTemperature < 95 || convertedTemperature > 106) ) { const tempRange = - unit === "celsius" ? "35°C to 41.1°C" : "95°F to 106°F"; + unit === "celsius" ? t("celsius_range") : t("fahrenheit_range"); errors[field] = `Temperature must be between ${tempRange}.`; diff --git a/src/Locale/en.json b/src/Locale/en.json index 5e63c5e1bda..282dd775bcb 100644 --- a/src/Locale/en.json +++ b/src/Locale/en.json @@ -682,6 +682,8 @@ "LOG_UPDATE_FIELD_LABEL__temperature": "Temperature", "LOG_UPDATE_FIELD_LABEL__other_details": "Other details", "LOG_UPDATE_FIELD_LABEL__pulse": "Pulse", + "celsius_range": "35°C to 41.1°C", + "fahrenheit_range": "95°F to 106°F", "ROUNDS_TYPE__NORMAL": "Brief Update", "ROUNDS_TYPE__COMMUNITY_NURSES_LOG": "Community Nurse's Log", "ROUNDS_TYPE__VENTILATOR": "Detailed Update", From 780b5ccd46c5da6690a5f8a6977830a2ba886b86 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Wed, 9 Oct 2024 01:39:25 +0530 Subject: [PATCH 08/15] cypress failed fix --- cypress/e2e/patient_spec/PatientLogUpdate.cy.ts | 4 ++-- cypress/pageobject/Patient/PatientLogupdate.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts index 7faaeed5a9f..3907784b4b7 100644 --- a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts +++ b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts @@ -302,9 +302,9 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => { patientRhythm, ]); patientLogupdate.clickUpdateDetail(); - patientLogupdate.clickClearButtonInElement("#systolic"); + patientLogupdate.clearIntoElementById("#systolic"); patientLogupdate.typeSystolic(patientModifiedSystolic); - patientLogupdate.clickClearButtonInElement("#diastolic"); + patientLogupdate.clearIntoElementById("#diastolic"); patientLogupdate.typeDiastolic(patientModifiedDiastolic); cy.submitButton("Continue"); cy.verifyNotification("Brief Update updated successfully"); diff --git a/cypress/pageobject/Patient/PatientLogupdate.ts b/cypress/pageobject/Patient/PatientLogupdate.ts index 0fbf6705939..83feafb33ea 100644 --- a/cypress/pageobject/Patient/PatientLogupdate.ts +++ b/cypress/pageobject/Patient/PatientLogupdate.ts @@ -93,8 +93,8 @@ class PatientLogupdate { cy.wait(3000); } - clickClearButtonInElement(elementId) { - cy.get(elementId).find("#clear-button").click(); + clearIntoElementById(elementId) { + cy.get(elementId).click().clear(); } clickVitals() { From 55a949e88ac035caa9f2ad6179c095dd04f5bf37 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Mon, 14 Oct 2024 01:05:39 +0530 Subject: [PATCH 09/15] fix: Limit temp input to one decimal place and C to F conversion --- .../Common/TemperatureFormField.tsx | 32 +++++++++++++++---- src/Components/Patient/DailyRounds.tsx | 4 +-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/Components/Common/TemperatureFormField.tsx b/src/Components/Common/TemperatureFormField.tsx index 671166032cd..bdc5ca2b0bd 100644 --- a/src/Components/Common/TemperatureFormField.tsx +++ b/src/Components/Common/TemperatureFormField.tsx @@ -1,5 +1,5 @@ import { FormFieldBaseProps } from "../Form/FormFields/Utils"; - +import { fahrenheitToCelsius, celsiusToFahrenheit } from "@/Utils/utils"; import CareIcon from "../../CAREUI/icons/CareIcon"; import ButtonV2 from "./components/ButtonV2"; @@ -9,6 +9,7 @@ type TemperatureFormFieldProps = FormFieldBaseProps & { unit: "celsius" | "fahrenheit"; setUnit: (unit: "celsius" | "fahrenheit") => void; }; + export default function TemperatureFormField({ onChange, unit, @@ -17,19 +18,38 @@ export default function TemperatureFormField({ label, error, value, + name, }: TemperatureFormFieldProps) { + const handleUnitChange = () => { + let newValue = parseFloat(value || "0"); + if (!isNaN(newValue)) { + if (unit === "celsius") { + newValue = celsiusToFahrenheit(newValue); + } else { + newValue = fahrenheitToCelsius(newValue); + } + onChange({ name, value: newValue.toFixed(1) }); + } + setUnit(unit === "celsius" ? "fahrenheit" : "celsius"); + }; + return (
{ + const newValue = e.value; + if (newValue === "" || /^-?\d*\.?\d{0,1}$/.test(newValue)) { + onChange(e); + } + }} autoComplete="off" error={error} /> @@ -37,11 +57,11 @@ export default function TemperatureFormField({ setUnit(unit === "celsius" ? "fahrenheit" : "celsius")} + onClick={handleUnitChange} > { resp: state.form.resp ?? null, temperature: (unit == "celsius" - ? celsiusToFahrenheit(state.form.temperature) + ? celsiusToFahrenheit(state.form.temperature).toFixed(1) : state.form.temperature) ?? null, rhythm: state.form.rhythm || undefined, rhythm_detail: state.form.rhythm_detail, @@ -806,8 +806,6 @@ export const DailyRounds = (props: any) => { <> From 047cba6883ddeea8a46f468316d842ecb58b731c Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Tue, 15 Oct 2024 18:08:37 +0530 Subject: [PATCH 10/15] Moved temperature state to TemperatureFormField --- .../Common/BloodPressureFormField.tsx | 22 +++--- .../Common/TemperatureFormField.tsx | 73 +++++++++++++------ src/Components/Patient/DailyRounds.tsx | 30 ++------ src/Locale/en.json | 10 ++- 4 files changed, 73 insertions(+), 62 deletions(-) diff --git a/src/Components/Common/BloodPressureFormField.tsx b/src/Components/Common/BloodPressureFormField.tsx index 5a13670af79..beddd34cf38 100644 --- a/src/Components/Common/BloodPressureFormField.tsx +++ b/src/Components/Common/BloodPressureFormField.tsx @@ -75,24 +75,20 @@ export const meanArterialPressure = (bp?: BloodPressure | null) => { return (2 * bp.diastolic + bp.systolic) / 3; }; -export const BloodPressureValidator: FieldValidator = (bp) => { +export const BloodPressureValidator: FieldValidator = ( + bp, + t, +) => { 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 || bp.diastolic == null) { + return t("blood_pressure_error.missing"); } - if (bp.systolic == null) { - return "Systolic is missing. Either specify both or clear both."; - } - if (bp.systolic > 250) { - return "Systolic value cannot exceed 250."; - } - - if (bp.diastolic > 250) { - return "Diastolic value cannot exceed 250."; + if (bp.systolic > 250 || bp.diastolic > 250) { + return t("blood_pressure_error.exceed"); } if (bp.systolic < bp.diastolic) { - return "Blood Pressure - Systolic must be greater than diastolic"; + return t("blood_pressure_error.systolic_less_than_diastolic"); } }; diff --git a/src/Components/Common/TemperatureFormField.tsx b/src/Components/Common/TemperatureFormField.tsx index bdc5ca2b0bd..9813f659956 100644 --- a/src/Components/Common/TemperatureFormField.tsx +++ b/src/Components/Common/TemperatureFormField.tsx @@ -1,36 +1,67 @@ +import { useState, useEffect } from "react"; import { FormFieldBaseProps } from "../Form/FormFields/Utils"; import { fahrenheitToCelsius, celsiusToFahrenheit } from "@/Utils/utils"; import CareIcon from "../../CAREUI/icons/CareIcon"; import ButtonV2 from "./components/ButtonV2"; - import TextFormField from "../Form/FormFields/TextFormField"; -type TemperatureFormFieldProps = FormFieldBaseProps & { - unit: "celsius" | "fahrenheit"; - setUnit: (unit: "celsius" | "fahrenheit") => void; -}; +type TemperatureUnit = "celsius" | "fahrenheit"; + +type TemperatureFormFieldProps = FormFieldBaseProps; export default function TemperatureFormField({ onChange, - unit, - setUnit, id, label, error, value, name, }: TemperatureFormFieldProps) { - const handleUnitChange = () => { - let newValue = parseFloat(value || "0"); - if (!isNaN(newValue)) { - if (unit === "celsius") { - newValue = celsiusToFahrenheit(newValue); - } else { - newValue = fahrenheitToCelsius(newValue); - } - onChange({ name, value: newValue.toFixed(1) }); + const [unit, setUnit] = useState("fahrenheit"); + const [inputValue, setInputValue] = useState(value || ""); + + useEffect(() => { + if (value) { + const initialTemperature = + unit === "celsius" + ? fahrenheitToCelsius(parseFloat(value)).toFixed(1) + : value; + setInputValue(initialTemperature); } + }, [value, unit]); + + const handleUnitChange = () => { setUnit(unit === "celsius" ? "fahrenheit" : "celsius"); + if (inputValue) { + const convertedValue = + unit === "celsius" + ? celsiusToFahrenheit(parseFloat(inputValue)).toFixed(1) + : fahrenheitToCelsius(parseFloat(inputValue)).toFixed(1); + setInputValue(convertedValue); + } + }; + + const handleInputChange = (e: any) => { + const newValue = e.value; + + const regex = /^-?\d*\.?\d{0,1}$/; + if (regex.test(newValue)) { + setInputValue(newValue); + } + }; + + const handleBlur = () => { + if (!inputValue) return; + const parsedValue = parseFloat(inputValue); + if (isNaN(parsedValue)) return; + + const finalValue = + unit === "celsius" + ? celsiusToFahrenheit(parsedValue).toString() + : parsedValue.toString(); + + setInputValue(finalValue); + onChange({ name, value: finalValue }); }; return ( @@ -39,17 +70,13 @@ export default function TemperatureFormField({ id={id} label={label} type="number" - value={value ? value : ""} + value={inputValue} name={name} min={`${unit === "celsius" ? 35 : 95}`} max={`${unit === "celsius" ? 41.1 : 106}`} step={0.1} - onChange={(e) => { - const newValue = e.value; - if (newValue === "" || /^-?\d*\.?\d{0,1}$/.test(newValue)) { - onChange(e); - } - }} + onChange={handleInputChange} + onBlur={handleBlur} autoComplete="off" error={error} /> diff --git a/src/Components/Patient/DailyRounds.tsx b/src/Components/Patient/DailyRounds.tsx index d71cce6844c..d83416f3f38 100644 --- a/src/Components/Patient/DailyRounds.tsx +++ b/src/Components/Patient/DailyRounds.tsx @@ -126,8 +126,6 @@ export const DailyRounds = (props: any) => { return state; } }; - type TemperatureUnit = "celsius" | "fahrenheit"; - const [unit, setUnit] = useState("fahrenheit"); const [state, dispatch] = useAutoSaveReducer( DailyRoundsFormReducer, initialState, @@ -250,7 +248,8 @@ export const DailyRounds = (props: any) => { } return; case "bp": { - const error = state.form.bp && BloodPressureValidator(state.form.bp); + const error = + state.form.bp && BloodPressureValidator(state.form.bp, t); if (error) { errors.bp = error; @@ -262,20 +261,12 @@ export const DailyRounds = (props: any) => { case "temperature": { const temperatureInputValue = state.form["temperature"]; - const convertedTemperature = - unit === "celsius" - ? celsiusToFahrenheit(temperatureInputValue) - : temperatureInputValue; if ( - convertedTemperature && - (convertedTemperature < 95 || convertedTemperature > 106) + temperatureInputValue && + (temperatureInputValue < 95 || temperatureInputValue > 106) ) { - const tempRange = - unit === "celsius" ? t("celsius_range") : t("fahrenheit_range"); - - errors[field] = `Temperature must be between ${tempRange}.`; - + errors[field] = t("temperature_error"); invalidForm = true; scrollTo("temperature"); } @@ -372,10 +363,7 @@ export const DailyRounds = (props: any) => { bp: state.form.bp, pulse: state.form.pulse ?? null, resp: state.form.resp ?? null, - temperature: - (unit == "celsius" - ? celsiusToFahrenheit(state.form.temperature).toFixed(1) - : state.form.temperature) ?? null, + temperature: state.form.temperature ?? null, rhythm: state.form.rhythm || undefined, rhythm_detail: state.form.rhythm_detail, ventilator_spo2: state.form.ventilator_spo2 ?? null, @@ -804,11 +792,7 @@ export const DailyRounds = (props: any) => { state.form.rounds_type, ) && ( <> - + Date: Tue, 15 Oct 2024 18:15:55 +0530 Subject: [PATCH 11/15] fix lint err --- src/Components/Patient/DailyRounds.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Components/Patient/DailyRounds.tsx b/src/Components/Patient/DailyRounds.tsx index d83416f3f38..78f865429bc 100644 --- a/src/Components/Patient/DailyRounds.tsx +++ b/src/Components/Patient/DailyRounds.tsx @@ -24,7 +24,6 @@ import BloodPressureFormField, { BloodPressureValidator, } from "../Common/BloodPressureFormField"; import TemperatureFormField from "../Common/TemperatureFormField"; -import { celsiusToFahrenheit } from "../../Utils/utils"; import { Cancel, Submit } from "../Common/components/ButtonV2"; import Page from "../Common/components/Page"; import RangeAutocompleteFormField from "../Form/FormFields/RangeAutocompleteFormField"; From ca9a5bb556e1ae95d72af1cf25fae34dc043a7e4 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Tue, 15 Oct 2024 20:07:40 +0530 Subject: [PATCH 12/15] interpolation_updated --- src/Components/Patient/DailyRounds.tsx | 5 ++++- src/Locale/en.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Components/Patient/DailyRounds.tsx b/src/Components/Patient/DailyRounds.tsx index 78f865429bc..3e10383e78a 100644 --- a/src/Components/Patient/DailyRounds.tsx +++ b/src/Components/Patient/DailyRounds.tsx @@ -265,7 +265,10 @@ export const DailyRounds = (props: any) => { temperatureInputValue && (temperatureInputValue < 95 || temperatureInputValue > 106) ) { - errors[field] = t("temperature_error"); + errors[field] = t("out_of_range_error", { + start: "95°F (35°C)", + end: "106°F (41.1°C)", + }); invalidForm = true; scrollTo("temperature"); } diff --git a/src/Locale/en.json b/src/Locale/en.json index c6eed354a50..1deaa38884b 100644 --- a/src/Locale/en.json +++ b/src/Locale/en.json @@ -801,7 +801,7 @@ "exceed": "Value cannot exceed 250 mmHg.", "systolic_less_than_diastolic": "Systolic must be greater than diastolic." }, - "temperature_error": "Temperature must be between 95°F (35°C) and 106°F (41.1°C).", + "out_of_range_error": "Value must be between {{ start }} and {{ end }}.", "pain": "Pain", "pain_chart_description": "Mark region and intensity of pain", "bradycardia": "Bradycardia", From 710754e3c06f66e5e063a929af037af966599022 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Tue, 15 Oct 2024 20:51:20 +0530 Subject: [PATCH 13/15] updated type of event --- src/Components/Common/TemperatureFormField.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/Common/TemperatureFormField.tsx b/src/Components/Common/TemperatureFormField.tsx index 9813f659956..8c9901e2b92 100644 --- a/src/Components/Common/TemperatureFormField.tsx +++ b/src/Components/Common/TemperatureFormField.tsx @@ -1,5 +1,5 @@ import { useState, useEffect } from "react"; -import { FormFieldBaseProps } from "../Form/FormFields/Utils"; +import { FieldChangeEvent, FormFieldBaseProps } from "../Form/FormFields/Utils"; import { fahrenheitToCelsius, celsiusToFahrenheit } from "@/Utils/utils"; import CareIcon from "../../CAREUI/icons/CareIcon"; import ButtonV2 from "./components/ButtonV2"; @@ -41,7 +41,7 @@ export default function TemperatureFormField({ } }; - const handleInputChange = (e: any) => { + const handleInputChange = (e: FieldChangeEvent) => { const newValue = e.value; const regex = /^-?\d*\.?\d{0,1}$/; From 02f9e46b19cb014db6ce563048c38e2ab0525970 Mon Sep 17 00:00:00 2001 From: AdityaJ2305 Date: Wed, 16 Oct 2024 16:18:25 +0530 Subject: [PATCH 14/15] lint fix --- src/Components/Common/TemperatureFormField.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Common/TemperatureFormField.tsx b/src/Components/Common/TemperatureFormField.tsx index 8c9901e2b92..49f59ee63ec 100644 --- a/src/Components/Common/TemperatureFormField.tsx +++ b/src/Components/Common/TemperatureFormField.tsx @@ -84,7 +84,7 @@ export default function TemperatureFormField({ Date: Wed, 16 Oct 2024 16:38:13 +0530 Subject: [PATCH 15/15] lint fix --- src/Components/Common/TemperatureFormField.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Common/TemperatureFormField.tsx b/src/Components/Common/TemperatureFormField.tsx index 49f59ee63ec..7b2d7124f09 100644 --- a/src/Components/Common/TemperatureFormField.tsx +++ b/src/Components/Common/TemperatureFormField.tsx @@ -84,7 +84,7 @@ export default function TemperatureFormField({