Filter based on previous vertex value

I want to follow each person’s journey through multiple vertices and edges. Many people go through the same vertices. How do I avoid overlapping one person’s journey with someone else’s?

Let’s say I have a patient who went to a doctor. That patient got referred to another doctor and then saw that 2nd doctor. Then the patient gets referred by that 2nd doctor to a third doctor and so on.
doctor - (created) -> referral
referral - (saw_by)-> doctor

referral has information such as who is the patient_id, etc. I want to know all patients’ journey, not just one patient. I also don’t want to merge one person’s journey with someone else’s.

I would recommend storing the uniquely-identifying patient information in the edges (created) and (saw_by) as attributes. That way, you can specify the examination of a single person’s journey by ensuring that their unique ID is marked on any edge traversal that you perform.

If you want to examine all patients’ journeys relating to a single referral, you can simply inspect all the edges that the referral is connected to in order to form an idea of who traveled down similar medical routes in relation to this referral.