From f9fbb8da4bb50124c6b820b27f7bb3d282ba3b45 Mon Sep 17 00:00:00 2001 From: Usama Idriss Kakumba Date: Wed, 16 Oct 2024 18:12:41 +0300 Subject: [PATCH 1/4] feat: sort diagnoses by order --- .../visit-summary.component.tsx | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx index 44f116ec99..f7890af148 100644 --- a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx +++ b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx @@ -1,7 +1,7 @@ import React, { useMemo } from 'react'; import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; -import { Tab, Tabs, TabList, TabPanel, TabPanels, Tag } from '@carbon/react'; +import { Tab, TabList, TabPanel, TabPanels, Tabs, Tag } from '@carbon/react'; import { type AssignedExtension, Extension, @@ -14,13 +14,13 @@ import { type Visit, } from '@openmrs/esm-framework'; import { - type Order, + type Diagnosis, type Encounter, + mapEncounters, type Note, type Observation, + type Order, type OrderItem, - type Diagnosis, - mapEncounters, } from '../visit.resource'; import VisitsTable from './visits-table/visits-table.component'; import MedicationSummary from './medications-summary.component'; @@ -117,11 +117,13 @@ const VisitSummary: React.FC = ({ visit, patientUuid }) => {

{t('diagnoses', 'Diagnoses')}

{diagnoses.length > 0 ? ( - diagnoses.map((diagnosis, i) => ( - - {diagnosis.diagnosis} - - )) + diagnoses + .sort((diagnosis) => (diagnosis.order === 'Primary' ? -1 : 1)) + .map((diagnosis, i) => ( + + {diagnosis.diagnosis} + + )) ) : (

{t('noDiagnosesFound', 'No diagnoses found')} From 8d3a1faeb24811ebf613f170e5259146e790c9b4 Mon Sep 17 00:00:00 2001 From: Usama Idriss Kakumba Date: Thu, 17 Oct 2024 10:33:42 +0300 Subject: [PATCH 2/4] feat: sort diagnoses by rank --- .../visit-summary.component.tsx | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx index f7890af148..f15ada6f0e 100644 --- a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx +++ b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx @@ -31,7 +31,8 @@ import styles from './visit-summary.scss'; interface DiagnosisItem { diagnosis: string; - order: string; + rank: number; + type: string; } interface VisitSummaryProps { @@ -70,14 +71,15 @@ const VisitSummary: React.FC = ({ visit, patientUuid }) => { ); } - //Check if there is a diagnosis associated with this encounter + // Check if there is a diagnosis associated with this encounter if (enc.hasOwnProperty('diagnoses')) { if (enc.diagnoses.length > 0) { enc.diagnoses.forEach((diagnosis: Diagnosis) => { // Putting all the diagnoses in a single array. diagnoses.push({ diagnosis: diagnosis.display, - order: diagnosis.rank === 1 ? 'Primary' : 'Secondary', + type: diagnosis.rank === 1 ? 'red' : 'blue', + rank: diagnosis.rank, }); }); } @@ -102,6 +104,9 @@ const VisitSummary: React.FC = ({ visit, patientUuid }) => { } }); + // Sort the diagnoses by rank, so that those of rank 1 come first + diagnoses.sort((a, b) => a.rank - b.rank); + return [diagnoses, notes, medications]; }, [config.notesConceptUuids, visit?.encounters]); @@ -117,13 +122,11 @@ const VisitSummary: React.FC = ({ visit, patientUuid }) => {

{t('diagnoses', 'Diagnoses')}

{diagnoses.length > 0 ? ( - diagnoses - .sort((diagnosis) => (diagnosis.order === 'Primary' ? -1 : 1)) - .map((diagnosis, i) => ( - - {diagnosis.diagnosis} - - )) + diagnoses.map((diagnosis, i) => ( + + {diagnosis.diagnosis} + + )) ) : (

{t('noDiagnosesFound', 'No diagnoses found')} From eda5598700c926fec50b8f56dd79f1efbcdb0b80 Mon Sep 17 00:00:00 2001 From: Usama Idriss Kakumba <53287480+usamaidrsk@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:07:35 +0300 Subject: [PATCH 3/4] add suggestions Co-authored-by: Dennis Kigen --- .../past-visits-components/visit-summary.component.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx index f15ada6f0e..191b442e9f 100644 --- a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx +++ b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx @@ -104,7 +104,7 @@ const VisitSummary: React.FC = ({ visit, patientUuid }) => { } }); - // Sort the diagnoses by rank, so that those of rank 1 come first + // Sort the diagnoses by rank, so that primary diagnoses come first diagnoses.sort((a, b) => a.rank - b.rank); return [diagnoses, notes, medications]; From f2f7621d5d58d7d28342aee0a7c65179c264b360 Mon Sep 17 00:00:00 2001 From: Usama Idriss Kakumba <53287480+usamaidrsk@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:37:41 +0300 Subject: [PATCH 4/4] add tests --- .../visit-summary.test.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.test.tsx b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.test.tsx index 26eb51f9f8..dd3a2cccfa 100644 --- a/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.test.tsx +++ b/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.test.tsx @@ -56,6 +56,24 @@ describe('VisitSummary', () => { expect(screen.getByText(/test-results-filtered-overview/)).toBeInTheDocument(); }); + it('renders diagnoses tags when there are diagnoses', () => { + const mockVisit = visitOverviewDetailMockDataNotEmpty.data.results[0]; + + render(); + + const malariaTag = screen.getByText(/^malaria, confirmed$/i); + const hivTag = screen.getByText(/human immunodeficiency virus \(hiv\)/i); + + expect(screen.getByText(/^diagnoses$/i)).toBeInTheDocument(); + expect(malariaTag).toBeInTheDocument(); + expect(hivTag).toBeInTheDocument(); + + // eslint-disable-next-line testing-library/no-node-access + expect(malariaTag.closest('div')).toHaveClass('cds--tag--red'); + // eslint-disable-next-line testing-library/no-node-access + expect(hivTag.closest('div')).toHaveClass('cds--tag--blue'); + }); + it('should display notes, tests and medication summary', async () => { const user = userEvent.setup();