This commit is contained in:
jamesagnew 2015-05-07 21:24:52 -04:00
parent dfbe2415d1
commit 8e81b069af
18 changed files with 42 additions and 55 deletions

View File

@ -9,13 +9,11 @@ import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt;
import ca.uhn.fhir.model.dstu2.composite.CodingDt;
import ca.uhn.fhir.model.dstu2.composite.HumanNameDt;
import ca.uhn.fhir.model.dstu2.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu2.composite.PeriodDt;
import ca.uhn.fhir.model.dstu2.composite.QuantityDt;
import ca.uhn.fhir.model.dstu2.resource.Observation;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
import ca.uhn.fhir.model.dstu2.valueset.MaritalStatusCodesEnum;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.primitive.StringDt;

View File

@ -3,11 +3,13 @@ package example;
import java.util.ArrayList;
import java.util.List;
import org.hl7.fhir.instance.model.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.model.base.resource.BaseConformance;
import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.model.dstu2.resource.Conformance;
import ca.uhn.fhir.model.dstu2.resource.Observation;
import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu2.resource.Organization;
@ -170,7 +172,7 @@ public class GenericClientExample {
// START SNIPPET: conformance
// Retrieve the server's conformance statement and print its
// description
BaseConformance conf = client.conformance();
Conformance conf = client.fetchConformance().ofType(Conformance.class).execute();
System.out.println(conf.getDescriptionElement().getValue());
// END SNIPPET: conformance
}
@ -273,7 +275,7 @@ public class GenericClientExample {
// .. populate this list - note that you can also pass in a populated
// Bundle if you want to create one manually ..
List<IResource> response = client.transaction().withResources(resources).execute();
List<IBaseResource> response = client.transaction().withResources(resources).execute();
// END SNIPPET: transaction
}

View File

@ -6,7 +6,6 @@ import java.util.List;
import org.hl7.fhir.instance.model.IBaseResource;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.Organization;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
@ -20,7 +19,7 @@ public class IncludesExamples {
}
private static void testSearchForPatients() {
List<IResource> resources = new IncludesExamples().searchForPatients();
List<IBaseResource> resources = new IncludesExamples().searchForPatients();
// Create a bundle with both
FhirContext ctx = FhirContext.forDstu2();
@ -36,7 +35,7 @@ public class IncludesExamples {
// START SNIPPET: addIncludes
@Search
private List<IResource> searchForPatients() {
private List<IBaseResource> searchForPatients() {
// Create an organization
Organization org = new Organization();
org.setId("Organization/65546");
@ -49,7 +48,7 @@ public class IncludesExamples {
patient.getManagingOrganization().setResource(org);
// Here we return only the patient object, which has links to other resources
List<IResource> retVal = new ArrayList<IResource>();
List<IBaseResource> retVal = new ArrayList<IBaseResource>();
retVal.add(patient);
return retVal;
}

View File

@ -2,6 +2,8 @@ package example;
import java.util.List;
import org.hl7.fhir.instance.model.IBaseResource;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.primitive.InstantDt;
@ -43,7 +45,7 @@ public class PagingPatientProvider implements IResourceProvider {
}
@Override
public List<IResource> getResources(int theFromIndex, int theToIndex) {
public List<IBaseResource> getResources(int theFromIndex, int theToIndex) {
int end = Math.max(theToIndex, matchingResourceIds.size() - 1);
List<Long> idsToReturn = matchingResourceIds.subList(theFromIndex, end);
return loadResourcesByIds(idsToReturn);
@ -65,7 +67,7 @@ public class PagingPatientProvider implements IResourceProvider {
/**
* Load a list of patient resources given their IDs
*/
private List<IResource> loadResourcesByIds(List<Long> theIdsToReturn) {
private List<IBaseResource> loadResourcesByIds(List<Long> theIdsToReturn) {
// .. implement this search against the database ..
return null;
}

View File

@ -8,7 +8,6 @@ import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.hl7.fhir.instance.model.IBaseResource;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.Patient;
import ca.uhn.fhir.model.dstu2.valueset.ContactPointSystemEnum;
import ca.uhn.fhir.validation.FhirValidator;

View File

@ -593,7 +593,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
return resp;
}
protected IResource parseResourceBody(String theResourceBody) {
protected IBaseResource parseResourceBody(String theResourceBody) {
EncodingEnum encoding = MethodUtil.detectEncodingNoDefault(theResourceBody);
if (encoding == null) {
throw new InvalidRequestException("FHIR client can't determine resource encoding");
@ -1622,7 +1622,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
*/
if (getParamEncoding() != null) {
if (MethodUtil.detectEncodingNoDefault(myRawBundle) != getParamEncoding()) {
IResource parsed = parseResourceBody(myRawBundle);
IBaseResource parsed = parseResourceBody(myRawBundle);
myRawBundle = getParamEncoding().newParser(getFhirContext()).encodeResourceToString(parsed);
}
}

View File

@ -20,9 +20,8 @@ package ca.uhn.fhir.rest.method;
* #L%
*/
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
@ -278,7 +277,7 @@ abstract class BaseOutcomeReturningMethodBinding extends BaseMethodBinding<Metho
/**
* @throws IOException
*/
protected IResource parseIncomingServerResource(Request theRequest) throws IOException {
protected IBaseResource parseIncomingServerResource(Request theRequest) throws IOException {
Reader requestReader;
EncodingEnum encoding = RestfulServerUtils.determineRequestEncodingNoDefault(theRequest);

View File

@ -25,6 +25,7 @@ import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.instance.model.IBaseResource;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
@ -161,7 +162,7 @@ public class FhirValidator {
* The resource to validate
* @throws ValidationFailureException
* If the validation fails
* @deprecated use {@link #validateWithResult(ca.uhn.fhir.model.api.IResource)} instead
* @deprecated use {@link #validateWithResult(IBaseResource)} instead
*/
@Deprecated
public void validate(IResource theResource) throws ValidationFailureException {
@ -199,10 +200,10 @@ public class FhirValidator {
* @return the results of validation
* @since 0.7
*/
public ValidationResult validateWithResult(IResource theResource) {
public ValidationResult validateWithResult(IBaseResource theResource) {
Validate.notNull(theResource, "theResource must not be null");
ValidationContext<IResource> ctx = ValidationContext.forResource(myContext, theResource);
ValidationContext<IBaseResource> ctx = ValidationContext.forResource(myContext, theResource);
for (IValidator next : myValidators) {
next.validateResource(ctx);

View File

@ -1,7 +1,8 @@
package ca.uhn.fhir.validation;
import org.hl7.fhir.instance.model.IBaseResource;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource;
/*
* #%L
@ -26,7 +27,7 @@ import ca.uhn.fhir.model.api.IResource;
interface IValidator {
void validateResource(ValidationContext<IResource> theCtx);
void validateResource(ValidationContext<IBaseResource> theCtx);
void validateBundle(ValidationContext<Bundle> theContext);

View File

@ -39,6 +39,7 @@ import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.apache.commons.io.input.BOMInputStream;
import org.hl7.fhir.instance.model.IBaseResource;
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;
import org.xml.sax.SAXException;
@ -48,7 +49,6 @@ import ca.uhn.fhir.context.ConfigurationException;
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.base.resource.BaseOperationOutcome.BaseIssue;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@ -155,7 +155,7 @@ class SchemaBaseValidator implements IValidator {
}
@Override
public void validateResource(ValidationContext<IResource> theContext) {
public void validateResource(ValidationContext<IBaseResource> theContext) {
doValidate(theContext, "fhir-single.xsd");
}

View File

@ -34,7 +34,6 @@ import org.oclc.purl.dsdl.svrl.SchematronOutputType;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.BundleEntry;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.base.resource.BaseOperationOutcome.BaseIssue;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@ -54,7 +53,7 @@ public class SchematronBaseValidator implements IValidator {
}
@Override
public void validateResource(ValidationContext<IResource> theCtx) {
public void validateResource(ValidationContext<IBaseResource> theCtx) {
ISchematronResource sch = getSchematron(theCtx);
StreamSource source = new StreamSource(new StringReader(theCtx.getXmlEncodedResource()));
@ -92,14 +91,14 @@ public class SchematronBaseValidator implements IValidator {
}
private ISchematronResource getSchematron(ValidationContext<IResource> theCtx) {
Class<? extends IResource> resource = theCtx.getResource().getClass();
private ISchematronResource getSchematron(ValidationContext<IBaseResource> theCtx) {
Class<? extends IBaseResource> resource = theCtx.getResource().getClass();
Class<? extends IBaseResource> baseResourceClass = theCtx.getFhirContext().getResourceDefinition(resource).getBaseDefinition().getImplementingClass();
return getSchematronAndCache(theCtx, "dstu", baseResourceClass);
}
private ISchematronResource getSchematronAndCache(ValidationContext<IResource> theCtx, String theVersion, Class<? extends IBaseResource> theClass) {
private ISchematronResource getSchematronAndCache(ValidationContext<IBaseResource> theCtx, String theVersion, Class<? extends IBaseResource> theClass) {
synchronized (myClassToSchematron) {
ISchematronResource retVal = myClassToSchematron.get(theClass);
if (retVal != null) {
@ -124,7 +123,7 @@ public class SchematronBaseValidator implements IValidator {
public void validateBundle(ValidationContext<Bundle> theContext) {
for (BundleEntry next : theContext.getResource().getEntries()) {
if (next.getResource() != null) {
ValidationContext<IResource> ctx = ValidationContext.newChild(theContext, next.getResource());
ValidationContext<IBaseResource> ctx = ValidationContext.newChild(theContext, next.getResource());
validateResource(ctx);
}
}

View File

@ -20,9 +20,10 @@ package ca.uhn.fhir.validation;
* #L%
*/
import org.hl7.fhir.instance.model.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.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@ -76,8 +77,8 @@ private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger
});
}
public static ValidationContext<IResource> forResource(final FhirContext theContext, final IResource theResource) {
return new ValidationContext<IResource>(theContext, theResource, new IEncoder() {
public static <T extends IBaseResource> ValidationContext<T> forResource(final FhirContext theContext, final T theResource) {
return new ValidationContext<T>(theContext, theResource, new IEncoder() {
@Override
public String encode() {
return theContext.newXmlParser().encodeResourceToString(theResource);
@ -85,8 +86,8 @@ private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger
});
}
public static ValidationContext<IResource> newChild(ValidationContext<Bundle> theContext, IResource theResource) {
ValidationContext<IResource> retVal = forResource(theContext.getFhirContext(), theResource);
public static ValidationContext<IBaseResource> newChild(ValidationContext<Bundle> theContext, IBaseResource theResource) {
ValidationContext<IBaseResource> retVal = forResource(theContext.getFhirContext(), theResource);
retVal.myOperationOutcome = theContext.getOperationOutcome();
return retVal;
}

View File

@ -2,8 +2,6 @@ package org.hl7.fhir.instance.model;
import org.hl7.fhir.instance.model.api.IIdType;
import ca.uhn.fhir.model.api.TagList;
/*
* #%L
* HAPI FHIR - Core Library

View File

@ -23,10 +23,8 @@ package ca.uhn.fhir.jpa.dao;
import static org.apache.commons.lang3.StringUtils.*;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.instance.model.IBaseResource;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

View File

@ -8,10 +8,6 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
@ -21,7 +17,6 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.builder.CompareToBuilder;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
@ -41,8 +36,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.google.common.net.UrlEscapers;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
@ -388,7 +381,7 @@ public class ResourceProviderDstu2Test {
assertEquals(BundleEntrySearchModeEnum.INCLUDE, found.getEntries().get(1).getResource().getResourceMetadata().get(ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE));
}
//@Test
@Test
public void testSearchWithMissing() throws Exception {
String methodName = "testSearchWithMissing";

View File

@ -8,7 +8,6 @@ import org.apache.commons.io.IOUtils;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.instance.model.IBaseResource;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

View File

@ -1,14 +1,11 @@
package ca.uhn.fhir.rest.client;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
@ -35,7 +32,7 @@ import org.mockito.stubbing.Answer;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.Include;
import ca.uhn.fhir.model.dstu2.resource.Observation;
import ca.uhn.fhir.model.dstu2.resource.Parameters;
import ca.uhn.fhir.model.dstu2.resource.Patient;