Skip to main content
Inspiring
Oct 21, 2021 10:18 AM UTC
Solved

convert the list into array

Hi team,

i have an expression rule to get the doctors with count of patients assigned to them with the disease but i want to get the  total patience count for that particular doctor with array of disease like eg:

swift:3:{cance,Gallstones,Emotional Disorder}, Please help me to achieve this format

substitute(substitute(substitute(substitute(
  substitute(
    substitute(
      a!queryEntity(
        entity: cons!PO_MEDICALINFO,
        query: a!query(
          logicalexpression: a!queryLogicalExpression(
           operator: "AND",
          filters:  {
           a!queryFilter(
             field: "reasonForVisit", 
             operator: "in",
             value:ri!reasonForVisit 
           ),
            a!queryFilter(
              field:"appointmentDate",
              operator: "between",
              value: {
                todatetime(ri!createddatefrom),
                todatetime(ri!createddateto)
              },
              applywhen: and(
                not(rule!APN_isEmpty(ri!createddatefrom)),
                not(rule!APN_isEmpty(ri!createddateto)))
              
            ),

 
          },
          ignorefilterswithemptyvalues: true()
          
          ),
          aggregation: a!queryAggregation(
            aggregationColumns: {
              a!queryAggregationColumn(
                field: "reportingDoctor",
                isGrouping: true,
              ),
              a!queryAggregationColumn(
                field: "patientId",
                alias:"patientCount",
                aggregationFunction:"COUNT"

              ),
              a!queryAggregationColumn(
                field: "reasonForVisit",
                isGrouping: true
              )
              
              
            },

          ),
          pagingInfo: a!pagingInfo(
            startIndex: 1,
            batchSize: -1,
            sort: a!sortInfo(
              field: "patientCount",
              ascending: true()
            )
          )
        ),
        fetchTotalCount: true
      ).data,"patientCount",""),"reportingDoctor:",""),",",""),"[",""),"]",""),"reasonForVisit","")

    andrewh0007
    Inspiring
    Oct 25, 2021 9:46 PM UTC

    Haha, I hadn't heard of property()!! Thanks.

    I agree with everything you've said. I've used reject() since before a!forEach() existed but never thought of using apply() either so I've just always used it. I might spawn different discussions (but also search for other discussions first) to dive deeper into why one is better than the other.

    13 replies

    Inspiring
    Oct 21, 2021 2:53 PM UTC

    Can you show what the return for your a!queryEntity(...).data looks like without all those substitutes in there?

    andrewh0007
    Inspiring
    Oct 22, 2021 4:29 AM UTC

    Likely the answer will be to build a view in the database that displays the data in the appropriate format but the need to output in that very particular text format confuses me. At the very least if that format is required for some reason I'd still output in a CDT and then have a transformation expression rule.

    If this hasn't answered your query please provide more details and the expression output of the a!queryEntity()

    Inspiring
    Oct 22, 2021 6:32 AM UTC

    my requirement is upon giving the doctor name  i need to get all the reasons for visit for that particular doctor with a comma separated like eg:{cancer,Gout,fever}. I need to get the reasonfor visit in a array format

    mikes0011
    Brainy
    Oct 22, 2021 3:08 PM UTC

    When you say "upon giving the doctor name..." - maybe you could pass the doctor name into the Query Entity rule as a filter, then the resulting list would only be visits to that particular doctor, and you could arrange the "reasonForVisit" properties in whatever way you require?  Or are you after some sort of enumeration of ALL doctors followed by an array of ALL visit reasons for that doctor, all at once?  This is trickier but should be doable.

    The Expression Guru