-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
When submitting a FHIR Bundle of type transaction that includes a POST request with ifNoneExist and the same query is reused (with different fullUrl) across multiple Bundles (e.g. for Encounter or Composition), the transaction fails on the second execution due to a unique constraint violation in hfj_res_search_url.
Reproduction Steps
Send a transaction Bundle that includes a POST request with an ifNoneExist clause, for example:
{ "resourceType":"Bundle", "type":"transaction", "entry":[ { "fullUrl":"urn:uuid:ref-to-encounter", "resource":{ "resourceType":"Encounter", "type":[ { "coding":[ { "system":"http://hl7.org/fhir/sid/icd-10", "code":"EDO", "display":"EDO" }, { "system":"http://hl7.org/fhir/sid/icd-10", "code":"B01", "display":"varicela" } ] } ], "status":"completed" }, "request":{ "method":"POST", "url":"Encounter", "ifNoneExist":"Encounter?subject.identifier=urn:oid:2.16.724.4.41|TRBC831246913010&status=planned,in-progress,on-hold,discharged,discontinued,entered-in-error,unknown&type=EDO&type=B01,B01.0,B01.11,B01.12,B01.2,B01.81,B01.89,B01.9,Z20.820" } }, { "resource":{ "resourceType":"Composition", "meta":{ "tag":[ { "system":"https://fhir/NamingSystem/reviex/origen", "code":"JARA" } ] }, "status":"final", "type":{ "coding":[ { "system":"http://hl7.org/fhir/sid/icd-10", "code":"EDO", "display":"EDO" }, { "system":"http://hl7.org/fhir/sid/icd-10", "code":"B01", "display":"varicela" } ] } }, "request":{ "method":"POST", "url":"Composition", "ifNoneExist":"Composition?subject.identifier=urn:oid:2.16.724.4.41|TRBC831246913010&status=unknown,registered,partial,corrected,preliminary,amended&type=EDO&type=B01,B01.0,B01.11,B01.12,B01.2,B01.81,B01.89,B01.9,Z20.820" } } ] }
The first request succeeds — a new Encounter and Composition is created.
On re-sending the same Bundle, the server fails with the following error:
{ "resourceType": "OperationOutcome", "issue": [ { "severity": "error", "code": "processing", "diagnostics": "HAPI-0550: could not execute batch [Batch entry 0 insert into hfj_res_search_url (created_time,res_id,res_search_url) values ('2025-05-21 13:56:37.138+02'::timestamp,6,'Encounter?status=discharged,discontinued,entered-in-error,in-progress,on-hold,planned,unknown&subject.identifier=urn%3Aoid%3A2.16.724.4.41%7CTRBC831246913010&type=B01,B01.0,B01.11,B01.12,B01.2,B01.81,B01.89,B01.9,Z20.820&type=EDO') was aborted: ERROR: llave duplicada viola restricción de unicidad «hfj_res_search_url_pkey»\n Detail: Ya existe la llave (res_search_url)=(Encounter?status=discharged,discontinued,entered-in-error,in-progress,on-hold,planned,unknown&subject.identifier=urn%3Aoid%3A2.16.724.4.41%7CTRBC831246913010&type=B01,B01.0,B01.11,B01.12,B01.2,B01.81,B01.89,B01.9,Z20.820&type=EDO). Call getNextException to see other errors in the batch.] [insert into hfj_res_search_url (created_time,res_id,res_search_url) values (?,?,?)]" } ] }