Skip to content

Commit 3f83f7b

Browse files
Fix session clinic invitations
1 parent b907243 commit 3f83f7b

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

app/controllers/session.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -819,26 +819,30 @@ export const sessionController = {
819819
)
820820

821821
// Find patients to invite to clinic
822-
const patientSessionsForClinic = session.patientSessionsForClinic.map(
822+
const patientUuidsForClinic = session.patientSessionsForClinic.map(
823823
(patient) => patient.uuid
824824
)
825825

826-
// Move patients to clinic
827826
if (clinic) {
828-
for (const patientSession of patientSessionsForClinic) {
829-
const patient = Patient.findOne(patientSession.patient_uuid, data)
830-
patientSession.removeFromSession({
831-
createdBy_uid: account.uid
832-
})
833-
patient.addToSession(patientSession.session)
834-
Patient.update(patientSession.patient_uuid, {}, data)
827+
// Move patients to clinic
828+
for (const patientUuid of patientUuidsForClinic) {
829+
const patientSession = PatientSession.findOne(patientUuid, data)
830+
831+
if (patientSession) {
832+
patientSession.removeFromSession({
833+
createdBy_uid: account.uid
834+
})
835+
patientSession.patient.addToSession(patientSession.session)
836+
837+
Patient.update(patientSession.patient_uuid, {}, data)
838+
}
835839
}
836840
}
837841

838842
request.flash(
839843
'success',
840844
__mf(`session.inviteToClinic.success`, {
841-
count: patientSessionsForClinic.length
845+
count: patientUuidsForClinic.length
842846
})
843847
)
844848

0 commit comments

Comments
 (0)