From d63ef9f4a8fe77ac6933c1741b72fc8c5c397a5b Mon Sep 17 00:00:00 2001 From: Ashesh <3626859+Ashesh3@users.noreply.github.com> Date: Mon, 12 Feb 2024 16:31:37 +0530 Subject: [PATCH] Add min_encounter_date validation (#7207) * Add min_encounter_date validation * Add check for minimum encounter date in ConsultationForm --- public/config.json | 3 ++- src/Common/hooks/useConfig.ts | 5 +++++ src/Components/Facility/ConsultationForm.tsx | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/public/config.json b/public/config.json index 69d898af544..d02bd135cfe 100644 --- a/public/config.json +++ b/public/config.json @@ -22,5 +22,6 @@ "sample_format_asset_import": "https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key=11JaEhNHdyCHth4YQs_44YaRlP77Rrqe81VSEfg1glko&exportFormat=xlsx", "sample_format_external_result_import": "/External-Results-Template.csv", "enable_abdm": true, - "enable_hcx": false + "enable_hcx": false, + "min_encounter_date": "2020-01-01" } diff --git a/src/Common/hooks/useConfig.ts b/src/Common/hooks/useConfig.ts index 79addd71c8b..4e1cb806e3f 100644 --- a/src/Common/hooks/useConfig.ts +++ b/src/Common/hooks/useConfig.ts @@ -69,6 +69,11 @@ export interface IConfig { */ wartime_shifting: boolean; jwt_token_refresh_interval?: number; + + /* + * Minimum date for a possible consultation encounter. + */ + min_encounter_date: string; } const useConfig = () => { diff --git a/src/Components/Facility/ConsultationForm.tsx b/src/Components/Facility/ConsultationForm.tsx index d7bc5f67a70..344e24c7c31 100644 --- a/src/Components/Facility/ConsultationForm.tsx +++ b/src/Components/Facility/ConsultationForm.tsx @@ -263,6 +263,8 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { const [bedStatusVisible, bedStatusRef] = useVisibility(-300); const [disabledFields, setDisabledFields] = useState([]); + const { min_encounter_date } = useConfig(); + const sections = { "Consultation Details": { iconClass: "care-l-medkit", @@ -504,8 +506,13 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { errors[field] = "Field is required"; invalidForm = true; } - if (dayjs(state.form.encounter_date).isBefore(dayjs("2000-01-01"))) { - errors[field] = "Admission date cannot be before 01/01/2000"; + if ( + min_encounter_date && + dayjs(state.form.encounter_date).isBefore(dayjs(min_encounter_date)) + ) { + errors[ + field + ] = `Admission date cannot be before ${min_encounter_date}`; invalidForm = true; } return; @@ -1238,6 +1245,11 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { "YYYY-MM-DDTHH:mm" )} max={dayjs().format("YYYY-MM-DDTHH:mm")} + min={ + min_encounter_date + ? dayjs(min_encounter_date).format("YYYY-MM-DDTHH:mm") + : undefined + } />