From 3dfb6959c14c7c2dddf16a0b4bdcb565870916ed Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 29 Oct 2019 11:35:26 -0400 Subject: [PATCH 1/2] Don't reload terminology resources when nothing has changed --- .../dstu3/FhirResourceDaoCodeSystemDstu3.java | 11 ++++++---- .../dstu3/FhirResourceDaoConceptMapDstu3.java | 20 ++++++++++--------- .../dstu3/FhirResourceDaoValueSetDstu3.java | 2 +- .../dao/r4/FhirResourceDaoCodeSystemR4.java | 8 +++++--- .../dao/r4/FhirResourceDaoConceptMapR4.java | 12 ++++++----- .../jpa/dao/r4/FhirResourceDaoValueSetR4.java | 2 +- .../dao/r5/FhirResourceDaoCodeSystemR5.java | 8 +++++--- .../dao/r5/FhirResourceDaoConceptMapR5.java | 14 +++++++------ .../jpa/dao/r5/FhirResourceDaoValueSetR5.java | 2 +- 9 files changed, 46 insertions(+), 33 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java index 21a4e28a615..2f92d732643 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java @@ -131,13 +131,16 @@ public class FhirResourceDaoCodeSystemDstu3 extends FhirResourceDaoDstu3 boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequestDetails, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); - if (myDaoConfig.isPreExpandValueSets()) { + if (myDaoConfig.isPreExpandValueSets() && !retVal.isUnchangedInCurrentOperation()) { if (retVal.getDeleted() == null) { try { ValueSet valueSet = (ValueSet) theResource; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCodeSystemR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCodeSystemR4.java index 46d38a2fd06..ce3ddfa992b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCodeSystemR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCodeSystemR4.java @@ -135,10 +135,12 @@ public class FhirResourceDaoCodeSystemR4 extends FhirResourceDaoR4 i boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); - CodeSystem cs = (CodeSystem) theResource; - addPidToResource(theEntity, theResource); + if (!retVal.isUnchangedInCurrentOperation()) { + CodeSystem cs = (CodeSystem) theResource; + addPidToResource(theEntity, theResource); - myTerminologyCodeSystemStorageSvc.storeNewCodeSystemVersionIfNeeded(cs, theEntity); + myTerminologyCodeSystemStorageSvc.storeNewCodeSystemVersionIfNeeded(cs, theEntity); + } return retVal; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoConceptMapR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoConceptMapR4.java index d715b273018..1e2c9c2264b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoConceptMapR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoConceptMapR4.java @@ -160,11 +160,13 @@ public class FhirResourceDaoConceptMapR4 extends FhirResourceDaoR4 i boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequestDetails, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); - if (retVal.getDeleted() == null) { - ConceptMap conceptMap = (ConceptMap) theResource; - myHapiTerminologySvc.storeTermConceptMapAndChildren(retVal, conceptMap); - } else { - myHapiTerminologySvc.deleteConceptMapAndChildren(retVal); + if (!retVal.isUnchangedInCurrentOperation()) { + if (retVal.getDeleted() == null) { + ConceptMap conceptMap = (ConceptMap) theResource; + myHapiTerminologySvc.storeTermConceptMapAndChildren(retVal, conceptMap); + } else { + myHapiTerminologySvc.deleteConceptMapAndChildren(retVal); + } } return retVal; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoValueSetR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoValueSetR4.java index 57db07cf3a7..e938e32a8cc 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoValueSetR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoValueSetR4.java @@ -391,7 +391,7 @@ public class FhirResourceDaoValueSetR4 extends FhirResourceDaoR4 imple boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequestDetails, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); - if (myDaoConfig.isPreExpandValueSets()) { + if (myDaoConfig.isPreExpandValueSets() && !retVal.isUnchangedInCurrentOperation()) { if (retVal.getDeleted() == null) { ValueSet valueSet = (ValueSet) theResource; myHapiTerminologySvc.storeTermValueSet(retVal, valueSet); diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoCodeSystemR5.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoCodeSystemR5.java index fbdea21197e..b8c857cc409 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoCodeSystemR5.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoCodeSystemR5.java @@ -134,11 +134,13 @@ public class FhirResourceDaoCodeSystemR5 extends FhirResourceDaoR5 i public ResourceTable updateEntity(RequestDetails theRequest, IBaseResource theResource, ResourceTable theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequest, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); + if (!retVal.isUnchangedInCurrentOperation()) { - CodeSystem cs = (CodeSystem) theResource; - addPidToResource(theEntity, theResource); + CodeSystem cs = (CodeSystem) theResource; + addPidToResource(theEntity, theResource); - myTerminologyCodeSystemStorageSvc.storeNewCodeSystemVersionIfNeeded(org.hl7.fhir.convertors.conv40_50.CodeSystem.convertCodeSystem(cs), theEntity); + myTerminologyCodeSystemStorageSvc.storeNewCodeSystemVersionIfNeeded(org.hl7.fhir.convertors.conv40_50.CodeSystem.convertCodeSystem(cs), theEntity); + } return retVal; } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoConceptMapR5.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoConceptMapR5.java index ea7b2525463..a9b124d25de 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoConceptMapR5.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoConceptMapR5.java @@ -160,14 +160,16 @@ public class FhirResourceDaoConceptMapR5 extends FhirResourceDaoR5 i public ResourceTable updateEntity(RequestDetails theRequestDetails, IBaseResource theResource, ResourceTable theEntity, Date theDeletedTimestampOrNull, boolean thePerformIndexing, boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequestDetails, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); + if (!retVal.isUnchangedInCurrentOperation()) { - if (retVal.getDeleted() == null) { - ConceptMap conceptMap = (ConceptMap) theResource; - myHapiTerminologySvc.storeTermConceptMapAndChildren(retVal, org.hl7.fhir.convertors.conv40_50.ConceptMap.convertConceptMap(conceptMap)); - } else { - myHapiTerminologySvc.deleteConceptMapAndChildren(retVal); + if (retVal.getDeleted() == null) { + ConceptMap conceptMap = (ConceptMap) theResource; + myHapiTerminologySvc.storeTermConceptMapAndChildren(retVal, org.hl7.fhir.convertors.conv40_50.ConceptMap.convertConceptMap(conceptMap)); + } else { + myHapiTerminologySvc.deleteConceptMapAndChildren(retVal); + } } - + return retVal; } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoValueSetR5.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoValueSetR5.java index ce1cbdcc515..a1adefbd9be 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoValueSetR5.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoValueSetR5.java @@ -403,7 +403,7 @@ public class FhirResourceDaoValueSetR5 extends FhirResourceDaoR5 imple boolean theUpdateVersion, Date theUpdateTime, boolean theForceUpdate, boolean theCreateNewHistoryEntry) { ResourceTable retVal = super.updateEntity(theRequestDetails, theResource, theEntity, theDeletedTimestampOrNull, thePerformIndexing, theUpdateVersion, theUpdateTime, theForceUpdate, theCreateNewHistoryEntry); - if (myDaoConfig.isPreExpandValueSets()) { + if (myDaoConfig.isPreExpandValueSets() && !retVal.isUnchangedInCurrentOperation()) { if (retVal.getDeleted() == null) { ValueSet valueSet = (ValueSet) theResource; myHapiTerminologySvc.storeTermValueSet(retVal, org.hl7.fhir.convertors.conv40_50.ValueSet.convertValueSet(valueSet)); From 84803a02ef1f2e72a98a7a576c9932cbe614b29e Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 29 Oct 2019 15:54:49 -0400 Subject: [PATCH 2/2] Preserve line numbers in XML validation (#1567) * Preserve line numbers in XML validation * Test fixes --- .../jpa/provider/dstu3/ResourceProviderDstu3Test.java | 10 ++-------- .../fhir/jpa/provider/r4/ResourceProviderR4Test.java | 4 +--- .../fhir/common/hapi/validation/ValidatorWrapper.java | 6 +++++- .../r4/validation/FhirInstanceValidatorR4Test.java | 2 ++ src/site/xdoc/download.xml.vm | 10 ++++++++++ 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java index 0439df50d23..69a03290a8a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java @@ -4080,22 +4080,16 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { Patient patient = new Patient(); patient.addName().addGiven("James"); patient.setBirthDateElement(new DateType("2011-02-02")); - patient.addContact().setGender(AdministrativeGender.MALE); String inputStr = myFhirCtx.newXmlParser().encodeResourceToString(patient); HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate"); post.setEntity(new StringEntity(inputStr, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); - CloseableHttpResponse response = ourHttpClient.execute(post); - try { + try (CloseableHttpResponse response = ourHttpClient.execute(post)) { String resp = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); ourLog.info(resp); - assertEquals(412, response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); assertThat(resp, not(containsString("Resource has no id"))); - assertThat(resp, containsString("")); - } finally { - IOUtils.closeQuietly(response.getEntity().getContent()); - response.close(); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index d4ce979de70..ca67457117f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -5308,7 +5308,6 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient patient = new Patient(); patient.addName().addGiven("James"); patient.setBirthDateElement(new DateType("2011-02-02")); - patient.addContact().setGender(AdministrativeGender.MALE); String inputStr = myFhirCtx.newXmlParser().encodeResourceToString(patient); HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate"); @@ -5317,9 +5316,8 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { try (CloseableHttpResponse response = ourHttpClient.execute(post)) { String resp = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); ourLog.info(resp); - assertEquals(412, response.getStatusLine().getStatusCode()); + assertEquals(200, response.getStatusLine().getStatusCode()); assertThat(resp, not(containsString("Resource has no id"))); - assertThat(resp, containsString("")); } } diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/ValidatorWrapper.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/ValidatorWrapper.java index 27ddb19b07f..61f1358ec1b 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/ValidatorWrapper.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/ValidatorWrapper.java @@ -111,7 +111,11 @@ public class ValidatorWrapper { profileSet.getCanonical().add(new ValidationProfileSet.ProfileRegistration(nextProfile, true)); } - v.validate(null, messages, document, profileSet); + String resourceAsString = theValidationContext.getResourceAsString(); + InputStream inputStream = new ReaderInputStream(new StringReader(resourceAsString), Charsets.UTF_8); + + Manager.FhirFormat format = Manager.FhirFormat.XML; + v.validate(null, messages, inputStream, format, profileSet); } else if (encoding == EncodingEnum.JSON) { diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java index 881f0e95d7d..a9f9cbdda01 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java @@ -799,6 +799,8 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ourLog.info(output.getMessages().get(0).getMessage()); assertEquals("/f:Patient", output.getMessages().get(0).getLocationString()); assertEquals("Undefined element 'foo'", output.getMessages().get(0).getMessage()); + assertEquals(28, output.getMessages().get(0).getLocationCol().intValue()); + assertEquals(4, output.getMessages().get(0).getLocationLine().intValue()); } @Test diff --git a/src/site/xdoc/download.xml.vm b/src/site/xdoc/download.xml.vm index 804b0f79aad..ac699047c8f 100644 --- a/src/site/xdoc/download.xml.vm +++ b/src/site/xdoc/download.xml.vm @@ -262,6 +262,16 @@ 4.0.0 4.1.0-e0e3caf9ba + + HAPI FHIR 4.1.0 + JDK8 + + 1.0.2 + 1.4.0 + 3.0.1 + 4.0.0 + 4.1.0-1a7623d866 +