Terser should create correct Enumeration on create

This commit is contained in:
jamesagnew 2020-06-17 18:28:18 -04:00
parent 0d4e12fe58
commit f74eba5397
2 changed files with 18 additions and 1 deletions

View File

@ -454,7 +454,14 @@ public class FhirTerser {
List<? extends IBase> values = nextDef.getAccessor().getValues(theCurrentObj);
if (values.isEmpty() && theCreate) {
IBase value = nextDef.getChildByName(name).newInstance();
BaseRuntimeElementDefinition<?> childByName = nextDef.getChildByName(name);
Object arg = nextDef.getInstanceConstructorArguments();
IBase value;
if (arg != null) {
value = childByName.newInstance(arg);
} else {
value = childByName.newInstance();
}
nextDef.getMutator().addValue(theCurrentObj, value);
List<IBase> list = new ArrayList<>();
list.add(value);

View File

@ -8,6 +8,7 @@ import ca.uhn.fhir.parser.DataFormatException;
import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.*;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r4.model.Enumeration;
import org.hl7.fhir.r4.model.Patient.LinkType;
import org.junit.AfterClass;
import org.junit.Assert;
@ -31,6 +32,15 @@ public class FhirTerserR4Test {
private static final Logger ourLog = LoggerFactory.getLogger(FhirTerserR4Test.class);
private static FhirContext ourCtx = FhirContext.forR4();
@Test
public void testGetValuesCreateEnumeration_SetsEnumFactory() {
Patient patient = new Patient();
Enumeration<?> enumeration = (Enumeration<?>) ourCtx.newTerser().getValues(patient, "Patient.gender", Enumeration.class, true).get(0);
assertNotNull(enumeration.getEnumFactory());
}
@Test
public void testClear() {
Bundle input = new Bundle();