(Untitled)

Options
I have an API that pulls peoples' daily entries for various symptom pain levels. Each symptom is rated on a score from 0-8 (called ECOG)

Here's a sample of what the data JSON looks like. The average user will have ~10 different symptoms tracked over several months.

Objective: How do I filter for the top 5 symptoms with the highest cumulative ECOG values?
[{"id":418,
"user_id":142,
"date_entry":"2022-09-06",
"symptoms_ecog":
[{
"symptoms_id":137,
"ecog":5,
"symptoms_name":{"symptom":"Fatigue","medical_term":""}},

{"symptoms_id":162,
"ecog":3,
"symptoms_name":
{"symptom":"Headaches",
"medical_term":""}},

{"symptoms_id":138,
"ecog":7,
"symptoms_name":{"symptom":"Nausea","medical_term":""}}]},

{"id":419,
"user_id":142,
"date_entry":"2022-09-05",
"symptoms_ecog":
[{
"symptoms_id":137,
"ecog":5,
"symptoms_name":{"symptom":"Fatigue","medical_term":""}},

{"symptoms_id":162,
"ecog":3,
"symptoms_name":
{"symptom":"Headaches",
"medical_term":""}},

{"symptoms_id":138,
"ecog":7,
"symptoms_name":{"symptom":"Nausea","medical_term":""}}]},

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    You use the sort filter with the path of "ecog" and descending order to get the top egogs floating to the top of your list. 

    Then you add the "slice" filter and take the first five - offset 0 and length 5. 

    Hooray! You have your top 5!
  • Thanks Ray! I see what you mean here, I think the challenge is that only works if I'm filtering for a single day. 

    What I was hoping to achieve is to look at which symptoms have the highest "cumulative" value of ecog over the past 2 weeks or months or whatever, and then take the symptoms with the highest cumulative value and select the top 5 from there, basically taking the 5 selected symptoms and applying that as a filter to my original query (would have to be some form of higher order filtering I'm guessing). 

    I'm finding myself stuck at the filtering section, once I have a list of which top 5 symptoms I need to filter for, how can I go back to the original query and set it up to only pull symptoms that I specified after running that calculation

    Does that make sense?

    Appreciate you taking the time to respond btw!