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

(fix) O3-4270: Group obs by encounter instead of datetime #2150

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
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 uniqueEncounterReferences = [...new Set(obss.map((o) => o.encounter.reference))].sort();
const obssGroupedByEncounters = uniqueEncounterReferences.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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Tile, InlineLoading , InlineNotification } from '@carbon/react';
import { Tile, InlineLoading, InlineNotification } from '@carbon/react';
import { type Order } from '@openmrs/esm-patient-common-lib';
import React from 'react';
import { useTranslation } from 'react-i18next';
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-patient-orders-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"errorSavingLabResults": "Error saving lab results",
"goToDrugOrderForm": "Order form",
"indication": "Indication",
"labResultError": "Error loading lab results",
"inStock": "In stock",
"instructions": "Instructions",
"labResultError": "Error loading lab results",
"launchOrderBasket": "Launch order basket",
"loading": "Loading",
"loadingInitialValues": "Loading initial values",
Expand Down
Loading
Loading