LinuxForHealth / FHIR

The LinuxForHealth FHIR® Server and related projects
https://linuxforhealth.github.io/FHIR
Apache License 2.0
328 stars 157 forks source link

Identifier: Expected: JsonObject but found: ARRAY #4243

Closed j-frei closed 9 months ago

j-frei commented 9 months ago

Describe the bug The following Bundle cannot uploaded as expected. It states that the identifier should be a JSON object, but according to the FHIR cardinality on the identifier attribute, it should be a list of FHIR Identifier objects.

FHIR Bundle:

{
  "resourceType": "Bundle",
  "type": "transaction",
  "entry": [
    {
      "resource": {
        "resourceType": "QuestionnaireResponse",
        "identifier": [
          {
            "system": "redcapid",
            "value": "1"
          }
        ],
        "status": "completed",
        "item": [
          {
            "linkId": "record_id",
            "text": "Record ID",
            "answer": [
              {
                "valueString": "1"
              }
            ]
          }
        ]
      },
      "request": {
        "method": "PUT",
        "url": "QuestionnaireResponse?identifier=redcapid|1"
      }
    }
  ]
}

The error message is as follows:

{
  "resourceType": "OperationOutcome",
  "issue": [
    {
      "severity": "fatal",
      "code": "invalid",
      "details": {
        "text": "FHIRProvider: Expected: JsonObject but found: ARRAY for element: identifier [Bundle.entry[0].resource]"
      },
      "expression": [
        "Bundle.entry[0].resource"
      ]
    }
  ]
}

Environment Which version of LinuxForHealth FHIR Server? 5.1.1 (based on the official Docker image)

To Reproduce Steps to reproduce the behavior:

  1. Initialize a FHIR server
  2. Save the attached bundle locally as bundle.json
  3. Run curl -X POST -u fhiruser:change-password 'http://fhir-host/fhir-server/api/v4' -H 'Content-Type: application/fhir+json' --data @bundle.json
  4. Observe the error message.

Expected behavior The operation should succeed.

HAPI FHIR accepts the bundle.

Additional context Replacing the list of identifiers by an identifier object is accepted by the server:

Modified files Bundle: ```json { "resourceType": "Bundle", "type": "transaction", "entry": [ { "resource": { "resourceType": "QuestionnaireResponse", "identifier": { "system": "redcapid", "value": "1" } , "status": "completed", "item": [ { "linkId": "record_id", "text": "Record ID", "answer": [ { "valueString": "1" } ] } ] }, "request": { "method": "PUT", "url": "QuestionnaireResponse?identifier=redcapid|1" } } ] } ``` Response: ```json { "resourceType": "Bundle", "type": "transaction-response", "entry": [ { "response": { "id": "18ccf691c97-9a34a7ae-f4aa-4d96-9c5d-46fed2fd92dd", "status": "201", "location": "QuestionnaireResponse/18ccf691c97-9a34a7ae-f4aa-4d96-9c5d-46fed2fd92dd/_history/1", "etag": "W/\"1\"", "lastModified": "2024-01-03T13:00:21.529054Z", "outcome": { "resourceType": "OperationOutcome", "issue": [ { "severity": "warning", "code": "invariant", "details": { "text": "dom-6: A resource should have narrative for robust management" }, "expression": [ "QuestionnaireResponse" ] } ] } } } ] } ```
berkant-k commented 9 months ago

I think the problem is with the identifier data element. If you are using FHIR R4B, the identifier is not defined as an array for the QuestionnaireResponse resource.

Check the StructureDefinition at https://hl7.org/fhir/R4B/questionnaireresponse.html.

image

I tested as below and succeeded.


{    
    "resourceType": "QuestionnaireResponse",
    "identifier": {
        "system": "redcapid",
        "value": "1"
    },
    "status": "completed",
    "item": [
        {
            "linkId": "record_id",
            "text": "Record ID",
            "answer": [
                {
                    "valueString": "1"
                }
            ]
        }
    ]
}
j-frei commented 9 months ago

@berkant-k Indeed, you are right! I was not aware that something had changed from R4B->R5 for QR. Thank you for pointing this out!