Attempt to correct build issues

This commit is contained in:
James Agnew 2016-03-16 18:00:57 -04:00
parent 3922ff026e
commit c8173810f4
8 changed files with 121 additions and 155 deletions

View File

@ -64,14 +64,6 @@ public class BaseDstu3Config extends BaseConfig {
ca.uhn.fhir.jpa.dao.dstu3.JpaValidationSupportDstu3 retVal = new ca.uhn.fhir.jpa.dao.dstu3.JpaValidationSupportDstu3();
return retVal;
}
@Bean(name="myQuestionnaireResponseValidatorDstu3")
@Lazy
public IValidatorModule questionnaireResponseValidatorDstu3() {
FhirQuestionnaireResponseValidator module = new FhirQuestionnaireResponseValidator();
module.setValidationSupport(validationSupportChainDstu3());
return module;
}
@Bean(autowire = Autowire.BY_TYPE)
public IFulltextSearchSvc searchDaoDstu3() {

View File

@ -1,124 +1,65 @@
package ca.uhn.fhir.jpa.dao.dstu3;
/*
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2016 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import javax.annotation.PostConstruct;
import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.dstu3.model.Questionnaire;
import org.hl7.fhir.dstu3.model.QuestionnaireResponse;
import org.hl7.fhir.dstu3.model.ValueSet;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import ca.uhn.fhir.jpa.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.validation.FhirValidator;
import ca.uhn.fhir.validation.IResourceLoader;
import ca.uhn.fhir.validation.IValidatorModule;
import ca.uhn.fhir.validation.ValidationResult;
public class FhirResourceDaoQuestionnaireResponseDstu3 extends FhirResourceDaoDstu3<QuestionnaireResponse> {
private Boolean myValidateResponses;
@Autowired
@Qualifier("myQuestionnaireResponseValidatorDstu3")
private IValidatorModule myQuestionnaireResponseValidatorDstu3;
/**
* Initialize the bean
*/
@PostConstruct
public void initialize() {
try {
Class.forName("org.hl7.fhir.instance.model.QuestionnaireResponse");
myValidateResponses = true;
} catch (ClassNotFoundException e) {
myValidateResponses = Boolean.FALSE;
}
}
@Override
protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) {
super.validateResourceForStorage(theResource, theEntityToSave, theRequestDetails);
if (!myValidateResponses) {
return;
}
if (theResource == null || theResource.getQuestionnaire() == null || theResource.getQuestionnaire().getReference() == null || theResource.getQuestionnaire().getReference().isEmpty()) {
return;
}
FhirValidator val = getContext().newValidator();
val.setValidateAgainstStandardSchema(false);
val.setValidateAgainstStandardSchematron(false);
val.registerValidatorModule(myQuestionnaireResponseValidatorDstu3);
ValidationResult result = val.validateWithResult(getContext().newJsonParser().parseResource(getContext().newJsonParser().encodeResourceToString(theResource)));
if (!result.isSuccessful()) {
IBaseOperationOutcome oo = getContext().newJsonParser().parseResource(OperationOutcome.class, getContext().newJsonParser().encodeResourceToString(result.toOperationOutcome()));
throw new UnprocessableEntityException(getContext(), oo);
}
}
public class JpaResourceLoader implements IResourceLoader {
private RequestDetails myRequestDetails;
public JpaResourceLoader(RequestDetails theRequestDetails) {
super();
myRequestDetails = theRequestDetails;
}
@Override
public <T extends IBaseResource> T load(Class<T> theType, IIdType theId) throws ResourceNotFoundException {
/*
* The QuestionnaireResponse validator uses RI structures, so for now we need to convert between that and HAPI
* structures. This is a bit hackish, but hopefully it will go away at some point.
*/
if ("ValueSet".equals(theType.getSimpleName())) {
IFhirResourceDao<ValueSet> dao = getDao(ValueSet.class);
ValueSet in = dao.read(theId, myRequestDetails);
return (T) in;
} else if ("Questionnaire".equals(theType.getSimpleName())) {
IFhirResourceDao<Questionnaire> dao = getDao(Questionnaire.class);
Questionnaire vs = dao.read(theId, myRequestDetails);
return (T) vs;
} else {
// Should not happen, validator will only ask for these two
throw new IllegalStateException("Unexpected request to load resource of type " + theType);
}
}
}
// @Override
// protected void validateResourceForStorage(QuestionnaireResponse theResource, ResourceTable theEntityToSave, RequestDetails theRequestDetails) {
// super.validateResourceForStorage(theResource, theEntityToSave, theRequestDetails);
// if (!myValidateResponses) {
// return;
// }
//
// if (theResource == null || theResource.getQuestionnaire() == null || theResource.getQuestionnaire().getReference() == null || theResource.getQuestionnaire().getReference().isEmpty()) {
// return;
// }
//
// FhirValidator val = getContext().newValidator();
// val.setValidateAgainstStandardSchema(false);
// val.setValidateAgainstStandardSchematron(false);
//
// val.registerValidatorModule(myQuestionnaireResponseValidatorDstu3);
//
// ValidationResult result = val.validateWithResult(getContext().newJsonParser().parseResource(getContext().newJsonParser().encodeResourceToString(theResource)));
// if (!result.isSuccessful()) {
// IBaseOperationOutcome oo = getContext().newJsonParser().parseResource(OperationOutcome.class, getContext().newJsonParser().encodeResourceToString(result.toOperationOutcome()));
// throw new UnprocessableEntityException(getContext(), oo);
// }
// }
//
// public class JpaResourceLoader implements IResourceLoader {
//
// private RequestDetails myRequestDetails;
//
// public JpaResourceLoader(RequestDetails theRequestDetails) {
// super();
// myRequestDetails = theRequestDetails;
// }
//
// @Override
// public <T extends IBaseResource> T load(Class<T> theType, IIdType theId) throws ResourceNotFoundException {
//
// /*
// * The QuestionnaireResponse validator uses RI structures, so for now we need to convert between that and HAPI
// * structures. This is a bit hackish, but hopefully it will go away at some point.
// */
// if ("ValueSet".equals(theType.getSimpleName())) {
// IFhirResourceDao<ValueSet> dao = getDao(ValueSet.class);
// ValueSet in = dao.read(theId, myRequestDetails);
// return (T) in;
// } else if ("Questionnaire".equals(theType.getSimpleName())) {
// IFhirResourceDao<Questionnaire> dao = getDao(Questionnaire.class);
// Questionnaire vs = dao.read(theId, myRequestDetails);
// return (T) vs;
// } else {
// // Should not happen, validator will only ask for these two
// throw new IllegalStateException("Unexpected request to load resource of type " + theType);
// }
//
// }
//
// }
}

View File

@ -1,5 +1,8 @@
package ca.uhn.fhir.jpa.term;
import static java.util.stream.Collectors.collectingAndThen;
import java.util.Collections;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Set;
@ -71,15 +74,18 @@ public class TerminologySvcImpl implements ITerminologySvc {
@Override
public Set<TermConcept> findCodesAbove(Long theCodeSystemResourcePid, Long theCodeSystemVersionPid, String theCode) {
Stopwatch stopwatch = Stopwatch.createStarted();
TermConcept concept = fetchLoadedCode(theCodeSystemResourcePid, theCodeSystemVersionPid, theCode);
if (concept == null) {
return Collections.emptySet();
}
Set<TermConcept> retVal = new HashSet<TermConcept>();
retVal.add(concept);
fetchParents(concept, retVal);
ourLog.info("Fetched {} codes above code {} in {}ms", retVal.size(), theCode, stopwatch.elapsed(TimeUnit.MILLISECONDS));
ourLog.info("Fetched {} codes above code {} in {}ms", new Object[] { retVal.size(), theCode, stopwatch.elapsed(TimeUnit.MILLISECONDS) });
return retVal;
}
@ -87,15 +93,18 @@ public class TerminologySvcImpl implements ITerminologySvc {
@Override
public Set<TermConcept> findCodesBelow(Long theCodeSystemResourcePid, Long theCodeSystemVersionPid, String theCode) {
Stopwatch stopwatch = Stopwatch.createStarted();
TermConcept concept = fetchLoadedCode(theCodeSystemResourcePid, theCodeSystemVersionPid, theCode);
if (concept == null) {
return Collections.emptySet();
}
Set<TermConcept> retVal = new HashSet<TermConcept>();
retVal.add(concept);
fetchChildren(concept, retVal);
ourLog.info("Fetched {} codes below code {} in {}ms", retVal.size(), theCode, stopwatch.elapsed(TimeUnit.MILLISECONDS));
ourLog.info("Fetched {} codes below code {} in {}ms", new Object[] { retVal.size(), theCode, stopwatch.elapsed(TimeUnit.MILLISECONDS) });
return retVal;
}
@ -131,7 +140,8 @@ public class TerminologySvcImpl implements ITerminologySvc {
myCodeSystemDao.save(newCodeSystem);
} else {
if (!ObjectUtil.equals(codeSystem.getResource().getId(), theCodeSystem.getResource().getId())) {
throw new InvalidRequestException(myContext.getLocalizer().getMessage(TerminologySvcImpl.class, "cannotCreateDuplicateCodeSystemUri", theSystemUri, codeSystem.getResource().getIdDt().getValue()));
throw new InvalidRequestException(
myContext.getLocalizer().getMessage(TerminologySvcImpl.class, "cannotCreateDuplicateCodeSystemUri", theSystemUri, codeSystem.getResource().getIdDt().getValue()));
}
}

View File

@ -9,11 +9,14 @@ import org.apache.commons.dbcp2.BasicDataSource;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import ca.uhn.fhir.jpa.dao.DaoConfig;
import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor;
import ca.uhn.fhir.validation.ResultSeverityEnum;
@Configuration
@EnableTransactionManagement()
@ -65,4 +68,19 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 {
return extraProperties;
}
/**
* Bean which validates incoming requests
*/
@Bean
@Lazy
public RequestValidatingInterceptor requestValidatingInterceptor() {
RequestValidatingInterceptor requestValidator = new RequestValidatingInterceptor();
requestValidator.setFailOnSeverity(ResultSeverityEnum.ERROR);
requestValidator.setAddResponseHeaderOnSeverity(null);
requestValidator.setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
requestValidator.addValidatorModule(instanceValidatorDstu3());
return requestValidator;
}
}

View File

@ -2,6 +2,7 @@ package ca.uhn.fhir.jpa.term;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
@ -100,9 +101,15 @@ public class TerminologySvcImplTest extends BaseJpaDstu3Test {
concepts = myTermSvc.findCodesBelow(id.getIdPartAsLong(), id.getVersionIdPartAsLong(), "childAA");
codes = toCodes(concepts);
assertThat(codes, containsInAnyOrder("childAA", "childAAA", "childAAB"));
}
// Try an unknown code
concepts = myTermSvc.findCodesBelow(id.getIdPartAsLong(), id.getVersionIdPartAsLong(), "FOO_BAD_CODE");
codes = toCodes(concepts);
assertThat(codes, empty());
@Test@Ignore
}
@Test
public void testFindCodesAbove() {
CodeSystem codeSystem = new CodeSystem();
codeSystem.setUrl("http://example.com/my_code_system");
@ -145,6 +152,11 @@ public class TerminologySvcImplTest extends BaseJpaDstu3Test {
concepts = myTermSvc.findCodesAbove(id.getIdPartAsLong(), id.getVersionIdPartAsLong(), "childAAB");
codes = toCodes(concepts);
assertThat(codes, containsInAnyOrder("ParentA", "childAA", "childAAB"));
// Try an unknown code
concepts = myTermSvc.findCodesAbove(id.getIdPartAsLong(), id.getVersionIdPartAsLong(), "FOO_BAD_CODE");
codes = toCodes(concepts);
assertThat(codes, empty());
}
@Test

View File

@ -157,14 +157,12 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.0.1</version>
</dependency>
<!-- Only required for CORS support -->
<dependency>
<groupId>org.ebaysf.web</groupId>
<artifactId>cors-filter</artifactId>
<version>${ebay_cors_filter_version}</version>
</dependency>
</dependencies>

View File

@ -14,6 +14,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
@ -93,12 +94,12 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 {
* Bean which validates incoming requests
*/
@Bean
@Lazy
public RequestValidatingInterceptor requestValidatingInterceptor() {
RequestValidatingInterceptor requestValidator = new RequestValidatingInterceptor();
requestValidator.setFailOnSeverity(ResultSeverityEnum.ERROR);
requestValidator.setAddResponseHeaderOnSeverity(null);
requestValidator.setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum.INFORMATION);
requestValidator.addValidatorModule(questionnaireResponseValidatorDstu3());
requestValidator.addValidatorModule(instanceValidatorDstu3());
return requestValidator;
@ -108,6 +109,7 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 {
* Bean which validates outgoing responses
*/
@Bean
@Lazy
public ResponseValidatingInterceptor responseValidatingInterceptor() {
ResponseValidatingInterceptor responseValidator = new ResponseValidatingInterceptor();
responseValidator.setResponseHeaderValueNoIssues("Validation did not detect any issues");
@ -124,7 +126,6 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 {
responseValidator.addExcludeOperationType(RestOperationTypeEnum.HISTORY_TYPE);
responseValidator.addExcludeOperationType(RestOperationTypeEnum.SEARCH_SYSTEM);
responseValidator.addExcludeOperationType(RestOperationTypeEnum.SEARCH_TYPE);
responseValidator.addValidatorModule(questionnaireResponseValidatorDstu3());
responseValidator.addValidatorModule(instanceValidatorDstu3());
return responseValidator;
}

View File

@ -2,16 +2,14 @@ package ca.uhn.fhirtest;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
import org.hl7.fhir.dstu3.model.Organization;
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.dstu3.model.Subscription;
import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType;
import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus;
import org.hl7.fhir.instance.model.api.IIdType;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.dstu.resource.Organization;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu2.resource.Subscription;
import ca.uhn.fhir.model.dstu2.valueset.SubscriptionChannelTypeEnum;
import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.client.IGenericClient;
@ -20,7 +18,7 @@ public class UhnFhirTestApp {
public static void main(String[] args) throws Exception {
int myPort = 8888;
String base = "http://localhost:" + myPort + "/baseDstu2";
String base = "http://localhost:" + myPort + "/baseDstu3";
// new File("target/testdb").mkdirs();
System.setProperty("fhir.db.location", "./target/testdb");
@ -50,28 +48,24 @@ public class UhnFhirTestApp {
// base = "http://spark.furore.com/fhir";
if (true) {
FhirContext ctx = FhirContext.forDstu2();
FhirContext ctx = FhirContext.forDstu3();
IGenericClient client = ctx.newRestfulGenericClient(base);
// client.setLogRequestAndResponse(true);
Organization o1 = new Organization();
o1.getName().setValue("Some Org");
o1.getNameElement().setValue("Some Org");
MethodOutcome create = client.create().resource(o1).execute();
IdDt orgId = (IdDt) create.getId();
IIdType orgId = (IIdType) create.getId();
Patient p1 = new Patient();
p1.addIdentifier("foo:bar", "12345");
p1.getMeta().addTag("http://hl7.org/fhir/tag", "urn:happytag", "This is a happy resource");
p1.addIdentifier().setSystem("foo:bar").setValue("12345");
p1.addName().addFamily("Smith").addGiven("John");
p1.getManagingOrganization().setReference(orgId);
TagList list = new TagList();
list.addTag("http://hl7.org/fhir/tag", "urn:happytag", "This is a happy resource");
ResourceMetadataKeyEnum.TAG_LIST.put(p1, list);
client.create().resource(p1).execute();
p1.getManagingOrganization().setReferenceElement(orgId);
Subscription subs = new Subscription();
subs.setStatus(SubscriptionStatusEnum.ACTIVE);
subs.getChannel().setType(SubscriptionChannelTypeEnum.WEBSOCKET);
subs.setStatus(SubscriptionStatus.ACTIVE);
subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET);
subs.setCriteria("Observation?");
client.create().resource(subs).execute();