Can you add an PatientID attribute to MedicalEvent and then maybe create and run a conversion microflow which retrieves all the medicalevents and then uses a loop to iterate over each and retrieve the associated patient and then fills in the PatientID attribute in MedicalEvent with the one from Patient?
So it would look like this (to avoid committing in loops): Retrieve (MedicalEventList). → [Loop (MedicalEventIterator): Retrieve Patient over association → ChangeObject (MedicalEvent) Set(PatientIDME = PatientID) no refresh/no commit) and then commit the medicaleventlist after the loop.
You can then sort based on patientID. You could name the new attribute _PatientID (with the underscore). That reads as a helper attribute (best practices).
There are other ways im sure but this is one as well.