Question
· May 21

Join JSON responses

Good morning, 🙂

I would like to ask a question, which has to do with how to manage %GlobalCharacterStream representing JSONS.

Thank you for reading this question, thank you for your help, and thank you for your time and attention.

Specifically, in a certain Process, we were querying 2 Operations, whose response we were converting to a Property called "informesAutorizadosRangoFechas" (reportsAuthorizedInRangeDates) which is %GlobalCharacterStream whose content is a JSON with the same structure.

That is, at a visual level, a concrete example is the following:

Response from Operation 1: the content of the Property informesAutorizadosRangoFechas (reportsAuthorizedInRangeDates) is:

{
    "resourceType": "Bundle",
    "type": "searchset",
    "entry": [
        {
            "resource": [
                {
                    "resourceType": "ServiceRequest",
                    "contained": [
                        {
                            "resourceType": "Practitioner",
                            "id": "id",
                            "name": [
                                {
                                    "text": "text",
                                    "family": " ",
                                    "given": [
                                        "given"
                                    ],
                                    "extension": [
                                        {
                                            "url": "url",
                                            "valueString": ""
                                        },
                                        {
                                            "url": "url",
                                            "valueString": ""
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "resourceType": "Patient",
                            "id": "id",
                            "name": [
                                {
                                    "text": "text",
                                    "family": "family",
                                    "given": [
                                        "given"
                                    ],
                                    "extension": [
                                        {
                                            "url": "url",
                                            "valueString": "valueString"
                                        },
                                        {
                                            "url": "url",
                                            "valueString": "valueString"
                                        }
                                    ]
                                }
                            ],
                            "identifier": [
                                {
                                    "type": [
                                        {
                                            "text": "text",
                                            "value": "value"
                                        },
                                        {
                                            "text": "MR",
                                            "value": "value"
                                        },
                                        {
                                            "text": "JHN",
                                            "value": "value"
                                        },
                                        {
                                            "text": "NIIP",
                                            "value": ""
                                        },
                                        {
                                            "text": "PRN",
                                            "value": "value"
                                        }
                                    ]
                                }
                            ],
                            "telecom": [
                                {
                                    "value": "928000001"
                                }
                            ],
                            "gender": "male",
                            "birthDate": "birthDate"
                        },
                        {
                            "resourceType": "QuestionnaireResponse",
                            "id": "cuestionario1",
                            "identifier": [
                                {
                                    "value": "cuestionario 1"
                                }
                            ],
                            "item": [
                                {
                                    "definition": "pregunta 1",
                                    "text": "Zona",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 2",
                                    "text": "Alertas",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 3",
                                    "text": "Tipo Estudio",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 4",
                                    "text": "Abierta",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 5",
                                    "text": "Anestesia",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 6",
                                    "text": "Contraste",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 7",
                                    "text": "Oxígeno",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 8",
                                    "text": "Sospecha Diagnóstica",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 9",
                                    "text": "Datos Clínicos",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 10",
                                    "text": "Observaciones",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 11",
                                    "text": "Solo RADIOLOGO (para TER)",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 12",
                                    "text": "Solo RADIOLOGO (para administ)",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 13",
                                    "text": "Circunstancia",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 14",
                                    "text": "Forma de acceso",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                }
                            ]
                        }
                    ],
                    "extension": [
                        {
                            "url": "AMBITO",
                            "valueInteger": "CON"
                        },
                        {
                            "url": "IMAGEN",
                            "valueInteger": "0"
                        },
                        {
                            "url": "INFORME",
                            "valueInteger": "1"
                        },
                        {
                            "url": "CENTROSOLICITANTE",
                            "valueCoding": {
                                "code": "0535001830",
                                "display": "0535001830"
                            }
                        }
                    ],
                    "identifier": [
                        {
                            "type": [
                                {
                                    "text": "NORDEN",
                                    "value": "NORDEN"
                                },
                                {
                                    "text": "IDPETICION",
                                    "value": "IDPETICION"
                                },
                                {
                                    "text": "EPISODIO",
                                    "value": "EPISODIO"
                                }
                            ]
                        }
                    ],
                    "status": "AUTORIZADA",
                    "code": {
                        "coding": [
                            {
                                "code": "D.56"
                            }
                        ],
                        "text": "RM ABDOMEN SIN Y CON CONTRASTE"
                    },
                    "subject": {
                        "reference": "#reference"
                    },
                    "occurrenceDateTime": "2023-10-10",
                    "authoredOn": "2023-10-10 00:00:00.0",
                    "requester": {
                        "reference": "#reference"
                    },
                    "locationCode": [
                        {
                            "text": "text"
                        }
                    ],
                    "supportingInfo": [
                        {
                            "reference": "#reference"
                        }
                    ],
                    "note": ""
                }
            ]
        }
    ]
}

Operation 2 Response: the content of the Property informesAutorizadosRangoFechas is:

{
    "resourceType": "Bundle",
    "type": "searchset",
    "entry": [
        {
            "resource": [
                {
                    "resourceType": "ServiceRequest",
                    "contained": [
                        {
                            "resourceType": "Practitioner",
                            "id": "id",
                            "name": [
                                {
                                    "text": "text",
                                    "family": "family",
                                    "given": [
                                        "given"
                                    ],
                                    "extension": [
                                        {
                                            "url": "first-surname",
                                            "valueString": "valueString"
                                        },
                                        {
                                            "url": "second-surname",
                                            "valueString": "valueString"
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "resourceType": "Patient",
                            "id": "id",
                            "name": [
                                {
                                    "text": "text",
                                    "family": "family",
                                    "given": [
                                        "given"
                                    ],
                                    "extension": [
                                        {
                                            "url": "first-surname",
                                            "valueString": "first-surname"
                                        },
                                        {
                                            "url": "second-surname",
                                            "valueString": "second-surname"
                                        }
                                    ]
                                }
                            ],
                            "identifier": [
                                {
                                    "type": [
                                        {
                                            "text": "NNESP",
                                            "value": "value"
                                        },
                                        {
                                            "text": "MR",
                                            "value": "value"
                                        },
                                        {
                                            "text": "JHN",
                                            "value": "value"
                                        },
                                        {
                                            "text": "NIIP",
                                            "value": "value"
                                        }
                                    ]
                                }
                            ],
                            "telecom": [
                                {
                                    "value": "629893558"
                                }
                            ],
                            "gender": "male",
                            "birthDate": "birthDate"
                        },
                        {
                            "resourceType": "QuestionnaireResponse",
                            "id": "cuestionario1",
                            "identifier": [
                                {
                                    "value": "cuestionario 1"
                                }
                            ],
                            "item": [
                                {
                                    "definition": "pregunta 1",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 2",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 3",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "NO"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 4",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "NO"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 5",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "NO"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 6",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 7",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 8",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 9",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 10",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "NO"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 11",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "NO"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 12",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "A4.05 - Estudio básico"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 13",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "Derecha"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 14",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "Procedimiento diagnóstico de control"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 15",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": ""
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 16",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": ""
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 17",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": ""
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 18",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": ""
                                        }
                                    ]
                                }
                            ]
                        }
                    ],
                    "extension": [
                        {
                            "url": "AMBITO",
                            "valueInteger": "valueInteger"
                        },
                        {
                            "url": "IMAGEN",
                            "valueInteger": "0"
                        },
                        {
                            "url": "INFORME",
                            "valueInteger": "0"
                        },
                        {
                            "url": "CENTROSOLICITANTE",
                            "valueCoding": {
                                "code": "0535001838",
                                "display": "display"
                            }
                        }
                    ],
                    "identifier": [
                        {
                            "type": [
                                {
                                    "text": "NORDEN",
                                    "value": "value"
                                },
                                {
                                    "text": "IDPETICION",
                                    "value": "value"
                                }
                            ]
                        }
                    ],
                    "status": "Incidencia Finalizada",
                    "code": {
                        "coding": [
                            {
                                "code": "code"
                            }
                        ],
                        "text": "RM DE MUÑECA SIN/CON CONTRASTE"
                    },
                    "subject": {
                        "reference": "#reference"
                    },
                    "occurrenceDateTime": "2022-06-27",
                    "authoredOn": "",
                    "requester": {
                        "reference": "#reference"
                    },
                    "locationCode": [
                        {
                            "text": "text"
                        }
                    ],
                    "supportingInfo": [
                        {
                            "reference": "#reference"
                        }
                    ],
                    "note": "note"
                }
            ]
        }
    ]
}

 

The need is the following: to join to the response of Operation 1, the Response of Operation 2, in such a way that the values of the “resource” of the response 2 are below the values of the “resource” of the response 1; that is to say, that the resulting JSON structure is valid.

As a concrete example I have manually performed the binding that would be the needed one:

{
    "resourceType": "Bundle",
    "type": "searchset",
    "entry": [
        {
            "resource": [
                {
                    "resourceType": "ServiceRequest",
                    "contained": [
                        {
                            "resourceType": "Practitioner",
                            "id": "id",
                            "name": [
                                {
                                    "text": "text",
                                    "family": " ",
                                    "given": [
                                        "given"
                                    ],
                                    "extension": [
                                        {
                                            "url": "url",
                                            "valueString": ""
                                        },
                                        {
                                            "url": "url",
                                            "valueString": ""
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "resourceType": "Patient",
                            "id": "id",
                            "name": [
                                {
                                    "text": "text",
                                    "family": "family",
                                    "given": [
                                        "given"
                                    ],
                                    "extension": [
                                        {
                                            "url": "url",
                                            "valueString": "valueString"
                                        },
                                        {
                                            "url": "url",
                                            "valueString": "valueString"
                                        }
                                    ]
                                }
                            ],
                            "identifier": [
                                {
                                    "type": [
                                        {
                                            "text": "text",
                                            "value": "value"
                                        },
                                        {
                                            "text": "MR",
                                            "value": "value"
                                        },
                                        {
                                            "text": "JHN",
                                            "value": "value"
                                        },
                                        {
                                            "text": "NIIP",
                                            "value": ""
                                        },
                                        {
                                            "text": "PRN",
                                            "value": "value"
                                        }
                                    ]
                                }
                            ],
                            "telecom": [
                                {
                                    "value": "928000001"
                                }
                            ],
                            "gender": "male",
                            "birthDate": "birthDate"
                        },
                        {
                            "resourceType": "QuestionnaireResponse",
                            "id": "cuestionario1",
                            "identifier": [
                                {
                                    "value": "cuestionario 1"
                                }
                            ],
                            "item": [
                                {
                                    "definition": "pregunta 1",
                                    "text": "Zona",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 2",
                                    "text": "Alertas",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 3",
                                    "text": "Tipo Estudio",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 4",
                                    "text": "Abierta",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 5",
                                    "text": "Anestesia",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 6",
                                    "text": "Contraste",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 7",
                                    "text": "Oxígeno",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 8",
                                    "text": "Sospecha Diagnóstica",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 9",
                                    "text": "Datos Clínicos",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 10",
                                    "text": "Observaciones",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 11",
                                    "text": "Solo RADIOLOGO (para TER)",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 12",
                                    "text": "Solo RADIOLOGO (para administ)",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 13",
                                    "text": "Circunstancia",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 14",
                                    "text": "Forma de acceso",
                                    "answer": [
                                        {
                                            "valueString": "answer"
                                        }
                                    ]
                                }
                            ]
                        }
                    ],
                    "extension": [
                        {
                            "url": "AMBITO",
                            "valueInteger": "CON"
                        },
                        {
                            "url": "IMAGEN",
                            "valueInteger": "0"
                        },
                        {
                            "url": "INFORME",
                            "valueInteger": "1"
                        },
                        {
                            "url": "CENTROSOLICITANTE",
                            "valueCoding": {
                                "code": "0535001830",
                                "display": "0535001830"
                            }
                        }
                    ],
                    "identifier": [
                        {
                            "type": [
                                {
                                    "text": "NORDEN",
                                    "value": "NORDEN"
                                },
                                {
                                    "text": "IDPETICION",
                                    "value": "IDPETICION"
                                },
                                {
                                    "text": "EPISODIO",
                                    "value": "EPISODIO"
                                }
                            ]
                        }
                    ],
                    "status": "AUTORIZADA",
                    "code": {
                        "coding": [
                            {
                                "code": "D.56"
                            }
                        ],
                        "text": "RM ABDOMEN SIN Y CON CONTRASTE"
                    },
                    "subject": {
                        "reference": "#reference"
                    },
                    "occurrenceDateTime": "2023-10-10",
                    "authoredOn": "2023-10-10 00:00:00.0",
                    "requester": {
                        "reference": "#reference"
                    },
                    "locationCode": [
                        {
                            "text": "text"
                        }
                    ],
                    "supportingInfo": [
                        {
                            "reference": "#reference"
                        }
                    ],
                    "note": ""
                },
				{
                    "resourceType": "ServiceRequest",
                    "contained": [
                        {
                            "resourceType": "Practitioner",
                            "id": "id",
                            "name": [
                                {
                                    "text": "text",
                                    "family": "family",
                                    "given": [
                                        "given"
                                    ],
                                    "extension": [
                                        {
                                            "url": "first-surname",
                                            "valueString": "valueString"
                                        },
                                        {
                                            "url": "second-surname",
                                            "valueString": "valueString"
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "resourceType": "Patient",
                            "id": "id",
                            "name": [
                                {
                                    "text": "text",
                                    "family": "family",
                                    "given": [
                                        "given"
                                    ],
                                    "extension": [
                                        {
                                            "url": "first-surname",
                                            "valueString": "first-surname"
                                        },
                                        {
                                            "url": "second-surname",
                                            "valueString": "second-surname"
                                        }
                                    ]
                                }
                            ],
                            "identifier": [
                                {
                                    "type": [
                                        {
                                            "text": "NNESP",
                                            "value": "value"
                                        },
                                        {
                                            "text": "MR",
                                            "value": "value"
                                        },
                                        {
                                            "text": "JHN",
                                            "value": "value"
                                        },
                                        {
                                            "text": "NIIP",
                                            "value": "value"
                                        }
                                    ]
                                }
                            ],
                            "telecom": [
                                {
                                    "value": "629893558"
                                }
                            ],
                            "gender": "male",
                            "birthDate": "birthDate"
                        },
                        {
                            "resourceType": "QuestionnaireResponse",
                            "id": "cuestionario1",
                            "identifier": [
                                {
                                    "value": "cuestionario 1"
                                }
                            ],
                            "item": [
                                {
                                    "definition": "pregunta 1",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 2",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 3",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "NO"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 4",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "NO"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 5",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "NO"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 6",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 7",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 8",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 9",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "No"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 10",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "NO"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 11",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "NO"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 12",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "A4.05 - Estudio básico"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 13",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "Derecha"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 14",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": "Procedimiento diagnóstico de control"
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 15",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": ""
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 16",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": ""
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 17",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": ""
                                        }
                                    ]
                                },
                                {
                                    "definition": "pregunta 18",
                                    "text": "text",
                                    "answer": [
                                        {
                                            "valueString": ""
                                        }
                                    ]
                                }
                            ]
                        }
                    ],
                    "extension": [
                        {
                            "url": "AMBITO",
                            "valueInteger": "valueInteger"
                        },
                        {
                            "url": "IMAGEN",
                            "valueInteger": "0"
                        },
                        {
                            "url": "INFORME",
                            "valueInteger": "0"
                        },
                        {
                            "url": "CENTROSOLICITANTE",
                            "valueCoding": {
                                "code": "0535001838",
                                "display": "display"
                            }
                        }
                    ],
                    "identifier": [
                        {
                            "type": [
                                {
                                    "text": "NORDEN",
                                    "value": "value"
                                },
                                {
                                    "text": "IDPETICION",
                                    "value": "value"
                                }
                            ]
                        }
                    ],
                    "status": "Incidencia Finalizada",
                    "code": {
                        "coding": [
                            {
                                "code": "code"
                            }
                        ],
                        "text": "RM DE MUÑECA SIN/CON CONTRASTE"
                    },
                    "subject": {
                        "reference": "#reference"
                    },
                    "occurrenceDateTime": "2022-06-27",
                    "authoredOn": "",
                    "requester": {
                        "reference": "#reference"
                    },
                    "locationCode": [
                        {
                            "text": "text"
                        }
                    ],
                    "supportingInfo": [
                        {
                            "reference": "#reference"
                        }
                    ],
                    "note": "note"
                }
            ]
        }
    ]
}

Please, how would you recommend, suggest, structure this logic? I ask because perhaps there is a standard, solid, robust, recommended, suggested and advisable way to do this type of logic.

Thank you for reading this question, thank you for your help, and thank you for your time and attention.

🙂

Thanks.

Product version: IRIS 2023.1
Discussion (5)2
Log in or sign up to continue

Hello Enrico Parisi, @Enrico Parisi, thanks for your questions and thanks for your reply, sincerely.

The required logic is to merge the "resource" objects within the "entry" arrays, focusing solely on the "resource" objects. The process should not merge the entire entries themselves but rather extract and combine the "resource" objects from each entry.

Here's a brief summary of the logic:

    - Extract the "resource" objects from each "entry" in response1 and response2.
    - Combine these "resource" objects into a single array.
    - Ensure the merged JSON contains only the combined "resource" objects, maintaining the integrity and structure of each "resource".
    
Please let me know if further clarification is needed.

Thanks Enrico Parisi for your time, reply and help.

Assuming response1 json ALWAYS contain a single entry, then:

    ; import stream into Dynamic Object
    Set Response1=##class(%DynamicObject).%FromJSON(response1.informesAutorizadosRangoFechas)
    Set Response2=##class(%DynamicObject).%FromJSON(response2.informesAutorizadosRangoFechas)
    
    Write "Response1 has ",Response1.entry.%Size()," entries",!
    Write "Response2 has ",Response2.entry.%Size()," entries",!

    ; loop all the entries in Response2
    Set EntryIter=Response2.entry.%GetIterator()
    While EntryIter.%GetNext(.EntryKey, .Entry) {
        Write "Response2, entry ",EntryKey+1," has ",Entry.resource.%Size()," resources",!

        ; loop all resources within Entry
        Set ResourceIter=Entry.resource.%GetIterator()
        While ResourceIter.%GetNext(.ResourceKey, .Resource) {

            ; add resource from Result2 in first entry of Result1
            Do Response1.entry.%Get(0).resource.%Push(Resource)  
        }   
    }
    Write "Merged Response1 has ",Response1.entry.%Get(0).resource.%Size()," resources",!

Using your samples the output is:

Response1 has 1 entries
Response2 has 7 entries
Response2, entry 1 has 1 resources
Response2, entry 2 has 1 resources
Response2, entry 3 has 1 resources
Response2, entry 4 has 1 resources
Response2, entry 5 has 1 resources
Response2, entry 6 has 1 resources
Response2, entry 7 has 1 resources
Merged Response1 has 8 resources

The resulting json is different than your manual merge.......