Skip to content

Commit

Permalink
Appointments: Update relative date filters; configurable default filt…
Browse files Browse the repository at this point in the history
…er (#9933)
  • Loading branch information
rithviknishad authored Jan 13, 2025
1 parent 195e944 commit b8f25c2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
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 @@ -1171,7 +1171,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 @@ -1302,7 +1301,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

0 comments on commit b8f25c2

Please sign in to comment.