2

I'm looking for help on how to post a bundle containing multiple resources to a HAPI Server. I'm running the [test server][1], and I've tried using both the Jetty server and running it as a docker container. I'm able to successfully start the server, go to the UI and post a patient directly. And I can also post a patient directly from within Postman:

POST /hapi-fhir-jpaserver/fhir/Patient HTTP/1.1
Host: localhost:8080
Content-Type: application/fhir+json
{
  "resourceType": "Patient",
  "name": [
    {
      "use": "official",
      "family": "Solo",
      "given": [
        "Han"
      ]
    }
  ]

This all works fine. However, when I try to post this:

{
  "resourceType": "Bundle",
  "type": "transaction",
  "entry": [
    {
      "resource": {
        "resourceType": "Patient",
        "name": [
          {
            "use": "official",
            "family": "Stark",
            "given": [
              "Anthony"
            ]
          }
        ]
      },
      "request": {
        "method": "PUT",
        "url": "Patient"
      }
    }
  ]
}

I receive an "OperationOutcome" error: "Unable to store a Bundle resource on this server with a Bundle.type value of: transaction"

I get this error both from the web UI and from postman. I can change the type of Bundle to something like "message", and I don't get the same error. However, when I search, while the whole Bundle has been posted, the patient inside hasn't. Does anyone know how to get the server to read the resources inside a Bundle separately from the Bundle itself?

  [1]: https://github.com/hapifhir/hapi-fhir-jpaserver-starter
Grey
  • 331
  • 3
  • 11

1 Answers1

5

To execute a transaction or a batch, POST it to the server's 'root' endpoint, not the Bundle endpoint - so .../hapi-fhir-jpaserver/fhir, not .../hapi-fhir-jpaserver/fhir/Bundle

Lloyd McKenzie
  • 6,345
  • 1
  • 13
  • 10
  • 1
    Thank you! That was exactly what I needed. Could I also ask a quick f/u? The resources I'm posting already have IDs, but my server keeps assigning them new ones. I know there's a way to force it to keep the old IDs, but I can't seem to find it in the documentation. – Grey Jul 14 '20 at 20:38
  • 2
    If you use PUT rather than POST *and* the server supports it, it'll create the resource with the id you specify if it doesn't already exist. However, not all servers will allow this due to the potential of id collisions or because their persistence layer doesn't allow externally-determined ids. Guidance is here: http://build.fhir.org/http.html#upsert – Lloyd McKenzie Jul 15 '20 at 03:04