Skip to main content
May 15, 2024
Question

JSON Payload for HAPI/FHIR

  • May 15, 2024
  • 3 replies
  • 0 views

Hello - I am trying to test creating a FHIR compliant JSON payload to send to hapi.fhir.org/Patient.  Here is what I done so far.

created an expression to create the JSON payload:

concat( "{","""resourceType""",":","""Patient""",",","""name""",":[{","""use""",":","""official""",",","""text""",":","""Brian Doe""",",","""family""",":","""Doe""",",","""given""",":","[","""",tostring(ri!firstName),"""","]","}","]",",","""gender""",":","""male""",",","""birthDate""",":","""2000-04-30""","}"
)

This gives me: 

"{"resourceType":"Patient","name":[{"use":"official","text":"Brian Doe","family":"Doe","given":[""]}],"gender":"male","birthDate":"2000-04-30"}"

When I put this in the integration's request body, it results in errors.  First error is because of the " at the start and the end.  I removed those manually and then it gives an 'open bracket' error.  The open error seems to be because of [ brackets.  If I remove all [ brackets, and the payload is now

{"resourceType": "Patient", "name": {"use": "official","text": "Brian Doe","family": "Doe","given": "Brian"},"gender":"male","birthDate": "2000-04-30"}

The API returns success.  Any suggestion on how I can get the payload to be generated without the string so I can pass it to the integration as a parameter and keep the [ brackets? 

Thank you!

John.

3 replies

mikes0011
Brainy
May 15, 2024

I'm unclear what the square brackets (particularly the inner set, at "given") are trying to do in the generated JSON.  Are you saying the API requires this somehow?

As a potential alternate approach to try, if you just create a dictionary and then wrap it in a!toJson, you should get the JSON text, without having to use such a cumbersome and error-prone concat statement (particularly given how hard it is to work with double-quotes given the need to escape each one, and the consequent confusion).  This could at the very least provide you an easier method by which to test different potential generated inputs.

stewart.burchell
May 15, 2024

String concatenation, whilst it can work, is hard to implement and hard to maintain. You'd be better off creating an Appian data structure (e.g. using a CDT) and then casting that to JSON using a!toJson(). 

To do this you'll need to work backwards from the JSON message that you want to create and create an Appian data structure that will align to the target JSON structure.

stefanhelzle0001
May 15, 2024

Do this instead:

a!toJson(
  {
    resourceType: "Patient",
    name: {
      use: "official",
      text: "Brian Doe",
      family: "Doe",
      given: "Brian"
    },
    gender: "male",
    birthDate: date(2000, 04, 3)
  }
)