hapi-fhir-jpaserver-starter icon indicating copy to clipboard operation
hapi-fhir-jpaserver-starter copied to clipboard

ThymeLeaf error when updating DiagnosticReport to refer to an Observation with a valueBoolean

Open theGOTOguy opened this issue 3 years ago • 3 comments

I cannot reproduce this error in the https://hapi.fhir.org server, but it is straightforward to reproduce from the DockerHub images. It appears that a valueBoolean from an Observation triggers an error when updating a DiagnosticReport in a batch bundle even though these two updates should be independent.

Specifically, the error that appears in the server is:

org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'ca.uhn.fhir.narrative2.ThymeleafNarrativeGenerator$NarrativeAttributeProcessor' (template: "diagnosticreport" - line 81, col 10)
<...snip...>
Caused by: ca.uhn.fhir.rest.server.exceptions.InternalErrorException: No template for type: class org.hl7.fhir.dstu3.model.BooleanType

This example uses STU3, but the error also reproduces in R4.

To reproduce, start by booting up a local server:

docker run -p 8080:8080
          -e hapi.fhir.server_address=http://localhost:8080/fhir
          -e hapi.fhir.subscription.resthook_enabled=true
          -e hapi.fhir.allow_external_references=true
          -e hapi.fhir.fhir_version=DSTU3
          hapiproject/hapi:v5.4.1

First create a Patient:

curl -X POST --header "Content-Type: application/fhir+json" --data '{"resourceType": "Patient"}' http://localhost:8080/fhir/Patient

This will become Patient/1 for the sake of what follows.

Next, create a DiagnosticReport:

curl -X POST --header "Content-Type: application/fhir+json" --data '{"resourceType": "DiagnosticReport", "status": "final", "subject": {"reference": "Patient/1"}}' http://localhost:8080/fhir/DiagnosticReport

This will become DiagnosticReport/2.

Next, create an Observation:

curl -X POST --header "Content-Type: application/fhir+json" --data '{"resourceType": "Observation", "status": "final", "subject": {"reference": "Patient/1"}}' http://localhost:8080/fhir/Observation

This will become Observation/3.

Now we will create a file batch_update_test.json where we will update the Observation to have a valueBoolean and the DiagnosticReport to refer to the Observation.

{
   "entry" : [
      {
         "fullUrl" : "http://localhost:8080/fhir/DiagnosticReport/2",
         "request" : {
            "method" : "PUT",
            "url" : "DiagnosticReport/2"
         },
         "resource" : {
            "id" : "2",
            "resourceType" : "DiagnosticReport",
            "result" : [
               {
                  "reference" : "Observation/3"
               }
            ],
            "status" : "final",
            "subject" : {
               "reference" : "Patient/1"
            }
         }
      },
      {
         "fullUrl" : "http://localhost:8080/fhir/Observation/3",
         "request" : {
            "method" : "PUT",
            "url" : "Observation/3"
         },
         "resource" : {
            "id" : "3",
            "resourceType" : "Observation",
            "status" : "final",
            "subject" : {
               "reference" : "Patient/1"
            },
            "valueBoolean" : true
         }
      }
   ],
   "resourceType" : "Bundle",
   "type" : "batch"
}

Posting this bundle,

curl -X POST --header "Content-Type: application/fhir+json" --data @batch_update_test.json http://localhost:8080/fhir/

We get:

{
  "resourceType": "Bundle",
  "id": "5a08c8fd-d64b-4e16-bb57-0c7a37b854a5",
  "type": "batch-response",
  "link": [ {
    "relation": "self",
    "url": "http://localhost:4180/fhir"
  } ],
  "entry": [ {
    "response": {
      "status": "500 Internal Server Error",
      "outcome": {
        "resourceType": "OperationOutcome",
        "text": {
          "status": "generated",
          "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">ERROR</td><td>[]</td><td><pre>Error during execution of processor 'ca.uhn.fhir.narrative2.ThymeleafNarrativeGenerator$NarrativeAttributeProcessor' (template: &quot;diagnosticreport&quot; - line 81, col 10)</pre></td>\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
        },
        "issue": [ {
          "severity": "error",
          "code": "exception",
          "diagnostics": "Error during execution of processor 'ca.uhn.fhir.narrative2.ThymeleafNarrativeGenerator$NarrativeAttributeProcessor' (template: \"diagnosticreport\" - line 81, col 10)"
        } ]
      }
    }
  }, {
    "response": {
      "status": "200 OK",
      "location": "Observation/3/_history/2",
      "etag": "2"
    }
  } ]
}

Strangely, while the error occurs on the DiagnosticReport, it is somehow related to the Observation! If you go back and change the valueBoolean: true to valueString: "true" in the update, then your batch bundle works just fine.

This error does occur if you use a transaction instead of a batch as well, and as obscure as this issue seems it is preventing our ETL from running on HAPI as we are trying to migrate away from Azure API for FHIR. For now, we are able to work around this by setting hapi.fhir.narrative_enabled: false.

theGOTOguy avatar Jun 11 '21 05:06 theGOTOguy

This is related to the https://github.com/hapifhir/hapi-fhir project - not this project.

jkiddo avatar Jun 26 '21 19:06 jkiddo

@jamesagnew you might wan't to have a look at this

jkiddo avatar Jun 26 '21 19:06 jkiddo

I've just experienced this as well when my Observation had valueInteger: 29 I changed it to valueString: "29" and it worked.

rcrichton avatar Jul 22 '22 15:07 rcrichton