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 0beae3a5f75..191bebbf9ca 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 @@ -156,8 +156,11 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD RuntimeResourceReferenceDefinition def = new RuntimeResourceReferenceDefinition(value, types); def.sealAndInitialize(theContext, theClassToElementDefinitions); myAttributeNameToDefinition.put(value, def); + myDatatypeToDefinition.put(BaseResourceReferenceDt.class, def); - myDatatypeToDefinition.put(theContext.getVersion().getResourceReferenceType(), def); + + Class versionReferenceType = theContext.getVersion().getResourceReferenceType(); + myDatatypeToDefinition.put(versionReferenceType, def); } public static String createExtensionChildName(BaseRuntimeElementDefinition next) { 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 79c3a32dcec..f16e39dcb27 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 @@ -678,7 +678,7 @@ public class JsonParser extends BaseParser implements IParser { } } else if (theResource instanceof IAnyResource) { IAnyResource res = (IAnyResource) theResource; - if (theContainedResource && StringUtils.isNotBlank(res.getId().getIdPart())) { + if (/*theContainedResource && */ StringUtils.isNotBlank(res.getId().getIdPart())) { resourceId = res.getId().getIdPart(); } } 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 a2b83d03ab7..3ead311a1cf 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 @@ -1959,8 +1959,10 @@ class ParserState { IDomainResource elem = (IDomainResource) getCurrentElement(); String resourceName = myContext.getResourceDefinition(elem).getName(); String versionId = elem.getMeta().getVersionId(); - if (StringUtils.isNotBlank(versionId)) { - elem.getIdElement().setValue(resourceName + "/" + elem.getId().getIdPart() + "/_history/" + versionId); + if (StringUtils.isBlank(elem.getId().getIdPart())) { + // nothing + } else if (StringUtils.isNotBlank(versionId)) { + elem.getIdElement().setValue(resourceName + "/" + elem.getId().getIdPart() + "/_history/" + versionId); } else { elem.getIdElement().setValue(resourceName + "/" + elem.getId().getIdPart()); } 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 996e6f7dfb3..af18a227d13 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 @@ -35,7 +35,7 @@ import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.client.api.IRestfulClient; import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException; -import ca.uhn.fhir.rest.client.exceptions.FhirClientInnapropriateForServerException; +import ca.uhn.fhir.rest.client.exceptions.FhirClientInappropriateForServerException; import ca.uhn.fhir.rest.gclient.ICreate; import ca.uhn.fhir.rest.gclient.IDelete; import ca.uhn.fhir.rest.gclient.IFetchConformanceUntyped; @@ -116,7 +116,7 @@ public interface IGenericClient extends IRestfulClient { * * @throws FhirClientConnectionException * if the conformance statement cannot be read, or if the client - * @throws FhirClientInnapropriateForServerException + * @throws FhirClientInappropriateForServerException * If the conformance statement indicates that the server is inappropriate for this client (e.g. it implements the wrong version of FHIR) */ void forceConformanceCheck() throws FhirClientConnectionException; diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/RestfulClientFactory.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/RestfulClientFactory.java index d113e2f16ec..35f89be3518 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/RestfulClientFactory.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/RestfulClientFactory.java @@ -51,7 +51,7 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.rest.client.api.IRestfulClient; import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException; -import ca.uhn.fhir.rest.client.exceptions.FhirClientInnapropriateForServerException; +import ca.uhn.fhir.rest.client.exceptions.FhirClientInappropriateForServerException; import ca.uhn.fhir.rest.method.BaseMethodBinding; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.util.FhirTerser; @@ -316,7 +316,7 @@ public class RestfulClientFactory implements IRestfulClientFactory { if (serverFhirVersionEnum != null) { FhirVersionEnum contextFhirVersion = myContext.getVersion().getVersion(); if (!contextFhirVersion.isEquivalentTo(serverFhirVersionEnum)) { - throw new FhirClientInnapropriateForServerException(myContext.getLocalizer().getMessage(RestfulClientFactory.class, "wrongVersionInConformance", theServerBase + Constants.URL_TOKEN_METADATA, serverFhirVersionString, serverFhirVersionEnum, contextFhirVersion)); + throw new FhirClientInappropriateForServerException(myContext.getLocalizer().getMessage(RestfulClientFactory.class, "wrongVersionInConformance", theServerBase + Constants.URL_TOKEN_METADATA, serverFhirVersionString, serverFhirVersionEnum, contextFhirVersion)); } } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/exceptions/FhirClientInnapropriateForServerException.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/exceptions/FhirClientInappropriateForServerException.java similarity index 82% rename from hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/exceptions/FhirClientInnapropriateForServerException.java rename to hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/exceptions/FhirClientInappropriateForServerException.java index 1e59d6dc0d9..c3bbd991acb 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/exceptions/FhirClientInnapropriateForServerException.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/exceptions/FhirClientInappropriateForServerException.java @@ -27,19 +27,19 @@ import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; * communicate with a server which is a valid FHIR server but is incompatible * with this client for some reason. */ -public class FhirClientInnapropriateForServerException extends BaseServerResponseException { +public class FhirClientInappropriateForServerException extends BaseServerResponseException { private static final long serialVersionUID = 1L; - public FhirClientInnapropriateForServerException(Throwable theCause) { + public FhirClientInappropriateForServerException(Throwable theCause) { super(0, theCause); } - public FhirClientInnapropriateForServerException(String theMessage, Throwable theCause) { + public FhirClientInappropriateForServerException(String theMessage, Throwable theCause) { super(0, theMessage, theCause); } - public FhirClientInnapropriateForServerException(String theMessage) { + public FhirClientInappropriateForServerException(String theMessage) { super(0, theMessage); } 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 8e401dbe271..1eba46015aa 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 @@ -127,8 +127,8 @@ public class FhirTerser { if (theElement == null || theElement.isEmpty()) { return; } - if (BaseResourceReferenceDt.class.isAssignableFrom(theElement.getClass())) { - retVal.add(new ResourceReferenceInfo(theResource, thePathToElement, (BaseResourceReferenceDt)theElement)); + if (IReference.class.isAssignableFrom(theElement.getClass())) { + retVal.add(new ResourceReferenceInfo(myContext, theResource, thePathToElement, (IReference)theElement)); } } @@ -136,7 +136,7 @@ public class FhirTerser { public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition theDefinition, ExtensionDt theNextExt) { if (theNextExt.getValue() != null && BaseResourceReferenceDt.class.isAssignableFrom(theNextExt.getValue().getClass())) { - retVal.add(new ResourceReferenceInfo(theResource, thePathToElement, (BaseResourceReferenceDt)theNextExt.getValue())); + retVal.add(new ResourceReferenceInfo(myContext, theResource, thePathToElement, (BaseResourceReferenceDt)theNextExt.getValue())); } } }); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java index fd50f9f5a81..1b49c0c32b4 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java @@ -20,79 +20,82 @@ package ca.uhn.fhir.util; * #L% */ -import ca.uhn.fhir.model.api.Include; -import ca.uhn.fhir.model.api.annotation.ResourceDef; -import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt; +import java.util.Iterator; +import java.util.List; +import java.util.Set; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import org.hl7.fhir.instance.model.IBaseResource; +import org.hl7.fhir.instance.model.api.IReference; -import java.util.Iterator; -import java.util.List; -import java.util.Set; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.Include; +import ca.uhn.fhir.model.api.annotation.ResourceDef; /** * Created by Bill de Beaubien on 2/26/2015. */ public class ResourceReferenceInfo { - private String myOwningResource; - private String myName; - private BaseResourceReferenceDt myResource; + private String myOwningResource; + private String myName; + private IReference myResource; - public ResourceReferenceInfo(IBaseResource theOwningResource, List thePathToElement, BaseResourceReferenceDt theResource) { - myOwningResource = theOwningResource.getClass().getAnnotation(ResourceDef.class).name(); - myResource = theResource; - if (thePathToElement != null && !thePathToElement.isEmpty()) { - StringBuilder sb = new StringBuilder(); - thePathToElement.iterator(); - for (Iterator iterator = thePathToElement.iterator(); iterator.hasNext(); ) { - sb.append(iterator.next()); - if (iterator.hasNext()) - sb.append("."); - } - myName = sb.toString(); - } else { - myName = null; - } - } + public ResourceReferenceInfo(FhirContext theContext, IBaseResource theOwningResource, List thePathToElement, IReference theElement) { - @Override - public String toString() { - ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); - b.append("name", myName); - b.append("resource", myResource.getReference()); - return b.build(); - } + myOwningResource = theContext.getResourceDefinition(theOwningResource).getName(); - public String getName() { - return myName; - } + myResource = theElement; + if (thePathToElement != null && !thePathToElement.isEmpty()) { + StringBuilder sb = new StringBuilder(); + thePathToElement.iterator(); + for (Iterator iterator = thePathToElement.iterator(); iterator.hasNext();) { + sb.append(iterator.next()); + if (iterator.hasNext()) + sb.append("."); + } + myName = sb.toString(); + } else { + myName = null; + } + } - public BaseResourceReferenceDt getResourceReference() { - return myResource; - } + @Override + public String toString() { + ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); + b.append("name", myName); + b.append("resource", myResource.getReference()); + return b.build(); + } - public boolean matchesIncludeSet(Set theIncludes) { - if (theIncludes == null) - return false; - for (Include include : theIncludes) { - if (matchesInclude(include)) - return true; - } - return false; - } + public String getName() { + return myName; + } - public boolean matchesInclude(Include theInclude) { - if (theInclude.getValue().equals("*")) { - return true; - } - if (theInclude.getValue().indexOf(':') != -1) { - // DSTU2 style - return (theInclude.getValue().equals(myOwningResource + ':' + myName)); - } else { - // DSTU1 style - return (theInclude.getValue().equals(myOwningResource + '.' + myName)); - } - } + public IReference getResourceReference() { + return myResource; + } + + public boolean matchesIncludeSet(Set theIncludes) { + if (theIncludes == null) + return false; + for (Include include : theIncludes) { + if (matchesInclude(include)) + return true; + } + return false; + } + + public boolean matchesInclude(Include theInclude) { + if (theInclude.getValue().equals("*")) { + return true; + } + if (theInclude.getValue().indexOf(':') != -1) { + // DSTU2 style + return (theInclude.getValue().equals(myOwningResource + ':' + myName)); + } else { + // DSTU1 style + return (theInclude.getValue().equals(myOwningResource + '.' + myName)); + } + } } diff --git a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IReference.java b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IReference.java index 8ce216dcfd3..82996234c76 100644 --- a/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IReference.java +++ b/hapi-fhir-base/src/main/java/org/hl7/fhir/instance/model/api/IReference.java @@ -22,9 +22,10 @@ package org.hl7.fhir.instance.model.api; import org.hl7.fhir.instance.model.IBase; import org.hl7.fhir.instance.model.IBaseResource; +import org.hl7.fhir.instance.model.ICompositeType; import org.hl7.fhir.instance.model.IPrimitiveType; -public interface IReference extends IBase { +public interface IReference extends ICompositeType { IBaseResource getResource(); diff --git a/hapi-fhir-structures-hl7org-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2hl7org/Dstu2Hl7OrgBundleFactory.java b/hapi-fhir-structures-hl7org-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2hl7org/Dstu2Hl7OrgBundleFactory.java index 058c49ed5ff..385070c4e89 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2hl7org/Dstu2Hl7OrgBundleFactory.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/main/java/ca/uhn/fhir/rest/server/provider/dstu2hl7org/Dstu2Hl7OrgBundleFactory.java @@ -99,15 +99,15 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { } } - List references = myContext.newTerser().getAllResourceReferences(next); + List references = myContext.newTerser().getAllResourceReferences(next); do { List addedResourcesThisPass = new ArrayList(); - for (ResourceReferenceInfo nextRefInfo : references) { - if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes)) - continue; + for (ResourceReferenceInfo nextRefInfo : references) { + if (!theBundleInclusionRule.shouldIncludeReferencedResource(nextRefInfo, theIncludes)) + continue; - IBaseResource nextRes = (IBaseResource) nextRefInfo.getResourceReference().getResource(); + IBaseResource nextRes = (IBaseResource) nextRefInfo.getResourceReference().getResource(); if (nextRes != null) { if (nextRes.getId().hasIdPart()) { if (containedIds.contains(nextRes.getId().getValue())) { @@ -130,22 +130,22 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { } } - includedResources.addAll(addedResourcesThisPass); + includedResources.addAll(addedResourcesThisPass); // Linked resources may themselves have linked resources - references = new ArrayList(); + references = new ArrayList(); for (IBaseResource iResource : addedResourcesThisPass) { - List newReferences = myContext.newTerser().getAllResourceReferences(iResource); + List newReferences = myContext.newTerser().getAllResourceReferences(iResource); references.addAll(newReferences); } } while (references.isEmpty() == false); BundleEntryComponent entry = myBundle.addEntry().setResource((Resource) next); - -// BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(next); -// if (searchMode != null) { -// entry.getSearch().getModeElement().setValue(searchMode.getCode()); -// } + + // BundleEntrySearchModeEnum searchMode = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(next); + // if (searchMode != null) { + // entry.getSearch().getModeElement().setValue(searchMode.getCode()); + // } } /* @@ -157,7 +157,7 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { } - @Override + @Override public void addRootPropertiesToBundle(String theAuthor, String theServerBase, String theCompleteUrl, Integer theTotalResults, BundleTypeEnum theBundleType) { if (myBundle.getId().isEmpty()) { @@ -194,7 +194,8 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { } @Override - public void initializeBundleFromBundleProvider(RestfulServer theServer, IBundleProvider theResult, EncodingEnum theResponseEncoding, String theServerBase, String theCompleteUrl, boolean thePrettyPrint, int theOffset, Integer theLimit, String theSearchId, BundleTypeEnum theBundleType, Set theIncludes) { + public void initializeBundleFromBundleProvider(RestfulServer theServer, IBundleProvider theResult, EncodingEnum theResponseEncoding, String theServerBase, String theCompleteUrl, + boolean thePrettyPrint, int theOffset, Integer theLimit, String theSearchId, BundleTypeEnum theBundleType, Set theIncludes) { int numToReturn; String searchId = null; List resourceList; @@ -252,11 +253,13 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { if (searchId != null) { if (theOffset + numToReturn < theResult.size()) { - myBundle.addLink().setRelation(Constants.LINK_NEXT).setUrl(RestfulServerUtils.createPagingLink(theIncludes, theServerBase, searchId, theOffset + numToReturn, numToReturn, theResponseEncoding, thePrettyPrint)); + myBundle.addLink().setRelation(Constants.LINK_NEXT) + .setUrl(RestfulServerUtils.createPagingLink(theIncludes, theServerBase, searchId, theOffset + numToReturn, numToReturn, theResponseEncoding, thePrettyPrint)); } if (theOffset > 0) { int start = Math.max(0, theOffset - limit); - myBundle.addLink().setRelation(Constants.LINK_PREVIOUS).setUrl(RestfulServerUtils.createPagingLink(theIncludes, theServerBase, searchId, start, limit, theResponseEncoding, thePrettyPrint)); + myBundle.addLink().setRelation(Constants.LINK_PREVIOUS) + .setUrl(RestfulServerUtils.createPagingLink(theIncludes, theServerBase, searchId, start, limit, theResponseEncoding, thePrettyPrint)); } } } @@ -273,7 +276,8 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { } @Override - public void initializeBundleFromResourceList(String theAuthor, List theResources, String theServerBase, String theCompleteUrl, int theTotalResults, BundleTypeEnum theBundleType) { + public void initializeBundleFromResourceList(String theAuthor, List theResources, String theServerBase, String theCompleteUrl, int theTotalResults, + BundleTypeEnum theBundleType) { myBundle = new Bundle(); myBundle.setId(UUID.randomUUID().toString()); @@ -286,7 +290,7 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { if (theBundleType.equals(BundleTypeEnum.TRANSACTION)) { for (IBaseResource nextBaseRes : theResources) { - IBaseResource next = (IBaseResource)nextBaseRes; + IBaseResource next = (IBaseResource) nextBaseRes; BundleEntryComponent nextEntry = myBundle.addEntry(); nextEntry.setResource((Resource) next); @@ -309,7 +313,7 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { myBundle.getTotalElement().setValue(theTotalResults); } - private void addResourcesForSearch(List theResult) { + private void addResourcesForSearch(List theResult) { List includedResources = new ArrayList(); Set addedResourceIds = new HashSet(); @@ -320,7 +324,7 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { } for (IBaseResource nextBaseRes : theResult) { - IDomainResource next = (IDomainResource)nextBaseRes; + IDomainResource next = (IDomainResource) nextBaseRes; Set containedIds = new HashSet(); for (IBaseResource nextContained : next.getContained()) { if (nextContained.getId().isEmpty() == false) { @@ -388,7 +392,7 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory { public List toListOfResources() { ArrayList retVal = new ArrayList(); for (BundleEntryComponent next : myBundle.getEntry()) { - if (next.getResource()!=null) { + if (next.getResource() != null) { retVal.add(next.getResource()); } else if (next.getTransactionResponse().getLocationElement().isEmpty() == false) { IdType id = new IdType(next.getTransactionResponse().getLocation()); diff --git a/hapi-fhir-structures-hl7org-dstu2/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java b/hapi-fhir-structures-hl7org-dstu2/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java index 7c939e2f81f..c33c99a3f2d 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlNode.java @@ -85,6 +85,9 @@ public class XhtmlNode implements IBaseXhtml { } public List getChildNodes() { + if (childNodes == null) { + childNodes = new ArrayList(); + } return childNodes; } diff --git a/hapi-fhir-structures-hl7org-dstu2/src/main/resources/org/hl7/fhir/instance/model/fhirversion.properties b/hapi-fhir-structures-hl7org-dstu2/src/main/resources/org/hl7/fhir/instance/model/fhirversion.properties index 9bf9713e1c6..6efb37a6114 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/main/resources/org/hl7/fhir/instance/model/fhirversion.properties +++ b/hapi-fhir-structures-hl7org-dstu2/src/main/resources/org/hl7/fhir/instance/model/fhirversion.properties @@ -92,8 +92,8 @@ resource.Supply=org.hl7.fhir.instance.model.Supply resource.ValueSet=org.hl7.fhir.instance.model.ValueSet resource.VisionPrescription=org.hl7.fhir.instance.model.VisionPrescription -datatype.Address=org.hl7.fhir.instance.model.AddressType -datatype.Attachment=org.hl7.fhir.instance.model.AttachmentType +datatype.Address=org.hl7.fhir.instance.model.Address +datatype.Attachment=org.hl7.fhir.instance.model.Attachment datatype.CodeableConcept=org.hl7.fhir.instance.model.CodeableConceptType datatype.Coding=org.hl7.fhir.instance.model.CodingType datatype.ContactPoint=org.hl7.fhir.instance.model.ContactPointType @@ -125,3 +125,4 @@ datatype.time=org.hl7.fhir.instance.model.TimeType datatype.unsignedInt=org.hl7.fhir.instance.model.UnsignedIntType datatype.uri=org.hl7.fhir.instance.model.UriType datatype.xhtml=org.hl7.fhir.instance.model.XhtmlType +datatype.reference=org.hl7.fhir.instance.model.Reference \ No newline at end of file diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java index 43272aa0daf..266c4305b7b 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java @@ -3,7 +3,9 @@ package ca.uhn.fhir.parser; import static org.junit.Assert.*; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.UUID; import org.hl7.fhir.instance.model.CodeableConcept; @@ -29,7 +31,11 @@ import org.slf4j.LoggerFactory; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.api.Include; +import ca.uhn.fhir.model.valueset.BundleTypeEnum; +import ca.uhn.fhir.rest.server.BundleInclusionRule; import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.rest.server.provider.dstu2hl7org.Dstu2Hl7OrgBundleFactory; /** * Initially contributed by Alexander Kley for bug #29 @@ -38,26 +44,26 @@ public class ContainedResourceEncodingTest { private static Logger logger = LoggerFactory.getLogger(ContainedResourceEncodingTest.class); - private FhirContext ctx; - - private Composition comp; + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ContainedResourceEncodingTest.class); private Practitioner author; - private Patient patient; + private Composition comp; + + private FhirContext ctx; private final String patFamName1 = "FirstFamilyName"; private final String patGivName1 = "FirstGivenName"; - @Before - public void initTest() { - logger.info("[initTest]"); + private Patient patient; - initPatient(); - initAuthor(); - initComposition(); - this.ctx = new FhirContext(); + private void initAuthor() { + this.author = new Practitioner(); + this.author.setId((UUID.randomUUID().toString())); + this.author.addIdentifier().setSystem("DoctorID").setValue("4711"); + this.author.addPractitionerRole().getRole().addCoding().setCode("doctor"); + this.author.setName(new HumanName().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); } @@ -99,40 +105,109 @@ public class ContainedResourceEncodingTest { } - private void initAuthor() { - this.author = new Practitioner(); - this.author.setId((UUID.randomUUID().toString())); - this.author.addIdentifier().setSystem("DoctorID").setValue("4711"); - this.author.addPractitionerRole().getRole().addCoding().setCode("doctor"); - this.author.setName(new HumanName().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); + @Before + public void initTest() { + logger.info("[initTest]"); + + initPatient(); + initAuthor(); + initComposition(); + this.ctx = new FhirContext(); } @Test - public void testPatient() { - logger.debug("[xmlEncoding] encode resource to xml."); + public void testBundleWithContained() { - /** - * This works fine, although patient instance is modifing from encoder - */ - final String expectedPatientXml = this.ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(this.patient); - logger.debug("[xmlEncoding] first encoding: {}", expectedPatientXml); - final String actualPatientXml = this.ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(this.patient); - // second encoding - xml is corrupt - i.e.: patient content 4 times! should be the same as after first encoding! - logger.debug("[xmlEncoding] second encoding: {}", actualPatientXml); + DiagnosticReport dr = new DiagnosticReport(); + dr.setId(("123")); - Assert.assertEquals(expectedPatientXml.length(), actualPatientXml.length()); - Assert.assertArrayEquals(expectedPatientXml.getBytes(), actualPatientXml.getBytes()); + Observation observation = new Observation(); + + CodeableConcept obsName = new CodeableConcept(); + obsName.setText("name"); + observation.setCode(obsName); + + Reference result = dr.addResult(); + result.setResource(observation); + + ArrayList performers = new ArrayList(); + Reference performer = new Reference(); + + Practitioner p = new Practitioner(); + p.setId((UUID.randomUUID().toString())); + p.addIdentifier().setSystem("DoctorID").setValue("4711"); + p.addPractitionerRole().getRole().setText("Doctor"); + p.setName(new HumanName().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); + + performer.setResource(p); + performers.add(performer); + observation.getPerformer().addAll(performers); + + List list = new ArrayList(); + list.add(dr); + + Dstu2Hl7OrgBundleFactory builder = new Dstu2Hl7OrgBundleFactory(ctx); + Set inc2 = Collections.emptySet(); + builder.addResourcesToBundle(list, BundleTypeEnum.TRANSACTION, "http://foo", BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE, inc2); + IBaseResource bundle = builder.getResourceBundle(); + + IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); + String xml = parser.encodeResourceToString(bundle); + ourLog.info(xml); + Assert.assertTrue(xml.contains("Mueller")); } - + + @Test + public void testBundleWithContainedWithNoIdDt() { + + DiagnosticReport dr = new DiagnosticReport(); + dr.setId("123"); + + Observation observation = new Observation(); + + CodeableConcept obsName = new CodeableConcept(); + obsName.setText("name"); + observation.setCode(obsName); + + Reference result = dr.addResult(); + result.setResource(observation); + + ArrayList performers = new ArrayList(); + Reference performer = new Reference(); + + Practitioner p = new Practitioner(); + // no idDt on practitioner p + p.addIdentifier().setSystem("DoctorID").setValue("4711"); + p.addPractitionerRole().getRole().setText("Doctor"); + p.setName(new HumanName().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); + + performer.setResource(p); + performers.add(performer); + observation.getPerformer().addAll(performers); + + List list = new ArrayList(); + list.add(dr); + + Dstu2Hl7OrgBundleFactory builder = new Dstu2Hl7OrgBundleFactory(ctx); + Set inc2 = Collections.emptySet(); + builder.addResourcesToBundle(list, BundleTypeEnum.TRANSACTION, "http://foo", BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE, inc2); + IBaseResource bundle = builder.getResourceBundle(); + + IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); + String xml = parser.encodeResourceToString(bundle); + Assert.assertTrue(xml.contains("Mueller")); + + } + @Test public void testComposition() { IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); - + assertEquals(0, this.comp.getContained().size()); - + /** * This doesn't works, secund encoding creates corrupt xml */ @@ -161,84 +236,23 @@ public class ContainedResourceEncodingTest { Assert.assertArrayEquals(expectedCompXml.getBytes(), actualCompXml.getBytes()); } - - + @Test - public void testBundleWithContained() { - - DiagnosticReport dr = new DiagnosticReport(); - dr.setId(("123")); - - Observation observation = new Observation(); - - CodeableConcept obsName = new CodeableConcept(); - obsName.setText("name"); - observation.setCode(obsName); + public void testPatient() { + logger.debug("[xmlEncoding] encode resource to xml."); - Reference result = dr.addResult(); - result.setResource(observation); + /** + * This works fine, although patient instance is modifing from encoder + */ + final String expectedPatientXml = this.ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(this.patient); + logger.debug("[xmlEncoding] first encoding: {}", expectedPatientXml); + final String actualPatientXml = this.ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(this.patient); + // second encoding - xml is corrupt - i.e.: patient content 4 times! should be the same as after first encoding! + logger.debug("[xmlEncoding] second encoding: {}", actualPatientXml); - ArrayList performers = new ArrayList(); - Reference performer = new Reference(); - - Practitioner p = new Practitioner(); - p.setId((UUID.randomUUID().toString())); - p.addIdentifier().setSystem("DoctorID").setValue("4711"); - p.addPractitionerRole().getRole().setText("Doctor"); - p.setName(new HumanName().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); - - performer.setResource(p); - performers.add(performer); - observation.getPerformer().addAll(performers); - - - List list = new ArrayList(); - list.add(dr); - Bundle bundle = null; // RestfulServer.createBundleFromResourceList(new FhirContext(), null, list, null, null, 0); - - IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); - String xml = parser.encodeBundleToString(bundle); - Assert.assertTrue(xml.contains("Mueller")); - - } - - @Test - public void testBundleWithContainedWithNoIdDt() { - - DiagnosticReport dr = new DiagnosticReport(); - dr.setId("123"); - - Observation observation = new Observation(); - - CodeableConcept obsName = new CodeableConcept(); - obsName.setText("name"); - observation.setCode(obsName); + Assert.assertEquals(expectedPatientXml.length(), actualPatientXml.length()); + Assert.assertArrayEquals(expectedPatientXml.getBytes(), actualPatientXml.getBytes()); - Reference result = dr.addResult(); - result.setResource(observation); - - ArrayList performers = new ArrayList(); - Reference performer = new Reference(); - - Practitioner p = new Practitioner(); - // no idDt on practitioner p - p.addIdentifier().setSystem("DoctorID").setValue("4711"); - p.addPractitionerRole().getRole().setText("Doctor"); - p.setName(new HumanName().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); - - performer.setResource(p); - performers.add(performer); - observation.getPerformer().addAll(performers); - - - List list = new ArrayList(); - list.add(dr); - Bundle bundle = null; // RestfulServer.createBundleFromResourceList(new FhirContext(), null, list, null, null, 0); - - IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); - String xml = parser.encodeBundleToString(bundle); - Assert.assertTrue(xml.contains("Mueller")); - } } diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgTest.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgTest.java index 6f9539ba901..e6190feafeb 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgTest.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgTest.java @@ -595,7 +595,7 @@ public class JsonParserHl7OrgTest { String val = parser.encodeResourceToString(patient); ourLog.info(val); - assertThat(val, StringContains.containsString("\"extension\":[{\"url\":\"urn:foo\",\"valueResource\":{\"reference\":\"Organization/123\"}}]")); + assertThat(val, StringContains.containsString("\"extension\":[{\"url\":\"urn:foo\",\"valueReference\":{\"reference\":\"Organization/123\"}}]")); Patient actual = parser.parseResource(Patient.class, val); assertEquals(AddressUse.HOME, patient.getAddress().get(0).getUse()); @@ -664,7 +664,7 @@ public class JsonParserHl7OrgTest { out = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b); ourLog.info(out); // Backslashes need to be escaped because they are in a JSON value - assertThat(out, containsString("
hello
")); + assertThat(out, containsString("hello")); } diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java index c991ce59458..7694b54b4b5 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java @@ -484,7 +484,7 @@ public class XmlParserHl7OrgDstu2Test { public void testParseNarrative() throws Exception { //@formatter:off String htmlNoNs = "
AAABBBCCC
"; - String htmlNs = htmlNoNs.replace("
", "
"); + String htmlNs = fixDivNodeText(htmlNoNs); String res= "\n" + " \n" + " \n" + @@ -494,7 +494,14 @@ public class XmlParserHl7OrgDstu2Test { //@formatter:on Patient p = ourCtx.newXmlParser().parseResource(Patient.class, res); - assertEquals(htmlNoNs, p.getText().getDivAsString()); + assertEquals(htmlNs, p.getText().getDivAsString()); + } + + private String fixDivNodeText(String htmlNoNs) { + return htmlNoNs.replace("
", "
"); + } + private String fixDivNodeTextJson(String htmlNoNs) { + return htmlNoNs.replace("
", "
"); } @Test @@ -841,7 +848,7 @@ public class XmlParserHl7OrgDstu2Test { String val = parser.encodeResourceToString(patient); ourLog.info(val); - assertThat(val, StringContains.containsString("")); + assertThat(val, StringContains.containsString("")); Patient actual = parser.parseResource(Patient.class, val); assertEquals(AddressUse.HOME, patient.getAddress().get(0).getUse()); @@ -1062,7 +1069,7 @@ public class XmlParserHl7OrgDstu2Test { Patient patient = ourCtx.newXmlParser().parseResource(Patient.class, msg); assertEquals(NarrativeStatus.GENERATED, patient.getText().getStatus()); - assertEquals("
John Cardinal: 444333333
", patient.getText().getDiv().getValueAsString()); + assertEquals("
John Cardinal: 444333333
", patient.getText().getDiv().getValueAsString()); assertEquals("PRP1660", patient.getIdentifier().get(0).getValue()); String encoded = ourCtx.newXmlParser().encodeResourceToString(patient); @@ -1197,6 +1204,9 @@ public class XmlParserHl7OrgDstu2Test { Patient patient1 = ourCtx.newXmlParser().parseResource(Patient.class, msg); String encoded1 = ourCtx.newXmlParser().encodeResourceToString(patient1); + ourLog.info("Expected: {}", msg); + ourLog.info("Actual: {}", encoded1); + Diff d = new Diff(new StringReader(msg), new StringReader(encoded1)); assertTrue(d.toString(), d.identical()); @@ -1492,8 +1502,8 @@ public class XmlParserHl7OrgDstu2Test { JSON actual = JSONSerializer.toJSON(encoded.trim()); // The encoded escapes quote marks using XML escaping instead of JSON escaping, which is probably nicer anyhow... - String exp = expected.toString().replace("\\\"Jim\\\"", ""Jim""); - String act = actual.toString(); + String exp = fixDivNodeTextJson(expected.toString().replace("\\\"Jim\\\"", ""Jim"")); + String act = fixDivNodeTextJson(actual.toString()); ourLog.info("Expected: {}", exp); ourLog.info("Actual : {}", act); diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestDstu2.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestDstu2.java index 411ece75277..ae2f82f522f 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestDstu2.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestDstu2.java @@ -34,6 +34,7 @@ import org.mockito.stubbing.Answer; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException; +import ca.uhn.fhir.rest.client.exceptions.FhirClientInappropriateForServerException; import ca.uhn.fhir.rest.server.Constants; public class ClientServerValidationTestDstu2 { @@ -146,7 +147,7 @@ public class ClientServerValidationTestDstu2 { try { myCtx.newRestfulGenericClient("http://foo").read(new UriDt("http://foo/Patient/123")); fail(); - } catch (FhirClientConnectionException e) { + } catch (FhirClientInappropriateForServerException e) { String out = e.toString(); String want = "The server at base URL \"http://foo/metadata\" returned a conformance statement indicating that it supports FHIR version \"0.80\" which corresponds to DSTU1, but this client is configured to use DSTU2_HL7ORG (via the FhirContext)"; ourLog.info(out);