Skip to content

Commit

Permalink
(fix) Resolve issue preventing addition of patients to existing groups (
Browse files Browse the repository at this point in the history
#81)

* Fixed error when adding a patient to an existing group

* Fixed patient list sorting when loading an existing group
  • Loading branch information
icrc-psousa authored Apr 3, 2024
1 parent 0493326 commit ad854e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
32 changes: 17 additions & 15 deletions src/add-group-modal/AddGroupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ const NewGroupForm = (props) => {
};

const AddGroupModal = ({
patients = undefined,
isCreate = undefined,
groupName = "",
cohortUuid = undefined,
isOpen,
onPostCancel,
onPostSubmit,
}) => {
patients = undefined,
isCreate = undefined,
groupName = "",
cohortUuid = undefined,
isOpen,
onPostCancel,
onPostSubmit,
}) => {
const { setGroup } = useContext(GroupFormWorkflowContext);
const { t } = useTranslation();
const [errors, setErrors] = useState({});
Expand Down Expand Up @@ -197,17 +197,19 @@ const AddGroupModal = ({

const updatePatientList = useCallback(
(patientUuid) => {
function getPatientName(patient) {
return [patient?.name?.[0]?.given, patient?.name?.[0]?.family].join(
" "
);
}
if (!patientList.find((p) => p.uuid === patientUuid)) {
fetchCurrentPatient(patientUuid).then((result) => {
const newPatient = {
uuid: patientUuid,
name: [result?.name?.[0]?.given, result?.name?.[0]?.family].join(
" "
),
};
const newPatient = { uuid: patientUuid, ...result };
setPatientList(
[...patientList, newPatient].sort((a, b) =>
a.name?.localeCompare(b?.name, { sensitivity: "base" })
getPatientName(a).localeCompare(getPatientName(b), undefined, {
sensitivity: "base",
})
)
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ const GroupSearchHeader = () => {
);
const [isOpen, setOpen] = useState(false);
const handleSelectGroup = (group) => {
group.cohortMembers.sort((a, b) =>
a.display?.localeCompare(b?.display, { sensitivity: "base" })
group.cohortMembers.sort((a, b) => {
let aName = a?.patient?.person?.names?.[0]?.display;
let bName = b?.patient?.person?.names?.[0]?.display;
return aName.localeCompare(bName, undefined, {sensitivity: "base"});
}
);
setGroup(group);
};
Expand Down

0 comments on commit ad854e4

Please sign in to comment.