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-2280: Fix navigation links in the active visits widget #761

Merged
merged 3 commits into from
Jul 21, 2023
Merged
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 @@ -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);
denniskigen marked this conversation as resolved.
Show resolved Hide resolved

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,
Comment on lines +137 to 139
Copy link
Member Author

@denniskigen denniskigen Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renames isError to error, a more accurate representation of what the variable does.

isError: error,
totalResults: data?.[0]?.data?.totalCount ?? 0,
};
}
Expand Down
Loading