add helper function for checking if a resource has been deleted or not
This commit is contained in:
parent
8e790e2b21
commit
28f2cef6dd
13
README.md
13
README.md
|
@ -426,6 +426,11 @@ resource to be deleted. The return value will typically be `nil` on success, tho
|
|||
some servers may return an OperationOutcome resource that includes more details about
|
||||
the successful deletion.
|
||||
|
||||
You can use the helper function `deleted?` to determine if a resource has been deleted
|
||||
or not, since `get-resource` returns nil for both deleted resources and resources
|
||||
which do not exist at all (an important distinction, as in FHIR a deleted resource
|
||||
technically still exists under previous version numbers).
|
||||
|
||||
##### Examples
|
||||
|
||||
```clojure
|
||||
|
@ -440,6 +445,14 @@ the successful deletion.
|
|||
; try to delete a non-existant patient
|
||||
(delete server-url :patient 9001)
|
||||
=> ExceptionInfo FHIR request failed: HTTP 404
|
||||
|
||||
; testing if a resource has been deleted or not
|
||||
(deleted? server-url :patient 1654)
|
||||
=> true
|
||||
|
||||
; testing if a non-existant resource has been deleted
|
||||
(deleted? server-url :patient 9001)
|
||||
=> false
|
||||
```
|
||||
|
||||
### Error Handling
|
||||
|
|
|
@ -365,6 +365,24 @@
|
|||
base-url
|
||||
(apply join-paths uri-components))))
|
||||
|
||||
(defn deleted?
|
||||
[base-url type id]
|
||||
(let [resource-name (->fhir-resource-name type)
|
||||
url-components ["/" resource-name id]
|
||||
relative-url (apply join-paths url-components)]
|
||||
(try
|
||||
(fhir-request :get
|
||||
base-url
|
||||
relative-url)
|
||||
; not deleted
|
||||
false
|
||||
(catch ExceptionInfo ex
|
||||
(let [http-status (:status (ex-data ex))]
|
||||
(cond
|
||||
(= http-status 410) true
|
||||
(= http-status 404) false
|
||||
:else (throw ex)))))))
|
||||
|
||||
;(def server-url "http://fhir.healthintersections.com.au/open")
|
||||
;(def server-url "http://spark.furore.com/fhir")
|
||||
;(def server-url "http://fhirtest.uhn.ca/base")
|
||||
|
|
Reference in a new issue