Skip to content

Commit

Permalink
(fix) O3-2280: Fix navigation links in the active visits widget (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
denniskigen authored Jul 21, 2023
1 parent b3f3025 commit 8269de2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ const ActiveVisitsTable = () => {
const { t } = useTranslation();
const config = useConfig();
const layout = useLayoutType();
const [pageSize, setPageSize] = useState(config?.activeVisits?.pageSize ?? 10);
const pageSizes = config?.activeVisits?.pageSizes ?? [10, 20, 30, 40, 50];
const { activeVisits, isLoading, isValidating, isError } = useActiveVisits();
const [pageSize, setPageSize] = useState(config?.activeVisits?.pageSize ?? 10);
const { activeVisits, isLoading, isValidating, error } = useActiveVisits();
const [searchString, setSearchString] = useState('');

const currentPathName = window.location.pathname;
Expand Down Expand Up @@ -184,11 +184,11 @@ const ActiveVisitsTable = () => {
);
}

if (isError) {
if (error) {
return (
<div className={styles.activeVisitsContainer}>
<Layer>
<ErrorState error={isError} headerTitle={t('activeVisits', 'Active Visits')} />
<ErrorState error={error} headerTitle={t('activeVisits', 'Active Visits')} />
</Layer>
</div>
);
Expand Down Expand Up @@ -244,43 +244,45 @@ const ActiveVisitsTable = () => {
</TableRow>
</TableHead>
<TableBody>
{rows.map((row, index) => (
<React.Fragment key={index}>
<TableExpandRow
{...getRowProps({ row })}
data-testid={`activeVisitRow${activeVisits?.[index]?.patientUuid}`}>
{row.cells.map((cell) => (
<TableCell key={cell.id} data-testid={cell.id}>
{cell.info.header === 'name' ? (
<PatientNameLink
from={fromPage}
to={`\${openmrsSpaBase}/patient/${activeVisits?.[index]?.patientUuid}/chart/`}>
{cell.value}
</PatientNameLink>
) : (
cell.value
)}
</TableCell>
))}
</TableExpandRow>
{row.isExpanded ? (
<TableRow className={styles.expandedActiveVisitRow}>
<th colSpan={headers.length + 2}>
<ExtensionSlot
className={styles.visitSummaryContainer}
name="visit-summary-slot"
state={{
visitUuid: activeVisits[index]?.visitUuid,
patientUuid: activeVisits[index]?.patientUuid,
}}
/>
</th>
</TableRow>
) : (
<TableExpandedRow className={styles.hiddenRow} colSpan={headers.length + 2} />
)}
</React.Fragment>
))}
{rows.map((row, index) => {
const visit = activeVisits.find((visit) => visit.id === row.id);

return (
<React.Fragment key={index}>
<TableExpandRow {...getRowProps({ row })} data-testid={`activeVisitRow${visit.patientUuid}`}>
{row.cells.map((cell) => (
<TableCell key={cell.id} data-testid={cell.id}>
{cell.info.header === 'name' ? (
<PatientNameLink
from={fromPage}
to={`\${openmrsSpaBase}/patient/${visit.patientUuid}/chart/Patient%20Summary`}>
{cell.value}
</PatientNameLink>
) : (
cell.value
)}
</TableCell>
))}
</TableExpandRow>
{row.isExpanded ? (
<TableRow className={styles.expandedActiveVisitRow}>
<th colSpan={headers.length + 2}>
<ExtensionSlot
className={styles.visitSummaryContainer}
name="visit-summary-slot"
state={{
visitUuid: activeVisits[index]?.visitUuid,
patientUuid: activeVisits[index]?.patientUuid,
}}
/>
</th>
</TableRow>
) : (
<TableExpandedRow className={styles.hiddenRow} colSpan={headers.length + 2} />
)}
</React.Fragment>
);
})}
</TableBody>
</Table>
</TableContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,18 @@ export function useActiveVisits() {
return null;
}

let url = `/ws/rest/v1/visit?includeInactive=false&v=${customRepresentation}&totalCount=true&location=${sessionLocation}`;
let url = `/ws/rest/v1/visit?v=${customRepresentation}&`;
let urlSearchParams = new URLSearchParams();

urlSearchParams.append('includeInactive', 'false');
urlSearchParams.append('totalCount', 'true');
urlSearchParams.append('location', `${sessionLocation}`);

if (pageIndex) {
url += `&startIndex=${pageIndex * 50}`;
urlSearchParams.append('startIndex', `${pageIndex * 50}`);
}

return url;
return url + urlSearchParams.toString();
};

const {
Expand All @@ -73,7 +78,7 @@ export function useActiveVisits() {
}, [data, pageNumber]);

const mapVisitProperties = (visit: Visit): ActiveVisit => {
//create base object
// create base object
const activeVisits: ActiveVisit = {
age: visit?.patient?.person?.age,
id: visit.uuid,
Expand All @@ -87,36 +92,36 @@ export function useActiveVisits() {
visitUuid: visit.uuid,
};

//in case no configuration is given the previous behavior remains the same
// in case no configuration is given the previous behavior remains the same
if (!config?.activeVisits?.identifiers) {
activeVisits.idNumber = visit?.patient?.identifiers[0]?.identifier ?? '--';
} else {
//map identifiers on config
// map identifiers on config
config?.activeVisits?.identifiers?.map((configIdentifier) => {
//check if in the current visit the patient has in his identifiers the current identifierType name
// check if in the current visit the patient has in his identifiers the current identifierType name
const visitIdentifier = visit?.patient?.identifiers.find(
(visitIdentifier) => visitIdentifier?.identifierType?.name === configIdentifier?.identifierName,
);

//add the new identifier or rewrite existing one to activeVisit object
//the parameter will corresponds to the name of the key value of the configuration
//and the respective value is the visit identifier
//If there isn't a identifier we display this default text '--'
// add the new identifier or rewrite existing one to activeVisit object
// the parameter will corresponds to the name of the key value of the configuration
// and the respective value is the visit identifier
// If there isn't a identifier we display this default text '--'
activeVisits[configIdentifier.header?.key] = visitIdentifier?.identifier ?? '--';
});
}

//map attributes on config
// map attributes on config
config?.activeVisits?.attributes?.map(({ display, header }) => {
//check if in the current visit the person has in his attributes the current display
// check if in the current visit the person has in his attributes the current display
const personAttributes = visit?.patient?.person?.attributes.find(
(personAttributes) => personAttributes?.attributeType?.display === display,
);

//add the new attribute or rewrite existing one to activeVisit object
//the parameter will correspond to the name of the key value of the configuration
//and the respective value is the persons value
//If there isn't a attribute we display this default text '--'
// add the new attribute or rewrite existing one to activeVisit object
// the parameter will correspond to the name of the key value of the configuration
// and the respective value is the persons value
// If there isn't a attribute we display this default text '--'
activeVisits[header?.key] = personAttributes?.value ?? '--';
});

Expand All @@ -129,9 +134,9 @@ export function useActiveVisits() {

return {
activeVisits: formattedActiveVisits,
error,
isLoading,
isValidating,
isError: error,
totalResults: data?.[0]?.data?.totalCount ?? 0,
};
}
Expand Down

0 comments on commit 8269de2

Please sign in to comment.