DSTU2.1 structures working

This commit is contained in:
jamesagnew 2016-01-01 16:59:19 -05:00
parent 056900f324
commit 718a26671f
45 changed files with 691 additions and 2605 deletions

View File

@ -8,6 +8,11 @@ import javax.servlet.ServletException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.hl7.fhir.instance.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.instance.hapi.validation.FhirInstanceValidator;
import org.hl7.fhir.instance.hapi.validation.IValidationSupport;
import org.hl7.fhir.instance.hapi.validation.IValidationSupport.CodeValidationResult;
import org.hl7.fhir.instance.hapi.validation.ValidationSupportChain;
import org.hl7.fhir.instance.model.ValueSet;
import org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.instance.model.ValueSet.ValueSetExpansionComponent;
@ -23,11 +28,7 @@ import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.parser.StrictErrorHandler;
import ca.uhn.fhir.rest.client.IGenericClient;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.validation.DefaultProfileValidationSupport;
import ca.uhn.fhir.validation.ValidationSupportChain;
import ca.uhn.fhir.validation.FhirInstanceValidator;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.IValidationSupport;
import ca.uhn.fhir.validation.SingleValidationMessage;
import ca.uhn.fhir.validation.ValidationResult;

View File

@ -75,7 +75,7 @@ abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding<Void>
myResourceName = theConetxt.getResourceDefinition(myType).getName();
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod);
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
myVersionIdParamIndex = MethodUtil.findVersionIdParameterIndex(theMethod);
myTagListParamIndex = MethodUtil.findTagListParameterIndex(theMethod);

View File

@ -75,7 +75,7 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu
}
myResourceName = theContext.getResourceDefinition(myResourceType).getName();
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod);
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
if (myIdParamIndex != null) {
myIdParamType = (Class<? extends IIdType>) theMethod.getParameterTypes()[myIdParamIndex];
}

View File

@ -66,7 +66,7 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBinding {
}
}
myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod);
myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
if (myIdParameterIndex == null) {
throw new ConfigurationException("Method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName() + "' has no parameter annotated with the @" + IdParam.class.getSimpleName() + " annotation");
}

View File

@ -59,7 +59,7 @@ public class DynamicSearchMethodBinding extends BaseResourceReturningMethodBindi
myParamNames.add(next.getName());
}
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod);
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
}

View File

@ -67,7 +67,7 @@ public class GetTagsMethodBinding extends BaseMethodBinding<TagList> {
myResourceName = theConetxt.getResourceDefinition(myType).getName();
}
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod);
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
myVersionIdParamIndex = MethodUtil.findVersionIdParameterIndex(theMethod);
if (myIdParamIndex != null && myType.equals(IResource.class)) {

View File

@ -55,7 +55,7 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
public HistoryMethodBinding(Method theMethod, FhirContext theConetxt, Object theProvider) {
super(toReturnType(theMethod, theProvider), theMethod, theConetxt, theProvider);
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod);
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
History historyAnnotation = theMethod.getAnnotation(History.class);
Class<? extends IBaseResource> type = historyAnnotation.type();

View File

@ -322,8 +322,20 @@ public class MethodUtil {
return MethodUtil.findParamAnnotationIndex(theMethod, ConditionalUrlParam.class);
}
public static Integer findIdParameterIndex(Method theMethod) {
return MethodUtil.findParamAnnotationIndex(theMethod, IdParam.class);
public static Integer findIdParameterIndex(Method theMethod, FhirContext theContext) {
Integer index = MethodUtil.findParamAnnotationIndex(theMethod, IdParam.class);
if (index != null) {
Class<?> paramType = theMethod.getParameterTypes()[index];
if (IIdType.class.equals(paramType)) {
return index;
}
boolean isRi = theContext.getVersion().getVersion().isRi();
boolean usesHapiId = IdDt.class.equals(paramType);
if (isRi == usesHapiId) {
throw new ConfigurationException("Method uses the wrong Id datatype (IdDt / IdType) for the given context FHIR version: " + theMethod.toString());
}
}
return index;
}
public static Integer findParamAnnotationIndex(Method theMethod, Class<?> toFind) {

View File

@ -35,6 +35,7 @@ import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseDatatype;
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 ca.uhn.fhir.context.ConfigurationException;
@ -42,7 +43,6 @@ 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.annotation.Description;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
@ -76,7 +76,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
super(theReturnResourceType, theMethod, theContext, theProvider);
myIdempotent = theIdempotent;
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod);
myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
if (myIdParamIndex != null) {
for (Annotation next : theMethod.getParameterAnnotations()[myIdParamIndex]) {
if (next instanceof IdParam) {
@ -230,7 +230,7 @@ public class OperationMethodBinding extends BaseResourceReturningMethodBinding {
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
String id = null;
if (myIdParamIndex != null) {
IdDt idDt = (IdDt) theArgs[myIdParamIndex];
IIdType idDt = (IIdType) theArgs[myIdParamIndex];
id = idDt.getValue();
}
IBaseParameters parameters = (IBaseParameters) getContext().getResourceDefinition("Parameters").newInstance();

View File

@ -72,7 +72,7 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem
Validate.notNull(theMethod, "Method must not be null");
Integer idIndex = MethodUtil.findIdParameterIndex(theMethod);
Integer idIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
Integer versionIdIndex = MethodUtil.findVersionIdParameterIndex(theMethod);
Class<?>[] parameterTypes = theMethod.getParameterTypes();

View File

@ -65,7 +65,7 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
Search search = theMethod.getAnnotation(Search.class);
this.myQueryName = StringUtils.defaultIfBlank(search.queryName(), null);
this.myCompartmentName = StringUtils.defaultIfBlank(search.compartmentName(), null);
this.myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod);
this.myIdParamIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
this.myAllowUnknownParams = search.allowUnknownParams();
Description desc = theMethod.getAnnotation(Description.class);

View File

@ -45,7 +45,7 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
public UpdateMethodBinding(Method theMethod, FhirContext theContext, Object theProvider) {
super(theMethod, theContext, Update.class, theProvider);
myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod);
myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
}
@Override

View File

@ -40,7 +40,7 @@ public class ValidateMethodBindingDstu1 extends BaseOutcomeReturningMethodBindin
public ValidateMethodBindingDstu1(Method theMethod, FhirContext theContext, Object theProvider) {
super(theMethod, theContext, Validate.class, theProvider);
myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod);
myIdParameterIndex = MethodUtil.findIdParameterIndex(theMethod, getContext());
}
@Override

View File

@ -1,15 +1,15 @@
package ca.uhn.fhir.cli;
import org.hl7.fhir.instance.model.ValueSet;
import org.hl7.fhir.instance.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.instance.model.ValueSet.ValueSetExpansionComponent;
import org.hl7.fhir.dstu21.hapi.validation.IValidationSupport;
import org.hl7.fhir.dstu21.model.ValueSet;
import org.hl7.fhir.dstu21.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ValueSetExpansionComponent;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.IGenericClient;
import ca.uhn.fhir.rest.client.ServerValidationModeEnum;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.validation.IValidationSupport;
public class LoadingValidationSupport implements IValidationSupport {

View File

@ -4,15 +4,13 @@ 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.leftPad;
import static org.fusesource.jansi.Ansi.*;
import static org.fusesource.jansi.Ansi.ansi;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
@ -21,24 +19,20 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.text.WordUtils;
import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.Ansi.Color;
import org.hl7.fhir.dstu21.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.dstu21.hapi.validation.FhirInstanceValidator;
import org.hl7.fhir.dstu21.hapi.validation.ValidationSupportChain;
import org.hl7.fhir.dstu21.model.StructureDefinition;
import com.phloc.commons.io.file.FileUtils;
import com.sun.tools.corba.se.idl.ParameterEntry;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.dstu2.resource.StructureDefinition;
import ca.uhn.fhir.rest.method.MethodUtil;
import ca.uhn.fhir.rest.param.ParameterUtil;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.validation.DefaultProfileValidationSupport;
import ca.uhn.fhir.validation.FhirInstanceValidator;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.SingleValidationMessage;
import ca.uhn.fhir.validation.ValidationResult;
import ca.uhn.fhir.validation.ValidationSupportChain;
import net.sf.saxon.expr.instruct.LocalParam;
import net.sf.saxon.om.Chain;
public class ValidateCommand extends BaseCommand {
@ -112,7 +106,7 @@ public class ValidateCommand extends BaseCommand {
throw new ParseException("Failed to load file '" + localProfile + "' - Error: " + e.toString());
}
org.hl7.fhir.instance.model.StructureDefinition sd = (org.hl7.fhir.instance.model.StructureDefinition) MethodUtil.detectEncodingNoDefault(input).newParser(FhirContext.forDstu2Hl7Org()).parseResource(input);
StructureDefinition sd = (StructureDefinition) MethodUtil.detectEncodingNoDefault(input).newParser(getFhirCtx()).parseResource(input);
instanceValidator.setStructureDefintion(sd);
}
if (theCommandLine.hasOption("r")) {

View File

@ -23,11 +23,10 @@ package ca.uhn.fhir.jpa.dao;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@ -36,7 +35,6 @@ import javax.annotation.PostConstruct;
import org.apache.commons.codec.binary.StringUtils;
import org.hl7.fhir.dstu21.hapi.validation.DefaultProfileValidationSupport;
import org.hl7.fhir.dstu21.hapi.validation.HapiWorkerContext;
import org.hl7.fhir.dstu21.hapi.validation.IValidationSupport.CodeValidationResult;
import org.hl7.fhir.dstu21.hapi.validation.ValidationSupportChain;
import org.hl7.fhir.dstu21.model.CodeableConcept;
import org.hl7.fhir.dstu21.model.Coding;
@ -48,19 +46,16 @@ import org.hl7.fhir.dstu21.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ValueSetExpansionComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ValueSetExpansionContainsComponent;
import org.hl7.fhir.dstu21.terminologies.ValueSetExpander;
import org.hl7.fhir.dstu21.terminologies.ValueSetExpander.ETooCostly;
import org.hl7.fhir.dstu21.terminologies.ValueSetExpander.ValueSetExpansionOutcome;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.springframework.beans.factory.annotation.Autowired;
import ca.uhn.fhir.jpa.entity.BaseHasResource;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSet> implements IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> {
@ -81,31 +76,23 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
@Override
public ValueSet expand(IIdType theId, String theFilter) {
// throw new UnsupportedOperationException();
HapiWorkerContext workerContext = new HapiWorkerContext(getContext(), myValidationSupport);
ConceptSetComponent inc = new ConceptSetComponent();
inc.setSystem(theId.getValue());
ValueSetExpansionComponent outcome = workerContext.expandVS(inc);
ValueSet source = workerContext.fetchResource(ValueSet.class, theId.getValue());
ValueSet retVal = new ValueSet();
retVal.setExpansion(outcome);
return retVal;
}
private ValueSet loadValueSetForExpansion(IIdType theId) {
if (theId.getValue().startsWith("http://hl7.org/fhir/")) {
ValueSet valueSet = myValidationSupport.fetchResource(getContext(), ValueSet.class, theId.getValue());
if (valueSet != null) {
return valueSet; // getContext().newJsonParser().parseResource(ValueSet.class,
// getContext().newJsonParser().encodeResourceToString(valueSet));
ValueSetExpansionOutcome outcome = workerContext.expand(source);
ValueSetExpansionComponent expansion = outcome.getValueset().getExpansion();
if (isNotBlank(theFilter)) {
for (Iterator<ValueSetExpansionContainsComponent> containsIter = expansion.getContains().iterator(); containsIter.hasNext();) {
ValueSetExpansionContainsComponent nextContains = containsIter.next();
if (!nextContains.getDisplay().toLowerCase().contains(theFilter.toLowerCase())) {
containsIter.remove();
}
}
}
BaseHasResource sourceEntity = readEntity(theId);
if (sourceEntity == null) {
throw new ResourceNotFoundException(theId);
}
ValueSet source = (ValueSet) toResource(sourceEntity, false);
return source;
ValueSet retVal = new ValueSet();
retVal.setExpansion(expansion);
return retVal;
}
@Override
@ -239,9 +226,9 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
}
private List<IIdType> findValueSetIdsContainingSystemAndCode(String theCode, String theSystem) {
if (theSystem != null && theSystem.startsWith("http://hl7.org/fhir/ValueSet")) {
return Collections.singletonList((IIdType) new IdType(theSystem));
}
// if (theSystem != null && theSystem.startsWith("http://hl7.org/fhir/ValueSet")) {
// return Collections.singletonList((IIdType) new IdType(theSystem));
// }
List<IIdType> valueSetIds;
Set<Long> ids = searchForIds(ValueSet.SP_CODE, new TokenParam(theSystem, theCode));
@ -320,48 +307,65 @@ public class FhirResourceDaoValueSetDstu21 extends FhirResourceDaoDstu21<ValueSe
system = theSystem.getValue();
}
// CodeValidationResult validateOutcome = myJpaValidationSupport.validateCode(getContext(), system, code, null);
//
// LookupCodeResult result = new LookupCodeResult();
// result.setSearchedForCode(code);
// result.setSearchedForSystem(system);
// result.setFound(false);
// if (validateOutcome.isOk()) {
// result.setFound(true);
// result.setCodeIsAbstract(validateOutcome.asConceptDefinition().getAbstract());
// result.setCodeDisplay(validateOutcome.asConceptDefinition().getDisplay());
// }
// return result;
// result.getDisplay()
//
// List<IIdType> valueSetIds = findValueSetIdsContainingSystemAndCode(code, system);
// for (IIdType nextId : valueSetIds) {
// ValueSet expansion = expand(nextId, null);
// List<ValueSetExpansionContainsComponent> contains = expansion.getExpansion().getContains();
// ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult result = lookup(contains, system, code);
// if (result != null) {
// return result;
// }
// }
//
// CodeValidationResult validateOutcome = myJpaValidationSupport.validateCode(getContext(), system, code, null);
//
// LookupCodeResult result = new LookupCodeResult();
// result.setSearchedForCode(code);
// result.setSearchedForSystem(system);
// result.setFound(false);
// if (validateOutcome.isOk()) {
// result.setFound(true);
// result.setCodeIsAbstract(validateOutcome.asConceptDefinition().getAbstract());
// result.setCodeDisplay(validateOutcome.asConceptDefinition().getDisplay());
// }
// return result;
HapiWorkerContext ctx = new HapiWorkerContext(getContext(), myValidationSupport);
ValueSetExpander expander = ctx.getExpander();
ValueSet source = new ValueSet();
source.getCompose().addInclude().setSystem(system).addConcept().setCode(code);
if (myValidationSupport.isCodeSystemSupported(getContext(), system)) {
HapiWorkerContext ctx = new HapiWorkerContext(getContext(), myValidationSupport);
ValueSetExpander expander = ctx.getExpander();
ValueSet source = new ValueSet();
source.getCompose().addInclude().setSystem(system).addConcept().setCode(code);
ValueSetExpansionOutcome expansion;
try {
expansion = expander.expand(source);
} catch (Exception e) {
throw new InternalErrorException(e);
}
List<ValueSetExpansionContainsComponent> contains = expansion.getValueset().getExpansion().getContains();
ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult result = lookup(contains, system, code);
if (result != null) {
return result;
}
} else {
/*
* If it's not a built-in code system, use ones from the database
*/
List<IIdType> valueSetIds = findValueSetIdsContainingSystemAndCode(code, system);
for (IIdType nextId : valueSetIds) {
ValueSet expansion = read(nextId);
for (ConceptDefinitionComponent next : expansion.getCodeSystem().getConcept()) {
if (code.equals(next.getCode())) {
ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult retVal = new LookupCodeResult();
retVal.setSearchedForCode(code);
retVal.setSearchedForSystem(system);
retVal.setFound(true);
if (next.getAbstractElement().getValue() != null) {
retVal.setCodeIsAbstract(next.getAbstractElement().booleanValue());
}
retVal.setCodeDisplay(next.getDisplay());
retVal.setCodeSystemDisplayName("Unknown"); // TODO: implement
return retVal;
}
}
}
ValueSetExpansionOutcome expansion;
try {
expansion = expander.expand(source);
} catch (Exception e) {
throw new InternalErrorException(e);
}
List<ValueSetExpansionContainsComponent> contains = expansion.getValueset().getExpansion().getContains();
ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.LookupCodeResult result = lookup(contains, system, code);
if (result != null) {
return result;
}
// We didn't find it..
LookupCodeResult retVal = new LookupCodeResult();
retVal.setFound(false);
retVal.setSearchedForCode(code);

View File

@ -1,5 +1,6 @@
package ca.uhn.fhir.jpa.dao;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.StructureDefinition;
import org.hl7.fhir.dstu21.model.ValueSet;
import org.hl7.fhir.dstu21.model.ValueSet.ConceptSetComponent;
@ -30,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.UriParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
@ -61,10 +63,20 @@ public class JpaValidationSupportDstu21 implements IJpaValidationSupportDstu21 {
@Override
public <T extends IBaseResource> T fetchResource(FhirContext theContext, Class<T> theClass, String theUri) {
IdType id = new IdType(theUri);
boolean localReference = false;
if (id.hasBaseUrl() == false && id.hasIdPart() == true) {
localReference = true;
}
String resourceName = myDstu21Ctx.getResourceDefinition(theClass).getName();
IBundleProvider search;
if ("ValueSet".equals(resourceName)) {
search = myValueSetDao.search(ca.uhn.fhir.model.dstu2.resource.ValueSet.SP_URL, new UriParam(theUri));
if (localReference) {
search = myValueSetDao.search(ca.uhn.fhir.model.dstu2.resource.ValueSet.SP_RES_ID, new StringParam(theUri));
} else {
search = myValueSetDao.search(ca.uhn.fhir.model.dstu2.resource.ValueSet.SP_URL, new UriParam(theUri));
}
} else if ("StructureDefinition".equals(resourceName)) {
search = myStructureDefinitionDao.search(ca.uhn.fhir.model.dstu2.resource.StructureDefinition.SP_URL, new UriParam(theUri));
} else {

View File

@ -30,7 +30,6 @@ import org.springframework.beans.factory.annotation.Required;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.GetTags;
import ca.uhn.fhir.rest.annotation.History;
import ca.uhn.fhir.rest.annotation.IdParam;
@ -83,7 +82,7 @@ public abstract class BaseJpaResourceProvider<T extends IBaseResource> extends B
}
@GetTags
public TagList getTagsForResourceInstance(HttpServletRequest theRequest, @IdParam IdDt theResourceId) {
public TagList getTagsForResourceInstance(HttpServletRequest theRequest, @IdParam IIdType theResourceId) {
startRequest(theRequest);
try {
return myDao.getTags(theResourceId);
@ -103,7 +102,7 @@ public abstract class BaseJpaResourceProvider<T extends IBaseResource> extends B
}
@Read(version = true)
public T read(HttpServletRequest theRequest, @IdParam IdDt theId) {
public T read(HttpServletRequest theRequest, @IdParam IIdType theId) {
startRequest(theRequest);
try {
return myDao.read(theId);

View File

@ -35,7 +35,7 @@ public class FhirResourceDaoValueSetDstu21Test extends BaseJpaDstu21Test {
@Before
@Transactional
public void before02() throws IOException {
ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.xml");
ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.1.xml");
upload.setId("");
myExtensionalVsId = myValueSetDao.create(upload).getId().toUnqualifiedVersionless();
}
@ -45,7 +45,7 @@ public class FhirResourceDaoValueSetDstu21Test extends BaseJpaDstu21Test {
UriType valueSetIdentifier = null;
IdType id = null;
CodeType code = new CodeType("8450-9-XXX");
UriType system = new UriType("http://loinc.org");
UriType system = new UriType("http://acme.org");
StringType display = null;
Coding coding = null;
CodeableConcept codeableConcept = null;
@ -58,7 +58,7 @@ public class FhirResourceDaoValueSetDstu21Test extends BaseJpaDstu21Test {
UriType valueSetIdentifier = null;
IdType id = null;
CodeType code = new CodeType("8450-9");
UriType system = new UriType("http://loinc.org");
UriType system = new UriType("http://acme.org");
StringType display = null;
Coding coding = null;
CodeableConcept codeableConcept = null;
@ -72,7 +72,7 @@ public class FhirResourceDaoValueSetDstu21Test extends BaseJpaDstu21Test {
UriType valueSetIdentifier = new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2");
IdType id = null;
CodeType code = new CodeType("11378-7");
UriType system = new UriType("http://loinc.org");
UriType system = new UriType("http://acme.org");
StringType display = null;
Coding coding = null;
CodeableConcept codeableConcept = null;
@ -86,7 +86,7 @@ public class FhirResourceDaoValueSetDstu21Test extends BaseJpaDstu21Test {
UriType valueSetIdentifier = new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2");
IdType id = null;
CodeType code = new CodeType("11378-7");
UriType system = new UriType("http://loinc.org");
UriType system = new UriType("http://acme.org");
StringType display = new StringType("Systolic blood pressure at First encounterXXXX");
Coding coding = null;
CodeableConcept codeableConcept = null;
@ -100,7 +100,7 @@ public class FhirResourceDaoValueSetDstu21Test extends BaseJpaDstu21Test {
UriType valueSetIdentifier = new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2");
IdType id = null;
CodeType code = new CodeType("11378-7");
UriType system = new UriType("http://loinc.org");
UriType system = new UriType("http://acme.org");
StringType display = new StringType("Systolic blood pressure at First encounter");
Coding coding = null;
CodeableConcept codeableConcept = null;
@ -118,7 +118,7 @@ public class FhirResourceDaoValueSetDstu21Test extends BaseJpaDstu21Test {
StringType display = null;
Coding coding = null;
CodeableConcept codeableConcept = new CodeableConcept();
codeableConcept.addCoding().setSystem("http://loinc.org").setCode("11378-7");
codeableConcept.addCoding().setSystem("http://acme.org").setCode("11378-7");
ValidateCodeResult result = myValueSetDao.validateCode(valueSetIdentifier, id, code, system, display, coding, codeableConcept);
assertTrue(result.isResult());
assertEquals("Systolic blood pressure at First encounter", result.getDisplay());
@ -129,7 +129,7 @@ public class FhirResourceDaoValueSetDstu21Test extends BaseJpaDstu21Test {
UriType valueSetIdentifier = null;
IIdType id = myExtensionalVsId;
CodeType code = new CodeType("11378-7");
UriType system = new UriType("http://loinc.org");
UriType system = new UriType("http://acme.org");
StringType display = null;
Coding coding = null;
CodeableConcept codeableConcept = null;
@ -150,15 +150,15 @@ public class FhirResourceDaoValueSetDstu21Test extends BaseJpaDstu21Test {
stringContainsInOrder("<ValueSet xmlns=\"http://hl7.org/fhir\">",
"<expansion>",
"<contains>",
"<system value=\"http://loinc.org\"/>",
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>",
"</contains>",
"<contains>",
"<system value=\"http://loinc.org\"/>",
"<system value=\"http://acme.org\"/>",
"<code value=\"8450-9\"/>",
"<display value=\"Systolic blood pressure--expiration\"/>",
"</contains>",
"<contains>",
"<system value=\"http://acme.org\"/>",
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>",
"</contains>",
"</expansion>"
));
//@formatter:on
@ -176,18 +176,6 @@ public class FhirResourceDaoValueSetDstu21Test extends BaseJpaDstu21Test {
"<display value=\"Systolic blood pressure at First encounter\"/>"));
//@formatter:on
/*
* Filter with code
*/
expanded = myValueSetDao.expand(myExtensionalVsId, ("11378"));
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(expanded);
ourLog.info(resp);
//@formatter:off
assertThat(resp, stringContainsInOrder(
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>"));
//@formatter:on
}
@Test

View File

@ -2299,7 +2299,7 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test {
@Test
public void testValueSetExpandOperation() throws IOException {
ValueSet upload = myFhirCtx.newXmlParser().parseResource(ValueSet.class, new InputStreamReader(ResourceProviderDstu21Test.class.getResourceAsStream("/extensional-case-2.xml")));
ValueSet upload = myFhirCtx.newXmlParser().parseResource(ValueSet.class, new InputStreamReader(ResourceProviderDstu21Test.class.getResourceAsStream("/extensional-case-2.1.xml")));
IIdType vsid = ourClient.create().resource(upload).execute().getId().toUnqualifiedVersionless();
HttpGet get = new HttpGet(ourServerBase + "/ValueSet/" + vsid.getIdPart() + "/$expand");
@ -2313,15 +2313,15 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test {
stringContainsInOrder("<ValueSet xmlns=\"http://hl7.org/fhir\">",
"<expansion>",
"<contains>",
"<system value=\"http://loinc.org\"/>",
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>",
"</contains>",
"<contains>",
"<system value=\"http://loinc.org\"/>",
"<system value=\"http://acme.org\"/>",
"<code value=\"8450-9\"/>",
"<display value=\"Systolic blood pressure--expiration\"/>",
"</contains>",
"<contains>",
"<system value=\"http://acme.org\"/>",
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>",
"</contains>",
"</expansion>"
));
//@formatter:on
@ -2350,27 +2350,6 @@ public class ResourceProviderDstu21Test extends BaseResourceProviderDstu21Test {
response.close();
}
/*
* Filter with code
*/
get = new HttpGet(ourServerBase + "/ValueSet/" + vsid.getIdPart() + "/$expand?filter=11378");
response = ourHttpClient.execute(get);
try {
String resp = IOUtils.toString(response.getEntity().getContent());
ourLog.info(resp);
assertEquals(200, response.getStatusLine().getStatusCode());
//@formatter:off
assertThat(resp, stringContainsInOrder(
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>"
));
//@formatter:on
} finally {
IOUtils.closeQuietly(response.getEntity().getContent());
response.close();
}
}
}

View File

@ -22,179 +22,21 @@ import org.junit.Test;
import org.springframework.transaction.annotation.Transactional;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
public class ResourceProviderDstu21ValueSetTest extends BaseResourceProviderDstu21Test {
private IIdType myExtensionalVsId;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu21ValueSetTest.class);
private IIdType myExtensionalVsId;
@Before
@Transactional
public void before02() throws IOException {
ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.xml");
ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.1.xml");
upload.setId("");
myExtensionalVsId = myValueSetDao.create(upload).getId().toUnqualifiedVersionless();
}
@Test
public void testValidateCodeOperationByCodeAndSystemInstance() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onInstance(myExtensionalVsId)
.named("validate-code")
.withParameter(Parameters.class, "code", new CodeType("8495-4"))
.andParameter("system", new UriType("http://loinc.org"))
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals(true, ((BooleanType)respParam.getParameter().get(0).getValue()).booleanValue());
}
@Test
public void testValidateCodeOperationByCodeAndSystemType() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "code", new CodeType("8450-9"))
.andParameter("system", new UriType("http://loinc.org"))
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals(true, ((BooleanType)respParam.getParameter().get(0).getValue()).booleanValue());
}
@Test
public void testLookupOperationByCodeAndSystem() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "code", new CodeType("8450-9"))
.andParameter("system", new UriType("http://loinc.org"))
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals("name", respParam.getParameter().get(0).getName());
assertEquals(("Unknown"), ((StringType)respParam.getParameter().get(0).getValue()).getValue());
assertEquals("display", respParam.getParameter().get(1).getName());
assertEquals(("Systolic blood pressure--expiration"), ((StringType)respParam.getParameter().get(1).getValue()).getValue());
assertEquals("abstract", respParam.getParameter().get(2).getName());
assertEquals(false, ((BooleanType)respParam.getParameter().get(2).getValue()).getValue().booleanValue());
}
@Test
// @Ignore
public void testLookupOperationForBuiltInCode() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "code", new CodeType("M"))
.andParameter("system", new UriType("http://hl7.org/fhir/v3/MaritalStatus"))
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals("name", respParam.getParameter().get(0).getName());
assertEquals("Unknown", ((StringType)respParam.getParameter().get(0).getValue()).getValue());
assertEquals("display", respParam.getParameter().get(1).getName());
assertEquals("Married", ((StringType)respParam.getParameter().get(1).getValue()).getValue());
assertEquals("abstract", respParam.getParameter().get(2).getName());
assertEquals(false, ((BooleanType)respParam.getParameter().get(2).getValue()).booleanValue());
}
@Test
public void testLookupOperationByCoding() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://loinc.org").setCode("8450-9"))
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals("name", respParam.getParameter().get(0).getName());
assertEquals(("Unknown"), ((StringType)respParam.getParameter().get(0).getValue()).getValue());
assertEquals("display", respParam.getParameter().get(1).getName());
assertEquals(("Systolic blood pressure--expiration"), ((StringType)respParam.getParameter().get(1).getValue()).getValue());
assertEquals("abstract", respParam.getParameter().get(2).getName());
assertEquals(false, ((BooleanType)respParam.getParameter().get(2).getValue()).getValue().booleanValue());
}
@Test
public void testLookupOperationByInvalidCombination() {
//@formatter:off
try {
ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://loinc.org").setCode("8450-9"))
.andParameter("code", new CodeType("8450-9"))
.andParameter("system", new UriType("http://loinc.org"))
.execute();
fail();
} catch (InvalidRequestException e) {
assertEquals("HTTP 400 Bad Request: $lookup can only validate (system AND code) OR (coding.system AND coding.code)", e.getMessage());
}
//@formatter:on
}
@Test
public void testLookupOperationByInvalidCombination2() {
//@formatter:off
try {
ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://loinc.org").setCode("8450-9"))
.andParameter("system", new UriType("http://loinc.org"))
.execute();
fail();
} catch (InvalidRequestException e) {
assertEquals("HTTP 400 Bad Request: $lookup can only validate (system AND code) OR (coding.system AND coding.code)", e.getMessage());
}
//@formatter:on
}
@Test
public void testLookupOperationByInvalidCombination3() {
//@formatter:off
try {
ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://loinc.org").setCode(null))
.execute();
fail();
} catch (InvalidRequestException e) {
assertEquals("HTTP 400 Bad Request: No code, coding, or codeableConcept provided to validate", e.getMessage());
}
//@formatter:on
}
@Test
public void testExpandById() throws IOException {
//@formatter:off
@ -214,15 +56,15 @@ public class ResourceProviderDstu21ValueSetTest extends BaseResourceProviderDstu
stringContainsInOrder("<ValueSet xmlns=\"http://hl7.org/fhir\">",
"<expansion>",
"<contains>",
"<system value=\"http://loinc.org\"/>",
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>",
"</contains>",
"<contains>",
"<system value=\"http://loinc.org\"/>",
"<system value=\"http://acme.org\"/>",
"<code value=\"8450-9\"/>",
"<display value=\"Systolic blood pressure--expiration\"/>",
"</contains>",
"<contains>",
"<system value=\"http://acme.org\"/>",
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>",
"</contains>",
"</expansion>"
));
//@formatter:on
@ -250,26 +92,6 @@ public class ResourceProviderDstu21ValueSetTest extends BaseResourceProviderDstu
"<display value=\"Systolic blood pressure at First encounter\"/>"));
//@formatter:on
/*
* Filter with code
*/
//@formatter:off
respParam = ourClient
.operation()
.onInstance(myExtensionalVsId)
.named("expand")
.withParameter(Parameters.class, "filter", new StringType("11378"))
.execute();
expanded = (ValueSet) respParam.getParameter().get(0).getResource();
//@formatter:on
resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(expanded);
ourLog.info(resp);
//@formatter:off
assertThat(resp, stringContainsInOrder(
"<code value=\"11378-7\"/>",
"<display value=\"Systolic blood pressure at First encounter\"/>"));
//@formatter:on
}
@Test
@ -372,4 +194,222 @@ public class ResourceProviderDstu21ValueSetTest extends BaseResourceProviderDstu
}
@Test
public void testLookupOperationByCodeAndSystemBuiltInCode() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "code", new CodeType("ACSN"))
.andParameter("system", new UriType("http://hl7.org/fhir/v2/0203"))
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals("name", respParam.getParameter().get(0).getName());
assertEquals(("Unknown"), ((StringType)respParam.getParameter().get(0).getValue()).getValue());
assertEquals("display", respParam.getParameter().get(1).getName());
assertEquals("Accession ID", ((StringType)respParam.getParameter().get(1).getValue()).getValue());
assertEquals("abstract", respParam.getParameter().get(2).getName());
assertEquals(false, ((BooleanType)respParam.getParameter().get(2).getValue()).getValue().booleanValue());
}
@Test
public void testLookupOperationByCodeAndSystemBuiltInNonexistantCode() {
//@formatter:off
try {
ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "code", new CodeType("ACSNAAAAAA"))
.andParameter("system", new UriType("http://hl7.org/fhir/v2/0203"))
.execute();
fail();
} catch (ResourceNotFoundException e) {
// good
}
//@formatter:on
}
@Test
public void testLookupOperationByCodeAndSystemUserDefinedCode() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "code", new CodeType("8450-9"))
.andParameter("system", new UriType("http://acme.org"))
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals("name", respParam.getParameter().get(0).getName());
assertEquals(("Unknown"), ((StringType)respParam.getParameter().get(0).getValue()).getValue());
assertEquals("display", respParam.getParameter().get(1).getName());
assertEquals(("Systolic blood pressure--expiration"), ((StringType)respParam.getParameter().get(1).getValue()).getValue());
assertEquals("abstract", respParam.getParameter().get(2).getName());
assertEquals(false, ((BooleanType)respParam.getParameter().get(2).getValue()).getValue().booleanValue());
}
@Test
public void testLookupOperationByCodeAndSystemUserDefinedNonExistantCode() {
//@formatter:off
try {
ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "code", new CodeType("8450-9AAAAA"))
.andParameter("system", new UriType("http://acme.org"))
.execute();
fail();
} catch (ResourceNotFoundException e) {
// good
}
//@formatter:on
}
@Test
public void testLookupOperationByCoding() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://acme.org").setCode("8450-9"))
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals("name", respParam.getParameter().get(0).getName());
assertEquals(("Unknown"), ((StringType)respParam.getParameter().get(0).getValue()).getValue());
assertEquals("display", respParam.getParameter().get(1).getName());
assertEquals(("Systolic blood pressure--expiration"), ((StringType)respParam.getParameter().get(1).getValue()).getValue());
assertEquals("abstract", respParam.getParameter().get(2).getName());
assertEquals(false, ((BooleanType)respParam.getParameter().get(2).getValue()).getValue().booleanValue());
}
@Test
public void testLookupOperationByInvalidCombination() {
//@formatter:off
try {
ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://acme.org").setCode("8450-9"))
.andParameter("code", new CodeType("8450-9"))
.andParameter("system", new UriType("http://acme.org"))
.execute();
fail();
} catch (InvalidRequestException e) {
assertEquals("HTTP 400 Bad Request: $lookup can only validate (system AND code) OR (coding.system AND coding.code)", e.getMessage());
}
//@formatter:on
}
@Test
public void testLookupOperationByInvalidCombination2() {
//@formatter:off
try {
ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://acme.org").setCode("8450-9"))
.andParameter("system", new UriType("http://acme.org"))
.execute();
fail();
} catch (InvalidRequestException e) {
assertEquals("HTTP 400 Bad Request: $lookup can only validate (system AND code) OR (coding.system AND coding.code)", e.getMessage());
}
//@formatter:on
}
@Test
public void testLookupOperationByInvalidCombination3() {
//@formatter:off
try {
ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "coding", new Coding().setSystem("http://acme.org").setCode(null))
.execute();
fail();
} catch (InvalidRequestException e) {
assertEquals("HTTP 400 Bad Request: No code, coding, or codeableConcept provided to validate", e.getMessage());
}
//@formatter:on
}
@Test
// @Ignore
public void testLookupOperationForBuiltInCode() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("lookup")
.withParameter(Parameters.class, "code", new CodeType("M"))
.andParameter("system", new UriType("http://hl7.org/fhir/v3/MaritalStatus"))
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals("name", respParam.getParameter().get(0).getName());
assertEquals("Unknown", ((StringType)respParam.getParameter().get(0).getValue()).getValue());
assertEquals("display", respParam.getParameter().get(1).getName());
assertEquals("Married", ((StringType)respParam.getParameter().get(1).getValue()).getValue());
assertEquals("abstract", respParam.getParameter().get(2).getName());
assertEquals(false, ((BooleanType)respParam.getParameter().get(2).getValue()).booleanValue());
}
@Test
public void testValidateCodeOperationByCodeAndSystemInstance() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onInstance(myExtensionalVsId)
.named("validate-code")
.withParameter(Parameters.class, "code", new CodeType("8495-4"))
.andParameter("system", new UriType("http://acme.org"))
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals(true, ((BooleanType)respParam.getParameter().get(0).getValue()).booleanValue());
}
@Test
public void testValidateCodeOperationByCodeAndSystemType() {
//@formatter:off
Parameters respParam = ourClient
.operation()
.onType(ValueSet.class)
.named("validate-code")
.withParameter(Parameters.class, "code", new CodeType("8450-9"))
.andParameter("system", new UriType("http://acme.org"))
.execute();
//@formatter:on
String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam);
ourLog.info(resp);
assertEquals(true, ((BooleanType)respParam.getParameter().get(0).getValue()).booleanValue());
}
}

View File

@ -95,7 +95,7 @@ public class SystemProviderDstu21Test extends BaseJpaDstu21Test {
servletHolder.setServlet(restServer);
proxyHandler.addServlet(servletHolder, "/fhir/context/*");
ourCtx = FhirContext.forDstu2();
ourCtx = FhirContext.forDstu2_1();
restServer.setFhirContext(ourCtx);
ourServer.setHandler(proxyHandler);
@ -213,9 +213,9 @@ public class SystemProviderDstu21Test extends BaseJpaDstu21Test {
Parameters parameters = ourCtx.newXmlParser().parseResource(Parameters.class, output);
assertEquals(2, parameters.getParameter().size());
assertEquals("keyword", parameters.getParameter().get(0).getPart().get(0).getName());
assertEquals(new StringType("ZXCVBNM"), parameters.getParameter().get(0).getPart().get(0).getValue());
assertEquals(("ZXCVBNM"), ((StringType)parameters.getParameter().get(0).getPart().get(0).getValue()).getValueAsString());
assertEquals("score", parameters.getParameter().get(0).getPart().get(1).getName());
assertEquals(new DecimalType("1.0"), parameters.getParameter().get(0).getPart().get(1).getValue());
assertEquals(("1.0"), ((DecimalType)parameters.getParameter().get(0).getPart().get(1).getValue()).getValueAsString());
} finally {
http.close();
@ -356,7 +356,7 @@ public class SystemProviderDstu21Test extends BaseJpaDstu21Test {
} catch (InvalidRequestException e) {
OperationOutcome oo = (OperationOutcome) e.getOperationOutcome();
assertEquals("Invalid placeholder ID found: uri:uuid:bb0cd4bc-1839-4606-8c46-ba3069e69b1d - Must be of the form 'urn:uuid:[uuid]' or 'urn:oid:[oid]'", oo.getIssue().get(0).getDiagnostics());
assertEquals("processing", oo.getIssue().get(0).getCode());
assertEquals("processing", oo.getIssue().get(0).getCode().toCode());
}
}

View File

@ -0,0 +1,121 @@
<ValueSet xmlns="http://hl7.org/fhir">
<id value="extensional-case-2" />
<text>
<status value="generated" />
<div xmlns="http://www.w3.org/1999/xhtml">A selection of codes from http://acme.org</div>
</text>
<url value="http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2" />
<identifier>
<value value="http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2" />
</identifier>
<name value="Terminology Services Connectation #1 Extensional case #2" />
<publisher value="Grahame Grieve" />
<contact>
<telecom>
<system value="email" />
<value value="grahame@healthintersections.com.au" />
</telecom>
</contact>
<description value="an enumeration of codes defined by LOINC" />
<status value="draft" />
<experimental value="true" />
<codeSystem>
<system value="http://acme.org" />
<concept>
<code value="8450-9" />
<display value="Systolic blood pressure--expiration" />
</concept>
<concept>
<code value="11378-7" />
<display value="Systolic blood pressure at First encounter" />
</concept>
<concept>
<code value="8493-9" />
<display value="Systolic blood pressure 10 hour minimum" />
</concept>
<concept>
<code value="8494-7" />
<display value="Systolic blood pressure 12 hour minimum" />
</concept>
<concept>
<code value="8495-4" />
<display value="Systolic blood pressure 24 hour minimum" />
</concept>
<concept>
<code value="8451-7" />
<display value="Systolic blood pressure--inspiration" />
</concept>
<concept>
<code value="8452-5" />
<display value="Systolic blood pressure.inspiration - expiration" />
</concept>
<concept>
<code value="8459-0" />
<display value="Systolic blood pressure--sitting" />
</concept>
<concept>
<code value="8460-8" />
<display value="Systolic blood pressure--standing" />
</concept>
<concept>
<code value="8461-6" />
<display value="Systolic blood pressure--supine" />
</concept>
<concept>
<code value="8479-8" />
<display value="Systolic blood pressure by palpation" />
</concept>
<concept>
<code value="8480-6" />
<display value="Systolic blood pressure" />
</concept>
<concept>
<code value="8481-4" />
<display value="Systolic blood pressure 1 hour maximum" />
</concept>
<concept>
<code value="8482-2" />
<display value="Systolic blood pressure 8 hour maximum" />
</concept>
<concept>
<code value="8483-0" />
<display value="Systolic blood pressure 10 hour maximum" />
</concept>
<concept>
<code value="8484-8" />
<display value="Systolic blood pressure 12 hour maximum" />
</concept>
<concept>
<code value="8485-5" />
<display value="Systolic blood pressure 24 hour maximum" />
</concept>
<concept>
<code value="8486-3" />
<display value="Systolic blood pressure 1 hour mean" />
</concept>
<concept>
<code value="8487-1" />
<display value="Systolic blood pressure 8 hour mean" />
</concept>
<concept>
<code value="8488-9" />
<display value="Systolic blood pressure 10 hour mean" />
</concept>
<concept>
<code value="8489-7" />
<display value="Systolic blood pressure 12 hour mean" />
</concept>
<concept>
<code value="8490-5" />
<display value="Systolic blood pressure 24 hour mean" />
</concept>
<concept>
<code value="8491-3" />
<display value="Systolic blood pressure 1 hour minimum" />
</concept>
<concept>
<code value="8492-1" />
<display value="Systolic blood pressure 8 hour minimum" />
</concept>
</codeSystem>
</ValueSet>

View File

@ -182,7 +182,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<!--<redirectTestOutputToFile>false</redirectTestOutputToFile>-->
<runOrder>random</runOrder>
<argLine>-Dfile.encoding=UTF-8</argLine>
<reuseForks>false</reuseForks>

View File

@ -27,12 +27,12 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.StructureDefinition;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
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.Search;
@ -55,7 +55,7 @@ public class ServerProfileProvider implements IResourceProvider {
}
@Read()
public StructureDefinition getProfileById(HttpServletRequest theRequest, @IdParam IdDt theId) {
public StructureDefinition getProfileById(HttpServletRequest theRequest, @IdParam IdType theId) {
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart());
if (retVal==null) {
return null;

View File

@ -6,7 +6,9 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.hl7.fhir.dstu21.model.Bundle;
import org.hl7.fhir.dstu21.model.Bundle.BundleEntryComponent;
@ -14,6 +16,7 @@ import org.hl7.fhir.dstu21.model.IdType;
import org.hl7.fhir.dstu21.model.OperationOutcome.IssueSeverity;
import org.hl7.fhir.dstu21.model.ValueSet;
import org.hl7.fhir.dstu21.model.ValueSet.ConceptDefinitionComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ConceptReferenceComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.dstu21.model.ValueSet.ValueSetExpansionComponent;
import org.hl7.fhir.instance.model.api.IBaseResource;
@ -30,7 +33,21 @@ public class DefaultProfileValidationSupport implements IValidationSupport {
@Override
public ValueSetExpansionComponent expandValueSet(FhirContext theContext, ConceptSetComponent theInclude) {
return null;
ValueSetExpansionComponent retVal = new ValueSetExpansionComponent();
Set<String> wantCodes = new HashSet<String>();
for (ConceptReferenceComponent next : theInclude.getConcept()) {
wantCodes.add(next.getCode());
}
ValueSet system = fetchCodeSystem(theContext, theInclude.getSystem());
for (ConceptDefinitionComponent next : system.getCodeSystem().getConcept()) {
if (wantCodes.isEmpty() || wantCodes.contains(next.getCode())) {
retVal.addContains().setSystem(theInclude.getSystem()).setCode(next.getCode()).setDisplay(next.getDisplay());
}
}
return retVal;
}
@Override
@ -98,7 +115,7 @@ public class DefaultProfileValidationSupport implements IValidationSupport {
}
private void loadCodeSystems(FhirContext theContext, Map<String, ValueSet> theCodeSystems, String theClasspath) {
ourLog.info("Loading code systems from file: {}", theClasspath);
ourLog.info("Loading code systems from classpath: {}", theClasspath);
InputStream valuesetText = DefaultProfileValidationSupport.class.getResourceAsStream(theClasspath);
if (valuesetText != null) {
InputStreamReader reader;

View File

@ -28,6 +28,7 @@ import org.hl7.fhir.dstu21.validation.IResourceValidator;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
public final class HapiWorkerContext implements IWorkerContext, ValueSetExpander, ValueSetExpanderFactory {
private final FhirContext myCtx;
@ -169,7 +170,7 @@ public final class HapiWorkerContext implements IWorkerContext, ValueSetExpander
throw new InternalErrorException(e);
}
if (vso.getError() != null) {
return null;
throw new InvalidRequestException(vso.getError());
} else {
return vso;
}

View File

@ -119,7 +119,7 @@ public class DateType extends BaseDateTimeType {
@Override
public DateType copy() {
return new DateType(getValue());
return new DateType(getValueAsString());
}
public static InstantType today() {

View File

@ -56,7 +56,7 @@ public class DocumentManifest extends DomainResource {
/**
* The list of references to document content, or Attachment that consist of the parts of this document manifest. Usually, these would be document references, but direct references to Media or Attachments are also allowed.
*/
@Child(name = "p", type = {Attachment.class}, order=1, min=1, max=1, modifier=false, summary=true)
@Child(name = "p", type = {Attachment.class, ValueSet.class}, order=1, min=1, max=1, modifier=false, summary=true)
@Description(shortDefinition="Contents of this set of documents", formalDefinition="The list of references to document content, or Attachment that consist of the parts of this document manifest. Usually, these would be document references, but direct references to Media or Attachments are also allowed." )
protected Type p;

View File

@ -197,7 +197,7 @@ public class InstantType extends BaseDateTimeType {
@Override
public InstantType copy() {
return new InstantType(getValue());
return new InstantType(getValueAsString());
}
/**

View File

@ -32,6 +32,7 @@ import org.hamcrest.text.StringContainsInOrder;
import org.hl7.fhir.dstu21.model.Address.AddressUse;
import org.hl7.fhir.dstu21.model.AllergyIntolerance;
import org.hl7.fhir.dstu21.model.Annotation;
import org.hl7.fhir.dstu21.model.Attachment;
import org.hl7.fhir.dstu21.model.Binary;
import org.hl7.fhir.dstu21.model.Bundle;
import org.hl7.fhir.dstu21.model.Bundle.BundleEntryComponent;
@ -82,6 +83,7 @@ import org.junit.Test;
import org.mockito.ArgumentCaptor;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.annotation.Child;
import ca.uhn.fhir.parser.IParserErrorHandler.IParseLocation;
import ca.uhn.fhir.rest.client.IGenericClient;
import ca.uhn.fhir.rest.server.Constants;
@ -1679,6 +1681,12 @@ public class XmlParserDstu21Test {
DocumentManifest actual = ourCtx.newXmlParser().parseResource(DocumentManifest.class, encoded);
assertEquals(1, actual.getContained().size());
assertEquals(1, actual.getContent().size());
/*
* If this fails, it's possibe the DocumentManifest structure is wrong:
* It should be
* @Child(name = "p", type = {Attachment.class, ValueSet.class}, order=1, min=1, max=1, modifier=false, summary=true)
*/
assertNotNull(((Reference) actual.getContent().get(0).getP()).getResource());
}
@ -1730,7 +1738,7 @@ public class XmlParserDstu21Test {
" <id value=\"1\"/>\n" +
" <meta>\n" +
" <versionId value=\"2\"/>\n" +
" <lastUpdated value=\"2001-02-22T11:22:33-05:00\"/>\n" +
" <lastUpdated value=\"2001-02-22T09:22:33-07:00\"/>\n" +
" </meta>\n" +
" <birthDate value=\"2012-01-02\"/>\n" +
" </Patient>\n" +
@ -1758,9 +1766,10 @@ public class XmlParserDstu21Test {
assertEquals("match", entry.getSearch().getMode().toCode());
assertEquals("POST", entry.getRequest().getMethod().toCode());
assertEquals("http://foo/Patient?identifier=value", entry.getRequest().getUrl());
assertEquals("2001-02-22T11:22:33-05:00", pt.getMeta().getLastUpdatedElement().getValueAsString());
assertEquals("2001-02-22T09:22:33-07:00", pt.getMeta().getLastUpdatedElement().getValueAsString());
String reEncoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
IParser p = ourCtx.newXmlParser().setPrettyPrint(true);
String reEncoded = p.encodeResourceToString(b);
ourLog.info(reEncoded);
Diff d = new Diff(new StringReader(bundle), new StringReader(reEncoded));

View File

@ -11,23 +11,22 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.IntegerDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
import ca.uhn.fhir.rest.annotation.OptionalParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Search;
public class ServerUsingOldTypesDstu21Test {
private static FhirContext ourCtx = FhirContext.forDstu2_1();
@Test
public void testReadProvider() {
public void testReadProviderString() {
RestfulServer srv = new RestfulServer(ourCtx);
srv.setFhirContext(ourCtx);
srv.setResourceProviders(new ReadProvider());
srv.setResourceProviders(new ReadProviderString());
try {
srv.init();
@ -36,6 +35,21 @@ public class ServerUsingOldTypesDstu21Test {
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
}
}
@Test
public void testReadProviderIdDt() {
RestfulServer srv = new RestfulServer(ourCtx);
srv.setFhirContext(ourCtx);
srv.setResourceProviders(new ReadProviderIdDt());
try {
srv.init();
fail();
} catch (ServletException e) {
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
}
}
@Test
public void testOperationProvider() {
RestfulServer srv = new RestfulServer(ourCtx);
@ -50,7 +64,7 @@ public class ServerUsingOldTypesDstu21Test {
}
}
public static class ReadProvider implements IResourceProvider {
public static class ReadProviderString implements IResourceProvider {
@Override
public Class<? extends IBaseResource> getResourceType() {
@ -64,6 +78,20 @@ public class ServerUsingOldTypesDstu21Test {
}
public static class ReadProviderIdDt implements IResourceProvider {
@Override
public Class<? extends IBaseResource> getResourceType() {
return Patient.class;
}
@Read
public Patient opTypeRetOldBundle(@IdParam IdDt theId) {
return null;
}
}
public static class OperationProvider implements IResourceProvider {
@Override
@ -71,8 +99,8 @@ public class ServerUsingOldTypesDstu21Test {
return Patient.class;
}
@Operation(name="foo")
public Patient opTypeRetOldBundle(@OperationParam(name="foo") IntegerDt theId) {
@Operation(name = "foo")
public Patient opTypeRetOldBundle(@OperationParam(name = "foo") IntegerDt theId) {
return null;
}

View File

@ -57,6 +57,7 @@ import org.hl7.fhir.instance.model.Conformance.TypeRestfulInteraction;
import org.hl7.fhir.instance.model.Conformance.UnknownContentCode;
import org.hl7.fhir.instance.model.Enumerations.ConformanceResourceStatus;
import org.hl7.fhir.instance.model.Enumerations.ResourceType;
import org.hl7.fhir.instance.model.IdType;
import org.hl7.fhir.instance.model.OperationDefinition;
import org.hl7.fhir.instance.model.OperationDefinition.OperationDefinitionParameterComponent;
import org.hl7.fhir.instance.model.OperationDefinition.OperationParameterUse;
@ -64,8 +65,6 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Initialize;
import ca.uhn.fhir.rest.annotation.Metadata;
@ -82,7 +81,6 @@ import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.IServerConformanceProvider;
import ca.uhn.fhir.rest.server.ResourceBinding;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
/**
@ -512,7 +510,7 @@ public class ServerConformanceProvider implements IServerConformanceProvider<Con
}
@Read(type = OperationDefinition.class)
public OperationDefinition readOperationDefinition(@IdParam IdDt theId) {
public OperationDefinition readOperationDefinition(@IdParam IdType theId) {
if (theId == null || theId.hasIdPart() == false) {
throw new ResourceNotFoundException(theId);
}

View File

@ -27,12 +27,12 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.hl7.fhir.instance.model.IdType;
import org.hl7.fhir.instance.model.StructureDefinition;
import org.hl7.fhir.instance.model.api.IBaseResource;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
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.Search;
@ -55,7 +55,7 @@ public class ServerProfileProvider implements IResourceProvider {
}
@Read()
public StructureDefinition getProfileById(HttpServletRequest theRequest, @IdParam IdDt theId) {
public StructureDefinition getProfileById(HttpServletRequest theRequest, @IdParam IdType theId) {
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart());
if (retVal==null) {
return null;

View File

@ -20,6 +20,7 @@ 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.hl7.fhir.instance.model.IdType;
import org.hl7.fhir.instance.model.Parameters;
import org.hl7.fhir.instance.model.Patient;
import org.hl7.fhir.instance.model.StringType;
@ -31,7 +32,6 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
@ -52,7 +52,7 @@ public class OperationClientTest {
ourHttpClient = mock(HttpClient.class, new ReturnsDeepStubs());
ourCtx.getRestfulClientFactory().setHttpClient(ourHttpClient);
ourCtx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
ourHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
}
@ -78,7 +78,7 @@ public class OperationClientTest {
int idx = 0;
Parameters response = client.opInstance(new IdDt("222"), new StringType("PARAM1str"), new Patient().setActive(true));
Parameters response = client.opInstance(new IdType("222"), new StringType("PARAM1str"), new Patient().setActive(true));
assertEquals("FOO", response.getParameter().get(0).getName());
HttpPost value = (HttpPost) capt.getAllValues().get(idx);
String requestBody = IOUtils.toString(((HttpPost) value).getEntity().getContent());
@ -273,7 +273,7 @@ public class OperationClientTest {
//@formatter:off
@Operation(name="$OP_INSTANCE", type=Patient.class)
public Parameters opInstance(
@IdParam IdDt theId,
@IdParam IdType theId,
@OperationParam(name="PARAM1") StringType theParam1,
@OperationParam(name="PARAM2") Patient theParam2
);

View File

@ -1,7 +1,9 @@
package ca.uhn.fhir.rest.server;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.util.Collections;
import java.util.List;
@ -21,6 +23,7 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.instance.model.Binary;
import org.hl7.fhir.instance.model.IdType;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.AfterClass;
import org.junit.Before;
@ -28,7 +31,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
@ -205,7 +207,7 @@ public class BinaryHl7OrgDstu2Test {
@Create
public MethodOutcome create(@ResourceParam Binary theBinary) {
ourLast = theBinary;
return new MethodOutcome(new IdDt("1"));
return new MethodOutcome(new IdType("1"));
}
@Override
@ -214,7 +216,7 @@ public class BinaryHl7OrgDstu2Test {
}
@Read
public Binary read(@IdParam IdDt theId) {
public Binary read(@IdParam IdType theId) {
Binary retVal = new Binary();
retVal.setId("1");
retVal.setContent(new byte[] { 1, 2, 3, 4 });

View File

@ -1,6 +1,7 @@
package ca.uhn.fhir.rest.server;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.util.concurrent.TimeUnit;
@ -12,6 +13,7 @@ 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.hl7.fhir.instance.model.IdType;
import org.hl7.fhir.instance.model.Patient;
import org.junit.AfterClass;
import org.junit.Before;
@ -35,7 +37,7 @@ public class DeleteConditionalHl7OrgTest {
private static int ourPort;
private static final FhirContext ourCtx = FhirContext.forDstu2Hl7Org();
private static Server ourServer;
private static IdDt ourLastIdParam;
private static IdType ourLastIdParam;
@ -113,10 +115,10 @@ public class DeleteConditionalHl7OrgTest {
@Delete()
public MethodOutcome updatePatient(@ConditionalUrlParam String theConditional, @IdParam IdDt theIdParam) {
public MethodOutcome updatePatient(@ConditionalUrlParam String theConditional, @IdParam IdType theIdParam) {
ourLastConditionalUrl = theConditional;
ourLastIdParam = theIdParam;
return new MethodOutcome(new IdDt("Patient/001/_history/002"));
return new MethodOutcome(new IdType("Patient/001/_history/002"));
}
}

View File

@ -1,6 +1,7 @@
package ca.uhn.fhir.rest.server;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
import java.util.Date;
@ -20,6 +21,7 @@ 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.hl7.fhir.instance.model.IdType;
import org.hl7.fhir.instance.model.Identifier;
import org.hl7.fhir.instance.model.Patient;
import org.junit.AfterClass;
@ -28,7 +30,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
@ -178,12 +179,12 @@ public class ETagServerHl7OrgTest {
}
private static IdDt ourLastId;
private static IdType ourLastId;
public static class PatientProvider implements IResourceProvider {
@Read(version = true)
public Patient findPatient(@IdParam IdDt theId) {
public Patient findPatient(@IdParam IdType theId) {
Patient patient = new Patient();
patient.getMeta().setLastUpdated(ourLastModifiedDate);
patient.addIdentifier().setSystem(theId.getIdPart()).setValue(theId.getVersionIdPart());
@ -192,7 +193,7 @@ public class ETagServerHl7OrgTest {
}
@Update
public MethodOutcome updatePatient(@IdParam IdDt theId, @ResourceParam Patient theResource) {
public MethodOutcome updatePatient(@IdParam IdType theId, @ResourceParam Patient theResource) {
ourLastId = theId;
if ("222".equals(theId.getVersionIdPart())) {

View File

@ -1,7 +1,11 @@
package ca.uhn.fhir.rest.server;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import java.util.ArrayList;
import java.util.List;
@ -21,6 +25,7 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.instance.model.Bundle;
import org.hl7.fhir.instance.model.IdType;
import org.hl7.fhir.instance.model.IntegerType;
import org.hl7.fhir.instance.model.Parameters;
import org.hl7.fhir.instance.model.Patient;
@ -32,7 +37,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
@ -50,7 +54,7 @@ public class OperationServerHl7OrgTest {
private static Patient ourLastParam2;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(OperationServerHl7OrgTest.class);
private static int ourPort;
private static IdDt ourLastId;
private static IdType ourLastId;
private static Server ourServer;
private static String ourLastMethod;
private static List<StringType> ourLastParam3;
@ -294,7 +298,7 @@ public class OperationServerHl7OrgTest {
@Test
public void testInstanceEverythingHapiClient() throws Exception {
Parameters p = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort).operation().onInstance(new IdDt("Patient/123")).named("$everything").withParameters(new Parameters()).execute();
Parameters p = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort).operation().onInstance(new IdType("Patient/123")).named("$everything").withParameters(new Parameters()).execute();
Bundle b = (Bundle) p.getParameter().get(0).getResource();
assertNotNull(b);
@ -416,7 +420,7 @@ public class OperationServerHl7OrgTest {
* Just to make sure this method doesn't "steal" calls
*/
@Read
public Patient read(@IdParam IdDt theId) {
public Patient read(@IdParam IdType theId) {
ourLastMethod = "read";
Patient retVal = new Patient();
retVal.setId(theId);
@ -424,7 +428,7 @@ public class OperationServerHl7OrgTest {
}
@Operation(name = "$everything", idempotent=true)
public Bundle patientEverything(@IdParam IdDt thePatientId) {
public Bundle patientEverything(@IdParam IdType thePatientId) {
ourLastMethod = "instance $everything";
ourLastId = thePatientId;
return new Bundle();
@ -482,7 +486,7 @@ public class OperationServerHl7OrgTest {
//@formatter:off
@Operation(name="$OP_INSTANCE")
public Parameters opInstance(
@IdParam IdDt theId,
@IdParam IdType theId,
@OperationParam(name="PARAM1") StringType theParam1,
@OperationParam(name="PARAM2") Patient theParam2
) {

View File

@ -1,6 +1,6 @@
package ca.uhn.fhir.rest.server;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.TimeUnit;
@ -15,13 +15,13 @@ 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.hl7.fhir.instance.model.IdType;
import org.hl7.fhir.instance.model.Patient;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.ResourceParam;
@ -103,13 +103,13 @@ public class PreferHl7OrgDstu2Test {
@Create()
public MethodOutcome createPatient(@ResourceParam Patient thePatient) {
MethodOutcome retVal = new MethodOutcome(new IdDt("Patient/001/_history/002"));
MethodOutcome retVal = new MethodOutcome(new IdType("Patient/001/_history/002"));
return retVal;
}
@Update()
public MethodOutcome updatePatient(@ResourceParam Patient thePatient, @IdParam IdDt theIdParam) {
return new MethodOutcome(new IdDt("Patient/001/_history/002"));
public MethodOutcome updatePatient(@ResourceParam Patient thePatient, @IdParam IdType theIdParam) {
return new MethodOutcome(new IdType("Patient/001/_history/002"));
}
}

View File

@ -1,8 +1,13 @@
package ca.uhn.fhir.rest.server;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
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.util.Collection;
import java.util.List;
@ -18,18 +23,18 @@ import org.hl7.fhir.instance.model.Conformance.ConformanceRestComponent;
import org.hl7.fhir.instance.model.Conformance.ConformanceRestResourceComponent;
import org.hl7.fhir.instance.model.Conformance.SystemRestfulInteraction;
import org.hl7.fhir.instance.model.Conformance.TypeRestfulInteraction;
import org.hl7.fhir.instance.model.DateType;
import org.hl7.fhir.instance.model.DiagnosticReport;
import org.hl7.fhir.instance.model.IdType;
import org.hl7.fhir.instance.model.OperationDefinition;
import org.hl7.fhir.instance.model.Patient;
import org.hl7.fhir.instance.model.StringType;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.primitive.DateDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.annotation.ConditionalUrlParam;
import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.Delete;
@ -49,6 +54,7 @@ import ca.uhn.fhir.rest.method.BaseMethodBinding;
import ca.uhn.fhir.rest.method.SearchMethodBinding;
import ca.uhn.fhir.rest.method.SearchParameter;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenOrListParam;
import ca.uhn.fhir.rest.param.TokenParam;
@ -128,7 +134,7 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
rs.init(createServletConfig());
OperationDefinition opDef = sc.readOperationDefinition(new IdDt("OperationDefinition/everything"));
OperationDefinition opDef = sc.readOperationDefinition(new IdType("OperationDefinition/everything"));
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(opDef);
ourLog.info(conf);
@ -263,7 +269,7 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
Conformance sconf = sc.getServerConformance(createHttpServletRequest());
assertEquals("OperationDefinition/plain", sconf.getRest().get(0).getOperation().get(0).getDefinition().getReference());
OperationDefinition opDef = sc.readOperationDefinition(new IdDt("OperationDefinition/plain"));
OperationDefinition opDef = sc.readOperationDefinition(new IdType("OperationDefinition/plain"));
String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(opDef);
ourLog.info(conf);
@ -448,7 +454,7 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
}
@Delete
public MethodOutcome delete(@IdParam IdDt theId, @ConditionalUrlParam String theConditionalUrl) {
public MethodOutcome delete(@IdParam IdType theId, @ConditionalUrlParam String theConditionalUrl) {
return null;
}
@ -458,7 +464,7 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
}
@Update
public MethodOutcome update(@IdParam IdDt theId, @ResourceParam Patient thePatient, @ConditionalUrlParam String theConditionalUrl) {
public MethodOutcome update(@IdParam IdType theId, @ResourceParam Patient thePatient, @ConditionalUrlParam String theConditionalUrl) {
return null;
}
@ -471,7 +477,7 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
}
@History
public List<IBaseResource> history(@IdParam IdDt theId) {
public List<IBaseResource> history(@IdParam IdType theId) {
return null;
}
@ -483,7 +489,7 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
public static class MultiOptionalProvider {
@Search(type = Patient.class)
public Patient findPatient(@Description(shortDefinition = "The patient's identifier") @OptionalParam(name = Patient.SP_IDENTIFIER) TokenParam theIdentifier, @Description(shortDefinition = "The patient's name") @OptionalParam(name = Patient.SP_NAME) StringDt theName) {
public Patient findPatient(@Description(shortDefinition = "The patient's identifier") @OptionalParam(name = Patient.SP_IDENTIFIER) TokenParam theIdentifier, @Description(shortDefinition = "The patient's name") @OptionalParam(name = Patient.SP_NAME) StringParam theName) {
return null;
}
@ -497,7 +503,7 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
}
@Delete
public MethodOutcome delete(@IdParam IdDt theId) {
public MethodOutcome delete(@IdParam IdType theId) {
return null;
}
@ -507,7 +513,7 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
}
@Update
public MethodOutcome update(@IdParam IdDt theId, @ResourceParam Patient thePatient) {
public MethodOutcome update(@IdParam IdType theId, @ResourceParam Patient thePatient) {
return null;
}
@ -516,9 +522,9 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
public static class PlainProviderWithExtendedOperationOnNoType {
@Operation(name = "plain", idempotent = true, returnParameters= {
@OperationParam(min=1, max=2, name="out1", type=StringDt.class)
@OperationParam(min=1, max=2, name="out1", type=StringType.class)
})
public ca.uhn.fhir.rest.server.IBundleProvider everything(javax.servlet.http.HttpServletRequest theServletRequest, @IdParam ca.uhn.fhir.model.primitive.IdDt theId, @OperationParam(name = "start") DateDt theStart, @OperationParam(name = "end") DateDt theEnd) {
public ca.uhn.fhir.rest.server.IBundleProvider everything(javax.servlet.http.HttpServletRequest theServletRequest, @IdParam IdType theId, @OperationParam(name = "start") DateType theStart, @OperationParam(name = "end") DateType theEnd) {
return null;
}
@ -527,7 +533,7 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
public static class ProviderWithExtendedOperationReturningBundle implements IResourceProvider {
@Operation(name = "everything", idempotent = true)
public ca.uhn.fhir.rest.server.IBundleProvider everything(javax.servlet.http.HttpServletRequest theServletRequest, @IdParam ca.uhn.fhir.model.primitive.IdDt theId, @OperationParam(name = "start") DateDt theStart, @OperationParam(name = "end") DateDt theEnd) {
public ca.uhn.fhir.rest.server.IBundleProvider everything(javax.servlet.http.HttpServletRequest theServletRequest, @IdParam IdType theId, @OperationParam(name = "start") DateType theStart, @OperationParam(name = "end") DateType theEnd) {
return null;
}
@ -560,7 +566,7 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
}
@Read(version = false)
public Patient readPatient(@IdParam IdDt theId) {
public Patient readPatient(@IdParam IdType theId) {
return null;
}
@ -612,7 +618,7 @@ public class ServerConformanceProviderHl7OrgDstu2Test {
}
@Read(version = true)
public Patient readPatient(@IdParam IdDt theId) {
public Patient readPatient(@IdParam IdType theId) {
return null;
}

View File

@ -1,50 +1,56 @@
package ca.uhn.fhir.rest.server;
import static org.junit.Assert.*;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import javax.servlet.ServletException;
import org.hamcrest.core.StringContains;
import org.hl7.fhir.instance.model.Patient;
import org.hl7.fhir.instance.model.StringType;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
public class ServerInvalidDefinitionHl7OrgDstu2Test {
private static FhirContext ourCtx = FhirContext.forDstu2Hl7Org();
private static FhirContext ourCtx = FhirContext.forDstu2Hl7Org();
@Test
public void testOperationReturningOldBundleProvider() {
RestfulServer srv = new RestfulServer(ourCtx);
srv.setFhirContext(ourCtx);
srv.setResourceProviders(new OperationReturningOldBundleProvider());
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory
.getLogger(ServerInvalidDefinitionHl7OrgDstu2Test.class);
try {
srv.init();
fail();
} catch (ServletException e) {
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
assertThat(e.getCause().toString(), StringContains.containsString("Can not return a DSTU1 bundle"));
}
}
@Test
public void testOperationReturningOldBundleProvider() {
RestfulServer srv = new RestfulServer(ourCtx);
srv.setFhirContext(ourCtx);
srv.setResourceProviders(new OperationReturningOldBundleProvider());
public static class OperationReturningOldBundleProvider implements IResourceProvider {
try {
srv.init();
fail();
} catch (ServletException e) {
ourLog.info(e.getCause().toString());
assertThat(e.getCause().toString(), StringContains.containsString("ConfigurationException"));
assertThat(e.getCause().toString(), StringContains.containsString("Can not return a DSTU1 bundle"));
}
}
@Override
public Class<? extends IBaseResource> getResourceType() {
return Patient.class;
}
public static class OperationReturningOldBundleProvider implements IResourceProvider {
@Operation(name = "$OP_TYPE_RET_OLD_BUNDLE")
public ca.uhn.fhir.model.api.Bundle opTypeRetOldBundle(@OperationParam(name = "PARAM1") StringDt theParam1, @OperationParam(name = "PARAM2") Patient theParam2) {
return null;
}
@Override
public Class<? extends IBaseResource> getResourceType() {
return Patient.class;
}
}
@Operation(name = "$OP_TYPE_RET_OLD_BUNDLE")
public ca.uhn.fhir.model.api.Bundle opTypeRetOldBundle(@OperationParam(name = "PARAM1") StringType theParam1,
@OperationParam(name = "PARAM2") Patient theParam2) {
return null;
}
}
}

View File

@ -1,6 +1,8 @@
package ca.uhn.fhir.rest.server;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
@ -27,7 +29,6 @@ import org.junit.Test;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.annotation.ConditionalUrlParam;
import ca.uhn.fhir.rest.annotation.IdParam;
@ -49,7 +50,7 @@ public class UpdateConditionalHl7OrgDstu2Test {
private static FhirContext ourCtx = FhirContext.forDstu2Hl7Org();
private static Server ourServer;
private static String ourLastId;
private static IdDt ourLastIdParam;
private static IdType ourLastIdParam;
private static boolean ourLastRequestWasSearch;
@ -179,11 +180,11 @@ public class UpdateConditionalHl7OrgDstu2Test {
}
@Update()
public MethodOutcome updatePatient(@ResourceParam Patient thePatient, @ConditionalUrlParam String theConditional, @IdParam IdDt theIdParam) {
public MethodOutcome updatePatient(@ResourceParam Patient thePatient, @ConditionalUrlParam String theConditional, @IdParam IdType theIdParam) {
ourLastConditionalUrl = theConditional;
ourLastId = thePatient.getId();
ourLastIdParam = theIdParam;
return new MethodOutcome(new IdDt("Patient/001/_history/002"));
return new MethodOutcome(new IdType("Patient/001/_history/002"));
}
}

View File

@ -80,7 +80,6 @@ cp $FHIRTRUNK/build/implementations/java/org.hl7.fhir.$PACKAGEVERSION/src/org/hl
cp $FHIRTRUNK/build/implementations/java/org.hl7.fhir.$PACKAGEVERSION/src/org/hl7/fhir/$PACKAGEVERSION/utils/INarrativeGenerator.java hapi-fhir-structures-$PROJVERSION/src/main/java/org/hl7/fhir/$PACKAGEVERSION/utils/
cp $FHIRTRUNK/build/implementations/java/org.hl7.fhir.$PACKAGEVERSION/src/org/hl7/fhir/$PACKAGEVERSION/utils/EOperationOutcome.java hapi-fhir-structures-$PROJVERSION/src/main/java/org/hl7/fhir/$PACKAGEVERSION/utils/
cp $FHIRTRUNK/build/implementations/java/org.hl7.fhir.$PACKAGEVERSION/src/org/hl7/fhir/$PACKAGEVERSION/utils/FHIRPathEngine.java hapi-fhir-structures-$PROJVERSION/src/main/java/org/hl7/fhir/$PACKAGEVERSION/utils/
cp $FHIRTRUNK/build/implementations/java/org.hl7.fhir.$PACKAGEVERSION/src/org/hl7/fhir/$PACKAGEVERSION/utils/ProfileUtilities.java hapi-fhir-structures-$PROJVERSION/src/main/java/org/hl7/fhir/$PACKAGEVERSION/utils/
# Validation
cp $FHIRTRUNK/build/implementations/java/org.hl7.fhir.$PACKAGEVERSION/src/org/hl7/fhir/$PACKAGEVERSION/validation/* hapi-fhir-structures-$PROJVERSION/src/main/java/org/hl7/fhir/$PACKAGEVERSION/validation/