Removing duplicates while filtering list of items

We have a list of illnesses for which the same medication is recommended. We wanted
to show the user an aggregate list of medications where duplicates are removed.
Specifically, we are looking for a way of filtering a list of medications in such
a way that the filter rule merges medications with the same name but different dosage, taking
taking the medication with the higher dose.

Example:-
Input:
[{name:Amoxilin,dose: 10}, {name:jentamicin, dose 10}, {name:Amoxilin, dose: 5} ]

Expected output:
[{name:Amoxilin,dose: 10}, {name:jentamicin, dose: 10} ]

Where does this aggregate list of medications come from - how is it generated?

it comes from lookup table and generated using this xpath Expression
instance(‘iccm_illness_meds’)/iccm_illness_meds_list/iccm_illness_meds[index = current()/…/…/@id]/medication

This sounds a bit tricky, but you may be able to get something working. Here’s one possible approach:

  • It sounds like you already have a list (an itemset, in xpath terminology) of recommended medicines for the patient. I’ll call this prescribed_meds
  • Create a lookup table of all unique medication types. (unique_meds)
  • Filter unique_meds by whether that medication is in prescribed_meds, something like:
    instance('unique_meds')/meds_list/meds/med[selected(/path/to/prescribed_meds/medication_id, medication_id].
  • That will give you a deduplicated itemset of all medications prescribed for the patient.
  • Within that, select the maximum dosage from prescribed_meds, filtered by the current medication_id. Something like:
    dosage = max(/path/to/prescribed_meds[medication_id=current()/../../medication_id]/dosage)

It does seem quite complicated though. Let us know if you manage to get something working!