Fix: Replace basic field with empty value in TerserUtil (#4842)
* add test proving bug * fix: handle empty fromValue in TerserUtil.replaceField * add comment to TerserUtilTest.testReplaceFieldByEmptyValue
This commit is contained in:
parent
c052663561
commit
679b809bf3
|
@ -441,7 +441,10 @@ public final class TerserUtil {
|
||||||
private static void replaceField(FhirTerser theTerser, IBaseResource theFrom, IBaseResource theTo, BaseRuntimeChildDefinition childDefinition) {
|
private static void replaceField(FhirTerser theTerser, IBaseResource theFrom, IBaseResource theTo, BaseRuntimeChildDefinition childDefinition) {
|
||||||
List<IBase> fromValues = childDefinition.getAccessor().getValues(theFrom);
|
List<IBase> fromValues = childDefinition.getAccessor().getValues(theFrom);
|
||||||
List<IBase> toValues = childDefinition.getAccessor().getValues(theTo);
|
List<IBase> toValues = childDefinition.getAccessor().getValues(theTo);
|
||||||
if (fromValues != toValues) {
|
|
||||||
|
if (fromValues.isEmpty() && !toValues.isEmpty()) {
|
||||||
|
childDefinition.getMutator().setValue(theTo, null);
|
||||||
|
} else if (fromValues != toValues) {
|
||||||
clear(toValues);
|
clear(toValues);
|
||||||
|
|
||||||
mergeFields(theTerser, theTo, childDefinition, fromValues, toValues);
|
mergeFields(theTerser, theTo, childDefinition, fromValues, toValues);
|
||||||
|
@ -529,7 +532,6 @@ public final class TerserUtil {
|
||||||
* Creates a new element taking into consideration elements with choice that are not directly retrievable by element
|
* Creates a new element taking into consideration elements with choice that are not directly retrievable by element
|
||||||
* name
|
* name
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param theFhirTerser
|
* @param theFhirTerser
|
||||||
* @param theChildDefinition Child to create a new instance for
|
* @param theChildDefinition Child to create a new instance for
|
||||||
* @param theFromFieldValue The base parent field
|
* @param theFromFieldValue The base parent field
|
||||||
|
|
|
@ -468,6 +468,17 @@ class TerserUtilTest {
|
||||||
assertEquals(1, p2.getName().size());
|
assertEquals(1, p2.getName().size());
|
||||||
assertEquals("Doe", p2.getName().get(0).getFamily());
|
assertEquals("Doe", p2.getName().get(0).getFamily());
|
||||||
}
|
}
|
||||||
|
@Test
|
||||||
|
public void testReplaceFieldByEmptyValue() {
|
||||||
|
Patient p1 = new Patient();
|
||||||
|
Patient p2 = new Patient();
|
||||||
|
p2.setActive(true);
|
||||||
|
|
||||||
|
TerserUtil.replaceField(ourFhirContext, "active", p1, p2);
|
||||||
|
|
||||||
|
// expect p2 to have 'active removed'
|
||||||
|
assertFalse(p2.hasActive());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReplaceFieldsByPredicate() {
|
public void testReplaceFieldsByPredicate() {
|
||||||
|
|
Loading…
Reference in New Issue