-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe the bug
A resource that is referenced both from itself and from other resources can be deleted despite conflicts. This issue is sensitive to the order in which the references are made: the self-reference must be created before any "external" references. I.e., the first relevant record in HFJ_RES_LINK
must be the self-reference, which causes DeleteConflictService
to ignore it.
To Reproduce
#!/bin/bash
unlinked='{
"resourceType": "Patient",
"id": "$id",
"name": [
{
"family": "Doe"
}
]
}'
linked='{
"resourceType": "Patient",
"id": "$id",
"name": [
{
"family": "Doe"
}
],
"link": [
{
"other": {
"reference": "Patient/$other_id"
},
"type": "seealso"
}
]
}'
put() {
local template="$1"; shift
local id="$1"; shift
local other_id="$1"; shift
export id
export other_id
echo "PUT $id"
echo "$template" \
| envsubst \
| curl -sSX PUT "http://localhost:8080/fhir/Patient/$id" \
-H 'Content-Type: application/fhir+json' \
--data-binary @- \
-o /dev/null
}
delete() {
local id="$1"; shift
echo "DELETE $id"
curl -sSX DELETE "http://localhost:8080/fhir/Patient/$id" \
| jq -r '.issue[].diagnostics'
}
docker run --name hapi -p 8080:8080 -d hapiproject/hapi:latest
while ! curl -sX GET 'http://localhost:8080/' -o /dev/null; do
echo -n '.'
sleep 1
done
echo
echo
echo 'No self-reference'
put "$unlinked" 'target-1'
put "$linked" 'source-1' 'target-1'
delete 'target-1'
echo
echo 'Self-reference after source'
put "$unlinked" 'target-2'
put "$linked" 'source-2' 'target-2'
put "$linked" 'target-2' 'target-2'
delete 'target-2'
echo
echo 'Self-reference before source'
put "$unlinked" 'target-3'
put "$linked" 'target-3' 'target-3'
put "$linked" 'source-3' 'target-3'
delete 'target-3'
echo
docker rm -f hapi
Typical output:
0c4b78adb59a84e6ff30b65cf893f1057f0644da6f33fe4a80fdb5a6c68de78c
.....................
No self-reference
PUT target-1
PUT source-1
DELETE target-1
Unable to delete Patient/target-1 because at least one resource has a reference to this resource. First reference found was resource Patient/source-1 in path Patient.link.other
Self-reference after source
PUT target-2
PUT source-2
PUT target-2
DELETE target-2
Unable to delete Patient/target-2 because at least one resource has a reference to this resource. First reference found was resource Patient/source-2 in path Patient.link.other
Self-reference before source
PUT target-3
PUT target-3
PUT source-3
DELETE target-3
Successfully deleted 1 resource(s). Took 12ms.
hapi
Expected behavior
Admittedly, this might be a "bad data" situation. But given that HAPI allows you to create self-references, it should handle them appropriately during deletion. I.e., DeleteConflictService
should detect "external" references even in the presence of early self-references. Perhaps by filtering out self-references in DeleteConflictFinderService
?
Environment
- hapiproject/hapi:v8.0.0-1