Remove DSTU1 Bundle
This commit is contained in:
parent
c52cacf71b
commit
92224c2532
|
@ -14,11 +14,11 @@ public class FhirContextIntro {
|
|||
@SuppressWarnings("unused")
|
||||
public static void creatingContext() {
|
||||
// START SNIPPET: creatingContext
|
||||
// Create a context for DSTU1
|
||||
FhirContext ctx = FhirContext.forDstu1();
|
||||
|
||||
// Alternately, create a context for DSTU2
|
||||
// Create a context for DSTU2
|
||||
FhirContext ctxDstu2 = FhirContext.forDstu2();
|
||||
|
||||
// Alternately, create a context for R4
|
||||
FhirContext ctxR4 = FhirContext.forR4();
|
||||
// END SNIPPET: creatingContext
|
||||
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ System.out.println(encoded);
|
|||
|
||||
|
||||
public static void parseMsg() {
|
||||
FhirContext ctx = FhirContext.forDstu1();
|
||||
FhirContext ctx = FhirContext.forR4();
|
||||
|
||||
//START SNIPPET: parseMsg
|
||||
// The following is an example Patient resource
|
||||
|
|
|
@ -144,8 +144,6 @@ public class FhirContext {
|
|||
throw new IllegalStateException(getLocalizer().getMessage(FhirContext.class, "noStructuresForSpecifiedVersion", theVersion.name()));
|
||||
}
|
||||
myVersion = theVersion.getVersionImplementation();
|
||||
} else if (FhirVersionEnum.DSTU1.isPresentOnClasspath()) {
|
||||
myVersion = FhirVersionEnum.DSTU1.getVersionImplementation();
|
||||
} else if (FhirVersionEnum.DSTU2.isPresentOnClasspath()) {
|
||||
myVersion = FhirVersionEnum.DSTU2.getVersionImplementation();
|
||||
} else if (FhirVersionEnum.DSTU2_HL7ORG.isPresentOnClasspath()) {
|
||||
|
@ -848,13 +846,6 @@ public class FhirContext {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new FhirContext with version {@link FhirVersionEnum#DSTU1 DSTU1}
|
||||
*/
|
||||
public static FhirContext forDstu1() {
|
||||
return new FhirContext(FhirVersionEnum.DSTU1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new FhirContext with version {@link FhirVersionEnum#DSTU2 DSTU2}
|
||||
*/
|
||||
|
|
|
@ -34,8 +34,6 @@ public enum FhirVersionEnum {
|
|||
* ***********************
|
||||
*/
|
||||
|
||||
DSTU1("ca.uhn.fhir.model.dstu.FhirDstu1", null, false, new Version("0.0.82")),
|
||||
|
||||
DSTU2("ca.uhn.fhir.model.dstu2.FhirDstu2", null, false, new Version("1.0.2")),
|
||||
|
||||
DSTU2_HL7ORG("org.hl7.fhir.instance.FhirDstu2Hl7Org", DSTU2, true, new Version("1.0.2")),
|
||||
|
|
|
@ -84,11 +84,7 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
|
|||
myDatatypeToElementDefinition = new HashMap<Class<? extends IBase>, BaseRuntimeElementDefinition<?>>();
|
||||
myResourceTypes = new ArrayList<Class<? extends IBaseResource>>();
|
||||
|
||||
if (theContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
|
||||
myReferenceSuffix = "Resource";
|
||||
} else {
|
||||
myReferenceSuffix = "Reference";
|
||||
}
|
||||
myReferenceSuffix = "Reference";
|
||||
|
||||
for (Class<? extends IBase> next : myChoiceTypes) {
|
||||
|
||||
|
|
|
@ -56,8 +56,7 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
|
|||
/*
|
||||
* Resource reference - The correct name is 'valueReference' in DSTU2 and 'valueResource' in DSTU1
|
||||
*/
|
||||
boolean dstu1 = (theContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1));
|
||||
if ((dstu1 && (value != VALUE_REFERENCE)) || (!dstu1 && (value != VALUE_RESOURCE))) {
|
||||
if (value != VALUE_RESOURCE) {
|
||||
myDatatypeToAttributeName.put(theContext.getVersion().getResourceReferenceType(), value);
|
||||
myDatatypeToDefinition.put(BaseResourceReferenceDt.class, def);
|
||||
myDatatypeToDefinition.put(theContext.getVersion().getResourceReferenceType(), def);
|
||||
|
|
|
@ -131,9 +131,6 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
|
|||
|
||||
if (!UrlUtil.isValid(profile)) {
|
||||
String resourceName = "/StructureDefinition/";
|
||||
if (myContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
resourceName = "/Profile/";
|
||||
}
|
||||
String profileWithUrl = theServerBase + resourceName + profile;
|
||||
if (UrlUtil.isValid(profileWithUrl)) {
|
||||
return profileWithUrl;
|
||||
|
|
|
@ -1,443 +0,0 @@
|
|||
package ca.uhn.fhir.model.api;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2017 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.model.base.resource.ResourceMetadataMap;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.model.valueset.*;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
|
||||
public class Bundle extends BaseBundle /* implements IBase implements IElement */{
|
||||
|
||||
private static final long serialVersionUID = 5811989173275366745L;
|
||||
private ResourceMetadataMap myResourceMetadata;
|
||||
private BoundCodeDt<BundleTypeEnum> myType;
|
||||
private StringDt myBundleId;
|
||||
private TagList myCategories;
|
||||
private List<BundleEntry> myEntries;
|
||||
private volatile transient Map<IdDt, IResource> myIdToEntries;
|
||||
private StringDt myLinkBase;
|
||||
private StringDt myLinkFirst;
|
||||
private StringDt myLinkLast;
|
||||
private StringDt myLinkNext;
|
||||
private StringDt myLinkPrevious;
|
||||
private StringDt myLinkSelf;
|
||||
private StringDt myTitle;
|
||||
private IntegerDt myTotalResults;
|
||||
|
||||
/**
|
||||
* @deprecated Tags wil become immutable in a future release of HAPI, so
|
||||
* {@link #addCategory(String, String, String)} should be used instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Tag addCategory() {
|
||||
Tag retVal = new Tag();
|
||||
getCategories().add(retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public void addCategory(String theScheme, String theTerm, String theLabel) {
|
||||
getCategories().add(new Tag(theScheme, theTerm, theLabel));
|
||||
}
|
||||
|
||||
public void addCategory(Tag theTag) {
|
||||
getCategories().add(theTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds and returns a new bundle entry
|
||||
*/
|
||||
public BundleEntry addEntry() {
|
||||
BundleEntry retVal = new BundleEntry();
|
||||
getEntries().add(retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new entry
|
||||
*
|
||||
* @param theBundleEntry
|
||||
* The entry to add
|
||||
*/
|
||||
public void addEntry(BundleEntry theBundleEntry) {
|
||||
Validate.notNull(theBundleEntry, "theBundleEntry can not be null");
|
||||
getEntries().add(theBundleEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new entry using the given resource and populates it accordingly
|
||||
*
|
||||
* @param theResource
|
||||
* The resource to add
|
||||
* @return Returns the newly created bundle entry that was added to the bundle
|
||||
*/
|
||||
public BundleEntry addResource(IResource theResource, FhirContext theContext, String theServerBase) {
|
||||
BundleEntry entry = addEntry();
|
||||
entry.setResource(theResource);
|
||||
|
||||
RuntimeResourceDefinition def = theContext.getResourceDefinition(theResource);
|
||||
|
||||
String title = ResourceMetadataKeyEnum.TITLE.get(theResource);
|
||||
if (title != null) {
|
||||
entry.getTitle().setValue(title);
|
||||
} else {
|
||||
entry.getTitle().setValue(def.getName() + " " + StringUtils.defaultString(theResource.getId().getValue(), "(no ID)"));
|
||||
}
|
||||
|
||||
if (theResource.getId() != null) {
|
||||
if (theResource.getId().isAbsolute()) {
|
||||
|
||||
entry.getLinkSelf().setValue(theResource.getId().getValue());
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
entry.getId().setValue(theResource.getId().toVersionless().getValue());
|
||||
|
||||
} else if (StringUtils.isNotBlank(theResource.getId().getValue())) {
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append(theServerBase);
|
||||
if (b.length() > 0 && b.charAt(b.length() - 1) != '/') {
|
||||
b.append('/');
|
||||
}
|
||||
b.append(def.getName());
|
||||
b.append('/');
|
||||
String resId = theResource.getId().getIdPart();
|
||||
b.append(resId);
|
||||
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
entry.getId().setValue(b.toString());
|
||||
|
||||
if (isNotBlank(theResource.getId().getVersionIdPart())) {
|
||||
b.append('/');
|
||||
b.append(Constants.PARAM_HISTORY);
|
||||
b.append('/');
|
||||
b.append(theResource.getId().getVersionIdPart());
|
||||
} else {
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get(theResource);
|
||||
if (versionId != null) {
|
||||
b.append('/');
|
||||
b.append(Constants.PARAM_HISTORY);
|
||||
b.append('/');
|
||||
b.append(versionId.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
String qualifiedId = b.toString();
|
||||
entry.getLinkSelf().setValue(qualifiedId);
|
||||
|
||||
// String resourceType = theContext.getResourceDefinition(theResource).getName();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
InstantDt published = ResourceMetadataKeyEnum.PUBLISHED.get(theResource);
|
||||
if (published == null) {
|
||||
entry.getPublished().setToCurrentTimeInLocalTimeZone();
|
||||
} else {
|
||||
entry.setPublished(published);
|
||||
}
|
||||
|
||||
InstantDt updated = ResourceMetadataKeyEnum.UPDATED.get(theResource);
|
||||
if (updated != null) {
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
entry.setUpdated(updated);
|
||||
}
|
||||
|
||||
InstantDt deleted = ResourceMetadataKeyEnum.DELETED_AT.get(theResource);
|
||||
if (deleted != null) {
|
||||
entry.setDeleted(deleted);
|
||||
}
|
||||
|
||||
IdDt previous = ResourceMetadataKeyEnum.PREVIOUS_ID.get(theResource);
|
||||
if (previous != null) {
|
||||
entry.getLinkAlternate().setValue(previous.withServerBase(theServerBase, def.getName()).getValue());
|
||||
}
|
||||
|
||||
TagList tagList = ResourceMetadataKeyEnum.TAG_LIST.get(theResource);
|
||||
if (tagList != null) {
|
||||
for (Tag nextTag : tagList) {
|
||||
entry.addCategory(nextTag);
|
||||
}
|
||||
}
|
||||
|
||||
String linkSearch = ResourceMetadataKeyEnum.LINK_SEARCH.get(theResource);
|
||||
if (isNotBlank(linkSearch)) {
|
||||
if (!UrlUtil.isAbsolute(linkSearch)) {
|
||||
linkSearch = (theServerBase + "/" + linkSearch);
|
||||
}
|
||||
entry.getLinkSearch().setValue(linkSearch);
|
||||
}
|
||||
|
||||
String linkAlternate = ResourceMetadataKeyEnum.LINK_ALTERNATE.get(theResource);
|
||||
if (isNotBlank(linkAlternate)) {
|
||||
if (!UrlUtil.isAbsolute(linkAlternate)) {
|
||||
linkSearch = (theServerBase + "/" + linkAlternate);
|
||||
}
|
||||
entry.getLinkAlternate().setValue(linkSearch);
|
||||
}
|
||||
|
||||
BundleEntrySearchModeEnum entryStatus = ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.get(theResource);
|
||||
if (entryStatus != null) {
|
||||
entry.getSearchMode().setValueAsEnum(entryStatus);
|
||||
}
|
||||
|
||||
BundleEntryTransactionMethodEnum entryTransactionOperation = ResourceMetadataKeyEnum.ENTRY_TRANSACTION_METHOD.get(theResource);
|
||||
if (entryTransactionOperation != null) {
|
||||
entry.getTransactionMethod().setValueAsEnum(entryTransactionOperation);
|
||||
}
|
||||
|
||||
DecimalDt entryScore = ResourceMetadataKeyEnum.ENTRY_SCORE.get(theResource);
|
||||
if (entryScore != null) {
|
||||
entry.setScore(entryScore);
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
public StringDt getBundleId() {
|
||||
if (myBundleId == null) {
|
||||
myBundleId = new StringDt();
|
||||
}
|
||||
return myBundleId;
|
||||
}
|
||||
|
||||
public TagList getCategories() {
|
||||
if (myCategories == null) {
|
||||
myCategories = new TagList();
|
||||
}
|
||||
return myCategories;
|
||||
}
|
||||
|
||||
public List<BundleEntry> getEntries() {
|
||||
if (myEntries == null) {
|
||||
myEntries = new ArrayList<BundleEntry>();
|
||||
}
|
||||
return myEntries;
|
||||
}
|
||||
|
||||
public StringDt getLinkBase() {
|
||||
if (myLinkBase == null) {
|
||||
myLinkBase = new StringDt();
|
||||
}
|
||||
return myLinkBase;
|
||||
}
|
||||
|
||||
public StringDt getLinkFirst() {
|
||||
if (myLinkFirst == null) {
|
||||
myLinkFirst = new StringDt();
|
||||
}
|
||||
return myLinkFirst;
|
||||
}
|
||||
|
||||
public StringDt getLinkLast() {
|
||||
if (myLinkLast == null) {
|
||||
myLinkLast = new StringDt();
|
||||
}
|
||||
return myLinkLast;
|
||||
}
|
||||
|
||||
public StringDt getLinkNext() {
|
||||
if (myLinkNext == null) {
|
||||
myLinkNext = new StringDt();
|
||||
}
|
||||
return myLinkNext;
|
||||
}
|
||||
|
||||
public StringDt getLinkPrevious() {
|
||||
if (myLinkPrevious == null) {
|
||||
myLinkPrevious = new StringDt();
|
||||
}
|
||||
return myLinkPrevious;
|
||||
}
|
||||
|
||||
public StringDt getLinkSelf() {
|
||||
if (myLinkSelf == null) {
|
||||
myLinkSelf = new StringDt();
|
||||
}
|
||||
return myLinkSelf;
|
||||
}
|
||||
|
||||
/*
|
||||
public InstantDt getPublished() {
|
||||
InstantDt retVal = (InstantDt) getResourceMetadata().get(ResourceMetadataKeyEnum.PUBLISHED);
|
||||
if (retVal == null) {
|
||||
retVal= new InstantDt();
|
||||
getResourceMetadata().put(ResourceMetadataKeyEnum.PUBLISHED, retVal);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Retrieves a resource from a bundle given its logical ID.
|
||||
* <p>
|
||||
* <b>Important usage notes</b>: This method ignores base URLs (so passing in an ID of
|
||||
* <code>http://foo/Patient/123</code> will return a resource if it has the logical ID of
|
||||
* <code>http://bar/Patient/123</code>. Also, this method is intended to be used for bundles which have already been
|
||||
* populated. It will cache its results for fast performance, but that means that modifications to the bundle after
|
||||
* this method is called may not be accurately reflected.
|
||||
* </p>
|
||||
*
|
||||
* @param theId
|
||||
* The resource ID
|
||||
* @return Returns the resource with the given ID, or <code>null</code> if none is found
|
||||
*/
|
||||
public IResource getResourceById(IdDt theId) {
|
||||
Map<IdDt, IResource> map = myIdToEntries;
|
||||
if (map == null) {
|
||||
map = new HashMap<IdDt, IResource>();
|
||||
for (BundleEntry next : this.getEntries()) {
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
if (next.getId().isEmpty() == false) {
|
||||
map.put(next.getId().toUnqualified(), next.getResource());
|
||||
}
|
||||
}
|
||||
myIdToEntries = map;
|
||||
}
|
||||
return map.get(theId.toUnqualified());
|
||||
}
|
||||
|
||||
public ResourceMetadataMap getResourceMetadata() {
|
||||
if (myResourceMetadata == null) {
|
||||
myResourceMetadata = new ResourceMetadataMap();
|
||||
}
|
||||
return myResourceMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all resources of the given type from this bundle
|
||||
*/
|
||||
public <T extends IResource> List<T> getResources(Class<T> theClass) {
|
||||
ArrayList<T> retVal = new ArrayList<T>();
|
||||
for (BundleEntry next : getEntries()) {
|
||||
if (next.getResource() != null && theClass.isAssignableFrom(next.getResource().getClass())) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T resource = (T) next.getResource();
|
||||
retVal.add(resource);
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public StringDt getTitle() {
|
||||
if (myTitle == null) {
|
||||
myTitle = new StringDt();
|
||||
}
|
||||
return myTitle;
|
||||
}
|
||||
|
||||
public IntegerDt getTotalResults() {
|
||||
if (myTotalResults == null) {
|
||||
myTotalResults = new IntegerDt();
|
||||
}
|
||||
return myTotalResults;
|
||||
}
|
||||
|
||||
public BoundCodeDt<BundleTypeEnum> getType() {
|
||||
if (myType == null) {
|
||||
myType = new BoundCodeDt<BundleTypeEnum>(BundleTypeEnum.VALUESET_BINDER);
|
||||
}
|
||||
return myType;
|
||||
}
|
||||
|
||||
public InstantDt getUpdated() {
|
||||
InstantDt retVal = (InstantDt) getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
|
||||
if (retVal == null) {
|
||||
retVal= new InstantDt();
|
||||
getResourceMetadata().put(ResourceMetadataKeyEnum.UPDATED, retVal);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this bundle contains zero entries
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return getEntries().isEmpty();
|
||||
}
|
||||
|
||||
public void setCategories(TagList theCategories) {
|
||||
myCategories = theCategories;
|
||||
}
|
||||
|
||||
/*
|
||||
public void setPublished(InstantDt thePublished) {
|
||||
getResourceMetadata().put(ResourceMetadataKeyEnum.PUBLISHED, thePublished);
|
||||
}
|
||||
*/
|
||||
|
||||
public void setType(BoundCodeDt<BundleTypeEnum> theType) {
|
||||
myType = theType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of entries in this bundle
|
||||
*/
|
||||
public int size() {
|
||||
return getEntries().size();
|
||||
}
|
||||
|
||||
public List<IResource> toListOfResources() {
|
||||
ArrayList<IResource> retVal = new ArrayList<IResource>();
|
||||
for (BundleEntry next : getEntries()) {
|
||||
if (next.getResource() != null) {
|
||||
retVal.add(next.getResource());
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||
b.append(getEntries().size() + " entries");
|
||||
b.append("id", getId());
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public static Bundle withResources(List<IResource> theResources, FhirContext theContext, String theServerBase) {
|
||||
Bundle retVal = new Bundle();
|
||||
for (IResource next : theResources) {
|
||||
retVal.addResource(next, theContext, theServerBase);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static Bundle withSingleResource(IResource theResource) {
|
||||
Bundle retVal = new Bundle();
|
||||
retVal.addEntry().setResource(theResource);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,382 +0,0 @@
|
|||
package ca.uhn.fhir.model.api;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2017 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import ca.uhn.fhir.model.primitive.BoundCodeDt;
|
||||
import ca.uhn.fhir.model.primitive.CodeDt;
|
||||
import ca.uhn.fhir.model.primitive.DecimalDt;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.model.primitive.XhtmlDt;
|
||||
import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum;
|
||||
import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum;
|
||||
import ca.uhn.fhir.util.ElementUtil;
|
||||
|
||||
public class BundleEntry extends BaseBundle {
|
||||
|
||||
private static final long serialVersionUID = 2635639739195593736L;
|
||||
//@formatter:off
|
||||
/* ****************************************************
|
||||
* NB: add any new fields to the isEmpty() method!!!
|
||||
*****************************************************/
|
||||
//@formatter:on
|
||||
private TagList myCategories;
|
||||
private InstantDt myDeletedAt;
|
||||
private StringDt myDeletedByEmail;
|
||||
private StringDt myDeletedByName;
|
||||
private StringDt myDeletedComment;
|
||||
private IdDt myDeletedResourceId;
|
||||
private CodeDt myDeletedResourceType;
|
||||
private StringDt myDeletedResourceVersion;
|
||||
private StringDt myLinkAlternate;
|
||||
private StringDt myLinkBase;
|
||||
private StringDt myLinkSearch;
|
||||
private StringDt myLinkSelf;
|
||||
private InstantDt myPublished;
|
||||
private IResource myResource;
|
||||
private DecimalDt myScore;
|
||||
private BoundCodeDt<BundleEntrySearchModeEnum> mySearchMode;
|
||||
private BoundCodeDt<BundleEntryTransactionMethodEnum> myTransactionOperation;
|
||||
private XhtmlDt mySummary;
|
||||
private StringDt myTitle;
|
||||
private InstantDt myUpdated;
|
||||
|
||||
/**
|
||||
* @deprecated Tags wil become immutable in a future release of HAPI, so
|
||||
* {@link #addCategory(String, String, String)} should be used instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Tag addCategory() {
|
||||
Tag retVal = new Tag();
|
||||
getCategories().add(retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public void addCategory(String theScheme, String theTerm, String theLabel) {
|
||||
getCategories().add(new Tag(theScheme, theTerm, theLabel));
|
||||
}
|
||||
|
||||
public void addCategory(Tag theTag) {
|
||||
getCategories().add(theTag);
|
||||
}
|
||||
|
||||
public TagList getCategories() {
|
||||
if (myCategories == null) {
|
||||
myCategories = new TagList();
|
||||
}
|
||||
return myCategories;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the date/time that thius entry was deleted.
|
||||
*/
|
||||
public InstantDt getDeletedAt() {
|
||||
if (myDeletedAt == null) {
|
||||
myDeletedAt = new InstantDt();
|
||||
}
|
||||
return myDeletedAt;
|
||||
}
|
||||
|
||||
public StringDt getDeletedByEmail() {
|
||||
if (myDeletedByEmail == null) {
|
||||
myDeletedByEmail = new StringDt();
|
||||
}
|
||||
return myDeletedByEmail;
|
||||
}
|
||||
|
||||
public StringDt getDeletedByName() {
|
||||
if (myDeletedByName == null) {
|
||||
myDeletedByName = new StringDt();
|
||||
}
|
||||
return myDeletedByName;
|
||||
}
|
||||
|
||||
public StringDt getDeletedComment() {
|
||||
if (myDeletedComment == null) {
|
||||
myDeletedComment = new StringDt();
|
||||
}
|
||||
return myDeletedComment;
|
||||
}
|
||||
|
||||
public IdDt getDeletedResourceId() {
|
||||
if (myDeletedResourceId == null) {
|
||||
myDeletedResourceId = new IdDt();
|
||||
}
|
||||
return myDeletedResourceId;
|
||||
}
|
||||
|
||||
public CodeDt getDeletedResourceType() {
|
||||
if (myDeletedResourceType == null) {
|
||||
myDeletedResourceType = new CodeDt();
|
||||
}
|
||||
return myDeletedResourceType;
|
||||
}
|
||||
|
||||
public StringDt getDeletedResourceVersion() {
|
||||
if (myDeletedResourceVersion == null) {
|
||||
myDeletedResourceVersion = new StringDt();
|
||||
}
|
||||
return myDeletedResourceVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Setting IDs on bundle entries is redundant since resources already have an ID field. Instead of
|
||||
* providing an ID using this method, set the ID on the resource using {@link IResource#setId(IdDt)} or
|
||||
* if this entry represents a deleted resource, use {@link #setDeletedResourceId(IdDt)}.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public IdDt getId() {
|
||||
return super.getId();
|
||||
}
|
||||
|
||||
public StringDt getLinkAlternate() {
|
||||
if (myLinkAlternate == null) {
|
||||
myLinkAlternate = new StringDt();
|
||||
}
|
||||
return myLinkAlternate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use resource ID to determine base URL
|
||||
*/
|
||||
@Deprecated
|
||||
public StringDt getLinkBase() {
|
||||
if (myLinkBase == null) {
|
||||
myLinkBase = new StringDt();
|
||||
}
|
||||
return myLinkBase;
|
||||
}
|
||||
|
||||
public StringDt getLinkSearch() {
|
||||
if (myLinkSearch == null) {
|
||||
myLinkSearch = new StringDt();
|
||||
}
|
||||
return myLinkSearch;
|
||||
}
|
||||
|
||||
public StringDt getLinkSelf() {
|
||||
if (myLinkSelf == null) {
|
||||
myLinkSelf = new StringDt();
|
||||
}
|
||||
return myLinkSelf;
|
||||
}
|
||||
|
||||
public InstantDt getPublished() {
|
||||
if (myPublished == null) {
|
||||
myPublished = new InstantDt();
|
||||
}
|
||||
return myPublished;
|
||||
}
|
||||
|
||||
public IResource getResource() {
|
||||
return myResource;
|
||||
}
|
||||
|
||||
public DecimalDt getScore() {
|
||||
if (myScore == null) {
|
||||
myScore = new DecimalDt();
|
||||
}
|
||||
return myScore;
|
||||
}
|
||||
|
||||
|
||||
public XhtmlDt getSummary() {
|
||||
if (mySummary == null) {
|
||||
mySummary = new XhtmlDt();
|
||||
}
|
||||
return mySummary;
|
||||
}
|
||||
|
||||
public StringDt getTitle() {
|
||||
if (myTitle == null) {
|
||||
myTitle = new StringDt();
|
||||
}
|
||||
return myTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated <b>DSTU2 Note:</b> As of DSTU2, bundle entries no longer have an updated time (this bit of metadata
|
||||
* has been moved to the resource <meta/> element so it is redundant here). In preparation for
|
||||
* DSTU2, it is recommended that you migrate code away from using this method and over to using resource
|
||||
* metadata instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public InstantDt getUpdated() {
|
||||
if (myUpdated == null) {
|
||||
myUpdated = new InstantDt();
|
||||
}
|
||||
if (myUpdated.isEmpty() && myResource != null) {
|
||||
InstantDt resourceUpdated = ResourceMetadataKeyEnum.UPDATED.get(myResource);
|
||||
if (resourceUpdated != null && !resourceUpdated.isEmpty()) {
|
||||
return resourceUpdated;
|
||||
}
|
||||
}
|
||||
return myUpdated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
//@formatter:off
|
||||
return super.isEmpty() &&
|
||||
ElementUtil.isEmpty(
|
||||
myDeletedResourceId, myDeletedResourceType, myDeletedResourceVersion, myDeletedAt,
|
||||
myScore, mySearchMode, myTransactionOperation, myCategories,
|
||||
myLinkAlternate, myLinkSelf, myPublished, myResource, mySummary,
|
||||
myTitle, myUpdated, myDeletedByEmail, myDeletedByName, myDeletedComment);
|
||||
//@formatter:on
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the date/time that this entry was deleted.
|
||||
*/
|
||||
public void setDeleted(InstantDt theDeletedAt) {
|
||||
myDeletedAt = theDeletedAt;
|
||||
}
|
||||
|
||||
public void setDeletedByEmail(StringDt theDeletedByEmail) {
|
||||
myDeletedByEmail = theDeletedByEmail;
|
||||
}
|
||||
|
||||
public void setDeletedByName(StringDt theDeletedByName) {
|
||||
if (myDeletedByName == null) {
|
||||
myDeletedByName = new StringDt();
|
||||
}
|
||||
myDeletedByName = theDeletedByName;
|
||||
}
|
||||
|
||||
public void setDeletedComment(StringDt theDeletedComment) {
|
||||
myDeletedComment = theDeletedComment;
|
||||
}
|
||||
|
||||
public void setDeletedResourceId(IdDt theDeletedResourceId) {
|
||||
myDeletedResourceId = theDeletedResourceId;
|
||||
}
|
||||
|
||||
public void setDeletedResourceType(CodeDt theDeletedResourceType) {
|
||||
myDeletedResourceType = theDeletedResourceType;
|
||||
}
|
||||
|
||||
public void setDeletedResourceVersion(StringDt theDeletedResourceVersion) {
|
||||
myDeletedResourceVersion = theDeletedResourceVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Bundle entries no longer have an ID in DSTU2, as ID is explicitly stated in the resource itself.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setId(IdDt theId) {
|
||||
super.setId(theId);
|
||||
}
|
||||
|
||||
public void setLinkAlternate(StringDt theLinkAlternate) {
|
||||
myLinkAlternate = theLinkAlternate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use resource ID to determine base URL
|
||||
*/
|
||||
@Deprecated
|
||||
public void setLinkBase(StringDt theLinkBase) {
|
||||
myLinkBase = theLinkBase;
|
||||
}
|
||||
|
||||
public void setLinkSearch(StringDt theLinkSearch) {
|
||||
myLinkSearch = theLinkSearch;
|
||||
}
|
||||
|
||||
public void setLinkSelf(StringDt theLinkSelf) {
|
||||
if (myLinkSelf == null) {
|
||||
myLinkSelf = new StringDt();
|
||||
}
|
||||
myLinkSelf = theLinkSelf;
|
||||
}
|
||||
|
||||
public void setPublished(InstantDt thePublished) {
|
||||
Validate.notNull(thePublished, "Published may not be null");
|
||||
myPublished = thePublished;
|
||||
}
|
||||
|
||||
public void setResource(IResource theResource) {
|
||||
myResource = theResource;
|
||||
}
|
||||
|
||||
public void setScore(DecimalDt theScore) {
|
||||
myScore = theScore;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated <b>DSTU2 Note:</b> As of DSTU2, bundle entries no longer have an updated time (this bit of metadata
|
||||
* has been moved to the resource <meta/> element so it is redundant here). In preparation for
|
||||
* DSTU2, it is recommended that you migrate code away from using this method and over to using resource
|
||||
* metadata instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setUpdated(InstantDt theUpdated) {
|
||||
Validate.notNull(theUpdated, "Updated may not be null");
|
||||
myUpdated = theUpdated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||
if (getResource() != null) {
|
||||
b.append("type", getResource().getClass().getSimpleName());
|
||||
} else {
|
||||
b.append("No resource");
|
||||
}
|
||||
b.append("id", getId());
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public BoundCodeDt<BundleEntrySearchModeEnum> getSearchMode() {
|
||||
if (mySearchMode == null) {
|
||||
mySearchMode = new BoundCodeDt<BundleEntrySearchModeEnum>(BundleEntrySearchModeEnum.VALUESET_BINDER);
|
||||
}
|
||||
return mySearchMode;
|
||||
}
|
||||
|
||||
public void setSearchMode(BoundCodeDt<BundleEntrySearchModeEnum> theSearchMode) {
|
||||
mySearchMode = theSearchMode;
|
||||
}
|
||||
|
||||
public BoundCodeDt<BundleEntryTransactionMethodEnum> getTransactionMethod() {
|
||||
if (myTransactionOperation == null) {
|
||||
myTransactionOperation = new BoundCodeDt<BundleEntryTransactionMethodEnum>(BundleEntryTransactionMethodEnum.VALUESET_BINDER);
|
||||
}
|
||||
return myTransactionOperation;
|
||||
}
|
||||
|
||||
public void setTransactionMethod(BoundCodeDt<BundleEntryTransactionMethodEnum> theTransactionOperation) {
|
||||
myTransactionOperation = theTransactionOperation;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -25,21 +25,14 @@ import java.math.BigDecimal;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.BaseIdentifiableElement;
|
||||
import ca.uhn.fhir.model.api.ICompositeDatatype;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.primitive.BoundCodeDt;
|
||||
import ca.uhn.fhir.model.primitive.CodeDt;
|
||||
import ca.uhn.fhir.model.primitive.DecimalDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
|
||||
import ca.uhn.fhir.rest.param.QuantityParam;
|
||||
|
||||
public abstract class BaseQuantityDt extends BaseIdentifiableElement implements ICompositeDatatype, IQueryParameterType {
|
||||
|
||||
private static final long serialVersionUID = -925486613033086056L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Sets the value(s) for <b>value</b> (Numerical value (with implicit precision))
|
||||
|
@ -65,21 +58,21 @@ public abstract class BaseQuantityDt extends BaseIdentifiableElement implements
|
|||
}
|
||||
String[] parts = theValue.split("\\|");
|
||||
if (parts.length > 0 && StringUtils.isNotBlank(parts[0])) {
|
||||
if (parts[0].startsWith("<=")) {
|
||||
if (parts[0].startsWith("le")) {
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
getComparatorElement().setValue(QuantityCompararatorEnum.LESSTHAN_OR_EQUALS.getCode());
|
||||
getComparatorElement().setValue(ParamPrefixEnum.LESSTHAN_OR_EQUALS.getValue());
|
||||
setValue(new BigDecimal(parts[0].substring(2)));
|
||||
} else if (parts[0].startsWith("<")) {
|
||||
} else if (parts[0].startsWith("lt")) {
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
getComparatorElement().setValue(QuantityCompararatorEnum.LESSTHAN.getCode());
|
||||
getComparatorElement().setValue(ParamPrefixEnum.LESSTHAN.getValue());
|
||||
setValue(new BigDecimal(parts[0].substring(1)));
|
||||
} else if (parts[0].startsWith(">=")) {
|
||||
} else if (parts[0].startsWith("ge")) {
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
getComparatorElement().setValue(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS.getCode());
|
||||
getComparatorElement().setValue(ParamPrefixEnum.GREATERTHAN_OR_EQUALS.getValue());
|
||||
setValue(new BigDecimal(parts[0].substring(2)));
|
||||
} else if (parts[0].startsWith(">")) {
|
||||
} else if (parts[0].startsWith("gt")) {
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
getComparatorElement().setValue(QuantityCompararatorEnum.GREATERTHAN.getCode());
|
||||
getComparatorElement().setValue(ParamPrefixEnum.GREATERTHAN.getValue());
|
||||
setValue(new BigDecimal(parts[0].substring(1)));
|
||||
} else {
|
||||
setValue(new BigDecimal(parts[0]));
|
||||
|
|
|
@ -1,159 +0,0 @@
|
|||
|
||||
package ca.uhn.fhir.model.dstu.valueset;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2017 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import ca.uhn.fhir.model.api.IValueSetEnumBinder;
|
||||
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
|
||||
import ca.uhn.fhir.util.CoverageIgnore;
|
||||
|
||||
/**
|
||||
* @deprecated This class has been replaced by {@link ParamPrefixEnum} in HAPI FHIR 1.5
|
||||
*/
|
||||
@Deprecated
|
||||
@CoverageIgnore
|
||||
public enum QuantityCompararatorEnum {
|
||||
|
||||
/**
|
||||
* Code Value: <b><</b>
|
||||
*
|
||||
* The actual value is less than the given value.
|
||||
*/
|
||||
LESSTHAN("<", "http://hl7.org/fhir/quantity-comparator"),
|
||||
|
||||
/**
|
||||
* Code Value: <b><=</b>
|
||||
*
|
||||
* The actual value is less than or equal to the given value.
|
||||
*/
|
||||
LESSTHAN_OR_EQUALS("<=", "http://hl7.org/fhir/quantity-comparator"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>>=</b>
|
||||
*
|
||||
* The actual value is greater than or equal to the given value.
|
||||
*/
|
||||
GREATERTHAN_OR_EQUALS(">=", "http://hl7.org/fhir/quantity-comparator"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>></b>
|
||||
*
|
||||
* The actual value is greater than the given value.
|
||||
*/
|
||||
GREATERTHAN(">", "http://hl7.org/fhir/quantity-comparator"),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Identifier for this Value Set:
|
||||
* http://hl7.org/fhir/vs/quantity-comparator
|
||||
*/
|
||||
public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/quantity-comparator";
|
||||
|
||||
/**
|
||||
* Name for this Value Set:
|
||||
* QuantityCompararator
|
||||
*/
|
||||
public static final String VALUESET_NAME = "QuantityCompararator";
|
||||
|
||||
private static Map<String, QuantityCompararatorEnum> CODE_TO_ENUM = new HashMap<String, QuantityCompararatorEnum>();
|
||||
private static Map<String, Map<String, QuantityCompararatorEnum>> SYSTEM_TO_CODE_TO_ENUM = new HashMap<String, Map<String, QuantityCompararatorEnum>>();
|
||||
|
||||
private final String myCode;
|
||||
private final String mySystem;
|
||||
|
||||
static {
|
||||
for (QuantityCompararatorEnum next : QuantityCompararatorEnum.values()) {
|
||||
CODE_TO_ENUM.put(next.getCode(), next);
|
||||
|
||||
if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) {
|
||||
SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap<String, QuantityCompararatorEnum>());
|
||||
}
|
||||
SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code associated with this enumerated value
|
||||
*/
|
||||
public String getCode() {
|
||||
return myCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code system associated with this enumerated value
|
||||
*/
|
||||
public String getSystem() {
|
||||
return mySystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enumerated value associated with this code
|
||||
*/
|
||||
public static QuantityCompararatorEnum forCode(String theCode) {
|
||||
QuantityCompararatorEnum retVal = CODE_TO_ENUM.get(theCode);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts codes to their respective enumerated values
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static final IValueSetEnumBinder<QuantityCompararatorEnum> VALUESET_BINDER = new IValueSetEnumBinder<QuantityCompararatorEnum>() {
|
||||
@Override
|
||||
public String toCodeString(QuantityCompararatorEnum theEnum) {
|
||||
return theEnum.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSystemString(QuantityCompararatorEnum theEnum) {
|
||||
return theEnum.getSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuantityCompararatorEnum fromCodeString(String theCodeString) {
|
||||
return CODE_TO_ENUM.get(theCodeString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QuantityCompararatorEnum fromCodeString(String theCodeString, String theSystemString) {
|
||||
Map<String, QuantityCompararatorEnum> map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return map.get(theCodeString);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
QuantityCompararatorEnum(String theCode, String theSystem) {
|
||||
myCode = theCode;
|
||||
mySystem = theSystem;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -306,44 +306,20 @@ public abstract class BaseParser implements IParser {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private boolean isOverrideResourceIdWithBundleEntryFullUrl() {
|
||||
Boolean overrideResourceIdWithBundleEntryFullUrl = myOverrideResourceIdWithBundleEntryFullUrl;
|
||||
if (overrideResourceIdWithBundleEntryFullUrl != null) {
|
||||
return overrideResourceIdWithBundleEntryFullUrl;
|
||||
}
|
||||
|
||||
|
||||
return myContext.getParserOptions().isOverrideResourceIdWithBundleEntryFullUrl();
|
||||
}
|
||||
|
||||
protected abstract void doEncodeBundleToWriter(Bundle theBundle, Writer theWriter) throws IOException, DataFormatException;
|
||||
|
||||
protected abstract void doEncodeResourceToWriter(IBaseResource theResource, Writer theWriter) throws IOException, DataFormatException;
|
||||
|
||||
protected abstract <T extends IBaseResource> T doParseResource(Class<T> theResourceType, Reader theReader) throws DataFormatException;
|
||||
|
||||
@Override
|
||||
public String encodeBundleToString(Bundle theBundle) throws DataFormatException {
|
||||
if (theBundle == null) {
|
||||
throw new NullPointerException("Bundle can not be null");
|
||||
}
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
try {
|
||||
encodeBundleToWriter(theBundle, stringWriter);
|
||||
} catch (IOException e) {
|
||||
throw new Error("Encountered IOException during write to string - This should not happen!");
|
||||
}
|
||||
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void encodeBundleToWriter(Bundle theBundle, Writer theWriter) throws IOException, DataFormatException {
|
||||
Validate.notNull(theBundle, "theBundle must not be null");
|
||||
Validate.notNull(theWriter, "theWriter must not be null");
|
||||
doEncodeBundleToWriter(theBundle, theWriter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeResourceToString(IBaseResource theResource) throws DataFormatException {
|
||||
Writer stringWriter = new StringWriter();
|
||||
|
@ -368,17 +344,6 @@ public abstract class BaseParser implements IParser {
|
|||
doEncodeResourceToWriter(theResource, theWriter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeTagListToString(TagList theTagList) {
|
||||
Writer stringWriter = new StringWriter();
|
||||
try {
|
||||
encodeTagListToWriter(theTagList, stringWriter);
|
||||
} catch (IOException e) {
|
||||
throw new Error("Encountered IOException during write to string - This should not happen!");
|
||||
}
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
private void filterCodingsWithNoCodeOrSystem(List<? extends IBaseCoding> tagList) {
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
if (isBlank(tagList.get(i).getCode()) && isBlank(tagList.get(i).getSystem())) {
|
||||
|
@ -514,27 +479,25 @@ public abstract class BaseParser implements IParser {
|
|||
break;
|
||||
}
|
||||
|
||||
if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
RuntimeResourceDefinition nextDef = myContext.getResourceDefinition(theResource);
|
||||
String profile = nextDef.getResourceProfile(myServerBaseUrl);
|
||||
if (isNotBlank(profile)) {
|
||||
for (T next : theProfiles) {
|
||||
if (profile.equals(next.getValue())) {
|
||||
return theProfiles;
|
||||
}
|
||||
RuntimeResourceDefinition nextDef = myContext.getResourceDefinition(theResource);
|
||||
String profile = nextDef.getResourceProfile(myServerBaseUrl);
|
||||
if (isNotBlank(profile)) {
|
||||
for (T next : theProfiles) {
|
||||
if (profile.equals(next.getValue())) {
|
||||
return theProfiles;
|
||||
}
|
||||
|
||||
List<T> newList = new ArrayList<T>();
|
||||
newList.addAll(theProfiles);
|
||||
|
||||
BaseRuntimeElementDefinition<?> idElement = myContext.getElementDefinition("id");
|
||||
@SuppressWarnings("unchecked")
|
||||
T newId = (T) idElement.newInstance();
|
||||
newId.setValue(profile);
|
||||
|
||||
newList.add(newId);
|
||||
return newList;
|
||||
}
|
||||
|
||||
List<T> newList = new ArrayList<T>();
|
||||
newList.addAll(theProfiles);
|
||||
|
||||
BaseRuntimeElementDefinition<?> idElement = myContext.getElementDefinition("id");
|
||||
@SuppressWarnings("unchecked")
|
||||
T newId = (T) idElement.newInstance();
|
||||
newId.setValue(profile);
|
||||
|
||||
newList.add(newId);
|
||||
return newList;
|
||||
}
|
||||
|
||||
return theProfiles;
|
||||
|
@ -565,7 +528,7 @@ public abstract class BaseParser implements IParser {
|
|||
public Boolean getStripVersionsFromReferences() {
|
||||
return myStripVersionsFromReferences;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Boolean getOverrideResourceIdWithBundleEntryFullUrl() {
|
||||
return myOverrideResourceIdWithBundleEntryFullUrl;
|
||||
|
@ -586,20 +549,6 @@ public abstract class BaseParser implements IParser {
|
|||
return mySuppressNarratives;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle parseBundle(Reader theReader) {
|
||||
if (myContext.getVersion().getVersion() == FhirVersionEnum.DSTU2_HL7ORG) {
|
||||
throw new IllegalStateException("Can't parse DSTU1 (Atom) bundle in HL7.org DSTU2 mode. Use parseResource(Bundle.class, foo) instead.");
|
||||
}
|
||||
return parseBundle(null, theReader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle parseBundle(String theXml) throws ConfigurationException, DataFormatException {
|
||||
StringReader reader = new StringReader(theXml);
|
||||
return parseBundle(reader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IBaseResource> T parseResource(Class<T> theResourceType, Reader theReader) throws DataFormatException {
|
||||
|
||||
|
@ -674,10 +623,6 @@ public abstract class BaseParser implements IParser {
|
|||
return parseResource(null, theMessageString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagList parseTagList(String theString) {
|
||||
return parseTagList(new StringReader(theString));
|
||||
}
|
||||
|
||||
protected List<? extends IBase> preProcessValues(BaseRuntimeChildDefinition theMetaChildUncast, IBaseResource theResource, List<? extends IBase> theValues,
|
||||
CompositeChildElement theCompositeChildElement) {
|
||||
|
@ -851,7 +796,7 @@ public abstract class BaseParser implements IParser {
|
|||
myStripVersionsFromReferences = theStripVersionsFromReferences;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IParser setOverrideResourceIdWithBundleEntryFullUrl(Boolean theOverrideResourceIdWithBundleEntryFullUrl) {
|
||||
myOverrideResourceIdWithBundleEntryFullUrl = theOverrideResourceIdWithBundleEntryFullUrl;
|
||||
|
@ -927,10 +872,10 @@ public abstract class BaseParser implements IParser {
|
|||
return url;
|
||||
}
|
||||
|
||||
protected String getServerBaseUrl() {
|
||||
return myServerBaseUrl;
|
||||
protected String getServerBaseUrl() {
|
||||
return myServerBaseUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used for DSTU2 only
|
||||
*/
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.parser;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -25,9 +25,7 @@ import java.io.IOException;
|
|||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.parser.json.JsonLikeStructure;
|
||||
import ca.uhn.fhir.parser.json.JsonLikeWriter;
|
||||
|
||||
|
@ -41,27 +39,8 @@ import ca.uhn.fhir.parser.json.JsonLikeWriter;
|
|||
*/
|
||||
public interface IJsonLikeParser extends IParser {
|
||||
|
||||
void encodeBundleToJsonLikeWriter(Bundle theBundle, JsonLikeWriter theJsonLikeWriter) throws IOException, DataFormatException;
|
||||
|
||||
void encodeResourceToJsonLikeWriter(IBaseResource theResource, JsonLikeWriter theJsonLikeWriter) throws IOException, DataFormatException;
|
||||
|
||||
void encodeTagListToJsonLikeWriter(TagList theTagList, JsonLikeWriter theJsonLikeWriter) throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Parse a DSTU1 style Atom Bundle. Note that as of DSTU2, Bundle is a resource so you should use
|
||||
* {@link #parseResource(Class, JsonLikeStructure)} with the Bundle class found in the
|
||||
* <code>ca.uhn.hapi.fhir.model.[version].resource</code> package instead.
|
||||
*/
|
||||
<T extends IBaseResource> Bundle parseBundle(Class<T> theResourceType, JsonLikeStructure theJsonLikeStructure);
|
||||
|
||||
/**
|
||||
* Parse a DSTU1 style Atom Bundle. Note that as of DSTU2, Bundle is a resource so you should use
|
||||
* {@link #parseResource(Class, JsonLikeStructure)} with the Bundle class found in the
|
||||
* <code>ca.uhn.hapi.fhir.model.[version].resource</code> package instead.
|
||||
*/
|
||||
Bundle parseBundle(JsonLikeStructure theJsonLikeStructure) throws DataFormatException;
|
||||
|
||||
/**
|
||||
* Parses a resource from a JSON-like data structure
|
||||
*
|
||||
|
@ -76,7 +55,6 @@ public interface IJsonLikeParser extends IParser {
|
|||
*/
|
||||
<T extends IBaseResource> T parseResource(Class<T> theResourceType, JsonLikeStructure theJsonLikeStructure) throws DataFormatException;
|
||||
|
||||
|
||||
/**
|
||||
* Parses a resource from a JSON-like data structure
|
||||
*
|
||||
|
@ -89,13 +67,4 @@ public interface IJsonLikeParser extends IParser {
|
|||
*/
|
||||
IBaseResource parseResource(JsonLikeStructure theJsonLikeStructure) throws DataFormatException;
|
||||
|
||||
/**
|
||||
* Parses a tag list from a JSON-like data structure
|
||||
*
|
||||
* @param theJsonLikeStructure
|
||||
* The JSON-like structure to parse
|
||||
* @return A parsed tag list
|
||||
*/
|
||||
TagList parseTagList(JsonLikeStructure theJsonLikeStructure);
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.parser;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -25,7 +25,7 @@ import java.util.*;
|
|||
import org.hl7.fhir.instance.model.api.*;
|
||||
|
||||
import ca.uhn.fhir.context.*;
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
|
||||
/**
|
||||
|
@ -38,35 +38,10 @@ import ca.uhn.fhir.rest.api.EncodingEnum;
|
|||
*/
|
||||
public interface IParser {
|
||||
|
||||
String encodeBundleToString(Bundle theBundle) throws DataFormatException;
|
||||
|
||||
void encodeBundleToWriter(Bundle theBundle, Writer theWriter) throws IOException, DataFormatException;
|
||||
|
||||
String encodeResourceToString(IBaseResource theResource) throws DataFormatException;
|
||||
|
||||
void encodeResourceToWriter(IBaseResource theResource, Writer theWriter) throws IOException, DataFormatException;
|
||||
|
||||
/**
|
||||
* Encodes a tag list, as defined in the <a href="http://hl7.org/implement/standards/fhir/http.html#tags">FHIR
|
||||
* Specification</a>.
|
||||
*
|
||||
* @param theTagList
|
||||
* The tag list to encode. Must not be null.
|
||||
* @return An encoded tag list
|
||||
*/
|
||||
String encodeTagListToString(TagList theTagList);
|
||||
|
||||
/**
|
||||
* Encodes a tag list, as defined in the <a href="http://hl7.org/implement/standards/fhir/http.html#tags">FHIR
|
||||
* Specification</a>.
|
||||
*
|
||||
* @param theTagList
|
||||
* The tag list to encode. Must not be null.
|
||||
* @param theWriter
|
||||
* The writer to encode to
|
||||
*/
|
||||
void encodeTagListToWriter(TagList theTagList, Writer theWriter) throws IOException;
|
||||
|
||||
/**
|
||||
* See {@link #setEncodeElements(Set)}
|
||||
*/
|
||||
|
@ -117,7 +92,7 @@ public interface IParser {
|
|||
* @see ParserOptions
|
||||
*/
|
||||
Boolean getStripVersionsFromReferences();
|
||||
|
||||
|
||||
/**
|
||||
* If set to <code>true</code> (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource's
|
||||
* resource id if the fullUrl is defined. This behavior happens when parsing the source data into a Bundle object. Set this
|
||||
|
@ -138,27 +113,6 @@ public interface IParser {
|
|||
*/
|
||||
boolean isSummaryMode();
|
||||
|
||||
/**
|
||||
* Parse a DSTU1 style Atom Bundle. Note that as of DSTU2, Bundle is a resource so you should use
|
||||
* {@link #parseResource(Class, Reader)} with the Bundle class found in the
|
||||
* <code>ca.uhn.hapi.fhir.model.[version].resource</code> package instead.
|
||||
*/
|
||||
<T extends IBaseResource> Bundle parseBundle(Class<T> theResourceType, Reader theReader);
|
||||
|
||||
/**
|
||||
* Parse a DSTU1 style Atom Bundle. Note that as of DSTU2, Bundle is a resource so you should use
|
||||
* {@link #parseResource(Class, Reader)} with the Bundle class found in the
|
||||
* <code>ca.uhn.hapi.fhir.model.[version].resource</code> package instead.
|
||||
*/
|
||||
Bundle parseBundle(Reader theReader);
|
||||
|
||||
/**
|
||||
* Parse a DSTU1 style Atom Bundle. Note that as of DSTU2, Bundle is a resource so you should use
|
||||
* {@link #parseResource(Class, String)} with the Bundle class found in the
|
||||
* <code>ca.uhn.hapi.fhir.model.[version].resource</code> package instead.
|
||||
*/
|
||||
Bundle parseBundle(String theMessageString) throws ConfigurationException, DataFormatException;
|
||||
|
||||
/**
|
||||
* Parses a resource
|
||||
*
|
||||
|
@ -211,26 +165,6 @@ public interface IParser {
|
|||
*/
|
||||
IBaseResource parseResource(String theMessageString) throws ConfigurationException, DataFormatException;
|
||||
|
||||
/**
|
||||
* Parses a tag list, as defined in the <a href="http://hl7.org/implement/standards/fhir/http.html#tags">FHIR
|
||||
* Specification</a>.
|
||||
*
|
||||
* @param theReader
|
||||
* A reader which will supply a tag list
|
||||
* @return A parsed tag list
|
||||
*/
|
||||
TagList parseTagList(Reader theReader);
|
||||
|
||||
/**
|
||||
* Parses a tag list, as defined in the <a href="http://hl7.org/implement/standards/fhir/http.html#tags">FHIR
|
||||
* Specification</a>.
|
||||
*
|
||||
* @param theString
|
||||
* A string containing a tag list
|
||||
* @return A parsed tag list
|
||||
*/
|
||||
TagList parseTagList(String theString);
|
||||
|
||||
/**
|
||||
* If provided, specifies the elements which should NOT be encoded. Valid values for this
|
||||
* field would include:
|
||||
|
@ -356,6 +290,7 @@ public interface IParser {
|
|||
* This method provides the ability to globally disable reference encoding. If finer-grained
|
||||
* control is needed, use {@link #setDontStripVersionsFromReferencesAtPaths(String...)}
|
||||
* </p>
|
||||
*
|
||||
* @param theStripVersionsFromReferences
|
||||
* Set this to <code>false<code> to prevent the parser from removing resource versions from references (or <code>null</code> to apply the default setting from the {@link ParserOptions}
|
||||
* @see #setDontStripVersionsFromReferencesAtPaths(String...)
|
||||
|
@ -363,7 +298,7 @@ public interface IParser {
|
|||
* @return Returns a reference to <code>this</code> parser so that method calls can be chained together
|
||||
*/
|
||||
IParser setStripVersionsFromReferences(Boolean theStripVersionsFromReferences);
|
||||
|
||||
|
||||
/**
|
||||
* If set to <code>true</code> (which is the default), the Bundle.entry.fullUrl will override the Bundle.entry.resource's
|
||||
* resource id if the fullUrl is defined. This behavior happens when parsing the source data into a Bundle object. Set this
|
||||
|
@ -415,7 +350,7 @@ public interface IParser {
|
|||
* @return Returns a reference to <code>this</code> parser so that method calls can be chained together
|
||||
*/
|
||||
IParser setDontStripVersionsFromReferencesAtPaths(String... thePaths);
|
||||
|
||||
|
||||
/**
|
||||
* If supplied value(s), any resource references at the specified paths will have their
|
||||
* resource versions encoded instead of being automatically stripped during the encoding
|
||||
|
@ -440,7 +375,7 @@ public interface IParser {
|
|||
|
||||
/**
|
||||
* Returns the value supplied to {@link IParser#setDontStripVersionsFromReferencesAtPaths(String...)}
|
||||
* or <code>null</code> if no value has been set for this parser (in which case the default from
|
||||
* or <code>null</code> if no value has been set for this parser (in which case the default from
|
||||
* the {@link ParserOptions} will be used}
|
||||
*
|
||||
* @see #setDontStripVersionsFromReferencesAtPaths(String...)
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.parser;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -19,10 +19,7 @@ package ca.uhn.fhir.parser;
|
|||
* limitations under the License.
|
||||
* #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.*;
|
||||
import java.math.BigDecimal;
|
||||
|
@ -42,7 +39,8 @@ import ca.uhn.fhir.model.api.*;
|
|||
import ca.uhn.fhir.model.api.annotation.Child;
|
||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||
import ca.uhn.fhir.model.base.composite.BaseContainedDt;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.narrative.INarrativeGenerator;
|
||||
import ca.uhn.fhir.parser.json.*;
|
||||
import ca.uhn.fhir.parser.json.JsonLikeValue.ScalarType;
|
||||
|
@ -56,26 +54,8 @@ import ca.uhn.fhir.util.ElementUtil;
|
|||
*/
|
||||
public class JsonParser extends BaseParser implements IJsonLikeParser {
|
||||
|
||||
private static final Set<String> BUNDLE_TEXTNODE_CHILDREN_DSTU1;
|
||||
private static final Set<String> BUNDLE_TEXTNODE_CHILDREN_DSTU2;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParser.HeldExtension.class);
|
||||
|
||||
static {
|
||||
HashSet<String> hashSetDstu1 = new HashSet<String>();
|
||||
hashSetDstu1.add("title");
|
||||
hashSetDstu1.add("id");
|
||||
hashSetDstu1.add("updated");
|
||||
hashSetDstu1.add("published");
|
||||
hashSetDstu1.add("totalResults");
|
||||
BUNDLE_TEXTNODE_CHILDREN_DSTU1 = Collections.unmodifiableSet(hashSetDstu1);
|
||||
|
||||
HashSet<String> hashSetDstu2 = new HashSet<String>();
|
||||
hashSetDstu2.add("type");
|
||||
hashSetDstu2.add("base");
|
||||
hashSetDstu2.add("total");
|
||||
BUNDLE_TEXTNODE_CHILDREN_DSTU2 = Collections.unmodifiableSet(hashSetDstu2);
|
||||
}
|
||||
|
||||
private FhirContext myContext;
|
||||
private boolean myPrettyPrint;
|
||||
|
||||
|
@ -105,7 +85,8 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean addToHeldExtensions(int valueIdx, List<? extends IBaseExtension<?, ?>> ext, ArrayList<ArrayList<HeldExtension>> list, boolean theIsModifier, CompositeChildElement theChildElem, CompositeChildElement theParent) {
|
||||
private boolean addToHeldExtensions(int valueIdx, List<? extends IBaseExtension<?, ?>> ext, ArrayList<ArrayList<HeldExtension>> list, boolean theIsModifier, CompositeChildElement theChildElem,
|
||||
CompositeChildElement theParent) {
|
||||
if (ext.size() > 0) {
|
||||
list.ensureCapacity(valueIdx);
|
||||
while (list.size() <= valueIdx) {
|
||||
|
@ -132,15 +113,15 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
}
|
||||
}
|
||||
|
||||
// private void assertObjectOfType(JsonLikeValue theResourceTypeObj, Object theValueType, String thePosition) {
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
// private void assertObjectOfType(JsonLikeValue theResourceTypeObj, Object theValueType, String thePosition) {
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void beginArray(JsonLikeWriter theEventWriter, String arrayName) throws IOException {
|
||||
theEventWriter.beginArray(arrayName);
|
||||
|
@ -156,33 +137,13 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doEncodeBundleToWriter(Bundle theBundle, Writer theWriter) throws IOException {
|
||||
JsonLikeWriter eventWriter = createJsonWriter(theWriter);
|
||||
doEncodeBundleToJsonLikeWriter(theBundle, eventWriter);
|
||||
}
|
||||
|
||||
public void doEncodeBundleToJsonLikeWriter(Bundle theBundle, JsonLikeWriter theEventWriter) throws IOException {
|
||||
if (myPrettyPrint) {
|
||||
theEventWriter.setPrettyPrint(myPrettyPrint);
|
||||
}
|
||||
theEventWriter.init();
|
||||
|
||||
if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
encodeBundleToWriterInDstu2Format(theBundle, theEventWriter);
|
||||
} else {
|
||||
encodeBundleToWriterInDstu1Format(theBundle, theEventWriter);
|
||||
}
|
||||
theEventWriter.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doEncodeResourceToWriter(IBaseResource theResource, Writer theWriter) throws IOException {
|
||||
JsonLikeWriter eventWriter = createJsonWriter(theWriter);
|
||||
doEncodeResourceToJsonLikeWriter(theResource, eventWriter);
|
||||
}
|
||||
|
||||
public void doEncodeResourceToJsonLikeWriter(IBaseResource theResource, JsonLikeWriter theEventWriter) throws IOException {
|
||||
|
||||
public void doEncodeResourceToJsonLikeWriter(IBaseResource theResource, JsonLikeWriter theEventWriter) throws IOException {
|
||||
if (myPrettyPrint) {
|
||||
theEventWriter.setPrettyPrint(myPrettyPrint);
|
||||
}
|
||||
|
@ -197,213 +158,38 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
public <T extends IBaseResource> T doParseResource(Class<T> theResourceType, Reader theReader) {
|
||||
JsonLikeStructure jsonStructure = new GsonStructure();
|
||||
jsonStructure.load(theReader);
|
||||
|
||||
|
||||
T retVal = doParseResource(theResourceType, jsonStructure);
|
||||
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public <T extends IBaseResource> T doParseResource(Class<T> theResourceType, JsonLikeStructure theJsonStructure) {
|
||||
JsonLikeObject object = theJsonStructure.getRootObject();
|
||||
|
||||
JsonLikeValue resourceTypeObj = object.get("resourceType");
|
||||
if (resourceTypeObj == null || !resourceTypeObj.isString() || isBlank(resourceTypeObj.getAsString())) {
|
||||
throw new DataFormatException("Invalid JSON content detected, missing required element: 'resourceType'");
|
||||
}
|
||||
|
||||
String resourceType = resourceTypeObj.getAsString();
|
||||
JsonLikeObject object = theJsonStructure.getRootObject();
|
||||
|
||||
ParserState<? extends IBaseResource> state = ParserState.getPreResourceInstance(this, theResourceType, myContext, true, getErrorHandler());
|
||||
state.enteringNewElement(null, resourceType);
|
||||
JsonLikeValue resourceTypeObj = object.get("resourceType");
|
||||
if (resourceTypeObj == null || !resourceTypeObj.isString() || isBlank(resourceTypeObj.getAsString())) {
|
||||
throw new DataFormatException("Invalid JSON content detected, missing required element: 'resourceType'");
|
||||
}
|
||||
|
||||
parseChildren(object, state);
|
||||
String resourceType = resourceTypeObj.getAsString();
|
||||
|
||||
state.endingElement();
|
||||
state.endingElement();
|
||||
ParserState<? extends IBaseResource> state = ParserState.getPreResourceInstance(this, theResourceType, myContext, true, getErrorHandler());
|
||||
state.enteringNewElement(null, resourceType);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T retVal = (T) state.getObject();
|
||||
parseChildren(object, state);
|
||||
|
||||
return retVal;
|
||||
state.endingElement();
|
||||
state.endingElement();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
T retVal = (T) state.getObject();
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeBundleToJsonLikeWriter(Bundle theBundle, JsonLikeWriter theJsonLikeWriter) throws IOException, DataFormatException {
|
||||
Validate.notNull(theBundle, "theBundle must not be null");
|
||||
Validate.notNull(theJsonLikeWriter, "theJsonLikeWriter must not be null");
|
||||
|
||||
doEncodeBundleToJsonLikeWriter(theBundle, theJsonLikeWriter);
|
||||
}
|
||||
|
||||
private void encodeBundleToWriterInDstu1Format(Bundle theBundle, JsonLikeWriter theEventWriter) throws IOException {
|
||||
theEventWriter.beginObject();
|
||||
|
||||
write(theEventWriter, "resourceType", "Bundle");
|
||||
|
||||
writeTagWithTextNode(theEventWriter, "title", theBundle.getTitle());
|
||||
writeTagWithTextNode(theEventWriter, "id", theBundle.getBundleId());
|
||||
writeOptionalTagWithTextNode(theEventWriter, "updated", theBundle.getUpdated());
|
||||
|
||||
boolean linkStarted = false;
|
||||
linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "self", theBundle.getLinkSelf(), linkStarted);
|
||||
linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "first", theBundle.getLinkFirst(), linkStarted);
|
||||
linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "previous", theBundle.getLinkPrevious(), linkStarted);
|
||||
linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "next", theBundle.getLinkNext(), linkStarted);
|
||||
linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "last", theBundle.getLinkLast(), linkStarted);
|
||||
linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "fhir-base", theBundle.getLinkBase(), linkStarted);
|
||||
if (linkStarted) {
|
||||
theEventWriter.endArray();
|
||||
}
|
||||
|
||||
writeCategories(theEventWriter, theBundle.getCategories());
|
||||
|
||||
writeOptionalTagWithTextNode(theEventWriter, "totalResults", theBundle.getTotalResults());
|
||||
|
||||
writeAuthor(theBundle, theEventWriter);
|
||||
|
||||
beginArray(theEventWriter, "entry");
|
||||
for (BundleEntry nextEntry : theBundle.getEntries()) {
|
||||
theEventWriter.beginObject();
|
||||
|
||||
boolean deleted = nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false;
|
||||
if (deleted) {
|
||||
writeTagWithTextNode(theEventWriter, "deleted", nextEntry.getDeletedAt());
|
||||
}
|
||||
writeTagWithTextNode(theEventWriter, "title", nextEntry.getTitle());
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
writeTagWithTextNode(theEventWriter, "id", nextEntry.getId());
|
||||
|
||||
linkStarted = false;
|
||||
linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "self", nextEntry.getLinkSelf(), linkStarted);
|
||||
linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "alternate", nextEntry.getLinkAlternate(), linkStarted);
|
||||
linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "search", nextEntry.getLinkSearch(), linkStarted);
|
||||
if (linkStarted) {
|
||||
theEventWriter.endArray();
|
||||
}
|
||||
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
writeOptionalTagWithTextNode(theEventWriter, "updated", nextEntry.getUpdated());
|
||||
writeOptionalTagWithTextNode(theEventWriter, "published", nextEntry.getPublished());
|
||||
|
||||
writeCategories(theEventWriter, nextEntry.getCategories());
|
||||
|
||||
writeAuthor(nextEntry, theEventWriter);
|
||||
|
||||
IResource resource = nextEntry.getResource();
|
||||
if (resource != null && !resource.isEmpty() && !deleted) {
|
||||
RuntimeResourceDefinition resDef = myContext.getResourceDefinition(resource);
|
||||
encodeResourceToJsonStreamWriter(resDef, resource, theEventWriter, "content", false, true);
|
||||
}
|
||||
|
||||
if (nextEntry.getSummary().isEmpty() == false) {
|
||||
write(theEventWriter, "summary", nextEntry.getSummary().getValueAsString());
|
||||
}
|
||||
|
||||
theEventWriter.endObject(); // entry object
|
||||
}
|
||||
theEventWriter.endArray(); // entry array
|
||||
|
||||
theEventWriter.endObject(); // resource object
|
||||
}
|
||||
|
||||
private void encodeBundleToWriterInDstu2Format(Bundle theBundle, JsonLikeWriter theEventWriter) throws IOException {
|
||||
theEventWriter.beginObject();
|
||||
|
||||
write(theEventWriter, "resourceType", "Bundle");
|
||||
|
||||
writeOptionalTagWithTextNode(theEventWriter, "id", theBundle.getId().getIdPart());
|
||||
|
||||
if (!ElementUtil.isEmpty(theBundle.getId().getVersionIdPart(), theBundle.getUpdated())) {
|
||||
beginObject(theEventWriter, "meta");
|
||||
writeOptionalTagWithTextNode(theEventWriter, "versionId", theBundle.getId().getVersionIdPart());
|
||||
writeOptionalTagWithTextNode(theEventWriter, "lastUpdated", theBundle.getUpdated());
|
||||
theEventWriter.endObject();
|
||||
}
|
||||
|
||||
writeOptionalTagWithTextNode(theEventWriter, "type", theBundle.getType());
|
||||
|
||||
writeOptionalTagWithNumberNode(theEventWriter, "total", theBundle.getTotalResults());
|
||||
|
||||
boolean linkStarted = false;
|
||||
linkStarted = writeAtomLinkInDstu2Format(theEventWriter, "next", theBundle.getLinkNext(), linkStarted);
|
||||
linkStarted = writeAtomLinkInDstu2Format(theEventWriter, "self", theBundle.getLinkSelf(), linkStarted);
|
||||
linkStarted = writeAtomLinkInDstu2Format(theEventWriter, "first", theBundle.getLinkFirst(), linkStarted);
|
||||
linkStarted = writeAtomLinkInDstu2Format(theEventWriter, "previous", theBundle.getLinkPrevious(), linkStarted);
|
||||
linkStarted = writeAtomLinkInDstu2Format(theEventWriter, "last", theBundle.getLinkLast(), linkStarted);
|
||||
if (linkStarted) {
|
||||
theEventWriter.endArray();
|
||||
}
|
||||
|
||||
beginArray(theEventWriter, "entry");
|
||||
for (BundleEntry nextEntry : theBundle.getEntries()) {
|
||||
theEventWriter.beginObject();
|
||||
|
||||
if (nextEntry.getResource() != null && isNotBlank(nextEntry.getResource().getIdElement().getValue()) && (nextEntry.getResource().getId().getBaseUrl() != null || nextEntry.getResource().getId().getValueAsString().startsWith("urn:"))) {
|
||||
writeOptionalTagWithTextNode(theEventWriter, "fullUrl", nextEntry.getResource().getId().getValue());
|
||||
}
|
||||
|
||||
boolean deleted = nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false;
|
||||
IResource resource = nextEntry.getResource();
|
||||
if (resource != null && !resource.isEmpty() && !deleted) {
|
||||
RuntimeResourceDefinition resDef = myContext.getResourceDefinition(resource);
|
||||
encodeResourceToJsonStreamWriter(resDef, resource, theEventWriter, "resource", false, true);
|
||||
}
|
||||
|
||||
if (nextEntry.getSearchMode().isEmpty() == false || nextEntry.getScore().isEmpty() == false) {
|
||||
beginObject(theEventWriter, "search");
|
||||
writeOptionalTagWithTextNode(theEventWriter, "mode", nextEntry.getSearchMode().getValueAsString());
|
||||
writeOptionalTagWithDecimalNode(theEventWriter, "score", nextEntry.getScore());
|
||||
theEventWriter.endObject();
|
||||
// IResource nextResource = nextEntry.getResource();
|
||||
}
|
||||
|
||||
if (nextEntry.getTransactionMethod().isEmpty() == false || nextEntry.getLinkSearch().isEmpty() == false) {
|
||||
beginObject(theEventWriter, "request");
|
||||
writeOptionalTagWithTextNode(theEventWriter, "method", nextEntry.getTransactionMethod().getValue());
|
||||
writeOptionalTagWithTextNode(theEventWriter, "url", nextEntry.getLinkSearch().getValue());
|
||||
theEventWriter.endObject();
|
||||
}
|
||||
|
||||
if (deleted) {
|
||||
beginObject(theEventWriter, "deleted");
|
||||
if (nextEntry.getResource() != null) {
|
||||
write(theEventWriter, "type", myContext.getResourceDefinition(nextEntry.getResource()).getName());
|
||||
writeOptionalTagWithTextNode(theEventWriter, "resourceId", nextEntry.getResource().getId().getIdPart());
|
||||
writeOptionalTagWithTextNode(theEventWriter, "versionId", nextEntry.getResource().getId().getVersionIdPart());
|
||||
}
|
||||
writeTagWithTextNode(theEventWriter, "instant", nextEntry.getDeletedAt());
|
||||
theEventWriter.endObject();
|
||||
}
|
||||
|
||||
// linkStarted = false;
|
||||
// linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "self", nextEntry.getLinkSelf(), linkStarted);
|
||||
// linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "alternate", nextEntry.getLinkAlternate(),
|
||||
// linkStarted);
|
||||
// linkStarted = writeAtomLinkInDstu1Format(theEventWriter, "search", nextEntry.getLinkSearch(),
|
||||
// linkStarted);
|
||||
// if (linkStarted) {
|
||||
// theEventWriter.writeEnd();
|
||||
// }
|
||||
//
|
||||
// writeOptionalTagWithTextNode(theEventWriter, "updated", nextEntry.getUpdated());
|
||||
// writeOptionalTagWithTextNode(theEventWriter, "published", nextEntry.getPublished());
|
||||
//
|
||||
// writeCategories(theEventWriter, nextEntry.getCategories());
|
||||
//
|
||||
// writeAuthor(nextEntry, theEventWriter);
|
||||
|
||||
if (nextEntry.getSummary().isEmpty() == false) {
|
||||
write(theEventWriter, "summary", nextEntry.getSummary().getValueAsString());
|
||||
}
|
||||
|
||||
theEventWriter.endObject(); // entry object
|
||||
}
|
||||
theEventWriter.endArray(); // entry array
|
||||
|
||||
theEventWriter.endObject(); // resource object
|
||||
}
|
||||
|
||||
private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonLikeWriter theEventWriter, IBase theNextValue, BaseRuntimeElementDefinition<?> theChildDef, String theChildName, boolean theContainedResource, CompositeChildElement theChildElem,
|
||||
private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonLikeWriter theEventWriter, IBase theNextValue,
|
||||
BaseRuntimeElementDefinition<?> theChildDef, String theChildName, boolean theContainedResource, CompositeChildElement theChildElem,
|
||||
boolean theForceEmpty) throws IOException {
|
||||
|
||||
switch (theChildDef.getChildType()) {
|
||||
|
@ -531,7 +317,8 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
|
||||
}
|
||||
|
||||
private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theElement, JsonLikeWriter theEventWriter, boolean theContainedResource, CompositeChildElement theParent) throws IOException {
|
||||
private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theElement, JsonLikeWriter theEventWriter,
|
||||
boolean theContainedResource, CompositeChildElement theParent) throws IOException {
|
||||
|
||||
{
|
||||
String elementId = getCompositeElementId(theElement);
|
||||
|
@ -545,7 +332,8 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
|
||||
BaseRuntimeChildDefinition nextChild = nextChildElem.getDef();
|
||||
|
||||
if (nextChildElem.getDef().getElementName().equals("extension") || nextChildElem.getDef().getElementName().equals("modifierExtension") || nextChild instanceof RuntimeChildDeclaredExtensionDefinition) {
|
||||
if (nextChildElem.getDef().getElementName().equals("extension") || nextChildElem.getDef().getElementName().equals("modifierExtension")
|
||||
|| nextChild instanceof RuntimeChildDeclaredExtensionDefinition) {
|
||||
if (!haveWrittenExtensions) {
|
||||
extractAndWriteExtensionsAsDirectChild(theElement, theEventWriter, myContext.getElementDefinition(theElement.getClass()), theResDef, theResource, nextChildElem, theParent);
|
||||
haveWrittenExtensions = true;
|
||||
|
@ -614,7 +402,7 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
if (childNameAndDef == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
String childName = childNameAndDef.getChildName();
|
||||
BaseRuntimeElementDefinition<?> childDef = childNameAndDef.getChildDef();
|
||||
boolean primitive = childDef.getChildType() == ChildTypeEnum.PRIMITIVE_DATATYPE;
|
||||
|
@ -750,7 +538,8 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theNextValue, JsonLikeWriter theEventWriter, boolean theContainedResource, CompositeChildElement theParent) throws IOException, DataFormatException {
|
||||
private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theNextValue, JsonLikeWriter theEventWriter, boolean theContainedResource,
|
||||
CompositeChildElement theParent) throws IOException, DataFormatException {
|
||||
|
||||
writeCommentsPreAndPost(theNextValue, theEventWriter);
|
||||
encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theNextValue, theEventWriter, theContainedResource, theParent);
|
||||
|
@ -762,38 +551,37 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
Validate.notNull(theJsonLikeWriter, "theJsonLikeWriter can not be null");
|
||||
|
||||
if (theResource.getStructureFhirVersionEnum() != myContext.getVersion().getVersion()) {
|
||||
throw new IllegalArgumentException("This parser is for FHIR version " + myContext.getVersion().getVersion() + " - Can not encode a structure for version " + theResource.getStructureFhirVersionEnum());
|
||||
throw new IllegalArgumentException(
|
||||
"This parser is for FHIR version " + myContext.getVersion().getVersion() + " - Can not encode a structure for version " + theResource.getStructureFhirVersionEnum());
|
||||
}
|
||||
|
||||
doEncodeResourceToJsonLikeWriter(theResource, theJsonLikeWriter);
|
||||
}
|
||||
|
||||
private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonLikeWriter theEventWriter, String theObjectNameOrNull, boolean theContainedResource, boolean theSubResource) throws IOException {
|
||||
private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonLikeWriter theEventWriter, String theObjectNameOrNull,
|
||||
boolean theContainedResource, boolean theSubResource) throws IOException {
|
||||
IIdType resourceId = null;
|
||||
// if (theResource instanceof IResource) {
|
||||
// IResource res = (IResource) theResource;
|
||||
// if (StringUtils.isNotBlank(res.getId().getIdPart())) {
|
||||
// if (theContainedResource) {
|
||||
// resourceId = res.getId().getIdPart();
|
||||
// } else if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
// resourceId = res.getId().getIdPart();
|
||||
// }
|
||||
// }
|
||||
// } else if (theResource instanceof IAnyResource) {
|
||||
// IAnyResource res = (IAnyResource) theResource;
|
||||
// if (/* theContainedResource && */StringUtils.isNotBlank(res.getIdElement().getIdPart())) {
|
||||
// resourceId = res.getIdElement().getIdPart();
|
||||
// }
|
||||
// }
|
||||
// if (theResource instanceof IResource) {
|
||||
// IResource res = (IResource) theResource;
|
||||
// if (StringUtils.isNotBlank(res.getId().getIdPart())) {
|
||||
// if (theContainedResource) {
|
||||
// resourceId = res.getId().getIdPart();
|
||||
// } else if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
// resourceId = res.getId().getIdPart();
|
||||
// }
|
||||
// }
|
||||
// } else if (theResource instanceof IAnyResource) {
|
||||
// IAnyResource res = (IAnyResource) theResource;
|
||||
// if (/* theContainedResource && */StringUtils.isNotBlank(res.getIdElement().getIdPart())) {
|
||||
// resourceId = res.getIdElement().getIdPart();
|
||||
// }
|
||||
// }
|
||||
|
||||
if (StringUtils.isNotBlank(theResource.getIdElement().getIdPart())) {
|
||||
resourceId = theResource.getIdElement();
|
||||
if (theResource.getIdElement().getValue().startsWith("urn:")) {
|
||||
resourceId = null;
|
||||
}
|
||||
if (myContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
|
||||
resourceId = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!theContainedResource) {
|
||||
|
@ -807,7 +595,8 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
encodeResourceToJsonStreamWriter(theResDef, theResource, theEventWriter, theObjectNameOrNull, theContainedResource, resourceId);
|
||||
}
|
||||
|
||||
private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonLikeWriter theEventWriter, String theObjectNameOrNull, boolean theContainedResource, IIdType theResourceId) throws IOException {
|
||||
private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonLikeWriter theEventWriter, String theObjectNameOrNull,
|
||||
boolean theContainedResource, IIdType theResourceId) throws IOException {
|
||||
if (!theContainedResource) {
|
||||
super.containResourcesForEncoding(theResource);
|
||||
}
|
||||
|
@ -830,7 +619,7 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
}
|
||||
}
|
||||
|
||||
if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1) && theResource instanceof IResource) {
|
||||
if (theResource instanceof IResource) {
|
||||
IResource resource = (IResource) theResource;
|
||||
// Object securityLabelRawObj =
|
||||
|
||||
|
@ -907,52 +696,15 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
theEventWriter.endObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeTagListToWriter(TagList theTagList, Writer theWriter) throws IOException {
|
||||
JsonLikeWriter theEventWriter = createJsonWriter(theWriter);
|
||||
encodeTagListToJsonLikeWriter(theTagList, theEventWriter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeTagListToJsonLikeWriter(TagList theTagList, JsonLikeWriter theEventWriter) throws IOException {
|
||||
if (myPrettyPrint) {
|
||||
theEventWriter.setPrettyPrint(myPrettyPrint);
|
||||
}
|
||||
theEventWriter.init();
|
||||
|
||||
theEventWriter.beginObject();
|
||||
|
||||
write(theEventWriter, "resourceType", TagList.ELEMENT_NAME);
|
||||
|
||||
beginArray(theEventWriter, TagList.ATTR_CATEGORY);
|
||||
for (Tag next : theTagList) {
|
||||
theEventWriter.beginObject();
|
||||
|
||||
if (isNotBlank(next.getTerm())) {
|
||||
write(theEventWriter, Tag.ATTR_TERM, next.getTerm());
|
||||
}
|
||||
if (isNotBlank(next.getLabel())) {
|
||||
write(theEventWriter, Tag.ATTR_LABEL, next.getLabel());
|
||||
}
|
||||
if (isNotBlank(next.getScheme())) {
|
||||
write(theEventWriter, Tag.ATTR_SCHEME, next.getScheme());
|
||||
}
|
||||
|
||||
theEventWriter.endObject();
|
||||
}
|
||||
theEventWriter.endArray();
|
||||
|
||||
theEventWriter.endObject();
|
||||
theEventWriter.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param theChildElem
|
||||
* @param theParent
|
||||
*
|
||||
* @param theChildElem
|
||||
* @param theParent
|
||||
*/
|
||||
private void extractAndWriteExtensionsAsDirectChild(IBase theElement, JsonLikeWriter theEventWriter, BaseRuntimeElementDefinition<?> theElementDef, RuntimeResourceDefinition theResDef, IBaseResource theResource, CompositeChildElement theChildElem, CompositeChildElement theParent) throws IOException {
|
||||
private void extractAndWriteExtensionsAsDirectChild(IBase theElement, JsonLikeWriter theEventWriter, BaseRuntimeElementDefinition<?> theElementDef, RuntimeResourceDefinition theResDef,
|
||||
IBaseResource theResource, CompositeChildElement theChildElem, CompositeChildElement theParent) throws IOException {
|
||||
List<HeldExtension> extensions = new ArrayList<HeldExtension>(0);
|
||||
List<HeldExtension> modifierExtensions = new ArrayList<HeldExtension>(0);
|
||||
|
||||
|
@ -968,7 +720,8 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
writeExtensionsAsDirectChild(theResource, theEventWriter, theResDef, extensions, modifierExtensions);
|
||||
}
|
||||
|
||||
private void extractDeclaredExtensions(IBase theResource, BaseRuntimeElementDefinition<?> resDef, List<HeldExtension> extensions, List<HeldExtension> modifierExtensions, CompositeChildElement theChildElem) {
|
||||
private void extractDeclaredExtensions(IBase theResource, BaseRuntimeElementDefinition<?> resDef, List<HeldExtension> extensions, List<HeldExtension> modifierExtensions,
|
||||
CompositeChildElement theChildElem) {
|
||||
for (RuntimeChildDeclaredExtensionDefinition nextDef : resDef.getExtensionsNonModifier()) {
|
||||
for (IBase nextValue : nextDef.getAccessor().getValues(theResource)) {
|
||||
if (nextValue != null) {
|
||||
|
@ -991,7 +744,8 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void extractUndeclaredExtensions(IBase theElement, List<HeldExtension> extensions, List<HeldExtension> modifierExtensions, CompositeChildElement theChildElem, CompositeChildElement theParent) {
|
||||
private void extractUndeclaredExtensions(IBase theElement, List<HeldExtension> extensions, List<HeldExtension> modifierExtensions, CompositeChildElement theChildElem,
|
||||
CompositeChildElement theParent) {
|
||||
if (theElement instanceof ISupportsUndeclaredExtensions) {
|
||||
ISupportsUndeclaredExtensions element = (ISupportsUndeclaredExtensions) theElement;
|
||||
List<ExtensionDt> ext = element.getUndeclaredExtensions();
|
||||
|
@ -1049,36 +803,36 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
return object.getAsArray();
|
||||
}
|
||||
|
||||
// private JsonObject parse(Reader theReader) {
|
||||
//
|
||||
// PushbackReader pbr = new PushbackReader(theReader);
|
||||
// JsonObject object;
|
||||
// try {
|
||||
// while(true) {
|
||||
// int nextInt;
|
||||
// nextInt = pbr.read();
|
||||
// if (nextInt == -1) {
|
||||
// throw new DataFormatException("Did not find any content to parse");
|
||||
// }
|
||||
// if (nextInt == '{') {
|
||||
// pbr.unread('{');
|
||||
// break;
|
||||
// }
|
||||
// if (Character.isWhitespace(nextInt)) {
|
||||
// continue;
|
||||
// }
|
||||
// throw new DataFormatException("Content does not appear to be FHIR JSON, first non-whitespace character was: '" + (char)nextInt + "' (must be '{')");
|
||||
// }
|
||||
//
|
||||
// Gson gson = newGson();
|
||||
//
|
||||
// object = gson.fromJson(pbr, JsonObject.class);
|
||||
// } catch (Exception e) {
|
||||
// throw new DataFormatException("Failed to parse JSON content, error was: " + e.getMessage(), e);
|
||||
// }
|
||||
//
|
||||
// return object;
|
||||
// }
|
||||
// private JsonObject parse(Reader theReader) {
|
||||
//
|
||||
// PushbackReader pbr = new PushbackReader(theReader);
|
||||
// JsonObject object;
|
||||
// try {
|
||||
// while(true) {
|
||||
// int nextInt;
|
||||
// nextInt = pbr.read();
|
||||
// if (nextInt == -1) {
|
||||
// throw new DataFormatException("Did not find any content to parse");
|
||||
// }
|
||||
// if (nextInt == '{') {
|
||||
// pbr.unread('{');
|
||||
// break;
|
||||
// }
|
||||
// if (Character.isWhitespace(nextInt)) {
|
||||
// continue;
|
||||
// }
|
||||
// throw new DataFormatException("Content does not appear to be FHIR JSON, first non-whitespace character was: '" + (char)nextInt + "' (must be '{')");
|
||||
// }
|
||||
//
|
||||
// Gson gson = newGson();
|
||||
//
|
||||
// object = gson.fromJson(pbr, JsonObject.class);
|
||||
// } catch (Exception e) {
|
||||
// throw new DataFormatException("Failed to parse JSON content, error was: " + e.getMessage(), e);
|
||||
// }
|
||||
//
|
||||
// return object;
|
||||
// }
|
||||
|
||||
private void parseAlternates(JsonLikeValue theAlternateVal, ParserState<?> theState, String theElementName, String theAlternateName) {
|
||||
if (theAlternateVal == null || theAlternateVal.isNull()) {
|
||||
|
@ -1126,129 +880,6 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IBaseResource> Bundle parseBundle(Class<T> theResourceType, Reader theReader) {
|
||||
JsonLikeStructure jsonStructure = new GsonStructure();
|
||||
jsonStructure.load(theReader);
|
||||
|
||||
Bundle retVal = parseBundle(theResourceType, jsonStructure);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle parseBundle(JsonLikeStructure theJsonLikeStructure) throws DataFormatException {
|
||||
return parseBundle(null, theJsonLikeStructure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IBaseResource> Bundle parseBundle(Class<T> theResourceType, JsonLikeStructure theJsonStructure) {
|
||||
JsonLikeObject object = theJsonStructure.getRootObject();
|
||||
|
||||
JsonLikeValue resourceTypeObj = object.get("resourceType");
|
||||
if (resourceTypeObj == null || !resourceTypeObj.isString()) {
|
||||
throw new DataFormatException("Invalid JSON content detected, missing required element: 'resourceType'");
|
||||
}
|
||||
String resourceType = resourceTypeObj.getAsString();
|
||||
if (!"Bundle".equals(resourceType)) {
|
||||
throw new DataFormatException("Trying to parse bundle but found resourceType other than 'Bundle'. Found: '" + resourceType + "'");
|
||||
}
|
||||
|
||||
ParserState<Bundle> state = ParserState.getPreAtomInstance(this, myContext, theResourceType, true, getErrorHandler());
|
||||
if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
state.enteringNewElement(null, "Bundle");
|
||||
} else {
|
||||
state.enteringNewElement(null, "feed");
|
||||
}
|
||||
|
||||
parseBundleChildren(object, state);
|
||||
|
||||
state.endingElement();
|
||||
state.endingElement();
|
||||
|
||||
Bundle retVal = state.getObject();
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private void parseBundleChildren(JsonLikeObject theObject, ParserState<?> theState) {
|
||||
for (String nextName : theObject.keySet()) {
|
||||
if ("resourceType".equals(nextName)) {
|
||||
continue;
|
||||
} else if ("entry".equals(nextName)) {
|
||||
JsonLikeArray entries = grabJsonArray(theObject, nextName, "entry");
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
JsonLikeValue jsonValue = entries.get(i);
|
||||
theState.enteringNewElement(null, "entry");
|
||||
parseBundleChildren(jsonValue.getAsObject(), theState);
|
||||
theState.endingElement();
|
||||
}
|
||||
continue;
|
||||
} else if (myContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
if ("link".equals(nextName)) {
|
||||
JsonLikeArray entries = grabJsonArray(theObject, nextName, "link");
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
JsonLikeValue jsonValue = entries.get(i);
|
||||
theState.enteringNewElement(null, "link");
|
||||
JsonLikeObject linkObj = jsonValue.getAsObject();
|
||||
String rel = linkObj.getString("rel", null);
|
||||
String href = linkObj.getString("href", null);
|
||||
theState.attributeValue("rel", rel);
|
||||
theState.attributeValue("href", href);
|
||||
theState.endingElement();
|
||||
}
|
||||
continue;
|
||||
} else if (BUNDLE_TEXTNODE_CHILDREN_DSTU1.contains(nextName)) {
|
||||
theState.enteringNewElement(null, nextName);
|
||||
JsonLikeValue jsonElement = theObject.get(nextName);
|
||||
if (jsonElement.isScalar()) {
|
||||
theState.string(jsonElement.getAsString());
|
||||
}
|
||||
theState.endingElement();
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if ("link".equals(nextName)) {
|
||||
JsonLikeArray entries = grabJsonArray(theObject, nextName, "link");
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
JsonLikeValue jsonValue = entries.get(i);
|
||||
theState.enteringNewElement(null, "link");
|
||||
JsonLikeObject linkObj = jsonValue.getAsObject();
|
||||
String rel = linkObj.getString("relation", null);
|
||||
String href = linkObj.getString("url", null);
|
||||
theState.enteringNewElement(null, "relation");
|
||||
theState.attributeValue("value", rel);
|
||||
theState.endingElement();
|
||||
theState.enteringNewElement(null, "url");
|
||||
theState.attributeValue("value", href);
|
||||
theState.endingElement();
|
||||
theState.endingElement();
|
||||
}
|
||||
continue;
|
||||
} else if (BUNDLE_TEXTNODE_CHILDREN_DSTU2.contains(nextName)) {
|
||||
theState.enteringNewElement(null, nextName);
|
||||
// String obj = theObject.getString(nextName, null);
|
||||
|
||||
JsonLikeValue obj = theObject.get(nextName);
|
||||
if (obj == null || obj.isNull()) {
|
||||
theState.attributeValue("value", null);
|
||||
} else if (obj.isScalar()) {
|
||||
theState.attributeValue("value", obj.getAsString());
|
||||
} else {
|
||||
throw new DataFormatException("Unexpected JSON object for entry '" + nextName + "'");
|
||||
}
|
||||
|
||||
theState.endingElement();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
JsonLikeValue nextVal = theObject.get(nextName);
|
||||
parseChildren(theState, nextName, nextVal, null, null, false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void parseChildren(JsonLikeObject theObject, ParserState<?> theState) {
|
||||
Set<String> keySet = theObject.keySet();
|
||||
|
||||
|
@ -1280,19 +911,19 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
if (alternateVal != null) {
|
||||
handledUnderscoreNames++;
|
||||
}
|
||||
|
||||
|
||||
parseChildren(theState, nextName, nextVal, alternateVal, alternateName, false);
|
||||
|
||||
}
|
||||
|
||||
// if (elementId != null) {
|
||||
// IBase object = (IBase) theState.getObject();
|
||||
// if (object instanceof IIdentifiableElement) {
|
||||
// ((IIdentifiableElement) object).setElementSpecificId(elementId);
|
||||
// } else if (object instanceof IBaseResource) {
|
||||
// ((IBaseResource) object).getIdElement().setValue(elementId);
|
||||
// }
|
||||
// }
|
||||
// if (elementId != null) {
|
||||
// IBase object = (IBase) theState.getObject();
|
||||
// if (object instanceof IIdentifiableElement) {
|
||||
// ((IIdentifiableElement) object).setElementSpecificId(elementId);
|
||||
// } else if (object instanceof IBaseResource) {
|
||||
// ((IBaseResource) object).getIdElement().setValue(elementId);
|
||||
// }
|
||||
// }
|
||||
|
||||
/*
|
||||
* This happens if an element has an extension but no actual value. I.e.
|
||||
|
@ -1351,7 +982,7 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
if (!theInArray && theState.elementIsRepeating(theName)) {
|
||||
getErrorHandler().incorrectJsonType(null, theName, ValueType.ARRAY, null, ValueType.OBJECT, null);
|
||||
}
|
||||
|
||||
|
||||
theState.enteringNewElement(null, theName);
|
||||
parseAlternates(theAlternateVal, theState, theAlternateName, theAlternateName);
|
||||
JsonLikeObject nextObject = theJsonVal.getAsObject();
|
||||
|
@ -1435,17 +1066,17 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
|
||||
@Override
|
||||
public <T extends IBaseResource> T parseResource(Class<T> theResourceType, JsonLikeStructure theJsonLikeStructure) throws DataFormatException {
|
||||
|
||||
|
||||
/*****************************************************
|
||||
* ************************************************* *
|
||||
* ** NOTE: this duplicates most of the code in ** *
|
||||
* ** NOTE: this duplicates most of the code in ** *
|
||||
* ** BaseParser.parseResource(Class<T>, Reader). ** *
|
||||
* ** Unfortunately, there is no way to avoid ** *
|
||||
* ** this without doing some refactoring of the ** *
|
||||
* ** BaseParser class. ** *
|
||||
* ** Unfortunately, there is no way to avoid ** *
|
||||
* ** this without doing some refactoring of the ** *
|
||||
* ** BaseParser class. ** *
|
||||
* ************************************************* *
|
||||
*****************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* We do this so that the context can verify that the structure is for
|
||||
* the correct FHIR version
|
||||
|
@ -1504,34 +1135,6 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
return parseResource(null, theJsonLikeStructure);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagList parseTagList(Reader theReader) {
|
||||
JsonLikeStructure jsonStructure = new GsonStructure();
|
||||
jsonStructure.load(theReader);
|
||||
|
||||
TagList retVal = parseTagList(jsonStructure);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagList parseTagList(JsonLikeStructure theJsonStructure) {
|
||||
JsonLikeObject object = theJsonStructure.getRootObject();
|
||||
|
||||
JsonLikeValue resourceTypeObj = object.get("resourceType");
|
||||
String resourceType = resourceTypeObj.getAsString();
|
||||
|
||||
ParserState<TagList> state = ParserState.getPreTagListInstance(this, myContext, true, getErrorHandler());
|
||||
state.enteringNewElement(null, resourceType);
|
||||
|
||||
parseChildren(object, state);
|
||||
|
||||
state.endingElement();
|
||||
state.endingElement();
|
||||
|
||||
return state.getObject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParser setPrettyPrint(boolean thePrettyPrint) {
|
||||
myPrettyPrint = thePrettyPrint;
|
||||
|
@ -1578,63 +1181,6 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
theEventWriter.write(theChildName, theValue);
|
||||
}
|
||||
|
||||
private boolean writeAtomLinkInDstu1Format(JsonLikeWriter theEventWriter, String theRel, StringDt theLink, boolean theStarted) throws IOException {
|
||||
boolean retVal = theStarted;
|
||||
if (isNotBlank(theLink.getValue())) {
|
||||
if (theStarted == false) {
|
||||
theEventWriter.beginArray("link");
|
||||
retVal = true;
|
||||
}
|
||||
|
||||
theEventWriter.beginObject();
|
||||
write(theEventWriter, "rel", theRel);
|
||||
write(theEventWriter, "href", theLink.getValue());
|
||||
theEventWriter.endObject();
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private boolean writeAtomLinkInDstu2Format(JsonLikeWriter theEventWriter, String theRel, StringDt theLink, boolean theStarted) throws IOException {
|
||||
boolean retVal = theStarted;
|
||||
if (isNotBlank(theLink.getValue())) {
|
||||
if (theStarted == false) {
|
||||
theEventWriter.beginArray("link");
|
||||
retVal = true;
|
||||
}
|
||||
|
||||
theEventWriter.beginObject();
|
||||
write(theEventWriter, "relation", theRel);
|
||||
write(theEventWriter, "url", theLink.getValue());
|
||||
theEventWriter.endObject();
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private void writeAuthor(BaseBundle theBundle, JsonLikeWriter theEventWriter) throws IOException {
|
||||
if (StringUtils.isNotBlank(theBundle.getAuthorName().getValue())) {
|
||||
beginArray(theEventWriter, "author");
|
||||
theEventWriter.beginObject();
|
||||
writeTagWithTextNode(theEventWriter, "name", theBundle.getAuthorName());
|
||||
writeOptionalTagWithTextNode(theEventWriter, "uri", theBundle.getAuthorUri());
|
||||
theEventWriter.endObject();
|
||||
theEventWriter.endArray();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeCategories(JsonLikeWriter theEventWriter, TagList categories) throws IOException {
|
||||
if (categories != null && categories.size() > 0) {
|
||||
theEventWriter.beginArray("category");
|
||||
for (Tag next : categories) {
|
||||
theEventWriter.beginObject();
|
||||
write(theEventWriter, "term", defaultString(next.getTerm()));
|
||||
write(theEventWriter, "label", defaultString(next.getLabel()));
|
||||
write(theEventWriter, "scheme", defaultString(next.getScheme()));
|
||||
theEventWriter.endObject();
|
||||
}
|
||||
theEventWriter.endArray();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeCommentsPreAndPost(IBase theNextValue, JsonLikeWriter theEventWriter) throws IOException {
|
||||
if (theNextValue.hasFormatComment()) {
|
||||
beginArray(theEventWriter, "fhir_comments");
|
||||
|
@ -1654,7 +1200,8 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void writeExtensionsAsDirectChild(IBaseResource theResource, JsonLikeWriter theEventWriter, RuntimeResourceDefinition resDef, List<HeldExtension> extensions, List<HeldExtension> modifierExtensions) throws IOException {
|
||||
private void writeExtensionsAsDirectChild(IBaseResource theResource, JsonLikeWriter theEventWriter, RuntimeResourceDefinition resDef, List<HeldExtension> extensions,
|
||||
List<HeldExtension> modifierExtensions) throws IOException {
|
||||
if (extensions.isEmpty() == false) {
|
||||
beginArray(theEventWriter, "extension");
|
||||
for (HeldExtension next : extensions) {
|
||||
|
@ -1671,18 +1218,6 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void writeOptionalTagWithDecimalNode(JsonLikeWriter theEventWriter, String theElementName, DecimalDt theValue) throws IOException {
|
||||
if (theValue != null && theValue.isEmpty() == false) {
|
||||
write(theEventWriter, theElementName, theValue.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void writeOptionalTagWithNumberNode(JsonLikeWriter theEventWriter, String theElementName, IntegerDt theValue) throws IOException {
|
||||
if (theValue != null && theValue.isEmpty() == false) {
|
||||
write(theEventWriter, theElementName, theValue.getValue().intValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void writeOptionalTagWithTextNode(JsonLikeWriter theEventWriter, String theElementName, IPrimitiveDatatype<?> thePrimitive) throws IOException {
|
||||
if (thePrimitive == null) {
|
||||
return;
|
||||
|
@ -1697,32 +1232,15 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void writeTagWithTextNode(JsonLikeWriter theEventWriter, String theElementName, IPrimitiveDatatype<?> theIdDt) throws IOException {
|
||||
if (theIdDt != null && !theIdDt.isEmpty()) {
|
||||
write(theEventWriter, theElementName, theIdDt.getValueAsString());
|
||||
} else {
|
||||
theEventWriter.writeNull(theElementName);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeTagWithTextNode(JsonLikeWriter theEventWriter, String theElementName, StringDt theStringDt) throws IOException {
|
||||
if (StringUtils.isNotBlank(theStringDt.getValue())) {
|
||||
write(theEventWriter, theElementName, theStringDt.getValue());
|
||||
}
|
||||
// else {
|
||||
// theEventWriter.writeNull(theElementName);
|
||||
// }
|
||||
}
|
||||
|
||||
public static Gson newGson() {
|
||||
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
return gson;
|
||||
}
|
||||
|
||||
|
||||
private static void write(JsonLikeWriter theWriter, String theName, String theValue) throws IOException {
|
||||
theWriter.write(theName, theValue);
|
||||
}
|
||||
|
||||
|
||||
private class HeldExtension implements Comparable<HeldExtension> {
|
||||
|
||||
private CompositeChildElement myChildElem;
|
||||
|
@ -1771,25 +1289,25 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
* This makes sure that even if the extension contains a reference to a contained
|
||||
* resource which has a HAPI-assigned ID we'll still encode that ID.
|
||||
*
|
||||
* See #327
|
||||
* See #327
|
||||
*/
|
||||
List<? extends IBase> preProcessedValue = preProcessValues(myDef, theResource, Collections.singletonList(myValue), myChildElem);
|
||||
|
||||
// // Check for undeclared extensions on the declared extension
|
||||
// // (grrrrrr....)
|
||||
// if (myValue instanceof ISupportsUndeclaredExtensions) {
|
||||
// ISupportsUndeclaredExtensions value = (ISupportsUndeclaredExtensions)myValue;
|
||||
// List<ExtensionDt> exts = value.getUndeclaredExtensions();
|
||||
// if (exts.size() > 0) {
|
||||
// ArrayList<IBase> newValueList = new ArrayList<IBase>();
|
||||
// newValueList.addAll(preProcessedValue);
|
||||
// newValueList.addAll(exts);
|
||||
// preProcessedValue = newValueList;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Check for undeclared extensions on the declared extension
|
||||
// // (grrrrrr....)
|
||||
// if (myValue instanceof ISupportsUndeclaredExtensions) {
|
||||
// ISupportsUndeclaredExtensions value = (ISupportsUndeclaredExtensions)myValue;
|
||||
// List<ExtensionDt> exts = value.getUndeclaredExtensions();
|
||||
// if (exts.size() > 0) {
|
||||
// ArrayList<IBase> newValueList = new ArrayList<IBase>();
|
||||
// newValueList.addAll(preProcessedValue);
|
||||
// newValueList.addAll(exts);
|
||||
// preProcessedValue = newValueList;
|
||||
// }
|
||||
// }
|
||||
|
||||
myValue = preProcessedValue.get(0);
|
||||
|
||||
|
||||
BaseRuntimeElementDefinition<?> def = myDef.getChildElementDefinitionByDatatype(myValue.getClass());
|
||||
if (def.getChildType() == ChildTypeEnum.RESOURCE_BLOCK) {
|
||||
extractAndWriteExtensionsAsDirectChild(myValue, theEventWriter, def, theResDef, theResource, myChildElem, null);
|
||||
|
@ -1802,7 +1320,6 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void writeUndeclaredExtension(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonLikeWriter theEventWriter, IBaseExtension<?, ?> ext) throws IOException {
|
||||
IBase value = ext.getValue();
|
||||
final String extensionUrl = getExtensionUrl(ext.getUrl());
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,29 +1,10 @@
|
|||
package ca.uhn.fhir.parser;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2017 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #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 java.io.*;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
@ -38,16 +19,14 @@ import ca.uhn.fhir.model.api.*;
|
|||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.narrative.INarrativeGenerator;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.util.*;
|
||||
|
||||
/**
|
||||
* This class is the FHIR XML parser/encoder. Users should not interact with this class directly, but should use
|
||||
* {@link FhirContext#newXmlParser()} to get an instance.
|
||||
*/
|
||||
public class XmlParser extends BaseParser /*implements IParser */{
|
||||
public class XmlParser extends BaseParser /* implements IParser */ {
|
||||
|
||||
static final String ATOM_NS = "http://www.w3.org/2005/Atom";
|
||||
static final String FHIR_NS = "http://hl7.org/fhir";
|
||||
|
@ -100,20 +79,6 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doEncodeBundleToWriter(Bundle theBundle, Writer theWriter) throws DataFormatException {
|
||||
try {
|
||||
XMLStreamWriter eventWriter = createXmlWriter(theWriter);
|
||||
if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
encodeBundleToWriterDstu2(theBundle, eventWriter);
|
||||
} else {
|
||||
encodeBundleToWriterDstu1(theBundle, eventWriter);
|
||||
}
|
||||
} catch (XMLStreamException e) {
|
||||
throw new ConfigurationException("Failed to initialize STaX event factory", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doEncodeResourceToWriter(IBaseResource theResource, Writer theWriter) throws DataFormatException {
|
||||
XMLStreamWriter eventWriter;
|
||||
|
@ -199,9 +164,9 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
heldComments.clear();
|
||||
}
|
||||
parserState.endingElement();
|
||||
// if (parserState.isComplete()) {
|
||||
// return parserState.getObject();
|
||||
// }
|
||||
// if (parserState.isComplete()) {
|
||||
// return parserState.getObject();
|
||||
// }
|
||||
break;
|
||||
}
|
||||
case XMLStreamConstants.CHARACTERS: {
|
||||
|
@ -228,221 +193,6 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String encodeBundleToString(Bundle theBundle) throws DataFormatException {
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
try {
|
||||
encodeBundleToWriter(theBundle, stringWriter);
|
||||
} catch (IOException e) {
|
||||
throw new InternalErrorException("IOException writing to StringWriter - Should not happen", e);
|
||||
}
|
||||
|
||||
return stringWriter.toString();
|
||||
}
|
||||
|
||||
private void encodeBundleToWriterDstu1(Bundle theBundle, XMLStreamWriter eventWriter) throws XMLStreamException {
|
||||
eventWriter.writeStartElement("feed");
|
||||
eventWriter.writeDefaultNamespace(ATOM_NS);
|
||||
|
||||
writeTagWithTextNode(eventWriter, "title", theBundle.getTitle());
|
||||
writeTagWithTextNode(eventWriter, "id", theBundle.getBundleId());
|
||||
|
||||
writeAtomLink(eventWriter, Constants.LINK_SELF, theBundle.getLinkSelf());
|
||||
writeAtomLink(eventWriter, Constants.LINK_FIRST, theBundle.getLinkFirst());
|
||||
writeAtomLink(eventWriter, Constants.LINK_PREVIOUS, theBundle.getLinkPrevious());
|
||||
writeAtomLink(eventWriter, Constants.LINK_NEXT, theBundle.getLinkNext());
|
||||
writeAtomLink(eventWriter, Constants.LINK_LAST, theBundle.getLinkLast());
|
||||
writeAtomLink(eventWriter, Constants.LINK_FHIR_BASE, theBundle.getLinkBase());
|
||||
|
||||
if (theBundle.getTotalResults().getValue() != null) {
|
||||
eventWriter.writeStartElement("os", "totalResults", OPENSEARCH_NS);
|
||||
eventWriter.writeNamespace("os", OPENSEARCH_NS);
|
||||
eventWriter.writeCharacters(theBundle.getTotalResults().getValue().toString());
|
||||
eventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
writeOptionalTagWithTextNode(eventWriter, "updated", theBundle.getUpdated());
|
||||
|
||||
writeAuthor(eventWriter, theBundle);
|
||||
|
||||
writeCategories(eventWriter, theBundle.getCategories());
|
||||
|
||||
for (BundleEntry nextEntry : theBundle.getEntries()) {
|
||||
boolean deleted = false;
|
||||
if (nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false) {
|
||||
deleted = true;
|
||||
eventWriter.writeStartElement("at", "deleted-entry", TOMBSTONES_NS);
|
||||
eventWriter.writeNamespace("at", TOMBSTONES_NS);
|
||||
|
||||
if (nextEntry.getDeletedResourceId().isEmpty()) {
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
writeOptionalAttribute(eventWriter, "ref", nextEntry.getId().getValueAsString());
|
||||
} else {
|
||||
writeOptionalAttribute(eventWriter, "ref", nextEntry.getDeletedResourceId().getValueAsString());
|
||||
}
|
||||
|
||||
writeOptionalAttribute(eventWriter, "when", nextEntry.getDeletedAt().getValueAsString());
|
||||
if (nextEntry.getDeletedByEmail().isEmpty() == false || nextEntry.getDeletedByName().isEmpty() == false) {
|
||||
eventWriter.writeStartElement(TOMBSTONES_NS, "by");
|
||||
if (nextEntry.getDeletedByName().isEmpty() == false) {
|
||||
eventWriter.writeStartElement(TOMBSTONES_NS, "name");
|
||||
eventWriter.writeCharacters(nextEntry.getDeletedByName().getValue());
|
||||
eventWriter.writeEndElement();
|
||||
}
|
||||
if (nextEntry.getDeletedByEmail().isEmpty() == false) {
|
||||
eventWriter.writeStartElement(TOMBSTONES_NS, "email");
|
||||
eventWriter.writeCharacters(nextEntry.getDeletedByEmail().getValue());
|
||||
eventWriter.writeEndElement();
|
||||
}
|
||||
eventWriter.writeEndElement();
|
||||
}
|
||||
if (nextEntry.getDeletedComment().isEmpty() == false) {
|
||||
eventWriter.writeStartElement(TOMBSTONES_NS, "comment");
|
||||
eventWriter.writeCharacters(nextEntry.getDeletedComment().getValue());
|
||||
eventWriter.writeEndElement();
|
||||
}
|
||||
} else {
|
||||
eventWriter.writeStartElement("entry");
|
||||
}
|
||||
|
||||
writeOptionalTagWithTextNode(eventWriter, "title", nextEntry.getTitle());
|
||||
if (!deleted) {
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
if (nextEntry.getId().isEmpty() == false) {
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
writeTagWithTextNode(eventWriter, "id", nextEntry.getId());
|
||||
} else {
|
||||
writeTagWithTextNode(eventWriter, "id", nextEntry.getResource().getId());
|
||||
}
|
||||
}
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
writeOptionalTagWithTextNode(eventWriter, "updated", nextEntry.getUpdated());
|
||||
writeOptionalTagWithTextNode(eventWriter, "published", nextEntry.getPublished());
|
||||
|
||||
writeAuthor(eventWriter, nextEntry);
|
||||
|
||||
writeCategories(eventWriter, nextEntry.getCategories());
|
||||
|
||||
if (!nextEntry.getLinkSelf().isEmpty()) {
|
||||
writeAtomLink(eventWriter, "self", nextEntry.getLinkSelf());
|
||||
}
|
||||
|
||||
if (!nextEntry.getLinkAlternate().isEmpty()) {
|
||||
writeAtomLink(eventWriter, "alternate", nextEntry.getLinkAlternate());
|
||||
}
|
||||
|
||||
if (!nextEntry.getLinkSearch().isEmpty()) {
|
||||
writeAtomLink(eventWriter, "search", nextEntry.getLinkSearch());
|
||||
}
|
||||
|
||||
IResource resource = nextEntry.getResource();
|
||||
if (resource != null && !resource.isEmpty() && !deleted) {
|
||||
eventWriter.writeStartElement("content");
|
||||
eventWriter.writeAttribute("type", "text/xml");
|
||||
encodeResourceToXmlStreamWriter(resource, eventWriter, false, true);
|
||||
eventWriter.writeEndElement(); // content
|
||||
} else {
|
||||
ourLog.debug("Bundle entry contains null resource");
|
||||
}
|
||||
|
||||
if (!nextEntry.getSummary().isEmpty()) {
|
||||
eventWriter.writeStartElement("summary");
|
||||
eventWriter.writeAttribute("type", "xhtml");
|
||||
encodeXhtml(nextEntry.getSummary(), eventWriter);
|
||||
eventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
eventWriter.writeEndElement(); // entry
|
||||
}
|
||||
|
||||
eventWriter.writeEndElement();
|
||||
eventWriter.close();
|
||||
}
|
||||
|
||||
private void encodeBundleToWriterDstu2(Bundle theBundle, XMLStreamWriter theEventWriter) throws XMLStreamException {
|
||||
theEventWriter.writeStartElement("Bundle");
|
||||
theEventWriter.writeDefaultNamespace(FHIR_NS);
|
||||
|
||||
writeOptionalTagWithValue(theEventWriter, "id", theBundle.getId().getIdPart());
|
||||
|
||||
InstantDt updated = (InstantDt) theBundle.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
|
||||
IdDt bundleId = theBundle.getId();
|
||||
if (bundleId != null && isNotBlank(bundleId.getVersionIdPart()) || (updated != null && !updated.isEmpty())) {
|
||||
theEventWriter.writeStartElement("meta");
|
||||
//FIXME potential null acces bundleId may be null at this time due to the OR clause
|
||||
writeOptionalTagWithValue(theEventWriter, "versionId", bundleId.getVersionIdPart());
|
||||
if (updated != null) {
|
||||
writeOptionalTagWithValue(theEventWriter, "lastUpdated", updated.getValueAsString());
|
||||
}
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
writeOptionalTagWithValue(theEventWriter, "type", theBundle.getType().getValue());
|
||||
writeOptionalTagWithValue(theEventWriter, "total", theBundle.getTotalResults().getValueAsString());
|
||||
|
||||
writeBundleResourceLink(theEventWriter, "first", theBundle.getLinkFirst());
|
||||
writeBundleResourceLink(theEventWriter, "previous", theBundle.getLinkPrevious());
|
||||
writeBundleResourceLink(theEventWriter, "next", theBundle.getLinkNext());
|
||||
writeBundleResourceLink(theEventWriter, "last", theBundle.getLinkLast());
|
||||
writeBundleResourceLink(theEventWriter, "self", theBundle.getLinkSelf());
|
||||
|
||||
for (BundleEntry nextEntry : theBundle.getEntries()) {
|
||||
theEventWriter.writeStartElement("entry");
|
||||
|
||||
boolean deleted = false;
|
||||
if (nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false) {
|
||||
deleted = true;
|
||||
}
|
||||
|
||||
writeBundleResourceLink(theEventWriter, "alternate", nextEntry.getLinkAlternate());
|
||||
|
||||
if (nextEntry.getResource() != null && isNotBlank(nextEntry.getResource().getIdElement().getValue()) && (nextEntry.getResource().getId().getBaseUrl() != null || nextEntry.getResource().getId().getValueAsString().startsWith("urn:"))) {
|
||||
writeOptionalTagWithValue(theEventWriter, "fullUrl", nextEntry.getResource().getId().getValue());
|
||||
}
|
||||
|
||||
IResource resource = nextEntry.getResource();
|
||||
if (resource != null && !resource.isEmpty() && !deleted) {
|
||||
theEventWriter.writeStartElement("resource");
|
||||
encodeResourceToXmlStreamWriter(resource, theEventWriter, false, true);
|
||||
theEventWriter.writeEndElement(); // content
|
||||
} else {
|
||||
ourLog.debug("Bundle entry contains null resource");
|
||||
}
|
||||
|
||||
if (nextEntry.getSearchMode().isEmpty() == false || nextEntry.getScore().isEmpty() == false) {
|
||||
theEventWriter.writeStartElement("search");
|
||||
writeOptionalTagWithValue(theEventWriter, "mode", nextEntry.getSearchMode().getValueAsString());
|
||||
writeOptionalTagWithValue(theEventWriter, "score", nextEntry.getScore().getValueAsString());
|
||||
theEventWriter.writeEndElement();
|
||||
// IResource nextResource = nextEntry.getResource();
|
||||
}
|
||||
|
||||
if (nextEntry.getTransactionMethod().isEmpty() == false || nextEntry.getLinkSearch().isEmpty() == false) {
|
||||
theEventWriter.writeStartElement("request");
|
||||
writeOptionalTagWithValue(theEventWriter, "method", nextEntry.getTransactionMethod().getValue());
|
||||
writeOptionalTagWithValue(theEventWriter, "url", nextEntry.getLinkSearch().getValue());
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
if (deleted) {
|
||||
theEventWriter.writeStartElement("deleted");
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
writeOptionalTagWithValue(theEventWriter, "type", nextEntry.getId().getResourceType());
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
writeOptionalTagWithValue(theEventWriter, "id", nextEntry.getId().getIdPart());
|
||||
//TODO: Use of a deprecated method should be resolved.
|
||||
writeOptionalTagWithValue(theEventWriter, "versionId", nextEntry.getId().getVersionIdPart());
|
||||
writeOptionalTagWithValue(theEventWriter, "instant", nextEntry.getDeletedAt().getValueAsString());
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
theEventWriter.writeEndElement(); // entry
|
||||
}
|
||||
|
||||
theEventWriter.writeEndElement();
|
||||
theEventWriter.close();
|
||||
}
|
||||
|
||||
private void encodeChildElementToStreamWriter(IBaseResource theResource, XMLStreamWriter theEventWriter, IBase theElement, String childName, BaseRuntimeElementDefinition<?> childDef,
|
||||
String theExtensionUrl, boolean theIncludedResource, CompositeChildElement theParent) throws XMLStreamException, DataFormatException {
|
||||
if (theElement == null || theElement.isEmpty()) {
|
||||
|
@ -547,13 +297,13 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
|
||||
private void encodeCompositeElementToStreamWriter(IBaseResource theResource, IBase theElement, XMLStreamWriter theEventWriter, boolean theContainedResource, CompositeChildElement theParent)
|
||||
throws XMLStreamException, DataFormatException {
|
||||
|
||||
|
||||
for (CompositeChildElement nextChildElem : super.compositeChildIterator(theElement, theContainedResource, theParent)) {
|
||||
|
||||
BaseRuntimeChildDefinition nextChild = nextChildElem.getDef();
|
||||
|
||||
|
||||
if (nextChild.getElementName().equals("url") && theElement instanceof IBaseExtension) {
|
||||
/*
|
||||
/*
|
||||
* XML encoding is a one-off for extensions. The URL element goes in an attribute
|
||||
* instead of being encoded as a normal element, only for XML encoding
|
||||
*/
|
||||
|
@ -570,7 +320,7 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
} else {
|
||||
narr = null;
|
||||
}
|
||||
//FIXME potential null access on narr see line 623
|
||||
// FIXME potential null access on narr see line 623
|
||||
if (gen != null && narr.isEmpty()) {
|
||||
gen.generateNarrative(myContext, theResource, narr);
|
||||
}
|
||||
|
@ -584,7 +334,8 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
}
|
||||
|
||||
if (nextChild instanceof RuntimeChildContainedResources) {
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, null, nextChild.getChildNameByDatatype(null), nextChild.getChildElementDefinitionByDatatype(null), null, theContainedResource, nextChildElem);
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, null, nextChild.getChildNameByDatatype(null), nextChild.getChildElementDefinitionByDatatype(null), null, theContainedResource,
|
||||
nextChildElem);
|
||||
} else {
|
||||
|
||||
List<? extends IBase> values = nextChild.getAccessor().getValues(theElement);
|
||||
|
@ -597,22 +348,17 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
if ((nextValue == null || nextValue.isEmpty())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
BaseParser.ChildNameAndDef childNameAndDef = super.getChildNameAndDef(nextChild, nextValue);
|
||||
if (childNameAndDef == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
String childName = childNameAndDef.getChildName();
|
||||
BaseRuntimeElementDefinition<?> childDef = childNameAndDef.getChildDef();
|
||||
String extensionUrl = getExtensionUrl(nextChild.getExtensionUrl());
|
||||
|
||||
if (nextValue instanceof IBaseExtension && myContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
// This is called for the Query resource in DSTU1 only
|
||||
extensionUrl = getExtensionUrl(((IBaseExtension<?, ?>) nextValue).getUrl());
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextValue, childName, childDef, extensionUrl, theContainedResource, nextChildElem);
|
||||
|
||||
} else if (extensionUrl != null && childName.equals("extension") == false) {
|
||||
if (extensionUrl != null && childName.equals("extension") == false) {
|
||||
encodeExtension(theResource, theEventWriter, theContainedResource, nextChildElem, nextChild, nextValue, childName, extensionUrl, childDef);
|
||||
} else if (nextChild instanceof RuntimeChildExtension) {
|
||||
IBaseExtension<?, ?> extension = (IBaseExtension<?, ?>) nextValue;
|
||||
|
@ -632,7 +378,8 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
}
|
||||
}
|
||||
|
||||
private void encodeExtension(IBaseResource theResource, XMLStreamWriter theEventWriter, boolean theContainedResource, CompositeChildElement nextChildElem, BaseRuntimeChildDefinition nextChild, IBase nextValue, String childName, String extensionUrl, BaseRuntimeElementDefinition<?> childDef)
|
||||
private void encodeExtension(IBaseResource theResource, XMLStreamWriter theEventWriter, boolean theContainedResource, CompositeChildElement nextChildElem, BaseRuntimeChildDefinition nextChild,
|
||||
IBase nextValue, String childName, String extensionUrl, BaseRuntimeElementDefinition<?> childDef)
|
||||
throws XMLStreamException {
|
||||
BaseRuntimeDeclaredChildDefinition extDef = (BaseRuntimeDeclaredChildDefinition) nextChild;
|
||||
if (extDef.isModifier()) {
|
||||
|
@ -645,7 +392,7 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
if (isNotBlank(elementId)) {
|
||||
theEventWriter.writeAttribute("id", elementId);
|
||||
}
|
||||
|
||||
|
||||
theEventWriter.writeAttribute("url", extensionUrl);
|
||||
encodeChildElementToStreamWriter(theResource, theEventWriter, nextValue, childName, childDef, null, theContainedResource, nextChildElem);
|
||||
theEventWriter.writeEndElement();
|
||||
|
@ -667,7 +414,8 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
}
|
||||
}
|
||||
|
||||
private void encodeResourceToXmlStreamWriter(IBaseResource theResource, XMLStreamWriter theEventWriter, boolean theIncludedResource, boolean theSubResource) throws XMLStreamException, DataFormatException {
|
||||
private void encodeResourceToXmlStreamWriter(IBaseResource theResource, XMLStreamWriter theEventWriter, boolean theIncludedResource, boolean theSubResource)
|
||||
throws XMLStreamException, DataFormatException {
|
||||
IIdType resourceId = null;
|
||||
|
||||
if (StringUtils.isNotBlank(theResource.getIdElement().getIdPart())) {
|
||||
|
@ -675,9 +423,6 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
if (theResource.getIdElement().getValue().startsWith("urn:")) {
|
||||
resourceId = null;
|
||||
}
|
||||
if (myContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
|
||||
resourceId = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!theIncludedResource) {
|
||||
|
@ -691,7 +436,6 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
encodeResourceToXmlStreamWriter(theResource, theEventWriter, theIncludedResource, resourceId);
|
||||
}
|
||||
|
||||
|
||||
private void encodeResourceToXmlStreamWriter(IBaseResource theResource, XMLStreamWriter theEventWriter, boolean theContainedResource, IIdType theResourceId) throws XMLStreamException {
|
||||
if (!theContainedResource) {
|
||||
super.containResourcesForEncoding(theResource);
|
||||
|
@ -718,86 +462,65 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
|
||||
} else {
|
||||
|
||||
if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
// DSTU2+
|
||||
|
||||
// DSTU2+
|
||||
IResource resource = (IResource) theResource;
|
||||
if (theResourceId != null) {
|
||||
writeCommentsPre(theEventWriter, theResourceId);
|
||||
writeOptionalTagWithValue(theEventWriter, "id", theResourceId.getIdPart());
|
||||
writeCommentsPost(theEventWriter, theResourceId);
|
||||
}
|
||||
|
||||
IResource resource = (IResource) theResource;
|
||||
if (theResourceId != null) {
|
||||
writeCommentsPre(theEventWriter, theResourceId);
|
||||
writeOptionalTagWithValue(theEventWriter, "id", theResourceId.getIdPart());
|
||||
writeCommentsPost(theEventWriter, theResourceId);
|
||||
InstantDt updated = (InstantDt) resource.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
|
||||
IdDt resourceId = resource.getId();
|
||||
String versionIdPart = resourceId.getVersionIdPart();
|
||||
if (isBlank(versionIdPart)) {
|
||||
versionIdPart = ResourceMetadataKeyEnum.VERSION.get(resource);
|
||||
}
|
||||
List<BaseCodingDt> securityLabels = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.SECURITY_LABELS);
|
||||
List<? extends IIdType> profiles = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.PROFILES);
|
||||
profiles = super.getProfileTagsForEncoding(resource, profiles);
|
||||
|
||||
TagList tags = getMetaTagsForEncoding((resource));
|
||||
|
||||
if (super.shouldEncodeResourceMeta(resource) && ElementUtil.isEmpty(versionIdPart, updated, securityLabels, tags, profiles) == false) {
|
||||
theEventWriter.writeStartElement("meta");
|
||||
writeOptionalTagWithValue(theEventWriter, "versionId", versionIdPart);
|
||||
if (updated != null) {
|
||||
writeOptionalTagWithValue(theEventWriter, "lastUpdated", updated.getValueAsString());
|
||||
}
|
||||
|
||||
InstantDt updated = (InstantDt) resource.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
|
||||
IdDt resourceId = resource.getId();
|
||||
String versionIdPart = resourceId.getVersionIdPart();
|
||||
if (isBlank(versionIdPart)) {
|
||||
versionIdPart = ResourceMetadataKeyEnum.VERSION.get(resource);
|
||||
}
|
||||
List<BaseCodingDt> securityLabels = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.SECURITY_LABELS);
|
||||
List<? extends IIdType> profiles = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.PROFILES);
|
||||
profiles = super.getProfileTagsForEncoding(resource, profiles);
|
||||
|
||||
TagList tags = getMetaTagsForEncoding((resource));
|
||||
|
||||
if (super.shouldEncodeResourceMeta(resource) && ElementUtil.isEmpty(versionIdPart, updated, securityLabels, tags, profiles) == false) {
|
||||
theEventWriter.writeStartElement("meta");
|
||||
writeOptionalTagWithValue(theEventWriter, "versionId", versionIdPart);
|
||||
if (updated != null) {
|
||||
writeOptionalTagWithValue(theEventWriter, "lastUpdated", updated.getValueAsString());
|
||||
}
|
||||
|
||||
for (IIdType profile : profiles) {
|
||||
theEventWriter.writeStartElement("profile");
|
||||
theEventWriter.writeAttribute("value", profile.getValue());
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
for (BaseCodingDt securityLabel : securityLabels) {
|
||||
theEventWriter.writeStartElement("security");
|
||||
encodeCompositeElementToStreamWriter(resource, securityLabel, theEventWriter, theContainedResource, null);
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
if (tags != null) {
|
||||
for (Tag tag : tags) {
|
||||
if (tag.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
theEventWriter.writeStartElement("tag");
|
||||
writeOptionalTagWithValue(theEventWriter, "system", tag.getScheme());
|
||||
writeOptionalTagWithValue(theEventWriter, "code", tag.getTerm());
|
||||
writeOptionalTagWithValue(theEventWriter, "display", tag.getLabel());
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
}
|
||||
for (IIdType profile : profiles) {
|
||||
theEventWriter.writeStartElement("profile");
|
||||
theEventWriter.writeAttribute("value", profile.getValue());
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
if (theResource instanceof IBaseBinary) {
|
||||
IBaseBinary bin = (IBaseBinary) theResource;
|
||||
writeOptionalTagWithValue(theEventWriter, "contentType", bin.getContentType());
|
||||
writeOptionalTagWithValue(theEventWriter, "content", bin.getContentAsBase64());
|
||||
} else {
|
||||
encodeCompositeElementToStreamWriter(theResource, theResource, theEventWriter, theContainedResource, new CompositeChildElement(resDef));
|
||||
for (BaseCodingDt securityLabel : securityLabels) {
|
||||
theEventWriter.writeStartElement("security");
|
||||
encodeCompositeElementToStreamWriter(resource, securityLabel, theEventWriter, theContainedResource, null);
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// DSTU1
|
||||
if (theResourceId != null && theContainedResource && theResourceId.hasIdPart()) {
|
||||
theEventWriter.writeAttribute("id", theResourceId.getIdPart());
|
||||
}
|
||||
|
||||
if (theResource instanceof IBaseBinary) {
|
||||
IBaseBinary bin = (IBaseBinary) theResource;
|
||||
if (bin.getContentType() != null) {
|
||||
theEventWriter.writeAttribute("contentType", bin.getContentType());
|
||||
if (tags != null) {
|
||||
for (Tag tag : tags) {
|
||||
if (tag.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
theEventWriter.writeStartElement("tag");
|
||||
writeOptionalTagWithValue(theEventWriter, "system", tag.getScheme());
|
||||
writeOptionalTagWithValue(theEventWriter, "code", tag.getTerm());
|
||||
writeOptionalTagWithValue(theEventWriter, "display", tag.getLabel());
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
theEventWriter.writeCharacters(bin.getContentAsBase64());
|
||||
} else {
|
||||
encodeCompositeElementToStreamWriter(theResource, theResource, theEventWriter, theContainedResource, new CompositeChildElement(resDef));
|
||||
}
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
if (theResource instanceof IBaseBinary) {
|
||||
IBaseBinary bin = (IBaseBinary) theResource;
|
||||
writeOptionalTagWithValue(theEventWriter, "contentType", bin.getContentType());
|
||||
writeOptionalTagWithValue(theEventWriter, "content", bin.getContentAsBase64());
|
||||
} else {
|
||||
encodeCompositeElementToStreamWriter(theResource, theResource, theEventWriter, theContainedResource, new CompositeChildElement(resDef));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -805,39 +528,8 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void encodeTagListToWriter(TagList theTagList, Writer theWriter) throws IOException {
|
||||
try {
|
||||
XMLStreamWriter eventWriter = createXmlWriter(theWriter);
|
||||
|
||||
eventWriter.writeStartElement(TagList.ELEMENT_NAME_LC);
|
||||
eventWriter.writeDefaultNamespace(FHIR_NS);
|
||||
|
||||
for (Tag next : theTagList) {
|
||||
eventWriter.writeStartElement(TagList.ATTR_CATEGORY);
|
||||
|
||||
if (isNotBlank(next.getTerm())) {
|
||||
eventWriter.writeAttribute(Tag.ATTR_TERM, next.getTerm());
|
||||
}
|
||||
if (isNotBlank(next.getLabel())) {
|
||||
eventWriter.writeAttribute(Tag.ATTR_LABEL, next.getLabel());
|
||||
}
|
||||
if (isNotBlank(next.getScheme())) {
|
||||
eventWriter.writeAttribute(Tag.ATTR_SCHEME, next.getScheme());
|
||||
}
|
||||
|
||||
eventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
eventWriter.writeEndElement();
|
||||
eventWriter.close();
|
||||
} catch (XMLStreamException e) {
|
||||
throw new ConfigurationException("Failed to initialize STaX event factory", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void encodeUndeclaredExtensions(IBaseResource theResource, XMLStreamWriter theEventWriter, List<? extends IBaseExtension<?, ?>> theExtensions, String tagName, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
|
||||
private void encodeUndeclaredExtensions(IBaseResource theResource, XMLStreamWriter theEventWriter, List<? extends IBaseExtension<?, ?>> theExtensions, String tagName, boolean theIncludedResource)
|
||||
throws XMLStreamException, DataFormatException {
|
||||
for (IBaseExtension<?, ?> next : theExtensions) {
|
||||
if (next == null || (ElementUtil.isEmpty(next.getValue()) && next.getExtension().isEmpty())) {
|
||||
continue;
|
||||
|
@ -864,7 +556,7 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
childDef = myContext.getElementDefinition(value.getClass());
|
||||
if (childDef == null) {
|
||||
throw new ConfigurationException("Unable to encode extension, unrecognized child element type: " + value.getClass().getCanonicalName());
|
||||
}
|
||||
}
|
||||
childName = RuntimeChildUndeclaredExtensionDefinition.createExtensionChildName(childDef);
|
||||
} else {
|
||||
childDef = extDef.getChildElementDefinitionByDatatype(value.getClass());
|
||||
|
@ -983,31 +675,11 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
return EncodingEnum.XML;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IBaseResource> Bundle parseBundle(Class<T> theResourceType, Reader theReader) {
|
||||
XMLEventReader streamReader = createStreamReader(theReader);
|
||||
|
||||
return parseBundle(streamReader, theResourceType);
|
||||
}
|
||||
|
||||
private Bundle parseBundle(XMLEventReader theStreamReader, Class<? extends IBaseResource> theResourceType) {
|
||||
ParserState<Bundle> parserState = ParserState.getPreAtomInstance(this, myContext, theResourceType, false, getErrorHandler());
|
||||
return doXmlLoop(theStreamReader, parserState);
|
||||
}
|
||||
|
||||
private <T extends IBaseResource> T parseResource(Class<T> theResourceType, XMLEventReader theStreamReader) {
|
||||
ParserState<T> parserState = ParserState.getPreResourceInstance(this, theResourceType, myContext, false, getErrorHandler());
|
||||
return doXmlLoop(theStreamReader, parserState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagList parseTagList(Reader theReader) {
|
||||
XMLEventReader streamReader = createStreamReader(theReader);
|
||||
|
||||
ParserState<TagList> parserState = ParserState.getPreTagListInstance(this, myContext, false, getErrorHandler());
|
||||
return doXmlLoop(streamReader, parserState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IParser setPrettyPrint(boolean thePrettyPrint) {
|
||||
myPrettyPrint = thePrettyPrint;
|
||||
|
@ -1025,49 +697,6 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
return retVal;
|
||||
}
|
||||
|
||||
private void writeAuthor(XMLStreamWriter theEventWriter, BaseBundle theBundle) throws XMLStreamException {
|
||||
if (StringUtils.isNotBlank(theBundle.getAuthorName().getValue())) {
|
||||
theEventWriter.writeStartElement("author");
|
||||
writeTagWithTextNode(theEventWriter, "name", theBundle.getAuthorName());
|
||||
writeOptionalTagWithTextNode(theEventWriter, "uri", theBundle.getAuthorUri());
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeAtomLink(XMLStreamWriter theEventWriter, String theRel, StringDt theStringDt) throws XMLStreamException {
|
||||
if (StringUtils.isNotBlank(theStringDt.getValue())) {
|
||||
theEventWriter.writeStartElement("link");
|
||||
theEventWriter.writeAttribute("rel", theRel);
|
||||
theEventWriter.writeAttribute("href", theStringDt.getValue());
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeBundleResourceLink(XMLStreamWriter theEventWriter, String theRel, StringDt theUrl) throws XMLStreamException {
|
||||
if (theUrl.isEmpty() == false) {
|
||||
theEventWriter.writeStartElement("link");
|
||||
theEventWriter.writeStartElement("relation");
|
||||
theEventWriter.writeAttribute("value", theRel);
|
||||
theEventWriter.writeEndElement();
|
||||
theEventWriter.writeStartElement("url");
|
||||
theEventWriter.writeAttribute("value", theUrl.getValue());
|
||||
theEventWriter.writeEndElement();
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeCategories(XMLStreamWriter eventWriter, TagList categories) throws XMLStreamException {
|
||||
if (categories != null) {
|
||||
for (Tag next : categories) {
|
||||
eventWriter.writeStartElement("category");
|
||||
eventWriter.writeAttribute("term", defaultString(next.getTerm()));
|
||||
eventWriter.writeAttribute("label", defaultString(next.getLabel()));
|
||||
eventWriter.writeAttribute("scheme", defaultString(next.getScheme()));
|
||||
eventWriter.writeEndElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeCommentsPost(XMLStreamWriter theEventWriter, IBase theElement) throws XMLStreamException {
|
||||
if (theElement != null && theElement.hasFormatComment()) {
|
||||
for (String next : theElement.getFormatCommentsPost()) {
|
||||
|
@ -1088,28 +717,6 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
}
|
||||
}
|
||||
|
||||
private void writeOptionalAttribute(XMLStreamWriter theEventWriter, String theName, String theValue) throws XMLStreamException {
|
||||
if (StringUtils.isNotBlank(theValue)) {
|
||||
theEventWriter.writeAttribute(theName, theValue);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeOptionalTagWithTextNode(XMLStreamWriter theEventWriter, String theTagName, InstantDt theInstantDt) throws XMLStreamException {
|
||||
if (theInstantDt.getValue() != null) {
|
||||
theEventWriter.writeStartElement(theTagName);
|
||||
theEventWriter.writeCharacters(theInstantDt.getValueAsString());
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeOptionalTagWithTextNode(XMLStreamWriter theEventWriter, String theElementName, StringDt theTextValue) throws XMLStreamException {
|
||||
if (StringUtils.isNotBlank(theTextValue.getValue())) {
|
||||
theEventWriter.writeStartElement(theElementName);
|
||||
theEventWriter.writeCharacters(theTextValue.getValue());
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeOptionalTagWithValue(XMLStreamWriter theEventWriter, String theName, String theValue) throws XMLStreamException {
|
||||
if (StringUtils.isNotBlank(theValue)) {
|
||||
theEventWriter.writeStartElement(theName);
|
||||
|
@ -1118,20 +725,4 @@ public class XmlParser extends BaseParser /*implements IParser */{
|
|||
}
|
||||
}
|
||||
|
||||
private void writeTagWithTextNode(XMLStreamWriter theEventWriter, String theElementName, IdDt theIdDt) throws XMLStreamException {
|
||||
theEventWriter.writeStartElement(theElementName);
|
||||
if (StringUtils.isNotBlank(theIdDt.getValue())) {
|
||||
theEventWriter.writeCharacters(theIdDt.getValue());
|
||||
}
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
private void writeTagWithTextNode(XMLStreamWriter theEventWriter, String theElementName, StringDt theStringDt) throws XMLStreamException {
|
||||
theEventWriter.writeStartElement(theElementName);
|
||||
if (StringUtils.isNotBlank(theStringDt.getValue())) {
|
||||
theEventWriter.writeCharacters(theStringDt.getValue());
|
||||
}
|
||||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,19 +19,13 @@ package ca.uhn.fhir.rest.annotation;
|
|||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* RESTful method annotation to be used for the FHIR <a href="http://hl7.org/implement/standards/fhir/http.html#transaction">transaction</a> method.
|
||||
*
|
||||
* <p>
|
||||
* This method should have a parameter of type {@link Bundle} annotated with the {@link TransactionParam} annotation.
|
||||
* This method should have a parameter of type Bundle annotated with the {@link TransactionParam} annotation.
|
||||
* </p>
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
@ -19,19 +19,13 @@ package ca.uhn.fhir.rest.annotation;
|
|||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
|
||||
/**
|
||||
* Parameter annotation for the "transaction" operation. The parameter annotated with this
|
||||
* annotation must be either of type <code>{@link Bundle}</code> or of type
|
||||
* <code>{@link List}<IResource></code>
|
||||
* annotation must be a Bundle resource type, or a type that implements
|
||||
* <code>{@link List}<IBaseResource></code>
|
||||
*/
|
||||
@Target(value=ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
@ -19,15 +19,12 @@ package ca.uhn.fhir.rest.api;
|
|||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||
|
||||
import ca.uhn.fhir.context.api.BundleInclusionRule;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.Include;
|
||||
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
||||
|
||||
|
@ -40,8 +37,6 @@ public interface IVersionSpecificBundleFactory {
|
|||
|
||||
void addRootPropertiesToBundle(String theAuthor, String theServerBase, String theLinkSelf, String theLinkPrev, String theLinkNext, Integer theTotalResults, BundleTypeEnum theBundleType, IPrimitiveType<Date> theLastUpdated);
|
||||
|
||||
Bundle getDstu1Bundle();
|
||||
|
||||
IBaseResource getResourceBundle();
|
||||
|
||||
void initializeBundleFromResourceList(String theAuthor, List<? extends IBaseResource> theResult, String theServerBase, String theCompleteUrl, int theTotalResults, BundleTypeEnum theBundleType);
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.client.api;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -21,13 +21,13 @@ package ca.uhn.fhir.rest.client.api;
|
|||
*/
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseConformance;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
|
||||
import ca.uhn.fhir.rest.client.exceptions.FhirClientInappropriateForServerException;
|
||||
|
@ -47,12 +47,12 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Fluent method for the "create" operation, which creates a new resource instance on the server
|
||||
*/
|
||||
ICreate create();
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the "type create" method.
|
||||
*
|
||||
* @param theResource
|
||||
* The resource to create
|
||||
* The resource to create
|
||||
* @return An outcome
|
||||
* @deprecated Use {@link #create() fluent method instead}. This method will be removed.
|
||||
*
|
||||
|
@ -69,9 +69,9 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Implementation of the "delete instance" method.
|
||||
*
|
||||
* @param theType
|
||||
* The type of resource to delete
|
||||
* The type of resource to delete
|
||||
* @param theId
|
||||
* the ID of the resource to delete
|
||||
* the ID of the resource to delete
|
||||
* @return An outcome
|
||||
* @deprecated Use {@link #delete()} instead
|
||||
*/
|
||||
|
@ -82,9 +82,9 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Implementation of the "delete instance" method.
|
||||
*
|
||||
* @param theType
|
||||
* The type of resource to delete
|
||||
* The type of resource to delete
|
||||
* @param theId
|
||||
* the ID of the resource to delete
|
||||
* the ID of the resource to delete
|
||||
* @return An outcome
|
||||
* @deprecated Use {@link #delete()} instead
|
||||
*/
|
||||
|
@ -100,9 +100,9 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Force the client to fetch the server's conformance statement and validate that it is appropriate for this client.
|
||||
*
|
||||
* @throws FhirClientConnectionException
|
||||
* if the conformance statement cannot be read, or if the client
|
||||
* if the conformance statement cannot be read, or if the client
|
||||
* @throws FhirClientInappropriateForServerException
|
||||
* If the conformance statement indicates that the server is inappropriate for this client (e.g. it implements the wrong version of FHIR)
|
||||
* 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;
|
||||
|
||||
|
@ -116,44 +116,6 @@ public interface IGenericClient extends IRestfulClient {
|
|||
*/
|
||||
IHistory history();
|
||||
|
||||
/**
|
||||
* Implementation of the "history instance" method.
|
||||
*
|
||||
* @param theType
|
||||
* The type of resource to return the history for, or <code>null</code> to search for history across all resources
|
||||
* @param theId
|
||||
* The ID of the resource to return the history for, or <code>null</code> to search for all resource instances. Note that if this param is not null, <code>theType</code> must also not
|
||||
* be null
|
||||
* @param theSince
|
||||
* If not null, request that the server only return resources updated since this time
|
||||
* @param theLimit
|
||||
* If not null, request that the server return no more than this number of resources. Note that the server may return less even if more are available, but should not return more
|
||||
* according to the FHIR specification.
|
||||
* @return A bundle containing returned resources
|
||||
* @deprecated As of 0.9, use the fluent {@link #history()} method instead
|
||||
*/
|
||||
@Deprecated
|
||||
<T extends IBaseResource> Bundle history(Class<T> theType, IdDt theId, DateTimeDt theSince, Integer theLimit);
|
||||
|
||||
/**
|
||||
* Implementation of the "history instance" method.
|
||||
*
|
||||
* @param theType
|
||||
* The type of resource to return the history for, or <code>null</code> to search for history across all resources
|
||||
* @param theId
|
||||
* The ID of the resource to return the history for, or <code>null</code> to search for all resource instances. Note that if this param is not null, <code>theType</code> must also not
|
||||
* be null
|
||||
* @param theSince
|
||||
* If not null, request that the server only return resources updated since this time
|
||||
* @param theLimit
|
||||
* If not null, request that the server return no more than this number of resources. Note that the server may return less even if more are available, but should not return more
|
||||
* according to the FHIR specification.
|
||||
* @return A bundle containing returned resources
|
||||
* @deprecated As of 0.9, use the fluent {@link #history()} method instead
|
||||
*/
|
||||
@Deprecated
|
||||
<T extends IBaseResource> Bundle history(Class<T> theType, String theId, DateTimeDt theSince, Integer theLimit);
|
||||
|
||||
/**
|
||||
* Loads the previous/next bundle of resources from a paged set, using the link specified in the "link type=next" tag within the atom bundle.
|
||||
*
|
||||
|
@ -201,9 +163,9 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Implementation of the "instance read" method.
|
||||
*
|
||||
* @param theType
|
||||
* The type of resource to load
|
||||
* The type of resource to load
|
||||
* @param theId
|
||||
* The ID to load
|
||||
* The ID to load
|
||||
* @return The resource
|
||||
*/
|
||||
<T extends IBaseResource> T read(Class<T> theType, String theId);
|
||||
|
@ -212,9 +174,9 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Perform the "read" operation (retrieve the latest version of a resource instance by ID) using an absolute URL.
|
||||
*
|
||||
* @param theType
|
||||
* The resource type that is being retrieved
|
||||
* The resource type that is being retrieved
|
||||
* @param theUrl
|
||||
* The absolute URL, e.g. "http://example.com/fhir/Patient/123"
|
||||
* The absolute URL, e.g. "http://example.com/fhir/Patient/123"
|
||||
* @return The returned resource from the server
|
||||
*/
|
||||
<T extends IBaseResource> T read(Class<T> theType, UriDt theUrl);
|
||||
|
@ -223,7 +185,7 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Perform the "read" operation (retrieve the latest version of a resource instance by ID) using an absolute URL.
|
||||
*
|
||||
* @param theUrl
|
||||
* The absolute URL, e.g. "http://example.com/fhir/Patient/123"
|
||||
* The absolute URL, e.g. "http://example.com/fhir/Patient/123"
|
||||
* @return The returned resource from the server
|
||||
*/
|
||||
IBaseResource read(UriDt theUrl);
|
||||
|
@ -241,43 +203,21 @@ public interface IGenericClient extends IRestfulClient {
|
|||
|
||||
/**
|
||||
* Search for resources matching a given set of criteria. Searching is a very powerful
|
||||
* feature in FHIR with many features for specifying exactly what should be seaerched for
|
||||
* feature in FHIR with many features for specifying exactly what should be seaerched for
|
||||
* and how it should be returned. See the <a href="http://www.hl7.org/fhir/search.html">specification on search</a>
|
||||
* for more information.
|
||||
*/
|
||||
IUntypedQuery search();
|
||||
|
||||
/**
|
||||
* Implementation of the "instance search" method.
|
||||
*
|
||||
* @param theType
|
||||
* The type of resource to load
|
||||
* @param theParams
|
||||
*/
|
||||
<T extends IBaseResource> Bundle search(Class<T> theType, Map<String, List<IQueryParameterType>> theParams);
|
||||
|
||||
/**
|
||||
* Perform the "search" operation using an absolute URL.
|
||||
*
|
||||
* @param theType
|
||||
* The primary resource type that is being retrieved
|
||||
* @param theUrl
|
||||
* The absolute URL, e.g. "http://example.com/fhir/Patient/123"
|
||||
* @return The returned bundle from the server
|
||||
*/
|
||||
<T extends IBaseResource> Bundle search(Class<T> theType, UriDt theUrl);
|
||||
|
||||
Bundle search(UriDt theUrl);
|
||||
|
||||
/**
|
||||
* If set to <code>true</code>, the client will log all requests and all responses. This is probably not a good production setting since it will result in a lot of extra logging, but it can be
|
||||
* useful for troubleshooting.
|
||||
*
|
||||
* @param theLogRequestAndResponse
|
||||
* Should requests and responses be logged
|
||||
* Should requests and responses be logged
|
||||
* @deprecated Use LoggingInterceptor as a client interceptor registered to your
|
||||
* client instead, as this provides much more fine-grained control over what is logged. This
|
||||
* method will be removed at some point (deprecated in HAPI 1.6 - 2016-06-16)
|
||||
* client instead, as this provides much more fine-grained control over what is logged. This
|
||||
* method will be removed at some point (deprecated in HAPI 1.6 - 2016-06-16)
|
||||
*/
|
||||
@Deprecated
|
||||
void setLogRequestAndResponse(boolean theLogRequestAndResponse);
|
||||
|
@ -291,7 +231,7 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Implementation of the "transaction" method.
|
||||
*
|
||||
* @param theResources
|
||||
* The resources to create/update in a single transaction
|
||||
* The resources to create/update in a single transaction
|
||||
* @return A list of resource stubs (<b>these will not be fully populated</b>) containing IDs and other {@link IResource#getResourceMetadata() metadata}
|
||||
* @deprecated Use {@link #transaction()}
|
||||
*
|
||||
|
@ -314,9 +254,9 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Implementation of the "instance update" method.
|
||||
*
|
||||
* @param theId
|
||||
* The ID to update
|
||||
* The ID to update
|
||||
* @param theResource
|
||||
* The new resource body
|
||||
* The new resource body
|
||||
* @return An outcome containing the results and possibly the new version ID
|
||||
*/
|
||||
MethodOutcome update(IdDt theId, IBaseResource theResource);
|
||||
|
@ -325,9 +265,9 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Implementation of the "instance update" method.
|
||||
*
|
||||
* @param theId
|
||||
* The ID to update
|
||||
* The ID to update
|
||||
* @param theResource
|
||||
* The new resource body
|
||||
* The new resource body
|
||||
* @return An outcome containing the results and possibly the new version ID
|
||||
*/
|
||||
MethodOutcome update(String theId, IBaseResource theResource);
|
||||
|
@ -341,7 +281,7 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Implementation of the "type validate" method.
|
||||
*
|
||||
* @param theResource
|
||||
* The resource to validate
|
||||
* The resource to validate
|
||||
* @return An outcome containing any validation issues
|
||||
*/
|
||||
MethodOutcome validate(IBaseResource theResource);
|
||||
|
@ -354,9 +294,9 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* </p>
|
||||
*
|
||||
* @param theType
|
||||
* The type of resource to load
|
||||
* The type of resource to load
|
||||
* @param theId
|
||||
* 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"
|
||||
* 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 extends IBaseResource> T vread(Class<T> theType, IdDt theId);
|
||||
|
@ -365,11 +305,11 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Implementation of the "instance vread" method.
|
||||
*
|
||||
* @param theType
|
||||
* The type of resource to load
|
||||
* The type of resource to load
|
||||
* @param theId
|
||||
* The ID to load
|
||||
* The ID to load
|
||||
* @param theVersionId
|
||||
* The version ID
|
||||
* The version ID
|
||||
* @return The resource
|
||||
* @deprecated Deprecated in 0.7 - IdDt can contain an ID and a version, so this class doesn't make a lot of sense
|
||||
*/
|
||||
|
@ -380,15 +320,13 @@ public interface IGenericClient extends IRestfulClient {
|
|||
* Implementation of the "instance vread" method.
|
||||
*
|
||||
* @param theType
|
||||
* The type of resource to load
|
||||
* The type of resource to load
|
||||
* @param theId
|
||||
* The ID to load
|
||||
* The ID to load
|
||||
* @param theVersionId
|
||||
* The version ID
|
||||
* The version ID
|
||||
* @return The resource
|
||||
*/
|
||||
<T extends IBaseResource> T vread(Class<T> theType, String theId, String theVersionId);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public class DateClientParam extends BaseClientParam implements IParam {
|
|||
b.append(',');
|
||||
}
|
||||
if (myPrefix != null && myPrefix != ParamPrefixEnum.EQUAL) {
|
||||
b.append(myPrefix.getValueForContext(theContext));
|
||||
b.append(myPrefix.getValue());
|
||||
}
|
||||
b.append(myValue);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,9 @@ public interface IClientExecutable<T extends IClientExecutable<?,?>, Y> {
|
|||
|
||||
T encodedXml();
|
||||
|
||||
/**
|
||||
* Actually execute the client operation
|
||||
*/
|
||||
Y execute();
|
||||
|
||||
T prettyPrint();
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.gclient;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -22,16 +22,8 @@ package ca.uhn.fhir.rest.gclient;
|
|||
|
||||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
|
||||
public interface IGetPage {
|
||||
|
||||
/**
|
||||
* Load the next page of results using the link with relation "next" in the bundle. This
|
||||
* method accepts a DSTU1 Atom Bundle
|
||||
*/
|
||||
IGetPageTyped<Bundle> next(Bundle theBundle);
|
||||
|
||||
/**
|
||||
* Load the next page of results using the link with relation "next" in the bundle. This
|
||||
* method accepts a DSTU2 Bundle resource
|
||||
|
@ -39,13 +31,7 @@ public interface IGetPage {
|
|||
* @since 1.1
|
||||
*/
|
||||
<T extends IBaseBundle> IGetPageTyped<T> next(T theBundle);
|
||||
|
||||
/**
|
||||
* Load the previous page of results using the link with relation "previous" in the bundle. This
|
||||
* method accepts a DSTU1 Atom Bundle
|
||||
*/
|
||||
IGetPageTyped<Bundle> previous(Bundle theBundle);
|
||||
|
||||
|
||||
/**
|
||||
* Load the previous page of results using the link with relation "prev" in the bundle. This
|
||||
* method accepts a DSTU2+ Bundle resource
|
||||
|
@ -54,14 +40,6 @@ public interface IGetPage {
|
|||
*/
|
||||
<T extends IBaseBundle> IGetPageTyped<T> previous(T theBundle);
|
||||
|
||||
/**
|
||||
* Load a page of results using the a given URL and return a DSTU1 Atom bundle
|
||||
*
|
||||
* @deprecated Use {@link #byUrl(String)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
IGetPageTyped<Bundle> url(String thePageUrl);
|
||||
|
||||
/**
|
||||
* Load a page of results using the a given URL and return a DSTU1 Atom bundle
|
||||
*/
|
||||
|
|
|
@ -22,14 +22,7 @@ package ca.uhn.fhir.rest.gclient;
|
|||
|
||||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
|
||||
public interface IGetPageUntyped {
|
||||
|
||||
/**
|
||||
* Return a DSTU1 Atom feed
|
||||
*/
|
||||
IGetPageTyped<Bundle> andReturnDstu1Bundle();
|
||||
|
||||
/**
|
||||
* Return a Bundle resource of the given type
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.gclient;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -22,20 +22,12 @@ package ca.uhn.fhir.rest.gclient;
|
|||
|
||||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
|
||||
public interface IHistoryUntyped {
|
||||
|
||||
/**
|
||||
* Request that the method return a DSTU1 style bundle object. This method should only
|
||||
* be called if you are accessing a DSTU1 server.
|
||||
*/
|
||||
IHistoryTyped<Bundle> andReturnDstu1Bundle();
|
||||
|
||||
/**
|
||||
* Request that the method return a Bundle resource (such as <code>ca.uhn.fhir.model.dstu2.resource.Bundle</code>).
|
||||
* Use this method if you are accessing a DSTU2+ server.
|
||||
*/
|
||||
<T extends IBaseBundle> IHistoryTyped<T> andReturnBundle(Class<T> theType);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import ca.uhn.fhir.model.api.Include;
|
|||
import ca.uhn.fhir.rest.api.SearchStyleEnum;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
|
||||
public interface IQuery<T> extends IClientExecutable<IQuery<T>, T>, IBaseQuery<IQuery<T>> {
|
||||
public interface IQuery extends IBaseQuery<IQuery> {
|
||||
|
||||
/**
|
||||
* Add an "_include" specification or an "_include:recurse" specification. If you are using
|
||||
|
@ -39,9 +39,9 @@ public interface IQuery<T> extends IClientExecutable<IQuery<T>, T>, IBaseQuery<I
|
|||
* <li><b>No Recurse:</b> <code>.include(Patient.INCLUDE_ORGANIZATION.asNonRecursive())</code>
|
||||
* </ul>
|
||||
*/
|
||||
IQuery<T> include(Include theInclude);
|
||||
IQuery include(Include theInclude);
|
||||
|
||||
ISort<T> sort();
|
||||
ISort sort();
|
||||
|
||||
/**
|
||||
* Specifies the <code>_count</code> parameter, which indicates to the server how many resources should be returned
|
||||
|
@ -50,7 +50,7 @@ public interface IQuery<T> extends IClientExecutable<IQuery<T>, T>, IBaseQuery<I
|
|||
* @deprecated This parameter is badly named, since FHIR calls this parameter "_count" and not "_limit". Use {@link #count(int)} instead (it also sets the _count parameter)
|
||||
*/
|
||||
@Deprecated
|
||||
IQuery<T> limitTo(int theLimitTo);
|
||||
IQuery limitTo(int theLimitTo);
|
||||
|
||||
/**
|
||||
* Specifies the <code>_count</code> parameter, which indicates to the server how many resources should be returned
|
||||
|
@ -58,7 +58,7 @@ public interface IQuery<T> extends IClientExecutable<IQuery<T>, T>, IBaseQuery<I
|
|||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
IQuery<T> count(int theCount);
|
||||
IQuery count(int theCount);
|
||||
|
||||
/**
|
||||
* Match only resources where the resource has the given tag. This parameter corresponds to
|
||||
|
@ -66,7 +66,7 @@ public interface IQuery<T> extends IClientExecutable<IQuery<T>, T>, IBaseQuery<I
|
|||
* @param theSystem The tag code system, or <code>null</code> to match any code system (this may not be supported on all servers)
|
||||
* @param theCode The tag code. Must not be <code>null</code> or empty.
|
||||
*/
|
||||
IQuery<T> withTag(String theSystem, String theCode);
|
||||
IQuery withTag(String theSystem, String theCode);
|
||||
|
||||
/**
|
||||
* Match only resources where the resource has the given security tag. This parameter corresponds to
|
||||
|
@ -74,21 +74,21 @@ public interface IQuery<T> extends IClientExecutable<IQuery<T>, T>, IBaseQuery<I
|
|||
* @param theSystem The tag code system, or <code>null</code> to match any code system (this may not be supported on all servers)
|
||||
* @param theCode The tag code. Must not be <code>null</code> or empty.
|
||||
*/
|
||||
IQuery<T> withSecurity(String theSystem, String theCode);
|
||||
IQuery withSecurity(String theSystem, String theCode);
|
||||
|
||||
/**
|
||||
* Match only resources where the resource has the given profile declaration. This parameter corresponds to
|
||||
* the <code>_profile</code> URL parameter.
|
||||
* @param theProfileUri The URI of a given profile to search for resources which match
|
||||
*/
|
||||
IQuery<T> withProfile(String theProfileUri);
|
||||
IQuery withProfile(String theProfileUri);
|
||||
|
||||
/**
|
||||
* Matches any of the profiles given as argument. This would result in an OR search for resources matching one or more profiles.
|
||||
* To do an AND search, make multiple calls to {@link #withProfile(String)}.
|
||||
* @param theProfileUris The URIs of a given profile to search for resources which match.
|
||||
*/
|
||||
IQuery<T> withAnyProfile(Collection<String> theProfileUris);
|
||||
IQuery withAnyProfile(Collection<String> theProfileUris);
|
||||
|
||||
/**
|
||||
* Forces the query to perform the search using the given method (allowable methods are described in the
|
||||
|
@ -100,51 +100,42 @@ public interface IQuery<T> extends IClientExecutable<IQuery<T>, T>, IBaseQuery<I
|
|||
* @see SearchStyleEnum
|
||||
* @since 0.6
|
||||
*/
|
||||
IQuery<T> usingStyle(SearchStyleEnum theStyle);
|
||||
IQuery usingStyle(SearchStyleEnum theStyle);
|
||||
|
||||
IQuery<T> withIdAndCompartment(String theResourceId, String theCompartmentName);
|
||||
IQuery withIdAndCompartment(String theResourceId, String theCompartmentName);
|
||||
|
||||
/**
|
||||
* Add a "_revinclude" specification
|
||||
*
|
||||
* @since HAPI FHIR 1.0 - Note that option was added to FHIR itself in DSTU2
|
||||
*/
|
||||
IQuery<T> revInclude(Include theIncludeTarget);
|
||||
IQuery revInclude(Include theIncludeTarget);
|
||||
|
||||
/**
|
||||
* Add a "_lastUpdated" specification
|
||||
*
|
||||
* @since HAPI FHIR 1.1 - Note that option was added to FHIR itself in DSTU2
|
||||
*/
|
||||
IQuery<T> lastUpdated(DateRangeParam theLastUpdated);
|
||||
IQuery lastUpdated(DateRangeParam theLastUpdated);
|
||||
|
||||
/**
|
||||
* Request that the client return the specified bundle type, e.g. <code>org.hl7.fhir.instance.model.Bundle.class</code>
|
||||
* or <code>ca.uhn.fhir.model.dstu2.resource.Bundle.class</code>
|
||||
*/
|
||||
<B extends IBaseBundle> IClientExecutable<IQuery<B>, B> returnBundle(Class<B> theClass);
|
||||
<B extends IBaseBundle> IQueryTyped<B> returnBundle(Class<B> theClass);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
// This is here as an overridden method to allow mocking clients with Mockito to work
|
||||
@Override
|
||||
IQuery<T> where(ICriterion<?> theCriterion);
|
||||
IQuery where(ICriterion<?> theCriterion);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
// This is here as an overridden method to allow mocking clients with Mockito to work
|
||||
@Override
|
||||
IQuery<T> and(ICriterion<?> theCriterion);
|
||||
IQuery and(ICriterion<?> theCriterion);
|
||||
|
||||
/**
|
||||
* @deprecated You should call {@link #returnBundle(Class)} on the method chain before calling
|
||||
* {@link #execute()} in order to specify why return type to use
|
||||
*/
|
||||
// This is overriding in order to deprecate
|
||||
@Deprecated
|
||||
@Override
|
||||
T execute();
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package ca.uhn.fhir.rest.gclient;
|
||||
|
||||
public interface IQueryTyped<T> extends IQuery, IClientExecutable<IClientExecutable<?,?>, T> {
|
||||
|
||||
/**
|
||||
* Actually execute the client operation
|
||||
*/
|
||||
@Override
|
||||
T execute();
|
||||
|
||||
}
|
|
@ -20,19 +20,19 @@ package ca.uhn.fhir.rest.gclient;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
public interface ISort<T> {
|
||||
public interface ISort {
|
||||
|
||||
/**
|
||||
* Sort ascending
|
||||
*/
|
||||
IQuery<T> ascending(IParam theParam);
|
||||
IQuery ascending(IParam theParam);
|
||||
|
||||
/**
|
||||
* Sort ascending
|
||||
*
|
||||
* @param theParam The param name, e.g. "address"
|
||||
*/
|
||||
IQuery<T> ascending(String theParam);
|
||||
IQuery ascending(String theParam);
|
||||
|
||||
/**
|
||||
* Sort by the default order. Note that as of STU3, there is no longer
|
||||
|
@ -40,7 +40,7 @@ public interface ISort<T> {
|
|||
* technically implies "ascending" but it makes more sense to use
|
||||
* {@link #ascending(IParam)}
|
||||
*/
|
||||
IQuery<T> defaultOrder(IParam theParam);
|
||||
IQuery defaultOrder(IParam theParam);
|
||||
|
||||
/**
|
||||
* Sort descending
|
||||
|
@ -48,13 +48,13 @@ public interface ISort<T> {
|
|||
* @param theParam A query param - Could be a constant such as <code>Patient.ADDRESS</code> or a custom
|
||||
* param such as <code>new StringClientParam("foo")</code>
|
||||
*/
|
||||
IQuery<T> descending(IParam theParam);
|
||||
IQuery descending(IParam theParam);
|
||||
|
||||
/**
|
||||
* Sort ascending
|
||||
*
|
||||
* @param theParam The param name, e.g. "address"
|
||||
*/
|
||||
IQuery<T> descending(String theParam);
|
||||
IQuery descending(String theParam);
|
||||
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@ import java.util.List;
|
|||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
|
||||
public interface ITransaction {
|
||||
|
||||
/**
|
||||
|
@ -35,12 +33,7 @@ public interface ITransaction {
|
|||
ITransactionTyped<List<IBaseResource>> withResources(List<? extends IBaseResource> theResources);
|
||||
|
||||
/**
|
||||
* Use a DSTU1 Bundle (Atom) as the transaction input
|
||||
*/
|
||||
ITransactionTyped<Bundle> withBundle(Bundle theBundle);
|
||||
|
||||
/**
|
||||
* Use a DSTU2+ Bundle resource as the transaction input
|
||||
* Use the given Bundle resource as the transaction input
|
||||
*/
|
||||
<T extends IBaseBundle> ITransactionTyped<T> withBundle(T theBundleResource);
|
||||
|
||||
|
|
|
@ -22,15 +22,13 @@ package ca.uhn.fhir.rest.gclient;
|
|||
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
|
||||
public interface IUntypedQuery {
|
||||
|
||||
IQuery<Bundle> forAllResources();
|
||||
IQuery forAllResources();
|
||||
|
||||
IQuery<Bundle> forResource(String theResourceName);
|
||||
IQuery forResource(String theResourceName);
|
||||
|
||||
IQuery<Bundle> forResource(Class<? extends IBaseResource> theClass);
|
||||
IQuery forResource(Class<? extends IBaseResource> theClass);
|
||||
|
||||
/**
|
||||
* Perform a search directly by URL. It is usually better to construct the URL using the {@link #forAllResources()}, {@link #forResource(Class)} etc, but sometimes it is useful to simply search by
|
||||
|
@ -40,6 +38,6 @@ public interface IUntypedQuery {
|
|||
* The URL to search for. Note that this URL may be complete (e.g. "http://example.com/base/Patient?name=foo") in which case the client's base URL will be ignored. Or it can be relative
|
||||
* (e.g. "Patient?name=foo") in which case the client's base URL will be used.
|
||||
*/
|
||||
IQuery<Bundle> byUrl(String theSearchUrl);
|
||||
IQuery byUrl(String theSearchUrl);
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ package ca.uhn.fhir.rest.gclient;
|
|||
*/
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.rest.gclient.NumberClientParam.IMatches;
|
||||
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
|
||||
|
||||
|
@ -126,26 +125,6 @@ public class QuantityClientParam extends BaseClientParam implements IParam {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #withPrefix(ParamPrefixEnum)} instead, as {@link QuantityCompararatorEnum} has been deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public IMatches<IAndUnits> withComparator(QuantityCompararatorEnum theComparator) {
|
||||
final String cmpString = theComparator != null ? theComparator.getCode() : "";
|
||||
final ParamPrefixEnum prefix = ParamPrefixEnum.forDstu1Value(cmpString);
|
||||
return new NumberClientParam.IMatches<IAndUnits>() {
|
||||
@Override
|
||||
public IAndUnits number(long theNumber) {
|
||||
return new AndUnits(prefix, Long.toString(theNumber));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAndUnits number(String theNumber) {
|
||||
return new AndUnits(prefix, theNumber);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the given quantity prefix
|
||||
*
|
||||
|
|
|
@ -52,7 +52,7 @@ class QuantityCriterion implements ICriterion<QuantityClientParam>, ICriterionIn
|
|||
StringBuilder b = new StringBuilder();
|
||||
if (isNotBlank(myValue) || isNotBlank(mySystem) || isNotBlank(myUnits)) {
|
||||
if (myPrefix != null) {
|
||||
b.append(ParameterUtil.escapeWithDefault(myPrefix.getValueForContext(theContext)));
|
||||
b.append(ParameterUtil.escapeWithDefault(myPrefix.getValue()));
|
||||
}
|
||||
b.append(ParameterUtil.escapeWithDefault(myValue));
|
||||
b.append('|');
|
||||
|
|
|
@ -73,7 +73,7 @@ class StringCriterion<A extends IParam> implements ICriterion<A>, ICriterionInte
|
|||
return "";
|
||||
}
|
||||
if (myPrefix != null) {
|
||||
return myPrefix.getValueForContext(theContext) + myValue;
|
||||
return myPrefix.getValue() + myValue;
|
||||
}
|
||||
return myValue;
|
||||
}
|
||||
|
|
|
@ -1,33 +1,9 @@
|
|||
package ca.uhn.fhir.rest.param;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2017 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.util.CoverageIgnore;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class BaseParamWithPrefix<T extends BaseParam> extends BaseParam {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ParamPrefixEnum myPrefix;
|
||||
|
||||
/**
|
||||
|
@ -57,26 +33,10 @@ public abstract class BaseParamWithPrefix<T extends BaseParam> extends BaseParam
|
|||
|
||||
String prefix = theString.substring(0, offset);
|
||||
myPrefix = ParamPrefixEnum.forValue(prefix);
|
||||
if (myPrefix == null) {
|
||||
myPrefix = ParamPrefixEnum.forDstu1Value(prefix);
|
||||
}
|
||||
|
||||
return theString.substring(offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getPrefix()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public QuantityCompararatorEnum getComparator() {
|
||||
ParamPrefixEnum prefix = getPrefix();
|
||||
if (prefix == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return QuantityCompararatorEnum.forCode(prefix.getDstu1Value());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prefix used by this parameter (e.g. "<code>gt</code>", or "<code>eq</code>")
|
||||
*/
|
||||
|
@ -84,36 +44,6 @@ public abstract class BaseParamWithPrefix<T extends BaseParam> extends BaseParam
|
|||
return myPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setPrefix(ParamPrefixEnum)} instead
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@CoverageIgnore
|
||||
@Deprecated
|
||||
public T setComparator(QuantityCompararatorEnum theComparator) {
|
||||
if (theComparator != null) {
|
||||
myPrefix = ParamPrefixEnum.forDstu1Value(theComparator.getCode());
|
||||
} else {
|
||||
myPrefix = null;
|
||||
}
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setPrefix(ParamPrefixEnum)} instead
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@CoverageIgnore
|
||||
@Deprecated
|
||||
public T setComparator(String theComparator) {
|
||||
if (isNotBlank(theComparator)) {
|
||||
myPrefix = ParamPrefixEnum.forDstu1Value(theComparator);
|
||||
} else {
|
||||
myPrefix = null;
|
||||
}
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the prefix used by this parameter (e.g. "<code>gt</code>", or "<code>eq</code>")
|
||||
*/
|
||||
|
|
|
@ -31,13 +31,11 @@ import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
|||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterOr;
|
||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.rest.api.QualifiedParamList;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.util.ValidateUtil;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DateParam extends BaseParamWithPrefix<DateParam> implements /*IQueryParameterType , */IQueryParameterOr<DateParam> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
@ -91,66 +89,6 @@ public class DateParam extends BaseParamWithPrefix<DateParam> implements /*IQuer
|
|||
setValueAsString(theDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @deprecated Use constructors with {@link ParamPrefixEnum} parameter instead, as {@link QuantityCompararatorEnum}
|
||||
* is deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public DateParam(QuantityCompararatorEnum theComparator, Date theDate) {
|
||||
setPrefix(toPrefix(theComparator));
|
||||
setValue(theDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @deprecated Use constructors with {@link ParamPrefixEnum} parameter instead, as {@link QuantityCompararatorEnum}
|
||||
* is deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public DateParam(QuantityCompararatorEnum theComparator, DateTimeDt theDate) {
|
||||
setPrefix(toPrefix(theComparator));
|
||||
setValue(theDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @deprecated Use constructors with {@link ParamPrefixEnum} parameter instead, as {@link QuantityCompararatorEnum}
|
||||
* is deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public DateParam(QuantityCompararatorEnum theComparator, IPrimitiveType<Date> theDate) {
|
||||
setPrefix(toPrefix(theComparator));
|
||||
setValue(theDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @deprecated Use constructors with {@link ParamPrefixEnum} parameter instead, as {@link QuantityCompararatorEnum}
|
||||
* is deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public DateParam(QuantityCompararatorEnum theComparator, long theDate) {
|
||||
ValidateUtil.isGreaterThan(theDate, 0, "theDate must not be 0 or negative");
|
||||
setPrefix(toPrefix(theComparator));
|
||||
setValue(new Date(theDate));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @deprecated Use constructors with {@link ParamPrefixEnum} parameter instead, as {@link QuantityCompararatorEnum}
|
||||
* is deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public DateParam(QuantityCompararatorEnum theComparator, String theDate) {
|
||||
setPrefix(toPrefix(theComparator));
|
||||
setValueAsString(theDate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which takes a complete [qualifier]{date} string.
|
||||
|
@ -171,7 +109,7 @@ public class DateParam extends BaseParamWithPrefix<DateParam> implements /*IQuer
|
|||
String doGetValueAsQueryToken(FhirContext theContext) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
if (getPrefix() != null) {
|
||||
b.append(ParameterUtil.escapeWithDefault(getPrefix().getValueForContext(theContext)));
|
||||
b.append(ParameterUtil.escapeWithDefault(getPrefix().getValue()));
|
||||
}
|
||||
|
||||
if (myValue != null) {
|
||||
|
@ -284,12 +222,6 @@ public class DateParam extends BaseParamWithPrefix<DateParam> implements /*IQuer
|
|||
|
||||
}
|
||||
|
||||
private ParamPrefixEnum toPrefix(QuantityCompararatorEnum theComparator) {
|
||||
if (theComparator != null) {
|
||||
return ParamPrefixEnum.forDstu1Value(theComparator.getCode());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
@ -71,7 +71,7 @@ public class NumberParam extends BaseParamWithPrefix<NumberParam> implements IQu
|
|||
String doGetValueAsQueryToken(FhirContext theContext) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
if (getPrefix() != null) {
|
||||
b.append(ParameterUtil.escapeWithDefault(getPrefix().getValueForContext(theContext)));
|
||||
b.append(ParameterUtil.escapeWithDefault(getPrefix().getValue()));
|
||||
}
|
||||
b.append(ParameterUtil.escapeWithDefault(myQuantity.toPlainString()));
|
||||
return b.toString();
|
||||
|
|
|
@ -1,33 +1,6 @@
|
|||
package ca.uhn.fhir.rest.param;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2017 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Comparator/qualifier for values used in REST params, such as {@link DateParam}, {@link NumberParam}, and
|
||||
|
@ -42,126 +15,88 @@ public enum ParamPrefixEnum {
|
|||
*
|
||||
* The actual value is equal to the given value
|
||||
*/
|
||||
APPROXIMATE("~", "ap"),
|
||||
APPROXIMATE("ap"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>eb</b>
|
||||
*
|
||||
* The range of the search value does overlap not with the range of the target value, and the range above the search value contains the range of the target value
|
||||
*/
|
||||
ENDS_BEFORE("", "eb"),
|
||||
ENDS_BEFORE("eb"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>eq</b>
|
||||
*
|
||||
* The actual value is equal to the given value
|
||||
*/
|
||||
EQUAL("", "eq"),
|
||||
EQUAL("eq"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>gt</b>
|
||||
*
|
||||
* The actual value is greater than the given value.
|
||||
*/
|
||||
GREATERTHAN(">", "gt"),
|
||||
GREATERTHAN("gt"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>ge</b>
|
||||
*
|
||||
* The actual value is greater than or equal to the given value.
|
||||
*/
|
||||
GREATERTHAN_OR_EQUALS(">=", "ge"),
|
||||
GREATERTHAN_OR_EQUALS("ge"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>lt</b>
|
||||
*
|
||||
* The actual value is less than the given value.
|
||||
*/
|
||||
LESSTHAN("<", "lt"),
|
||||
LESSTHAN("lt"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>le</b>
|
||||
*
|
||||
* The actual value is less than or equal to the given value.
|
||||
*/
|
||||
LESSTHAN_OR_EQUALS("<=", "le"),
|
||||
LESSTHAN_OR_EQUALS("le"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>ne</b>
|
||||
*
|
||||
* The actual value is not equal to the given value
|
||||
*/
|
||||
NOT_EQUAL("", "ne"),
|
||||
NOT_EQUAL("ne"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>sa</b>
|
||||
*
|
||||
* The range of the search value does not overlap with the range of the target value, and the range below the search value contains the range of the target value
|
||||
*/
|
||||
STARTS_AFTER("", "sa");
|
||||
STARTS_AFTER("sa");
|
||||
|
||||
private static final Map<String, ParamPrefixEnum> DSTU1_TO_PREFIX;
|
||||
private static final Map<String, ParamPrefixEnum> VALUE_TO_PREFIX;
|
||||
|
||||
static {
|
||||
HashMap<String, ParamPrefixEnum> valueToPrefix = new HashMap<String, ParamPrefixEnum>();
|
||||
HashMap<String, ParamPrefixEnum> dstu1ToPrefix = new HashMap<String, ParamPrefixEnum>();
|
||||
for (ParamPrefixEnum next : values()) {
|
||||
valueToPrefix.put(next.getValue(), next);
|
||||
if (isNotBlank(next.getDstu1Value())) {
|
||||
dstu1ToPrefix.put(next.getDstu1Value(), next);
|
||||
}
|
||||
}
|
||||
|
||||
VALUE_TO_PREFIX = Collections.unmodifiableMap(valueToPrefix);
|
||||
DSTU1_TO_PREFIX = Collections.unmodifiableMap(dstu1ToPrefix);
|
||||
}
|
||||
|
||||
private final String myDstu1Value;
|
||||
|
||||
private final String myValue;
|
||||
|
||||
private ParamPrefixEnum(String theDstu1Value, String theValue) {
|
||||
myDstu1Value = theDstu1Value;
|
||||
private ParamPrefixEnum(String theValue) {
|
||||
myValue = theValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the DSTU1 value, e.g. <code><</code> or <code>~</code>
|
||||
*/
|
||||
public String getDstu1Value() {
|
||||
return myDstu1Value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the DSTU2+ value, e.g. <code>lt</code> or <code>eq</code>
|
||||
* Returns the value, e.g. <code>lt</code> or <code>eq</code>
|
||||
*/
|
||||
public String getValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate value for the given context, based on the
|
||||
* FHIR version supported by the context
|
||||
*/
|
||||
public String getValueForContext(FhirContext theContext) {
|
||||
if (theContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
return getDstu1Value();
|
||||
}
|
||||
return getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prefix associated with a given DSTU1 value (e.g. <code><</code> or <code>~</code>)
|
||||
*
|
||||
* @param theValue
|
||||
* e.g. <code><</code> or <code>~</code>
|
||||
* @return The prefix, or <code>null</code> if no prefix matches the value
|
||||
*/
|
||||
public static ParamPrefixEnum forDstu1Value(String theValue) {
|
||||
return DSTU1_TO_PREFIX.get(theValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the prefix associated with a given DSTU2+ value (e.g. <code>lt</code> or <code>eq</code>)
|
||||
*
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.rest.param;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -30,14 +30,13 @@ import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.primitive.DecimalDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.util.CoverageIgnore;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class QuantityParam extends BaseParamWithPrefix<QuantityParam> implements IQueryParameterType {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private BigDecimal myValue;
|
||||
private String mySystem;
|
||||
private String myUnits;
|
||||
|
@ -49,86 +48,17 @@ public class QuantityParam extends BaseParamWithPrefix<QuantityParam> implements
|
|||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param theComparator
|
||||
* The comparator, or <code>null</code> for an equals comparator
|
||||
* @param theValue
|
||||
* A quantity value
|
||||
* @param theSystem
|
||||
* The unit system
|
||||
* @param theUnits
|
||||
* The unit code
|
||||
* @deprecated Use the equivalent constructor which uses {@link ParamPrefixEnum} instead, as {@link QuantityCompararatorEnum} has been deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public QuantityParam(QuantityCompararatorEnum theComparator, BigDecimal theValue, String theSystem, String theUnits) {
|
||||
setComparator(theComparator);
|
||||
setValue(theValue);
|
||||
setSystem(theSystem);
|
||||
setUnits(theUnits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param theComparator
|
||||
* The comparator, or <code>null</code> for an equals comparator
|
||||
* @param theValue
|
||||
* A quantity value
|
||||
* @param theSystem
|
||||
* The unit system
|
||||
* @param theUnits
|
||||
* The unit code
|
||||
* @deprecated Use the equivalent constructor which uses {@link ParamPrefixEnum} instead, as {@link QuantityCompararatorEnum} has been deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public QuantityParam(QuantityCompararatorEnum theComparator, double theValue, String theSystem, String theUnits) {
|
||||
setComparator(theComparator);
|
||||
setValue(theValue);
|
||||
setSystem(theSystem);
|
||||
setUnits(theUnits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param theComparator
|
||||
* The comparator, or <code>null</code> for an equals comparator
|
||||
* @param theValue
|
||||
* A quantity value
|
||||
* @param theSystem
|
||||
* The unit system
|
||||
* @param theUnits
|
||||
* The unit code
|
||||
* @deprecated Use the equivalent constructor which uses {@link ParamPrefixEnum} instead, as {@link QuantityCompararatorEnum} has been deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public QuantityParam(QuantityCompararatorEnum theComparator, long theValue, String theSystem, String theUnits) {
|
||||
setComparator(theComparator);
|
||||
setValue(theValue);
|
||||
setSystem(theSystem);
|
||||
setUnits(theUnits);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param thePrefix
|
||||
* The comparator, or <code>null</code> for an equals comparator
|
||||
* The comparator, or <code>null</code> for an equals comparator
|
||||
* @param theValue
|
||||
* A quantity value
|
||||
* A quantity value
|
||||
* @param theSystem
|
||||
* The unit system
|
||||
* The unit system
|
||||
* @param theUnits
|
||||
* The unit code
|
||||
* The unit code
|
||||
*/
|
||||
public QuantityParam(ParamPrefixEnum thePrefix, BigDecimal theValue, String theSystem, String theUnits) {
|
||||
setPrefix(thePrefix);
|
||||
|
@ -141,13 +71,13 @@ public class QuantityParam extends BaseParamWithPrefix<QuantityParam> implements
|
|||
* Constructor
|
||||
*
|
||||
* @param thePrefix
|
||||
* The comparator, or <code>null</code> for an equals comparator
|
||||
* The comparator, or <code>null</code> for an equals comparator
|
||||
* @param theValue
|
||||
* A quantity value
|
||||
* A quantity value
|
||||
* @param theSystem
|
||||
* The unit system
|
||||
* The unit system
|
||||
* @param theUnits
|
||||
* The unit code
|
||||
* The unit code
|
||||
*/
|
||||
public QuantityParam(ParamPrefixEnum thePrefix, double theValue, String theSystem, String theUnits) {
|
||||
setPrefix(thePrefix);
|
||||
|
@ -160,13 +90,13 @@ public class QuantityParam extends BaseParamWithPrefix<QuantityParam> implements
|
|||
* Constructor
|
||||
*
|
||||
* @param thePrefix
|
||||
* The comparator, or <code>null</code> for an equals comparator
|
||||
* The comparator, or <code>null</code> for an equals comparator
|
||||
* @param theValue
|
||||
* A quantity value
|
||||
* A quantity value
|
||||
* @param theSystem
|
||||
* The unit system
|
||||
* The unit system
|
||||
* @param theUnits
|
||||
* The unit code
|
||||
* The unit code
|
||||
*/
|
||||
public QuantityParam(ParamPrefixEnum thePrefix, long theValue, String theSystem, String theUnits) {
|
||||
setPrefix(thePrefix);
|
||||
|
@ -175,12 +105,11 @@ public class QuantityParam extends BaseParamWithPrefix<QuantityParam> implements
|
|||
setUnits(theUnits);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param theQuantity
|
||||
* A quantity value (with no system or units), such as "100.0" or "gt4"
|
||||
* A quantity value (with no system or units), such as "100.0" or "gt4"
|
||||
*/
|
||||
public QuantityParam(String theQuantity) {
|
||||
setValueAsQueryToken(null, null, null, theQuantity);
|
||||
|
@ -190,7 +119,7 @@ public class QuantityParam extends BaseParamWithPrefix<QuantityParam> implements
|
|||
* Constructor
|
||||
*
|
||||
* @param theQuantity
|
||||
* A quantity value (with no system or units), such as <code>100</code>
|
||||
* A quantity value (with no system or units), such as <code>100</code>
|
||||
*/
|
||||
public QuantityParam(long theQuantity) {
|
||||
setValueAsQueryToken(null, null, null, Long.toString(theQuantity));
|
||||
|
@ -200,11 +129,11 @@ public class QuantityParam extends BaseParamWithPrefix<QuantityParam> implements
|
|||
* Constructor
|
||||
*
|
||||
* @param theQuantity
|
||||
* A quantity value (with no system or units), such as "100.0" or "<=4"
|
||||
* A quantity value (with no system or units), such as "100.0" or "<=4"
|
||||
* @param theSystem
|
||||
* The unit system
|
||||
* The unit system
|
||||
* @param theUnits
|
||||
* The unit code
|
||||
* The unit code
|
||||
*/
|
||||
public QuantityParam(String theQuantity, String theSystem, String theUnits) {
|
||||
setValueAsQueryToken(null, null, null, theQuantity);
|
||||
|
@ -214,9 +143,9 @@ public class QuantityParam extends BaseParamWithPrefix<QuantityParam> implements
|
|||
|
||||
private void clear() {
|
||||
setPrefix(null);
|
||||
setSystem((String)null);
|
||||
setSystem((String) null);
|
||||
setUnits(null);
|
||||
setValue((BigDecimal)null);
|
||||
setValue((BigDecimal) null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -228,7 +157,7 @@ public class QuantityParam extends BaseParamWithPrefix<QuantityParam> implements
|
|||
String doGetValueAsQueryToken(FhirContext theContext) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
if (getPrefix() != null) {
|
||||
b.append(ParameterUtil.escapeWithDefault(getPrefix().getValueForContext(theContext)));
|
||||
b.append(ParameterUtil.escapeWithDefault(getPrefix().getValue()));
|
||||
}
|
||||
|
||||
b.append(ParameterUtil.escapeWithDefault(getValueAsString()));
|
||||
|
@ -294,7 +223,6 @@ public class QuantityParam extends BaseParamWithPrefix<QuantityParam> implements
|
|||
return myUnits;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the quantity/value, or null if none was provided
|
||||
* <p>
|
||||
|
@ -306,35 +234,6 @@ public class QuantityParam extends BaseParamWithPrefix<QuantityParam> implements
|
|||
public BigDecimal getValue() {
|
||||
return myValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getValue()} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public DecimalDt getValueAsDecimalDt() {
|
||||
return new DecimalDt(myValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getPrefix()} with the {@link ParamPrefixEnum#APPROXIMATE} constant
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isApproximate() {
|
||||
return getPrefix() == ParamPrefixEnum.APPROXIMATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setPrefix(ParamPrefixEnum)} with the {@link ParamPrefixEnum#APPROXIMATE} constant
|
||||
*/
|
||||
@Deprecated
|
||||
public void setApproximate(boolean theApproximate) {
|
||||
if (theApproximate) {
|
||||
setPrefix(ParamPrefixEnum.APPROXIMATE);
|
||||
} else {
|
||||
setPrefix(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public QuantityParam setSystem(String theSystem) {
|
||||
mySystem = theSystem;
|
||||
|
|
|
@ -19,11 +19,8 @@ package ca.uhn.fhir.rest.server.exceptions;
|
|||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
import org.hl7.fhir.instance.model.api.*;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.base.composite.BaseIdentifierDt;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.util.CoverageIgnore;
|
||||
|
@ -52,7 +49,7 @@ public class ResourceGoneException extends BaseServerResponseException {
|
|||
* 1.6 - 2016-07-02
|
||||
*/
|
||||
@Deprecated
|
||||
public ResourceGoneException(Class<? extends IResource> theClass, BaseIdentifierDt thePatientId) {
|
||||
public ResourceGoneException(Class<? extends IBaseResource> theClass, BaseIdentifierDt thePatientId) {
|
||||
super(STATUS_CODE, "Resource of type " + theClass.getSimpleName() + " with ID " + thePatientId + " is gone/deleted");
|
||||
}
|
||||
|
||||
|
@ -64,7 +61,7 @@ public class ResourceGoneException extends BaseServerResponseException {
|
|||
* @param theResourceId
|
||||
* The ID of the resource that could not be found
|
||||
*/
|
||||
public ResourceGoneException(Class<? extends IResource> theClass, IIdType theResourceId) {
|
||||
public ResourceGoneException(Class<? extends IBaseResource> theClass, IIdType theResourceId) {
|
||||
super(STATUS_CODE, "Resource of type " + theClass.getSimpleName() + " with ID " + theResourceId + " is gone/deleted");
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ public class ResourceNotFoundException extends BaseServerResponseException {
|
|||
super(STATUS_CODE, createErrorMessage(theId));
|
||||
}
|
||||
|
||||
public ResourceNotFoundException(IdDt theId, IBaseOperationOutcome theOperationOutcome) {
|
||||
public ResourceNotFoundException(IIdType theId, IBaseOperationOutcome theOperationOutcome) {
|
||||
super(STATUS_CODE, createErrorMessage(theId), theOperationOutcome);
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ public class ResourceNotFoundException extends BaseServerResponseException {
|
|||
super(STATUS_CODE, theMessage);
|
||||
}
|
||||
|
||||
private static String createErrorMessage(Class<? extends IResource> theClass, IIdType theId) {
|
||||
private static String createErrorMessage(Class<? extends IResource> theClass, IIdType theId) {
|
||||
return "Resource of type " + theClass.getSimpleName() + " with ID " + theId + " is not known";
|
||||
}
|
||||
|
||||
|
|
|
@ -70,10 +70,7 @@ public class OperationOutcomeUtil {
|
|||
}
|
||||
|
||||
public static String getFirstIssueDetails(FhirContext theCtx, IBaseOperationOutcome theOutcome) {
|
||||
if (theCtx.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
return getFirstIssueStringPart(theCtx, theOutcome, "diagnostics");
|
||||
}
|
||||
return getFirstIssueStringPart(theCtx, theOutcome, "details");
|
||||
return getFirstIssueStringPart(theCtx, theOutcome, "diagnostics");
|
||||
}
|
||||
|
||||
public static String getFirstIssueLocation(FhirContext theCtx, IBaseOperationOutcome theOutcome) {
|
||||
|
@ -130,16 +127,12 @@ public class OperationOutcomeUtil {
|
|||
private static void populateDetails(FhirContext theCtx, IBase theIssue, String theSeverity, String theDetails, String theLocation, String theCode) {
|
||||
BaseRuntimeElementCompositeDefinition<?> issueElement = (BaseRuntimeElementCompositeDefinition<?>) theCtx.getElementDefinition(theIssue.getClass());
|
||||
BaseRuntimeChildDefinition detailsChild;
|
||||
if (theCtx.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
detailsChild = issueElement.getChildByName("diagnostics");
|
||||
detailsChild = issueElement.getChildByName("diagnostics");
|
||||
|
||||
BaseRuntimeChildDefinition codeChild = issueElement.getChildByName("code");
|
||||
IPrimitiveType<?> codeElem = (IPrimitiveType<?>) codeChild.getChildByName("code").newInstance(codeChild.getInstanceConstructorArguments());
|
||||
codeElem.setValueAsString(theCode);
|
||||
codeChild.getMutator().addValue(theIssue, codeElem);
|
||||
} else {
|
||||
detailsChild = issueElement.getChildByName("details");
|
||||
}
|
||||
BaseRuntimeChildDefinition codeChild = issueElement.getChildByName("code");
|
||||
IPrimitiveType<?> codeElem = (IPrimitiveType<?>) codeChild.getChildByName("code").newInstance(codeChild.getInstanceConstructorArguments());
|
||||
codeElem.setValueAsString(theCode);
|
||||
codeChild.getMutator().addValue(theIssue, codeElem);
|
||||
|
||||
BaseRuntimeElementDefinition<?> stringDef = detailsChild.getChildByName(detailsChild.getElementName());
|
||||
BaseRuntimeChildDefinition severityChild = issueElement.getChildByName("severity");
|
||||
|
|
|
@ -19,19 +19,13 @@ package ca.uhn.fhir.validation;
|
|||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.util.OperationOutcomeUtil;
|
||||
import ca.uhn.fhir.validation.schematron.SchematronProvider;
|
||||
|
||||
/**
|
||||
|
@ -165,35 +159,6 @@ public class FhirValidator {
|
|||
myValidators = newValidators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a bundle instance, throwing a {@link ValidationFailureException} if the validation fails. This validation includes validation of all resources in the bundle.
|
||||
*
|
||||
* @param theBundle
|
||||
* The resource to validate
|
||||
* @throws ValidationFailureException
|
||||
* If the validation fails
|
||||
* @deprecated use {@link #validateWithResult(ca.uhn.fhir.model.api.Bundle)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void validate(Bundle theBundle) {
|
||||
Validate.notNull(theBundle, "theBundle must not be null");
|
||||
|
||||
applyDefaultValidators();
|
||||
|
||||
IValidationContext<Bundle> ctx = ValidationContext.forBundle(myContext, theBundle);
|
||||
|
||||
for (IValidatorModule next : myValidators) {
|
||||
next.validateBundle(ctx);
|
||||
}
|
||||
|
||||
if (ctx.toResult().isSuccessful() == false ) {
|
||||
IBaseOperationOutcome oo = ctx.toResult().toOperationOutcome();
|
||||
if (oo != null && OperationOutcomeUtil.hasIssues(myContext, oo)) {
|
||||
throw new ValidationFailureException(myContext, oo);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void applyDefaultValidators() {
|
||||
if (myValidators.isEmpty()) {
|
||||
|
@ -224,27 +189,6 @@ public class FhirValidator {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a bundle instance returning a {@link ca.uhn.fhir.validation.ValidationResult} which contains the results. This validation includes validation of all resources in the bundle.
|
||||
*
|
||||
* @param theBundle
|
||||
* the bundle to validate
|
||||
* @return the results of validation
|
||||
* @since 0.7
|
||||
*/
|
||||
public ValidationResult validateWithResult(Bundle theBundle) {
|
||||
Validate.notNull(theBundle, "theBundle must not be null");
|
||||
|
||||
applyDefaultValidators();
|
||||
|
||||
IValidationContext<Bundle> ctx = ValidationContext.forBundle(myContext, theBundle);
|
||||
|
||||
for (IValidatorModule next : myValidators) {
|
||||
next.validateBundle(ctx);
|
||||
}
|
||||
|
||||
return ctx.toResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a resource instance returning a {@link ca.uhn.fhir.validation.ValidationResult} which contains the results.
|
||||
|
|
|
@ -2,8 +2,6 @@ package ca.uhn.fhir.validation;
|
|||
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
|
||||
|
||||
/*
|
||||
* #%L
|
||||
|
@ -42,12 +40,4 @@ public interface IValidatorModule {
|
|||
*/
|
||||
void validateResource(IValidationContext<IBaseResource> theCtx);
|
||||
|
||||
/**
|
||||
* This method applies only to DSTU1 Atom Bundles. All other validation will pass through
|
||||
* {@link #validateResource(IValidationContext)} inclusing DSTU2+ Bundle resources. If you
|
||||
* will not be validating DSTU1 Bundles, you may implement this method as
|
||||
* a NO-OP.
|
||||
*/
|
||||
void validateBundle(IValidationContext<Bundle> theContext);
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ import org.w3c.dom.ls.LSInput;
|
|||
import org.w3c.dom.ls.LSResourceResolver;
|
||||
import org.xml.sax.*;
|
||||
|
||||
import ca.uhn.fhir.context.*;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
|
||||
|
@ -155,15 +155,6 @@ public class SchemaBaseValidator implements IValidatorModule {
|
|||
return baseSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateBundle(IValidationContext<Bundle> theContext) {
|
||||
if (myCtx.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
doValidate(theContext, "fhir-single.xsd");
|
||||
} else {
|
||||
doValidate(theContext, "fhir-atom-single.xsd");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateResource(IValidationContext<IBaseResource> theContext) {
|
||||
doValidate(theContext, "fhir-single.xsd");
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.validation;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -23,8 +23,6 @@ package ca.uhn.fhir.validation;
|
|||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.parser.LenientErrorHandler;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
|
@ -67,20 +65,6 @@ public class ValidationContext<T> extends BaseValidationContext<T> implements IV
|
|||
return myResourceAsStringEncoding;
|
||||
}
|
||||
|
||||
public static IValidationContext<Bundle> forBundle(final FhirContext theContext, final Bundle theBundle) {
|
||||
return new ValidationContext<Bundle>(theContext, theBundle, new IEncoder() {
|
||||
@Override
|
||||
public String encode() {
|
||||
return theContext.newXmlParser().encodeBundleToString(theBundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EncodingEnum getEncoding() {
|
||||
return EncodingEnum.XML;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static <T extends IBaseResource> IValidationContext<T> forResource(final FhirContext theContext, final T theResource) {
|
||||
return new ValidationContext<T>(theContext, theResource, new IEncoder() {
|
||||
@Override
|
||||
|
@ -95,41 +79,6 @@ public class ValidationContext<T> extends BaseValidationContext<T> implements IV
|
|||
});
|
||||
}
|
||||
|
||||
public static IValidationContext<IBaseResource> newChild(final IValidationContext<Bundle> theContext, final IResource theResource) {
|
||||
return new IValidationContext<IBaseResource>() {
|
||||
|
||||
@Override
|
||||
public void addValidationMessage(SingleValidationMessage theMessage) {
|
||||
theContext.addValidationMessage(theMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FhirContext getFhirContext() {
|
||||
return theContext.getFhirContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBaseResource getResource() {
|
||||
return theResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResourceAsString() {
|
||||
return theContext.getFhirContext().newXmlParser().encodeResourceToString(theResource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EncodingEnum getResourceAsStringEncoding() {
|
||||
return EncodingEnum.XML;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationResult toResult() {
|
||||
return theContext.toResult();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private interface IEncoder {
|
||||
String encode();
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ package ca.uhn.fhir.validation.schematron;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -37,8 +37,6 @@ import com.phloc.schematron.SchematronHelper;
|
|||
import com.phloc.schematron.xslt.SchematronResourceSCH;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.BundleEntry;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.validation.*;
|
||||
|
@ -124,11 +122,13 @@ public class SchematronBaseValidator implements IValidatorModule {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
String pathToBase = myCtx.getVersion().getPathToSchemaDefinitions() + '/' + theCtx.getFhirContext().getResourceDefinition(theCtx.getResource()).getBaseDefinition().getName().toLowerCase() + ".sch";
|
||||
String pathToBase = myCtx.getVersion().getPathToSchemaDefinitions() + '/' + theCtx.getFhirContext().getResourceDefinition(theCtx.getResource()).getBaseDefinition().getName().toLowerCase()
|
||||
+ ".sch";
|
||||
InputStream baseIs = FhirValidator.class.getResourceAsStream(pathToBase);
|
||||
try {
|
||||
if (baseIs == null) {
|
||||
throw new InternalErrorException("Failed to load schematron for resource '" + theCtx.getFhirContext().getResourceDefinition(theCtx.getResource()).getBaseDefinition().getName() + "'. " + SchemaBaseValidator.RESOURCES_JAR_NOTE);
|
||||
throw new InternalErrorException("Failed to load schematron for resource '" + theCtx.getFhirContext().getResourceDefinition(theCtx.getResource()).getBaseDefinition().getName() + "'. "
|
||||
+ SchemaBaseValidator.RESOURCES_JAR_NOTE);
|
||||
}
|
||||
} finally {
|
||||
IOUtils.closeQuietly(baseIs);
|
||||
|
@ -140,14 +140,4 @@ public class SchematronBaseValidator implements IValidatorModule {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateBundle(IValidationContext<Bundle> theContext) {
|
||||
for (BundleEntry next : theContext.getResource().getEntries()) {
|
||||
if (next.getResource() != null) {
|
||||
IValidationContext<IBaseResource> ctx = ValidationContext.newChild(theContext, next.getResource());
|
||||
validateResource(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package ca.uhn.fhir.rest.method;
|
||||
package ca.uhn.fhir.rest.api;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.rest.api.QualifiedParamList;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class QualifiedParamListTest {
|
|
@ -0,0 +1,71 @@
|
|||
package ca.uhn.fhir.cli;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.r4.model.CodeSystem;
|
||||
import org.hl7.fhir.r4.model.StructureDefinition;
|
||||
import org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent;
|
||||
import org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
||||
|
||||
public class LoadingValidationSupportR4 implements org.hl7.fhir.r4.hapi.ctx.IValidationSupport {
|
||||
|
||||
private FhirContext myCtx = FhirContext.forR4();
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(LoadingValidationSupportR4.class);
|
||||
|
||||
@Override
|
||||
public ValueSetExpansionComponent expandValueSet(FhirContext theContext, ConceptSetComponent theInclude) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeSystem fetchCodeSystem(FhirContext theContext, String theSystem) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends IBaseResource> T fetchResource(FhirContext theContext, Class<T> theClass, String theUri) {
|
||||
String resName = myCtx.getResourceDefinition(theClass).getName();
|
||||
ourLog.info("Attempting to fetch {} at URL: {}", resName, theUri);
|
||||
|
||||
myCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
IGenericClient client = myCtx.newRestfulGenericClient("http://example.com");
|
||||
|
||||
T result;
|
||||
try {
|
||||
result = client.read(theClass, theUri);
|
||||
} catch (BaseServerResponseException e) {
|
||||
throw new CommandFailureException("FAILURE: Received HTTP " + e.getStatusCode() + ": " + e.getMessage());
|
||||
}
|
||||
ourLog.info("Successfully loaded resource");
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StructureDefinition fetchStructureDefinition(FhirContext theCtx, String theUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCodeSystemSupported(FhirContext theContext, String theSystem) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeValidationResult validateCode(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StructureDefinition> fetchAllStructureDefinitions(FhirContext theContext) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
|
@ -22,9 +22,7 @@ import org.springframework.web.context.ContextLoaderListener;
|
|||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||
import ca.uhn.fhir.jpa.demo.ContextHolder;
|
||||
import ca.uhn.fhir.jpa.demo.FhirServerConfig;
|
||||
import ca.uhn.fhir.jpa.demo.FhirServerConfigDstu3;
|
||||
import ca.uhn.fhir.jpa.demo.*;
|
||||
|
||||
public class RunServerCommand extends BaseCommand {
|
||||
|
||||
|
@ -141,7 +139,9 @@ public class RunServerCommand extends BaseCommand {
|
|||
case DSTU3:
|
||||
theSce.getServletContext().setInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, FhirServerConfigDstu3.class.getName());
|
||||
break;
|
||||
case DSTU1:
|
||||
case R4:
|
||||
theSce.getServletContext().setInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, FhirServerConfigR4.class.getName());
|
||||
break;
|
||||
case DSTU2_1:
|
||||
case DSTU2_HL7ORG:
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
package ca.uhn.fhir.jpa.demo;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowire;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import ca.uhn.fhir.jpa.config.BaseJavaConfigR4;
|
||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||
import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorR4;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
import ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor;
|
||||
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
|
||||
|
||||
/**
|
||||
* This class isn't used by default by the example, but
|
||||
* you can use it as a config if you want to support DSTU3
|
||||
* instead of DSTU2 in your server.
|
||||
*
|
||||
* See https://github.com/jamesagnew/hapi-fhir/issues/278
|
||||
*/
|
||||
@Configuration
|
||||
@EnableTransactionManagement()
|
||||
@Import(FhirDbConfig.class)
|
||||
public class FhirServerConfigR4 extends BaseJavaConfigR4 {
|
||||
|
||||
/**
|
||||
* Configure FHIR properties around the the JPA server via this bean
|
||||
*/
|
||||
@Bean()
|
||||
public DaoConfig daoConfig() {
|
||||
DaoConfig retVal = new DaoConfig();
|
||||
retVal.setSubscriptionEnabled(true);
|
||||
retVal.setSubscriptionPollDelay(5000);
|
||||
retVal.setSubscriptionPurgeInactiveAfterMillis(DateUtils.MILLIS_PER_HOUR);
|
||||
retVal.setAllowMultipleDelete(true);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* The following bean configures the database connection. The 'url' property value of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the server should save resources in a
|
||||
* directory called "jpaserver_derby_files".
|
||||
*
|
||||
* A URL to a remote database could also be placed here, along with login credentials and other properties supported by BasicDataSource.
|
||||
*/
|
||||
@Bean(destroyMethod = "close")
|
||||
public DataSource dataSource() {
|
||||
BasicDataSource retVal = new BasicDataSource();
|
||||
retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
|
||||
retVal.setUrl("jdbc:derby:directory:target/jpaserver_derby_files;create=true");
|
||||
retVal.setUsername("");
|
||||
retVal.setPassword("");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Bean()
|
||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
|
||||
LocalContainerEntityManagerFactoryBean retVal = new LocalContainerEntityManagerFactoryBean();
|
||||
retVal.setPersistenceUnitName("HAPI_PU");
|
||||
retVal.setDataSource(dataSource());
|
||||
retVal.setPackagesToScan("ca.uhn.fhir.jpa.entity");
|
||||
retVal.setPersistenceProvider(new HibernatePersistenceProvider());
|
||||
retVal.setJpaProperties(myJpaProperties);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Autowired()
|
||||
@Qualifier("jpaProperties")
|
||||
private Properties myJpaProperties;
|
||||
|
||||
/**
|
||||
* Do some fancy logging to create a nice access log that has details about each incoming request.
|
||||
*/
|
||||
public IServerInterceptor loggingInterceptor() {
|
||||
LoggingInterceptor retVal = new LoggingInterceptor();
|
||||
retVal.setLoggerName("fhirtest.access");
|
||||
retVal.setMessageFormat(
|
||||
"Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${operationName} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}] ResponseEncoding[${responseEncodingNoDefault}]");
|
||||
retVal.setLogExceptions(true);
|
||||
retVal.setErrorMessageFormat("ERROR - ${requestVerb} ${requestUrl}");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* This interceptor adds some pretty syntax highlighting in responses when a browser is detected
|
||||
*/
|
||||
@Bean(autowire = Autowire.BY_TYPE)
|
||||
public IServerInterceptor responseHighlighterInterceptor() {
|
||||
ResponseHighlighterInterceptor retVal = new ResponseHighlighterInterceptor();
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Bean(autowire = Autowire.BY_TYPE)
|
||||
public IServerInterceptor subscriptionSecurityInterceptor() {
|
||||
SubscriptionsRequireManualActivationInterceptorR4 retVal = new SubscriptionsRequireManualActivationInterceptorR4();
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Bean()
|
||||
public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
|
||||
JpaTransactionManager retVal = new JpaTransactionManager();
|
||||
retVal.setEntityManagerFactory(entityManagerFactory);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,6 +15,7 @@ import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
|
|||
import ca.uhn.fhir.jpa.provider.JpaConformanceProviderDstu2;
|
||||
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2;
|
||||
import ca.uhn.fhir.jpa.provider.dstu3.*;
|
||||
import ca.uhn.fhir.jpa.provider.r4.*;
|
||||
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
||||
|
@ -47,15 +48,15 @@ public class JpaServerDemo extends RestfulServer {
|
|||
String resourceProviderBeanName;
|
||||
FhirVersionEnum fhirVersion = ContextHolder.getCtx().getVersion().getVersion();
|
||||
switch (fhirVersion) {
|
||||
case DSTU1:
|
||||
resourceProviderBeanName = "myResourceProvidersDstu1";
|
||||
break;
|
||||
case DSTU2:
|
||||
resourceProviderBeanName = "myResourceProvidersDstu2";
|
||||
break;
|
||||
case DSTU3:
|
||||
resourceProviderBeanName = "myResourceProvidersDstu3";
|
||||
break;
|
||||
case R4:
|
||||
resourceProviderBeanName = "myResourceProvidersR4";
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
@ -73,6 +74,9 @@ public class JpaServerDemo extends RestfulServer {
|
|||
} else if (fhirVersion == FhirVersionEnum.DSTU3) {
|
||||
systemProvider.add(myAppCtx.getBean("mySystemProviderDstu3", JpaSystemProviderDstu3.class));
|
||||
systemProvider.add(myAppCtx.getBean(TerminologyUploaderProviderDstu3.class));
|
||||
} else if (fhirVersion == FhirVersionEnum.R4) {
|
||||
systemProvider.add(myAppCtx.getBean("mySystemProviderR4", JpaSystemProviderR4.class));
|
||||
systemProvider.add(myAppCtx.getBean(TerminologyUploaderProviderR4.class));
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
@ -96,6 +100,13 @@ public class JpaServerDemo extends RestfulServer {
|
|||
myAppCtx.getBean(DaoConfig.class));
|
||||
confProvider.setImplementationDescription("Example Server");
|
||||
setServerConformanceProvider(confProvider);
|
||||
} else if (fhirVersion == FhirVersionEnum.R4) {
|
||||
IFhirSystemDao<org.hl7.fhir.r4.model.Bundle, org.hl7.fhir.r4.model.Meta> systemDao = myAppCtx
|
||||
.getBean("mySystemDaoR4", IFhirSystemDao.class);
|
||||
JpaConformanceProviderR4 confProvider = new JpaConformanceProviderR4(this, systemDao,
|
||||
myAppCtx.getBean(DaoConfig.class));
|
||||
confProvider.setImplementationDescription("Example Server");
|
||||
setServerConformanceProvider(confProvider);
|
||||
} else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
|
|
@ -24,144 +24,30 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.hl7.fhir.instance.model.api.IBase;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||
import org.hl7.fhir.instance.model.api.IBaseConformance;
|
||||
import org.hl7.fhir.instance.model.api.IBaseDatatype;
|
||||
import org.hl7.fhir.instance.model.api.IBaseMetaType;
|
||||
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
|
||||
import org.hl7.fhir.instance.model.api.IBaseParameters;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||
import org.hl7.fhir.instance.model.api.*;
|
||||
|
||||
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
|
||||
import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
|
||||
import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.context.IRuntimeDatatypeDefinition;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IQueryParameterType;
|
||||
import ca.uhn.fhir.model.api.Include;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.context.*;
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import ca.uhn.fhir.model.base.resource.BaseConformance;
|
||||
import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
|
||||
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.api.IVersionSpecificBundleFactory;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.PatchTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.PreferReturnEnum;
|
||||
import ca.uhn.fhir.rest.api.SearchStyleEnum;
|
||||
import ca.uhn.fhir.rest.api.SortOrderEnum;
|
||||
import ca.uhn.fhir.rest.api.SortSpec;
|
||||
import ca.uhn.fhir.rest.api.SummaryEnum;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.IHttpClient;
|
||||
import ca.uhn.fhir.rest.client.api.IHttpRequest;
|
||||
import ca.uhn.fhir.rest.api.*;
|
||||
import ca.uhn.fhir.rest.client.api.*;
|
||||
import ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException;
|
||||
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
||||
import ca.uhn.fhir.rest.client.method.DeleteMethodBinding;
|
||||
import ca.uhn.fhir.rest.client.method.HistoryMethodBinding;
|
||||
import ca.uhn.fhir.rest.client.method.HttpDeleteClientInvocation;
|
||||
import ca.uhn.fhir.rest.client.method.HttpGetClientInvocation;
|
||||
import ca.uhn.fhir.rest.client.method.HttpSimpleGetClientInvocation;
|
||||
import ca.uhn.fhir.rest.client.method.IClientResponseHandler;
|
||||
import ca.uhn.fhir.rest.client.method.MethodUtil;
|
||||
import ca.uhn.fhir.rest.client.method.OperationMethodBinding;
|
||||
import ca.uhn.fhir.rest.client.method.ReadMethodBinding;
|
||||
import ca.uhn.fhir.rest.client.method.SearchMethodBinding;
|
||||
import ca.uhn.fhir.rest.client.method.SortParameter;
|
||||
import ca.uhn.fhir.rest.client.method.TransactionMethodBinding;
|
||||
import ca.uhn.fhir.rest.client.method.ValidateMethodBindingDstu1;
|
||||
import ca.uhn.fhir.rest.client.method.ValidateMethodBindingDstu2Plus;
|
||||
import ca.uhn.fhir.rest.gclient.IClientExecutable;
|
||||
import ca.uhn.fhir.rest.gclient.ICreate;
|
||||
import ca.uhn.fhir.rest.gclient.ICreateTyped;
|
||||
import ca.uhn.fhir.rest.gclient.ICreateWithQuery;
|
||||
import ca.uhn.fhir.rest.gclient.ICreateWithQueryTyped;
|
||||
import ca.uhn.fhir.rest.gclient.ICriterion;
|
||||
import ca.uhn.fhir.rest.gclient.ICriterionInternal;
|
||||
import ca.uhn.fhir.rest.gclient.IDelete;
|
||||
import ca.uhn.fhir.rest.gclient.IDeleteTyped;
|
||||
import ca.uhn.fhir.rest.gclient.IDeleteWithQuery;
|
||||
import ca.uhn.fhir.rest.gclient.IDeleteWithQueryTyped;
|
||||
import ca.uhn.fhir.rest.gclient.IFetchConformanceTyped;
|
||||
import ca.uhn.fhir.rest.gclient.IFetchConformanceUntyped;
|
||||
import ca.uhn.fhir.rest.gclient.IGetPage;
|
||||
import ca.uhn.fhir.rest.gclient.IGetPageTyped;
|
||||
import ca.uhn.fhir.rest.gclient.IGetPageUntyped;
|
||||
import ca.uhn.fhir.rest.gclient.IGetTags;
|
||||
import ca.uhn.fhir.rest.gclient.IHistory;
|
||||
import ca.uhn.fhir.rest.gclient.IHistoryTyped;
|
||||
import ca.uhn.fhir.rest.gclient.IHistoryUntyped;
|
||||
import ca.uhn.fhir.rest.gclient.IMeta;
|
||||
import ca.uhn.fhir.rest.gclient.IMetaAddOrDeleteSourced;
|
||||
import ca.uhn.fhir.rest.gclient.IMetaAddOrDeleteUnsourced;
|
||||
import ca.uhn.fhir.rest.gclient.IMetaGetUnsourced;
|
||||
import ca.uhn.fhir.rest.gclient.IOperation;
|
||||
import ca.uhn.fhir.rest.gclient.IOperationProcessMsg;
|
||||
import ca.uhn.fhir.rest.gclient.IOperationProcessMsgMode;
|
||||
import ca.uhn.fhir.rest.gclient.IOperationUnnamed;
|
||||
import ca.uhn.fhir.rest.gclient.IOperationUntyped;
|
||||
import ca.uhn.fhir.rest.gclient.IOperationUntypedWithInput;
|
||||
import ca.uhn.fhir.rest.gclient.IOperationUntypedWithInputAndPartialOutput;
|
||||
import ca.uhn.fhir.rest.gclient.IParam;
|
||||
import ca.uhn.fhir.rest.gclient.IPatch;
|
||||
import ca.uhn.fhir.rest.gclient.IPatchExecutable;
|
||||
import ca.uhn.fhir.rest.gclient.IPatchWithBody;
|
||||
import ca.uhn.fhir.rest.gclient.IPatchWithQuery;
|
||||
import ca.uhn.fhir.rest.gclient.IPatchWithQueryTyped;
|
||||
import ca.uhn.fhir.rest.gclient.IQuery;
|
||||
import ca.uhn.fhir.rest.gclient.IRead;
|
||||
import ca.uhn.fhir.rest.gclient.IReadExecutable;
|
||||
import ca.uhn.fhir.rest.gclient.IReadIfNoneMatch;
|
||||
import ca.uhn.fhir.rest.gclient.IReadTyped;
|
||||
import ca.uhn.fhir.rest.gclient.ISort;
|
||||
import ca.uhn.fhir.rest.gclient.ITransaction;
|
||||
import ca.uhn.fhir.rest.gclient.ITransactionTyped;
|
||||
import ca.uhn.fhir.rest.gclient.IUntypedQuery;
|
||||
import ca.uhn.fhir.rest.gclient.IUpdate;
|
||||
import ca.uhn.fhir.rest.gclient.IUpdateExecutable;
|
||||
import ca.uhn.fhir.rest.gclient.IUpdateTyped;
|
||||
import ca.uhn.fhir.rest.gclient.IUpdateWithQuery;
|
||||
import ca.uhn.fhir.rest.gclient.IUpdateWithQueryTyped;
|
||||
import ca.uhn.fhir.rest.gclient.IValidate;
|
||||
import ca.uhn.fhir.rest.gclient.IValidateUntyped;
|
||||
import ca.uhn.fhir.rest.param.DateParam;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.NotModifiedException;
|
||||
import ca.uhn.fhir.util.ICallable;
|
||||
import ca.uhn.fhir.util.ParametersUtil;
|
||||
import ca.uhn.fhir.util.UrlUtil;
|
||||
import ca.uhn.fhir.rest.client.method.*;
|
||||
import ca.uhn.fhir.rest.gclient.*;
|
||||
import ca.uhn.fhir.rest.param.*;
|
||||
import ca.uhn.fhir.rest.server.exceptions.*;
|
||||
import ca.uhn.fhir.util.*;
|
||||
|
||||
/**
|
||||
* @author James Agnew
|
||||
|
@ -341,27 +227,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
return new HistoryInternal();
|
||||
}
|
||||
|
||||
@Deprecated // override deprecated method
|
||||
@Override
|
||||
public <T extends IBaseResource> Bundle history(final Class<T> theType, IdDt theIdDt, DateTimeDt theSince, Integer theLimit) {
|
||||
String resourceName = theType != null ? toResourceName(theType) : null;
|
||||
String id = theIdDt != null && theIdDt.isEmpty() == false ? theIdDt.getValue() : null;
|
||||
HttpGetClientInvocation invocation = HistoryMethodBinding.createHistoryInvocation(myContext, resourceName, id, theSince, theLimit);
|
||||
if (isKeepResponses()) {
|
||||
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding(), isPrettyPrint());
|
||||
}
|
||||
|
||||
BundleResponseHandler binding = new BundleResponseHandler(theType);
|
||||
Bundle resp = invokeClient(myContext, binding, invocation, myLogRequestAndResponse);
|
||||
return resp;
|
||||
|
||||
}
|
||||
|
||||
@Deprecated // override deprecated method
|
||||
@Override
|
||||
public <T extends IBaseResource> Bundle history(Class<T> theType, String theId, DateTimeDt theSince, Integer theLimit) {
|
||||
return history(theType, new IdDt(theId), theSince, theLimit);
|
||||
}
|
||||
|
||||
private Class<? extends IBaseResource> inferResourceClass(UriDt theUrl) {
|
||||
String urlString = theUrl.getValueAsString();
|
||||
|
@ -416,17 +281,11 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
|
||||
@Override
|
||||
public IMeta meta() {
|
||||
if (myContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
|
||||
throw new IllegalStateException("Can not call $meta operations on a DSTU1 client");
|
||||
}
|
||||
return new MetaInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOperation operation() {
|
||||
if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1) == false) {
|
||||
throw new IllegalStateException("Operations are only supported in FHIR DSTU2 and later. This client was created using a context configured for " + myContext.getVersion().getVersion().name());
|
||||
}
|
||||
return new OperationInternal();
|
||||
}
|
||||
|
||||
|
@ -570,11 +429,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
@Override
|
||||
public MethodOutcome validate(IBaseResource theResource) {
|
||||
BaseHttpClientInvocation invocation;
|
||||
if (myContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
|
||||
invocation = ValidateMethodBindingDstu1.createValidateInvocation(theResource, null, myContext);
|
||||
} else {
|
||||
invocation = ValidateMethodBindingDstu2Plus.createValidateInvocation(myContext, theResource);
|
||||
}
|
||||
invocation = ValidateMethodBindingDstu2Plus.createValidateInvocation(myContext, theResource);
|
||||
|
||||
if (isKeepResponses()) {
|
||||
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding(), isPrettyPrint());
|
||||
|
@ -774,24 +629,6 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
|
||||
}
|
||||
|
||||
private final class BundleResponseHandler implements IClientResponseHandler<Bundle> {
|
||||
|
||||
private Class<? extends IBaseResource> myType;
|
||||
|
||||
public BundleResponseHandler(Class<? extends IBaseResource> theType) {
|
||||
myType = theType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException {
|
||||
EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType);
|
||||
if (respType == null) {
|
||||
throw NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseReader);
|
||||
}
|
||||
IParser parser = respType.newParser(myContext);
|
||||
return parser.parseBundle(myType, theResponseReader);
|
||||
}
|
||||
}
|
||||
|
||||
private class CreateInternal extends BaseClientExecutable<ICreateTyped, MethodOutcome> implements ICreate, ICreateTyped, ICreateWithQuery, ICreateWithQueryTyped {
|
||||
|
||||
|
@ -1417,7 +1254,9 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
}
|
||||
|
||||
private enum MetaOperation {
|
||||
ADD, DELETE, GET
|
||||
ADD,
|
||||
DELETE,
|
||||
GET
|
||||
}
|
||||
|
||||
private final class MetaParametersResponseHandler<T extends IBaseMetaType> implements IClientResponseHandler<T> {
|
||||
|
@ -1928,20 +1767,17 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
@Override
|
||||
public List<IBaseResource> invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders)
|
||||
throws BaseServerResponseException {
|
||||
if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
Class<? extends IBaseResource> bundleType = myContext.getResourceDefinition("Bundle").getImplementingClass();
|
||||
ResourceResponseHandler<IBaseResource> handler = new ResourceResponseHandler<IBaseResource>((Class<IBaseResource>) bundleType);
|
||||
IBaseResource response = handler.invokeClient(theResponseMimeType, theResponseReader, theResponseStatusCode, theHeaders);
|
||||
IVersionSpecificBundleFactory bundleFactory = myContext.newBundleFactory();
|
||||
bundleFactory.initializeWithBundleResource(response);
|
||||
return bundleFactory.toListOfResources();
|
||||
}
|
||||
return new ArrayList<IBaseResource>(new BundleResponseHandler(myType).invokeClient(theResponseMimeType, theResponseReader, theResponseStatusCode, theHeaders).toListOfResources());
|
||||
Class<? extends IBaseResource> bundleType = myContext.getResourceDefinition("Bundle").getImplementingClass();
|
||||
ResourceResponseHandler<IBaseResource> handler = new ResourceResponseHandler<IBaseResource>((Class<IBaseResource>) bundleType);
|
||||
IBaseResource response = handler.invokeClient(theResponseMimeType, theResponseReader, theResponseStatusCode, theHeaders);
|
||||
IVersionSpecificBundleFactory bundleFactory = myContext.newBundleFactory();
|
||||
bundleFactory.initializeWithBundleResource(response);
|
||||
return bundleFactory.toListOfResources();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private class SearchInternal extends BaseClientExecutable<IQuery<Object>, Object> implements IQuery<Object>, IUntypedQuery {
|
||||
private class SearchInternal extends BaseClientExecutable implements IQuery, IUntypedQuery, IQueryTyped {
|
||||
|
||||
private String myCompartmentName;
|
||||
private CriterionList myCriterion = new CriterionList();
|
||||
|
@ -2010,9 +1846,8 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Deprecated // override deprecated method
|
||||
@Override
|
||||
public IBase execute() {
|
||||
public Object execute() {
|
||||
|
||||
Map<String, List<String>> params = new LinkedHashMap<String, List<String>>();
|
||||
// Map<String, List<String>> initial = createExtraParams();
|
||||
|
@ -2099,11 +1934,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
}
|
||||
|
||||
IClientResponseHandler<? extends IBase> binding;
|
||||
if (myReturnBundleType != null) {
|
||||
binding = new ResourceResponseHandler(myReturnBundleType, getPreferResponseTypes(myResourceType));
|
||||
} else {
|
||||
binding = new BundleResponseHandler(myResourceType);
|
||||
}
|
||||
binding = new ResourceResponseHandler(myReturnBundleType, getPreferResponseTypes(myResourceType));
|
||||
|
||||
IdDt resourceId = myResourceId != null ? new IdDt(myResourceId) : null;
|
||||
|
||||
|
@ -2154,7 +1985,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IQuery returnBundle(Class theClass) {
|
||||
public IQueryTyped returnBundle(Class theClass) {
|
||||
if (theClass == null) {
|
||||
throw new NullPointerException("theClass must not be null");
|
||||
}
|
||||
|
@ -2206,28 +2037,28 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public IQuery<Object> withProfile(String theProfileUri) {
|
||||
public IQuery withProfile(String theProfileUri) {
|
||||
Validate.notBlank(theProfileUri, "theProfileUri must not be null or empty");
|
||||
myProfiles.add(Collections.singletonList(theProfileUri));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuery<Object> withAnyProfile(Collection<String> theProfileUris) {
|
||||
public IQuery withAnyProfile(Collection<String> theProfileUris) {
|
||||
Validate.notEmpty(theProfileUris, "theProfileUris must not be null or empty");
|
||||
myProfiles.add(theProfileUris);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuery<Object> withSecurity(String theSystem, String theCode) {
|
||||
public IQuery withSecurity(String theSystem, String theCode) {
|
||||
Validate.notBlank(theCode, "theCode must not be null or empty");
|
||||
mySecurity.add(new TokenParam(theSystem, theCode));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQuery<Object> withTag(String theSystem, String theCode) {
|
||||
public IQuery withTag(String theSystem, String theCode) {
|
||||
Validate.notBlank(theCode, "theCode must not be null or empty");
|
||||
myTags.add(new TokenParam(theSystem, theCode));
|
||||
return this;
|
||||
|
@ -2326,15 +2157,10 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
private final class TransactionExecutable<T> extends BaseClientExecutable<ITransactionTyped<T>, T> implements ITransactionTyped<T> {
|
||||
|
||||
private IBaseBundle myBaseBundle;
|
||||
private Bundle myBundle;
|
||||
private String myRawBundle;
|
||||
private EncodingEnum myRawBundleEncoding;
|
||||
private List<? extends IBaseResource> myResources;
|
||||
|
||||
public TransactionExecutable(Bundle theResources) {
|
||||
myBundle = theResources;
|
||||
}
|
||||
|
||||
public TransactionExecutable(IBaseBundle theBundle) {
|
||||
myBaseBundle = theBundle;
|
||||
}
|
||||
|
|
|
@ -329,10 +329,7 @@ public abstract class RestfulClientFactory implements IRestfulClientFactory {
|
|||
if (StringUtils.isBlank(serverFhirVersionString)) {
|
||||
// we'll be lenient and accept this
|
||||
} else {
|
||||
//FIXME null access on serverFhirVersionString
|
||||
if (serverFhirVersionString.startsWith("0.80") || serverFhirVersionString.startsWith("0.0.8")) {
|
||||
serverFhirVersionEnum = FhirVersionEnum.DSTU1;
|
||||
} else if (serverFhirVersionString.startsWith("0.4")) {
|
||||
if (serverFhirVersionString.startsWith("0.4")) {
|
||||
serverFhirVersionEnum = FhirVersionEnum.DSTU2;
|
||||
} else if (serverFhirVersionString.startsWith("0.5")) {
|
||||
serverFhirVersionEnum = FhirVersionEnum.DSTU2;
|
||||
|
|
|
@ -51,7 +51,6 @@ import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation;
|
|||
*/
|
||||
abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvocation {
|
||||
|
||||
private final Bundle myBundle;
|
||||
private final BundleTypeEnum myBundleType;
|
||||
private final String myContents;
|
||||
private boolean myContentsIsBundle;
|
||||
|
@ -65,16 +64,6 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
private final String myUrlPath;
|
||||
private IIdType myForceResourceId;
|
||||
|
||||
public BaseHttpClientInvocationWithContents(FhirContext theContext, Bundle theBundle) {
|
||||
super(theContext);
|
||||
myResource = null;
|
||||
myTagList = null;
|
||||
myUrlPath = null;
|
||||
myResources = null;
|
||||
myBundle = theBundle;
|
||||
myContents = null;
|
||||
myBundleType = null;
|
||||
}
|
||||
|
||||
|
||||
public BaseHttpClientInvocationWithContents(FhirContext theContext, IBaseResource theResource, Map<String, List<String>> theParams, String... theUrlPath) {
|
||||
|
@ -83,7 +72,6 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
myTagList = null;
|
||||
myUrlPath = StringUtils.join(theUrlPath, '/');
|
||||
myResources = null;
|
||||
myBundle = null;
|
||||
myContents = null;
|
||||
myContentsIsBundle = false;
|
||||
myParams = theParams;
|
||||
|
@ -96,7 +84,6 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
myUrlPath = theUrlPath;
|
||||
myTagList = null;
|
||||
myResources = null;
|
||||
myBundle = null;
|
||||
myContents = null;
|
||||
myBundleType = null;
|
||||
}
|
||||
|
@ -107,7 +94,6 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
myTagList = null;
|
||||
myUrlPath = null;
|
||||
myResources = theResources;
|
||||
myBundle = null;
|
||||
myContents = null;
|
||||
myBundleType = theBundleType;
|
||||
}
|
||||
|
@ -118,7 +104,6 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
myTagList = null;
|
||||
myUrlPath = StringUtils.join(theUrlPath, '/');
|
||||
myResources = null;
|
||||
myBundle = null;
|
||||
myContents = null;
|
||||
myContentsIsBundle = false;
|
||||
myParams = theParams;
|
||||
|
@ -131,7 +116,6 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
myTagList = null;
|
||||
myUrlPath = theUrlPath;
|
||||
myResources = null;
|
||||
myBundle = null;
|
||||
myContents = theContents;
|
||||
myContentsIsBundle = theIsBundle;
|
||||
myBundleType = null;
|
||||
|
@ -143,7 +127,6 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
myTagList = null;
|
||||
myUrlPath = StringUtils.join(theUrlPath, '/');
|
||||
myResources = null;
|
||||
myBundle = null;
|
||||
myContents = theContents;
|
||||
myContentsIsBundle = false;
|
||||
myParams = theParams;
|
||||
|
@ -208,9 +191,7 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
}
|
||||
|
||||
private String getContentType(EncodingEnum encoding) {
|
||||
if (myBundle != null || (getContext().getVersion().getVersion() == FhirVersionEnum.DSTU1 && ((myContents != null && myContentsIsBundle) || myResources != null))) {
|
||||
return encoding.getBundleContentType();
|
||||
} else if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) {
|
||||
if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) {
|
||||
// application/xml+fhir
|
||||
return encoding.getResourceContentType();
|
||||
} else {
|
||||
|
@ -242,16 +223,12 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
}
|
||||
|
||||
parser.setOmitResourceId(myOmitResourceId);
|
||||
if (myTagList != null) {
|
||||
return parser.encodeTagListToString(myTagList);
|
||||
} else if (myBundle != null) {
|
||||
return parser.encodeBundleToString(myBundle);
|
||||
} else if (myResources != null) {
|
||||
if (myResources != null) {
|
||||
IVersionSpecificBundleFactory bundleFactory = getContext().newBundleFactory();
|
||||
bundleFactory.initializeBundleFromResourceList("", myResources, "", "", myResources.size(), myBundleType);
|
||||
Bundle bundle = bundleFactory.getDstu1Bundle();
|
||||
IBaseResource bundle = bundleFactory.getResourceBundle();
|
||||
if (bundle != null) {
|
||||
return parser.encodeBundleToString(bundle);
|
||||
return parser.encodeResourceToString(bundle);
|
||||
}
|
||||
IBaseResource bundleRes = bundleFactory.getResourceBundle();
|
||||
return parser.encodeResourceToString(bundleRes);
|
||||
|
|
|
@ -197,8 +197,6 @@ public abstract class BaseMethodBinding<T> implements IClientResponseHandler<T>
|
|||
}
|
||||
} else if (MethodOutcome.class.isAssignableFrom(returnTypeFromMethod)) {
|
||||
// returns a method outcome
|
||||
} else if (Bundle.class.equals(returnTypeFromMethod)) {
|
||||
// returns a bundle
|
||||
} else if (void.class.equals(returnTypeFromMethod)) {
|
||||
// returns a bundle
|
||||
} else if (Collection.class.isAssignableFrom(returnTypeFromMethod)) {
|
||||
|
@ -213,7 +211,7 @@ public abstract class BaseMethodBinding<T> implements IClientResponseHandler<T>
|
|||
} else {
|
||||
if (!isResourceInterface(returnTypeFromMethod) && !verifyIsValidResourceReturnType(returnTypeFromMethod)) {
|
||||
throw new ConfigurationException("Method '" + theMethod.getName() + "' from client type " + theMethod.getDeclaringClass().getCanonicalName()
|
||||
+ " returns " + toLogString(returnTypeFromMethod) + " - Must return a resource type (eg Patient, " + Bundle.class.getSimpleName()
|
||||
+ " returns " + toLogString(returnTypeFromMethod) + " - Must return a resource type (eg Patient, Bundle"
|
||||
+ ", etc., see the documentation for more details)");
|
||||
}
|
||||
}
|
||||
|
@ -277,9 +275,6 @@ public abstract class BaseMethodBinding<T> implements IClientResponseHandler<T>
|
|||
} else if (history != null) {
|
||||
return new HistoryMethodBinding(theMethod, theContext, theProvider);
|
||||
} else if (validate != null) {
|
||||
if (theContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
return new ValidateMethodBindingDstu1(theMethod, theContext, theProvider);
|
||||
}
|
||||
return new ValidateMethodBindingDstu2Plus(returnType, returnTypeFromRp, theMethod, theContext, theProvider, validate);
|
||||
} else if (getTags != null) {
|
||||
return new GetTagsMethodBinding(theMethod, theContext, theProvider, getTags);
|
||||
|
|
|
@ -76,8 +76,6 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
|
|||
} else {
|
||||
myMethodReturnType = MethodReturnTypeEnum.RESOURCE;
|
||||
}
|
||||
} else if (Bundle.class.isAssignableFrom(methodReturnType)) {
|
||||
myMethodReturnType = MethodReturnTypeEnum.BUNDLE;
|
||||
} else if (MethodOutcome.class.isAssignableFrom(methodReturnType)) {
|
||||
myMethodReturnType = MethodReturnTypeEnum.METHOD_OUTCOME;
|
||||
} else {
|
||||
|
@ -95,7 +93,7 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
myPreferTypesList = createPreferTypesList();
|
||||
}
|
||||
|
||||
|
@ -122,25 +120,13 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
|
|||
switch (getReturnType()) {
|
||||
case BUNDLE: {
|
||||
|
||||
Bundle dstu1bundle = null;
|
||||
IBaseBundle dstu2bundle = null;
|
||||
List<? extends IBaseResource> listOfResources = null;
|
||||
if (getMethodReturnType() == MethodReturnTypeEnum.BUNDLE || getContext().getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
if (myResourceType != null) {
|
||||
dstu1bundle = parser.parseBundle(myResourceType, theResponseReader);
|
||||
} else {
|
||||
dstu1bundle = parser.parseBundle(theResponseReader);
|
||||
}
|
||||
listOfResources = dstu1bundle.toListOfResources();
|
||||
} else {
|
||||
Class<? extends IBaseResource> type = getContext().getResourceDefinition("Bundle").getImplementingClass();
|
||||
dstu2bundle = (IBaseBundle) parser.parseResource(type, theResponseReader);
|
||||
listOfResources = BundleUtil.toListOfResources(getContext(), dstu2bundle);
|
||||
}
|
||||
Class<? extends IBaseResource> type = getContext().getResourceDefinition("Bundle").getImplementingClass();
|
||||
dstu2bundle = (IBaseBundle) parser.parseResource(type, theResponseReader);
|
||||
listOfResources = BundleUtil.toListOfResources(getContext(), dstu2bundle);
|
||||
|
||||
switch (getMethodReturnType()) {
|
||||
case BUNDLE:
|
||||
return dstu1bundle;
|
||||
case BUNDLE_RESOURCE:
|
||||
return dstu2bundle;
|
||||
case LIST_OF_RESOURCES:
|
||||
|
@ -155,7 +141,7 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
|
|||
}
|
||||
return listOfResources;
|
||||
case RESOURCE:
|
||||
//FIXME null access on dstu1bundle
|
||||
// FIXME null access on dstu1bundle
|
||||
List<IResource> list = dstu1bundle.toListOfResources();
|
||||
if (list.size() == 0) {
|
||||
return null;
|
||||
|
@ -180,8 +166,6 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
|
|||
MethodUtil.parseClientRequestResourceHeaders(null, theHeaders, resource);
|
||||
|
||||
switch (getMethodReturnType()) {
|
||||
case BUNDLE:
|
||||
return Bundle.withSingleResource((IResource) resource);
|
||||
case LIST_OF_RESOURCES:
|
||||
return Collections.singletonList(resource);
|
||||
case RESOURCE:
|
||||
|
@ -206,9 +190,9 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
|
|||
if (myResourceListCollectionType != null && IBaseResource.class.isAssignableFrom(myResourceListCollectionType)) {
|
||||
preferTypes = new ArrayList<Class<? extends IBaseResource>>(1);
|
||||
preferTypes.add((Class<? extends IBaseResource>) myResourceListCollectionType);
|
||||
// } else if (myResourceType != null) {
|
||||
// preferTypes = new ArrayList<Class<? extends IBaseResource>>(1);
|
||||
// preferTypes.add((Class<? extends IBaseResource>) myResourceListCollectionType);
|
||||
// } else if (myResourceType != null) {
|
||||
// preferTypes = new ArrayList<Class<? extends IBaseResource>>(1);
|
||||
// preferTypes.add((Class<? extends IBaseResource>) myResourceListCollectionType);
|
||||
}
|
||||
return preferTypes;
|
||||
}
|
||||
|
@ -225,26 +209,18 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
|
|||
}
|
||||
|
||||
public enum MethodReturnTypeEnum {
|
||||
BUNDLE, BUNDLE_RESOURCE, LIST_OF_RESOURCES, METHOD_OUTCOME, RESOURCE
|
||||
BUNDLE_RESOURCE,
|
||||
LIST_OF_RESOURCES,
|
||||
METHOD_OUTCOME,
|
||||
RESOURCE
|
||||
}
|
||||
|
||||
public static class ResourceOrDstu1Bundle {
|
||||
|
||||
private final Bundle myDstu1Bundle;
|
||||
private final IBaseResource myResource;
|
||||
|
||||
public ResourceOrDstu1Bundle(Bundle theBundle) {
|
||||
myDstu1Bundle = theBundle;
|
||||
myResource = null;
|
||||
}
|
||||
|
||||
public ResourceOrDstu1Bundle(IBaseResource theResource) {
|
||||
myResource = theResource;
|
||||
myDstu1Bundle = null;
|
||||
}
|
||||
|
||||
public Bundle getDstu1Bundle() {
|
||||
return myDstu1Bundle;
|
||||
}
|
||||
|
||||
public IBaseResource getResource() {
|
||||
|
|
|
@ -20,7 +20,6 @@ import ca.uhn.fhir.parser.IParser;
|
|||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.api.*;
|
||||
import ca.uhn.fhir.rest.client.api.IHttpRequest;
|
||||
import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation;
|
||||
import ca.uhn.fhir.rest.client.method.OperationParameter.IOperationParamConverter;
|
||||
import ca.uhn.fhir.rest.param.ParameterUtil;
|
||||
import ca.uhn.fhir.rest.param.binder.CollectionBinder;
|
||||
|
@ -65,19 +64,6 @@ public class MethodUtil {
|
|||
// nothing
|
||||
}
|
||||
|
||||
static void addTagsToPostOrPut(FhirContext theContext, IBaseResource resource, BaseHttpClientInvocation retVal) {
|
||||
if (theContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
|
||||
TagList list = (TagList) ((IResource) resource).getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST);
|
||||
if (list != null) {
|
||||
for (Tag tag : list) {
|
||||
if (StringUtils.isNotBlank(tag.getTerm())) {
|
||||
retVal.addHeader(Constants.HEADER_CATEGORY, tag.toHeaderValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpGetClientInvocation createConformanceInvocation(FhirContext theContext) {
|
||||
return new HttpGetClientInvocation(theContext, "metadata");
|
||||
}
|
||||
|
@ -94,29 +80,14 @@ public class MethodUtil {
|
|||
StringBuilder urlExtension = new StringBuilder();
|
||||
urlExtension.append(resourceName);
|
||||
|
||||
boolean dstu1 = theContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1);
|
||||
if (dstu1) {
|
||||
/*
|
||||
* This was allowable at one point, but as of DSTU2 it isn't.
|
||||
*/
|
||||
if (StringUtils.isNotBlank(theId)) {
|
||||
urlExtension.append('/');
|
||||
urlExtension.append(theId);
|
||||
}
|
||||
}
|
||||
|
||||
HttpPostClientInvocation retVal;
|
||||
if (StringUtils.isBlank(theResourceBody)) {
|
||||
retVal = new HttpPostClientInvocation(theContext, theResource, urlExtension.toString());
|
||||
} else {
|
||||
retVal = new HttpPostClientInvocation(theContext, theResourceBody, false, urlExtension.toString());
|
||||
}
|
||||
addTagsToPostOrPut(theContext, theResource, retVal);
|
||||
|
||||
if (!dstu1) {
|
||||
retVal.setOmitResourceId(true);
|
||||
}
|
||||
// addContentTypeHeaderBasedOnDetectedType(retVal, theResourceBody);
|
||||
retVal.setOmitResourceId(true);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
@ -164,8 +135,6 @@ public class MethodUtil {
|
|||
retVal = new HttpPutClientInvocation(theContext, theResourceBody, false, b.toString());
|
||||
}
|
||||
|
||||
addTagsToPostOrPut(theContext, theResource, retVal);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
@ -196,8 +165,6 @@ public class MethodUtil {
|
|||
retVal = new HttpPutClientInvocation(theContext, theResourceBody, false, theMatchUrl);
|
||||
}
|
||||
|
||||
addTagsToPostOrPut(theContext, theResource, retVal);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
@ -220,23 +187,9 @@ public class MethodUtil {
|
|||
retVal.setForceResourceId(theId);
|
||||
|
||||
if (theId.hasVersionIdPart()) {
|
||||
if (theContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1)) {
|
||||
retVal.addHeader(Constants.HEADER_IF_MATCH, '"' + theId.getVersionIdPart() + '"');
|
||||
} else {
|
||||
String versionId = theId.getVersionIdPart();
|
||||
if (StringUtils.isNotBlank(versionId)) {
|
||||
urlBuilder.append('/');
|
||||
urlBuilder.append(Constants.PARAM_HISTORY);
|
||||
urlBuilder.append('/');
|
||||
urlBuilder.append(versionId);
|
||||
retVal.addHeader(Constants.HEADER_CONTENT_LOCATION, urlBuilder.toString());
|
||||
}
|
||||
}
|
||||
retVal.addHeader(Constants.HEADER_IF_MATCH, '"' + theId.getVersionIdPart() + '"');
|
||||
}
|
||||
|
||||
addTagsToPostOrPut(theContext, theResource, retVal);
|
||||
// addContentTypeHeaderBasedOnDetectedType(retVal, theResourceBody);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,11 +93,6 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
|
|||
}
|
||||
myName = theOperationName;
|
||||
|
||||
if (theContext.getVersion().getVersion().isEquivalentTo(FhirVersionEnum.DSTU1)) {
|
||||
throw new ConfigurationException("@" + Operation.class.getSimpleName() + " methods are not supported on servers for FHIR version " + theContext.getVersion().getVersion().name()
|
||||
+ " - Found one on class " + theMethod.getDeclaringClass().getName());
|
||||
}
|
||||
|
||||
if (theReturnTypeFromRp != null) {
|
||||
setResourceName(theContext.getResourceDefinition(theReturnTypeFromRp).getName());
|
||||
} else {
|
||||
|
|
|
@ -137,8 +137,6 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem
|
|||
resource.setContent(contents);
|
||||
|
||||
switch (getMethodReturnType()) {
|
||||
case BUNDLE:
|
||||
return Bundle.withSingleResource((IResource) resource);
|
||||
case LIST_OF_RESOURCES:
|
||||
return Collections.singletonList(resource);
|
||||
case RESOURCE:
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
package ca.uhn.fhir.rest.client.method;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2017 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.annotation.Validate;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||
import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation;
|
||||
import ca.uhn.fhir.rest.param.ParameterUtil;
|
||||
|
||||
public class ValidateMethodBindingDstu1 extends BaseOutcomeReturningMethodBindingWithResourceParam {
|
||||
|
||||
private Integer myIdParameterIndex;
|
||||
|
||||
public ValidateMethodBindingDstu1(Method theMethod, FhirContext theContext, Object theProvider) {
|
||||
super(theMethod, theContext, Validate.class, theProvider);
|
||||
|
||||
myIdParameterIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestOperationTypeEnum getRestOperationType() {
|
||||
return RestOperationTypeEnum.VALIDATE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) {
|
||||
FhirContext context = getContext();
|
||||
|
||||
IdDt idDt=null;
|
||||
if (myIdParameterIndex != null) {
|
||||
idDt = (IdDt) theArgs[myIdParameterIndex];
|
||||
}
|
||||
|
||||
HttpPostClientInvocation retVal = createValidateInvocation(theResource, idDt, context);
|
||||
|
||||
for (int idx = 0; idx < theArgs.length; idx++) {
|
||||
IParameter nextParam = getParameters().get(idx);
|
||||
nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], null, null);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static HttpPostClientInvocation createValidateInvocation(IBaseResource theResource, IdDt theId, FhirContext theContext) {
|
||||
StringBuilder urlExtension = new StringBuilder();
|
||||
urlExtension.append(theContext.getResourceDefinition(theResource).getName());
|
||||
urlExtension.append('/');
|
||||
urlExtension.append(Constants.PARAM_VALIDATE);
|
||||
|
||||
if (theId != null && theId.isEmpty() == false) {
|
||||
String id = theId.getValue();
|
||||
urlExtension.append('/');
|
||||
urlExtension.append(id);
|
||||
}
|
||||
// TODO: is post correct here?
|
||||
HttpPostClientInvocation retVal = new HttpPostClientInvocation(theContext, theResource, urlExtension.toString());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean allowVoidReturnType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<RequestTypeEnum> provideAllowableRequestTypes() {
|
||||
// TODO: is post correct here?
|
||||
return Collections.singleton(RequestTypeEnum.POST);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getMatchingOperation() {
|
||||
return Constants.PARAM_VALIDATE;
|
||||
}
|
||||
|
||||
}
|
|
@ -24,13 +24,11 @@ import ca.uhn.fhir.jaxrs.client.JaxRsRestfulClientFactory;
|
|||
import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsExceptionInterceptor;
|
||||
import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsResponseException;
|
||||
import ca.uhn.fhir.jaxrs.server.test.*;
|
||||
import ca.uhn.fhir.model.api.BundleEntry;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
|
||||
import ca.uhn.fhir.model.dstu2.resource.*;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum;
|
||||
import ca.uhn.fhir.rest.api.*;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
|
@ -44,7 +42,6 @@ import ca.uhn.fhir.util.TestUtil;
|
|||
public class AbstractJaxRsResourceProviderTest {
|
||||
|
||||
private static IGenericClient client;
|
||||
|
||||
|
||||
private static FhirContext ourCtx = FhirContext.forDstu2();
|
||||
private static final String PATIENT_NAME = "Van Houte";
|
||||
|
@ -54,7 +51,7 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
private static Server jettyServer;
|
||||
private TestJaxRsMockPatientRestProvider mock;
|
||||
private ArgumentCaptor<IdDt> idCaptor;
|
||||
private ArgumentCaptor<String> conditionalCaptor;
|
||||
private ArgumentCaptor<String> conditionalCaptor;
|
||||
private ArgumentCaptor<Patient> patientCaptor;
|
||||
|
||||
private void compareResultId(int id, IResource resource) {
|
||||
|
@ -98,16 +95,6 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
compareResultUrl("/Patient/1", result);
|
||||
}
|
||||
|
||||
private Bundle getPatientBundle(int size) {
|
||||
Bundle result = new Bundle();
|
||||
for (long i = 0; i < size; i++) {
|
||||
Patient patient = createPatient(i);
|
||||
Entry entry = new Entry().setResource(patient);
|
||||
result.addEntry(entry);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.mock = TestJaxRsMockPatientRestProvider.mock;
|
||||
|
@ -166,13 +153,13 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
assertEquals("1", idCaptor.getValue().getIdPart());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConditionalDelete() throws Exception {
|
||||
when(mock.delete(idCaptor.capture(), conditionalCaptor.capture())).thenReturn(new MethodOutcome());
|
||||
client.delete().resourceConditionalByType("Patient").where(Patient.IDENTIFIER.exactly().identifier("2")).execute();
|
||||
assertEquals("Patient?identifier=2&_format=json", conditionalCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConditionalDelete() throws Exception {
|
||||
when(mock.delete(idCaptor.capture(), conditionalCaptor.capture())).thenReturn(new MethodOutcome());
|
||||
client.delete().resourceConditionalByType("Patient").where(Patient.IDENTIFIER.exactly().identifier("2")).execute();
|
||||
assertEquals("Patient?identifier=2&_format=json", conditionalCaptor.getValue());
|
||||
}
|
||||
|
||||
/** Extended Operations */
|
||||
@Test
|
||||
public void testExtendedOperations() {
|
||||
|
@ -185,11 +172,11 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
inParams.addParameter().setName("start").setValue(new DateDt("2001-01-01"));
|
||||
inParams.addParameter().setName("end").setValue(new DateDt("2015-03-01"));
|
||||
inParams.addParameter().setName("dummy").setValue(new StringDt("myAwesomeDummyValue"));
|
||||
//invoke
|
||||
// invoke
|
||||
Parameters outParams = client.operation().onInstance(new IdDt("Patient", "1")).named("$someCustomOperation")
|
||||
.withParameters(inParams).execute();
|
||||
//verify
|
||||
assertEquals("outputValue", ((StringDt)outParams.getParameter().get(0).getValue()).getValueAsString());
|
||||
// verify
|
||||
assertEquals("outputValue", ((StringDt) outParams.getParameter().get(0).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -197,7 +184,7 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
// prepare mock
|
||||
Parameters resultParameters = new Parameters();
|
||||
resultParameters.addParameter().setName("return").setResource(createPatient(1)).setValue(new StringDt("outputValue"));
|
||||
when(mock.someCustomOperation(any(IdDt.class), eq(new StringDt("myAwesomeDummyValue")))).thenReturn(resultParameters);
|
||||
when(mock.someCustomOperation(any(IdDt.class), eq(new StringDt("myAwesomeDummyValue")))).thenReturn(resultParameters);
|
||||
// Create the input parameters to pass to the server
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("start").setValue(new DateDt("2001-01-01"));
|
||||
|
@ -208,7 +195,7 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
Parameters outParams = client.operation().onInstance(new IdDt("Patient", "1")).named("$someCustomOperation")
|
||||
.withParameters(inParams).useHttpGet().execute();
|
||||
// verify
|
||||
assertEquals("outputValue", ((StringDt)outParams.getParameter().get(0).getValue()).getValueAsString());
|
||||
assertEquals("outputValue", ((StringDt) outParams.getParameter().get(0).getValue()).getValueAsString());
|
||||
}
|
||||
|
||||
/** Search using other query options */
|
||||
|
@ -254,10 +241,10 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
// Perform a search
|
||||
when(mock.search(any(StringParam.class), Matchers.isNull(StringAndListParam.class)))
|
||||
.thenReturn(Arrays.asList(createPatient(1)));
|
||||
final ca.uhn.fhir.model.api.Bundle results = client.search().forResource(Patient.class)
|
||||
.where(Patient.NAME.matchesExactly().value(PATIENT_NAME)).execute();
|
||||
Bundle results = client.search().forResource(Patient.class)
|
||||
.where(Patient.NAME.matchesExactly().value(PATIENT_NAME)).returnBundle(Bundle.class).execute();
|
||||
verify(mock).search(any(StringParam.class), Matchers.isNull(StringAndListParam.class));
|
||||
IResource resource = results.getEntries().get(0).getResource();
|
||||
IResource resource = results.getEntry().get(0).getResource();
|
||||
|
||||
compareResultId(1, resource);
|
||||
compareResultUrl("/Patient/1", resource);
|
||||
|
@ -268,11 +255,11 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
public void testSearchUsingGenericClientBySearchWithMultiValues() {
|
||||
when(mock.search(any(StringParam.class), Matchers.isNotNull(StringAndListParam.class)))
|
||||
.thenReturn(Arrays.asList(createPatient(1)));
|
||||
final ca.uhn.fhir.model.api.Bundle results = client.search().forResource(Patient.class)
|
||||
Bundle results = client.search().forResource(Patient.class)
|
||||
.where(Patient.ADDRESS.matches().values("Toronto")).and(Patient.ADDRESS.matches().values("Ontario"))
|
||||
.and(Patient.ADDRESS.matches().values("Canada"))
|
||||
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("SHORTNAME", "TOYS")).execute();
|
||||
IResource resource = results.getEntries().get(0).getResource();
|
||||
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("SHORTNAME", "TOYS")).returnBundle(Bundle.class).execute();
|
||||
IResource resource = results.getEntry().get(0).getResource();
|
||||
|
||||
compareResultId(1, resource);
|
||||
compareResultUrl("/Patient/1", resource);
|
||||
|
@ -293,10 +280,10 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
compareResultUrl("/Patient/1", resource);
|
||||
compareResultId(8, results.getEntry().get(7).getResource());
|
||||
|
||||
// ourLog.info("Next: " + results.getLink("next").getUrl());
|
||||
// String url = results.getLink("next").getUrl().replace("?", "Patient?");
|
||||
// results.getLink("next").setUrl(url);
|
||||
// ourLog.info("New Next: " + results.getLink("next").getUrl());
|
||||
// ourLog.info("Next: " + results.getLink("next").getUrl());
|
||||
// String url = results.getLink("next").getUrl().replace("?", "Patient?");
|
||||
// results.getLink("next").setUrl(url);
|
||||
// ourLog.info("New Next: " + results.getLink("next").getUrl());
|
||||
|
||||
// load next page
|
||||
final Bundle nextPage = client.loadPage().next(results).execute();
|
||||
|
@ -314,22 +301,6 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
.returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class).execute();
|
||||
}
|
||||
|
||||
/** Transaction - Server */
|
||||
@Ignore
|
||||
@Test
|
||||
public void testTransaction() {
|
||||
ca.uhn.fhir.model.api.Bundle bundle = new ca.uhn.fhir.model.api.Bundle();
|
||||
BundleEntry entry = bundle.addEntry();
|
||||
final Patient existing = new Patient();
|
||||
existing.getNameFirstRep().addFamily("Created with bundle");
|
||||
entry.setResource(existing);
|
||||
|
||||
BoundCodeDt<BundleEntryTransactionMethodEnum> theTransactionOperation = new BoundCodeDt(
|
||||
BundleEntryTransactionMethodEnum.VALUESET_BINDER, BundleEntryTransactionMethodEnum.POST);
|
||||
entry.setTransactionMethod(theTransactionOperation);
|
||||
ca.uhn.fhir.model.api.Bundle response = client.transaction().withBundle(bundle).execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateById() throws Exception {
|
||||
when(mock.update(idCaptor.capture(), patientCaptor.capture(), conditionalCaptor.capture())).thenReturn(new MethodOutcome());
|
||||
|
@ -338,16 +309,15 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
compareResultId(1, patientCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConditionalUpdate() throws Exception {
|
||||
when(mock.update(idCaptor.capture(), patientCaptor.capture(), conditionalCaptor.capture())).thenReturn(new MethodOutcome());
|
||||
client.update().resource(createPatient(1)).conditional().where(Patient.IDENTIFIER.exactly().identifier("2")).execute();
|
||||
|
||||
@Test
|
||||
public void testConditionalUpdate() throws Exception {
|
||||
when(mock.update(idCaptor.capture(), patientCaptor.capture(), conditionalCaptor.capture())).thenReturn(new MethodOutcome());
|
||||
client.update().resource(createPatient(1)).conditional().where(Patient.IDENTIFIER.exactly().identifier("2")).execute();
|
||||
assertEquals(null, patientCaptor.getValue().getId().getIdPart());
|
||||
assertEquals("Patient?identifier=2&_format=json", conditionalCaptor.getValue());
|
||||
}
|
||||
|
||||
assertEquals(null, patientCaptor.getValue().getId().getIdPart());
|
||||
assertEquals("Patient?identifier=2&_format=json", conditionalCaptor.getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Ignore
|
||||
@Test
|
||||
|
@ -384,21 +354,21 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test
|
||||
public void testValidate() {
|
||||
// prepare mock
|
||||
final OperationOutcome oo = new OperationOutcome();
|
||||
final Patient patient = new Patient();
|
||||
patient.addIdentifier((new IdentifierDt().setValue("1")));
|
||||
//invoke
|
||||
// invoke
|
||||
final Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setResource(patient);
|
||||
|
||||
final MethodOutcome mO = client.validate().resource(patient).execute();
|
||||
//verify
|
||||
// verify
|
||||
assertNotNull(mO.getOperationOutcome());
|
||||
}
|
||||
|
||||
|
||||
private <T> T withId(final T id) {
|
||||
return argThat(new BaseMatcher<T>() {
|
||||
@Override
|
||||
|
@ -441,14 +411,14 @@ public class AbstractJaxRsResourceProviderTest {
|
|||
TestJaxRsMockPageProvider.class.getCanonicalName()
|
||||
), ";"));
|
||||
//@formatter:on
|
||||
|
||||
|
||||
jettyServer.start();
|
||||
|
||||
ourCtx.setRestfulClientFactory(new JaxRsRestfulClientFactory(ourCtx));
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000);
|
||||
serverBase = "http://localhost:" + ourPort + "/";
|
||||
client = ourCtx.newRestfulGenericClient(serverBase);
|
||||
serverBase = "http://localhost:" + ourPort + "/";
|
||||
client = ourCtx.newRestfulGenericClient(serverBase);
|
||||
client.setEncoding(EncodingEnum.JSON);
|
||||
client.registerInterceptor(new LoggingInterceptor(true));
|
||||
}
|
||||
|
|
|
@ -23,29 +23,16 @@ import ca.uhn.fhir.rest.api.SummaryEnum;
|
|||
import ca.uhn.fhir.rest.server.RestfulServerUtils;
|
||||
|
||||
public class JaxRsResponseTest {
|
||||
|
||||
|
||||
private JaxRsResponse response;
|
||||
private JaxRsRequest request;
|
||||
private Bundle bundle;
|
||||
private Set<SummaryEnum> theSummaryMode;
|
||||
|
||||
@Before
|
||||
public void setUp() throws URISyntaxException {
|
||||
request = new JaxRsRequestTest().createRequestDetails();
|
||||
this.response = (JaxRsResponse) request.getResponse();
|
||||
bundle = getSinglePatientResource();
|
||||
theSummaryMode = Collections.<SummaryEnum>emptySet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResponseWriterNoZipNoBrowser() throws IOException {
|
||||
boolean respondGzip = false;
|
||||
Set<SummaryEnum> theSummaryMode = Collections.<SummaryEnum>emptySet();
|
||||
Response result = (Response) RestfulServerUtils.streamResponseAsBundle(request.getServer(), bundle, theSummaryMode, respondGzip, request);
|
||||
assertEquals(200, result.getStatus());
|
||||
assertEquals(Constants.CT_FHIR_JSON+Constants.CHARSET_UTF8_CTSUFFIX, result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
|
||||
assertTrue(result.getEntity().toString().contains("Patient"));
|
||||
assertTrue(result.getEntity().toString().contains("15"));
|
||||
theSummaryMode = Collections.<SummaryEnum> emptySet();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -62,19 +49,19 @@ public class JaxRsResponseTest {
|
|||
assertEquals(contentType, result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
|
||||
assertEquals(content, result.getEntity());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSendAttachmentResponseNoContent() throws IOException {
|
||||
boolean respondGzip = true;
|
||||
IBaseBinary binary = new Binary();
|
||||
binary.setContent(new byte[]{});
|
||||
binary.setContent(new byte[] {});
|
||||
boolean theAddContentLocationHeader = false;
|
||||
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, theAddContentLocationHeader, respondGzip, this.request);
|
||||
assertEquals(200, result.getStatus());
|
||||
assertEquals(null, result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
|
||||
assertEquals(null, result.getEntity());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSendAttachmentResponseEmptyContent() throws IOException {
|
||||
boolean respondGzip = true;
|
||||
|
@ -85,25 +72,24 @@ public class JaxRsResponseTest {
|
|||
assertEquals(null, result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
|
||||
assertEquals(null, result.getEntity());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReturnResponse() throws IOException {
|
||||
boolean addContentLocationHeader = true;
|
||||
boolean respondGzip = true;
|
||||
// Response result = response.returnResponse(outcome, operationStatus, allowPrefer, methodOutcome, resourceName);
|
||||
// Response result = response.returnResponse(outcome, operationStatus, allowPrefer, methodOutcome, resourceName);
|
||||
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
|
||||
assertEquals(200, result.getStatus());
|
||||
assertEquals("application/json+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
|
||||
System.out.println(result.getEntity().toString());
|
||||
assertTrue(result.getEntity().toString().contains("resourceType\": \"Patient"));
|
||||
assertTrue(result.getEntity().toString().contains("15"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReturnResponseAsXml() throws IOException {
|
||||
response.getRequestDetails().getParameters().put(Constants.PARAM_FORMAT, new String[]{Constants.CT_XML});
|
||||
response.getRequestDetails().getParameters().put(Constants.PARAM_FORMAT, new String[] { Constants.CT_XML });
|
||||
boolean addContentLocationHeader = true;
|
||||
boolean respondGzip = true;
|
||||
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
|
||||
|
@ -112,10 +98,10 @@ public class JaxRsResponseTest {
|
|||
assertTrue(result.getEntity().toString().contains("<Patient"));
|
||||
assertTrue(result.getEntity().toString().contains("15"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNoOutcomeXml() throws IOException {
|
||||
response.getRequestDetails().getParameters().put(Constants.PARAM_FORMAT, new String[]{Constants.CT_XML});
|
||||
response.getRequestDetails().getParameters().put(Constants.PARAM_FORMAT, new String[] { Constants.CT_XML });
|
||||
boolean addContentLocationHeader = true;
|
||||
boolean respondGzip = true;
|
||||
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
|
||||
|
@ -123,16 +109,10 @@ public class JaxRsResponseTest {
|
|||
assertEquals("application/xml+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
|
||||
}
|
||||
|
||||
private Bundle getSinglePatientResource() {
|
||||
Patient theResource = createPatient();
|
||||
Bundle bundle = Bundle.withSingleResource(theResource);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
private Patient createPatient() {
|
||||
Patient theResource = new Patient();
|
||||
theResource.setId(new IdDt(15L));
|
||||
return theResource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -562,12 +562,12 @@ public abstract class BaseHapiFhirDao<T extends IBaseResource> implements IDao {
|
|||
}
|
||||
|
||||
public FhirContext getContext(FhirVersionEnum theVersion) {
|
||||
FhirVersionEnum ver = theVersion != null ? theVersion : FhirVersionEnum.DSTU1;
|
||||
Validate.notNull(theVersion, "theVersion must not be null");
|
||||
synchronized (ourRetrievalContexts) {
|
||||
FhirContext retVal = ourRetrievalContexts.get(ver);
|
||||
FhirContext retVal = ourRetrievalContexts.get(theVersion);
|
||||
if (retVal == null) {
|
||||
retVal = new FhirContext(ver);
|
||||
ourRetrievalContexts.put(ver, retVal);
|
||||
retVal = new FhirContext(theVersion);
|
||||
ourRetrievalContexts.put(theVersion, retVal);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
|
|
@ -136,12 +136,7 @@ public abstract class BaseHapiFhirResourceDao<T extends IBaseResource> extends B
|
|||
@Override
|
||||
public DaoMethodOutcome create(T theResource, String theIfNoneExist, boolean thePerformIndexing, RequestDetails theRequestDetails) {
|
||||
if (isNotBlank(theResource.getIdElement().getIdPart())) {
|
||||
if (getContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
|
||||
if (theResource.getIdElement().isIdPartValidLong()) {
|
||||
String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedNumericId", theResource.getIdElement().getIdPart());
|
||||
throw new InvalidRequestException(message, createErrorOperationOutcome(message, "processing"));
|
||||
}
|
||||
} else if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) {
|
||||
if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3)) {
|
||||
String message = getContext().getLocalizer().getMessage(BaseHapiFhirResourceDao.class, "failedToCreateWithClientAssignedId", theResource.getIdElement().getIdPart());
|
||||
throw new InvalidRequestException(message, createErrorOperationOutcome(message, "processing"));
|
||||
} else {
|
||||
|
|
|
@ -67,7 +67,7 @@ import ca.uhn.fhir.util.UrlUtil;
|
|||
* searchs for resources
|
||||
*/
|
||||
public class SearchBuilder implements ISearchBuilder {
|
||||
|
||||
|
||||
private static final List<Long> EMPTY_LONG_LIST = Collections.unmodifiableList(new ArrayList<Long>());
|
||||
private static Long NO_MORE = Long.valueOf(-1);
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchBuilder.class);
|
||||
|
@ -89,7 +89,7 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
private ISearchParamRegistry mySearchParamRegistry;
|
||||
private String mySearchUuid;
|
||||
private IHapiTerminologySvc myTerminologySvc;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
|
@ -840,32 +840,32 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
private Predicate createCompositeParamPart(String theResourceName, Root<ResourceTable> theRoot, RuntimeSearchParam theParam, IQueryParameterType leftValue) {
|
||||
Predicate retVal = null;
|
||||
switch (theParam.getParamType()) {
|
||||
case STRING: {
|
||||
From<ResourceIndexedSearchParamString, ResourceIndexedSearchParamString> stringJoin = theRoot.join("myParamsString", JoinType.INNER);
|
||||
retVal = createPredicateString(leftValue, theResourceName, theParam.getName(), myBuilder, stringJoin);
|
||||
break;
|
||||
}
|
||||
case TOKEN: {
|
||||
From<ResourceIndexedSearchParamToken, ResourceIndexedSearchParamToken> tokenJoin = theRoot.join("myParamsToken", JoinType.INNER);
|
||||
retVal = createPredicateToken(leftValue, theResourceName, theParam.getName(), myBuilder, tokenJoin);
|
||||
break;
|
||||
}
|
||||
case DATE: {
|
||||
From<ResourceIndexedSearchParamDate, ResourceIndexedSearchParamDate> dateJoin = theRoot.join("myParamsDate", JoinType.INNER);
|
||||
retVal = createPredicateDate(leftValue, theResourceName, theParam.getName(), myBuilder, dateJoin);
|
||||
break;
|
||||
}
|
||||
case QUANTITY: {
|
||||
From<ResourceIndexedSearchParamQuantity, ResourceIndexedSearchParamQuantity> dateJoin = theRoot.join("myParamsQuantity", JoinType.INNER);
|
||||
retVal = createPredicateQuantity(leftValue, theResourceName, theParam.getName(), myBuilder, dateJoin);
|
||||
break;
|
||||
}
|
||||
case COMPOSITE:
|
||||
case HAS:
|
||||
case NUMBER:
|
||||
case REFERENCE:
|
||||
case URI:
|
||||
break;
|
||||
case STRING: {
|
||||
From<ResourceIndexedSearchParamString, ResourceIndexedSearchParamString> stringJoin = theRoot.join("myParamsString", JoinType.INNER);
|
||||
retVal = createPredicateString(leftValue, theResourceName, theParam.getName(), myBuilder, stringJoin);
|
||||
break;
|
||||
}
|
||||
case TOKEN: {
|
||||
From<ResourceIndexedSearchParamToken, ResourceIndexedSearchParamToken> tokenJoin = theRoot.join("myParamsToken", JoinType.INNER);
|
||||
retVal = createPredicateToken(leftValue, theResourceName, theParam.getName(), myBuilder, tokenJoin);
|
||||
break;
|
||||
}
|
||||
case DATE: {
|
||||
From<ResourceIndexedSearchParamDate, ResourceIndexedSearchParamDate> dateJoin = theRoot.join("myParamsDate", JoinType.INNER);
|
||||
retVal = createPredicateDate(leftValue, theResourceName, theParam.getName(), myBuilder, dateJoin);
|
||||
break;
|
||||
}
|
||||
case QUANTITY: {
|
||||
From<ResourceIndexedSearchParamQuantity, ResourceIndexedSearchParamQuantity> dateJoin = theRoot.join("myParamsQuantity", JoinType.INNER);
|
||||
retVal = createPredicateQuantity(leftValue, theResourceName, theParam.getName(), myBuilder, dateJoin);
|
||||
break;
|
||||
}
|
||||
case COMPOSITE:
|
||||
case HAS:
|
||||
case NUMBER:
|
||||
case REFERENCE:
|
||||
case URI:
|
||||
break;
|
||||
}
|
||||
|
||||
if (retVal == null) {
|
||||
|
@ -880,27 +880,27 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
Join<ResourceTable, ResourceIndexedSearchParamDate> join = null;
|
||||
|
||||
switch (theType) {
|
||||
case DATE:
|
||||
join = myResourceTableRoot.join("myParamsDate", JoinType.LEFT);
|
||||
break;
|
||||
case NUMBER:
|
||||
join = myResourceTableRoot.join("myParamsNumber", JoinType.LEFT);
|
||||
break;
|
||||
case QUANTITY:
|
||||
join = myResourceTableRoot.join("myParamsQuantity", JoinType.LEFT);
|
||||
break;
|
||||
case REFERENCE:
|
||||
join = myResourceTableRoot.join("myResourceLinks", JoinType.LEFT);
|
||||
break;
|
||||
case STRING:
|
||||
join = myResourceTableRoot.join("myParamsString", JoinType.LEFT);
|
||||
break;
|
||||
case URI:
|
||||
join = myResourceTableRoot.join("myParamsUri", JoinType.LEFT);
|
||||
break;
|
||||
case TOKEN:
|
||||
join = myResourceTableRoot.join("myParamsToken", JoinType.LEFT);
|
||||
break;
|
||||
case DATE:
|
||||
join = myResourceTableRoot.join("myParamsDate", JoinType.LEFT);
|
||||
break;
|
||||
case NUMBER:
|
||||
join = myResourceTableRoot.join("myParamsNumber", JoinType.LEFT);
|
||||
break;
|
||||
case QUANTITY:
|
||||
join = myResourceTableRoot.join("myParamsQuantity", JoinType.LEFT);
|
||||
break;
|
||||
case REFERENCE:
|
||||
join = myResourceTableRoot.join("myResourceLinks", JoinType.LEFT);
|
||||
break;
|
||||
case STRING:
|
||||
join = myResourceTableRoot.join("myParamsString", JoinType.LEFT);
|
||||
break;
|
||||
case URI:
|
||||
join = myResourceTableRoot.join("myParamsUri", JoinType.LEFT);
|
||||
break;
|
||||
case TOKEN:
|
||||
join = myResourceTableRoot.join("myParamsToken", JoinType.LEFT);
|
||||
break;
|
||||
}
|
||||
|
||||
JoinKey key = new JoinKey(theSearchParameterName, theType);
|
||||
|
@ -972,41 +972,41 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
String invalidMessageName) {
|
||||
Predicate num;
|
||||
switch (thePrefix) {
|
||||
case GREATERTHAN:
|
||||
num = builder.gt(thePath, theValue);
|
||||
break;
|
||||
case GREATERTHAN_OR_EQUALS:
|
||||
num = builder.ge(thePath, theValue);
|
||||
break;
|
||||
case LESSTHAN:
|
||||
num = builder.lt(thePath, theValue);
|
||||
break;
|
||||
case LESSTHAN_OR_EQUALS:
|
||||
num = builder.le(thePath, theValue);
|
||||
break;
|
||||
case APPROXIMATE:
|
||||
case EQUAL:
|
||||
case NOT_EQUAL:
|
||||
BigDecimal mul = calculateFuzzAmount(thePrefix, theValue);
|
||||
BigDecimal low = theValue.subtract(mul, MathContext.DECIMAL64);
|
||||
BigDecimal high = theValue.add(mul, MathContext.DECIMAL64);
|
||||
Predicate lowPred;
|
||||
Predicate highPred;
|
||||
if (thePrefix != ParamPrefixEnum.NOT_EQUAL) {
|
||||
lowPred = builder.ge(thePath.as(BigDecimal.class), low);
|
||||
highPred = builder.le(thePath.as(BigDecimal.class), high);
|
||||
num = builder.and(lowPred, highPred);
|
||||
ourLog.trace("Searching for {} <= val <= {}", low, high);
|
||||
} else {
|
||||
// Prefix was "ne", so reverse it!
|
||||
lowPred = builder.lt(thePath.as(BigDecimal.class), low);
|
||||
highPred = builder.gt(thePath.as(BigDecimal.class), high);
|
||||
num = builder.or(lowPred, highPred);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
String msg = myContext.getLocalizer().getMessage(SearchBuilder.class, invalidMessageName, thePrefix.getValue(), theParam.getValueAsQueryToken(myContext));
|
||||
throw new InvalidRequestException(msg);
|
||||
case GREATERTHAN:
|
||||
num = builder.gt(thePath, theValue);
|
||||
break;
|
||||
case GREATERTHAN_OR_EQUALS:
|
||||
num = builder.ge(thePath, theValue);
|
||||
break;
|
||||
case LESSTHAN:
|
||||
num = builder.lt(thePath, theValue);
|
||||
break;
|
||||
case LESSTHAN_OR_EQUALS:
|
||||
num = builder.le(thePath, theValue);
|
||||
break;
|
||||
case APPROXIMATE:
|
||||
case EQUAL:
|
||||
case NOT_EQUAL:
|
||||
BigDecimal mul = calculateFuzzAmount(thePrefix, theValue);
|
||||
BigDecimal low = theValue.subtract(mul, MathContext.DECIMAL64);
|
||||
BigDecimal high = theValue.add(mul, MathContext.DECIMAL64);
|
||||
Predicate lowPred;
|
||||
Predicate highPred;
|
||||
if (thePrefix != ParamPrefixEnum.NOT_EQUAL) {
|
||||
lowPred = builder.ge(thePath.as(BigDecimal.class), low);
|
||||
highPred = builder.le(thePath.as(BigDecimal.class), high);
|
||||
num = builder.and(lowPred, highPred);
|
||||
ourLog.trace("Searching for {} <= val <= {}", low, high);
|
||||
} else {
|
||||
// Prefix was "ne", so reverse it!
|
||||
lowPred = builder.lt(thePath.as(BigDecimal.class), low);
|
||||
highPred = builder.gt(thePath.as(BigDecimal.class), high);
|
||||
num = builder.or(lowPred, highPred);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
String msg = myContext.getLocalizer().getMessage(SearchBuilder.class, invalidMessageName, thePrefix.getValue(), theParam.getValueAsQueryToken(myContext));
|
||||
throw new InvalidRequestException(msg);
|
||||
}
|
||||
|
||||
if (theParamName == null) {
|
||||
|
@ -1026,7 +1026,7 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
BaseQuantityDt param = (BaseQuantityDt) theParam;
|
||||
systemValue = param.getSystemElement().getValueAsString();
|
||||
unitsValue = param.getUnitsElement().getValueAsString();
|
||||
cmpValue = ParamPrefixEnum.forDstu1Value(param.getComparatorElement().getValueAsString());
|
||||
cmpValue = ParamPrefixEnum.forValue(param.getComparatorElement().getValueAsString());
|
||||
valueValue = param.getValueElement().getValue();
|
||||
} else if (theParam instanceof QuantityParam) {
|
||||
QuantityParam param = (QuantityParam) theParam;
|
||||
|
@ -1411,43 +1411,43 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
JoinEnum joinType;
|
||||
|
||||
switch (param.getParamType()) {
|
||||
case STRING:
|
||||
joinAttrName = "myParamsString";
|
||||
sortAttrName = new String[] { "myValueExact" };
|
||||
joinType = JoinEnum.STRING;
|
||||
break;
|
||||
case DATE:
|
||||
joinAttrName = "myParamsDate";
|
||||
sortAttrName = new String[] { "myValueLow" };
|
||||
joinType = JoinEnum.DATE;
|
||||
break;
|
||||
case REFERENCE:
|
||||
joinAttrName = "myResourceLinks";
|
||||
sortAttrName = new String[] { "myTargetResourcePid" };
|
||||
joinType = JoinEnum.REFERENCE;
|
||||
break;
|
||||
case TOKEN:
|
||||
joinAttrName = "myParamsToken";
|
||||
sortAttrName = new String[] { "mySystem", "myValue" };
|
||||
joinType = JoinEnum.TOKEN;
|
||||
break;
|
||||
case NUMBER:
|
||||
joinAttrName = "myParamsNumber";
|
||||
sortAttrName = new String[] { "myValue" };
|
||||
joinType = JoinEnum.NUMBER;
|
||||
break;
|
||||
case URI:
|
||||
joinAttrName = "myParamsUri";
|
||||
sortAttrName = new String[] { "myUri" };
|
||||
joinType = JoinEnum.URI;
|
||||
break;
|
||||
case QUANTITY:
|
||||
joinAttrName = "myParamsQuantity";
|
||||
sortAttrName = new String[] { "myValue" };
|
||||
joinType = JoinEnum.QUANTITY;
|
||||
break;
|
||||
default:
|
||||
throw new InvalidRequestException("This server does not support _sort specifications of type " + param.getParamType() + " - Can't serve _sort=" + theSort.getParamName());
|
||||
case STRING:
|
||||
joinAttrName = "myParamsString";
|
||||
sortAttrName = new String[] { "myValueExact" };
|
||||
joinType = JoinEnum.STRING;
|
||||
break;
|
||||
case DATE:
|
||||
joinAttrName = "myParamsDate";
|
||||
sortAttrName = new String[] { "myValueLow" };
|
||||
joinType = JoinEnum.DATE;
|
||||
break;
|
||||
case REFERENCE:
|
||||
joinAttrName = "myResourceLinks";
|
||||
sortAttrName = new String[] { "myTargetResourcePid" };
|
||||
joinType = JoinEnum.REFERENCE;
|
||||
break;
|
||||
case TOKEN:
|
||||
joinAttrName = "myParamsToken";
|
||||
sortAttrName = new String[] { "mySystem", "myValue" };
|
||||
joinType = JoinEnum.TOKEN;
|
||||
break;
|
||||
case NUMBER:
|
||||
joinAttrName = "myParamsNumber";
|
||||
sortAttrName = new String[] { "myValue" };
|
||||
joinType = JoinEnum.NUMBER;
|
||||
break;
|
||||
case URI:
|
||||
joinAttrName = "myParamsUri";
|
||||
sortAttrName = new String[] { "myUri" };
|
||||
joinType = JoinEnum.URI;
|
||||
break;
|
||||
case QUANTITY:
|
||||
joinAttrName = "myParamsQuantity";
|
||||
sortAttrName = new String[] { "myValue" };
|
||||
joinType = JoinEnum.QUANTITY;
|
||||
break;
|
||||
default:
|
||||
throw new InvalidRequestException("This server does not support _sort specifications of type " + param.getParamType() + " - Can't serve _sort=" + theSort.getParamName());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1637,32 +1637,28 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
|
||||
List<String> paths;
|
||||
RuntimeSearchParam param = null;
|
||||
if (theContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
paths = Collections.singletonList(nextInclude.getValue());
|
||||
} else {
|
||||
String resType = nextInclude.getParamType();
|
||||
if (isBlank(resType)) {
|
||||
continue;
|
||||
}
|
||||
RuntimeResourceDefinition def = theContext.getResourceDefinition(resType);
|
||||
if (def == null) {
|
||||
ourLog.warn("Unknown resource type in include/revinclude=" + nextInclude.getValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
String paramName = nextInclude.getParamName();
|
||||
if (isNotBlank(paramName)) {
|
||||
param = theCallingDao.getSearchParamByName(def, paramName);
|
||||
} else {
|
||||
param = null;
|
||||
}
|
||||
if (param == null) {
|
||||
ourLog.warn("Unknown param name in include/revinclude=" + nextInclude.getValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
paths = param.getPathsSplit();
|
||||
String resType = nextInclude.getParamType();
|
||||
if (isBlank(resType)) {
|
||||
continue;
|
||||
}
|
||||
RuntimeResourceDefinition def = theContext.getResourceDefinition(resType);
|
||||
if (def == null) {
|
||||
ourLog.warn("Unknown resource type in include/revinclude=" + nextInclude.getValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
String paramName = nextInclude.getParamName();
|
||||
if (isNotBlank(paramName)) {
|
||||
param = theCallingDao.getSearchParamByName(def, paramName);
|
||||
} else {
|
||||
param = null;
|
||||
}
|
||||
if (param == null) {
|
||||
ourLog.warn("Unknown param name in include/revinclude=" + nextInclude.getValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
paths = param.getPathsSplit();
|
||||
|
||||
String targetResourceType = defaultString(nextInclude.getParamTargetType(), null);
|
||||
for (String nextPath : paths) {
|
||||
|
@ -1792,49 +1788,49 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
RuntimeSearchParam nextParamDef = mySearchParamRegistry.getActiveSearchParam(theResourceName, theParamName);
|
||||
if (nextParamDef != null) {
|
||||
switch (nextParamDef.getParamType()) {
|
||||
case DATE:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateDate(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case QUANTITY:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateQuantity(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case REFERENCE:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateReference(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateString(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case TOKEN:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateToken(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case NUMBER:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateNumber(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case COMPOSITE:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateComposite(theResourceName, nextParamDef, nextAnd);
|
||||
}
|
||||
break;
|
||||
case URI:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateUri(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case HAS:
|
||||
// should not happen
|
||||
break;
|
||||
case DATE:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateDate(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case QUANTITY:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateQuantity(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case REFERENCE:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateReference(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case STRING:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateString(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case TOKEN:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateToken(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case NUMBER:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateNumber(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case COMPOSITE:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateComposite(theResourceName, nextParamDef, nextAnd);
|
||||
}
|
||||
break;
|
||||
case URI:
|
||||
for (List<? extends IQueryParameterType> nextAnd : theAndOrParams) {
|
||||
addPredicateUri(theResourceName, theParamName, nextAnd);
|
||||
}
|
||||
break;
|
||||
case HAS:
|
||||
// should not happen
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (Constants.PARAM_CONTENT.equals(theParamName) || Constants.PARAM_TEXT.equals(theParamName)) {
|
||||
|
@ -1855,35 +1851,35 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
private IQueryParameterType toParameterType(RuntimeSearchParam theParam) {
|
||||
IQueryParameterType qp;
|
||||
switch (theParam.getParamType()) {
|
||||
case DATE:
|
||||
qp = new DateParam();
|
||||
break;
|
||||
case NUMBER:
|
||||
qp = new NumberParam();
|
||||
break;
|
||||
case QUANTITY:
|
||||
qp = new QuantityParam();
|
||||
break;
|
||||
case STRING:
|
||||
qp = new StringParam();
|
||||
break;
|
||||
case TOKEN:
|
||||
qp = new TokenParam();
|
||||
break;
|
||||
case COMPOSITE:
|
||||
List<RuntimeSearchParam> compositeOf = theParam.getCompositeOf();
|
||||
if (compositeOf.size() != 2) {
|
||||
throw new InternalErrorException("Parameter " + theParam.getName() + " has " + compositeOf.size() + " composite parts. Don't know how handlt this.");
|
||||
}
|
||||
IQueryParameterType leftParam = toParameterType(compositeOf.get(0));
|
||||
IQueryParameterType rightParam = toParameterType(compositeOf.get(1));
|
||||
qp = new CompositeParam<IQueryParameterType, IQueryParameterType>(leftParam, rightParam);
|
||||
break;
|
||||
case REFERENCE:
|
||||
qp = new ReferenceParam();
|
||||
break;
|
||||
default:
|
||||
throw new InternalErrorException("Don't know how to convert param type: " + theParam.getParamType());
|
||||
case DATE:
|
||||
qp = new DateParam();
|
||||
break;
|
||||
case NUMBER:
|
||||
qp = new NumberParam();
|
||||
break;
|
||||
case QUANTITY:
|
||||
qp = new QuantityParam();
|
||||
break;
|
||||
case STRING:
|
||||
qp = new StringParam();
|
||||
break;
|
||||
case TOKEN:
|
||||
qp = new TokenParam();
|
||||
break;
|
||||
case COMPOSITE:
|
||||
List<RuntimeSearchParam> compositeOf = theParam.getCompositeOf();
|
||||
if (compositeOf.size() != 2) {
|
||||
throw new InternalErrorException("Parameter " + theParam.getName() + " has " + compositeOf.size() + " composite parts. Don't know how handlt this.");
|
||||
}
|
||||
IQueryParameterType leftParam = toParameterType(compositeOf.get(0));
|
||||
IQueryParameterType rightParam = toParameterType(compositeOf.get(1));
|
||||
qp = new CompositeParam<IQueryParameterType, IQueryParameterType>(leftParam, rightParam);
|
||||
break;
|
||||
case REFERENCE:
|
||||
qp = new ReferenceParam();
|
||||
break;
|
||||
default:
|
||||
throw new InternalErrorException("Don't know how to convert param type: " + theParam.getParamType());
|
||||
}
|
||||
return qp;
|
||||
}
|
||||
|
@ -1966,7 +1962,7 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
return thePredicates.toArray(new Predicate[thePredicates.size()]);
|
||||
}
|
||||
|
||||
public class IncludesIterator extends BaseIterator<Long> implements Iterator<Long>{
|
||||
public class IncludesIterator extends BaseIterator<Long> implements Iterator<Long> {
|
||||
|
||||
private Iterator<Long> myCurrentIterator;
|
||||
private int myCurrentOffset;
|
||||
|
@ -1982,12 +1978,12 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
|
||||
private void fetchNext() {
|
||||
while (myNext == null) {
|
||||
|
||||
|
||||
if (myCurrentIterator.hasNext()) {
|
||||
myNext = myCurrentIterator.next();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!myCurrentIterator.hasNext()) {
|
||||
int start = myCurrentOffset;
|
||||
int end = myCurrentOffset + myPageSize;
|
||||
|
@ -2004,7 +2000,7 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
Set<Long> newPids = loadReverseIncludes(myCallingDao, myContext, myEntityManager, pidsToScan, includes, false, myParams.getLastUpdated());
|
||||
myCurrentIterator = newPids.iterator();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2023,8 +2019,15 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
private enum JoinEnum {
|
||||
DATE, NUMBER, QUANTITY, REFERENCE, STRING, TOKEN, URI
|
||||
DATE,
|
||||
NUMBER,
|
||||
QUANTITY,
|
||||
REFERENCE,
|
||||
STRING,
|
||||
TOKEN,
|
||||
URI
|
||||
|
||||
}
|
||||
|
||||
|
@ -2088,11 +2091,11 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
Integer maximumResults = myCallingDao.getConfig().getFetchSizeDefaultMaximum();
|
||||
|
||||
final TypedQuery<Long> query = createQuery(mySort, maximumResults);
|
||||
|
||||
|
||||
Query<Long> hibernateQuery = (Query<Long>) query;
|
||||
ScrollableResults scroll = hibernateQuery.scroll(ScrollMode.FORWARD_ONLY);
|
||||
myResultsIterator = new ScrollableResultsIterator(scroll);
|
||||
|
||||
|
||||
// If the query resulted in extra results being requested
|
||||
if (myAlsoIncludePids != null) {
|
||||
myPreResultsIterator = myAlsoIncludePids.iterator();
|
||||
|
@ -2148,11 +2151,11 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
ourLog.info("Initial query result returned in {}ms for query {}", myStopwatch.getMillis(), mySearchUuid);
|
||||
myFirst = false;
|
||||
}
|
||||
|
||||
|
||||
if (myNext == NO_MORE) {
|
||||
ourLog.info("Query found {} matches in {}ms for query {}", myPidSet.size(), myStopwatch.getMillis(), mySearchUuid);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2198,7 +2201,7 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
@Override
|
||||
public boolean hasNext() {
|
||||
ensureHaveNext();
|
||||
return myNext != NO_MORE;
|
||||
return myNext != NO_MORE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
package ca.uhn.fhir.jpa.util;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import org.hl7.fhir.r4.model.Subscription;
|
||||
import org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType;
|
||||
import org.hl7.fhir.r4.model.Subscription.SubscriptionStatus;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR JPA Server
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2017 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
|
||||
import ca.uhn.fhir.jpa.dao.r4.FhirResourceDaoSubscriptionR4;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||
import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter;
|
||||
import ca.uhn.fhir.util.CoverageIgnore;
|
||||
|
||||
/**
|
||||
* Interceptor which requires newly created {@link Subscription subscriptions} to be in
|
||||
* {@link SubscriptionStatus#REQUESTED} state and prevents clients from changing the status.
|
||||
*/
|
||||
public class SubscriptionsRequireManualActivationInterceptorR4 extends InterceptorAdapter {
|
||||
|
||||
public static final ResourceMetadataKeyEnum<Object> ALLOW_STATUS_CHANGE = new ResourceMetadataKeyEnum<Object>(FhirResourceDaoSubscriptionR4.class.getName() + "_ALLOW_STATUS_CHANGE") {
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
@CoverageIgnore
|
||||
@Override
|
||||
public Object get(IResource theResource) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@CoverageIgnore
|
||||
@Override
|
||||
public void put(IResource theResource, Object theObject) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mySubscriptionDaoR4")
|
||||
private IFhirResourceDao<Subscription> myDao;
|
||||
|
||||
@Override
|
||||
public void incomingRequestPreHandled(RestOperationTypeEnum theOperation, ActionRequestDetails theProcessedRequest) {
|
||||
switch (theOperation) {
|
||||
case CREATE:
|
||||
case UPDATE:
|
||||
if (theProcessedRequest.getResourceType().equals("Subscription")) {
|
||||
verifyStatusOk(theOperation, theProcessedRequest);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void setDao(IFhirResourceDao<Subscription> theDao) {
|
||||
myDao = theDao;
|
||||
}
|
||||
|
||||
private void verifyStatusOk(RestOperationTypeEnum theOperation, ActionRequestDetails theRequestDetails) {
|
||||
Subscription subscription = (Subscription) theRequestDetails.getResource();
|
||||
SubscriptionStatus newStatus = subscription.getStatusElement().getValue();
|
||||
|
||||
if (newStatus == SubscriptionStatus.REQUESTED || newStatus == SubscriptionStatus.OFF) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newStatus == null) {
|
||||
String actualCode = subscription.getStatusElement().getValueAsString();
|
||||
throw new UnprocessableEntityException("Can not " + theOperation.getCode() + " resource: Subscription.status must be populated" + ((isNotBlank(actualCode)) ? " (invalid value " + actualCode + ")" : ""));
|
||||
}
|
||||
|
||||
IIdType requestId = theRequestDetails.getId();
|
||||
if (requestId != null && requestId.hasIdPart()) {
|
||||
Subscription existing;
|
||||
try {
|
||||
existing = myDao.read(requestId, null);
|
||||
SubscriptionStatus existingStatus = existing.getStatusElement().getValue();
|
||||
if (existingStatus != newStatus) {
|
||||
verifyActiveStatus(subscription, newStatus, existingStatus);
|
||||
}
|
||||
} catch (ResourceNotFoundException e) {
|
||||
verifyActiveStatus(subscription, newStatus, null);
|
||||
}
|
||||
} else {
|
||||
verifyActiveStatus(subscription, newStatus, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyActiveStatus(Subscription theSubscription, SubscriptionStatus newStatus, SubscriptionStatus theExistingStatus) {
|
||||
SubscriptionChannelType channelType = theSubscription.getChannel().getTypeElement().getValue();
|
||||
|
||||
if (channelType == null) {
|
||||
throw new UnprocessableEntityException("Subscription.channel.type must be populated");
|
||||
}
|
||||
|
||||
if (channelType == SubscriptionChannelType.WEBSOCKET) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (theExistingStatus != null) {
|
||||
throw new UnprocessableEntityException("Subscription.status can not be changed from " + describeStatus(theExistingStatus) + " to " + describeStatus(newStatus));
|
||||
}
|
||||
|
||||
throw new UnprocessableEntityException("Subscription.status must be '" + SubscriptionStatus.OFF.toCode() + "' or '" + SubscriptionStatus.REQUESTED.toCode() + "' on a newly created subscription");
|
||||
}
|
||||
|
||||
private String describeStatus(SubscriptionStatus existingStatus) {
|
||||
String existingStatusString;
|
||||
if (existingStatus != null) {
|
||||
existingStatusString = '\'' + existingStatus.toCode() + '\'';
|
||||
} else {
|
||||
existingStatusString = "null";
|
||||
}
|
||||
return existingStatusString;
|
||||
}
|
||||
|
||||
}
|
|
@ -26,7 +26,6 @@ import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
|
|||
import ca.uhn.fhir.jpa.entity.TagTypeEnum;
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.dstu2.composite.*;
|
||||
import ca.uhn.fhir.model.dstu2.resource.*;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Bundle;
|
||||
|
@ -1678,10 +1677,10 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
|
||||
@Test
|
||||
public void testPersistSearchParamDate() {
|
||||
List<Patient> found = toList(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_BIRTHDATE, new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2000-01-01"))));
|
||||
List<Patient> found = toList(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_BIRTHDATE, new DateParam(ParamPrefixEnum.GREATERTHAN, "2000-01-01"))));
|
||||
int initialSize2000 = found.size();
|
||||
|
||||
found = toList(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_BIRTHDATE, new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2002-01-01"))));
|
||||
found = toList(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_BIRTHDATE, new DateParam(ParamPrefixEnum.GREATERTHAN, "2002-01-01"))));
|
||||
int initialSize2002 = found.size();
|
||||
|
||||
Patient patient = new Patient();
|
||||
|
@ -1690,15 +1689,15 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
|
||||
myPatientDao.create(patient, mySrd);
|
||||
|
||||
found = toList(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_BIRTHDATE, new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2000-01-01"))));
|
||||
found = toList(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_BIRTHDATE, new DateParam(ParamPrefixEnum.GREATERTHAN, "2000-01-01"))));
|
||||
assertEquals(1 + initialSize2000, found.size());
|
||||
|
||||
found = toList(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_BIRTHDATE, new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2002-01-01"))));
|
||||
found = toList(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_BIRTHDATE, new DateParam(ParamPrefixEnum.GREATERTHAN, "2002-01-01"))));
|
||||
assertEquals(initialSize2002, found.size());
|
||||
|
||||
// If this throws an exception, that would be an acceptable outcome as well..
|
||||
try {
|
||||
found = toList(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_BIRTHDATE + "AAAA", new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2000-01-01"))));
|
||||
found = toList(myPatientDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Patient.SP_BIRTHDATE + "AAAA", new DateParam(ParamPrefixEnum.GREATERTHAN, "2000-01-01"))));
|
||||
assertEquals(0, found.size());
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("Unknown search parameter birthdateAAAA for resource type Patient", e.getMessage());
|
||||
|
|
|
@ -31,7 +31,6 @@ import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum;
|
|||
import ca.uhn.fhir.jpa.entity.*;
|
||||
import ca.uhn.fhir.model.api.Include;
|
||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.parser.StrictErrorHandler;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.SortOrderEnum;
|
||||
|
@ -1237,8 +1236,8 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
|
|||
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), containsInAnyOrder(id1a, id1b));
|
||||
|
||||
map = new SearchParameterMap();
|
||||
map.setLastUpdated(new DateRangeParam(new DateParam(QuantityCompararatorEnum.GREATERTHAN, startDateTime.getValue()),
|
||||
new DateParam(QuantityCompararatorEnum.LESSTHAN, myPatientDao.read(id1b, mySrd).getMeta().getLastUpdatedElement().getValue())));
|
||||
map.setLastUpdated(new DateRangeParam(new DateParam(ParamPrefixEnum.GREATERTHAN, startDateTime.getValue()),
|
||||
new DateParam(ParamPrefixEnum.LESSTHAN, myPatientDao.read(id1b, mySrd).getMeta().getLastUpdatedElement().getValue())));
|
||||
ourLog.info("Searching: {}", map.getLastUpdated());
|
||||
assertThat(toUnqualifiedVersionlessIds(myPatientDao.search(map)), containsInAnyOrder(id1a));
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import ca.uhn.fhir.jpa.dao.*;
|
|||
import ca.uhn.fhir.jpa.entity.*;
|
||||
import ca.uhn.fhir.model.api.Include;
|
||||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum;
|
||||
import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum;
|
||||
import ca.uhn.fhir.rest.api.*;
|
||||
|
@ -2151,10 +2150,10 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
|
|||
|
||||
@Test
|
||||
public void testPersistSearchParamDate() {
|
||||
List<Patient> found = toList(myPatientDao.search(new SearchParameterMap(Patient.SP_BIRTHDATE, new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2000-01-01")).setLoadSynchronous(true)));
|
||||
List<Patient> found = toList(myPatientDao.search(new SearchParameterMap(Patient.SP_BIRTHDATE, new DateParam(ParamPrefixEnum.GREATERTHAN, "2000-01-01")).setLoadSynchronous(true)));
|
||||
int initialSize2000 = found.size();
|
||||
|
||||
found = toList(myPatientDao.search(new SearchParameterMap(Patient.SP_BIRTHDATE, new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2002-01-01")).setLoadSynchronous(true)));
|
||||
found = toList(myPatientDao.search(new SearchParameterMap(Patient.SP_BIRTHDATE, new DateParam(ParamPrefixEnum.GREATERTHAN, "2002-01-01")).setLoadSynchronous(true)));
|
||||
int initialSize2002 = found.size();
|
||||
|
||||
Patient patient = new Patient();
|
||||
|
@ -2163,15 +2162,15 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
|
|||
|
||||
myPatientDao.create(patient, mySrd);
|
||||
|
||||
found = toList(myPatientDao.search(new SearchParameterMap(Patient.SP_BIRTHDATE, new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2000-01-01")).setLoadSynchronous(true)));
|
||||
found = toList(myPatientDao.search(new SearchParameterMap(Patient.SP_BIRTHDATE, new DateParam(ParamPrefixEnum.GREATERTHAN, "2000-01-01")).setLoadSynchronous(true)));
|
||||
assertEquals(1 + initialSize2000, found.size());
|
||||
|
||||
found = toList(myPatientDao.search(new SearchParameterMap(Patient.SP_BIRTHDATE, new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2002-01-01")).setLoadSynchronous(true)));
|
||||
found = toList(myPatientDao.search(new SearchParameterMap(Patient.SP_BIRTHDATE, new DateParam(ParamPrefixEnum.GREATERTHAN, "2002-01-01")).setLoadSynchronous(true)));
|
||||
assertEquals(initialSize2002, found.size());
|
||||
|
||||
// If this throws an exception, that would be an acceptable outcome as well..
|
||||
try {
|
||||
found = toList(myPatientDao.search(new SearchParameterMap(Patient.SP_BIRTHDATE + "AAAA", new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2000-01-01")).setLoadSynchronous(true)));
|
||||
found = toList(myPatientDao.search(new SearchParameterMap(Patient.SP_BIRTHDATE + "AAAA", new DateParam(ParamPrefixEnum.GREATERTHAN, "2000-01-01")).setLoadSynchronous(true)));
|
||||
assertEquals(0, found.size());
|
||||
} catch (InvalidRequestException e) {
|
||||
assertEquals("Unknown search parameter birthdateAAAA for resource type Patient", e.getMessage());
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.util.Set;
|
|||
|
||||
import org.hl7.fhir.instance.model.api.*;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.SummaryEnum;
|
||||
|
||||
|
@ -33,8 +32,6 @@ public interface IRestfulResponse {
|
|||
|
||||
Object streamResponseAsResource(IBaseResource theActualResourceToReturn, boolean thePrettyPrint, Set<SummaryEnum> theSummaryMode, int theStatusCode, String theStatusMessage, boolean theRespondGzip, boolean theAddContentLocation) throws IOException;
|
||||
|
||||
Object streamResponseAsBundle(Bundle bundle, Set<SummaryEnum> summaryMode, boolean respondGzip, boolean requestIsBrowser) throws IOException;
|
||||
|
||||
/**
|
||||
* This is only used for DSTU1 getTags operations, so it can be removed at some point when we
|
||||
* drop DSTU1
|
||||
|
|
|
@ -25,11 +25,8 @@ import java.util.Date;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||
import org.hl7.fhir.instance.model.api.*;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.rest.api.SummaryEnum;
|
||||
import ca.uhn.fhir.rest.api.server.IRestfulResponse;
|
||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||
|
@ -84,12 +81,6 @@ public abstract class RestfulResponse<T extends RequestDetails> implements IRest
|
|||
this.theRequestDetails = requestDetails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object streamResponseAsBundle(Bundle bundle, Set<SummaryEnum> summaryMode, boolean respondGzip, boolean requestIsBrowser)
|
||||
throws IOException {
|
||||
return RestfulServerUtils.streamResponseAsBundle(theRequestDetails.getServer(), bundle, summaryMode, respondGzip, getRequestDetails());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object streamResponseAsResource(IBaseResource theResource, boolean thePrettyPrint, Set<SummaryEnum> theSummaryMode,
|
||||
int theStatusCode, String theStatusMessage, boolean theRespondGzip, boolean theAddContentLocation)
|
||||
|
|
|
@ -19,51 +19,25 @@ package ca.uhn.fhir.rest.server;
|
|||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.replace;
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||
import org.hl7.fhir.instance.model.api.*;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
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.api.ResourceMetadataKeyEnum;
|
||||
import ca.uhn.fhir.model.api.Tag;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.api.PreferReturnEnum;
|
||||
import ca.uhn.fhir.rest.api.SummaryEnum;
|
||||
import ca.uhn.fhir.rest.api.*;
|
||||
import ca.uhn.fhir.rest.api.server.IRestfulResponse;
|
||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
|
@ -561,32 +535,6 @@ public class RestfulServerUtils {
|
|||
return prettyPrint;
|
||||
}
|
||||
|
||||
public static Object streamResponseAsBundle(IRestfulServerDefaults theServer, Bundle bundle, Set<SummaryEnum> theSummaryMode, boolean respondGzip, RequestDetails theRequestDetails)
|
||||
throws IOException {
|
||||
|
||||
int status = 200;
|
||||
|
||||
// Determine response encoding
|
||||
EncodingEnum responseEncoding = RestfulServerUtils.determineResponseEncodingWithDefault(theRequestDetails).getEncoding();
|
||||
|
||||
String contentType = responseEncoding.getBundleContentType();
|
||||
|
||||
String charset = Constants.CHARSET_NAME_UTF8;
|
||||
Writer writer = theRequestDetails.getResponse().getResponseWriter(status, null, contentType, charset, respondGzip);
|
||||
|
||||
try {
|
||||
IParser parser = RestfulServerUtils.getNewParser(theServer.getFhirContext(), theRequestDetails);
|
||||
if (theSummaryMode.contains(SummaryEnum.TEXT)) {
|
||||
parser.setEncodeElements(TEXT_ENCODE_ELEMENTS);
|
||||
}
|
||||
parser.encodeBundleToWriter(bundle, writer);
|
||||
} catch (Exception e) {
|
||||
// always send a response, even if the parsing went wrong
|
||||
}
|
||||
//FIXME resource leak
|
||||
return theRequestDetails.getResponse().sendWriterResponse(status, contentType, charset, writer);
|
||||
}
|
||||
|
||||
public static Object streamResponseAsResource(IRestfulServerDefaults theServer, IBaseResource theResource, Set<SummaryEnum> theSummaryMode, int stausCode, boolean theAddContentLocationHeader,
|
||||
boolean respondGzip, RequestDetails theRequestDetails) throws IOException {
|
||||
return streamResponseAsResource(theServer, theResource, theSummaryMode, stausCode, null, theAddContentLocationHeader, respondGzip, theRequestDetails, null, null);
|
||||
|
@ -670,21 +618,6 @@ public class RestfulServerUtils {
|
|||
restUtil.addHeader(Constants.HEADER_LAST_MODIFIED, DateUtils.formatDate(lastUpdated.getValue()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Category header (DSTU1 only)
|
||||
*/
|
||||
|
||||
if (theResource instanceof IResource && theServer.getFhirContext().getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
TagList list = (TagList) ((IResource) theResource).getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST);
|
||||
if (list != null) {
|
||||
for (Tag tag : list) {
|
||||
if (StringUtils.isNotBlank(tag.getTerm())) {
|
||||
restUtil.addHeader(Constants.HEADER_CATEGORY, tag.toHeaderValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Stream the response body
|
||||
*/
|
||||
|
|
|
@ -519,9 +519,6 @@ public abstract class BaseMethodBinding<T> {
|
|||
} else if (history != null) {
|
||||
return new HistoryMethodBinding(theMethod, theContext, theProvider);
|
||||
} else if (validate != null) {
|
||||
if (theContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
return new ValidateMethodBindingDstu1(theMethod, theContext, theProvider);
|
||||
}
|
||||
return new ValidateMethodBindingDstu2Plus(returnType, returnTypeFromRp, theMethod, theContext, theProvider, validate);
|
||||
} else if (getTags != null) {
|
||||
return new GetTagsMethodBinding(theMethod, theContext, theProvider, getTags);
|
||||
|
|
|
@ -12,7 +12,7 @@ import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -85,7 +85,8 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu
|
|||
}
|
||||
|
||||
if (resourceParameter == null) {
|
||||
throw new ConfigurationException("Method " + theMethod.getName() + " in type " + theMethod.getDeclaringClass().getCanonicalName() + " does not have a resource parameter annotated with @" + ResourceParam.class.getSimpleName());
|
||||
throw new ConfigurationException("Method " + theMethod.getName() + " in type " + theMethod.getDeclaringClass().getCanonicalName() + " does not have a resource parameter annotated with @"
|
||||
+ ResourceParam.class.getSimpleName());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -99,20 +100,16 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu
|
|||
IBaseResource resource = ((IBaseResource) theParams[myResourceParameterIndex]);
|
||||
String resourceId = resource.getIdElement().getIdPart();
|
||||
String urlId = theRequest.getId() != null ? theRequest.getId().getIdPart() : null;
|
||||
if (getContext().getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
resource.setId(urlId);
|
||||
} else {
|
||||
if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3) == false) {
|
||||
resource.setId(theRequest.getId());
|
||||
}
|
||||
|
||||
String matchUrl = null;
|
||||
if (myConditionalUrlIndex != -1) {
|
||||
matchUrl = (String) theParams[myConditionalUrlIndex];
|
||||
matchUrl = defaultIfBlank(matchUrl, null);
|
||||
}
|
||||
validateResourceIdAndUrlIdForNonConditionalOperation(resource, resourceId, urlId, matchUrl);
|
||||
if (getContext().getVersion().getVersion().isOlderThan(FhirVersionEnum.DSTU3) == false) {
|
||||
resource.setId(theRequest.getId());
|
||||
}
|
||||
|
||||
String matchUrl = null;
|
||||
if (myConditionalUrlIndex != -1) {
|
||||
matchUrl = (String) theParams[myConditionalUrlIndex];
|
||||
matchUrl = defaultIfBlank(matchUrl, null);
|
||||
}
|
||||
validateResourceIdAndUrlIdForNonConditionalOperation(resource, resourceId, urlId, matchUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -105,11 +105,6 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
|
|||
}
|
||||
myName = theOperationName;
|
||||
|
||||
if (theContext.getVersion().getVersion().isEquivalentTo(FhirVersionEnum.DSTU1)) {
|
||||
throw new ConfigurationException("@" + Operation.class.getSimpleName() + " methods are not supported on servers for FHIR version " + theContext.getVersion().getVersion().name()
|
||||
+ " - Found one on class " + theMethod.getDeclaringClass().getName());
|
||||
}
|
||||
|
||||
if (theReturnTypeFromRp != null) {
|
||||
setResourceName(theContext.getResourceDefinition(theReturnTypeFromRp).getName());
|
||||
} else {
|
||||
|
|
|
@ -183,15 +183,6 @@ public class ResourceParameter implements IParameter {
|
|||
throw new InvalidRequestException(msg);
|
||||
}
|
||||
|
||||
if (theRequest.getServer().getFhirContext().getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
|
||||
TagList tagList = new TagList();
|
||||
for (String nextTagComplete : theRequest.getHeaders(Constants.HEADER_CATEGORY)) {
|
||||
ParameterUtil.parseTagValue(tagList, nextTagComplete);
|
||||
}
|
||||
if (tagList.isEmpty() == false) {
|
||||
((IResource) retVal).getResourceMetadata().put(ResourceMetadataKeyEnum.TAG_LIST, tagList);
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
package ca.uhn.fhir.rest.server.method;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* HAPI FHIR - Core Library
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2017 University Health Network
|
||||
* %%
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.rest.annotation.Validate;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||
import ca.uhn.fhir.rest.param.ParameterUtil;
|
||||
|
||||
public class ValidateMethodBindingDstu1 extends BaseOutcomeReturningMethodBindingWithResourceParam {
|
||||
|
||||
private Integer myIdParameterIndex;
|
||||
|
||||
public ValidateMethodBindingDstu1(Method theMethod, FhirContext theContext, Object theProvider) {
|
||||
super(theMethod, theContext, Validate.class, theProvider);
|
||||
|
||||
myIdParameterIndex = ParameterUtil.findIdParameterIndex(theMethod, getContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestOperationTypeEnum getRestOperationType() {
|
||||
return RestOperationTypeEnum.VALIDATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addParametersForServerRequest(RequestDetails theRequest, Object[] theParams) {
|
||||
if (myIdParameterIndex != null) {
|
||||
theParams[myIdParameterIndex] = theRequest.getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean allowVoidReturnType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<RequestTypeEnum> provideAllowableRequestTypes() {
|
||||
// TODO: is post correct here?
|
||||
return Collections.singleton(RequestTypeEnum.POST);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String getMatchingOperation() {
|
||||
return Constants.PARAM_VALIDATE;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,204 +0,0 @@
|
|||
package ca.uhn.fhir.rest.method;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class BaseOutcomeReturningMethodBindingTest {
|
||||
|
||||
@Test
|
||||
public void testParseTagHeader() {
|
||||
|
||||
String headerString = "http://britsystems.com/fhir/tag/4567; scheme=\"http://britsystems.com/fhir\"; label=\"Tag-4567\",http://client/scheme/tag/123; scheme=\"http://client/scheme\"; label=\"tag 123\",http://client/scheme/tag/456; scheme=\"http://client/scheme\"; label=\"tag 456\",http://fhir.healthintersections.com.au/open/Patient/1; scheme=\"http://hl7.org/fhir/tag\"; label=\"GET <host>/<resourceType>/<id>\",http://hl7.fhir/example; scheme=\"http://hl7.org/fhir/tag\"; label=\"FHIR example\",http://hl7.org/fhir/sid/us-ssn; scheme=\"http://hl7.org/fhir/tag\"; label=\"POST <host>/<resourceType>\",http://hl7.org/fhir/tools/tag/test; scheme=\"http://hl7.org/fhir/tag\"; label=\"Test Tag\",http://hl7.org/implement/standards/fhir/v3/ActCode/InformationSensitivityPolicy#GDIS; scheme=\"http://hl7.org/fhir/tag\"; label=\"GDIS\",http://hl7.org/implement/standards/fhir/v3/Confidentiality#N; scheme=\"http://hl7.org/fhir/tag\"; label=\"N (Normal)\",http://hl7.org/implement/standards/fhir/v3/Confidentiality#R; scheme=\"http://hl7.org/fhir/tag\"; label=\"restricted\",http://nu.nl/testname; scheme=\"http://hl7.org/fhir/tag\"; label=\"TestCreateEditDelete\",http://readtag.nu.nl; scheme=\"http://hl7.org/fhir/tag\"; label=\"readTagTest\",http://spark.furore.com/fhir; scheme=\"http://hl7.org/fhir/tag\"; label=\"GET <host>/<resourceType>/<id>\",http://www.healthintersections.com.au/fhir/tags/invalid; scheme=\"http://hl7.org/fhir/tag\"; label=\"Non-conformant Resource\",urn:happytag; scheme=\"http://hl7.org/fhir/tag\"; label=\"This is a happy resource\",condition; scheme=\"http://hl7.org/fhir/tag/profile\"; label=\"Profile condition\",device; scheme=\"http://hl7.org/fhir/tag/profile\"; label=\"Profile device\",http://fhir.healthintersections.com.au/open/Profile/condition; scheme=\"http://hl7.org/fhir/tag/profile\"; label=\"Profile condition\",http://fhir.healthintersections.com.au/open/Profile/device; scheme=\"http://hl7.org/fhir/tag/profile\"; label=\"Profile device\",http://hl7.org/fhir/v3/ActCode#CEL; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Celebrity / VIP\",http://hl7.org/fhir/v3/ActCode#DEMO; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Contact/Employment Confidential\",http://hl7.org/fhir/v3/ActCode#DIA; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Diagnosis is/would be Confidential\",http://hl7.org/fhir/v3/ActCode#EMP; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Employee / Staff member\",http://hl7.org/fhir/v3/ActCode#ORCON; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Author only\",http://hl7.org/fhir/v3/ActCode#TABOO; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Patient/Carer Only\",http://hl7.org/fhir/v3/Confidentiality#L; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Confidentiality = Low\",http://hl7.org/fhir/v3/Confidentiality#M; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Confidentiality = Moderate\",http://hl7.org/fhir/v3/Confidentiality#N; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Confidentiality = Normal\",http://hl7.org/fhir/v3/Confidentiality#R; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Confidentiality = Restricted\",http://hl7.org/fhir/v3/Confidentiality#U; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Confidentiality = none\",http://hl7.org/fhir/v3/Confidentiality#V; scheme=\"http://hl7.org/fhir/tag/security\"; label=\"Confidentiality = Very Restricted\",http://term.com; scheme=\"http://scheme.com\"; label=\"Some good ole term\"";
|
||||
TagList parsedFromHeader = new TagList();
|
||||
MethodUtil.parseTagValue(parsedFromHeader, headerString);
|
||||
|
||||
//@formatter:off
|
||||
String resourceString = "{\n" +
|
||||
" \"resourceType\" : \"TagList\",\n" +
|
||||
" \"category\" : [\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://britsystems.com/fhir\",\n" +
|
||||
" \"term\" : \"http://britsystems.com/fhir/tag/4567\",\n" +
|
||||
" \"label\" : \"Tag-4567\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://client/scheme\",\n" +
|
||||
" \"term\" : \"http://client/scheme/tag/123\",\n" +
|
||||
" \"label\" : \"tag 123\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://client/scheme\",\n" +
|
||||
" \"term\" : \"http://client/scheme/tag/456\",\n" +
|
||||
" \"label\" : \"tag 456\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"http://fhir.healthintersections.com.au/open/Patient/1\",\n" +
|
||||
" \"label\" : \"GET <host>/<resourceType>/<id>\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"http://hl7.fhir/example\",\n" +
|
||||
" \"label\" : \"FHIR example\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/sid/us-ssn\",\n" +
|
||||
" \"label\" : \"POST <host>/<resourceType>\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/tools/tag/test\",\n" +
|
||||
" \"label\" : \"Test Tag\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"http://hl7.org/implement/standards/fhir/v3/ActCode/InformationSensitivityPolicy#GDIS\",\n" +
|
||||
" \"label\" : \"GDIS\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"http://hl7.org/implement/standards/fhir/v3/Confidentiality#N\",\n" +
|
||||
" \"label\" : \"N (Normal)\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"http://hl7.org/implement/standards/fhir/v3/Confidentiality#R\",\n" +
|
||||
" \"label\" : \"restricted\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"http://nu.nl/testname\",\n" +
|
||||
" \"label\" : \"TestCreateEditDelete\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"http://readtag.nu.nl\",\n" +
|
||||
" \"label\" : \"readTagTest\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"http://spark.furore.com/fhir\",\n" +
|
||||
" \"label\" : \"GET <host>/<resourceType>/<id>\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"http://www.healthintersections.com.au/fhir/tags/invalid\",\n" +
|
||||
" \"label\" : \"Non-conformant Resource\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag\",\n" +
|
||||
" \"term\" : \"urn:happytag\",\n" +
|
||||
" \"label\" : \"This is a happy resource\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/profile\",\n" +
|
||||
" \"term\" : \"condition\",\n" +
|
||||
" \"label\" : \"Profile condition\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/profile\",\n" +
|
||||
" \"term\" : \"device\",\n" +
|
||||
" \"label\" : \"Profile device\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/profile\",\n" +
|
||||
" \"term\" : \"http://fhir.healthintersections.com.au/open/Profile/condition\",\n" +
|
||||
" \"label\" : \"Profile condition\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/profile\",\n" +
|
||||
" \"term\" : \"http://fhir.healthintersections.com.au/open/Profile/device\",\n" +
|
||||
" \"label\" : \"Profile device\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/ActCode#CEL\",\n" +
|
||||
" \"label\" : \"Celebrity / VIP\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/ActCode#DEMO\",\n" +
|
||||
" \"label\" : \"Contact/Employment Confidential\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/ActCode#DIA\",\n" +
|
||||
" \"label\" : \"Diagnosis is/would be Confidential\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/ActCode#EMP\",\n" +
|
||||
" \"label\" : \"Employee / Staff member\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/ActCode#ORCON\",\n" +
|
||||
" \"label\" : \"Author only\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/ActCode#TABOO\",\n" +
|
||||
" \"label\" : \"Patient/Carer Only\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/Confidentiality#L\",\n" +
|
||||
" \"label\" : \"Confidentiality = Low\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/Confidentiality#M\",\n" +
|
||||
" \"label\" : \"Confidentiality = Moderate\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/Confidentiality#N\",\n" +
|
||||
" \"label\" : \"Confidentiality = Normal\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/Confidentiality#R\",\n" +
|
||||
" \"label\" : \"Confidentiality = Restricted\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/Confidentiality#U\",\n" +
|
||||
" \"label\" : \"Confidentiality = none\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://hl7.org/fhir/tag/security\",\n" +
|
||||
" \"term\" : \"http://hl7.org/fhir/v3/Confidentiality#V\",\n" +
|
||||
" \"label\" : \"Confidentiality = Very Restricted\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"scheme\" : \"http://scheme.com\",\n" +
|
||||
" \"term\" : \"http://term.com\",\n" +
|
||||
" \"label\" : \"Some good ole term\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
"}";
|
||||
//@formatter:on
|
||||
|
||||
TagList parsedFromResource = FhirContext.forDstu1().newJsonParser().parseTagList(resourceString);
|
||||
|
||||
assertEquals(parsedFromHeader.size(), parsedFromResource.size());
|
||||
|
||||
for (int i = 0; i < parsedFromHeader.size(); i++) {
|
||||
assertEquals(parsedFromHeader.get(i), parsedFromResource.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,298 +0,0 @@
|
|||
package ca.uhn.fhir.rest.server.interceptor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
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;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||
import ca.uhn.fhir.model.base.resource.BaseSecurityEvent;
|
||||
import ca.uhn.fhir.model.dstu.composite.HumanNameDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.resource.SecurityEvent;
|
||||
import ca.uhn.fhir.model.dstu.resource.SecurityEvent.ObjectElement;
|
||||
import ca.uhn.fhir.model.dstu.valueset.IdentifierUseEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.SecurityEventObjectLifecycleEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.SecurityEventObjectTypeEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.SecurityEventOutcomeEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.SecurityEventSourceTypeEnum;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.client.interceptor.UserInfoInterceptor;
|
||||
import ca.uhn.fhir.rest.param.TokenOrListParam;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import ca.uhn.fhir.rest.server.audit.IResourceAuditor;
|
||||
import ca.uhn.fhir.rest.server.audit.PatientAuditor;
|
||||
import ca.uhn.fhir.store.IAuditDataStore;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class AuditingInterceptorTest {
|
||||
|
||||
private static CloseableHttpClient ourClient;
|
||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static RestfulServer servlet;
|
||||
private IServerInterceptor myInterceptor;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
myInterceptor = mock(IServerInterceptor.class);
|
||||
servlet.setInterceptors(Collections.singletonList(myInterceptor));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBundle() throws Exception {
|
||||
|
||||
AuditingInterceptor interceptor = new AuditingInterceptor("HAPITEST", false);
|
||||
Map<String, Class<? extends IResourceAuditor<? extends IResource>>> auditors = new HashMap<String, Class<? extends IResourceAuditor<? extends IResource>>>();
|
||||
auditors.put("Patient", PatientAuditor.class);
|
||||
interceptor.setAuditableResources(auditors );
|
||||
servlet.setInterceptors(Collections.singletonList((IServerInterceptor)interceptor));
|
||||
|
||||
MockDataStore mockDataStore = mock(MockDataStore.class);
|
||||
interceptor.setDataStore(mockDataStore);
|
||||
|
||||
String requestURL = "http://localhost:" + ourPort + "/Patient?_id=1,2";
|
||||
HttpGet httpGet = new HttpGet(requestURL);
|
||||
httpGet.addHeader(UserInfoInterceptor.HEADER_USER_ID, "hapi-fhir-junit-user");
|
||||
httpGet.addHeader(UserInfoInterceptor.HEADER_USER_NAME, "HAPI FHIR Junit Test Cases");
|
||||
httpGet.addHeader(UserInfoInterceptor.HEADER_APPLICATION_NAME, "hapi-fhir-junit");
|
||||
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
ArgumentCaptor<SecurityEvent> captor = ArgumentCaptor.forClass(SecurityEvent.class);
|
||||
|
||||
verify(mockDataStore, times(1)).store(captor.capture());
|
||||
|
||||
SecurityEvent auditEvent = captor.getValue();
|
||||
assertEquals(SecurityEventOutcomeEnum.SUCCESS.getCode(), auditEvent.getEvent().getOutcome().getValue());
|
||||
assertEquals("HAPI FHIR Junit Test Cases", auditEvent.getParticipantFirstRep().getName().getValue());
|
||||
assertEquals("hapi-fhir-junit-user", auditEvent.getParticipantFirstRep().getUserId().getValue());
|
||||
assertEquals("hapi-fhir-junit", auditEvent.getSource().getIdentifier().getValue());
|
||||
assertEquals("HAPITEST", auditEvent.getSource().getSite().getValue());
|
||||
assertEquals(SecurityEventSourceTypeEnum.USER_DEVICE.getCode(), auditEvent.getSource().getTypeFirstRep().getCode().getValue());
|
||||
|
||||
List<ObjectElement> objects = auditEvent.getObject();
|
||||
assertEquals(2, objects.size());
|
||||
|
||||
for(ObjectElement object: objects){
|
||||
if("00001".equals(object.getIdentifier().getValue().getValue())){
|
||||
assertEquals("Patient: PatientOne Test", object.getName().getValue());
|
||||
}else if("00002".equals(object.getIdentifier().getValue().getValue())){
|
||||
assertEquals("Patient: Ms Laura Elizabeth MacDougall Sookraj B.Sc.", object.getName().getValue());
|
||||
}else{
|
||||
fail("Unexpected patient identifier being audited: " + object.getIdentifier().getValue().getValue());
|
||||
}
|
||||
assertEquals(requestURL, new String(Base64.decodeBase64(object.getQuery().getValueAsString())));
|
||||
assertEquals(SecurityEventObjectTypeEnum.PERSON, object.getType().getValueAsEnum());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSinglePatient() throws Exception {
|
||||
|
||||
AuditingInterceptor interceptor = new AuditingInterceptor("HAPITEST", false);
|
||||
Map<String, Class<? extends IResourceAuditor<? extends IResource>>> auditors = new HashMap<String, Class<? extends IResourceAuditor<? extends IResource>>>();
|
||||
auditors.put("Patient", PatientAuditor.class);
|
||||
interceptor.setAuditableResources(auditors );
|
||||
servlet.setInterceptors(Collections.singletonList((IServerInterceptor)interceptor));
|
||||
|
||||
MockDataStore mockDataStore = mock(MockDataStore.class);
|
||||
interceptor.setDataStore(mockDataStore);
|
||||
|
||||
String requestURL = "http://localhost:" + ourPort + "/Patient/1";
|
||||
HttpGet httpGet = new HttpGet(requestURL);
|
||||
httpGet.addHeader(UserInfoInterceptor.HEADER_USER_ID, "hapi-fhir-junit-user");
|
||||
httpGet.addHeader(UserInfoInterceptor.HEADER_USER_NAME, "HAPI FHIR Junit Test Cases");
|
||||
httpGet.addHeader(UserInfoInterceptor.HEADER_APPLICATION_NAME, "hapi-fhir-junit");
|
||||
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
ArgumentCaptor<SecurityEvent> captor = ArgumentCaptor.forClass(SecurityEvent.class);
|
||||
|
||||
verify(mockDataStore, times(1)).store(captor.capture());
|
||||
|
||||
SecurityEvent auditEvent = captor.getValue();
|
||||
assertEquals(SecurityEventOutcomeEnum.SUCCESS.getCode(), auditEvent.getEvent().getOutcome().getValue());
|
||||
assertEquals("HAPI FHIR Junit Test Cases", auditEvent.getParticipantFirstRep().getName().getValue());
|
||||
assertEquals("hapi-fhir-junit-user", auditEvent.getParticipantFirstRep().getUserId().getValue());
|
||||
assertEquals("hapi-fhir-junit", auditEvent.getSource().getIdentifier().getValue());
|
||||
assertEquals("HAPITEST", auditEvent.getSource().getSite().getValue());
|
||||
assertEquals(SecurityEventSourceTypeEnum.USER_DEVICE.getCode(), auditEvent.getSource().getTypeFirstRep().getCode().getValue());
|
||||
|
||||
List<ObjectElement> objects = auditEvent.getObject();
|
||||
assertEquals(1, objects.size());
|
||||
ObjectElement object = objects.get(0);
|
||||
assertEquals("00001", object.getIdentifier().getValue().getValue());
|
||||
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(Base64.decodeBase64(object.getQuery().getValueAsString())));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() throws Exception {
|
||||
ourServer.stop();
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
ourPort = PortUtil.findFreePort();
|
||||
ourServer = new Server(ourPort);
|
||||
|
||||
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
||||
|
||||
ServletHandler proxyHandler = new ServletHandler();
|
||||
servlet = new RestfulServer(ourCtx);
|
||||
servlet.setResourceProviders(patientProvider);
|
||||
ServletHolder servletHolder = new ServletHolder(servlet);
|
||||
proxyHandler.addServletWithMapping(servletHolder, "/*");
|
||||
ourServer.setHandler(proxyHandler);
|
||||
ourServer.start();
|
||||
|
||||
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
||||
HttpClientBuilder builder = HttpClientBuilder.create();
|
||||
builder.setConnectionManager(connectionManager);
|
||||
ourClient = builder.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class DummyPatientResourceProvider implements IResourceProvider {
|
||||
|
||||
private Patient createPatient1() {
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier();
|
||||
patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
|
||||
patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
|
||||
patient.getIdentifier().get(0).setValue("00001");
|
||||
patient.addName();
|
||||
patient.getName().get(0).addFamily("Test");
|
||||
patient.getName().get(0).addGiven("PatientOne");
|
||||
patient.getGender().setText("M");
|
||||
patient.getId().setValue("1");
|
||||
return patient;
|
||||
}
|
||||
|
||||
public Map<String, Patient> getIdToPatient() {
|
||||
Map<String, Patient> idToPatient = new HashMap<String, Patient>();
|
||||
{
|
||||
Patient patient = createPatient1();
|
||||
idToPatient.put("1", patient);
|
||||
}
|
||||
{
|
||||
Patient patient = new Patient();
|
||||
patient.getIdentifier().add(new IdentifierDt());
|
||||
patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL);
|
||||
patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns"));
|
||||
patient.getIdentifier().get(0).setValue("00002");
|
||||
HumanNameDt name = new HumanNameDt();
|
||||
name.addPrefix("Ms");
|
||||
name.addGiven("Laura");
|
||||
name.addGiven("Elizabeth");
|
||||
name.addFamily("MacDougall");
|
||||
name.addFamily("Sookraj");
|
||||
name.addSuffix("B.Sc.");
|
||||
patient.getName().add(name);
|
||||
patient.getGender().setText("F");
|
||||
patient.getId().setValue("2");
|
||||
idToPatient.put("2", patient);
|
||||
}
|
||||
return idToPatient;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the resource by its identifier
|
||||
*
|
||||
* @param theId
|
||||
* The resource identity
|
||||
* @return The resource
|
||||
*/
|
||||
@Read()
|
||||
public Patient getResourceById(@IdParam IdDt theId) {
|
||||
String key = theId.getIdPart();
|
||||
Patient retVal = getIdToPatient().get(key);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the resource by its identifier
|
||||
*
|
||||
* @param theId
|
||||
* The resource identity
|
||||
* @return The resource
|
||||
*/
|
||||
@Search()
|
||||
public List<Patient> getResourceById(@RequiredParam(name = "_id") TokenOrListParam theIds) {
|
||||
List<Patient> patients = new ArrayList<Patient>();
|
||||
for(BaseCodingDt id: theIds.getListAsCodings()){
|
||||
Patient patient = getIdToPatient().get(id.getCodeElement().getValue());
|
||||
if (patient != null) {
|
||||
patients.add(patient);
|
||||
}
|
||||
}
|
||||
return patients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Patient> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class MockDataStore implements IAuditDataStore {
|
||||
|
||||
@Override
|
||||
public void store(BaseSecurityEvent auditEvent) throws Exception {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -5,11 +5,7 @@ import java.util.List;
|
|||
import org.hl7.fhir.dstu2016may.validation.ValidationMessage;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.validation.IValidationContext;
|
||||
import ca.uhn.fhir.validation.IValidatorModule;
|
||||
import ca.uhn.fhir.validation.ResultSeverityEnum;
|
||||
import ca.uhn.fhir.validation.SingleValidationMessage;
|
||||
import ca.uhn.fhir.validation.*;
|
||||
|
||||
/**
|
||||
* Base class for a bridge between the RI validation tools and HAPI
|
||||
|
@ -42,11 +38,6 @@ abstract class BaseValidatorBridge implements IValidatorModule {
|
|||
|
||||
protected abstract List<ValidationMessage> validate(IValidationContext<?> theCtx);
|
||||
|
||||
@Override
|
||||
public void validateBundle(IValidationContext<Bundle> theCtx) {
|
||||
doValidate(theCtx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateResource(IValidationContext<IBaseResource> theCtx) {
|
||||
doValidate(theCtx);
|
||||
|
|
|
@ -2,13 +2,7 @@ package ca.uhn.fhir.rest.client;
|
|||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
@ -40,7 +34,6 @@ import com.phloc.commons.io.streams.StringInputStream;
|
|||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.parser.CustomTypeDstu2_1Test;
|
||||
import ca.uhn.fhir.parser.CustomTypeDstu2_1Test.MyCustomPatient;
|
||||
|
@ -364,24 +357,24 @@ public class GenericClientDstu2_1Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.setEncoding(EncodingEnum.JSON);
|
||||
client.search()
|
||||
.forResource("Device")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Device?_format=json", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
assertEquals(Constants.CT_FHIR_JSON, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_ACCEPT).getValue());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.setEncoding(EncodingEnum.XML);
|
||||
client.search()
|
||||
.forResource("Device")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Device?_format=xml", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
assertEquals(Constants.CT_FHIR_XML, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_ACCEPT).getValue());
|
||||
idx++;
|
||||
|
@ -519,13 +512,13 @@ public class GenericClientDstu2_1Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
client.registerInterceptor(new CookieInterceptor("foo=bar"));
|
||||
|
||||
//@formatter:off
|
||||
|
||||
Bundle resp = client
|
||||
.history()
|
||||
.onType(Patient.class)
|
||||
.andReturnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
|
||||
assertEquals("foo=bar", capt.getAllValues().get(0).getFirstHeader("Cookie").getValue());
|
||||
}
|
||||
|
@ -640,13 +633,13 @@ public class GenericClientDstu2_1Test {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
|
||||
Bundle resp = client
|
||||
.history()
|
||||
.onType(CustomTypeDstu2_1Test.MyCustomPatient.class)
|
||||
.andReturnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
|
||||
assertEquals(1, resp.getEntry().size());
|
||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||
|
@ -671,25 +664,25 @@ public class GenericClientDstu2_1Test {
|
|||
Bundle bundle = new Bundle();
|
||||
bundle.addLink().setRelation("next").setUrl("http://foo/next");
|
||||
|
||||
//@formatter:off
|
||||
|
||||
Bundle resp = client
|
||||
.loadPage()
|
||||
.next(bundle)
|
||||
.preferResponseType(MyCustomPatient.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
|
||||
assertEquals(1, resp.getEntry().size());
|
||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||
assertEquals("http://foo/next", capt.getAllValues().get(0).getURI().toASCIIString());
|
||||
|
||||
//@formatter:off
|
||||
|
||||
resp = client
|
||||
.loadPage()
|
||||
.next(bundle)
|
||||
.preferResponseTypes(toTypeList(MyCustomPatient.class))
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
|
||||
assertEquals(1, resp.getEntry().size());
|
||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||
|
@ -718,7 +711,7 @@ public class GenericClientDstu2_1Test {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
|
||||
Parameters resp = client
|
||||
.operation()
|
||||
.onServer()
|
||||
|
@ -726,20 +719,20 @@ public class GenericClientDstu2_1Test {
|
|||
.withNoParameters(Parameters.class)
|
||||
.preferResponseType(MyCustomPatient.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
|
||||
assertEquals(1, resp.getParameter().size());
|
||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getParameter().get(0).getResource().getClass());
|
||||
assertEquals("http://example.com/fhir/$foo", capt.getAllValues().get(0).getURI().toASCIIString());
|
||||
|
||||
//@formatter:off
|
||||
|
||||
resp = client
|
||||
.operation()
|
||||
.onType(MyCustomPatient.class)
|
||||
.named("foo")
|
||||
.withNoParameters(Parameters.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
|
||||
assertEquals(1, resp.getParameter().size());
|
||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getParameter().get(0).getResource().getClass());
|
||||
|
@ -762,13 +755,13 @@ public class GenericClientDstu2_1Test {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
|
||||
Bundle resp = client
|
||||
.search()
|
||||
.forResource(CustomTypeDstu2_1Test.MyCustomPatient.class)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
|
||||
assertEquals(1, resp.getEntry().size());
|
||||
assertEquals(CustomTypeDstu2_1Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||
|
@ -995,7 +988,7 @@ public class GenericClientDstu2_1Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
|
@ -1005,31 +998,31 @@ public class GenericClientDstu2_1Test {
|
|||
.and(Patient.ORGANIZATION.hasId((String)null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client
|
||||
.search()
|
||||
.forResource(Encounter.class)
|
||||
.where(Encounter.LENGTH.exactly().number(null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
|
||||
assertEquals("http://example.com/fhir/Encounter", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client
|
||||
.search()
|
||||
.forResource(Observation.class)
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number(null).andUnits(null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
@ -1065,7 +1058,7 @@ public class GenericClientDstu2_1Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client
|
||||
.update()
|
||||
.resource(bundle)
|
||||
|
@ -1109,7 +1102,7 @@ public class GenericClientDstu2_1Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client
|
||||
.update()
|
||||
.resource(bundle)
|
||||
|
@ -1226,93 +1219,93 @@ public class GenericClientDstu2_1Test {
|
|||
DateTimeDt now = DateTimeDt.withCurrentTime();
|
||||
String dateString = now.getValueAsString().substring(0, 10);
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt"+dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().day(now.getValue()))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt"+dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.afterOrEquals().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=ge"+dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.before().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=lt"+dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.beforeOrEquals().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=le"+dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.exactly().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate="+dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().second("2011-01-02T22:33:01Z"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt2011-01-02T22:33:01Z", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().second(now.getValueAsString()))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + now.getValueAsString(), UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().now())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertThat(capt.getAllValues().get(idx).getURI().toString(), startsWith("http://example.com/fhir/Patient?birthdate=gt2"));
|
||||
dateString = UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()).substring(44);
|
||||
ourLog.info(dateString);
|
||||
|
@ -1339,123 +1332,113 @@ public class GenericClientDstu2_1Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.approximately().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123||CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("SYSTEM", "CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123|SYSTEM|CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=123||CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("SYSTEM", "CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=123|SYSTEM|CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.greaterThan().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=gt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.lessThan().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=lt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.greaterThanOrEquals().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ge123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.lessThanOrEquals().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=le123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.withComparator(QuantityCompararatorEnum.GREATERTHAN).number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=gt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.withPrefix(ParamPrefixEnum.GREATERTHAN).number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=gt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
|
@ -1479,83 +1462,83 @@ public class GenericClientDstu2_1Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("AAA"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value(new StringDt("AAA")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().values("AAA", "BBB"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().values(Arrays.asList("AAA", "BBB")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().value("AAA"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name%3Aexact=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().value(new StringDt("AAA")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name%3Aexact=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().values("AAA", "BBB"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name:exact=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().values(Arrays.asList("AAA", "BBB")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name:exact=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
|
@ -1579,24 +1562,24 @@ public class GenericClientDstu2_1Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Device")
|
||||
.where(Device.URL.matches().value("http://foo.com"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Device?url=http://foo.com", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
assertEquals("http://example.com/fhir/Device?url=http%3A%2F%2Ffoo.com", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Device")
|
||||
.where(Device.URL.matches().value(new StringDt("http://foo.com")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Device?url=http://foo.com", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
|
@ -1622,13 +1605,13 @@ public class GenericClientDstu2_1Test {
|
|||
|
||||
Collection<String> values = Arrays.asList("VAL1", "VAL2", "VAL3A,B");
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.IDENTIFIER.exactly().systemAndValues("SYS", values))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?identifier=SYS%7CVAL1%2CSYS%7CVAL2%2CSYS%7CVAL3A%5C%2CB", capt.getAllValues().get(idx).getURI().toString());
|
||||
assertEquals("http://example.com/fhir/Patient?identifier=SYS|VAL1,SYS|VAL2,SYS|VAL3A\\,B", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
@ -1660,7 +1643,7 @@ public class GenericClientDstu2_1Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
|
||||
client
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
|
@ -1686,7 +1669,7 @@ public class GenericClientDstu2_1Test {
|
|||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
assertEquals("http://example.com/fhir/Patient?_sort=-address%2Cname%2C-birthdate", capt.getAllValues().get(idx++).getURI().toASCIIString());
|
||||
//@formatter:on
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1940,13 +1923,13 @@ public class GenericClientDstu2_1Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
client.registerInterceptor(new UserInfoInterceptor("user_id", "user_name", "app-name"));
|
||||
|
||||
//@formatter:off
|
||||
|
||||
Bundle resp = client
|
||||
.history()
|
||||
.onType(Patient.class)
|
||||
.andReturnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package ca.uhn.fhir.rest.param;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -11,7 +10,6 @@ import java.util.TimeZone;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
|
||||
|
@ -28,10 +26,6 @@ public class DateParamTest {
|
|||
new DateParam(ParamPrefixEnum.GREATERTHAN, InstantDt.withCurrentTime());
|
||||
new DateParam(ParamPrefixEnum.GREATERTHAN, "2011-01-02");
|
||||
|
||||
new DateParam(QuantityCompararatorEnum.GREATERTHAN, new Date());
|
||||
new DateParam(QuantityCompararatorEnum.GREATERTHAN, new DateTimeDt("2011-01-02"));
|
||||
new DateParam(QuantityCompararatorEnum.GREATERTHAN, InstantDt.withCurrentTime());
|
||||
new DateParam(QuantityCompararatorEnum.GREATERTHAN, "2011-01-02");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -2,13 +2,7 @@ package ca.uhn.fhir.rest.client;
|
|||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
@ -40,7 +34,6 @@ import com.phloc.commons.io.streams.StringInputStream;
|
|||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.parser.CustomTypeDstu3Test;
|
||||
import ca.uhn.fhir.parser.CustomTypeDstu3Test.MyCustomPatient;
|
||||
|
@ -121,7 +114,8 @@ public class GenericClientDstu3Test {
|
|||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/EpisodeOfCare?patient=123&_revinclude=Encounter%3Aepisodeofcare&_revinclude%3Arecurse=Observation%3Aencounter", capt.getAllValues().get(idx).getURI().toString());
|
||||
assertEquals("http://example.com/fhir/EpisodeOfCare?patient=123&_revinclude=Encounter%3Aepisodeofcare&_revinclude%3Arecurse=Observation%3Aencounter",
|
||||
capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
}
|
||||
|
@ -163,8 +157,6 @@ public class GenericClientDstu3Test {
|
|||
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
|
||||
assertThat(oo.getText().getDivAsString(), containsString("OK!"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testPatchJsonByIdType() throws Exception {
|
||||
|
@ -391,24 +383,22 @@ public class GenericClientDstu3Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
client.setEncoding(EncodingEnum.JSON);
|
||||
client.search()
|
||||
.forResource("Device")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Device")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Device?_format=json", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
assertEquals("application/fhir+json;q=1.0, application/json+fhir;q=0.9", capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_ACCEPT).getValue());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.setEncoding(EncodingEnum.XML);
|
||||
client.search()
|
||||
.forResource("Device")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Device")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Device?_format=xml", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
assertEquals("application/fhir+xml;q=1.0, application/xml+fhir;q=0.9", capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_ACCEPT).getValue());
|
||||
idx++;
|
||||
|
@ -544,13 +534,11 @@ public class GenericClientDstu3Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
client.registerInterceptor(new CookieInterceptor("foo=bar"));
|
||||
|
||||
//@formatter:off
|
||||
Bundle resp = client
|
||||
.history()
|
||||
.onType(Patient.class)
|
||||
.andReturnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.history()
|
||||
.onType(Patient.class)
|
||||
.andReturnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("foo=bar", capt.getAllValues().get(0).getFirstHeader("Cookie").getValue());
|
||||
}
|
||||
|
@ -665,13 +653,11 @@ public class GenericClientDstu3Test {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
Bundle resp = client
|
||||
.history()
|
||||
.onType(CustomTypeDstu3Test.MyCustomPatient.class)
|
||||
.andReturnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.history()
|
||||
.onType(CustomTypeDstu3Test.MyCustomPatient.class)
|
||||
.andReturnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals(1, resp.getEntry().size());
|
||||
assertEquals(CustomTypeDstu3Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||
|
@ -696,25 +682,21 @@ public class GenericClientDstu3Test {
|
|||
Bundle bundle = new Bundle();
|
||||
bundle.addLink().setRelation("next").setUrl("http://foo/next");
|
||||
|
||||
//@formatter:off
|
||||
Bundle resp = client
|
||||
.loadPage()
|
||||
.next(bundle)
|
||||
.preferResponseType(MyCustomPatient.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.loadPage()
|
||||
.next(bundle)
|
||||
.preferResponseType(MyCustomPatient.class)
|
||||
.execute();
|
||||
|
||||
assertEquals(1, resp.getEntry().size());
|
||||
assertEquals(CustomTypeDstu3Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||
assertEquals("http://foo/next", capt.getAllValues().get(0).getURI().toASCIIString());
|
||||
|
||||
//@formatter:off
|
||||
resp = client
|
||||
.loadPage()
|
||||
.next(bundle)
|
||||
.preferResponseTypes(toTypeList(MyCustomPatient.class))
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.loadPage()
|
||||
.next(bundle)
|
||||
.preferResponseTypes(toTypeList(MyCustomPatient.class))
|
||||
.execute();
|
||||
|
||||
assertEquals(1, resp.getEntry().size());
|
||||
assertEquals(CustomTypeDstu3Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||
|
@ -743,28 +725,24 @@ public class GenericClientDstu3Test {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
Parameters resp = client
|
||||
.operation()
|
||||
.onServer()
|
||||
.named("foo")
|
||||
.withNoParameters(Parameters.class)
|
||||
.preferResponseType(MyCustomPatient.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.operation()
|
||||
.onServer()
|
||||
.named("foo")
|
||||
.withNoParameters(Parameters.class)
|
||||
.preferResponseType(MyCustomPatient.class)
|
||||
.execute();
|
||||
|
||||
assertEquals(1, resp.getParameter().size());
|
||||
assertEquals(CustomTypeDstu3Test.MyCustomPatient.class, resp.getParameter().get(0).getResource().getClass());
|
||||
assertEquals("http://example.com/fhir/$foo", capt.getAllValues().get(0).getURI().toASCIIString());
|
||||
|
||||
//@formatter:off
|
||||
resp = client
|
||||
.operation()
|
||||
.onType(MyCustomPatient.class)
|
||||
.named("foo")
|
||||
.withNoParameters(Parameters.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.operation()
|
||||
.onType(MyCustomPatient.class)
|
||||
.named("foo")
|
||||
.withNoParameters(Parameters.class)
|
||||
.execute();
|
||||
|
||||
assertEquals(1, resp.getParameter().size());
|
||||
assertEquals(CustomTypeDstu3Test.MyCustomPatient.class, resp.getParameter().get(0).getResource().getClass());
|
||||
|
@ -787,13 +765,11 @@ public class GenericClientDstu3Test {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
Bundle resp = client
|
||||
.search()
|
||||
.forResource(CustomTypeDstu3Test.MyCustomPatient.class)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.search()
|
||||
.forResource(CustomTypeDstu3Test.MyCustomPatient.class)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals(1, resp.getEntry().size());
|
||||
assertEquals(CustomTypeDstu3Test.MyCustomPatient.class, resp.getEntry().get(0).getResource().getClass());
|
||||
|
@ -969,41 +945,35 @@ public class GenericClientDstu3Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
client
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.where(Patient.FAMILY.matches().value((String)null))
|
||||
.and(Patient.BIRTHDATE.exactly().day((Date)null))
|
||||
.and(Patient.GENDER.exactly().code((String)null))
|
||||
.and(Patient.ORGANIZATION.hasId((String)null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
client
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.where(Patient.FAMILY.matches().value((String) null))
|
||||
.and(Patient.BIRTHDATE.exactly().day((Date) null))
|
||||
.and(Patient.GENDER.exactly().code((String) null))
|
||||
.and(Patient.ORGANIZATION.hasId((String) null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client
|
||||
.search()
|
||||
.forResource(Encounter.class)
|
||||
.where(Encounter.LENGTH.exactly().number(null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
client
|
||||
.search()
|
||||
.forResource(Encounter.class)
|
||||
.where(Encounter.LENGTH.exactly().number(null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Encounter", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client
|
||||
.search()
|
||||
.forResource(Observation.class)
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number(null).andUnits(null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
client
|
||||
.search()
|
||||
.forResource(Observation.class)
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number(null).andUnits(null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
@ -1039,36 +1009,37 @@ public class GenericClientDstu3Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
client
|
||||
.update()
|
||||
.resource(bundle)
|
||||
.prefer(PreferReturnEnum.REPRESENTATION)
|
||||
.encodedJson()
|
||||
.execute();
|
||||
|
||||
.update()
|
||||
.resource(bundle)
|
||||
.prefer(PreferReturnEnum.REPRESENTATION)
|
||||
.encodedJson()
|
||||
.execute();
|
||||
|
||||
HttpPut httpRequest = (HttpPut) capt.getValue();
|
||||
assertEquals("http://example.com/fhir/Bundle/BUNDLE1", httpRequest.getURI().toASCIIString());
|
||||
|
||||
|
||||
String requestString = IOUtils.toString(httpRequest.getEntity().getContent(), StandardCharsets.UTF_8);
|
||||
assertEquals(encoded, requestString);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPutDoesntForceAllIdsXml() throws Exception {
|
||||
IParser p = ourCtx.newXmlParser();
|
||||
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.setId("PATIENT1");
|
||||
patient.addName().setFamily("PATIENT1");
|
||||
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.setId("BUNDLE1");
|
||||
bundle.addEntry().setResource(patient);
|
||||
|
||||
|
||||
final String encoded = p.encodeResourceToString(bundle);
|
||||
assertEquals("<Bundle xmlns=\"http://hl7.org/fhir\"><id value=\"BUNDLE1\"/><entry><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"PATIENT1\"/><name><family value=\"PATIENT1\"/></name></Patient></resource></entry></Bundle>", encoded);
|
||||
|
||||
assertEquals(
|
||||
"<Bundle xmlns=\"http://hl7.org/fhir\"><id value=\"BUNDLE1\"/><entry><resource><Patient xmlns=\"http://hl7.org/fhir\"><id value=\"PATIENT1\"/><name><family value=\"PATIENT1\"/></name></Patient></resource></entry></Bundle>",
|
||||
encoded);
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
|
@ -1083,16 +1054,15 @@ public class GenericClientDstu3Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
client
|
||||
.update()
|
||||
.resource(bundle)
|
||||
.prefer(PreferReturnEnum.REPRESENTATION)
|
||||
.execute();
|
||||
|
||||
.update()
|
||||
.resource(bundle)
|
||||
.prefer(PreferReturnEnum.REPRESENTATION)
|
||||
.execute();
|
||||
|
||||
HttpPut httpRequest = (HttpPut) capt.getValue();
|
||||
assertEquals("http://example.com/fhir/Bundle/BUNDLE1", httpRequest.getURI().toASCIIString());
|
||||
|
||||
|
||||
String requestString = IOUtils.toString(httpRequest.getEntity().getContent(), StandardCharsets.UTF_8);
|
||||
assertEquals(encoded, requestString);
|
||||
}
|
||||
|
@ -1113,7 +1083,9 @@ public class GenericClientDstu3Test {
|
|||
client.read().resource("Patient").withId("123").elementsSubset("name", "identifier").execute();
|
||||
fail();
|
||||
} catch (FhirClientConnectionException e) {
|
||||
assertEquals("Failed to parse response from server when performing GET to URL http://example.com/fhir/Patient/123?_elements=identifier%2Cname - ca.uhn.fhir.parser.DataFormatException: Invalid JSON content detected, missing required element: 'resourceType'", e.getMessage());
|
||||
assertEquals(
|
||||
"Failed to parse response from server when performing GET to URL http://example.com/fhir/Patient/123?_elements=identifier%2Cname - ca.uhn.fhir.parser.DataFormatException: Invalid JSON content detected, missing required element: 'resourceType'",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1127,7 +1099,7 @@ public class GenericClientDstu3Test {
|
|||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
// when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||
// when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||
when(myHttpResponse.getEntity().getContentType()).thenReturn(null);
|
||||
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
||||
@Override
|
||||
|
@ -1144,8 +1116,8 @@ public class GenericClientDstu3Test {
|
|||
assertEquals("Response contains no Content-Type", e.getMessage());
|
||||
}
|
||||
|
||||
// Patient resp = client.read().resource(Patient.class).withId("1").execute();
|
||||
// assertEquals("FAM", resp.getNameFirstRep().getFamilyAsSingleString());
|
||||
// Patient resp = client.read().resource(Patient.class).withId("1").execute();
|
||||
// assertEquals("FAM", resp.getNameFirstRep().getFamilyAsSingleString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1159,7 +1131,7 @@ public class GenericClientDstu3Test {
|
|||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", "text/plain"));
|
||||
// when(myHttpResponse.getEntity().getContentType()).thenReturn(null);
|
||||
// when(myHttpResponse.getEntity().getContentType()).thenReturn(null);
|
||||
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
|
||||
@Override
|
||||
public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
||||
|
@ -1175,12 +1147,12 @@ public class GenericClientDstu3Test {
|
|||
assertEquals("Response contains non FHIR Content-Type 'text/plain' : <Patient xmlns=\"http://hl7.org/fhir\"><name><family value=\"FAM\"/></name></Patient>", e.getMessage());
|
||||
}
|
||||
|
||||
// Patient resp = client.read().resource(Patient.class).withId("1").execute();
|
||||
// assertEquals("FAM", resp.getNameFirstRep().getFamilyAsSingleString());
|
||||
// Patient resp = client.read().resource(Patient.class).withId("1").execute();
|
||||
// assertEquals("FAM", resp.getNameFirstRep().getFamilyAsSingleString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithNullParameters() throws Exception {
|
||||
public void testSearchWithNullParameters() throws Exception {
|
||||
final String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
|
@ -1201,16 +1173,16 @@ public class GenericClientDstu3Test {
|
|||
String dateString = now.getValueAsString().substring(0, 10);
|
||||
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value((String)null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value((String) null))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchByDate() throws Exception {
|
||||
public void testSearchByDate() throws Exception {
|
||||
final String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
|
@ -1230,93 +1202,84 @@ public class GenericClientDstu3Test {
|
|||
DateTimeDt now = DateTimeDt.withCurrentTime();
|
||||
String dateString = now.getValueAsString().substring(0, 10);
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().day(now.getValue()))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().day(now.getValue()))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.afterOrEquals().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.afterOrEquals().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=ge" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.before().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.before().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=lt" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.beforeOrEquals().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.beforeOrEquals().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=le" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.exactly().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.exactly().day(dateString))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=" + dateString, capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().second("2011-01-02T22:33:01Z"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().second("2011-01-02T22:33:01Z"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt2011-01-02T22:33:01Z", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().second(now.getValueAsString()))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().second(now.getValueAsString()))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + now.getValueAsString(), UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().now())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.BIRTHDATE.after().now())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertThat(capt.getAllValues().get(idx).getURI().toString(), startsWith("http://example.com/fhir/Patient?birthdate=gt2"));
|
||||
dateString = UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()).substring(44);
|
||||
ourLog.info(dateString);
|
||||
|
@ -1343,123 +1306,102 @@ public class GenericClientDstu3Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.approximately().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.approximately().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123||CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("SYSTEM", "CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.approximately().number("123").andUnits("SYSTEM", "CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ap123|SYSTEM|CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=123||CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("SYSTEM", "CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.exactly().number("123").andUnits("SYSTEM", "CODE"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=123|SYSTEM|CODE", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.greaterThan().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.greaterThan().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=gt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.lessThan().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.lessThan().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=lt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.greaterThanOrEquals().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.greaterThanOrEquals().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=ge123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.lessThanOrEquals().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.lessThanOrEquals().number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=le123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.withComparator(QuantityCompararatorEnum.GREATERTHAN).number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=gt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.withPrefix(ParamPrefixEnum.GREATERTHAN).number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Observation")
|
||||
.where(Observation.VALUE_QUANTITY.withPrefix(ParamPrefixEnum.GREATERTHAN).number(123).andNoUnits())
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
assertEquals("http://example.com/fhir/Observation?value-quantity=gt123||", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
|
@ -1483,83 +1425,75 @@ public class GenericClientDstu3Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("AAA"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value("AAA"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value(new StringDt("AAA")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().value(new StringDt("AAA")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().values("AAA", "BBB"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().values("AAA", "BBB"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().values(Arrays.asList("AAA", "BBB")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matches().values(Arrays.asList("AAA", "BBB")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().value("AAA"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().value("AAA"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name%3Aexact=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().value(new StringDt("AAA")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().value(new StringDt("AAA")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name%3Aexact=AAA", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().values("AAA", "BBB"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().values("AAA", "BBB"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name:exact=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().values(Arrays.asList("AAA", "BBB")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.matchesExactly().values(Arrays.asList("AAA", "BBB")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?name:exact=AAA,BBB", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
|
@ -1583,24 +1517,22 @@ public class GenericClientDstu3Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Device")
|
||||
.where(Device.URL.matches().value("http://foo.com"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Device")
|
||||
.where(Device.URL.matches().value("http://foo.com"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Device?url=http://foo.com", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
assertEquals("http://example.com/fhir/Device?url=http%3A%2F%2Ffoo.com", capt.getAllValues().get(idx).getURI().toString());
|
||||
idx++;
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Device")
|
||||
.where(Device.URL.matches().value(new StringDt("http://foo.com")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Device")
|
||||
.where(Device.URL.matches().value(new StringDt("http://foo.com")))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Device?url=http://foo.com", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
||||
|
@ -1626,13 +1558,12 @@ public class GenericClientDstu3Test {
|
|||
|
||||
Collection<String> values = Arrays.asList("VAL1", "VAL2", "VAL3A,B");
|
||||
|
||||
//@formatter:off
|
||||
client.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.IDENTIFIER.exactly().systemAndValues("SYS", values))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.forResource("Patient")
|
||||
.where(Patient.IDENTIFIER.exactly().systemAndValues("SYS", values))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?identifier=SYS%7CVAL1%2CSYS%7CVAL2%2CSYS%7CVAL3A%5C%2CB", capt.getAllValues().get(idx).getURI().toString());
|
||||
assertEquals("http://example.com/fhir/Patient?identifier=SYS|VAL1,SYS|VAL2,SYS|VAL3A\\,B", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
|
||||
idx++;
|
||||
|
@ -1664,33 +1595,32 @@ public class GenericClientDstu3Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
int idx = 0;
|
||||
|
||||
//@formatter:off
|
||||
client
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.sort().ascending("address")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.sort().ascending("address")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
assertEquals("http://example.com/fhir/Patient?_sort=address", capt.getAllValues().get(idx++).getURI().toASCIIString());
|
||||
|
||||
client
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.sort().descending("address")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
client
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.sort().descending("address")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
assertEquals("http://example.com/fhir/Patient?_sort=-address", capt.getAllValues().get(idx++).getURI().toASCIIString());
|
||||
|
||||
client
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.sort().descending("address")
|
||||
.sort().ascending("name")
|
||||
.sort().descending(Patient.BIRTHDATE)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
client
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.sort().descending("address")
|
||||
.sort().ascending("name")
|
||||
.sort().descending(Patient.BIRTHDATE)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
assertEquals("http://example.com/fhir/Patient?_sort=-address%2Cname%2C-birthdate", capt.getAllValues().get(idx++).getURI().toASCIIString());
|
||||
//@formatter:on
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1943,13 +1873,11 @@ public class GenericClientDstu3Test {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
client.registerInterceptor(new UserInfoInterceptor("user_id", "user_name", "app-name"));
|
||||
|
||||
//@formatter:off
|
||||
Bundle resp = client
|
||||
.history()
|
||||
.onType(Patient.class)
|
||||
.andReturnBundle(Bundle.class)
|
||||
.execute();
|
||||
//@formatter:on
|
||||
.history()
|
||||
.onType(Patient.class)
|
||||
.andReturnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.junit.Test;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.primitive.DateTimeDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.rest.api.QualifiedParamList;
|
||||
|
@ -114,23 +113,23 @@ public class DateRangeParamTest {
|
|||
public void testRange() {
|
||||
InstantDt start = new InstantDt("2015-09-23T07:43:34.811-04:00");
|
||||
InstantDt end = new InstantDt("2015-09-23T07:43:34.899-04:00");
|
||||
DateParam lowerBound = new DateParam(QuantityCompararatorEnum.GREATERTHAN, start.getValue());
|
||||
DateParam upperBound = new DateParam(QuantityCompararatorEnum.LESSTHAN, end.getValue());
|
||||
assertEquals(QuantityCompararatorEnum.GREATERTHAN, lowerBound.getComparator());
|
||||
assertEquals(QuantityCompararatorEnum.LESSTHAN, upperBound.getComparator());
|
||||
DateParam lowerBound = new DateParam(ParamPrefixEnum.GREATERTHAN, start.getValue());
|
||||
DateParam upperBound = new DateParam(ParamPrefixEnum.LESSTHAN, end.getValue());
|
||||
assertEquals(ParamPrefixEnum.GREATERTHAN, lowerBound.getPrefix());
|
||||
assertEquals(ParamPrefixEnum.LESSTHAN, upperBound.getPrefix());
|
||||
|
||||
/*
|
||||
* When DateParam (which extends DateTimeDt) gets passed in, make sure we preserve the comparators..
|
||||
*/
|
||||
DateRangeParam param = new DateRangeParam(lowerBound, upperBound);
|
||||
ourLog.info(param.toString());
|
||||
assertEquals(QuantityCompararatorEnum.GREATERTHAN, param.getLowerBound().getComparator());
|
||||
assertEquals(QuantityCompararatorEnum.LESSTHAN, param.getUpperBound().getComparator());
|
||||
assertEquals(ParamPrefixEnum.GREATERTHAN, param.getLowerBound().getPrefix());
|
||||
assertEquals(ParamPrefixEnum.LESSTHAN, param.getUpperBound().getPrefix());
|
||||
|
||||
param = new DateRangeParam(new DateTimeDt(lowerBound.getValue()), new DateTimeDt(upperBound.getValue()));
|
||||
ourLog.info(param.toString());
|
||||
assertEquals(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, param.getLowerBound().getComparator());
|
||||
assertEquals(QuantityCompararatorEnum.LESSTHAN_OR_EQUALS, param.getUpperBound().getComparator());
|
||||
assertEquals(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, param.getLowerBound().getPrefix());
|
||||
assertEquals(ParamPrefixEnum.LESSTHAN_OR_EQUALS, param.getUpperBound().getPrefix());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ public class NumberParamTest {
|
|||
public void testApproximateLegacy() {
|
||||
NumberParam p = new NumberParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "~5.4");
|
||||
assertEquals(null,p.getComparator());
|
||||
assertEquals(ParamPrefixEnum.APPROXIMATE, p.getPrefix());
|
||||
assertEquals("5.4", p.getValue().toPlainString());
|
||||
assertEquals("ap5.4", p.getValueAsQueryToken(ourCtx));
|
||||
|
@ -36,7 +35,6 @@ public class NumberParamTest {
|
|||
public void testApproximate() {
|
||||
NumberParam p = new NumberParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "ap5.4");
|
||||
assertEquals(null,p.getComparator());
|
||||
assertEquals(ParamPrefixEnum.APPROXIMATE, p.getPrefix());
|
||||
assertEquals("5.4", p.getValue().toPlainString());
|
||||
assertEquals("ap5.4", p.getValueAsQueryToken(ourCtx));
|
||||
|
@ -46,7 +44,6 @@ public class NumberParamTest {
|
|||
public void testNoQualifier() {
|
||||
NumberParam p = new NumberParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "5.4");
|
||||
assertEquals(null, p.getComparator());
|
||||
assertEquals(null, p.getPrefix());
|
||||
assertEquals("5.4", p.getValue().toPlainString());
|
||||
assertEquals("5.4", p.getValueAsQueryToken(ourCtx));
|
||||
|
@ -60,7 +57,6 @@ public class NumberParamTest {
|
|||
public void testNegativeNumber() {
|
||||
NumberParam p = new NumberParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "-5.4");
|
||||
assertEquals(null, p.getComparator());
|
||||
assertEquals(null, p.getPrefix());
|
||||
assertEquals("-5.4", p.getValue().toPlainString());
|
||||
assertEquals(new BigDecimal("-5.4"), p.getValue());
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.uhn.fhir.rest.param;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
@ -8,7 +8,6 @@ import org.junit.AfterClass;
|
|||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class QuantityParamTest {
|
||||
|
@ -18,7 +17,6 @@ public class QuantityParamTest {
|
|||
public void testFull() {
|
||||
QuantityParam p = new QuantityParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "<5.4|http://unitsofmeasure.org|mg");
|
||||
assertEquals(QuantityCompararatorEnum.LESSTHAN,p.getComparator());
|
||||
assertEquals(ParamPrefixEnum.LESSTHAN, p.getPrefix());
|
||||
assertEquals("5.4", p.getValue().toPlainString());
|
||||
assertEquals("http://unitsofmeasure.org", p.getSystem());
|
||||
|
@ -30,9 +28,7 @@ public class QuantityParamTest {
|
|||
public void testApproximateLegacy() {
|
||||
QuantityParam p = new QuantityParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "~5.4|http://unitsofmeasure.org|mg");
|
||||
assertEquals(null,p.getComparator());
|
||||
assertEquals(ParamPrefixEnum.APPROXIMATE, p.getPrefix());
|
||||
assertEquals(true, p.isApproximate());
|
||||
assertEquals("5.4", p.getValue().toPlainString());
|
||||
assertEquals("http://unitsofmeasure.org", p.getSystem());
|
||||
assertEquals("mg", p.getUnits());
|
||||
|
@ -43,9 +39,7 @@ public class QuantityParamTest {
|
|||
public void testApproximate() {
|
||||
QuantityParam p = new QuantityParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "ap5.4|http://unitsofmeasure.org|mg");
|
||||
assertEquals(null,p.getComparator());
|
||||
assertEquals(ParamPrefixEnum.APPROXIMATE, p.getPrefix());
|
||||
assertEquals(true, p.isApproximate());
|
||||
assertEquals("5.4", p.getValue().toPlainString());
|
||||
assertEquals("http://unitsofmeasure.org", p.getSystem());
|
||||
assertEquals("mg", p.getUnits());
|
||||
|
@ -56,7 +50,6 @@ public class QuantityParamTest {
|
|||
public void testNoQualifier() {
|
||||
QuantityParam p = new QuantityParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "5.4|http://unitsofmeasure.org|mg");
|
||||
assertEquals(null, p.getComparator());
|
||||
assertEquals(null, p.getPrefix());
|
||||
assertEquals("5.4", p.getValue().toPlainString());
|
||||
assertEquals("http://unitsofmeasure.org", p.getSystem());
|
||||
|
@ -69,7 +62,6 @@ public class QuantityParamTest {
|
|||
public void testNoUnits() {
|
||||
QuantityParam p = new QuantityParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "5.4");
|
||||
assertEquals(null, p.getComparator());
|
||||
assertEquals(null, p.getPrefix());
|
||||
assertEquals("5.4", p.getValue().toPlainString());
|
||||
assertEquals(null, p.getSystem());
|
||||
|
@ -109,7 +101,6 @@ public class QuantityParamTest {
|
|||
public void testNegativeQuantityWithUnits() {
|
||||
QuantityParam p = new QuantityParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "-5.4|http://unitsofmeasure.org|mg");
|
||||
assertEquals(null, p.getComparator());
|
||||
assertEquals(null, p.getPrefix());
|
||||
assertEquals("-5.4", p.getValue().toPlainString());
|
||||
assertEquals(new BigDecimal("-5.4"), p.getValue());
|
||||
|
@ -125,7 +116,6 @@ public class QuantityParamTest {
|
|||
public void testNegativeQuantityWithoutUnits() {
|
||||
QuantityParam p = new QuantityParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "-5.4");
|
||||
assertEquals(null, p.getComparator());
|
||||
assertEquals(null, p.getPrefix());
|
||||
assertEquals("-5.4", p.getValue().toPlainString());
|
||||
assertEquals(new BigDecimal("-5.4"), p.getValue());
|
||||
|
@ -141,7 +131,6 @@ public class QuantityParamTest {
|
|||
public void testNegativeQuantityWithoutUnitsWithComparator() {
|
||||
QuantityParam p = new QuantityParam();
|
||||
p.setValueAsQueryToken(ourCtx, null, null, "gt-5.4");
|
||||
assertEquals(QuantityCompararatorEnum.GREATERTHAN, p.getComparator());
|
||||
assertEquals(ParamPrefixEnum.GREATERTHAN, p.getPrefix());
|
||||
assertEquals("-5.4", p.getValue().toPlainString());
|
||||
assertEquals(new BigDecimal("-5.4"), p.getValue());
|
||||
|
|
|
@ -253,11 +253,6 @@ public class Dstu2Hl7OrgBundleFactory implements IVersionSpecificBundleFactory {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ca.uhn.fhir.model.api.Bundle getDstu1Bundle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBaseResource getResourceBundle() {
|
||||
return myBundle;
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
package ca.uhn.fhir.rest.client;
|
||||
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.io.input.ReaderInputStream;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.hl7.fhir.instance.model.Patient;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
|
||||
public class BundleTypeTest {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BundleTypeTest.class);
|
||||
private FhirContext ourCtx;
|
||||
private HttpClient ourHttpClient;
|
||||
|
||||
private HttpResponse ourHttpResponse;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ourCtx = FhirContext.forDstu2Hl7Org();
|
||||
|
||||
ourHttpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
||||
ourCtx.getRestfulClientFactory().setHttpClient(ourHttpClient);
|
||||
ourCtx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
|
||||
|
||||
ourHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransaction() throws Exception {
|
||||
String retVal = ourCtx.newXmlParser().encodeBundleToString(new Bundle());
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(ourHttpClient.execute(capt.capture())).thenReturn(ourHttpResponse);
|
||||
when(ourHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(ourHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8"));
|
||||
when(ourHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(retVal), Charset.forName("UTF-8")));
|
||||
|
||||
Patient p1 = new Patient();
|
||||
p1.addIdentifier().setSystem("urn:system").setValue("value");
|
||||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://foo");
|
||||
client.transaction().withResources(Arrays.asList((IBaseResource) p1)).execute();
|
||||
|
||||
HttpUriRequest value = capt.getValue();
|
||||
|
||||
assertTrue("Expected request of type POST on long params list", value instanceof HttpPost);
|
||||
HttpPost post = (HttpPost) value;
|
||||
String body = IOUtils.toString(post.getEntity().getContent());
|
||||
IOUtils.closeQuietly(post.getEntity().getContent());
|
||||
ourLog.info(body);
|
||||
|
||||
assertThat(body, Matchers.containsString("<type value=\"" + BundleTypeEnum.TRANSACTION.getCode()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
changes in 3.0.0
|
||||
|
||||
- QuantityComparatorEnum has been removed. It was deprecated replaced with ParamPrefixEnum in HAPI FHIR 1.5.
|
||||
- ca.uhn.fhir.model.api.Bundle (the DSTU1 Atom Bundle class) has been removed. Each structure JAR includes a Bundle resource class which can be used instead.
|
File diff suppressed because it is too large
Load Diff
|
@ -3,6 +3,7 @@ package ca.uhn.fhir.rest.server.exceptions;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -10,8 +11,6 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.google.common.reflect.ClassPath;
|
||||
import com.google.common.reflect.ClassPath.ClassInfo;
|
||||
|
||||
import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
|
||||
import ca.uhn.fhir.model.dstu.resource.Practitioner;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
|
||||
import ca.uhn.fhir.rest.client.exceptions.FhirClientInappropriateForServerException;
|
||||
|
@ -32,7 +31,7 @@ public class ExceptionPropertiesTest {
|
|||
|
||||
assertEquals("Resource Patient/123 is gone/deleted", new ResourceGoneException(new IdDt("Patient/123")).getMessage());
|
||||
assertEquals("FOO", new ResourceGoneException("FOO", new OperationOutcome()).getMessage());
|
||||
assertEquals("Resource of type Practitioner with ID Patient/123 is gone/deleted", new ResourceGoneException(Practitioner.class, new IdDt("Patient/123")).getMessage());
|
||||
assertEquals("Resource of type Practitioner with ID Patient/123 is gone/deleted", new ResourceGoneException(Practitioner.class, new IdType("Patient/123")).getMessage());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
|
@ -1,14 +1,11 @@
|
|||
package ca.uhn.fhir.rest.server.interceptor;
|
||||
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
|
@ -19,39 +16,30 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.hamcrest.core.StringContains;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.junit.*;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.server.ExceptionTest;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.*;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
public class ExceptionHandlingInterceptorTest {
|
||||
|
||||
private static ExceptionHandlingInterceptor myInterceptor;
|
||||
private static final String OPERATION_OUTCOME_DETAILS = "OperationOutcomeDetails";
|
||||
private static CloseableHttpClient ourClient;
|
||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static FhirContext ourCtx = FhirContext.forR4();
|
||||
private static Class<? extends Exception> ourExceptionType;
|
||||
private static boolean ourGenerateOperationOutcome;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExceptionTest.class);
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExceptionHandlingInterceptorTest.class);
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private static RestfulServer servlet;
|
||||
|
@ -70,13 +58,13 @@ public class ExceptionHandlingInterceptorTest {
|
|||
{
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?throwInternalError=aaa");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent(), Charsets.UTF_8);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
assertEquals(500, status.getStatusLine().getStatusCode());
|
||||
OperationOutcome oo = (OperationOutcome) servlet.getFhirContext().newXmlParser().parseResource(responseContent);
|
||||
assertThat(oo.getIssueFirstRep().getDetails().getValue(), StringContains.containsString("Exception Text"));
|
||||
assertThat(oo.getIssueFirstRep().getDetails().getValue(), (StringContains.containsString("InternalErrorException: Exception Text")));
|
||||
assertThat(oo.getIssueFirstRep().getDiagnosticsElement().getValue(), StringContains.containsString("Exception Text"));
|
||||
assertThat(oo.getIssueFirstRep().getDiagnosticsElement().getValue(), (StringContains.containsString("InternalErrorException: Exception Text")));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,13 +74,13 @@ public class ExceptionHandlingInterceptorTest {
|
|||
{
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?throwInternalError=aaa&_format=true");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent(), Charsets.UTF_8);
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
ourLog.info(responseContent);
|
||||
assertEquals(500, status.getStatusLine().getStatusCode());
|
||||
OperationOutcome oo = (OperationOutcome) servlet.getFhirContext().newXmlParser().parseResource(responseContent);
|
||||
assertThat(oo.getIssueFirstRep().getDetails().getValue(), StringContains.containsString("Exception Text"));
|
||||
assertThat(oo.getIssueFirstRep().getDetails().getValue(), (StringContains.containsString("InternalErrorException: Exception Text")));
|
||||
assertThat(oo.getIssueFirstRep().getDiagnosticsElement().getValue(), StringContains.containsString("Exception Text"));
|
||||
assertThat(oo.getIssueFirstRep().getDiagnosticsElement().getValue(), (StringContains.containsString("InternalErrorException: Exception Text")));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,16 +123,16 @@ public class ExceptionHandlingInterceptorTest {
|
|||
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
public Class<Patient> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
||||
@Read
|
||||
public Patient read(@IdParam IdDt theId) {
|
||||
public Patient read(@IdParam IdType theId) {
|
||||
OperationOutcome oo = null;
|
||||
if (ourGenerateOperationOutcome) {
|
||||
oo = new OperationOutcome();
|
||||
oo.addIssue().setDetails(OPERATION_OUTCOME_DETAILS);
|
||||
oo.addIssue().setDiagnostics(OPERATION_OUTCOME_DETAILS);
|
||||
}
|
||||
|
||||
if (ourExceptionType == ResourceNotFoundException.class) {
|
|
@ -1,6 +1,7 @@
|
|||
package ca.uhn.fhir.rest.server.interceptor;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -19,18 +20,15 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.method.RequestDetails;
|
||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
|
||||
|
@ -41,7 +39,7 @@ import ca.uhn.fhir.util.TestUtil;
|
|||
public class ExceptionInterceptorMethodTest {
|
||||
|
||||
private static CloseableHttpClient ourClient;
|
||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static FhirContext ourCtx = FhirContext.forR4();
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExceptionInterceptorMethodTest.class);
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
|
@ -1,40 +1,37 @@
|
|||
package ca.uhn.fhir.util;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.composite.QuantityDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
|
||||
public class FhirTerserTest {
|
||||
|
||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static FhirContext ourCtx = FhirContext.forR4();
|
||||
|
||||
@Test
|
||||
public void testGetAllPopulatedChildElementsOfType() {
|
||||
|
||||
Patient p = new Patient();
|
||||
p.setGender(AdministrativeGenderCodesEnum.M);
|
||||
p.setGender(AdministrativeGender.MALE);
|
||||
p.addIdentifier().setSystem("urn:foo");
|
||||
p.addAddress().addLine("Line1");
|
||||
p.addAddress().addLine("Line2");
|
||||
p.addName().addFamily("Line3");
|
||||
p.addName().setFamily("Line3");
|
||||
|
||||
FhirTerser t = ourCtx.newTerser();
|
||||
List<StringDt> strings = t.getAllPopulatedChildElementsOfType(p, StringDt.class);
|
||||
List<StringType> strings = t.getAllPopulatedChildElementsOfType(p, StringType.class);
|
||||
|
||||
assertEquals(3, strings.size());
|
||||
assertThat(strings, containsInAnyOrder(new StringDt("Line1"), new StringDt("Line2"), new StringDt("Line3")));
|
||||
assertThat(strings, containsInAnyOrder(new StringType("Line1"), new StringType("Line2"), new StringType("Line3")));
|
||||
|
||||
}
|
||||
|
||||
|
@ -42,7 +39,7 @@ public class FhirTerserTest {
|
|||
public void testMultiValueTypes() {
|
||||
|
||||
Observation obs = new Observation();
|
||||
obs.setValue(new QuantityDt(123L));
|
||||
obs.setValue(new Quantity(123L));
|
||||
|
||||
FhirTerser t = ourCtx.newTerser();
|
||||
|
||||
|
@ -56,8 +53,8 @@ public class FhirTerserTest {
|
|||
{
|
||||
List<Object> values = t.getValues(obs, "Observation.valueQuantity");
|
||||
assertEquals(1, values.size());
|
||||
QuantityDt actual = (QuantityDt) values.get(0);
|
||||
assertEquals("123", actual.getValue().getValueAsString());
|
||||
Quantity actual = (Quantity) values.get(0);
|
||||
assertEquals("123", actual.getValueElement().getValueAsString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,10 +95,10 @@ public class FhirTerserTest {
|
|||
Observation parsed = ourCtx.newXmlParser().parseResource(Observation.class, msg);
|
||||
FhirTerser t = ourCtx.newTerser();
|
||||
|
||||
List<ResourceReferenceDt> elems = t.getAllPopulatedChildElementsOfType(parsed, ResourceReferenceDt.class);
|
||||
List<Reference> elems = t.getAllPopulatedChildElementsOfType(parsed, Reference.class);
|
||||
assertEquals(2, elems.size());
|
||||
assertEquals("cid:patient@bundle", elems.get(0).getReference().getValue());
|
||||
assertEquals("cid:device@bundle", elems.get(1).getReference().getValue());
|
||||
assertEquals("cid:patient@bundle", elems.get(0).getReferenceElement().getValue());
|
||||
assertEquals("cid:device@bundle", elems.get(1).getReferenceElement().getValue());
|
||||
}
|
||||
|
||||
@AfterClass
|
|
@ -1,9 +1,31 @@
|
|||
package ca.uhn.fhir.to;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.hl7.fhir.dstu3.model.*;
|
||||
import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestComponent;
|
||||
import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceComponent;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IDomainResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.thymeleaf.TemplateEngine;
|
||||
|
||||
import ca.uhn.fhir.context.*;
|
||||
import ca.uhn.fhir.model.api.ExtensionDt;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.primitive.DecimalDt;
|
||||
|
@ -13,31 +35,6 @@ import ca.uhn.fhir.rest.client.api.*;
|
|||
import ca.uhn.fhir.rest.client.impl.GenericClient;
|
||||
import ca.uhn.fhir.to.model.HomeRequest;
|
||||
import ca.uhn.fhir.util.ExtensionConstants;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.hl7.fhir.dstu3.model.CapabilityStatement;
|
||||
import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestComponent;
|
||||
import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceComponent;
|
||||
import org.hl7.fhir.dstu3.model.DecimalType;
|
||||
import org.hl7.fhir.dstu3.model.Extension;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IDomainResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.thymeleaf.TemplateEngine;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
||||
public class BaseController {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseController.class);
|
||||
|
@ -537,7 +534,6 @@ public class BaseController {
|
|||
String narrativeString = "";
|
||||
|
||||
StringBuilder resultDescription = new StringBuilder();
|
||||
Bundle bundle = null;
|
||||
IBaseResource riBundle = null;
|
||||
|
||||
FhirContext context = getContext(theRequest);
|
||||
|
@ -551,11 +547,7 @@ public class BaseController {
|
|||
resultDescription.append("JSON resource");
|
||||
} else if (theResultType == ResultType.BUNDLE) {
|
||||
resultDescription.append("JSON bundle");
|
||||
if (context.getVersion().getVersion().isRi()) {
|
||||
riBundle = context.newJsonParser().parseResource(resultBody);
|
||||
} else {
|
||||
bundle = context.newJsonParser().parseBundle(resultBody);
|
||||
}
|
||||
riBundle = context.newJsonParser().parseResource(resultBody);
|
||||
}
|
||||
break;
|
||||
case XML:
|
||||
|
@ -565,11 +557,7 @@ public class BaseController {
|
|||
resultDescription.append("XML resource");
|
||||
} else if (theResultType == ResultType.BUNDLE) {
|
||||
resultDescription.append("XML bundle");
|
||||
if (context.getVersion().getVersion().isRi()) {
|
||||
riBundle = context.newXmlParser().parseResource(resultBody);
|
||||
} else {
|
||||
bundle = context.newXmlParser().parseBundle(resultBody);
|
||||
}
|
||||
riBundle = context.newXmlParser().parseResource(resultBody);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -583,7 +571,6 @@ public class BaseController {
|
|||
theModelMap.put("outcomeDescription", outcomeDescription);
|
||||
theModelMap.put("resultDescription", resultDescription.toString());
|
||||
theModelMap.put("action", action);
|
||||
theModelMap.put("bundle", bundle);
|
||||
theModelMap.put("riBundle", riBundle);
|
||||
theModelMap.put("resultStatus", resultStatus);
|
||||
|
||||
|
|
|
@ -440,7 +440,7 @@ public class Controller extends BaseController {
|
|||
return "resource";
|
||||
}
|
||||
int limitInt = Integer.parseInt(limit);
|
||||
query.limitTo(limitInt);
|
||||
query.count(limitInt);
|
||||
clientCodeJsonWriter.name("limit");
|
||||
clientCodeJsonWriter.value(limit);
|
||||
} else {
|
||||
|
@ -465,14 +465,16 @@ public class Controller extends BaseController {
|
|||
}
|
||||
}
|
||||
|
||||
query.returnBundle(client.getFhirContext().getResourceDefinition("Bundle").getImplementingClass());
|
||||
Class<? extends IBaseBundle> bundleType;
|
||||
bundleType = (Class<? extends IBaseBundle>) client.getFhirContext().getResourceDefinition("Bundle").getImplementingClass();
|
||||
IQueryTyped<? extends IBaseBundle> queryTyped = query.returnBundle(bundleType);
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
ResultType returnsResource;
|
||||
try {
|
||||
ourLog.info(logPrefix(theModel) + "Executing a search");
|
||||
|
||||
query.execute();
|
||||
queryTyped.execute();
|
||||
returnsResource = ResultType.BUNDLE;
|
||||
} catch (Exception e) {
|
||||
returnsResource = handleClientException(client, e, theModel);
|
||||
|
@ -793,7 +795,7 @@ public class Controller extends BaseController {
|
|||
return haveSearchParams;
|
||||
}
|
||||
|
||||
private boolean handleSearchParam(String paramIdxString, HttpServletRequest theReq, IQuery<?> theQuery, JsonWriter theClientCodeJsonWriter) throws IOException {
|
||||
private boolean handleSearchParam(String paramIdxString, HttpServletRequest theReq, IQuery theQuery, JsonWriter theClientCodeJsonWriter) throws IOException {
|
||||
String nextName = theReq.getParameter("param." + paramIdxString + ".name");
|
||||
if (isBlank(nextName)) {
|
||||
return false;
|
||||
|
|
|
@ -105,13 +105,6 @@ public class TesterConfig {
|
|||
|
||||
if (nextSplit.length < 3) {
|
||||
throw new IllegalArgumentException("Invalid serveer line '" + nextRaw + "' - Must be comma separated");
|
||||
} else if (nextSplit.length == 3) {
|
||||
Validate.notBlank(nextSplit[0], "theId can not be blank");
|
||||
Validate.notBlank(nextSplit[1], "theDisplayName can not be blank");
|
||||
Validate.notBlank(nextSplit[2], "theServerBase can not be blank");
|
||||
myIdToServerName.put(nextSplit[0].trim(), nextSplit[1].trim());
|
||||
myIdToServerBase.put(nextSplit[0].trim(), nextSplit[2].trim());
|
||||
myIdToFhirVersion.put(nextSplit[0].trim(), FhirVersionEnum.DSTU1);
|
||||
} else {
|
||||
Validate.notBlank(nextSplit[0], "theId can not be blank");
|
||||
Validate.notBlank(nextSplit[1], "theVersion can not be blank");
|
||||
|
|
|
@ -49,9 +49,7 @@ public abstract class AbstractGenerator {
|
|||
*/
|
||||
FhirContext fhirContext;
|
||||
String packageSuffix = "";
|
||||
if ("dstu".equals(context.getVersion())) {
|
||||
fhirContext = FhirContext.forDstu1();
|
||||
} else if ("dstu2".equals(context.getVersion())) {
|
||||
if ("dstu2".equals(context.getVersion())) {
|
||||
fhirContext = FhirContext.forDstu2();
|
||||
} else if ("dstu3".equals(context.getVersion())) {
|
||||
fhirContext = FhirContext.forDstu3();
|
||||
|
@ -91,14 +89,6 @@ public abstract class AbstractGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* No spreadsheet existed for Binary in DSTU1 so we don't generate it.. this
|
||||
* is something we could work around, but at this point why bother since it's
|
||||
* only an issue for DSTU1
|
||||
*/
|
||||
if (fhirContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
includeResources.remove("binary");
|
||||
}
|
||||
if (fhirContext.getVersion().getVersion() == FhirVersionEnum.DSTU3) {
|
||||
includeResources.remove("conformance");
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue