Skip to content

Commit 5b639ee

Browse files
jdar8jdarvolodymyr-korzh
authored
fix reference prefetch caching (#6822)
* failing test * failing test * fix and changelog * update changelog based on review suggestion Co-authored-by: volodymyr-korzh <[email protected]> * review change --------- Co-authored-by: jdar <[email protected]> Co-authored-by: volodymyr-korzh <[email protected]>
1 parent 2a09917 commit 5b639ee

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: fix
3+
issue: 6821
4+
jira: SMILE-10029
5+
title: "Previously, when submitting a transaction bundle with a placeholder ID referencing another resource within the same bundle, the
6+
reference would sometimes fail to resolve, resulting in a 400 Bad Request error. This has now been fixed."

hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package ca.uhn.fhir.jpa.dao.r4;
22

33
import static ca.uhn.fhir.test.utilities.UuidUtils.HASH_UUID_PATTERN;
4+
5+
import org.hl7.fhir.r4.model.MessageHeader;
6+
import org.hl7.fhir.r4.model.RequestGroup;
7+
48
import static org.junit.jupiter.api.Assertions.assertNull;
59
import static org.junit.jupiter.api.Assertions.assertTrue;
610
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -5173,4 +5177,23 @@ public void testTransactionWithDuplicateConditionalCreateAndDelete() {
51735177
assertEquals(status204, resp.getEntry().get(1).getResponse().getStatus());
51745178
}
51755179

5180+
@Test
5181+
public void testTransaction_withPlaceholderIdReferences_referencesResolveSuccessfully() {
5182+
Patient p = new Patient();
5183+
p.setActive(true);
5184+
p.setId("A123");
5185+
myPatientDao.update(p, mySrd);
5186+
5187+
String bundleString = ClasspathUtil.loadResource("/transaction-bundles/transaction-bundle.json");
5188+
Bundle input = myFhirContext.newJsonParser().parseResource(Bundle.class, bundleString);
5189+
5190+
Bundle resp = mySystemDao.transaction(null, input);
5191+
assertThat(resp.getEntry()).hasSize(2);
5192+
resp.getEntry().stream().map(bundleEntry -> bundleEntry.getResponse().getStatus()).forEach(statusMessage -> assertThat(statusMessage).isEqualTo("201 Created"));
5193+
List<String> createdResources = resp.getEntry().stream().map(b->b.getResponse().getLocation()).toList();
5194+
assertThat(createdResources)
5195+
.hasSize(2)
5196+
.allMatch(resourceLocation -> resourceLocation.contains("MessageHeader") || resourceLocation.contains("RequestGroup"));
5197+
}
5198+
51765199
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"resourceType": "Bundle",
3+
"type": "transaction",
4+
"entry": [
5+
{
6+
"fullUrl": "urn:uuid:a6017be3-a75c-40d2-bf31-42037df175a7",
7+
"resource": {
8+
"resourceType": "RequestGroup"
9+
},
10+
"request": {
11+
"method": "POST",
12+
"url": "RequestGroup"
13+
}
14+
},
15+
{
16+
"fullUrl": "urn:uuid:aa3ed9c6-21f0-4904-b101-08f7efd638b7",
17+
"resource": {
18+
"resourceType": "MessageHeader",
19+
"meta": {
20+
"extension": [
21+
{
22+
"url": "http://hapifhir.io/fhir/StructureDefinition/auto-version-references-at-path",
23+
"valueString": "focus"
24+
}
25+
]
26+
},
27+
"focus": [
28+
{
29+
"reference": "urn:uuid:a6017be3-a75c-40d2-bf31-42037df175a7",
30+
"type": "RequestGroup"
31+
},
32+
{
33+
"reference": "Patient/A123",
34+
"type": "Patient"
35+
}
36+
]
37+
},
38+
"request": {
39+
"method": "POST",
40+
"url": "MessageHeader"
41+
}
42+
}
43+
]
44+
}

hapi-fhir-storage/src/main/java/ca/uhn/fhir/jpa/dao/BaseTransactionProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1851,7 +1851,10 @@ private void resolveReferencesThenSaveAndIndexResource(
18511851
} else {
18521852
// we will add the looked up info to the transaction
18531853
// for later
1854-
theTransactionDetails.addResolvedResourceId(id, resourceVersionMap.getResourcePersistentId(id));
1854+
if (resourceVersionMap.containsKey(id)) {
1855+
theTransactionDetails.addResolvedResourceId(
1856+
id, resourceVersionMap.getResourcePersistentId(id));
1857+
}
18551858
}
18561859
}
18571860

0 commit comments

Comments
 (0)