From e1aa3f335ecc4dedb7f3356ce91c102be1b6d375 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Wed, 10 Dec 2014 22:02:31 -0500 Subject: [PATCH] Unit tests all pass! --- .../BaseRuntimeDeclaredChildDefinition.java | 17 +-- .../java/ca/uhn/fhir/context/FhirContext.java | 5 +- .../context/RuntimeChildChoiceDefinition.java | 10 +- ...ntimeChildDeclaredExtensionDefinition.java | 5 +- ...imeChildUndeclaredExtensionDefinition.java | 6 +- .../RuntimeResourceReferenceDefinition.java | 2 +- .../model/api/BaseIdentifiableElement.java | 2 +- .../ca/uhn/fhir/model/api/BasePrimitive.java | 4 +- .../java/ca/uhn/fhir/model/api/IElement.java | 3 - .../fhir/model/api/IPrimitiveDatatype.java | 4 +- .../fhir/model/primitive/BaseDateTimeDt.java | 3 +- .../ca/uhn/fhir/model/primitive/IdDt.java | 22 ++- .../ca/uhn/fhir/model/view/ViewGenerator.java | 10 +- .../BaseThymeleafNarrativeGenerator.java | 10 +- .../fhir/narrative/INarrativeGenerator.java | 11 +- .../java/ca/uhn/fhir/parser/BaseParser.java | 102 ++++++++----- .../main/java/ca/uhn/fhir/parser/IParser.java | 12 +- .../java/ca/uhn/fhir/parser/JsonParser.java | 136 +++++++++--------- .../java/ca/uhn/fhir/parser/ParserState.java | 70 ++++----- .../java/ca/uhn/fhir/parser/XmlParser.java | 75 ++++++---- .../uhn/fhir/rest/client/GenericClient.java | 28 ++-- .../uhn/fhir/rest/client/IGenericClient.java | 10 +- .../ca/uhn/fhir/rest/method/MethodUtil.java | 37 +++-- .../uhn/fhir/rest/param/ReferenceParam.java | 5 +- .../java/ca/uhn/fhir/util/FhirTerser.java | 14 +- .../java/ca/uhn/fhir/util/IModelVisitor.java | 5 +- .../validation/SchematronBaseValidator.java | 3 +- .../org/hl7/fhir/instance/model/IBase.java | 2 + .../fhir/instance/model/IPrimitiveType.java | 11 +- .../fhir/instance/model/PrimitiveType.java | 2 +- .../ca/uhn/fhir/model/dstu/FhirDstu1.java | 6 +- .../interceptor/AuditingInterceptorTest.java | 6 +- .../ca/uhn/fhir/parser/XmlParserTest.java | 3 +- 33 files changed, 370 insertions(+), 271 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeDeclaredChildDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeDeclaredChildDefinition.java index 799f2f1944a..acc92534b20 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeDeclaredChildDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/BaseRuntimeDeclaredChildDefinition.java @@ -30,6 +30,7 @@ import java.util.Collections; import java.util.List; import org.apache.commons.lang3.text.WordUtils; +import org.hl7.fhir.instance.model.IBase; import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.annotation.Child; @@ -185,7 +186,7 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil private final class FieldPlainMutator implements IMutator { @Override - public void addValue(Object theTarget, IElement theValue) { + public void addValue(Object theTarget, IBase theValue) { try { myField.set(theTarget, theValue); } catch (IllegalArgumentException e) { @@ -216,12 +217,12 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil private final class FieldListMutator implements IMutator { @Override - public void addValue(Object theTarget, IElement theValue) { + public void addValue(Object theTarget, IBase theValue) { try { @SuppressWarnings("unchecked") - List existingList = (List) myField.get(theTarget); + List existingList = (List) myField.get(theTarget); if (existingList == null) { - existingList = new ArrayList(2); + existingList = new ArrayList(2); myField.set(theTarget, existingList); } existingList.add(theValue); @@ -282,11 +283,11 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil } @Override - public void addValue(Object theTarget, IElement theValue) { + public void addValue(Object theTarget, IBase theValue) { @SuppressWarnings("unchecked") - List existingList = (List) myAccessor.getValues(theTarget); + List existingList = (List) myAccessor.getValues(theTarget); if (existingList == null) { - existingList = new ArrayList(); + existingList = new ArrayList(); try { myMutatorMethod.invoke(theTarget, existingList); } catch (IllegalAccessException e) { @@ -335,7 +336,7 @@ public abstract class BaseRuntimeDeclaredChildDefinition extends BaseRuntimeChil } @Override - public void addValue(Object theTarget, IElement theValue) { + public void addValue(Object theTarget, IBase theValue) { try { if (theValue != null && !myTargetReturnType.isAssignableFrom(theValue.getClass())) { throw new ConfigurationException("Value for field " + myElementName + " expects type " + myTargetReturnType + " but got " + theValue.getClass()); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java index f7c893227d3..bfc74a10193 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java @@ -33,7 +33,6 @@ import org.hl7.fhir.instance.model.IBase; import org.hl7.fhir.instance.model.IBaseResource; import ca.uhn.fhir.i18n.HapiLocalizer; -import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.IFhirVersion; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.resource.Binary; @@ -107,7 +106,7 @@ public class FhirContext { /** * Returns the scanned runtime model for the given type. This is an advanced feature which is generally only needed for extending the core library. */ - public BaseRuntimeElementDefinition getElementDefinition(Class theElementType) { + public BaseRuntimeElementDefinition getElementDefinition(Class theElementType) { return myClassToElementDefinition.get(theElementType); } @@ -144,7 +143,7 @@ public class FhirContext { /** * Returns the scanned runtime model for the given type. This is an advanced feature which is generally only needed for extending the core library. */ - public RuntimeResourceDefinition getResourceDefinition(IResource theResource) { + public RuntimeResourceDefinition getResourceDefinition(IBaseResource theResource) { return getResourceDefinition(theResource.getClass()); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java index ae2f7c22716..f1b229c6565 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java @@ -30,8 +30,8 @@ import java.util.Set; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.IBase; +import org.hl7.fhir.instance.model.IBaseResource; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; @@ -88,11 +88,11 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini String elementName; String alternateElementName = null; BaseRuntimeElementDefinition nextDef; - if (IResource.class.isAssignableFrom(next)) { + if (IBaseResource.class.isAssignableFrom(next)) { elementName = getElementName() + StringUtils.capitalize(next.getSimpleName()); alternateElementName = getElementName() + "Resource"; - List> types = new ArrayList>(); - types.add((Class) next); + List> types = new ArrayList>(); + types.add((Class) next); nextDef = new RuntimeResourceReferenceDefinition(elementName, types); nextDef.sealAndInitialize(theClassToElementDefinitions); } else { @@ -105,7 +105,7 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini myNameToChildDefinition.put(alternateElementName, nextDef); } - if (IResource.class.isAssignableFrom(next)) { + if (IBaseResource.class.isAssignableFrom(next)) { myDatatypeToElementDefinition.put(ResourceReferenceDt.class, nextDef); alternateElementName = getElementName() + "Resource"; myDatatypeToElementName.put(ResourceReferenceDt.class, alternateElementName); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java index 528a1d14013..0fe5e165780 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildDeclaredExtensionDefinition.java @@ -20,7 +20,7 @@ package ca.uhn.fhir.context; * #L% */ -import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.apache.commons.lang3.StringUtils.*; import java.lang.reflect.Field; import java.util.ArrayList; @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Set; import org.hl7.fhir.instance.model.IBase; +import org.hl7.fhir.instance.model.IBaseResource; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.Child; @@ -140,7 +141,7 @@ public class RuntimeChildDeclaredExtensionDefinition extends BaseRuntimeDeclared if ("valueResourceReference".equals(myDatatypeChildName)) { // Per one of the examples here: http://hl7.org/implement/standards/fhir/extensibility.html#extension myDatatypeChildName = "valueResource"; - List> types = new ArrayList>(); + List> types = new ArrayList>(); types.add(IResource.class); myChildDef = new RuntimeResourceReferenceDefinition("valueResource", types); }else { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java index c241ff44b0c..99e7932bc20 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java @@ -30,10 +30,10 @@ import java.util.Set; import org.apache.commons.lang3.text.WordUtils; import org.hl7.fhir.instance.model.IBase; +import org.hl7.fhir.instance.model.IBaseResource; import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.IDatatype; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; @@ -99,8 +99,8 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD // Resource Reference myDatatypeToAttributeName.put(ResourceReferenceDt.class, "valueResource"); - List> types = new ArrayList>(); - types.add(IResource.class); + List> types = new ArrayList>(); + types.add(IBaseResource.class); RuntimeResourceReferenceDefinition def = new RuntimeResourceReferenceDefinition("valueResource", types); def.sealAndInitialize(theClassToElementDefinitions); myAttributeNameToDefinition.put("valueResource", def); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceReferenceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceReferenceDefinition.java index be0bc8d01ab..bfabffcc302 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceReferenceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeResourceReferenceDefinition.java @@ -52,7 +52,7 @@ public class RuntimeResourceReferenceDefinition extends BaseRuntimeElementDefini void sealAndInitialize(Map, BaseRuntimeElementDefinition> theClassToElementDefinitions) { myResourceTypeToDefinition = new HashMap, RuntimeResourceDefinition>(); for (Class next : myResourceTypes) { - if (next.equals(IResource.class) || next.equals(Resource.class)) { + if (next.equals(IResource.class) || next.equals(Resource.class) || next.equals(IBaseResource.class)) { continue; } RuntimeResourceDefinition definition = (RuntimeResourceDefinition) theClassToElementDefinitions.get(next); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BaseIdentifiableElement.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BaseIdentifiableElement.java index 9bc279a4112..482405e151e 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BaseIdentifiableElement.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BaseIdentifiableElement.java @@ -82,7 +82,7 @@ public abstract class BaseIdentifiableElement extends BaseElement implements IId } @Override - public void setValue(String theValue) throws DataFormatException { + public IdDt setValue(String theValue) throws DataFormatException { throw new UnsupportedOperationException("Use IElement#setElementSpecificId(String) to set the element ID for an element"); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BasePrimitive.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BasePrimitive.java index c099a4e8611..0bc1becda34 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BasePrimitive.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BasePrimitive.java @@ -22,6 +22,7 @@ package ca.uhn.fhir.model.api; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.hl7.fhir.instance.model.IPrimitiveType; import ca.uhn.fhir.parser.DataFormatException; @@ -67,9 +68,10 @@ public abstract class BasePrimitive extends BaseIdentifiableElement implement } @Override - public void setValue(T theValue) throws DataFormatException { + public IPrimitiveType setValue(T theValue) throws DataFormatException { myCoercedValue = theValue; updateStringValue(); + return this; } protected void updateStringValue() { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IElement.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IElement.java index b202a75714a..d4c77185f49 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IElement.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IElement.java @@ -25,8 +25,5 @@ import org.hl7.fhir.instance.model.IBase; public interface IElement extends IBase { - - boolean isEmpty(); - } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IPrimitiveDatatype.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IPrimitiveDatatype.java index 488c322eeda..785db26f5a7 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IPrimitiveDatatype.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/IPrimitiveDatatype.java @@ -24,7 +24,7 @@ import org.hl7.fhir.instance.model.IPrimitiveType; import ca.uhn.fhir.parser.DataFormatException; -public interface IPrimitiveDatatype extends IDatatype, IPrimitiveType { +public interface IPrimitiveDatatype extends IDatatype, IPrimitiveType { void setValueAsString(String theValue) throws DataFormatException; @@ -32,5 +32,5 @@ public interface IPrimitiveDatatype extends IDatatype, IPrimitiveType { T getValue(); - void setValue(T theValue) throws DataFormatException; + IPrimitiveType setValue(T theValue) throws DataFormatException; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java index 498876c028e..303b94b331a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/BaseDateTimeDt.java @@ -373,9 +373,10 @@ public abstract class BaseDateTimeDt extends BasePrimitive { } @Override - public void setValue(Date theValue) { + public BaseDateTimeDt setValue(Date theValue) { clearTimeZone(); super.setValue(theValue); + return this; } /** diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java index 6778035ddcb..fcae180a8d3 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/IdDt.java @@ -20,8 +20,7 @@ package ca.uhn.fhir.model.primitive; * #L% */ -import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.apache.commons.lang3.StringUtils.*; import java.math.BigDecimal; @@ -29,8 +28,11 @@ import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.hl7.fhir.instance.model.IBaseResource; +import org.hl7.fhir.instance.model.Resource; import ca.uhn.fhir.model.api.IPrimitiveDatatype; +import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.DatatypeDef; import ca.uhn.fhir.model.api.annotation.SimpleSetter; import ca.uhn.fhir.parser.DataFormatException; @@ -346,9 +348,10 @@ public class IdDt implements IPrimitiveDatatype { *

* regex: [a-z0-9\-\.]{1,36} *

+ * @return */ @Override - public void setValue(String theValue) throws DataFormatException { + public IdDt setValue(String theValue) throws DataFormatException { // TODO: add validation myValue = theValue; myHaveComponentParts = false; @@ -388,6 +391,7 @@ public class IdDt implements IPrimitiveDatatype { } } + return this; } /** @@ -505,4 +509,16 @@ public class IdDt implements IPrimitiveDatatype { return isBlank(getValue()); } + public void applyTo(IBaseResource theResouce) { + if (theResouce == null) { + throw new NullPointerException("theResource can not be null"); + } else if (theResouce instanceof IResource) { + ((IResource) theResouce).setId(new IdDt(getValue())); + } else if (theResouce instanceof Resource) { + ((Resource) theResouce).setId(getIdPart()); + } else { + throw new IllegalArgumentException("Unknown resource class type, does not implement IResource or extend Resource"); + } + } + } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/view/ViewGenerator.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/view/ViewGenerator.java index 27807d57331..a8f526161b2 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/view/ViewGenerator.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/view/ViewGenerator.java @@ -22,6 +22,8 @@ package ca.uhn.fhir.model.view; import java.util.List; +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition; import ca.uhn.fhir.context.ConfigurationException; @@ -81,8 +83,8 @@ public class ViewGenerator { continue; } - List sourceValues = sourceChildEquivalent.getAccessor().getValues(theSource); - for (IElement nextElement : sourceValues) { + List sourceValues = sourceChildEquivalent.getAccessor().getValues(theSource); + for (IBase nextElement : sourceValues) { nextChild.getMutator().addValue(theTarget, nextElement); } } @@ -102,8 +104,8 @@ public class ViewGenerator { } else { - List values = sourceDeclaredExt.getAccessor().getValues(theSource); - for (IElement nextElement : values) { + List values = sourceDeclaredExt.getAccessor().getValues(theSource); + for (IBase nextElement : values) { nextExt.getMutator().addValue(theTarget, nextElement); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java index e442b63ffce..a9c48bb273f 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java @@ -36,6 +36,7 @@ import java.util.Properties; import org.apache.commons.io.IOUtils; import org.apache.commons.io.input.ReaderInputStream; import org.apache.commons.lang3.StringUtils; +import org.hl7.fhir.instance.model.IBaseResource; import org.thymeleaf.Arguments; import org.thymeleaf.Configuration; import org.thymeleaf.TemplateEngine; @@ -60,7 +61,6 @@ import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; import org.thymeleaf.templateresolver.TemplateResolver; import ca.uhn.fhir.context.ConfigurationException; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.composite.NarrativeDt; import ca.uhn.fhir.model.dstu.valueset.NarrativeStatusEnum; import ca.uhn.fhir.model.primitive.XhtmlDt; @@ -92,12 +92,12 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener } @Override - public NarrativeDt generateNarrative(IResource theResource) { + public NarrativeDt generateNarrative(IBaseResource theResource) { return generateNarrative(null, theResource); } @Override - public NarrativeDt generateNarrative(String theProfile, IResource theResource) { + public NarrativeDt generateNarrative(String theProfile, IBaseResource theResource) { if (!myInitialized) { initialize(); } @@ -144,12 +144,12 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener } @Override - public String generateTitle(IResource theResource) { + public String generateTitle(IBaseResource theResource) { return generateTitle(null, theResource); } @Override - public String generateTitle(String theProfile, IResource theResource) { + public String generateTitle(String theProfile, IBaseResource theResource) { if (!myInitialized) { initialize(); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/INarrativeGenerator.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/INarrativeGenerator.java index c64445f6db9..2d5e8f6345d 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/INarrativeGenerator.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/INarrativeGenerator.java @@ -20,18 +20,19 @@ package ca.uhn.fhir.narrative; * #L% */ -import ca.uhn.fhir.model.api.IResource; +import org.hl7.fhir.instance.model.IBaseResource; + import ca.uhn.fhir.model.dstu.composite.NarrativeDt; import ca.uhn.fhir.parser.DataFormatException; public interface INarrativeGenerator { - NarrativeDt generateNarrative(String theProfile, IResource theResource) throws DataFormatException; + NarrativeDt generateNarrative(String theProfile, IBaseResource theResource) throws DataFormatException; - NarrativeDt generateNarrative(IResource theResource); + NarrativeDt generateNarrative(IBaseResource theResource); - String generateTitle(IResource theResource); + String generateTitle(IBaseResource theResource); - String generateTitle(String theProfile, IResource theResource); + String generateTitle(String theProfile, IBaseResource theResource); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java index aae97c3536b..c84d2945a71 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/BaseParser.java @@ -20,7 +20,7 @@ package ca.uhn.fhir.parser; * #L% */ -import static org.apache.commons.lang3.StringUtils.isBlank; +import static org.apache.commons.lang3.StringUtils.*; import java.io.IOException; import java.io.Reader; @@ -34,7 +34,11 @@ import java.util.List; import java.util.Set; import org.apache.commons.lang3.StringUtils; +import org.hl7.fhir.instance.model.DomainResource; +import org.hl7.fhir.instance.model.IBase; import org.hl7.fhir.instance.model.IBaseResource; +import org.hl7.fhir.instance.model.Reference; +import org.hl7.fhir.instance.model.Resource; import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeDeclaredChildDefinition; @@ -42,7 +46,6 @@ import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeChildChoiceDefinition; import ca.uhn.fhir.model.api.Bundle; -import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; @@ -59,35 +62,64 @@ public abstract class BaseParser implements IParser { } protected String fixContainedResourceId(String theValue) { - if (StringUtils.isNotBlank(theValue)&&theValue.charAt(0)=='#') { + if (StringUtils.isNotBlank(theValue) && theValue.charAt(0) == '#') { return theValue.substring(1); } return theValue; } - private void containResourcesForEncoding(ContainedResources theContained, IBaseResource theResource, IBaseResource theTarget) { - List allElements = myContext.newTerser().getAllPopulatedChildElementsOfType(theResource, ResourceReferenceDt.class); Set allIds = new HashSet(); + if (theTarget instanceof IResource) { + List containedResources = ((IResource) theTarget).getContained().getContainedResources(); + for (IResource next : containedResources) { + String nextId = next.getId().getValue(); + if (StringUtils.isNotBlank(nextId)) { + allIds.add(nextId); + } + } + } else if (theTarget instanceof DomainResource) { + List containedResources = ((DomainResource) theTarget).getContained(); + for (Resource next : containedResources) { + String nextId = next.getId(); + if (StringUtils.isNotBlank(nextId)) { + allIds.add(nextId); + } + } + } else { + // no resources to contain + } - for (IResource next : theTarget.getContained().getContainedResources()) { - String nextId = next.getId().getValue(); - if (StringUtils.isNotBlank(nextId)) { - allIds.add(nextId); + { + List allElements = myContext.newTerser().getAllPopulatedChildElementsOfType(theResource, ResourceReferenceDt.class); + for (ResourceReferenceDt next : allElements) { + IResource resource = next.getResource(); + if (resource != null) { + if (resource.getId().isEmpty() || resource.getId().isLocal()) { + theContained.addContained(resource); + } else { + continue; + } + + containResourcesForEncoding(theContained, resource, theTarget); + } } } - for (ResourceReferenceDt next : allElements) { - IResource resource = next.getResource(); - if (resource != null) { - if (resource.getId().isEmpty() || resource.getId().isLocal()) { - theContained.addContained(resource); - } else { - continue; - } + { + List allElements = myContext.newTerser().getAllPopulatedChildElementsOfType(theResource, Reference.class); + for (Reference next : allElements) { + Resource resource = next.getResource(); + if (resource != null) { + if (resource.getIdElement().isEmpty() || resource.getId().startsWith("#")) { + theContained.addContained(resource); + } else { + continue; + } - containResourcesForEncoding(theContained, resource, theTarget); + containResourcesForEncoding(theContained, resource, theTarget); + } } } @@ -141,7 +173,8 @@ public abstract class BaseParser implements IParser { } /** - * If set to true (default is false), narratives will not be included in the encoded values. + * If set to true (default is false), narratives will not be included in the encoded + * values. */ public boolean getSuppressNarratives() { return mySuppressNarratives; @@ -186,12 +219,12 @@ public abstract class BaseParser implements IParser { return this; } - protected void throwExceptionForUnknownChildType(BaseRuntimeChildDefinition nextChild, Class type) { + protected void throwExceptionForUnknownChildType(BaseRuntimeChildDefinition nextChild, Class theType) { if (nextChild instanceof BaseRuntimeDeclaredChildDefinition) { StringBuilder b = new StringBuilder(); b.append(((BaseRuntimeDeclaredChildDefinition) nextChild).getElementName()); b.append(" has type "); - b.append(type); + b.append(theType.getName()); b.append(" but this is not a valid type for this element"); if (nextChild instanceof RuntimeChildChoiceDefinition) { RuntimeChildChoiceDefinition choice = (RuntimeChildChoiceDefinition) nextChild; @@ -199,7 +232,7 @@ public abstract class BaseParser implements IParser { } throw new DataFormatException(b.toString()); } - throw new DataFormatException(nextChild + " has no child of type " + type); + throw new DataFormatException(nextChild + " has no child of type " + theType); } protected String determineReferenceText(ResourceReferenceDt theRef) { @@ -221,37 +254,38 @@ public abstract class BaseParser implements IParser { return reference; } - static class ContainedResources { private long myNextContainedId = 1; - private IdentityHashMap myResourceToId = new IdentityHashMap(); - private List myResources = new ArrayList(); + private IdentityHashMap myResourceToId = new IdentityHashMap(); + private List myResources = new ArrayList(); - public void addContained(IResource theResource) { + public void addContained(IBaseResource theResource) { if (myResourceToId.containsKey(theResource)) { return; } - + IdDt newId; - if (theResource.getId().isLocal()) { - newId = theResource.getId(); + if (theResource instanceof IResource && ((IResource) theResource).getId().isLocal()) { + newId = ((IResource) theResource).getId(); + } else if (theResource instanceof Resource && ((Resource)theResource).getId() != null && ((Resource)theResource).getId().startsWith("#")) { + newId = new IdDt(((Resource)theResource).getId()); } else { // TODO: make this configurable between the two below (and something else?) // newId = new IdDt(UUID.randomUUID().toString()); newId = new IdDt(myNextContainedId++); } - + myResourceToId.put(theResource, newId); myResources.add(theResource); } - public List getContainedResources() { + public List getContainedResources() { return myResources; } - - public IdDt getResourceId(IResource theResource) { - return myResourceToId.get(theResource); + + public IdDt getResourceId(IBaseResource theNext) { + return myResourceToId.get(theNext); } public boolean isEmpty() { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/IParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/IParser.java index 78e2fe61bc6..8915eba3c1b 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/IParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/IParser.java @@ -25,7 +25,6 @@ import java.io.Reader; import java.io.Writer; import org.hl7.fhir.instance.model.IBaseResource; -import org.hl7.fhir.instance.model.Resource; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.model.api.Bundle; @@ -67,7 +66,7 @@ public interface IParser { */ void encodeTagListToWriter(TagList theTagList, Writer theWriter) throws IOException; - Bundle parseBundle(Class theResourceType, Reader theReader); + Bundle parseBundle(Class theResourceType, Reader theReader); Bundle parseBundle(Reader theReader); @@ -153,13 +152,4 @@ public interface IParser { */ IParser setSuppressNarratives(boolean theSuppressNarratives); - /** - * Parses a resource from the HL7.org structure library - * - * @param theClass The resource type - * @param theResourceBody The body of the resource to parse - * @return A parsed resource - */ - T parse(Class theClass, String theResourceBody); - } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java index 93a095d1b51..b573b494819 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java @@ -20,9 +20,7 @@ package ca.uhn.fhir.parser; * #L% */ -import static org.apache.commons.lang3.StringUtils.defaultString; -import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.apache.commons.lang3.StringUtils.*; import java.io.IOException; import java.io.Reader; @@ -51,7 +49,9 @@ import javax.json.stream.JsonParsingException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; +import org.hl7.fhir.instance.model.IBase; import org.hl7.fhir.instance.model.IBaseResource; +import org.hl7.fhir.instance.model.Resource; import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition; @@ -129,7 +129,7 @@ public class JsonParser extends BaseParser implements IParser { if (theResourceTypeObj == null) { throw new DataFormatException("Invalid JSON content detected, missing required element: '" + thePosition + "'"); } - + if (theResourceTypeObj.getValueType() != theValueType) { throw new DataFormatException("Invalid content of element " + thePosition + ", expected " + theValueType); } @@ -167,7 +167,7 @@ public class JsonParser extends BaseParser implements IParser { if (linkStarted) { eventWriter.writeEnd(); } - + writeCategories(eventWriter, theBundle.getCategories()); writeOptionalTagWithTextNode(eventWriter, "totalResults", theBundle.getTotalResults()); @@ -206,10 +206,10 @@ public class JsonParser extends BaseParser implements IParser { encodeResourceToJsonStreamWriter(resDef, resource, eventWriter, "content", false); } - if (nextEntry.getSummary().isEmpty()==false) { + if (nextEntry.getSummary().isEmpty() == false) { eventWriter.write("summary", nextEntry.getSummary().getValueAsString()); } - + eventWriter.writeEnd(); // entry object } eventWriter.writeEnd(); // entry array @@ -232,16 +232,15 @@ public class JsonParser extends BaseParser implements IParser { } } - private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, JsonGenerator theWriter, IElement theValue, BaseRuntimeElementDefinition theChildDef, - String theChildName, boolean theIsSubElementWithinResource) throws IOException { + private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theWriter, IBase theNextValue, BaseRuntimeElementDefinition theChildDef, String theChildName, boolean theIsSubElementWithinResource) throws IOException { switch (theChildDef.getChildType()) { case PRIMITIVE_DATATYPE: { - IPrimitiveDatatype value = (IPrimitiveDatatype) theValue; + IPrimitiveDatatype value = (IPrimitiveDatatype) theNextValue; if (isBlank(value.getValueAsString())) { break; } - + if (value instanceof IntegerDt) { if (theChildName != null) { theWriter.write(theChildName, ((IntegerDt) value).getValue()); @@ -278,23 +277,23 @@ public class JsonParser extends BaseParser implements IParser { } else { theWriter.writeStartObject(); } - if (theValue instanceof ExtensionDt) { - theWriter.write("url", ((ExtensionDt) theValue).getUrlAsString()); + if (theNextValue instanceof ExtensionDt) { + theWriter.write("url", ((ExtensionDt) theNextValue).getUrlAsString()); } - encodeCompositeElementToStreamWriter(theResDef, theResource, theValue, theWriter, childCompositeDef, theIsSubElementWithinResource); + encodeCompositeElementToStreamWriter(theResDef, theResource, theNextValue, theWriter, childCompositeDef, theIsSubElementWithinResource); theWriter.writeEnd(); break; } case RESOURCE_REF: { - ResourceReferenceDt referenceDt = (ResourceReferenceDt) theValue; + ResourceReferenceDt referenceDt = (ResourceReferenceDt) theNextValue; if (theChildName != null) { theWriter.writeStartObject(theChildName); } else { theWriter.writeStartObject(); } - String reference = determineReferenceText(referenceDt); - + String reference = determineReferenceText(referenceDt); + if (StringUtils.isNotBlank(reference)) { theWriter.write(XmlParser.RESREF_REFERENCE, reference); } @@ -306,14 +305,14 @@ public class JsonParser extends BaseParser implements IParser { } case CONTAINED_RESOURCES: { theWriter.writeStartArray(theChildName); - ContainedDt value = (ContainedDt) theValue; + ContainedDt value = (ContainedDt) theNextValue; for (IResource next : value.getContainedResources()) { - if (getContainedResources().getResourceId(next)!=null) { + if (getContainedResources().getResourceId(next) != null) { continue; } encodeResourceToJsonStreamWriter(theResDef, next, theWriter, null, true, fixContainedResourceId(next.getId().getValue())); } - for (IResource next : getContainedResources().getContainedResources()) { + for (IBaseResource next : getContainedResources().getContainedResources()) { IdDt resourceId = getContainedResources().getResourceId(next); encodeResourceToJsonStreamWriter(theResDef, next, theWriter, null, true, fixContainedResourceId(resourceId.getValue())); } @@ -322,7 +321,7 @@ public class JsonParser extends BaseParser implements IParser { } case PRIMITIVE_XHTML: { if (!getSuppressNarratives()) { - XhtmlDt dt = (XhtmlDt) theValue; + XhtmlDt dt = (XhtmlDt) theNextValue; if (theChildName != null) { theWriter.write(theChildName, dt.getValueAsString()); } else { @@ -344,10 +343,10 @@ public class JsonParser extends BaseParser implements IParser { } - private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, JsonGenerator theEventWriter, - List theChildren, boolean theIsSubElementWithinResource) throws IOException { + private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theNextValue, JsonGenerator theEventWriter, List theChildren, boolean theIsSubElementWithinResource) throws IOException { for (BaseRuntimeChildDefinition nextChild : theChildren) { if (nextChild instanceof RuntimeChildNarrativeDefinition) { + INarrativeGenerator gen = myContext.getNarrativeGenerator(); if (gen != null) { NarrativeDt narr = gen.generateNarrative(theResDef.getResourceProfile(), theResource); @@ -361,7 +360,7 @@ public class JsonParser extends BaseParser implements IParser { } } - List values = nextChild.getAccessor().getValues(theElement); + List values = nextChild.getAccessor().getValues(theNextValue); if (values == null || values.isEmpty()) { continue; } @@ -373,7 +372,7 @@ public class JsonParser extends BaseParser implements IParser { ArrayList> modifierExtensions = new ArrayList>(0); int valueIdx = 0; - for (IElement nextValue : values) { + for (IBase nextValue : values) { if (nextValue == null || nextValue.isEmpty()) { if (nextValue instanceof ContainedDt) { if (theIsSubElementWithinResource || getContainedResources().isEmpty()) { @@ -384,26 +383,27 @@ public class JsonParser extends BaseParser implements IParser { } } - Class type = nextValue.getClass(); + Class type = nextValue.getClass(); String childName = nextChild.getChildNameByDatatype(type); BaseRuntimeElementDefinition childDef = nextChild.getChildElementDefinitionByDatatype(type); if (childDef == null) { super.throwExceptionForUnknownChildType(nextChild, type); } boolean primitive = childDef.getChildType() == ChildTypeEnum.PRIMITIVE_DATATYPE; - + if (childDef.getChildType() == ChildTypeEnum.CONTAINED_RESOURCES && theIsSubElementWithinResource) { continue; } - + if (nextChild instanceof RuntimeChildDeclaredExtensionDefinition) { // Don't encode extensions -// RuntimeChildDeclaredExtensionDefinition extDef = (RuntimeChildDeclaredExtensionDefinition) nextChild; -// if (extDef.isModifier()) { -// addToHeldExtensions(valueIdx, modifierExtensions, extDef, nextValue); -// } else { -// addToHeldExtensions(valueIdx, extensions, extDef, nextValue); -// } + // RuntimeChildDeclaredExtensionDefinition extDef = (RuntimeChildDeclaredExtensionDefinition) + // nextChild; + // if (extDef.isModifier()) { + // addToHeldExtensions(valueIdx, modifierExtensions, extDef, nextValue); + // } else { + // addToHeldExtensions(valueIdx, extensions, extDef, nextValue); + // } } else { if (currentChildName == null || !currentChildName.equals(childName)) { @@ -468,25 +468,30 @@ public class JsonParser extends BaseParser implements IParser { } } - private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, JsonGenerator theEventWriter, - BaseRuntimeElementCompositeDefinition resDef, boolean theIsSubElementWithinResource) throws IOException, DataFormatException { - extractAndWriteExtensionsAsDirectChild(theElement, theEventWriter, resDef, theResDef, theResource); - encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getExtensions(), theIsSubElementWithinResource); - encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getChildren(),theIsSubElementWithinResource); + private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theNextValue, JsonGenerator theEventWriter, BaseRuntimeElementCompositeDefinition resDef, boolean theIsSubElementWithinResource) throws IOException, DataFormatException { + extractAndWriteExtensionsAsDirectChild(theNextValue, theEventWriter, resDef, theResDef, theResource); + encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theNextValue, theEventWriter, resDef.getExtensions(), theIsSubElementWithinResource); + encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theNextValue, theEventWriter, resDef.getChildren(), theIsSubElementWithinResource); } - private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, JsonGenerator theEventWriter, String theObjectNameOrNull, - boolean theIsSubElementWithinResource) throws IOException { + private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theEventWriter, String theObjectNameOrNull, boolean theIsSubElementWithinResource) throws IOException { String resourceId = null; - if (theIsSubElementWithinResource && StringUtils.isNotBlank(theResource.getId().getValue())) { - resourceId = theResource.getId().getValue(); + if (theResource instanceof IResource) { + IResource res = (IResource) theResource; + if (theIsSubElementWithinResource && StringUtils.isNotBlank(res.getId().getValue())) { + resourceId = res.getId().getValue(); + } + } else if (theResource instanceof Resource) { + Resource res = (Resource) theResource; + if (theIsSubElementWithinResource && StringUtils.isNotBlank(res.getId())) { + resourceId = res.getId(); + } } encodeResourceToJsonStreamWriter(theResDef, theResource, theEventWriter, theObjectNameOrNull, theIsSubElementWithinResource, resourceId); } - private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, JsonGenerator theEventWriter, String theObjectNameOrNull, boolean theIsSubElementWithinResource, - String theResourceId) throws IOException { + private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theEventWriter, String theObjectNameOrNull, boolean theIsSubElementWithinResource, String theResourceId) throws IOException { if (!theIsSubElementWithinResource) { super.containResourcesForEncoding(theResource); } @@ -515,7 +520,7 @@ public class JsonParser extends BaseParser implements IParser { } @Override - public void encodeResourceToWriter(IResource theResource, Writer theWriter) throws IOException { + public void encodeResourceToWriter(IBaseResource theResource, Writer theWriter) throws IOException { Validate.notNull(theResource, "Resource can not be null"); JsonGenerator eventWriter = createJsonGenerator(theWriter); @@ -556,10 +561,10 @@ public class JsonParser extends BaseParser implements IParser { } /** - * This is useful only for the two cases where extensions are encoded as direct children (e.g. not in some object called _name): resource extensions, and extension extensions + * This is useful only for the two cases where extensions are encoded as direct children (e.g. not in some object + * called _name): resource extensions, and extension extensions */ - private void extractAndWriteExtensionsAsDirectChild(IElement theElement, JsonGenerator theEventWriter, BaseRuntimeElementDefinition theElementDef, RuntimeResourceDefinition theResDef, - IResource theResource) throws IOException { + private void extractAndWriteExtensionsAsDirectChild(IBase theElement, JsonGenerator theEventWriter, BaseRuntimeElementDefinition theElementDef, RuntimeResourceDefinition theResDef, IBaseResource theResource) throws IOException { List extensions = new ArrayList(0); List modifierExtensions = new ArrayList(0); @@ -573,9 +578,9 @@ public class JsonParser extends BaseParser implements IParser { writeExtensionsAsDirectChild(theResource, theEventWriter, theResDef, extensions, modifierExtensions); } - private void extractDeclaredExtensions(IElement theResource, BaseRuntimeElementDefinition resDef, List extensions, List modifierExtensions) { + private void extractDeclaredExtensions(IBase theResource, BaseRuntimeElementDefinition resDef, List extensions, List modifierExtensions) { for (RuntimeChildDeclaredExtensionDefinition nextDef : resDef.getExtensionsNonModifier()) { - for (IElement nextValue : nextDef.getAccessor().getValues(theResource)) { + for (IBase nextValue : nextDef.getAccessor().getValues(theResource)) { if (nextValue != null) { if (nextValue == null || nextValue.isEmpty()) { continue; @@ -585,7 +590,7 @@ public class JsonParser extends BaseParser implements IParser { } } for (RuntimeChildDeclaredExtensionDefinition nextDef : resDef.getExtensionsModifier()) { - for (IElement nextValue : nextDef.getAccessor().getValues(theResource)) { + for (IBase nextValue : nextDef.getAccessor().getValues(theResource)) { if (nextValue != null) { if (nextValue == null || nextValue.isEmpty()) { continue; @@ -596,7 +601,7 @@ public class JsonParser extends BaseParser implements IParser { } } - private void extractUndeclaredExtensions(IElement theResource, List extensions, List modifierExtensions) { + private void extractUndeclaredExtensions(IBase theResource, List extensions, List modifierExtensions) { if (theResource instanceof ISupportsUndeclaredExtensions) { List ext = ((ISupportsUndeclaredExtensions) theResource).getUndeclaredExtensions(); for (ExtensionDt next : ext) { @@ -647,10 +652,10 @@ public class JsonParser extends BaseParser implements IParser { } @Override - public Bundle parseBundle(Class theResourceType, Reader theReader) { - JsonReader reader; + public Bundle parseBundle(Class theResourceType, Reader theReader) { + JsonReader reader; JsonObject object; - + try { reader = Json.createReader(theReader); object = reader.readObject(); @@ -853,7 +858,7 @@ public class JsonParser extends BaseParser implements IParser { def = myContext.getResourceDefinition(resourceType); } - ParserState state = ParserState.getPreResourceInstance(def.getImplementingClass(), myContext, true); + ParserState state = (ParserState) ParserState.getPreResourceInstance(def.getImplementingClass(), myContext, true); state.enteringNewElement(null, def.getName()); parseChildren(object, state); @@ -867,7 +872,7 @@ public class JsonParser extends BaseParser implements IParser { } @Override - public T parseResource(Class theResourceType, String theMessageString) { + public T parseResource(Class theResourceType, String theMessageString) { return parseResource(theResourceType, new StringReader(theMessageString)); } @@ -923,8 +928,7 @@ public class JsonParser extends BaseParser implements IParser { } } - private void writeExtensionsAsDirectChild(IResource theResource, JsonGenerator theEventWriter, RuntimeResourceDefinition resDef, List extensions, - List modifierExtensions) throws IOException { + private void writeExtensionsAsDirectChild(IBaseResource theResource, JsonGenerator theEventWriter, RuntimeResourceDefinition resDef, List extensions, List modifierExtensions) throws IOException { if (extensions.isEmpty() == false) { theEventWriter.writeStartArray("extension"); for (HeldExtension next : extensions) { @@ -969,21 +973,21 @@ public class JsonParser extends BaseParser implements IParser { private RuntimeChildDeclaredExtensionDefinition myDef; private ExtensionDt myUndeclaredExtension; - private IElement myValue; + private IBase myValue; public HeldExtension(ExtensionDt theUndeclaredExtension) { assert theUndeclaredExtension != null; myUndeclaredExtension = theUndeclaredExtension; } - public HeldExtension(RuntimeChildDeclaredExtensionDefinition theDef, IElement theValue) { + public HeldExtension(RuntimeChildDeclaredExtensionDefinition theDef, IBase theValue) { assert theDef != null; assert theValue != null; myDef = theDef; myValue = theValue; } - public void write(RuntimeResourceDefinition theResDef, IResource theResource, JsonGenerator theEventWriter) throws IOException { + public void write(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theEventWriter) throws IOException { if (myUndeclaredExtension != null) { writeUndeclaredExt(theResDef, theResource, theEventWriter, myUndeclaredExtension); } else { @@ -998,7 +1002,7 @@ public class JsonParser extends BaseParser implements IParser { // theEventWriter, myValue, def, "value" + // WordUtils.capitalize(def.getName())); String childName = myDef.getChildNameByDatatype(myValue.getClass()); - encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, myValue, def, childName,false); + encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, myValue, def, childName, false); } // theEventWriter.name(myUndeclaredExtension.get); @@ -1007,7 +1011,7 @@ public class JsonParser extends BaseParser implements IParser { } } - private void writeUndeclaredExt(RuntimeResourceDefinition theResDef, IResource theResource, JsonGenerator theEventWriter, ExtensionDt ext) throws IOException { + private void writeUndeclaredExt(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theEventWriter, ExtensionDt ext) throws IOException { IElement value = ext.getValue(); theEventWriter.writeStartObject(); @@ -1029,7 +1033,7 @@ public class JsonParser extends BaseParser implements IParser { throw new ConfigurationException("Unable to encode extension, unregognized child element type: " + value.getClass().getCanonicalName()); } BaseRuntimeElementDefinition childDef = extDef.getChildElementDefinitionByDatatype(value.getClass()); - encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, value, childDef, childName,true); + encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, value, childDef, childName, true); } // theEventWriter.name(myUndeclaredExtension.get); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java index 34c96799df2..e34d04b68b6 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java @@ -20,9 +20,7 @@ package ca.uhn.fhir.parser; * #L% */ -import static org.apache.commons.lang3.StringUtils.defaultIfBlank; -import static org.apache.commons.lang3.StringUtils.isNotBlank; -import static org.apache.commons.lang3.StringUtils.isNotEmpty; +import static org.apache.commons.lang3.StringUtils.*; import java.util.ArrayList; import java.util.HashMap; @@ -34,7 +32,10 @@ import javax.xml.stream.events.XMLEvent; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; +import org.hl7.fhir.instance.model.Element; +import org.hl7.fhir.instance.model.IBase; import org.hl7.fhir.instance.model.IBaseResource; +import org.hl7.fhir.instance.model.IPrimitiveType; import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition; @@ -52,11 +53,9 @@ import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.BundleEntry; import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.ICompositeDatatype; -import ca.uhn.fhir.model.api.ICompositeElement; import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.IIdentifiableElement; import ca.uhn.fhir.model.api.IPrimitiveDatatype; -import ca.uhn.fhir.model.api.IBaseResource; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResourceBlock; import ca.uhn.fhir.model.api.ISupportsUndeclaredExtensions; @@ -755,7 +754,7 @@ class ParserState { if (myInstance instanceof IIdentifiableElement) { ((IIdentifiableElement) myInstance).setElementSpecificId((theValue)); } else if (myInstance instanceof IBaseResource) { - ((IBaseResource) myInstance).setId(new IdDt(theValue)); + (myInstance).setId(new IdDt(theValue)); } } else if ("contentType".equals(theName)) { myInstance.setContentType(theValue); @@ -826,7 +825,7 @@ class ParserState { @Override public void wereBack() { - IBaseResource res = getCurrentElement(); + IResource res = (IResource) getCurrentElement(); assert res != null; if (res.getId() == null || res.getId().isEmpty()) { ourLog.debug("Discarding contained resource with no ID!"); @@ -836,7 +835,8 @@ class ParserState { res.setId(new IdDt('#' + res.getId().getIdPart())); } } - getPreResourceState().getCurrentElement().getContained().getContainedResources().add(res); + IResource preResCurrentElement = (IResource) getPreResourceState().getCurrentElement(); + preResCurrentElement.getContained().getContainedResources().add(res); } @@ -844,12 +844,12 @@ class ParserState { private class DeclaredExtensionState extends BaseState { - private IElement myChildInstance; + private IBase myChildInstance; private RuntimeChildDeclaredExtensionDefinition myDefinition; - private IElement myParentInstance; + private IBase myParentInstance; private PreResourceState myPreResourceState; - public DeclaredExtensionState(PreResourceState thePreResourceState, RuntimeChildDeclaredExtensionDefinition theDefinition, IElement theParentInstance) { + public DeclaredExtensionState(PreResourceState thePreResourceState, RuntimeChildDeclaredExtensionDefinition theDefinition, IBase theParentInstance) { super(thePreResourceState); myPreResourceState = thePreResourceState; myDefinition = theDefinition; @@ -879,7 +879,7 @@ class ParserState { } case PRIMITIVE_DATATYPE: { RuntimePrimitiveDatatypeDefinition primitiveTarget = (RuntimePrimitiveDatatypeDefinition) target; - IPrimitiveDatatype newChildInstance = primitiveTarget.newInstance(); + IPrimitiveType newChildInstance = primitiveTarget.newInstance(); myDefinition.getMutator().addValue(myParentInstance, newChildInstance); PrimitiveState newState = new PrimitiveState(getPreResourceState(), newChildInstance); push(newState); @@ -918,7 +918,7 @@ class ParserState { } @Override - protected IElement getCurrentElement() { + protected IBase getCurrentElement() { return myParentInstance; } @@ -927,9 +927,9 @@ class ParserState { private class ElementCompositeState extends BaseState { private BaseRuntimeElementCompositeDefinition myDefinition; - private ICompositeElement myInstance; + private IBase myInstance; - public ElementCompositeState(PreResourceState thePreResourceState, BaseRuntimeElementCompositeDefinition theDef, ICompositeElement theInstance) { + public ElementCompositeState(PreResourceState thePreResourceState, BaseRuntimeElementCompositeDefinition theDef, IBase theInstance) { super(thePreResourceState); myDefinition = theDef; myInstance = theInstance; @@ -940,8 +940,10 @@ class ParserState { if ("id".equals(theName)) { if (myInstance instanceof IIdentifiableElement) { ((IIdentifiableElement) myInstance).setElementSpecificId((theValue)); + } else if (myInstance instanceof Element) { + ((Element) myInstance).setId(theValue); } else if (myInstance instanceof IBaseResource) { - ((IBaseResource) myInstance).setId(new IdDt(theValue)); + new IdDt(theValue).applyTo((IBaseResource) myInstance); } } else if ("url".equals(theName) && myInstance instanceof ExtensionDt) { ((ExtensionDt) myInstance).setUrl(theValue); @@ -986,7 +988,7 @@ class ParserState { } case PRIMITIVE_DATATYPE: { RuntimePrimitiveDatatypeDefinition primitiveTarget = (RuntimePrimitiveDatatypeDefinition) target; - IPrimitiveDatatype newChildInstance; + IPrimitiveType newChildInstance; newChildInstance = primitiveTarget.newInstance(child.getInstanceConstructorArguments()); child.getMutator().addValue(myInstance, newChildInstance); PrimitiveState newState = new PrimitiveState(getPreResourceState(), newChildInstance); @@ -1020,7 +1022,7 @@ class ParserState { } case CONTAINED_RESOURCES: { RuntimeElemContainedResources targetElem = (RuntimeElemContainedResources) target; - List values = child.getAccessor().getValues(myInstance); + List values = child.getAccessor().getValues(myInstance); ContainedDt newDt; if (values == null || values.isEmpty() || values.get(0) == null) { newDt = targetElem.newInstance(); @@ -1055,7 +1057,7 @@ class ParserState { } @Override - protected IElement getCurrentElement() { + protected IBase getCurrentElement() { return myInstance; } @@ -1096,8 +1098,8 @@ class ParserState { } case PRIMITIVE_DATATYPE: { RuntimePrimitiveDatatypeDefinition primitiveTarget = (RuntimePrimitiveDatatypeDefinition) target; - IPrimitiveDatatype newChildInstance = primitiveTarget.newInstance(); - myExtension.setValue(newChildInstance); + IPrimitiveType newChildInstance = primitiveTarget.newInstance(); + myExtension.setValue((IElement) newChildInstance); PrimitiveState newState = new PrimitiveState(getPreResourceState(), newChildInstance); push(newState); return; @@ -1166,9 +1168,9 @@ class ParserState { * Stitch together resource references */ - Map idToResource = new HashMap(); - List resources = myInstance.toListOfResources(); - for (IBaseResource next : resources) { + Map idToResource = new HashMap(); + List resources = myInstance.toListOfResources(); + for (IResource next : resources) { if (next.getId() != null && next.getId().isEmpty() == false) { idToResource.put(next.getId().toUnqualifiedVersionless().getValue(), next); } @@ -1178,7 +1180,7 @@ class ParserState { List refs = myContext.newTerser().getAllPopulatedChildElementsOfType(next, ResourceReferenceDt.class); for (ResourceReferenceDt nextRef : refs) { if (nextRef.isEmpty() == false && nextRef.getReference() != null) { - IBaseResource target = idToResource.get(nextRef.getReference().getValue()); + IResource target = idToResource.get(nextRef.getReference().getValue()); if (target != null) { nextRef.setResource(target); } @@ -1194,7 +1196,7 @@ class ParserState { private Map myContainedResources = new HashMap(); private BundleEntry myEntry; - private IBaseResource myInstance; + private IResource myInstance; private List myResourceReferences = new ArrayList(); private Class myResourceType; @@ -1241,7 +1243,7 @@ class ParserState { } RuntimeResourceDefinition def = (RuntimeResourceDefinition) definition; - myInstance = def.newInstance(); + myInstance = (IResource) def.newInstance(); if (myEntry != null) { myEntry.setResource(myInstance); } @@ -1295,13 +1297,13 @@ class ParserState { } @Override - public void acceptElement(IElement theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition theDefinition) { + public void acceptElement(IBase theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition theDefinition) { if (theElement instanceof ResourceReferenceDt) { ResourceReferenceDt nextRef = (ResourceReferenceDt) theElement; String ref = nextRef.getReference().getValue(); if (isNotBlank(ref)) { if (ref.startsWith("#")) { - IBaseResource target = myContainedResources.get(ref.substring(1)); + IResource target = (IResource) myContainedResources.get(ref.substring(1)); if (target != null) { nextRef.setResource(target); } else { @@ -1359,9 +1361,9 @@ class ParserState { } private class PrimitiveState extends BaseState { - private IPrimitiveDatatype myInstance; + private IPrimitiveType myInstance; - public PrimitiveState(PreResourceState thePreResourceState, IPrimitiveDatatype theInstance) { + public PrimitiveState(PreResourceState thePreResourceState, IPrimitiveType theInstance) { super(thePreResourceState); myInstance = theInstance; } @@ -1373,8 +1375,10 @@ class ParserState { } else if ("id".equals(theName)) { if (myInstance instanceof IIdentifiableElement) { ((IIdentifiableElement) myInstance).setElementSpecificId(theValue); + } else if (myInstance instanceof Element) { + ((Element) myInstance).setId(theValue); } else if (myInstance instanceof IBaseResource) { - ((IBaseResource) myInstance).setId(new IdDt(theValue)); + new IdDt(theValue).applyTo((org.hl7.fhir.instance.model.IBaseResource) myInstance); } } } @@ -1404,7 +1408,7 @@ class ParserState { } @Override - protected IElement getCurrentElement() { + protected IBase getCurrentElement() { return myInstance; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java index 00e47eba787..dfd4b04f11c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java @@ -20,9 +20,7 @@ package ca.uhn.fhir.parser; * #L% */ -import static org.apache.commons.lang3.StringUtils.defaultString; -import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.apache.commons.lang3.StringUtils.*; import java.io.IOException; import java.io.Reader; @@ -46,7 +44,10 @@ import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; import org.apache.commons.lang3.StringUtils; +import org.hl7.fhir.instance.model.DomainResource; +import org.hl7.fhir.instance.model.IBase; import org.hl7.fhir.instance.model.IBaseResource; +import org.hl7.fhir.instance.model.Narrative; import org.hl7.fhir.instance.model.Resource; import ca.uhn.fhir.context.BaseRuntimeChildDefinition; @@ -300,14 +301,14 @@ public class XmlParser extends BaseParser implements IParser { } @Override - public Bundle parseBundle(Class theResourceType, Reader theReader) { + public Bundle parseBundle(Class theResourceType, Reader theReader) { XMLEventReader streamReader = createStreamReader(theReader); return parseBundle(streamReader, theResourceType); } @Override - public T parseResource(Class theResourceType, Reader theReader) { + public T parseResource(Class theResourceType, Reader theReader) { XMLEventReader streamReader = createStreamReader(theReader); return parseResource(theResourceType, streamReader); @@ -423,8 +424,8 @@ public class XmlParser extends BaseParser implements IParser { } } - private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theEventWriter, IElement nextValue, String childName, - BaseRuntimeElementDefinition childDef, String theExtensionUrl, boolean theIncludedResource) throws XMLStreamException, DataFormatException { + private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, XMLStreamWriter theEventWriter, IBase nextValue, String childName, BaseRuntimeElementDefinition childDef, String theExtensionUrl, boolean theIncludedResource) + throws XMLStreamException, DataFormatException { if (nextValue.isEmpty()) { if (childDef.getChildType() == ChildTypeEnum.CONTAINED_RESOURCES && getContainedResources().isEmpty() == false && theIncludedResource == false) { // We still want to go in.. @@ -474,7 +475,7 @@ public class XmlParser extends BaseParser implements IParser { } encodeResourceToXmlStreamWriter(next, theEventWriter, true, fixContainedResourceId(next.getId().getValue())); } - for (IResource next : getContainedResources().getContainedResources()) { + for (IBaseResource next : getContainedResources().getContainedResources()) { IdDt resourceId = getContainedResources().getResourceId(next); encodeResourceToXmlStreamWriter(next, theEventWriter, true, fixContainedResourceId(resourceId.getValue())); } @@ -499,34 +500,49 @@ public class XmlParser extends BaseParser implements IParser { } - private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, XMLStreamWriter theEventWriter, - List children, boolean theIncludedResource) throws XMLStreamException, DataFormatException { + private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theElement, XMLStreamWriter theEventWriter, List children, boolean theIncludedResource) throws XMLStreamException, + DataFormatException { for (BaseRuntimeChildDefinition nextChild : children) { if (nextChild instanceof RuntimeChildNarrativeDefinition && !theIncludedResource) { INarrativeGenerator gen = myContext.getNarrativeGenerator(); - NarrativeDt narr = theResource.getText(); - if (gen != null && narr.isEmpty()) { - narr = gen.generateNarrative(theResDef.getResourceProfile(), theResource); - } - if (narr != null) { - RuntimeChildNarrativeDefinition child = (RuntimeChildNarrativeDefinition) nextChild; - String childName = nextChild.getChildNameByDatatype(child.getDatatype()); - BaseRuntimeElementDefinition type = child.getChildByName(childName); - encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, narr, childName, type, null, theIncludedResource); - continue; + if (theResource instanceof IResource) { + NarrativeDt narr = ((IResource)theResource).getText(); + if (gen != null && narr.isEmpty()) { + narr = gen.generateNarrative(theResDef.getResourceProfile(), theResource); + } + if (narr != null) { + RuntimeChildNarrativeDefinition child = (RuntimeChildNarrativeDefinition) nextChild; + String childName = nextChild.getChildNameByDatatype(child.getDatatype()); + BaseRuntimeElementDefinition type = child.getChildByName(childName); + encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, narr, childName, type, null, theIncludedResource); + continue; + } + } else { + Narrative narr1 = ((DomainResource)theResource).getText(); + NarrativeDt narr2 = null; + if (gen != null && narr1.isEmpty()) { + narr2 = gen.generateNarrative(theResDef.getResourceProfile(), theResource); + } + if (narr2 != null) { + RuntimeChildNarrativeDefinition child = (RuntimeChildNarrativeDefinition) nextChild; + String childName = nextChild.getChildNameByDatatype(child.getDatatype()); + BaseRuntimeElementDefinition type = child.getChildByName(childName); + encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, narr2, childName, type, null, theIncludedResource); + continue; + } } } - List values = nextChild.getAccessor().getValues(theElement); + List values = nextChild.getAccessor().getValues(theElement); if (values == null || values.isEmpty()) { continue; } - for (IElement nextValue : values) { + for (IBase nextValue : values) { if ((nextValue == null || nextValue.isEmpty()) && !(nextValue instanceof ContainedDt)) { continue; } - Class type = nextValue.getClass(); + Class type = nextValue.getClass(); String childName = nextChild.getChildNameByDatatype(type); String extensionUrl = nextChild.getExtensionUrl(); BaseRuntimeElementDefinition childDef = nextChild.getChildElementDefinitionByDatatype(type); @@ -559,15 +575,13 @@ public class XmlParser extends BaseParser implements IParser { } } - private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, XMLStreamWriter theEventWriter, - BaseRuntimeElementCompositeDefinition resDef, boolean theIncludedResource) throws XMLStreamException, DataFormatException { + private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theElement, XMLStreamWriter theEventWriter, BaseRuntimeElementCompositeDefinition resDef, boolean theIncludedResource) throws XMLStreamException, DataFormatException { encodeExtensionsIfPresent(theResDef, theResource, theEventWriter, theElement, theIncludedResource); encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getExtensions(), theIncludedResource); encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getChildren(), theIncludedResource); } - private void encodeExtensionsIfPresent(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theWriter, IElement theElement, boolean theIncludedResource) - throws XMLStreamException, DataFormatException { + private void encodeExtensionsIfPresent(RuntimeResourceDefinition theResDef, IBaseResource theResource, XMLStreamWriter theWriter, IBase theElement, boolean theIncludedResource) throws XMLStreamException, DataFormatException { if (theElement instanceof ISupportsUndeclaredExtensions) { ISupportsUndeclaredExtensions res = (ISupportsUndeclaredExtensions) theElement; encodeUndeclaredExtensions(theResDef, theResource, theWriter, res.getUndeclaredExtensions(), "extension", theIncludedResource); @@ -638,8 +652,7 @@ public class XmlParser extends BaseParser implements IParser { theEventWriter.writeEndElement(); } - private void encodeUndeclaredExtensions(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theWriter, List extensions, String tagName, - boolean theIncludedResource) throws XMLStreamException, DataFormatException { + private void encodeUndeclaredExtensions(RuntimeResourceDefinition theResDef, IBaseResource theResource, XMLStreamWriter theWriter, List extensions, String tagName, boolean theIncludedResource) throws XMLStreamException, DataFormatException { for (ExtensionDt next : extensions) { theWriter.writeStartElement(tagName); theWriter.writeAttribute("url", next.getUrl().getValue()); @@ -755,12 +768,12 @@ public class XmlParser extends BaseParser implements IParser { } } - private Bundle parseBundle(XMLEventReader theStreamReader, Class theResourceType) { + private Bundle parseBundle(XMLEventReader theStreamReader, Class theResourceType) { ParserState parserState = ParserState.getPreAtomInstance(myContext, theResourceType, false); return doXmlLoop(theStreamReader, parserState); } - private T parseResource(Class theResourceType, XMLEventReader theStreamReader) { + private T parseResource(Class theResourceType, XMLEventReader theStreamReader) { ParserState parserState = ParserState.getPreResourceInstance(theResourceType, myContext, false); return doXmlLoop(theStreamReader, parserState); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java index 10f8fbf96aa..db1375379dc 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java @@ -20,8 +20,7 @@ package ca.uhn.fhir.rest.client; * #L% */ -import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.apache.commons.lang3.StringUtils.*; import java.io.IOException; import java.io.Reader; @@ -36,6 +35,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpRequestBase; +import org.hl7.fhir.instance.model.IBaseResource; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; @@ -233,7 +233,7 @@ public class GenericClient extends BaseClient implements IGenericClient { } @Override - public T read(final Class theType, IdDt theId) { + public T read(final Class theType, IdDt theId) { if (theId == null || theId.hasIdPart() == false) { throw new IllegalArgumentException("theId does not contain a valid ID, is: " + theId); } @@ -254,7 +254,7 @@ public class GenericClient extends BaseClient implements IGenericClient { } @Override - public T read(Class theType, String theId) { + public T read(Class theType, String theId) { return read(theType, new IdDt(theId)); } @@ -274,7 +274,7 @@ public class GenericClient extends BaseClient implements IGenericClient { if (def == null) { throw new IllegalArgumentException(myContext.getLocalizer().getMessage(I18N_CANNOT_DETEMINE_RESOURCE_TYPE, theUrl.getValueAsString())); } - return read(def.getImplementingClass(), id); + return (IResource) read(def.getImplementingClass(), id); } @Override @@ -283,7 +283,7 @@ public class GenericClient extends BaseClient implements IGenericClient { } @Override - public Bundle search(final Class theType, Map> theParams) { + public Bundle search(final Class theType, Map> theParams) { LinkedHashMap> params = new LinkedHashMap>(); for (Entry> nextEntry : theParams.entrySet()) { ArrayList valueList = new ArrayList(); @@ -307,7 +307,7 @@ public class GenericClient extends BaseClient implements IGenericClient { } @Override - public Bundle search(final Class theType, UriDt theUrl) { + public Bundle search(final Class theType, UriDt theUrl) { BaseHttpClientInvocation invocation = new HttpGetClientInvocation(theUrl.getValueAsString()); return invokeClient(myContext, new BundleResponseHandler(theType), invocation); } @@ -317,7 +317,7 @@ public class GenericClient extends BaseClient implements IGenericClient { return search(inferResourceClass(theUrl), theUrl); } - private Class inferResourceClass(UriDt theUrl) { + private Class inferResourceClass(UriDt theUrl) { String urlString = theUrl.getValueAsString(); int i = urlString.indexOf('?'); @@ -360,7 +360,7 @@ public class GenericClient extends BaseClient implements IGenericClient { myLogRequestAndResponse = theLogRequestAndResponse; } - private String toResourceName(Class theType) { + private String toResourceName(Class theType) { return myContext.getResourceDefinition(theType).getName(); } @@ -544,9 +544,9 @@ public class GenericClient extends BaseClient implements IGenericClient { private final class BundleResponseHandler implements IClientResponseHandler { - private Class myType; + private Class myType; - public BundleResponseHandler(Class theType) { + public BundleResponseHandler(Class theType) { myType = theType; } @@ -832,7 +832,7 @@ public class GenericClient extends BaseClient implements IGenericClient { } } - private final class ResourceResponseHandler implements IClientResponseHandler { + private final class ResourceResponseHandler implements IClientResponseHandler { private IdDt myId; private Class myType; @@ -852,7 +852,7 @@ public class GenericClient extends BaseClient implements IGenericClient { T retVal = parser.parseResource(myType, theResponseReader); if (myId != null) { - retVal.setId(myId); + myId.applyTo(retVal); } MethodUtil.parseClientRequestResourceHeaders(theHeaders, retVal); @@ -869,7 +869,7 @@ public class GenericClient extends BaseClient implements IGenericClient { private Integer myParamLimit; private String myResourceId; private String myResourceName; - private Class myResourceType; + private Class myResourceType; private SearchStyleEnum mySearchStyle; private List mySort = new ArrayList(); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/IGenericClient.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/IGenericClient.java index e2d10f90a90..dd728a00352 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/IGenericClient.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/IGenericClient.java @@ -23,6 +23,8 @@ package ca.uhn.fhir.rest.client; import java.util.List; import java.util.Map; +import org.hl7.fhir.instance.model.IBaseResource; + import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.api.IResource; @@ -152,7 +154,7 @@ public interface IGenericClient { * The ID to load, including the resource ID and the resource version ID. Valid values include "Patient/123/_history/222", or "http://example.com/fhir/Patient/123/_history/222" * @return The resource */ - T read(Class theType, IdDt theId); + T read(Class theType, IdDt theId); /** * Implementation of the "instance read" method. @@ -163,7 +165,7 @@ public interface IGenericClient { * The ID to load * @return The resource */ - T read(Class theType, String theId); + T read(Class theType, String theId); /** * Perform the "read" operation (retrieve the latest version of a resource instance by ID) using an absolute URL. @@ -200,7 +202,7 @@ public interface IGenericClient { * @param theParams * @return */ - Bundle search(Class theType, Map> theParams); + Bundle search(Class theType, Map> theParams); /** * Perform the "search" operation using an absolute URL. @@ -211,7 +213,7 @@ public interface IGenericClient { * The absolute URL, e.g. "http://example.com/fhir/Patient/123" * @return The returned bundle from the server */ - Bundle search(Class theType, UriDt theUrl); + Bundle search(Class theType, UriDt theUrl); Bundle search(UriDt theUrl); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/MethodUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/MethodUtil.java index fcb8c4e7207..5e983522b2c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/MethodUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/MethodUtil.java @@ -1,7 +1,6 @@ package ca.uhn.fhir.rest.method; -import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.apache.commons.lang3.StringUtils.*; import java.io.IOException; import java.io.PushbackReader; @@ -22,6 +21,9 @@ import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; import org.apache.http.client.utils.DateUtils; +import org.hl7.fhir.instance.model.IBaseResource; +import org.hl7.fhir.instance.model.Resource; +import org.hl7.fhir.instance.model.Resource.ResourceMetaComponent; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; @@ -115,20 +117,24 @@ public class MethodUtil { } addTagsToPostOrPut(theResource, retVal); -// addContentTypeHeaderBasedOnDetectedType(retVal, theResourceBody); - + // addContentTypeHeaderBasedOnDetectedType(retVal, theResourceBody); + return retVal; } - public static void parseClientRequestResourceHeaders(Map> theHeaders, IResource resource) { + public static void parseClientRequestResourceHeaders(Map> theHeaders, IBaseResource resource) { List lmHeaders = theHeaders.get(Constants.HEADER_LAST_MODIFIED_LOWERCASE); if (lmHeaders != null && lmHeaders.size() > 0 && StringUtils.isNotBlank(lmHeaders.get(0))) { String headerValue = lmHeaders.get(0); Date headerDateValue; try { headerDateValue = DateUtils.parseDate(headerValue); - InstantDt lmValue = new InstantDt(headerDateValue); - resource.getResourceMetadata().put(ResourceMetadataKeyEnum.UPDATED, lmValue); + if (resource instanceof IResource) { + InstantDt lmValue = new InstantDt(headerDateValue); + ((IResource) resource).getResourceMetadata().put(ResourceMetadataKeyEnum.UPDATED, lmValue); + } else if (resource instanceof Resource){ + ((Resource) resource).getMeta().setLastUpdated(headerDateValue); + } } catch (Exception e) { ourLog.warn("Unable to parse date string '{}'. Error is: {}", headerValue, e.toString()); } @@ -137,7 +143,9 @@ public class MethodUtil { List clHeaders = theHeaders.get(Constants.HEADER_CONTENT_LOCATION_LC); if (clHeaders != null && clHeaders.size() > 0 && StringUtils.isNotBlank(clHeaders.get(0))) { String headerValue = clHeaders.get(0); - resource.getId().setValue(headerValue); + if (isNotBlank(headerValue)) { + new IdDt(headerValue).applyTo(resource); + } } List categoryHeaders = theHeaders.get(Constants.HEADER_CATEGORY_LC); @@ -146,7 +154,14 @@ public class MethodUtil { for (String header : categoryHeaders) { parseTagValue(tagList, header); } - ResourceMetadataKeyEnum.TAG_LIST.put(resource, tagList); + if (resource instanceof IResource) { + ResourceMetadataKeyEnum.TAG_LIST.put((IResource) resource, tagList); + } else if (resource instanceof Resource) { + ResourceMetaComponent meta = ((Resource) resource).getMeta(); + for (Tag next : tagList) { + meta.addTag().setSystem(next.getScheme()).setCode(next.getTerm()).setDisplay(next.getLabel()); + } + } } } @@ -261,8 +276,8 @@ public class MethodUtil { } addTagsToPostOrPut(theResource, retVal); -// addContentTypeHeaderBasedOnDetectedType(retVal, theResourceBody); - + // addContentTypeHeaderBasedOnDetectedType(retVal, theResourceBody); + return retVal; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ReferenceParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ReferenceParam.java index 54cc7c0ee42..fb0ab2a6ca1 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ReferenceParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ReferenceParam.java @@ -21,6 +21,9 @@ package ca.uhn.fhir.rest.param; */ import static org.apache.commons.lang3.StringUtils.*; + +import org.hl7.fhir.instance.model.IBaseResource; + import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IQueryParameterType; import ca.uhn.fhir.model.api.IResource; @@ -89,7 +92,7 @@ public class ReferenceParam extends IdDt implements IQueryParameterType { myChain = theChain; } - public Class getResourceType(FhirContext theCtx) { + public Class getResourceType(FhirContext theCtx) { if (isBlank(getResourceType())) { return null; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java index a0a4b764fd7..984e6dec40d 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java @@ -53,7 +53,7 @@ public class FhirTerser { myContext = theContext; } - private void addUndeclaredExtensions(IElement theElement, BaseRuntimeElementDefinition theDefinition, BaseRuntimeChildDefinition theChildDefinition, + private void addUndeclaredExtensions(IBase theElement, BaseRuntimeElementDefinition theDefinition, BaseRuntimeChildDefinition theChildDefinition, IModelVisitor theCallback) { if (theElement instanceof ISupportsUndeclaredExtensions) { ISupportsUndeclaredExtensions containingElement = (ISupportsUndeclaredExtensions) theElement; @@ -87,7 +87,7 @@ public class FhirTerser { visit(theResource, null, def, new IModelVisitor() { @SuppressWarnings("unchecked") @Override - public void acceptElement(IElement theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition theDefinition) { + public void acceptElement(IBase theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition theDefinition) { if (theElement == null || theElement.isEmpty()) { return; } @@ -140,13 +140,13 @@ public class FhirTerser { private List getValues(BaseRuntimeElementCompositeDefinition theCurrentDef, Object theCurrentObj, List theSubList) { String name = theSubList.get(0); BaseRuntimeChildDefinition nextDef = theCurrentDef.getChildByNameOrThrowDataFormatException(name); - List values = nextDef.getAccessor().getValues(theCurrentObj); + List values = nextDef.getAccessor().getValues(theCurrentObj); List retVal = new ArrayList(); if (theSubList.size() == 1) { retVal.addAll(values); } else { - for (IElement nextElement : values) { + for (IBase nextElement : values) { BaseRuntimeElementCompositeDefinition nextChildDef = (BaseRuntimeElementCompositeDefinition) myContext.getElementDefinition(nextElement.getClass()); List foundValues = getValues(nextChildDef, nextElement, theSubList.subList(1, theSubList.size())); retVal.addAll(foundValues); @@ -170,7 +170,7 @@ public class FhirTerser { } - private void visit(IElement theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition theDefinition, IModelVisitor theCallback) { + private void visit(IBase theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition theDefinition, IModelVisitor theCallback) { theCallback.acceptElement(theElement, theChildDefinition, theDefinition); addUndeclaredExtensions(theElement, theDefinition, theChildDefinition, theCallback); @@ -198,9 +198,9 @@ public class FhirTerser { case RESOURCE: { BaseRuntimeElementCompositeDefinition childDef = (BaseRuntimeElementCompositeDefinition) theDefinition; for (BaseRuntimeChildDefinition nextChild : childDef.getChildrenAndExtension()) { - List values = nextChild.getAccessor().getValues(theElement); + List values = nextChild.getAccessor().getValues(theElement); if (values != null) { - for (IElement nextValue : values) { + for (IBase nextValue : values) { if (nextValue == null) { continue; } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java index 47fd52f6757..f4e4eaf7fec 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java @@ -20,10 +20,11 @@ package ca.uhn.fhir.util; * #L% */ +import org.hl7.fhir.instance.model.IBase; + import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeElementDefinition; import ca.uhn.fhir.model.api.ExtensionDt; -import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.ISupportsUndeclaredExtensions; /** @@ -37,7 +38,7 @@ public interface IModelVisitor { * @param theChildDefinition May be null if this is a root element * @param theDefinition */ - void acceptElement(IElement theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition theDefinition); + void acceptElement(IBase theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition theDefinition); /** * diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/SchematronBaseValidator.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/SchematronBaseValidator.java index 3f764dff327..cb87497b6ea 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/SchematronBaseValidator.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/SchematronBaseValidator.java @@ -34,7 +34,6 @@ import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.BundleEntry; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome.BaseIssue; -import ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import com.phloc.commons.error.IResourceError; @@ -88,7 +87,7 @@ public class SchematronBaseValidator implements IValidator { private ISchematronResource getSchematron(ValidationContext theCtx) { Class resource = theCtx.getResource().getClass(); - Class baseResourceClass = theCtx.getFhirContext().getResourceDefinition(resource).getBaseDefinition().getImplementingClass(); + Class baseResourceClass = (Class) theCtx.getFhirContext().getResourceDefinition(resource).getBaseDefinition().getImplementingClass(); return getSchematronAndCache(theCtx, "dstu", baseResourceClass); } diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/IBase.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/IBase.java index 03a4ba8cc54..2ed11fcb13a 100644 --- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/IBase.java +++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/IBase.java @@ -7,4 +7,6 @@ package org.hl7.fhir.instance.model; */ public interface IBase { + boolean isEmpty(); + } diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/IPrimitiveType.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/IPrimitiveType.java index 87476ad98cc..80eb21b0820 100644 --- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/IPrimitiveType.java +++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/IPrimitiveType.java @@ -1,5 +1,14 @@ package org.hl7.fhir.instance.model; -public interface IPrimitiveType extends IBase { +public interface IPrimitiveType extends IBase { + + void setValueAsString(String theValue) throws IllegalArgumentException; + + String getValueAsString(); + + T getValue(); + + IPrimitiveType setValue(T theValue) throws IllegalArgumentException; + } diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/PrimitiveType.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/PrimitiveType.java index 3a0cbddaf57..90cb8812ac7 100644 --- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/PrimitiveType.java +++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/PrimitiveType.java @@ -3,7 +3,7 @@ package org.hl7.fhir.instance.model; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; -public abstract class PrimitiveType extends Type implements IPrimitiveType { +public abstract class PrimitiveType extends Type implements IPrimitiveType { private static final long serialVersionUID = 2L; diff --git a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java index 4b88824e4dc..2b7cfafc0d1 100644 --- a/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java +++ b/hapi-fhir-structures-dstu/src/main/java/ca/uhn/fhir/model/dstu/FhirDstu1.java @@ -36,6 +36,7 @@ import ca.uhn.fhir.model.api.ICompositeDatatype; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.WordUtils; +import org.hl7.fhir.instance.model.IBaseResource; import ca.uhn.fhir.context.BaseRuntimeElementDefinition.ChildTypeEnum; import ca.uhn.fhir.model.api.IFhirVersion; @@ -131,12 +132,13 @@ public class FhirDstu1 implements IFhirVersion { private void fillName(StructureElement elem, BaseRuntimeElementDefinition nextDef) { if (nextDef instanceof RuntimeResourceReferenceDefinition) { RuntimeResourceReferenceDefinition rr = (RuntimeResourceReferenceDefinition) nextDef; - for (Class next : rr.getResourceTypes()) { + for (Class next : rr.getResourceTypes()) { StructureElementDefinitionType type = elem.getDefinition().addType(); type.getCode().setValue("ResourceReference"); if (next != IResource.class) { - RuntimeResourceDefinition resDef = rr.getDefinitionForResourceType(next); + @SuppressWarnings("unchecked") + RuntimeResourceDefinition resDef = rr.getDefinitionForResourceType((Class) next); type.getProfile().setValueAsString(resDef.getResourceProfile()); } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/AuditingInterceptorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/AuditingInterceptorTest.java index d4161181c4d..16b08c60e4f 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/AuditingInterceptorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/AuditingInterceptorTest.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -28,7 +29,6 @@ import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; -import sun.misc.BASE64Decoder; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.base.composite.BaseCodingDt; import ca.uhn.fhir.model.base.resource.BaseSecurityEvent; @@ -114,7 +114,7 @@ public class AuditingInterceptorTest { assertEquals("Patient: PatientOne Test", object.getName().getValue()); assertEquals(SecurityEventObjectLifecycleEnum.ACCESS_OR_USE, object.getLifecycle().getValueAsEnum()); assertEquals(SecurityEventObjectTypeEnum.PERSON, object.getType().getValueAsEnum()); - assertEquals(requestURL, new String(new BASE64Decoder().decodeBuffer(object.getQuery().getValueAsString()))); + assertEquals(requestURL, new String(Base64.decodeBase64(object.getQuery().getValueAsString()))); } @@ -162,7 +162,7 @@ public class AuditingInterceptorTest { }else{ fail("Unexpected patient identifier being audited: " + object.getIdentifier().getValue().getValue()); } - assertEquals(requestURL, new String(new BASE64Decoder().decodeBuffer(object.getQuery().getValueAsString()))); + assertEquals(requestURL, new String(Base64.decodeBase64(object.getQuery().getValueAsString()))); assertEquals(SecurityEventObjectTypeEnum.PERSON, object.getType().getValueAsEnum()); } diff --git a/hapi-fhir-structures-hl7org-dev/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java b/hapi-fhir-structures-hl7org-dev/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java index 2fd3b14488e..8a838b0ae41 100644 --- a/hapi-fhir-structures-hl7org-dev/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java +++ b/hapi-fhir-structures-hl7org-dev/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java @@ -31,6 +31,7 @@ import org.hamcrest.core.IsNot; import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; import org.hl7.fhir.instance.model.List_; +import org.hl7.fhir.instance.model.Narrative.NarrativeStatus; import org.hl7.fhir.instance.model.Organization; import org.hl7.fhir.instance.model.Patient; import org.hl7.fhir.instance.model.Profile; @@ -710,7 +711,7 @@ public class XmlParserTest { Patient patient = ourCtx.newXmlParser().parse(Patient.class, msg); - assertEquals(NarrativeStatusEnum.GENERATED, patient.getText().getStatus().getValueAsEnum()); + assertEquals(NarrativeStatus.GENERATED, patient.getText().getStatus()); assertEquals("
John Cardinal: 444333333
", patient.getText().getDiv().getValueAsString()); assertEquals("PRP1660", patient.getIdentifier().get(0).getValue().getValueAsString());