Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Nov 14, 2024
1 parent f178704 commit edd38ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
24 changes: 11 additions & 13 deletions packages/esm-patient-common-lib/src/orders/useOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export function usePatientOrders(
endDate?: string,
) {
const { mutate } = useSWRConfig();
const baseOrdersUrl = `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&v=full&status=${status}`;
const baseOrdersUrl =
startDate && endDate
? `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&v=full&activatedOnOrAfterDate=${startDate}&activatedOnOrBeforeDate=${endDate}`
: `${restBaseUrl}/order?patient=${patientUuid}&careSetting=${careSettingUuid}&v=full&status=${status}`;
const ordersUrl = orderType ? `${baseOrdersUrl}&orderType=${orderType}` : baseOrdersUrl;

const { data, error, isLoading, isValidating } = useSWR<FetchResponse<PatientOrderFetchResponse>, Error>(
Expand All @@ -36,18 +39,13 @@ export function usePatientOrders(
[data, mutate, patientUuid],
);

const orders = useMemo(() => {
if (!data?.data?.results) return null;

const filteredResults =
startDate && endDate
? data.data.results.filter((order) => {
return order.dateActivated >= toOmrsIsoString(startDate) && order.dateActivated <= toOmrsIsoString(endDate);
})
: data.data.results;

return filteredResults.sort((order1, order2) => (order2.dateActivated > order1.dateActivated ? 1 : -1));
}, [data, startDate, endDate]);
const orders = useMemo(
() =>
data?.data?.results
? data.data.results?.sort((order1, order2) => (order2.dateActivated > order1.dateActivated ? 1 : -1))
: null,
[data],
);

return {
data: orders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,15 @@ const OrderDetailsTable: React.FC<OrderDetailsProps> = ({ patientUuid, showAddBu

const handleDateFilterChange = ([startDate, endDate]) => {
if (startDate) {
setSelectedFromDate(startDate);
setSelectedFromDate(startDate.toISOString());
if (selectedToDate && startDate && selectedToDate < startDate) {
setSelectedToDate(startDate);
setSelectedToDate(startDate.toISOString());
}
}
if (endDate) {
setSelectedToDate(endDate);
setSelectedToDate(endDate.toISOString());
if (selectedFromDate && endDate && selectedFromDate > endDate) {
setSelectedFromDate(endDate);
setSelectedFromDate(endDate.toISOString());
}
}
};
Expand Down Expand Up @@ -352,8 +352,8 @@ const OrderDetailsTable: React.FC<OrderDetailsProps> = ({ patientUuid, showAddBu
handleDateFilterChange([startDate, endDate]);
}}
>
<DatePickerInput id="startDatePickerInput" placeholder="dd/mm/yyyy" value={formatDate(selectedFromDate)} />
<DatePickerInput id="endDatePickerInput" placeholder="dd/mm/yyyy" value={formatDate(selectedToDate)} />
<DatePickerInput id="startDatePickerInput" placeholder="dd/mm/yyyy" />
<DatePickerInput id="endDatePickerInput" placeholder="dd/mm/yyyy" />
</DatePicker>
</div>

Expand Down

0 comments on commit edd38ea

Please sign in to comment.