Skip to content

Commit

Permalink
Restructure directories and fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau committed Dec 18, 2024
1 parent 359217f commit e146333
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Tabs, Tab, TabList, TabPanels, TabPanel } from '@carbon/react';
import { EncounterList } from './encounter-list.component';
import { getMenuItemTabsConfiguration } from '../utils/encounter-list-config-builder';
import styles from './encounter-list-tabs.scss';
import { filter } from '../utils/helpers';
import { type Encounter } from '../types';
import { filter } from '../utils/helpers';

interface EncounterListTabsComponentProps {
patientUuid: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import React, { useCallback, useMemo, useState } from 'react';
import { navigate, showModal, showSnackbar, type Visit } from '@openmrs/esm-framework';
import { EmptyState } from '@openmrs/esm-patient-common-lib';
import { useTranslation } from 'react-i18next';
import { EncounterListDataTable } from './table.component';
import { Button, Link, OverflowMenu, OverflowMenuItem, DataTableSkeleton, Pagination } from '@carbon/react';
import { Add } from '@carbon/react/icons';
import { launchEncounterForm } from '../utils/helpers';
import { deleteEncounter } from '../encounter-list.resource';
import { useEncounterRows, useFormsJson } from '../hooks';

import styles from './encounter-list.scss';
import { type TableRow, type Encounter, type Mode, type ColumnValue } from '../types';
import { type FormattedColumn } from '../utils/encounter-list-config-builder';
import { type TableRow, type Encounter, type Mode, type ColumnValue, type FormattedColumn } from '../types';
import { deleteEncounter } from '../utils/encounter-list.resource';
import { EncounterListDataTable } from './table.component';
import { launchEncounterForm } from '../utils/helpers';

export interface EncounterListColumn {
key: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { memo, useMemo } from 'react';

import { useTranslation } from 'react-i18next';
import { EncounterTile } from './encounter-tile/encounter-tile.component';
import { type ConfigObject, useConfig } from '@openmrs/esm-framework';
import { getEncounterTileColumns, type MenuCardProps } from '../utils';
import { getEncounterTileColumns } from '../utils';
import { EncounterTile } from './encounter-tile.component';
import { type MenuCardProps } from '../types';

interface OverviewListProps {
patientUuid: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,10 @@ import React, { useMemo } from 'react';
import { useLayoutType } from '@openmrs/esm-framework';
import { CodeSnippetSkeleton, Tile, Column, Layer } from '@carbon/react';
import styles from './tile.scss';
import { type Encounter, groupColumnsByEncounterType } from '../../utils/helpers';
import { useLastEncounter } from '../../hooks/useLastEncounter';
import { groupColumnsByEncounterType } from '../utils/helpers';
import { useTranslation } from 'react-i18next';

export interface EncounterTileColumn {
key: string;
header: string;
encounterUuid: string;
concept: string;
title?: string;
getObsValue: (encounter: Encounter) => string;
getSummaryObsValue?: (encounter: Encounter) => string;
encounter?: Encounter;
hasSummary?: Boolean;
}
export interface EncounterTileProps {
patientUuid: string;
columns: Array<EncounterTileColumn>;
headerTitle: string;
}
import { type EncounterTileColumn, type EncounterTileProps } from '../types';
import { useLastEncounter } from '../hooks';

export const EncounterTile = React.memo(({ patientUuid, columns, headerTitle }: EncounterTileProps) => {
const columnsByEncounterType = useMemo(() => groupColumnsByEncounterType(columns), [columns]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './useEncounterRows';
export * from './useFormsJson';
export * from './useLastEncounter';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { openmrsFetch } from '@openmrs/esm-framework';
import useSWR from 'swr';
import { type Encounter } from '../utils/helpers';
import { type Encounter } from '../types';

export const encounterRepresentation =
const encounterRepresentation =
'custom:(uuid,encounterDatetime,encounterType,location:(uuid,name),' +
'patient:(uuid,display,age,identifiers,person),encounterProviders:(uuid,provider:(uuid,name)),' +
'obs:(uuid,obsDatetime,voided,groupMembers,concept:(uuid,display,name:(uuid,name)),value:(uuid,name:(uuid,name,display),' +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface Observation {
uuid: string;
name: {
name: string;
display?: string;
};
names?: Array<{ uuid: string; name: string; conceptNameType: string }>;
}
Expand Down Expand Up @@ -141,7 +142,7 @@ export interface ColumnDefinition {
conditionalActionOptions?: Array<ConditionalActionProps>;
isDate?: boolean;
isTrueFalseConcept?: boolean;
type?: string;
type?: EncounterPropertyType;
isLink?: boolean;
useMultipleObs?: boolean;
valueMappings?: Record<string, string>;
Expand All @@ -150,6 +151,9 @@ export interface ColumnDefinition {
isConditionalConcept?: boolean;
conditionalConceptMappings?: Record<string, string>;
conditionalEncounterMappings?: Record<string, ConditionalEncounterMapping>;
encounterType: string;
hasSummary?: boolean;
summaryConcept?: SummaryConcept;
}

export interface ConditionalEncounterMapping {
Expand Down Expand Up @@ -209,3 +213,86 @@ export interface ConfigConcepts {
falseConceptUuid: string;
otherConceptUuid: string;
}

export interface FormattedColumn {
key: string;
header: string;
getValue: (encounter: Encounter) => ColumnValue;
link?: { getUrl: (encounter: Encounter) => string; handleNavigate?: (encounter: Encounter) => void };
concept?: string;
}

export interface EncounterTileColumn {
key: string;
header: string;
encounterUuid: string;
concept: string;
title?: string;
getObsValue: (encounter: Encounter) => string;
getSummaryObsValue?: (encounter: Encounter) => string;
encounter?: Encounter;
hasSummary?: Boolean;
}
export interface EncounterTileProps {
patientUuid: string;
columns: Array<EncounterTileColumn>;
headerTitle: string;
}

export interface MenuCardProps {
tileHeader: string;
columns: Array<ColumnDefinition>;
}

interface SummaryConcept {
primaryConcept: string;
secondaryConcept?: string;
isDate?: boolean;
hasCalculatedDate?: boolean;
}

export interface FormattedCardColumn {
key: string;
header: string;
concept: string;
encounterUuid: string;
title?: string;
getObsValue: (encounter: Encounter) => string;
getSummaryObsValue?: (encounter: Encounter) => string;
hasSummary: boolean;
}

export interface ConfigConcepts {
trueConceptUuid: string;
falseConceptUuid: string;
otherConceptUuid: string;
}

export interface Encounter extends OpenmrsResource {
encounterDatetime: Date;
encounterType: { uuid: string; name: string };
patient: {
uuid: string;
display: string;
age: number;
birthDate: string;
};
location: {
uuid: string;
display: string;
name: string;
};
encounterProviders?: Array<{ encounterRole: string; provider: { uuid: string; name: string } }>;
obs: Array<Observation>;
form?: {
uuid: string;
};
visit?: string;
}

export enum EncounterPropertyType {
location = 'location',
provider = 'provider',
visitType = 'visitType',
ageAtEncounter = 'ageAtEncounter',
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
type NamedColumn,
type ConfigConcepts,
} from '../types';
import { renderTag } from '../components/tag.component';
import { renderTag } from '../encounter-list/tag.component';

export interface FormattedColumn {
key: string;
Expand Down
80 changes: 32 additions & 48 deletions packages/esm-patient-chart-app/src/clinical-views/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,33 @@
import { age, formatDate, type OpenmrsResource, parseDate } from '@openmrs/esm-framework';
import { type EncounterTileColumn } from '../components/encounter-tile/encounter-tile.component';
import { type ConfigConcepts } from '.';

export interface Observation {
uuid: string;
concept: { uuid: string; name: string };
value:
| {
uuid: string;
name: {
name: string;
display: string;
};
names?: Array<{ uuid: string; name: string; conceptNameType: string }>;
}
| string;
groupMembers?: Array<Observation>;
obsDatetime: string;
}

export interface Encounter extends OpenmrsResource {
encounterDatetime: Date;
encounterType: { uuid: string; name: string };
patient: {
uuid: string;
display: string;
age: number;
birthDate: string;
};
location: {
uuid: string;
display: string;
name: string;
};
encounterProviders?: Array<{ encounterRole: string; provider: { uuid: string; name: string } }>;
obs: Array<Observation>;
form?: {
uuid: string;
};
visit?: string;
}

export enum EncounterPropertyType {
location = 'location',
provider = 'provider',
visitType = 'visitType',
ageAtEncounter = 'ageAtEncounter',
import { age, formatDate, parseDate, type Visit } from '@openmrs/esm-framework';
import { type ConfigConcepts, type Encounter, type EncounterPropertyType, type EncounterTileColumn, type Form, type Observation } from '../types';
import { launchPatientWorkspace } from '@openmrs/esm-patient-common-lib';

type LaunchAction = 'add' | 'view' | 'edit' | 'embedded-view';

export function launchEncounterForm(
form: Form,
visit: Visit,
action: LaunchAction = 'add',
onFormSave: () => void,
encounterUuid?: string,
intent: string = '*',
patientUuid?: string,
) {
launchPatientWorkspace('patient-form-entry-workspace', {
workspaceTitle: form?.name,
mutateForm: onFormSave,
formInfo: {
encounterUuid,
formUuid: form?.uuid,
patientUuid: patientUuid,
visit: visit,
additionalProps: {
mode: action === 'add' ? 'enter' : action,
formSessionIntent: intent,
openClinicalFormsWorkspaceOnFormClose: false,
},
},
});
}

export function getEncounterValues(encounter: Encounter, param: string, isDate?: Boolean) {
Expand Down Expand Up @@ -211,3 +193,5 @@ export const getEncounterProperty = (encounter: Encounter, type: EncounterProper
return age(encounter.patient.birthDate, encounter.encounterDatetime);
}
};

export const filter = (encounter: Encounter, formUuid: string) => encounter?.form?.uuid === formUuid;
49 changes: 2 additions & 47 deletions packages/esm-patient-chart-app/src/clinical-views/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,5 @@
import { type TFunction } from 'i18next';
import { type Encounter, type EncounterPropertyType, getConceptFromMappings, getObsFromEncounter } from './helpers';
import { type EncounterTileColumn } from '../components/encounter-tile/encounter-tile.component';
import { OpenmrsEncounter } from '@openmrs/esm-patient-common-lib';

export interface MenuCardProps {
tileHeader: string;
columns: Array<ColumnDefinition>;
}

interface SummaryConcept {
primaryConcept: string;
secondaryConcept?: string;
isDate?: boolean;
hasCalculatedDate?: boolean;
}

export interface ColumnDefinition {
id: string;
title: string;
concept: string;
encounterType: string;
isDate?: boolean;
hasSummary?: boolean;
conceptMappings?: Array<string>;
summaryConcept?: SummaryConcept;
isTrueFalseConcept?: boolean;
type?: EncounterPropertyType;
fallbackConcepts?: Array<string>;
}

export interface FormattedCardColumn {
key: string;
header: string;
concept: string;
encounterUuid: string;
title?: string;
getObsValue: (encounter: Encounter) => string;
getSummaryObsValue?: (encounter: Encounter) => string;
hasSummary: boolean;
}

export interface ConfigConcepts {
trueConceptUuid: string;
falseConceptUuid: string;
otherConceptUuid: string;
}
import { getConceptFromMappings, getObsFromEncounter } from './helpers';
import { type ColumnDefinition, type ConfigConcepts, type EncounterTileColumn, type MenuCardProps } from '../types';

const calculateDateDifferenceInDate = (givenDate: string): string => {
const dateDifference = new Date().getTime() - new Date(givenDate).getTime();
Expand Down
Loading

0 comments on commit e146333

Please sign in to comment.