hapifhir / hapi-fhir-jpaserver-starter

Apache License 2.0
375 stars 1.01k forks source link

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

Closed theGOTOguy closed 1 month ago

theGOTOguy commented 3 years ago

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.

jkiddo commented 3 years ago

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

jkiddo commented 3 years ago

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

rcrichton commented 2 years ago

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

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 730 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 1 month ago

This issue was closed because it has been stalled for 5 days with no activity.