Switch public server to use CapabilityStatement for metadata return type

This commit is contained in:
James Agnew 2016-12-20 15:35:54 -05:00
parent 18e47c2130
commit 750d6d4655
4 changed files with 75 additions and 54 deletions

View File

@ -29,6 +29,8 @@ import java.lang.reflect.WildcardType;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.Validate;
import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.ConfigurationException;
import javassist.Modifier; import javassist.Modifier;
@ -131,6 +133,7 @@ public class ReflectionUtil {
*/ */
@CoverageIgnore @CoverageIgnore
public static <T> T newInstance(Class<T> theType) { public static <T> T newInstance(Class<T> theType) {
Validate.notNull(theType, "theType must not be null");
try { try {
return theType.newInstance(); return theType.newInstance();
} catch (Exception e) { } catch (Exception e) {

View File

@ -25,17 +25,8 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.CodeType; import org.hl7.fhir.dstu3.model.CapabilityStatement.*;
import org.hl7.fhir.dstu3.model.Conformance;
import org.hl7.fhir.dstu3.model.DecimalType;
import org.hl7.fhir.dstu3.model.Extension;
import org.hl7.fhir.dstu3.model.Meta;
import org.hl7.fhir.dstu3.model.Conformance.ConditionalDeleteStatus;
import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestComponent;
import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestResourceComponent;
import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestResourceSearchParamComponent;
import org.hl7.fhir.dstu3.model.Conformance.ResourceVersionPolicy;
import org.hl7.fhir.dstu3.model.Enumerations.SearchParamType; import org.hl7.fhir.dstu3.model.Enumerations.SearchParamType;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
@ -43,14 +34,13 @@ import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.jpa.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.dao.IFhirSystemDao;
import ca.uhn.fhir.jpa.entity.ResourceEncodingEnum;
import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.util.CoverageIgnore; import ca.uhn.fhir.util.CoverageIgnore;
import ca.uhn.fhir.util.ExtensionConstants; import ca.uhn.fhir.util.ExtensionConstants;
public class JpaConformanceProviderDstu3 extends org.hl7.fhir.dstu3.hapi.rest.server.ServerConformanceProvider { public class JpaConformanceProviderDstu3 extends org.hl7.fhir.dstu3.hapi.rest.server.ServerCapabilityStatementProvider {
private volatile Conformance myCachedValue; private volatile CapabilityStatement myCachedValue;
private DaoConfig myDaoConfig; private DaoConfig myDaoConfig;
private String myImplementationDescription; private String myImplementationDescription;
private RestfulServer myRestfulServer; private RestfulServer myRestfulServer;
@ -77,17 +67,17 @@ public class JpaConformanceProviderDstu3 extends org.hl7.fhir.dstu3.hapi.rest.se
} }
@Override @Override
public Conformance getServerConformance(HttpServletRequest theRequest) { public CapabilityStatement getServerConformance(HttpServletRequest theRequest) {
Conformance retVal = myCachedValue; CapabilityStatement retVal = myCachedValue;
Map<String, Long> counts = mySystemDao.getResourceCounts(); Map<String, Long> counts = mySystemDao.getResourceCounts();
FhirContext ctx = myRestfulServer.getFhirContext(); FhirContext ctx = myRestfulServer.getFhirContext();
retVal = super.getServerConformance(theRequest); retVal = super.getServerConformance(theRequest);
for (ConformanceRestComponent nextRest : retVal.getRest()) { for (CapabilityStatementRestComponent nextRest : retVal.getRest()) {
for (ConformanceRestResourceComponent nextResource : nextRest.getResource()) { for (CapabilityStatementRestResourceComponent nextResource : nextRest.getResource()) {
nextResource.setVersioning(ResourceVersionPolicy.VERSIONEDUPDATE); nextResource.setVersioning(ResourceVersionPolicy.VERSIONEDUPDATE);
@ -103,15 +93,15 @@ public class JpaConformanceProviderDstu3 extends org.hl7.fhir.dstu3.hapi.rest.se
} }
// Add chained params // Add chained params
for (ConformanceRestResourceSearchParamComponent nextParam : nextResource.getSearchParam()) { for (CapabilityStatementRestResourceSearchParamComponent nextParam : nextResource.getSearchParam()) {
if (nextParam.getType() == SearchParamType.REFERENCE) { if (nextParam.getType() == SearchParamType.REFERENCE) {
List<CodeType> targets = nextParam.getTarget(); // List<CodeType> targets = nextParam.getTarget();
for (CodeType next : targets) { // for (CodeType next : targets) {
RuntimeResourceDefinition def = ctx.getResourceDefinition(next.getValue()); // RuntimeResourceDefinition def = ctx.getResourceDefinition(next.getValue());
for (RuntimeSearchParam nextChainedParam : def.getSearchParams()) { // for (RuntimeSearchParam nextChainedParam : def.getSearchParams()) {
nextParam.addChain(nextChainedParam.getName()); // nextParam.addChain(nextChainedParam.getName());
} // }
} // }
} }
} }
@ -128,7 +118,7 @@ public class JpaConformanceProviderDstu3 extends org.hl7.fhir.dstu3.hapi.rest.se
/** /**
* Subclasses may override * Subclasses may override
*/ */
protected void massage(Conformance theStatement) { protected void massage(CapabilityStatement theStatement) {
// nothing // nothing
} }

View File

@ -60,18 +60,18 @@ public class FhirTesterConfig {
.withFhirVersion(FhirVersionEnum.DSTU1) .withFhirVersion(FhirVersionEnum.DSTU1)
.withBaseUrl("http://fhirtest.uhn.ca/baseDstu1") .withBaseUrl("http://fhirtest.uhn.ca/baseDstu1")
.withName("UHN/HAPI Server (DSTU1 FHIR)") .withName("UHN/HAPI Server (DSTU1 FHIR)")
.addServer() // .addServer()
.withId("tdl_d2") // .withId("tdl_d2")
.withFhirVersion(FhirVersionEnum.DSTU2) // .withFhirVersion(FhirVersionEnum.DSTU2)
.withBaseUrl("http://fhirtest.uhn.ca/testDataLibraryDstu2") // .withBaseUrl("http://fhirtest.uhn.ca/testDataLibraryDstu2")
.withName("Test Data Library (DSTU2 FHIR)") // .withName("Test Data Library (DSTU2 FHIR)")
.allowsApiKey() // .allowsApiKey()
.addServer() // .addServer()
.withId("tdl_d3") // .withId("tdl_d3")
.withFhirVersion(FhirVersionEnum.DSTU3) // .withFhirVersion(FhirVersionEnum.DSTU3)
.withBaseUrl("http://fhirtest.uhn.ca/testDataLibraryStu3") // .withBaseUrl("http://fhirtest.uhn.ca/testDataLibraryStu3")
.withName("Test Data Library (DSTU3 FHIR)") // .withName("Test Data Library (DSTU3 FHIR)")
.allowsApiKey() // .allowsApiKey()
.addServer() .addServer()
.withId("hi2") .withId("hi2")
.withFhirVersion(FhirVersionEnum.DSTU2) .withFhirVersion(FhirVersionEnum.DSTU2)

View File

@ -16,20 +16,11 @@ import java.util.List;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.hamcrest.core.StringContains; import org.hamcrest.core.StringContains;
import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.Coding;
import org.hl7.fhir.dstu3.model.Condition;
import org.hl7.fhir.dstu3.model.Condition.ConditionClinicalStatus; import org.hl7.fhir.dstu3.model.Condition.ConditionClinicalStatus;
import org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus; import org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus;
import org.hl7.fhir.dstu3.model.DateType;
import org.hl7.fhir.dstu3.model.EligibilityResponse;
import org.hl7.fhir.dstu3.model.EligibilityResponse.BenefitComponent; import org.hl7.fhir.dstu3.model.EligibilityResponse.BenefitComponent;
import org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus; import org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus;
import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Reference;
import org.hl7.fhir.dstu3.model.StringType;
import org.hl7.fhir.dstu3.model.UnsignedIntType;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -40,11 +31,7 @@ import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.parser.StrictErrorHandler; import ca.uhn.fhir.parser.StrictErrorHandler;
import ca.uhn.fhir.parser.XmlParserDstu3Test; import ca.uhn.fhir.parser.XmlParserDstu3Test;
import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.TestUtil;
import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.*;
import ca.uhn.fhir.validation.ResultSeverityEnum;
import ca.uhn.fhir.validation.SchemaBaseValidator;
import ca.uhn.fhir.validation.SingleValidationMessage;
import ca.uhn.fhir.validation.ValidationResult;
import ca.uhn.fhir.validation.schematron.SchematronBaseValidator; import ca.uhn.fhir.validation.schematron.SchematronBaseValidator;
public class ResourceValidatorDstu3Test { public class ResourceValidatorDstu3Test {
@ -358,5 +345,46 @@ public class ResourceValidatorDstu3Test {
// we should get some results, not an exception // we should get some results, not an exception
assertEquals(4, result.getMessages().size()); assertEquals(4, result.getMessages().size());
} }
/**
* TODO: re-enable this
*/
@Test
@Ignore
public void testValidateQuestionnaireWithCanonicalUrl() {
String input = "{\n" +
" \"resourceType\": \"Questionnaire\",\n" +
" \"url\": \"http://some.example.url\",\n" +
" \"status\": \"published\",\n" +
" \"subjectType\": [\n" +
" \"Patient\"\n" +
" ],\n" +
" \"item\": [\n" +
" {\n" +
" \"linkId\": \"example-question\",\n" +
" \"text\": \"Is the sky blue?\",\n" +
" \"type\": \"choice\",\n" +
" \"options\": {\n" +
" \"reference\": \"http://loinc.org/vs/LL3044-6\"\n" +
" }\n" +
" }\n" +
" ]\n" +
"}";
Questionnaire q = new Questionnaire();
q = ourCtx.newJsonParser().parseResource(Questionnaire.class, input);
FhirValidator val = ourCtx.newValidator();
val.registerValidatorModule(new SchemaBaseValidator(ourCtx));
val.registerValidatorModule(new SchematronBaseValidator(ourCtx));
val.registerValidatorModule(new FhirInstanceValidator());
ValidationResult result = val.validateWithResult(q);
OperationOutcome operationOutcome = (OperationOutcome) result.toOperationOutcome();
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome);
ourLog.info(encoded);
}
} }