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's no longer available with a 410 status code as per the FHIR specification.

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

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. Instead an OperationOutcome pointer to the resource will indicate that it has been deleted. Your application will no longer have the ability to recover that data so please ensure that you use the DELETE mechanism for FHIR resources and version history responsibly. It is your application's responsibility to adhere to requirement of HIPAA subject to backup and data retention policies.

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"
        }
      }]
    }
  }]
}