Skip to main content
October 21, 2021
Solved

convert the list into array

  • October 21, 2021
  • 13 replies
  • 0 views

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","")

    Best answer by andrewh0007

    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

    October 21, 2021

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

    andrewh0007
    October 22, 2021

    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()

    October 22, 2021

    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
    October 22, 2021

    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.