Filter list based on same association

0
Hello,    So I have three entities: Patient, Coordinator and Caregroup. -Each Coordinator has his own an account. - There are three different caregroups let's say a,b and c, both coordinator and patient are part of one of these caregroups.    So my question is how can I return a list of patients that have the same caregroup as the coordinator which is logged in at the moment.  I already tried using an Xpath query  [MyFirstModule.Patient_Caregroup/MyFirstModule.Caregroup] However this is just returning an empty list.   Thanks in Adcance  
asked
3 answers
2

 

Quite a lot to unpack here.  Firstly if 

 

[MyFirstModule.Patient_Caregroup/MyFirstModule.Caregroup]

is returning an empty list you don’t have any patients associated to a care group.  The above XPath is simply filtering to any patient in any caregroup.

 

Lennart’s answer on how to work out the XPath is correct though.  Here’s a bit of an explanation on where you’ve gone wrong and how to fix it.

 

 

[MyFirstModule.Coordinator_Caregroup/MyFirstModule.Coordinator/MyFirstModule.Coordinator_Account/Administration.Account/id = $currentUser]

This is getting a list of caregroups, whereas you only want one as your model has one coordinator per account, and one care group per coordinator.  You can therefore retrieve this from association, or just change your retrieve to return first rather than all.  

 

This XPath can be simplified/shortened a little bit anyhow:

[MyFirstModule.Coordinator_Caregroup/MyFirstModule.Coordinator/MyFirstModule.Coordinator_Account = $currentUser]

 

 

Once you get your caregroup (Rather than caregroup list) then this should work:

 

[MyFirstModule.Patient_Caregroup/MyFirstModule.Caregroup/id = $Caregroup]

 

You can simplify this down to a single retrieve of patients as follows:

[MyFirstModule.Patient_Caregroup/MyFirstModule.Caregroup
/MyFirstModule.Coordinator_Caregroup/MyFirstModule.Coordinator
/MyFirstModule.Coordinator_Account = $currentUser]

This is saying get me all patients who are in a care group where the coordinator of the caregroup has the same account as the current user.

 

Since this can be expressed as a single XPath you don’t need to retrieve using a microflow, but instead can use this xpath (Where you need to use the token for the current user):

[MyFirstModule.Patient_Caregroup/MyFirstModule.Caregroup
/MyFirstModule.Coordinator_Caregroup/MyFirstModule.Coordinator
/MyFirstModule.Coordinator_Account = '[%CurrentUser%]']

 

Hope that helps.  As Lennart says there are helpful learning paths to follow for this explaining how XPath works:

 

https://academy.mendix.com/link/paths/62/Constrain-Your-Data-Using-XPath  (Intermediate)

https://academy.mendix.com/link/paths/109/Constrain-your-Data-using-Advanced-XPath  (Advanced)

 

Cheers,

Dom

answered
3

You need to make a comparison. 

1) In order to use a parameter, first retrieve the caregroup that the current user belongs to.

2) Next retrieve the patients that belong to the same caregroup by comparing the id like this in your xpath:

[MyFirstModule.Patient_Caregroup/MyFirstModule.Caregroup/id = $Caregroup]

 

Or alternatively do a retrieve over association from the Caregroup you just retrieved in step 1.

 

 

answered
0

 

 

So I tried this for the first action: 

[MyFirstModule.Coordinator_Caregroup/MyFirstModule.Coordinator/MyFirstModule.Coordinator_Account/Administration.Account/id = $currentUser]

and this for the second one:

[MyFirstModule.Patient_Caregroup/MyFirstModule.Caregroup/id = $CaregroupList]

but I am still getting an error: Variable ‘CaregroupList’ has an unsupported type List. :/

answered