You are right, you have to create the properties before to use %FindDocuments...BUT...it doesn't work for arrays of data. I've found this answer to a similar question:

https://community.intersystems.com/post/how-query-data-docdb-through-py…

I was testing the behaviour with this example:

DO db.%CreateProperty("type","%String","$.PhoneNumber.type")
    

  SET dynAbObj = {
   "FullName":"John Smith",
   "FirstName":"John",
   "Address":{
              "street":"101 Main Street",
              "city":"Mapleville",
              "state":"NY",
              "postal code":10234
             },
   "PhoneNumber":
              [
               {"type":"home","number":"212-456-9876"},
               {"type":"cell","number":"401-123-4567"},
               {"type":"work","number":"212-444-5000"}
              ]
  }
  $$$TRACE(dynAbObj.%ToJSON())
  SET jstring = dynAbObj.%ToJSON() // dynamic abstract object to JSON stringDO db.%FromJSON(jstring)   // JSON string inserted into document database$$$TRACE(db.%FindDocuments(["type","cell","="]).%ToJSON())
  $$$TRACE(db.%FindDocuments(["type","home","="]).%ToJSON())

This is the answer for the first search:

{"sqlcode":100,"message":null,"content":[]}

And this is the answer for the second search:

{"sqlcode":100,"message":null,"content":[{"%Doc":"{\"FullName\":\"John Smith\",\"FirstName\":\"John\",\"Address\":{\"street\":\"101 Main Street\",\"city\":\"Mapleville\",\"state\":\"NY\",\"postal code\":10234},\"PhoneNumber\":[{\"type\":\"home\",\"number\":\"212-456-9876\"},{\"type\":\"cell\",\"number\":\"401-123-4567\"},{\"type\":\"work\",\"number\":\"212-444-5000\"}]}","%DocumentId":"1","%LastModified":"2023-09-18 10:13:30.694"}]}

As you can see, it only works fine for the first value of the array, the definition of the property doesn't allow to define an array of values.

Well, I guess that you just need to call the BO/endpoint form the WHILE loop:

Set tSC = ..SendRequestSync(outbound, pRequest, .pResponse)

What do you think that we have in the kitchenette (cocina) in southern Europe? A machine of sangria? That would be great...

Have you tried to split your variable in various variables to avoid the string length limitation?

XData VariableName1 [ MimeType = application/json ] {}

XData VariableName2 [ MimeType = application/json ] {}

...

XData VariableNameN [ MimeType = application/json ] {}
 

Well, in theory if you define the identifier in the request section and define the method as "PUT" the server should create the organization if it doesn't exist or updated if it do.

<?xml version="1.0" encoding="UTF-8"?><Bundlexmlns="http://hl7.org/fhir"><typevalue="transaction"></type><entry><resource><Organization><idvalue="17C7D86E-664F-4FE2-91D7-AF9A8E47311E"></id><text><statusvalue="generated"/><divxmlns="http://www.w3.org/1999/xhtml"> LITTLE CLINIC 2000 PATIENT DRIVE ANN
                        ARBOR MI US - NOI # 888333111 </div></text><identifier><systemvalue="www.nationalorgidentifier.gov"/><valuevalue="888333111"/></identifier><namevalue="LITTLE CLINIC"/><address><linevalue="2000 CLINIC DRIVE"/><cityvalue="ANN ARBOR"/><statevalue="MI"/><countryvalue="US"/></address></Organization></resource><request><methodvalue="PUT"/><urlvalue="Organization?identifier=www.nationalorgidentifier.gov|888333111"/></request></entry><entry><resource><Patient><text><statusvalue="generated"/><divxmlns="http://www.w3.org/1999/xhtml"> EVERYWOMAN EVE 2000 PATIENT DRIVE ANN
                        ARBOR MI MPI #12312311 </div></text><identifier><systemvalue="www.mypatientidentifier.com"/><valuevalue="12312311"/></identifier><name><familyvalue="EVERYWOMAN"/><givenvalue="EVE"/></name><address><linevalue="2000 PATIENT DRIVE"/><cityvalue="ANN ARBOR"/><statevalue="MI"/><countryvalue="US"/></address><managingOrganization><referencevalue="Organization/17C7D86E-664F-4FE2-91D7-AF9A8E47311E"></reference></managingOrganization></Patient></resource><request><methodvalue="PUT"/><urlvalue="Patient?identifier=www.mypatientidentifier.com|12312311"/></request></entry></Bundle>

But this is the theory...not sure if it will work for your FHIR server.

Hi Lorenzo! I'm no sure if this is the reason, but I've defined a proxy for the Angular front-end. You can check proxy.config.json:

{
    "/api/*": {
      "target": "http://iris:52773",
      "secure": false,
      "logLevel": "debug"
    }
  }

All my requests to the server are using localhost:4200 and they are translated into iris:52773 after the request.

Hi Yone! Your patientId is a param of the URL, you don't need to include it into the router map, to get the value you only need 

set patid = %request.Get("patientid")

Here you can see an example:

ClassMethod ImportRawMatches() As%DynamicObject
{
    Try {
        Do##class(%REST.Impl).%SetContentType("application/json")
        If '##class(%REST.Impl).%CheckAccepts("application/json") Do##class(%REST.Impl).%ReportRESTError(..#HTTP406NOTACCEPTABLE,$$$ERROR($$$RESTBadAccepts)) Quitset newRequest = ##class(QUINIELA.Message.OperationRequest).%New()
        set newRequest.Operation = "Import"set status = ##class(Ens.Director).CreateBusinessService("QUINIELA.BS.FromWSBS", .instance)
       	set response = ##class(QUINIELA.Message.ImportResponse).%New()
        set response.Status = "In Process"set response.Operation = "Import"set status = instance.SendRequestAsync("QUINIELA.BP.ImportBPL", newRequest, .response)
        
        if$ISOBJECT(response) {	        
            Do##class(%REST.Impl).%SetStatusCode("200")
            return response.%JSONExport()
		}		
        
    } Catch (ex) {
        Do##class(%REST.Impl).%SetStatusCode("400")
        return ex.DisplayString()
    }

The key is this row:

return response.%JSONExport()

You can configure a transform creating a new message and defining another context variable with the same type than the original message as output, then you keep your original message in the request and the transformed message in the new variable.