From e1ab2856e07007940f67d568235c180c3071fcb0 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Sun, 8 May 2016 10:29:08 -0400 Subject: [PATCH] Fix build --- .../uhn/fhir/cli/ValidationDataUploader.java | 19 +++++++++++ .../jpa/dao/dstu3/FhirSystemDaoDstu3Test.java | 15 +++----- .../uhn/fhirtest/config/TestDstu3Config.java | 2 +- .../uhn/fhir/rest/server/ReadDstu1Test.java | 5 +-- .../FhirInstanceValidatorDstu3Test.java | 34 +++++++++++++++++++ 5 files changed, 59 insertions(+), 16 deletions(-) diff --git a/hapi-fhir-cli/hapi-fhir-cli-app/src/main/java/ca/uhn/fhir/cli/ValidationDataUploader.java b/hapi-fhir-cli/hapi-fhir-cli-app/src/main/java/ca/uhn/fhir/cli/ValidationDataUploader.java index 2e98ac74e63..6847593b9b4 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-app/src/main/java/ca/uhn/fhir/cli/ValidationDataUploader.java +++ b/hapi-fhir-cli/hapi-fhir-cli-app/src/main/java/ca/uhn/fhir/cli/ValidationDataUploader.java @@ -4,6 +4,8 @@ import static org.apache.commons.lang3.StringUtils.isBlank; import java.io.IOException; import java.io.InputStreamReader; +import java.util.Collections; +import java.util.Comparator; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; @@ -273,6 +275,23 @@ public class ValidationDataUploader extends BaseCommand { bundle = ctx.newXmlParser().parseResource(org.hl7.fhir.dstu3.model.Bundle.class, vsContents); total = bundle.getEntry().size(); count = 1; + + Collections.sort(bundle.getEntry(), new Comparator() { + @Override + public int compare(BundleEntryComponent theO1, BundleEntryComponent theO2) { + if (theO1.getResource() == null && theO2.getResource() == null) { + return 0; + } + if (theO1.getResource() == null) { + return 1; + } + if (theO2.getResource() == null) { + return -1; + } + // StructureDefinition, then OperationDefinition, then CompartmentDefinition + return theO2.getResource().getClass().getName().compareTo(theO1.getResource().getClass().getName()); + }}); + for (BundleEntryComponent i : bundle.getEntry()) { org.hl7.fhir.dstu3.model.Resource next = i.getResource(); next.setId(next.getIdElement().toUnqualifiedVersionless()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java index d8fa2a3b61b..7eecc5d414e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java @@ -511,14 +511,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { myDaoConfig.setAllowInlineMatchUrlReferences(true); - Patient p = new Patient(); - p.addIdentifier().setSystem("urn:system").setValue(methodName); - myPatientDao.create(p, mySrd).getId(); - - p = new Patient(); - p.addIdentifier().setSystem("urn:system").setValue(methodName); - myPatientDao.create(p, mySrd).getId(); - + Observation o = new Observation(); o.getCode().setText("Some Observation"); o.getSubject().setReference("Patient?identifier=urn%3Asystem%7C" + methodName); @@ -527,8 +520,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { try { mySystemDao.transaction(mySrd, request); fail(); - } catch (InvalidRequestException e) { - assertEquals("Invalid match URL \"Patient?identifier=urn%3Asystem%7CtestTransactionCreateInlineMatchUrlWithNoMatches\" - Multiple resources match this search", e.getMessage()); + } catch (ResourceNotFoundException e) { + assertEquals("Invalid match URL \"Patient?identifier=urn%3Asystem%7CtestTransactionCreateInlineMatchUrlWithNoMatches\" - No resources match this search", e.getMessage()); } } @@ -555,7 +548,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { try { mySystemDao.transaction(mySrd, request); fail(); - } catch (InvalidRequestException e) { + } catch (PreconditionFailedException e) { assertEquals("Invalid match URL \"Patient?identifier=urn%3Asystem%7CtestTransactionCreateInlineMatchUrlWithTwoMatches\" - Multiple resources match this search", e.getMessage()); } } diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java index 4aed26d447e..7fba189a175 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/config/TestDstu3Config.java @@ -100,7 +100,7 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 { @Lazy public RequestValidatingInterceptor requestValidatingInterceptor() { RequestValidatingInterceptor requestValidator = new RequestValidatingInterceptor(); - requestValidator.setFailOnSeverity(ResultSeverityEnum.ERROR); + requestValidator.setFailOnSeverity(null); requestValidator.setAddResponseHeaderOnSeverity(null); requestValidator.setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum.INFORMATION); requestValidator.addValidatorModule(instanceValidatorDstu3()); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadDstu1Test.java index 0985f04b289..d9494014f3e 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadDstu1Test.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadDstu1Test.java @@ -33,9 +33,6 @@ import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.util.PortUtil; import ca.uhn.fhir.util.TestUtil; -/** - * Created by dsotnikov on 2/25/2014. - */ public class ReadDstu1Test { private static CloseableHttpClient ourClient; @@ -131,7 +128,7 @@ public class ReadDstu1Test { @Test public void testReadWithEscapedCharsInId() throws Exception { - String id = "ABC!@#$%DEF"; + String id = "ABC!@#$--DEF"; String idEscaped = URLEncoder.encode(id, "UTF-8"); String vid = "GHI:/:/JKL"; diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/FhirInstanceValidatorDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/FhirInstanceValidatorDstu3Test.java index b261c64c87f..ecb7ff8c72e 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/FhirInstanceValidatorDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/FhirInstanceValidatorDstu3Test.java @@ -21,9 +21,13 @@ import java.util.zip.GZIPInputStream; import org.apache.commons.io.IOUtils; import org.hl7.fhir.dstu3.hapi.validation.DefaultProfileValidationSupport; import org.hl7.fhir.dstu3.hapi.validation.FhirInstanceValidator; +import org.hl7.fhir.dstu3.hapi.validation.HapiWorkerContext; import org.hl7.fhir.dstu3.hapi.validation.IValidationSupport; import org.hl7.fhir.dstu3.hapi.validation.IValidationSupport.CodeValidationResult; import org.hl7.fhir.dstu3.hapi.validation.ValidationSupportChain; +import org.hl7.fhir.dstu3.model.Base; +import org.hl7.fhir.dstu3.model.BooleanType; +import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent; @@ -36,6 +40,7 @@ import org.hl7.fhir.dstu3.model.StructureDefinition; import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionComponent; +import org.hl7.fhir.dstu3.utils.FHIRPathEngine; import org.hl7.fhir.instance.model.api.IBaseResource; import org.junit.AfterClass; import org.junit.Before; @@ -97,6 +102,35 @@ public class FhirInstanceValidatorDstu3Test { } + @Test + // @Ignore + public void testValidateBundleWithObservations() throws Exception { + String name = "profiles-resources"; + ourLog.info("Uploading " + name); + String inputString; + inputString = IOUtils.toString(FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/brian_reinhold_bundle.json"), "UTF-8"); + Bundle bundle = ourCtx.newJsonParser().parseResource(Bundle.class, inputString); + + FHIRPathEngine fp = new FHIRPathEngine(new HapiWorkerContext(ourCtx, myDefaultValidationSupport)); + List fpOutput; + BooleanType bool; + + fpOutput = fp.evaluate(bundle.getEntry().get(0), "component.where(code = %resource.code).empty()"); + assertEquals(1, fpOutput.size()); + bool = (BooleanType) fpOutput.get(0); + assertTrue(bool.getValue()); +// +// fpOutput = fp.evaluate(bundle, "component.where(code = %resource.code).empty()"); +// assertEquals(1, fpOutput.size()); +// bool = (BooleanType) fpOutput.get(0); +// assertTrue(bool.getValue()); + + ValidationResult output = myVal.validateWithResult(inputString); + List errors = logResultsAndReturnNonInformationalOnes(output); + assertThat(errors, empty()); + + } + @Test public void testValidateDocument() throws Exception { String vsContents = IOUtils.toString(FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/sample-document.xml"), "UTF-8");