Skip to content

Commit

Permalink
Consider only patient name and not id when sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
icrc-psousa committed Mar 27, 2024
1 parent ea6edbb commit 121ea9c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/add-group-modal/AddGroupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,31 @@ const SortedPatientList = (props) => {
const getPersonDisplay = (patient) => {
if (!patient) return null;

const { identifier, name } = patient;
const displayIdentifier = identifier?.[0]?.value || "";
const givenNames = `${(name?.[0]?.given || []).join(" ")} ${
name?.[0]?.family || ""
}`;
const displayIdentifier = patient.identifier?.[0]?.value || "";

return `${
displayIdentifier ? `${displayIdentifier} -` : ""
} ${givenNames}`.trim();
} ${getPersonName(patient)}`.trim();
};

const getPersonName = (patient) => {
if (!patient) return null;
return `${(patient.name?.[0]?.given || []).join(" ")} ${
patient.name?.[0]?.family
}`.trim();
};

return patientList
.map((obj) => {
return {
uuid: obj.uuid,
name: getPersonName(obj),
display: getPersonDisplay(
patients.find((value) => value.id === obj.uuid)
),
};
})
.sort((a, b) => a.display?.localeCompare(b?.display));
.sort((a, b) => a.name?.localeCompare(b?.name));
}, [patients, patientList]);

return (
Expand Down

0 comments on commit 121ea9c

Please sign in to comment.