Failure in tx processing (#5703)
* Fix #5110 - Failure in tx processing * Test fix
This commit is contained in:
parent
2caccc796b
commit
90f1690809
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 5110
|
||||
title: "When processing a FHIR transaction in the JPA server, an identifier containing a
|
||||
system that has no value but has an extension present could cause a NullPointerException.
|
||||
This has been corrected."
|
|
@ -13,6 +13,7 @@ import org.hl7.fhir.r5.model.Parameters;
|
|||
import org.hl7.fhir.r5.model.Patient;
|
||||
import org.hl7.fhir.r5.model.Quantity;
|
||||
import org.hl7.fhir.r5.model.Reference;
|
||||
import org.hl7.fhir.r5.model.UriType;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
|
@ -27,6 +28,8 @@ import static org.apache.commons.lang3.StringUtils.countMatches;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.in;
|
||||
import static org.hamcrest.Matchers.matchesPattern;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
@ -670,6 +673,30 @@ public class FhirSystemDaoTransactionR5Test extends BaseJpaR5Test {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* See #5110
|
||||
*/
|
||||
@Test
|
||||
public void testTransactionWithMissingSystem() {
|
||||
BundleBuilder bb = new BundleBuilder(myFhirContext);
|
||||
Patient patient = new Patient();
|
||||
patient.setId(IdType.newRandomUuid());
|
||||
|
||||
// The identifier has a system URI that has no value, only an extension
|
||||
UriType system = new UriType();
|
||||
system.addExtension("http://hl7.org/fhir/StructureDefinition/data-absent-reason", new CodeType("unknown"));
|
||||
patient.addIdentifier().setValue("m123").setSystemElement(system);
|
||||
|
||||
patient.addName().setText("Jane Doe");
|
||||
bb.addTransactionCreateEntry(patient);
|
||||
Bundle inputBundle = bb.getBundleTyped();
|
||||
|
||||
Bundle outputBundle = mySystemDao.transaction(mySrd, inputBundle);
|
||||
|
||||
assertThat(outputBundle.getEntry().get(0).getResponse().getLocation(), matchesPattern("Patient/[0-9]+/_history/1"));
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
private static Bundle createBundleWithConditionalDeleteAndConditionalUpdateOnSameResource(FhirContext theFhirContext) {
|
||||
// Build a new bundle each time we need it
|
||||
|
|
|
@ -1745,16 +1745,18 @@ public abstract class BaseTransactionProcessor {
|
|||
continue; // No substitution on the resource ID itself!
|
||||
}
|
||||
String nextUriString = nextRef.getValueAsString();
|
||||
if (theIdSubstitutions.containsSource(nextUriString)) {
|
||||
IIdType newId = theIdSubstitutions.getForSource(nextUriString);
|
||||
ourLog.debug(" * Replacing resource ref {} with {}", nextUriString, newId);
|
||||
if (isNotBlank(nextUriString)) {
|
||||
if (theIdSubstitutions.containsSource(nextUriString)) {
|
||||
IIdType newId = theIdSubstitutions.getForSource(nextUriString);
|
||||
ourLog.debug(" * Replacing resource ref {} with {}", nextUriString, newId);
|
||||
|
||||
String existingValue = nextRef.getValueAsString();
|
||||
theTransactionDetails.addRollbackUndoAction(() -> nextRef.setValueAsString(existingValue));
|
||||
String existingValue = nextRef.getValueAsString();
|
||||
theTransactionDetails.addRollbackUndoAction(() -> nextRef.setValueAsString(existingValue));
|
||||
|
||||
nextRef.setValueAsString(newId.toVersionless().getValue());
|
||||
} else {
|
||||
ourLog.debug(" * Reference [{}] does not exist in bundle", nextUriString);
|
||||
nextRef.setValueAsString(newId.toVersionless().getValue());
|
||||
} else {
|
||||
ourLog.debug(" * Reference [{}] does not exist in bundle", nextUriString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue