From 3fef8f7befd51e01c8991c4667f2d7a5e6bb929a Mon Sep 17 00:00:00 2001 From: ianmarshall Date: Sun, 30 Aug 2020 15:29:57 -0400 Subject: [PATCH] Back out changes relating to validate operations. Cleanup of code --- .../dao/r5/FhirResourceDaoCodeSystemR5.java | 2 +- ...aseJpaResourceProviderCodeSystemDstu3.java | 2 +- .../BaseJpaResourceProviderCodeSystemR5.java | 2 +- .../fhir/jpa/term/BaseTermReadSvcImpl.java | 115 ++++++++---------- .../term/TermCodeSystemStorageSvcImpl.java | 15 +-- .../r4/ResourceProviderR4ValueSetTest.java | 45 ------- 6 files changed, 60 insertions(+), 121 deletions(-) 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 29a2f295eb9..9b5fe473c96 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 @@ -88,7 +88,7 @@ public class FhirResourceDaoCodeSystemR5 extends BaseHapiFhirResourceDao theCode, IPrimitiveType theSystem, Coding theCoding, RequestDetails theRequestDetails) { return lookupCode(theCode, theSystem, theCoding, null, theRequestDetails); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderCodeSystemDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderCodeSystemDstu3.java index 7cc793e5371..6b5c7cd7c77 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderCodeSystemDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderCodeSystemDstu3.java @@ -85,7 +85,7 @@ public class BaseJpaResourceProviderCodeSystemDstu3 extends JpaResourceProviderD @OperationParam(name = "system", min = 0, max = 1) UriType theSystem, @OperationParam(name = "codingA", min = 0, max = 1) Coding theCodingA, @OperationParam(name = "codingB", min = 0, max = 1) Coding theCodingB, - @OperationParam(name="version", min=0, max=1) org.hl7.fhir.r4.model.StringType theVersion, + @OperationParam(name="version", min=0, max=1) StringType theVersion, RequestDetails theRequestDetails ) { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r5/BaseJpaResourceProviderCodeSystemR5.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r5/BaseJpaResourceProviderCodeSystemR5.java index bcd7445766f..47c880a6a10 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r5/BaseJpaResourceProviderCodeSystemR5.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r5/BaseJpaResourceProviderCodeSystemR5.java @@ -85,7 +85,7 @@ public class BaseJpaResourceProviderCodeSystemR5 extends JpaResourceProviderR5 theAddedCodes, ValueSet.ConceptSetComponent theIncludeOrExclude, boolean theAdd, AtomicInteger theCodeCounter, int theQueryIndex, VersionIndependentConcept theWantConceptOrNull) { String system = theIncludeOrExclude.getSystem(); - String systemVersion = theIncludeOrExclude.getVersion(); boolean hasSystem = isNotBlank(system); boolean hasValueSet = theIncludeOrExclude.getValueSet().size() > 0; @@ -631,7 +625,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { TermCodeSystem cs = myCodeSystemDao.findByCodeSystemUri(system); if (cs != null) { - return expandValueSetHandleIncludeOrExcludeUsingDatabase(theValueSetCodeAccumulator, theAddedCodes, theIncludeOrExclude, theAdd, theCodeCounter, theQueryIndex, theWantConceptOrNull, system, cs, systemVersion); + return expandValueSetHandleIncludeOrExcludeUsingDatabase(theValueSetCodeAccumulator, theAddedCodes, theIncludeOrExclude, theAdd, theCodeCounter, theQueryIndex, theWantConceptOrNull, system, cs); } else { @@ -672,7 +666,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { nextSystem = system; } - LookupCodeResult lookup = myValidationSupport.lookupCode(new ValidationSupportContext(provideValidationSupport()), nextSystem, next.getCode(), systemVersion); + LookupCodeResult lookup = myValidationSupport.lookupCode(new ValidationSupportContext(provideValidationSupport()), nextSystem, next.getCode()); if (lookup != null && lookup.isFound()) { addOrRemoveCode(theValueSetCodeAccumulator, theAddedCodes, theAdd, nextSystem, next.getCode(), lookup.getCodeDisplay()); foundCount++; @@ -766,7 +760,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } @Nonnull - private Boolean expandValueSetHandleIncludeOrExcludeUsingDatabase(IValueSetConceptAccumulator theValueSetCodeAccumulator, Set theAddedCodes, ValueSet.ConceptSetComponent theIncludeOrExclude, boolean theAdd, AtomicInteger theCodeCounter, int theQueryIndex, VersionIndependentConcept theWantConceptOrNull, String theSystem, TermCodeSystem theCs, String theSystemVersion) { + private Boolean expandValueSetHandleIncludeOrExcludeUsingDatabase(IValueSetConceptAccumulator theValueSetCodeAccumulator, Set theAddedCodes, ValueSet.ConceptSetComponent theIncludeOrExclude, boolean theAdd, AtomicInteger theCodeCounter, int theQueryIndex, VersionIndependentConcept theWantConceptOrNull, String theSystem, TermCodeSystem theCs) { TermCodeSystemVersion csv = theCs.getCurrentVersion(); FullTextEntityManager em = org.hibernate.search.jpa.Search.getFullTextEntityManager(myEntityManager); @@ -794,7 +788,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { /* * Filters */ - handleFilters(bool, theSystem, qb, theIncludeOrExclude, theSystemVersion); + handleFilters(bool, theSystem, qb, theIncludeOrExclude); Query luceneQuery = bool.createQuery(); @@ -903,15 +897,15 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } } - private void handleFilters(BooleanJunction theBool, String theSystem, QueryBuilder theQb, ValueSet.ConceptSetComponent theIncludeOrExclude, String theSystemVersion) { + private void handleFilters(BooleanJunction theBool, String theSystem, QueryBuilder theQb, ValueSet.ConceptSetComponent theIncludeOrExclude) { if (theIncludeOrExclude.getFilter().size() > 0) { for (ValueSet.ConceptSetFilterComponent nextFilter : theIncludeOrExclude.getFilter()) { - handleFilter(theSystem, theQb, theBool, nextFilter, theSystemVersion); + handleFilter(theSystem, theQb, theBool, nextFilter); } } } - private void handleFilter(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter, String theSystemVersion) { + private void handleFilter(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { if (isBlank(theFilter.getValue()) && theFilter.getOp() == null && isBlank(theFilter.getProperty())) { return; } @@ -927,24 +921,24 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { break; case "concept": case "code": - handleFilterConceptAndCode(theSystem, theQb, theBool, theFilter, theSystemVersion); + handleFilterConceptAndCode(theSystem, theQb, theBool, theFilter); break; case "parent": case "child": isCodeSystemLoingOrThrowInvalidRequestException(theSystem, theFilter.getProperty()); - handleFilterLoincParentChild(theQb, theBool, theFilter); + handleFilterLoincParentChild(theBool, theFilter); break; case "ancestor": isCodeSystemLoingOrThrowInvalidRequestException(theSystem, theFilter.getProperty()); - handleFilterLoincAncestor(theSystem, theQb, theBool, theFilter, theSystemVersion); + handleFilterLoincAncestor(theSystem, theBool, theFilter); break; case "descendant": isCodeSystemLoingOrThrowInvalidRequestException(theSystem, theFilter.getProperty()); - handleFilterLoincDescendant(theSystem, theQb, theBool, theFilter, theSystemVersion); + handleFilterLoincDescendant(theSystem, theBool, theFilter); break; case "copyright": isCodeSystemLoingOrThrowInvalidRequestException(theSystem, theFilter.getProperty()); - handleFilterLoincCopyright(theQb, theBool, theFilter); + handleFilterLoincCopyright(theBool, theFilter); break; default: handleFilterRegex(theBool, theFilter); @@ -952,11 +946,10 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } } - private boolean isCodeSystemLoingOrThrowInvalidRequestException(String theSystem, String theProperty) { + private void isCodeSystemLoingOrThrowInvalidRequestException(String theSystem, String theProperty) { if (!isCodeSystemLoinc(theSystem)) { throw new InvalidRequestException("Invalid filter, property " + theProperty + " is LOINC-specific and cannot be used with system: " + theSystem); } - return true; } private boolean isCodeSystemLoinc(String theSystem) { @@ -991,8 +984,8 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { bool.must(textQuery); } - private void handleFilterConceptAndCode(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter, String theSystemVersion) { - TermConcept code = findCode(theSystem, theFilter.getValue(), theSystemVersion) + private void handleFilterConceptAndCode(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { + TermConcept code = findCode(theSystem, theFilter.getValue()) .orElseThrow(() -> new InvalidRequestException("Invalid filter criteria - code does not exist: {" + Constants.codeSystemWithDefaultDescription(theSystem) + "}" + theFilter.getValue())); if (theFilter.getOp() == ValueSet.FilterOperator.ISA) { @@ -1004,7 +997,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } @SuppressWarnings("EnumSwitchStatementWhichMissesCases") - private void handleFilterLoincParentChild(QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { + private void handleFilterLoincParentChild(BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { switch (theFilter.getOp()) { case EQUAL: addLoincFilterParentChildEqual(theBool, theFilter.getProperty(), theFilter.getValue()); @@ -1037,41 +1030,41 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } @SuppressWarnings("EnumSwitchStatementWhichMissesCases") - private void handleFilterLoincAncestor(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter, String theSystemVersion) { + private void handleFilterLoincAncestor(String theSystem, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { switch (theFilter.getOp()) { case EQUAL: - addLoincFilterAncestorEqual(theSystem, theQb, theBool, theFilter, theSystemVersion); + addLoincFilterAncestorEqual(theSystem, theBool, theFilter); break; case IN: - addLoincFilterAncestorIn(theSystem, theQb, theBool, theFilter, theSystemVersion); + addLoincFilterAncestorIn(theSystem, theBool, theFilter); break; default: throw new InvalidRequestException("Don't know how to handle op=" + theFilter.getOp() + " on property " + theFilter.getProperty()); } } - private void addLoincFilterAncestorEqual(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter, String theSystemVersion) { - addLoincFilterAncestorEqual(theSystem, theQb, theBool, theFilter.getProperty(), theFilter.getValue(), theSystemVersion); + private void addLoincFilterAncestorEqual(String theSystem, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { + addLoincFilterAncestorEqual(theSystem, theBool, theFilter.getProperty(), theFilter.getValue()); } - private void addLoincFilterAncestorEqual(String theSystem, QueryBuilder theQb, BooleanJunction theBool, String theProperty, String theValue, String theSystemVersion) { - List terms = getAncestorTerms(theSystem, theProperty, theValue, theSystemVersion); + private void addLoincFilterAncestorEqual(String theSystem, BooleanJunction theBool, String theProperty, String theValue) { + List terms = getAncestorTerms(theSystem, theProperty, theValue); theBool.must(new TermsQuery(terms)); } - private void addLoincFilterAncestorIn(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter, String theSystemVersion) { + private void addLoincFilterAncestorIn(String theSystem, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { String[] values = theFilter.getValue().split(","); List terms = new ArrayList<>(); for (String value : values) { - terms.addAll(getAncestorTerms(theSystem, theFilter.getProperty(), value, theSystemVersion)); + terms.addAll(getAncestorTerms(theSystem, theFilter.getProperty(), value)); } theBool.must(new TermsQuery(terms)); } - private List getAncestorTerms(String theSystem, String theProperty, String theValue, String theSystemVersion) { + private List getAncestorTerms(String theSystem, String theProperty, String theValue) { List retVal = new ArrayList<>(); - TermConcept code = findCode(theSystem, theValue, theSystemVersion) + TermConcept code = findCode(theSystem, theValue) .orElseThrow(() -> new InvalidRequestException("Invalid filter criteria - code does not exist: {" + Constants.codeSystemWithDefaultDescription(theSystem) + "}" + theValue)); retVal.add(new Term("myParentPids", "" + code.getId())); @@ -1081,41 +1074,41 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } @SuppressWarnings("EnumSwitchStatementWhichMissesCases") - private void handleFilterLoincDescendant(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter, String theSystemVersion) { + private void handleFilterLoincDescendant(String theSystem, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { switch (theFilter.getOp()) { case EQUAL: - addLoincFilterDescendantEqual(theSystem, theBool, theFilter, theSystemVersion); + addLoincFilterDescendantEqual(theSystem, theBool, theFilter); break; case IN: - addLoincFilterDescendantIn(theSystem, theQb, theBool, theFilter, theSystemVersion); + addLoincFilterDescendantIn(theSystem, theBool, theFilter); break; default: throw new InvalidRequestException("Don't know how to handle op=" + theFilter.getOp() + " on property " + theFilter.getProperty()); } } - private void addLoincFilterDescendantEqual(String theSystem, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter, String theSystemVersion) { - addLoincFilterDescendantEqual(theSystem, theBool, theFilter.getProperty(), theFilter.getValue(), theSystemVersion); + private void addLoincFilterDescendantEqual(String theSystem, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { + addLoincFilterDescendantEqual(theSystem, theBool, theFilter.getProperty(), theFilter.getValue()); } - private void addLoincFilterDescendantEqual(String theSystem, BooleanJunction theBool, String theProperty, String theValue, String theSystemVersion) { - List terms = getDescendantTerms(theSystem, theProperty, theValue, theSystemVersion); + private void addLoincFilterDescendantEqual(String theSystem, BooleanJunction theBool, String theProperty, String theValue) { + List terms = getDescendantTerms(theSystem, theProperty, theValue); theBool.must(new TermsQuery(terms)); } - private void addLoincFilterDescendantIn(String theSystem, QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter, String theSystemVersion) { + private void addLoincFilterDescendantIn(String theSystem, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { String[] values = theFilter.getValue().split(","); List terms = new ArrayList<>(); for (String value : values) { - terms.addAll(getDescendantTerms(theSystem, theFilter.getProperty(), value, theSystemVersion)); + terms.addAll(getDescendantTerms(theSystem, theFilter.getProperty(), value)); } theBool.must(new TermsQuery(terms)); } - private List getDescendantTerms(String theSystem, String theProperty, String theValue, String theSystemVersion) { + private List getDescendantTerms(String theSystem, String theProperty, String theValue) { List retVal = new ArrayList<>(); - TermConcept code = findCode(theSystem, theValue, theSystemVersion) + TermConcept code = findCode(theSystem, theValue) .orElseThrow(() -> new InvalidRequestException("Invalid filter criteria - code does not exist: {" + Constants.codeSystemWithDefaultDescription(theSystem) + "}" + theValue)); String[] parentPids = code.getParentPidsAsString().split(" "); @@ -1127,7 +1120,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { return retVal; } - private void handleFilterLoincCopyright(QueryBuilder theQb, BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { + private void handleFilterLoincCopyright(BooleanJunction theBool, ValueSet.ConceptSetFilterComponent theFilter) { if (theFilter.getOp() == ValueSet.FilterOperator.EQUAL) { String copyrightFilterValue = defaultString(theFilter.getValue()).toLowerCase(); @@ -1365,7 +1358,6 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { @Override public Optional findCode(String theCodeSystem, String theCode) { return findCode(theCodeSystem, theCode, null); - } @Override @@ -1378,7 +1370,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { TransactionTemplate txTemplate = new TransactionTemplate(myTransactionManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_MANDATORY); return txTemplate.execute(t -> { - TermCodeSystemVersion csv = getCurrentCodeSystemVersionForVersion(theCodeSystem, theVersion); + TermCodeSystemVersion csv = getCurrentCodeSystemVersion(theCodeSystem, theVersion); if (csv == null) { return Optional.empty(); } @@ -1387,8 +1379,8 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } @Nullable - private TermCodeSystemVersion getCurrentCodeSystemVersionForVersion(String theUri, String theVersion) { - StringBuffer key = new StringBuffer(theUri); + private TermCodeSystemVersion getCurrentCodeSystemVersion(String theUri, String theVersion) { + StringBuilder key = new StringBuilder(theUri); if (theVersion != null) { key.append("_").append(theVersion); } @@ -1820,16 +1812,13 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { @Override public IFhirResourceDaoCodeSystem.SubsumesResult subsumes(IPrimitiveType theCodeA, IPrimitiveType theCodeB, - IPrimitiveType theSystem, IBaseCoding theCodingA, IBaseCoding theCodingB) { + IPrimitiveType theSystem, IBaseCoding theCodingA, IBaseCoding theCodingB) { return subsumes(theCodeA, theCodeB, theSystem, theCodingA, theCodingB, null, null, null); } @Override @Transactional - public IFhirResourceDaoCodeSystem.SubsumesResult subsumes(IPrimitiveType theCodeA, IPrimitiveType theCodeB, - IPrimitiveType theSystem, IBaseCoding theCodingA, IBaseCoding theCodingB, - IPrimitiveType theSystemVersion, String theCodingAVersion, - String theCodingBVersion) { + public IFhirResourceDaoCodeSystem.SubsumesResult subsumes(IPrimitiveType theCodeA, IPrimitiveType theCodeB, IPrimitiveType theSystem, IBaseCoding theCodingA, IBaseCoding theCodingB, IPrimitiveType theSystemVersion, String theCodingAVersion, String theCodingBVersion) { VersionIndependentConceptWithSystemVersion conceptA = toConcept(theCodeA, theSystem, theCodingA, theSystemVersion, theCodingAVersion); VersionIndependentConceptWithSystemVersion conceptB = toConcept(theCodeB, theSystem, theCodingB, theSystemVersion, theCodingBVersion); @@ -2085,6 +2074,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { while (scrollableResultsIterator.hasNext()) { TermConceptMapGroupElement nextElement = scrollableResultsIterator.next(); + // TODO: The invocation of the size() below does not seem to be necessary but for some reason, removing it causes tests in TerminologySvcImplR4Test to fail. nextElement.getConceptMapGroupElementTargets().size(); myEntityManager.detach(nextElement); @@ -2138,11 +2128,6 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { @CoverageIgnore @Override public IValidationSupport.CodeValidationResult validateCode(ValidationSupportContext theValidationSupportContext, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl) { - return validateCode(theValidationSupportContext, theOptions, theCodeSystem, theCode, theDisplay, theValueSetUrl, null); - } - - @Override - public IValidationSupport.CodeValidationResult validateCode(ValidationSupportContext theValidationSupportContext, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl, String theSystemVersion) { invokeRunnableForUnitTest(); if (isNotBlank(theValueSetUrl)) { @@ -2151,7 +2136,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { TransactionTemplate txTemplate = new TransactionTemplate(myTransactionManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); - Optional codeOpt = txTemplate.execute(t -> findCode(theCodeSystem, theCode, theSystemVersion).map(c -> new VersionIndependentConcept(theCodeSystem, c.getCode()))); + Optional codeOpt = txTemplate.execute(t -> findCode(theCodeSystem, theCode).map(c -> new VersionIndependentConcept(theCodeSystem, c.getCode()))); if (codeOpt != null && codeOpt.isPresent()) { VersionIndependentConcept code = codeOpt.get(); @@ -2182,7 +2167,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } } - CodeValidationResult retVal = null; + CodeValidationResult retVal; if (valueSet != null) { retVal = new InMemoryTerminologyServerValidationSupport(myContext).validateCodeInValueSet(theValidationSupportContext, theValidationOptions, theCodeSystem, theCode, theDisplay, valueSet); } else { @@ -2415,9 +2400,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } @NotNull - private VersionIndependentConceptWithSystemVersion toConcept(IPrimitiveType theCodeType, IPrimitiveType theSystemType, - IBaseCoding theCodingType, IPrimitiveType theSystemVersionType, - String theCodingVersionType) { + private VersionIndependentConceptWithSystemVersion toConcept(IPrimitiveType theCodeType, IPrimitiveType theSystemType, IBaseCoding theCodingType, IPrimitiveType theSystemVersionType, String theCodingVersionType) { String code = theCodeType != null ? theCodeType.getValueAsString() : null; String system = theSystemType != null ? theSystemType.getValueAsString() : null; String systemVersion = theSystemVersionType != null ? theSystemVersionType.getValueAsString() : null; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java index 6230a94cc35..598c5eccdd4 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcImpl.java @@ -234,10 +234,12 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc { @Override @Transactional(propagation = Propagation.NEVER) public void deleteCodeSystemVersion(TermCodeSystemVersion theCodeSystemVersion) { - TermCodeSystem termCodeSystem = theCodeSystemVersion.getCodeSystem(); + // Delete TermCodeSystemVersion ourLog.info(" * Deleting code system version {}", theCodeSystemVersion.getCodeSystemVersionId()); deleteCodeSystemVersion(theCodeSystemVersion.getPid()); + // Check if the version deleted is the current version. If so, delete TermCodeSystem as well. + TermCodeSystem termCodeSystem = theCodeSystemVersion.getCodeSystem(); TransactionTemplate txTemplate = new TransactionTemplate(myTransactionManager); txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); txTemplate.executeWithoutResult(t -> { @@ -312,8 +314,7 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc { if (termCodeSystem != null) { TermCodeSystemVersion codeSystemVersion = getExistingTermCodeSystemVersion(termCodeSystem.getPid(), theCodeSystem.getVersion()); if (codeSystemVersion != null) { - TermCodeSystem myCodeSystemEntity = getOrCreateTermCodeSystem(codeSystemResourcePid, theCodeSystem.getUrl(), theCodeSystem.getUrl(), theResourceEntity); - validateCodeSystemVersionUpdate(myCodeSystemEntity,theCodeSystem.getUrl(), theCodeSystem.getVersion(), theResourceEntity); + TermCodeSystem myCodeSystemEntity = getOrCreateDistinctTermCodeSystem(codeSystemResourcePid, theCodeSystem.getUrl(), theCodeSystem.getUrl(), theCodeSystem.getVersion(), theResourceEntity); return; } } @@ -370,8 +371,7 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc { /* * Get CodeSystem and validate CodeSystemVersion */ - TermCodeSystem codeSystem = getOrCreateTermCodeSystem(theCodeSystemResourcePid, theSystemUri, theSystemName, theCodeSystemResourceTable); - validateCodeSystemVersionUpdate(codeSystem, theSystemUri, theSystemVersionId, theCodeSystemResourceTable); + TermCodeSystem codeSystem = getOrCreateDistinctTermCodeSystem(theCodeSystemResourcePid, theSystemUri, theSystemName, theSystemVersionId, theCodeSystemResourceTable); /* * Delete version being replaced. @@ -691,7 +691,7 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc { } @Nonnull - private TermCodeSystem getOrCreateTermCodeSystem(ResourcePersistentId theCodeSystemResourcePid, String theSystemUri, String theSystemName, ResourceTable theCodeSystemResourceTable) { + private TermCodeSystem getOrCreateDistinctTermCodeSystem(ResourcePersistentId theCodeSystemResourcePid, String theSystemUri, String theSystemName, String theSystemVersionId, ResourceTable theCodeSystemResourceTable) { TermCodeSystem codeSystem = myCodeSystemDao.findByCodeSystemUri(theSystemUri); if (codeSystem == null) { codeSystem = myCodeSystemDao.findByResourcePid(theCodeSystemResourcePid.getIdAsLong()); @@ -704,10 +704,11 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc { codeSystem.setCodeSystemUri(theSystemUri); codeSystem.setName(theSystemName); codeSystem = myCodeSystemDao.save(codeSystem); + checkForCodeSystemVersionDuplicate(codeSystem,theSystemUri, theSystemVersionId, theCodeSystemResourceTable); return codeSystem; } - private void validateCodeSystemVersionUpdate(TermCodeSystem theCodeSystem, String theSystemUri, String theSystemVersionId, ResourceTable theCodeSystemResourceTable) { + private void checkForCodeSystemVersionDuplicate(TermCodeSystem theCodeSystem, String theSystemUri, String theSystemVersionId, ResourceTable theCodeSystemResourceTable) { // Check if CodeSystemVersion entity already exists. TermCodeSystemVersion codeSystemVersionEntity; String msg = null; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetTest.java index 0d2c8d18407..1785024a411 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetTest.java @@ -416,51 +416,6 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { } - @Test - public void testExpandByValueSetWithFilter() throws IOException { - loadAndPersistCodeSystem(); - - ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); - - Parameters respParam = myClient - .operation() - .onType(ValueSet.class) - .named("expand") - .withParameter(Parameters.class, "valueSet", toExpand) - .andParameter("filter", new StringType("blood")) - .execute(); - ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource(); - - String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(expanded); - ourLog.info(resp); - assertThat(resp, stringContainsInOrder( - "", - "")); - - } - - @Test - public void testExpandByUrlWithFilter() throws Exception { - loadAndPersistCodeSystemAndValueSet(); - - Parameters respParam = myClient - .operation() - .onType(ValueSet.class) - .named("expand") - .withParameter(Parameters.class, "url", new UriType("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2")) - .andParameter("filter", new StringType("first")) - .execute(); - ValueSet expanded = (ValueSet) respParam.getParameter().get(0).getResource(); - - String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(expanded); - ourLog.info(resp); - assertThat(resp, stringContainsInOrder( - "", - "")); - - } - - @Test public void testExpandByValueSetWithPreExpansion() throws IOException { myDaoConfig.setPreExpandValueSets(true);