5 Replies Latest reply on Jul 9, 2018 7:08 AM by Thomas Righele

    Application Integration - Handling multiple JSON arrays

    Thomas Righele Seasoned Veteran

      I am having some difficulty with some API calls I am making.

       

      I want to be able to make a call that starts a process that returns a response with multiple records. I want to go through this response and return one of the fields in an array. Example below:

       

      Response from App:

      {

          "orders": [

              {

                  "patientid": "2638751",

                  "encounterid": "2422011",

                  "description": "XR, ELBOW, 2 VIEW",

                  "documentid": "19561120",

              },

              {

                  "patientid": "2536696",

                  "encounterid": "2422012",

                  "description": "INFUSION CENTER REFERRAL",

                  "documentid": "19561121",

                  "assigneduser": "luckowoncauths",

              },

              {

                  "patientid": "2536696",

                  "encounterid": "2422012",

                  "description": "CBC W/ AUTO DIFF",

                  "documentid": "19561122",

                  "assigneduser": "luckowonclab",

              }

          ],

          "totalcount": 3

      }

       

      I want to be able to send:

      {

          "orders": [

              {

                  "patientid": "2638751",

              },

              {

                  "patientid": "2536696",

              },

              {

                  "patientid": "2536696",

       

       

              }

          ],

      }

       

      I've created the some simplistic process objects but I am not sure how to tie everything together:

      Root: totalcount, orders

      orders: patientid

       

      Any help would be greatly appreciated!! Thanks =)

        • 1. Re: Application Integration - Handling multiple JSON arrays
          bhim mantha Guru

          Hello ,

           

          You can use a FLWR expression to iterate over your api response

           

          1 Create your output variable of type "List of Any"

           

          2 Your API response should be List of Orders

           

          3 You will then use an assignment expression to map the response

           

          for $patient in $output.Patient_List

          return

          <orders>

          <patientid>{$output.Patient_List[1]/patientid }</patientid>

          </orders>

           

          If you are on IICS , pls. look at the artifacts attached

          1 of 1 people found this helpful
          • 2. Re: Application Integration - Handling multiple JSON arrays
            Prakash Jain Guru

            Hi Thomas,

             

            In ICRT, all the JSON gets converted into XML for parsing them. The expression(Xquery) works on the XMLs.

             

            So your JSON would get converted into this:

             

             

            <root>

              <orders>

                <patientid>2638751</patientid>

                <encounterid>2422011</encounterid>

                <description>XR, ELBOW, 2 VIEW</description>

                <documentid>19561120</documentid>

              </orders>

              <orders>

                <patientid>2536696</patientid>

                <encounterid>2422012</encounterid>

                <description>INFUSION CENTER REFERRAL</description>

                <documentid>19561121</documentid>

                <assigneduser>luckowoncauths</assigneduser>

              </orders>

              <orders>

                <patientid>2536696</patientid>

                <encounterid>2422012</encounterid>

                <description>CBC W/ AUTO DIFF</description>

                <documentid>19561122</documentid>

                <assigneduser>luckowonclab</assigneduser>

              </orders>

              <totalcount>3</totalcount>

            </root>

             

             

            Create a simple Process Object with 1 field and write the expression as below in the assignment step:

             

            for $i in $OutputVariableName//orders

            return

            <orders><patientid>{$i/patientid/text()}</patientid></orders>

             

             

            Please let me know if you have any further questions in this regard.

             

             

             

            Thanks,

            Prakash Jain

            1 of 1 people found this helpful
            • 3. Re: Application Integration - Handling multiple JSON arrays
              Thomas Righele Seasoned Veteran

              Thank you all for your help! I was able to get this to work with the expressions. Much appreciated! That example really helped.

               

              Is there anyway to do this with a sub-process as well? If so, are there any examples out there?

               

              Thanks again!

              Tom

              • 4. Re: Application Integration - Handling multiple JSON arrays
                Uma Ashok Guru

                Hi Thomas,

                 

                 

                An iteration over subprocess is usually used when you have to iterate over a specific object list where each iteration will call the subprocess and perform some activities, within it. The iteration will continue and execute subprocess until end of the list and then only invoke the step next to it in the parent process.

                 

                This case, it may not be a preferred approach as you aren't returning the output to the parent.

                 

                Another way you can get this to work is to "manually" iterate over the list, get the results for each iteration, store them in a master copy of the list and return it from the parent process. This is some overhead/slowness involved, like first creating a master list of output variables, then individually fetching the topmost record of the list that needs to be processed, passing it to the subprocess, fetching the results and storing it to the master list, remove from the processed record and repeat the cycle.

                 

                Considering your use case, best would be one of the two approaches as mentioned in the prev post above.