-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(fix) O3-4294: Fix incorrect visit date validation in edit mode in the visit form #2165
Conversation
Size Change: +7 B (0%) Total Size: 16.1 MB ℹ️ View Unchanged
|
@@ -157,7 +156,8 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({ | |||
(value) => { | |||
const today = dayjs(); | |||
const startDate = dayjs(value); | |||
return displayVisitStopDateTimeFields ? true : startDate.isSameOrBefore(today, 'day'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual fix. The rest of the diff just reorganizes imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Can we also fix the logic that sets maxVisitStartDateTime
, so that future dates are not selectable in the datepicker?
Removes a condition that was incorrectly bypassing start date validation when `displayVisitStopDateTimeFields` is true. Start dates should always be validated to be on or before the current date, regardless of whether stop date fields are displayed.
AFAICT, there are already multiple safeguards that prevent users from selecting future visit start dates:
visitStartDate: z.date().refine(
(value) => {
const today = dayjs();
const startDate = dayjs(value);
return startDate.isSameOrBefore(today, 'day');
},
t('invalidVisitStartDate', 'Start date needs to be on or before {{firstEncounterDatetime}}', {
firstEncounterDatetime: formatDatetime(new Date()),
interpolation: {
escapeValue: false,
},
}),
),
const validateStartTime = (data: z.infer<typeof visitFormSchema>) => {
const [visitStartHours, visitStartMinutes] = convertTime12to24(data.visitStartTime, data.visitStartTimeFormat);
const visitStartDatetime = new Date(data.visitStartDate).setHours(visitStartHours, visitStartMinutes);
return new Date(visitStartDatetime) <= new Date();
}; Regarding the specific logic for
So the logic as-is should not allow selecting a future visit start date. |
41405c1
to
e2ea2e8
Compare
@brandones, I've grokked the issue after reading your comment again and looking through the code with Vineet. In as much as we have the validation logic in place, |
So, I two things:
Otherwise, LGTM. |
Thanks @brandones. I think we've covered the use-case here. See the additional explanations.
…e visit form (#2165) * (fix) visit-form: Fix incorrect visit date validation Removes a condition that was incorrectly bypassing start date validation when `displayVisitStopDateTimeFields` is true. Start dates should always be validated to be on or before the current date, regardless of whether stop date fields are displayed. * Rename variable * `maxVisitStartDatetime` should default to the current date
Requirements
Summary
This PR fixes a bug in the visit form that allows users to set future start dates when editing visits. This happens because the start date validation was getting bypassed when the
displayVisitStopDateTimeFields
was true (which is the case when editing an existing visit).Start dates should always be validated to be on or before the current date, regardless of whether stop date fields are displayed. This fix ensures that that is the case.
Screenshots
Visit start date validation not taking effect when editing an existing visit
visit-start-time-validation-bug.mp4
Fix
start-date-validation-fix.mp4
Related Issue
https://openmrs.atlassian.net/browse/O3-4294
Other