diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index 6d8694a60a7..40129fa9d6b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -102,8 +102,7 @@ import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.XhtmlDt; import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum; -import ca.uhn.fhir.parser.DataFormatException; -import ca.uhn.fhir.parser.IParser; +import ca.uhn.fhir.parser.*; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.method.MethodUtil; import ca.uhn.fhir.rest.method.QualifiedParamList; @@ -1222,6 +1221,8 @@ public abstract class BaseHapiFhirDao implements IDao { } IParser parser = theEntity.getEncoding().newParser(getContext(theEntity.getFhirVersion())); + parser.setParserErrorHandler(new LenientErrorHandler(false).setErrorOnInvalidValue(false)); + R retVal; try { retVal = parser.parseResource(resourceType, resourceText); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java index 6085197a401..694cf096705 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java @@ -288,6 +288,13 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { } + @Test + public void testExpandWithOpEquals() { + ValueSet result = myValueSetDao.expandByIdentifier("http://hl7.org/fhir/ValueSet/doc-typecodes", ""); + ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result)); + } + + @Test public void testExpandWithCodesAndDisplayFilterPartialOnFilter() { CodeSystem codeSystem = createExternalCsDogs(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java index 6300e474915..9675befad55 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java @@ -49,12 +49,14 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.support.*; +import com.google.common.base.Charsets; import com.google.common.collect.Lists; import ca.uhn.fhir.jpa.dao.*; -import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString; -import ca.uhn.fhir.jpa.entity.TagTypeEnum; +import ca.uhn.fhir.jpa.entity.*; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum; @@ -245,6 +247,37 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } } + /** + * Can we handle content that was previously saved containing vocabulary that + * is no longer valid + */ + @Test + public void testResourceInDatabaseContainsInvalidVocabulary() { + final Patient p = new Patient(); + p.setGender(AdministrativeGender.MALE); + final IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); + + TransactionTemplate tx = new TransactionTemplate(myTxManager); + tx.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW); + tx.execute(new TransactionCallbackWithoutResult() { + @Override + protected void doInTransactionWithoutResult(TransactionStatus theStatus) { + ResourceTable table = myResourceTableDao.findOne(id.getIdPartAsLong()); + String newContent = myFhirCtx.newJsonParser().encodeResourceToString(p); + newContent = newContent.replace("male", "foo"); + table.setResource(newContent.getBytes(Charsets.UTF_8)); + table.setEncoding(ResourceEncodingEnum.JSON); + myResourceTableDao.save(table); + } + }); + + Patient read = myPatientDao.read(id); + String string = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(read); + ourLog.info(string); + assertThat(string, containsString("value=\"foo\"")); + } + + @Test public void testChoiceParamDateEquals() { Encounter enc = new Encounter(); diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e40e4cdf9d1..b63fc1475c8 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -67,6 +67,14 @@ starting a context up on Android. Thanks to GitHub issue @Jaypeg85 for the pull request! + + Fix an issue in the JPA server if a resource has been previously + saved containing vocabulary that is no longer valid. This only really + happened if you were using a non-final version of FHIR (e.g. using DSTU3 + before it was finalized) but if you were in this situation, upgrading HAPI + could cause you to have old codes that no longer exist in your database. This + fix prevents these from blocking you from accesing those resources. +