Skip to content

Commit

Permalink
Add min_encounter_date validation (#7207)
Browse files Browse the repository at this point in the history
* Add min_encounter_date validation

* Add check for minimum encounter date in ConsultationForm
  • Loading branch information
Ashesh3 authored Feb 12, 2024
1 parent 2a7c261 commit d63ef9f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
5 changes: 5 additions & 0 deletions src/Common/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
16 changes: 14 additions & 2 deletions src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => {
const [bedStatusVisible, bedStatusRef] = useVisibility(-300);
const [disabledFields, setDisabledFields] = useState<string[]>([]);

const { min_encounter_date } = useConfig();

const sections = {
"Consultation Details": {
iconClass: "care-l-medkit",
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
/>
</div>

Expand Down

0 comments on commit d63ef9f

Please sign in to comment.