FHIR Delete a resource

With 1upHealth, you can DELETE any FHIR resource or version from the FHIR _history endpoint.

Here's how you delete a FHIR resource

To delete a single resource use the command below. It will only delete the individual resource. Past version histories will remain to help apps ensure HIPAA compliance and proper backups. Once a resource is deleted, a GET request to the same endpoint will indicate it is no longer available with a 410 GONE status code as per the FHIR specification.

curl -XDELETE 'https://api.1up.health/fhir/dstu2/Patient/{patientId}' \
  -H 'Authorization: Bearer access_token'

Deleting version history is a capability outside the FHIR specification, but is provided for customers to allow for their specific requirements. Once a resource AND its history are deleted, the information is not recoverable. Deleting a resource's version history will permanently delete the resource's version history. When the resource's version history is deleted AND the resource is deleted, then reading the resource explicitly by its id will return a 404 NOT FOUND status code as though the resource had never existed

To delete a FHIR resource's version history use the following command. Each individual version history item must be deleted explicitly using a command like this.

curl -XDELETE 'https://api.1up.health/fhir/dstu2/Patient/{patientId}/_history/{versionId}' \
  -H 'Authorization: Bearer access_token'

An example delete item's response looks like this:

{
  "resourceType": "OperationOutcome",
  "id": "qk8jk2coi",
  "issue": [
    {
      "severity": "information",
      "code": "value",
      "details": {
        "text": "this resource with id 3ad226c56b9b and version 9000000000002 has been deleted"
      }
    }
  ]
}

After a resource has been deleted it will no longer be returned in search requests. For an explicit read request of the deleted resource by it's id, an OperationOutcome will be returned with status code 410, indicating that the resource has been deleted. The previous state of the resource will still be available through a versioned read of its history

Example

Below are commands and responses that show the flow of creating a patient resource and deleting the same patient resource including its history.

Create a new Patient resource:

 curl -XPOST 'https://api.1up.health/fhir/dstu2/Patient' \
  -H 'Authorization: Bearer access_token' \
  -H 'Content-Type: application/json' \
  -d '{"resourceType": "Patient"}'

Response:

{
  "resourceType":"Patient",
  "id":"7hocu3823ze1",
  "meta":{
    "versionId":"9000000000000",
    "lastUpdated":"2019-09-19T17:28:37.449Z"
    }
}

Show the newly created Patient resource:

 curl -X GET https://api.1up.health/fhir/dstu2/Patient \
  -H 'Authorization: Bearer access_token'

Response:

{
  "resourceType":"Bundle",
  "type":"searchset",
  "total":1,
  "entry":[{
    "fullUrl":"https://api.1up.health/fhir/dstu2/Patient/7hocu3823ze1",
    "search":{
      "mode":"match"
    },
    "resource":{
      "resourceType":"Patient",
      "meta":{
        "lastUpdated":"2019-09-19T17:28:37.449Z",
        "versionId":"9000000000000"
      },
    "id":"7hocu3823ze1”
    }
  }]
}

Delete the new Patient resource:

 curl -XDELETE 'https://api.1up.health/fhir/dstu2/Patient/7hocu3823ze1' \
  -H 'Authorization: Bearer access_token'

Response:

{"id":"7hocu3823ze1"}

Show the Patient resource has been deleted:

 curl -X GET https://api.1up.health/fhir/dstu2/Patient \
  -H 'Authorization: Bearer access_token'

Response:

{
  "resourceType":"Bundle",
  "type":"searchset",
  "total":1,
  "entry":[{
    "fullUrl":"https://api.1up.health/fhir/dstu2/Patient/hwpvwsp7gsl",
    "search":{
      "mode":"match"
    },
    "resource":{
      "resourceType":"OperationOutcome",
      "id":"hwpvwsp7gsl",
      "issue":[{
        "severity":"information",
        "code":"value",
        "details":{
          "text":"this resource with id 7hocu3823ze1 and version 9000000000001 has been deleted"
        }
      }]
    }
  }]
}

Show the Patient History:

 curl -X GET https://api.1up.health/fhir/dstu2/Patient/7hocu3823ze1/_history \
  -H 'Authorization: Bearer access_token'

Response:

{
  "resourceType":"Bundle",
  "type":"searchset",
  "total":2,
  "entry":[{
    "fullUrl":"https://api.1up.health/fhir/dstu2/Patient/7hocu3823ze1",
    "search":{
      "mode":"match"
    },
    "resource":{
      "resourceType":"Patient",
      "meta":{
        "lastUpdated":"2019-09-19T17:28:37.449Z",
        "versionId":"9000000000000"},
        "id":"7hocu3823ze1"
      }
    },{
    "fullUrl":"https://api.1up.health/fhir/dstu2/Patient/g6ek4r0tpsj",
    "search":{
      "mode":"match"
    },
    "resource":{
      "resourceType":"OperationOutcome",
      "id":"g6ek4r0tpsj",
      "issue":[{
        "severity":"information",
        "code":"value",
        "details":{
          "text":"this resource with id 7hocu3823ze1 and version 9000000000001 has been deleted"
        }
      }]
    }
  }]
}

Delete the Patient History:

  curl -XDELETE 'https://api.1up.health/fhir/dstu2/Patient/7hocu3823ze1/_history/9000000000000' \
  -H 'Authorization: Bearer access_token'

Response:

{
  "resourceType":"OperationOutcome",
  "id":"qxfay3b0c9fkep0z3dp4aemi",
  "issue":[{
    "severity":"information",
    "code":"value",
    "details":{
      "text":"this resource has been deleted"
    }
  }]
}

Show the Patient History:

  curl -X GET https://api.1up.health/fhir/dstu2/Patient/7hocu3823ze1/_history \
  -H 'Authorization: Bearer access_token'

Response showing both versions have been deleted:

{
  "resourceType":"Bundle",
  "type":"searchset",
  "total":2,
  "entry":[{
    "fullUrl":"https://api.1up.health/fhir/dstu2/Patient/gmdu2j0571m",
    "search":{
      "mode":"match"
    },
    "resource":{
      "resourceType":"OperationOutcome",
      "id":"gmdu2j0571m",
      "issue":[{
        "severity":"information",
        "code":"value",
        "details":{
          "text":"this resource with id 7hocu3823ze1 and version 9000000000000 has been deleted"
        }
      }]
    }
  },{
    "fullUrl":"https://api.1up.health/fhir/dstu2/Patient/ie8df27mz3",
    "search":{
      "mode":"match"
    },
    "resource":{
      "resourceType":"OperationOutcome",
      "id":"ie8df27mz3",
      "issue":[{
        "severity":"information",
        "code":"value",
        "details":{
          "text":"this resource with id 7hocu3823ze1 and version 9000000000001 has been deleted"
        }
      }]
    }
  }]
}