Skip to content

Commit 6023f52

Browse files
authored
Merge 0c28a8e into 4482622
2 parents 4482622 + 0c28a8e commit 6023f52

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
type: fix
3+
issue: 4873
4+
title: "Previously, if the fhirId in ResourceTable happened to be set to an empty string, the resourceId would be missing when trying to generate the full ID string. This has now been fixed."

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,9 @@ private DaoMethodOutcome doCreateForPostOrPut(RequestDetails theRequest, T theRe
389389
String resourceIdBeforeStorage = theResource.getIdElement().getIdPart();
390390
boolean resourceHadIdBeforeStorage = isNotBlank(resourceIdBeforeStorage);
391391
boolean resourceIdWasServerAssigned = theResource.getUserData(JpaConstants.RESOURCE_ID_SERVER_ASSIGNED) == Boolean.TRUE;
392-
entity.setFhirId(resourceIdBeforeStorage);
392+
if (resourceHadIdBeforeStorage) {
393+
entity.setFhirId(resourceIdBeforeStorage);
394+
}
393395

394396
HookParams hookParams;
395397

hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/ResourceTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ public IIdType getIdType(FhirContext theContext) {
815815
}
816816

817817
private void populateId(IIdType retVal) {
818-
if (myFhirId != null) {
818+
if (myFhirId != null && !myFhirId.isEmpty()) {
819819
retVal.setValue(getResourceType() + '/' + myFhirId + '/' + Constants.PARAM_HISTORY + '/' + getVersion());
820820
} else if (getTransientForcedId() != null) {
821821
// Avoid a join query if possible

hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceTableTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package ca.uhn.fhir.jpa.model.entity;
22

33
import ca.uhn.fhir.context.FhirContext;
4+
import ca.uhn.fhir.model.primitive.IdDt;
5+
import org.hl7.fhir.r4.model.Patient;
46
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.CsvSource;
59

10+
import javax.measure.quantity.Force;
11+
12+
import static org.hamcrest.MatcherAssert.assertThat;
613
import static org.junit.jupiter.api.Assertions.*;
714

815
public class ResourceTableTest {
@@ -16,5 +23,26 @@ public void testResourceLength() {
1623
}
1724
}
1825

26+
@ParameterizedTest
27+
@CsvSource(value={
28+
"123, 123, Patient/123/_history/1",
29+
", 123, Patient/123/_history/1",
30+
"null, 456, Patient/456/_history/1"
31+
},nullValues={"null"})
32+
public void testPopulateId(String theFhirId, String theForcedId, String theExpected) {
33+
// Given
34+
ResourceTable t = new ResourceTable();
35+
t.setFhirId(theFhirId);
36+
ForcedId forcedId = new ForcedId();
37+
forcedId.setForcedId(theForcedId);
38+
t.setForcedId(forcedId);
39+
t.setResourceType(new Patient().getResourceType().name());
40+
t.setVersion(1);
41+
42+
// When
43+
IdDt actual = t.getIdDt();
1944

45+
// Then
46+
assertTrue(actual.equals(theExpected));
47+
}
2048
}

hapi-fhir-jpaserver-uhnfhirtest/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>ca.uhn.hapi.fhir</groupId>
77
<artifactId>hapi-fhir</artifactId>
8-
<version>6.5.20-SNAPSHOT</version>
8+
<version>6.5.21-SNAPSHOT</version>
99

1010
<relativePath>../pom.xml</relativePath>
1111
</parent>

tests/hapi-fhir-base-test-jaxrsserver-kotlin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>ca.uhn.hapi.fhir</groupId>
88
<artifactId>hapi-fhir</artifactId>
9-
<version>6.5.20-SNAPSHOT</version>
9+
<version>6.5.21-SNAPSHOT</version>
1010

1111
<relativePath>../../pom.xml</relativePath>
1212
</parent>

0 commit comments

Comments
 (0)