Fix operation on nested type-choices in FhirPatch implementation (#4783)
* Fix operation on nested type-choices in FhirPatch implementation * Add credit for #4783 --------- Co-authored-by: James Agnew <jamesagnew@gmail.com>
This commit is contained in:
parent
9a095cc2d7
commit
9c1d235f90
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 4783
|
||||
title: "FHIR Patch operations on choice types in nested expressions did not work correctly.
|
||||
Thanks to Zach Smith for the pull request!"
|
|
@ -19,6 +19,7 @@ import org.hl7.fhir.r4.model.Patient;
|
|||
import org.hl7.fhir.r4.model.Questionnaire;
|
||||
import org.hl7.fhir.r4.model.StringType;
|
||||
import org.hl7.fhir.r4.model.Type;
|
||||
import org.hl7.fhir.r4.model.UriType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -386,7 +387,7 @@ public class FhirPatchApplyR4Test {
|
|||
Patient patient = new Patient();
|
||||
patient.setActive(true);
|
||||
|
||||
//Given: We create a patch request to add a new active statuts
|
||||
//Given: We create a patch request to add a new active status
|
||||
BooleanType theValue = new BooleanType(false);
|
||||
Parameters patch = new Parameters();
|
||||
patch.addParameter(createPatchAddOperation("Patient", "active", theValue));
|
||||
|
@ -397,6 +398,37 @@ public class FhirPatchApplyR4Test {
|
|||
//TODO THIS SHOULD THROW AN EXCEPTION. you cannot `add` to a field that is already set.
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddExtensionWithChoiceType() {
|
||||
FhirPatch svc = new FhirPatch(ourCtx);
|
||||
Patient patient = new Patient();
|
||||
|
||||
Parameters patch = new Parameters();
|
||||
Parameters.ParametersParameterComponent addOperation = createPatchAddOperation("Patient", "extension", null);
|
||||
addOperation
|
||||
.addPart()
|
||||
.setName("value")
|
||||
.addPart(
|
||||
new Parameters.ParametersParameterComponent()
|
||||
.setName("url")
|
||||
.setValue(new UriType("http://foo/fhir/extension/foo"))
|
||||
)
|
||||
.addPart(
|
||||
new Parameters.ParametersParameterComponent()
|
||||
.setName("value")
|
||||
.setValue(new StringType("foo"))
|
||||
);
|
||||
patch.addParameter(addOperation);
|
||||
|
||||
svc.apply(patient, patch);
|
||||
ourLog.debug("Outcome:\n{}", ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient));
|
||||
|
||||
//Then: it adds the new extension correctly.
|
||||
assertThat(patient.getExtension(), hasSize(1));
|
||||
assertThat(patient.getExtension().get(0).getUrl(), is(equalTo("http://foo/fhir/extension/foo")));
|
||||
assertThat(patient.getExtension().get(0).getValueAsPrimitive().getValueAsString(), is(equalTo("foo")));
|
||||
}
|
||||
|
||||
private Parameters.ParametersParameterComponent createPatchAddOperation(String thePath, String theName, Type theValue) {
|
||||
return createPatchOperation("add", thePath, theName, theValue, null);
|
||||
}
|
||||
|
|
|
@ -225,6 +225,10 @@ public class FhirPatch {
|
|||
if (value.isPresent()) {
|
||||
|
||||
BaseRuntimeChildDefinition partChildDef = childElement.getChildByName(name);
|
||||
if (partChildDef == null) {
|
||||
name = name + "[x]";
|
||||
partChildDef = childElement.getChildByName(name);
|
||||
}
|
||||
partChildDef.getMutator().addValue(newValue, value.get());
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue