Skip to content

Commit

Permalink
(fix) O3-4270: Group obs by encounter instead of datetime (#2150)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasharma05 authored Jan 3, 2025
1 parent a928b89 commit 52b247f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ interface ObsTableProps {
const ObsTable: React.FC<ObsTableProps> = ({ patientUuid }) => {
const { t } = useTranslation();
const config = useConfig();
const { data: obss, error, isLoading, isValidating } = useObs(patientUuid, config.showEncounterType);
const uniqueDates = [...new Set(obss.map((o) => o.issued))].sort();
const obssByDate = uniqueDates.map((date) => obss.filter((o) => o.issued === date));
const { data: obss } = useObs(patientUuid, config.showEncounterType);
const uniqueEncounterUuids = [...new Set(obss.map((o) => o.encounter.reference))].sort();
const obssGroupedByEncounters = uniqueEncounterUuids.map((date) =>
obss.filter((o) => o.encounter.reference === date),
);

const tableHeaders = [
{ key: 'date', header: t('dateAndTime', 'Date and time'), isSortable: true },
Expand All @@ -40,7 +42,7 @@ const ObsTable: React.FC<ObsTableProps> = ({ patientUuid }) => {

const tableRows = React.useMemo(
() =>
obssByDate?.map((obss, index) => {
obssGroupedByEncounters?.map((obss, index) => {
const rowData = {
id: `${index}`,
date: formatDatetime(new Date(obss[0].effectiveDateTime), { mode: 'wide' }),
Expand Down Expand Up @@ -91,7 +93,7 @@ const ObsTable: React.FC<ObsTableProps> = ({ patientUuid }) => {

return rowData;
}),
[config, obssByDate],
[config.data, config?.dateFormat, obssGroupedByEncounters],
);

const { results, goTo, currentPage } = usePagination(tableRows, config.table.pageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type ObsResult = fhir.Observation & {
valueDateTime?: string;
encounter?: {
name?: string;
/**
* Reference to the encounter resource, in the format `Encounter/{uuid}`
*/
reference: string;
};
};

Expand Down

0 comments on commit 52b247f

Please sign in to comment.