Skip to content

(feat) O3-4228: RDE support for the order basket #2531

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

amosmachora
Copy link
Contributor

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

This PR adds RDE support to the order basket. When RDE is enabled, the user will now have the option to select a point in time within the bounds of a past visit in which the user can add retrospective data.

Screenshots

order-basket-with-rde.mp4

Related Issue

https://openmrs.atlassian.net/browse/O3-4228

Other

Comment on lines +99 to +104
// check if the date is within the bounds of the current visit
const isWithinBounds = isWithinInterval(completeDate, {
start: new Date(currentVisit.startDatetime),
end: currentVisit.stopDatetime ? new Date(currentVisit.stopDatetime) : new Date(),
});

Copy link
Contributor

@makombe makombe Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is RDE, I suggest restricting the date selection directly in the UI by setting appropriate boundaries. This will eliminate the need for an additional validation check elsewhere. Specifically, we can set
minDate = startDatetime/ visitStartDate

maxDate = stopDatetime / visitStopDate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a restriction from the date picker itself. The issue is that sometimes, as much as a user will click on a certain date, the time itself might be out of range. I am not sure the time picker has a way to limit the times natively like the date picker, so that check is for making sure that the user doesn't go out of the visit's bounds.

Comment on lines +121 to +134
if (hasRdeDateBoundsError && currentVisit) {
showSnackbar({
isLowContrast: true,
kind: 'error',
title: t('rdeDateOutOfBounds', 'Retrospective date is out of bounds'),
subtitle: t(
'rdeDateOutOfBoundsMessage',
`The retrospective date must be within {{startDate}} and {{endDate}}.`,
{
startDate: format(currentVisit.startDatetime, 'PPP hh:mm a'),
endDate: currentVisit.stopDatetime
? format(currentVisit.stopDatetime, 'PPP hh:mm a')
: t('currentDate', 'current date'),
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With setting the maxDate and minDate we will not need this now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to the comment above on this issue.

@amosmachora
Copy link
Contributor Author

@chibongho remember the bug on currentVisitIsRetrospective ? It is the reason why the tests are failing on this one. Technically I am disabling the submit button if the current visit is retrospective and the user has not selected a date.

@amosmachora amosmachora marked this pull request as draft July 1, 2025 06:07
const isAm = retrospectiveTimeFormat === 'AM';
const isPm = retrospectiveTimeFormat === 'PM';

if (isAm && parseInt(hours, 10) >= 12) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong, Won't 12:00am be changed to 12:00pm? The <TimePicker> below has a regex pattern passed to it. Does it correctly prevent dates that are not in the 12-hour format?

There is also date / time parsing code in visit-date-time.component.tsx. I think we should consolidate them instead of having separate implementations for different UIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The below has a regex pattern passed to it. Does it correctly prevent dates that are not in the 12-hour format?

I referred to other places the <TimePicker /> component was used , they all seemed to have that pattern to prevent users from entering 24 hour format times but in my UI it seems to be still possible, for other places the time picker is used I haven't verified that. I have added logic to make sure users don't enter invalid times. Thanks for catching that!

let [rawHour, minute] = dateTime.retrospectiveTime.split(':').map(Number);

// Adjust hour for AM/PM
let hour = rawHour;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use convertTime12to24 instead of reimplementing its logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!. Simplifies things a lot. I did not know that function existed. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants