Skip to content
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

Appointments: Update relative date filters; configurable default filter #9933

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions care.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ const careConfig = {
},

appointments: {
/**
* Relative number of days to show in the appointments page by default.
* 0 means today, positive for future days, negative for past days.
*/
defaultDateFilter: env.REACT_APPOINTMENTS_DEFAULT_DATE_FILTER
? parseInt(env.REACT_APPOINTMENTS_DEFAULT_DATE_FILTER)
: 7,

// Kill switch in-case the heatmap API doesn't scale as expected
useAvailabilityStatsAPI: boolean(
"REACT_APPOINTMENTS_USE_AVAILABILITY_STATS_API",
Expand Down
3 changes: 1 addition & 2 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,6 @@
"last_administered": "Last administered",
"last_discharge_reason": "Last Discharge Reason",
"last_edited": "Last Edited",
"last_fortnight_short": "Last 2wk",
"last_login": "Last Login",
"last_modified": "Last Modified",
"last_modified_by": "Last Modified By",
Expand Down Expand Up @@ -1290,7 +1289,7 @@
"new_password_same_as_old": "Your new password must not match the old password.",
"new_password_validation": "New password is not valid.",
"new_session": "New Session",
"next_fortnight_short": "Next 2wk",
"next_month": "Next month",
"next_sessions": "Next Sessions",
"next_week_short": "Next wk",
"no": "No",
Expand Down
46 changes: 29 additions & 17 deletions src/pages/Appointments/AppointmentsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import careConfig from "@careConfig";
import { CaretDownIcon, CheckIcon, ReloadIcon } from "@radix-ui/react-icons";
import { PopoverClose } from "@radix-ui/react-popover";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
Expand Down Expand Up @@ -123,25 +124,25 @@ function DateRangeDisplay({ dateFrom, dateTo }: DateRangeDisplayProps) {

// Case 2: Pre-defined ranges
const ranges = [
{
label: t("last_fortnight_short"),
from: subDays(today, 14),
to: today,
},
{
label: t("last_week_short"),
from: subDays(today, 7),
to: today,
},
{
label: t("yesterday"),
from: subDays(today, 1),
to: subDays(today, 1),
},
{
label: t("next_week_short"),
from: today,
to: addDays(today, 7),
},
{
label: t("next_fortnight_short"),
label: t("next_month"),
from: today,
to: addDays(today, 14),
to: addDays(today, 30),
},
];

Expand Down Expand Up @@ -266,11 +267,22 @@ export default function AppointmentsPage(props: { facilityId?: string }) {
updates.practitioner = authUser.username;
}

// Set today's date range if no dates are present
// Set default date range if no dates are present
if (!qParams.date_from && !qParams.date_to) {
const today = new Date();
updates.date_from = dateQueryString(today);
updates.date_to = dateQueryString(today);
const defaultDays = careConfig.appointments.defaultDateFilter;

if (defaultDays === 0) {
// Today only
updates.date_from = dateQueryString(today);
updates.date_to = dateQueryString(today);
} else {
// Past or future days based on configuration
const fromDate = defaultDays > 0 ? today : addDays(today, defaultDays);
const toDate = defaultDays > 0 ? addDays(today, defaultDays) : today;
updates.date_from = dateQueryString(fromDate);
updates.date_to = dateQueryString(toDate);
}
}

// Only update if there are changes
Expand Down Expand Up @@ -455,13 +467,13 @@ export default function AppointmentsPage(props: { facilityId?: string }) {
const today = new Date();
setQParams({
...qParams,
date_from: dateQueryString(subDays(today, 14)),
date_from: dateQueryString(subDays(today, 7)),
date_to: dateQueryString(today),
slot: null,
});
}}
>
{t("last_fortnight_short")}
{t("last_week_short")}
</Button>

<Button
Expand All @@ -471,13 +483,13 @@ export default function AppointmentsPage(props: { facilityId?: string }) {
const today = new Date();
setQParams({
...qParams,
date_from: dateQueryString(subDays(today, 7)),
date_to: dateQueryString(today),
date_from: dateQueryString(subDays(today, 1)),
date_to: dateQueryString(subDays(today, 1)),
slot: null,
});
}}
>
{t("last_week_short")}
{t("yesterday")}
</Button>

<Button
Expand Down Expand Up @@ -520,12 +532,12 @@ export default function AppointmentsPage(props: { facilityId?: string }) {
setQParams({
...qParams,
date_from: dateQueryString(today),
date_to: dateQueryString(addDays(today, 14)),
date_to: dateQueryString(addDays(today, 30)),
slot: null,
});
}}
>
{t("next_fortnight_short")}
{t("next_month")}
</Button>
</div>

Expand Down
Loading