From cd104ad6358ba4d2bf350bed002945491bc3615a Mon Sep 17 00:00:00 2001 From: ianmarshall Date: Tue, 15 Sep 2020 10:21:42 -0400 Subject: [PATCH] Revised approach for versioning of ValueSet. --- .../fhir/jpa/dao/data/ITermValueSetDao.java | 15 +- .../jpa/dao/data/ITermValueSetVersionDao.java | 52 ---- .../dstu3/FhirResourceDaoValueSetDstu3.java | 7 +- .../dao/expunge/ExpungeEverythingService.java | 11 +- .../jpa/dao/r4/FhirResourceDaoValueSetR4.java | 25 +- .../jpa/dao/r5/FhirResourceDaoValueSetR5.java | 7 +- .../ca/uhn/fhir/jpa/entity/TermValueSet.java | 105 +++++++- .../fhir/jpa/entity/TermValueSetVersion.java | 249 ------------------ .../fhir/jpa/term/BaseTermReadSvcImpl.java | 205 +++++--------- .../term/TermCodeSystemStorageSvcImpl.java | 2 +- .../jpa/term/TermDeferredStorageSvcImpl.java | 1 + .../jpa/term/ValueSetConceptAccumulator.java | 48 ++-- .../fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java | 4 - .../FhirResourceDaoDstu3TerminologyTest.java | 4 + .../FhirResourceDaoDstu3ValueSetTest.java | 20 +- .../ca/uhn/fhir/jpa/dao/r4/BaseJpaR4Test.java | 5 - ...esourceDaoR4SearchWithElasticSearchIT.java | 1 + ...sourceDaoR4TerminologyElasticsearchIT.java | 1 + .../r4/FhirResourceDaoR4TerminologyTest.java | 5 + .../dao/r4/FhirResourceDaoR4ValidateTest.java | 32 +-- .../ca/uhn/fhir/jpa/dao/r5/BaseJpaR5Test.java | 6 +- .../ResourceProviderDstu3ValueSetTest.java | 1 + .../r4/ResourceProviderR4CodeSystemTest.java | 3 - ...urceProviderR4CodeSystemVersionedTest.java | 3 - .../r4/ResourceProviderR4ValueSetTest.java | 30 ++- .../r4/TerminologyUploaderProviderR4Test.java | 2 +- .../r5/ResourceProviderR5ValueSetTest.java | 29 +- .../jpa/term/TerminologySvcImplDstu3Test.java | 11 +- .../jpa/term/TerminologySvcImplR4Test.java | 17 +- .../term/ValueSetConceptAccumulatorTest.java | 12 +- .../jpa/term/ValueSetExpansionR4Test.java | 113 +++++--- 31 files changed, 388 insertions(+), 638 deletions(-) delete mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetVersionDao.java delete mode 100644 hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetVersion.java diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetDao.java index 40dbc15027e..33883b6073c 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetDao.java @@ -29,18 +29,27 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import java.util.List; import java.util.Optional; public interface ITermValueSetDao extends JpaRepository { - @Query("SELECT vs FROM TermValueSet vs WHERE vs.myResourcePid = :resource_pid") Optional findByResourcePid(@Param("resource_pid") Long theResourcePid); @Query("SELECT vs FROM TermValueSet vs WHERE vs.myUrl = :url") Optional findByUrl(@Param("url") String theUrl); - @Query("SELECT vs FROM TermValueSet vs WHERE vs.myCurrentVersion.myId = :vsv_pid") - Optional findWithCodeSystemVersionAsCurrentVersion(@Param("vsv_pid") Long theValueSetVersionPid); + @Query("SELECT vs FROM TermValueSet vs WHERE vs.myExpansionStatus = :expansion_status") + Slice findByExpansionStatus(Pageable pageable, @Param("expansion_status") TermValueSetPreExpansionStatusEnum theExpansionStatus); + + @Query(value="SELECT vs FROM TermValueSet vs INNER JOIN ResourceTable r ON r.myId = vs.myResourcePid WHERE vs.myUrl = :url ORDER BY r.myUpdated DESC") + List findTermValueSetByUrl(Pageable thePage, @Param("url") String theUrl); + + @Query("SELECT vs FROM TermValueSet vs WHERE vs.myUrl = :url AND vs.myVersion IS NULL") + Optional findTermValueSetByUrlAndNullVersion(@Param("url") String theUrl); + + @Query("SELECT vs FROM TermValueSet vs WHERE vs.myUrl = :url AND vs.myVersion = :version") + Optional findTermValueSetByUrlAndVersion(@Param("url") String theUrl, @Param("version") String theVersion); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetVersionDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetVersionDao.java deleted file mode 100644 index b81d4a69914..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetVersionDao.java +++ /dev/null @@ -1,52 +0,0 @@ -package ca.uhn.fhir.jpa.dao.data; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2020 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 ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; -import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; -import ca.uhn.fhir.jpa.entity.TermValueSetVersion; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.List; -import java.util.Optional; - -public interface ITermValueSetVersionDao extends JpaRepository { - - @Query("SELECT vsv FROM TermValueSetVersion vsv WHERE vsv.myResourcePid = :resource_pid") - Optional findByResourcePid(@Param("resource_pid") Long theResourcePid); - - @Query("SELECT vsv FROM TermValueSetVersion vsv WHERE vsv.myValueSetPid = :valueset_pid AND vsv.myValueSetVersionId = :version" ) - TermValueSetVersion findByValueSetPidAndVersion(@Param("valueset_pid") Long theValueSetPid, @Param("version") String theVersion); - - @Query("SELECT vsv FROM TermValueSetVersion vsv WHERE vsv.myValueSetPid = :valueset_pid AND vsv.myValueSetVersionId IS NULL" ) - TermValueSetVersion findByValueSetPidAndNullVersion(@Param("valueset_pid") Long theValueSetPid); - - @Query("SELECT vsv FROM TermValueSetVersion vsv WHERE vsv.myExpansionStatus = :expansion_status") - Slice findByExpansionStatus(Pageable pageable, @Param("expansion_status") TermValueSetPreExpansionStatusEnum theExpansionStatus); - - @Query("SELECT vsv FROM TermValueSetVersion vsv WHERE vsv.myValueSetPid = :valueset_pid") - List findByValueSetPid(@Param("valueset_pid") Long theValueSetPid); - -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3.java index 9e6e229c04f..9def15576aa 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3.java @@ -65,9 +65,6 @@ import static org.hl7.fhir.convertors.conv30_40.ValueSet30_40.convertValueSet; public class FhirResourceDaoValueSetDstu3 extends BaseHapiFhirResourceDao implements IFhirResourceDaoValueSet { private static final Logger ourLog = LoggerFactory.getLogger(FhirResourceDaoValueSetDstu3.class); - @Autowired - private ITermReadSvc myHapiTerminologySvc; - @Autowired private DefaultProfileValidationSupport myDefaultProfileValidationSupport; @@ -283,12 +280,12 @@ public class FhirResourceDaoValueSetDstu3 extends BaseHapiFhirResourceDao { - counter.addAndGet(doExpungeEverythingQuery("UPDATE " + TermValueSet.class.getSimpleName() + " d SET d.myCurrentVersion = null")); - return null; - }); +// myTxTemplate.execute(t -> { +// counter.addAndGet(doExpungeEverythingQuery("UPDATE " + TermValueSet.class.getSimpleName() + " d SET d.myCurrentVersion = null")); +// return null; +// }); counter.addAndGet(expungeEverythingByType(NpmPackageVersionResourceEntity.class)); counter.addAndGet(expungeEverythingByType(NpmPackageVersionEntity.class)); counter.addAndGet(expungeEverythingByType(NpmPackageEntity.class)); @@ -140,7 +139,7 @@ public class ExpungeEverythingService { counter.addAndGet(expungeEverythingByType(SearchInclude.class)); counter.addAndGet(expungeEverythingByType(TermValueSetConceptDesignation.class)); counter.addAndGet(expungeEverythingByType(TermValueSetConcept.class)); - counter.addAndGet(expungeEverythingByType(TermValueSetVersion.class)); +// counter.addAndGet(expungeEverythingByType(TermValueSetVersion.class)); counter.addAndGet(expungeEverythingByType(TermValueSet.class)); counter.addAndGet(expungeEverythingByType(TermConceptParentChildLink.class)); counter.addAndGet(expungeEverythingByType(TermConceptMapGroupElementTarget.class)); 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 7a104f1ba97..20695859f3f 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 @@ -60,9 +60,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class FhirResourceDaoValueSetR4 extends BaseHapiFhirResourceDao implements IFhirResourceDaoValueSet { - @Autowired - private ITermReadSvc myHapiTerminologySvc; - @Autowired private DefaultProfileValidationSupport myDefaultProfileValidationSupport; @@ -113,17 +110,14 @@ public class FhirResourceDaoValueSetR4 extends BaseHapiFhirResourceDao ValueSet source = new ValueSet(); source.setUrl(theUri); -// source.getCompose().addInclude().addValueSet(theUri); + source.getCompose().addInclude().addValueSet(theUri); if (isNotBlank(theFilter)) { -// ConceptSetComponent include = source.getCompose().addInclude(); -// ConceptSetFilterComponent filter = include.addFilter(); - ConceptSetFilterComponent filter = source.getCompose().addInclude().addValueSet(theUri).addFilter(); + ConceptSetComponent include = source.getCompose().addInclude(); + ConceptSetFilterComponent filter = include.addFilter(); filter.setProperty("display"); filter.setOp(FilterOperator.EQUAL); filter.setValue(theFilter); - } else { - source.getCompose().addInclude().addValueSet(theUri); } ValueSet retVal = doExpand(source); @@ -151,17 +145,14 @@ public class FhirResourceDaoValueSetR4 extends BaseHapiFhirResourceDao ValueSet source = new ValueSet(); source.setUrl(theUri); -// source.getCompose().addInclude().addValueSet(theUri); + source.getCompose().addInclude().addValueSet(theUri); if (isNotBlank(theFilter)) { -// ConceptSetComponent include = source.getCompose().addInclude(); -// ConceptSetFilterComponent filter = include.addFilter(); - ConceptSetFilterComponent filter = source.getCompose().addInclude().addValueSet(theUri).addFilter(); + ConceptSetComponent include = source.getCompose().addInclude(); + ConceptSetFilterComponent filter = include.addFilter(); filter.setProperty("display"); filter.setOp(FilterOperator.EQUAL); filter.setValue(theFilter); - } else { - source.getCompose().addInclude().addValueSet(theUri); } ValueSet retVal = doExpand(source, theOffset, theCount); @@ -268,9 +259,9 @@ public class FhirResourceDaoValueSetR4 extends BaseHapiFhirResourceDao if (myDaoConfig.isPreExpandValueSets() && !retVal.isUnchangedInCurrentOperation()) { if (retVal.getDeleted() == null) { ValueSet valueSet = (ValueSet) theResource; - myHapiTerminologySvc.storeTermValueSet(retVal, valueSet); + myTerminologySvc.storeTermValueSet(retVal, valueSet); } else { - myHapiTerminologySvc.deleteValueSetAndChildren(retVal); + myTerminologySvc.deleteValueSetAndChildren(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 5001ca5420a..7000debd950 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 @@ -64,9 +64,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class FhirResourceDaoValueSetR5 extends BaseHapiFhirResourceDao implements IFhirResourceDaoValueSet { - @Autowired - private ITermReadSvc myHapiTerminologySvc; - @Autowired @Qualifier("myDefaultProfileValidationSupport") private IValidationSupport myDefaultProfileValidationSupport; @@ -267,9 +264,9 @@ public class FhirResourceDaoValueSetR5 extends BaseHapiFhirResourceDao if (myDaoConfig.isPreExpandValueSets() && !retVal.isUnchangedInCurrentOperation()) { if (retVal.getDeleted() == null) { ValueSet valueSet = (ValueSet) theResource; - myHapiTerminologySvc.storeTermValueSet(retVal, org.hl7.fhir.convertors.conv40_50.ValueSet40_50.convertValueSet(valueSet)); + myTerminologySvc.storeTermValueSet(retVal, org.hl7.fhir.convertors.conv40_50.ValueSet40_50.convertValueSet(valueSet)); } else { - myHapiTerminologySvc.deleteValueSetAndChildren(retVal); + myTerminologySvc.deleteValueSetAndChildren(retVal); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSet.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSet.java index c137c3d4643..4cbe867d6cf 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSet.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSet.java @@ -25,16 +25,19 @@ import ca.uhn.fhir.util.ValidateUtil; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; +import org.hibernate.annotations.ColumnDefault; import javax.annotation.Nonnull; import javax.persistence.*; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; import static org.apache.commons.lang3.StringUtils.left; import static org.apache.commons.lang3.StringUtils.length; @Table(name = "TRM_VALUESET", uniqueConstraints = { - @UniqueConstraint(name = "IDX_VALUESET_URL", columnNames = {"URL"}) + @UniqueConstraint(name = "IDX_VALUESET_URL", columnNames = {"URL", "VER"}) }) @Entity() public class TermValueSet implements Serializable { @@ -43,12 +46,7 @@ public class TermValueSet implements Serializable { public static final int MAX_EXPANSION_STATUS_LENGTH = 50; public static final int MAX_NAME_LENGTH = 200; public static final int MAX_URL_LENGTH = 200; - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "CURRENT_VERSION_PID", referencedColumnName = "PID", nullable = true, foreignKey = @ForeignKey(name = "FK_TRMVALUESET_CURVER")) - private TermValueSetVersion myCurrentVersion; - @Column(name = "CURRENT_VERSION_PID", nullable = true, insertable = false, updatable = false) - private Long myCurrentVersionPid; + static final int MAX_VER_LENGTH = 200; @Id() @SequenceGenerator(name = "SEQ_VALUESET_PID", sequenceName = "SEQ_VALUESET_PID") @@ -59,6 +57,9 @@ public class TermValueSet implements Serializable { @Column(name = "URL", nullable = false, length = MAX_URL_LENGTH) private String myUrl; + @Column(name = "VER", nullable = true, length = MAX_VER_LENGTH) + private String myVersion; + @OneToOne() @JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "FK_TRMVALUESET_RES")) private ResourceTable myResource; @@ -69,11 +70,29 @@ public class TermValueSet implements Serializable { @Column(name = "VSNAME", nullable = true, length = MAX_NAME_LENGTH) private String myName; + @OneToMany(mappedBy = "myValueSet", fetch = FetchType.LAZY) + private List myConcepts; + + @Column(name = "TOTAL_CONCEPTS", nullable = false) + @ColumnDefault("0") + private Long myTotalConcepts; + + @Column(name = "TOTAL_CONCEPT_DESIGNATIONS", nullable = false) + @ColumnDefault("0") + private Long myTotalConceptDesignations; + + @Enumerated(EnumType.STRING) + @Column(name = "EXPANSION_STATUS", nullable = false, length = MAX_EXPANSION_STATUS_LENGTH) + private TermValueSetPreExpansionStatusEnum myExpansionStatus; + @Transient private transient Integer myHashCode; public TermValueSet() { super(); + myExpansionStatus = TermValueSetPreExpansionStatusEnum.NOT_EXPANDED; + myTotalConcepts = 0L; + myTotalConceptDesignations = 0L; } public Long getId() { @@ -110,12 +129,72 @@ public class TermValueSet implements Serializable { return this; } - public TermValueSetVersion getCurrentVersion() { - return myCurrentVersion; + public List getConcepts() { + if (myConcepts == null) { + myConcepts = new ArrayList<>(); + } + + return myConcepts; } - public TermValueSet setCurrentVersion(TermValueSetVersion theCurrentVersion) { - myCurrentVersion = theCurrentVersion; + public Long getTotalConcepts() { + return myTotalConcepts; + } + + public TermValueSet setTotalConcepts(Long theTotalConcepts) { + myTotalConcepts = theTotalConcepts; + return this; + } + + public TermValueSet decrementTotalConcepts() { + if (myTotalConcepts > 0) { + myTotalConcepts--; + } + return this; + } + + public TermValueSet incrementTotalConcepts() { + myTotalConcepts++; + return this; + } + + public Long getTotalConceptDesignations() { + return myTotalConceptDesignations; + } + + public TermValueSet setTotalConceptDesignations(Long theTotalConceptDesignations) { + myTotalConceptDesignations = theTotalConceptDesignations; + return this; + } + + public TermValueSet decrementTotalConceptDesignations() { + if (myTotalConceptDesignations > 0) { + myTotalConceptDesignations--; + } + return this; + } + + public TermValueSet incrementTotalConceptDesignations() { + myTotalConceptDesignations++; + return this; + } + + public TermValueSetPreExpansionStatusEnum getExpansionStatus() { + return myExpansionStatus; + } + + public void setExpansionStatus(TermValueSetPreExpansionStatusEnum theExpansionStatus) { + myExpansionStatus = theExpansionStatus; + } + + public String getVersion() { + return myVersion; + } + + public TermValueSet setVersion(String theVersion) { + ValidateUtil.isNotTooLongOrThrowIllegalArgument(theVersion, MAX_VER_LENGTH, + "Version exceeds maximum length (" + MAX_VER_LENGTH + "): " + length(theVersion)); + myVersion = theVersion; return this; } @@ -148,6 +227,10 @@ public class TermValueSet implements Serializable { .append(myResource != null ? ("myResource=" + myResource.toString()) : ("myResource=(null)")) .append("myResourcePid", myResourcePid) .append("myName", myName) + .append(myConcepts != null ? ("myConcepts - size=" + myConcepts.size()) : ("myConcepts=(null)")) + .append("myTotalConcepts", myTotalConcepts) + .append("myTotalConceptDesignations", myTotalConceptDesignations) + .append("myExpansionStatus", myExpansionStatus) .toString(); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetVersion.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetVersion.java deleted file mode 100644 index 3b9bb8280f2..00000000000 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetVersion.java +++ /dev/null @@ -1,249 +0,0 @@ -package ca.uhn.fhir.jpa.entity; - -/* - * #%L - * HAPI FHIR JPA Server - * %% - * Copyright (C) 2014 - 2020 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 ca.uhn.fhir.jpa.model.entity.ResourceTable; -import ca.uhn.fhir.util.ValidateUtil; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import org.hibernate.annotations.ColumnDefault; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.FetchType; -import javax.persistence.ForeignKey; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.OneToOne; -import javax.persistence.SequenceGenerator; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import static org.apache.commons.lang3.StringUtils.length; - -@Table(name = "TRM_VALUESET_VER", uniqueConstraints = { - @UniqueConstraint(name = "IDX_VALUESET_URL_AND_VER", columnNames = {"VALUESET_PID", "VS_VERSION_ID"}) -}) -@Entity() -public class TermValueSetVersion implements Serializable { - private static final long serialVersionUID = 1L; - - public static final int MAX_EXPANSION_STATUS_LENGTH = 50; - public static final int MAX_NAME_LENGTH = 200; - public static final int MAX_VERSION_LENGTH = 200; - - @Id() - @SequenceGenerator(name = "SEQ_VALUESETVER_PID", sequenceName = "SEQ_VALUESETVER_PID") - @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_VALUESETVER_PID") - @Column(name = "PID") - private Long myId; - - @OneToOne() - @JoinColumn(name = "RES_ID", referencedColumnName = "RES_ID", nullable = false, updatable = false, foreignKey = @ForeignKey(name = "FK_TRMVALUESETVER_RES")) - private ResourceTable myResource; - - @Column(name = "RES_ID", insertable = false, updatable = false) - private Long myResourcePid; - - @OneToMany(mappedBy = "myValueSet", fetch = FetchType.LAZY) - private List myConcepts; - - @Column(name = "TOTAL_CONCEPTS", nullable = false) - @ColumnDefault("0") - private Long myTotalConcepts; - - @Column(name = "TOTAL_CONCEPT_DESIGNATIONS", nullable = false) - @ColumnDefault("0") - private Long myTotalConceptDesignations; - - @Enumerated(EnumType.STRING) - @Column(name = "EXPANSION_STATUS", nullable = false, length = MAX_EXPANSION_STATUS_LENGTH) - private TermValueSetPreExpansionStatusEnum myExpansionStatus; - - @Column(name = "VS_VERSION_ID", nullable = true, updatable = false, length = MAX_VERSION_LENGTH) - private String myValueSetVersionId; - - /** - * This was added in HAPI FHIR 3.3.0 and is nullable just to avoid migration - * issued. It should be made non-nullable at some point. - */ - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "VALUESET_PID", referencedColumnName = "PID", nullable = true, foreignKey = @ForeignKey(name = "FK_VALSETVER_VS_ID")) - private TermValueSet myValueSet; - - @Column(name = "VALUESET_PID", insertable = false, updatable = false) - private Long myValueSetPid; - - @SuppressWarnings("unused") - @OneToOne(mappedBy = "myCurrentVersion", optional = true, fetch = FetchType.LAZY) - private TermValueSet myValueSetHavingThisVersionAsCurrentVersionIfAny; - - public TermValueSetVersion() { - super(); - myExpansionStatus = TermValueSetPreExpansionStatusEnum.NOT_EXPANDED; - myTotalConcepts = 0L; - myTotalConceptDesignations = 0L; - } - - public Long getId() { - return myId; - } - - public ResourceTable getResource() { - return myResource; - } - - public TermValueSetVersion setResource(ResourceTable theResource) { - myResource = theResource; - return this; - } - - public List getConcepts() { - if (myConcepts == null) { - myConcepts = new ArrayList<>(); - } - - return myConcepts; - } - - public Long getTotalConcepts() { - return myTotalConcepts; - } - - public TermValueSetVersion setTotalConcepts(Long theTotalConcepts) { - myTotalConcepts = theTotalConcepts; - return this; - } - - public TermValueSetVersion decrementTotalConcepts() { - if (myTotalConcepts > 0) { - myTotalConcepts--; - } - return this; - } - - public TermValueSetVersion incrementTotalConcepts() { - myTotalConcepts++; - return this; - } - - public Long getTotalConceptDesignations() { - return myTotalConceptDesignations; - } - - public TermValueSetVersion setTotalConceptDesignations(Long theTotalConceptDesignations) { - myTotalConceptDesignations = theTotalConceptDesignations; - return this; - } - - public TermValueSetVersion decrementTotalConceptDesignations() { - if (myTotalConceptDesignations > 0) { - myTotalConceptDesignations--; - } - return this; - } - - public TermValueSetVersion incrementTotalConceptDesignations() { - myTotalConceptDesignations++; - return this; - } - - public TermValueSetPreExpansionStatusEnum getExpansionStatus() { - return myExpansionStatus; - } - - public void setExpansionStatus(TermValueSetPreExpansionStatusEnum theExpansionStatus) { - myExpansionStatus = theExpansionStatus; - } - - public String getValueSetVersionId() { - return myValueSetVersionId; - } - - public TermValueSetVersion setValueSetVersionId(String theValueSetVersionId) { - ValidateUtil.isNotTooLongOrThrowIllegalArgument( - theValueSetVersionId, MAX_VERSION_LENGTH, - "Version ID exceeds maximum length (" + MAX_VERSION_LENGTH + "): " + length(theValueSetVersionId)); - myValueSetVersionId = theValueSetVersionId; - return this; - } - - public TermValueSet getValueSet() { - return myValueSet; - } - - public TermValueSetVersion setValueSet(TermValueSet theValueSet) { - myValueSet = theValueSet; - return this; - } - - public Long getValueSetPid() { - return myValueSetPid; - } - - @Override - public boolean equals(Object theO) { - if (this == theO) return true; - - if (!(theO instanceof TermValueSetVersion)) return false; - - TermValueSetVersion that = (TermValueSetVersion) theO; - - return new EqualsBuilder() - .append(myValueSetVersionId, that.myValueSetVersionId) - .append(myValueSetPid, that.myValueSetPid) - .isEquals(); - } - - @Override - public int hashCode() { - HashCodeBuilder b = new HashCodeBuilder(17, 37); - b.append(myValueSetVersionId); - b.append(myValueSetPid); - return b.toHashCode(); - } - - @Override - public String toString() { - return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) - .append("myId", myId) - .append(myResource != null ? ("myResource=" + myResource.toString()) : ("myResource=(null)")) - .append("myResourcePid", myResourcePid) - .append("valueSetPid", myValueSetPid) - .append("valueSetVersionId", myValueSetVersionId) - .append(myConcepts != null ? ("myConcepts - size=" + myConcepts.size()) : ("myConcepts=(null)")) - .append("myTotalConcepts", myTotalConcepts) - .append("myTotalConceptDesignations", myTotalConceptDesignations) - .append("myExpansionStatus", myExpansionStatus) - .toString(); - } -} diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java index 06576adb74f..e38d53284b8 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/BaseTermReadSvcImpl.java @@ -45,7 +45,6 @@ import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDesignationDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptViewDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetDao; -import ca.uhn.fhir.jpa.dao.data.ITermValueSetVersionDao; import ca.uhn.fhir.jpa.entity.TermCodeSystem; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermConcept; @@ -63,7 +62,6 @@ import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetConceptView; import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; -import ca.uhn.fhir.jpa.entity.TermValueSetVersion; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.jpa.model.sched.ISchedulerService; @@ -83,7 +81,6 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.CoverageIgnore; -import ca.uhn.fhir.util.ObjectUtil; import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.util.UrlUtil; import ca.uhn.fhir.util.ValidateUtil; @@ -207,8 +204,6 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { @Autowired protected ITermValueSetDao myValueSetDao; @Autowired - protected ITermValueSetVersionDao myValueSetVersionDao; - @Autowired protected ITermValueSetConceptDao myValueSetConceptDao; @Autowired protected ITermValueSetConceptDesignationDao myValueSetConceptDesignationDao; @@ -338,37 +333,16 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { public void deleteValueSetForResource(ResourceTable theResourceTable) { // Get existing entity so it can be deleted. - Optional optionalExistingTermValueSetVersionById = myValueSetVersionDao.findByResourcePid(theResourceTable.getId()); + Optional optionalExistingTermValueSetById = myValueSetDao.findByResourcePid(theResourceTable.getId()); - if (optionalExistingTermValueSetVersionById.isPresent()) { - TermValueSetVersion existingTermValueSetVersion = optionalExistingTermValueSetVersionById.get(); + if (optionalExistingTermValueSetById.isPresent()) { + TermValueSet existingTermValueSet = optionalExistingTermValueSetById.get(); - ourLog.info("Deleting existing TermValueSetVersion[{}] and its children...", existingTermValueSetVersion.getId()); - myValueSetConceptDesignationDao.deleteByTermValueSetId(existingTermValueSetVersion.getId()); - myValueSetConceptDao.deleteByTermValueSetId(existingTermValueSetVersion.getId()); - - // Check if this is the current version. If so, clear the current version from TermValueSet. - TermValueSet termValueSet = existingTermValueSetVersion.getValueSet(); - TransactionTemplate txTemplate = new TransactionTemplate(myTransactionManager); - txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); - Boolean versionIsCurrent = termValueSet.getCurrentVersion().getId() == existingTermValueSetVersion.getId(); - if (versionIsCurrent) { - txTemplate.executeWithoutResult(t -> { - termValueSet.setCurrentVersion(null); - myValueSetDao.save(termValueSet); - }); - } - - myValueSetVersionDao.deleteById(existingTermValueSetVersion.getId()); - ourLog.info("Done deleting existing TermValueSetVersion[{}] and its children.", existingTermValueSetVersion.getId()); - - // If this is the current version, then delete the TermValueSet master as well. - if (versionIsCurrent) { - txTemplate.executeWithoutResult(t -> { - ourLog.info(" * Deleting value set {}", termValueSet.getId()); - myValueSetDao.deleteById(termValueSet.getId()); - }); - } + ourLog.info("Deleting existing TermValueSet[{}] and its children...", existingTermValueSet.getId()); + myValueSetConceptDesignationDao.deleteByTermValueSetId(existingTermValueSet.getId()); + myValueSetConceptDao.deleteByTermValueSetId(existingTermValueSet.getId()); + myValueSetDao.deleteById(existingTermValueSet.getId()); + ourLog.info("Done deleting existing TermValueSet[{}] and its children.", existingTermValueSet.getId()); } } @@ -418,7 +392,11 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { Optional optionalTermValueSet; if (theValueSetToExpand.hasUrl()) { - optionalTermValueSet = myValueSetDao.findByUrl(theValueSetToExpand.getUrl()); + if (theValueSetToExpand.hasVersion()) { + optionalTermValueSet = myValueSetDao.findTermValueSetByUrlAndVersion(theValueSetToExpand.getUrl(), theValueSetToExpand.getVersion()); + } else { + optionalTermValueSet = myValueSetDao.findTermValueSetByUrlAndNullVersion(theValueSetToExpand.getUrl()); + } } else { optionalTermValueSet = Optional.empty(); } @@ -429,17 +407,10 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } TermValueSet termValueSet = optionalTermValueSet.get(); - TermValueSetVersion termValueSetVersion; - String valueSetVersion = theValueSetToExpand.getVersion(); - if (valueSetVersion != null) { - termValueSetVersion = myValueSetVersionDao.findByValueSetPidAndVersion(termValueSet.getId(),theValueSetToExpand.getVersion()); - } else { - termValueSetVersion = myValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - } - if (termValueSetVersion.getExpansionStatus() != TermValueSetPreExpansionStatusEnum.EXPANDED) { + if (termValueSet.getExpansionStatus() != TermValueSetPreExpansionStatusEnum.EXPANDED) { ourLog.warn("{} is present in terminology tables but not ready for persistence-backed invocation of operation $expand. Will perform in-memory expansion without parameters. Current status: {} | {}", - getValueSetInfo(theValueSetToExpand), termValueSetVersion.getExpansionStatus().name(), termValueSetVersion.getExpansionStatus().getDescription()); + getValueSetInfo(theValueSetToExpand), termValueSet.getExpansionStatus().name(), termValueSet.getExpansionStatus().getDescription()); return expandValueSetInMemory(theExpansionOptions, theValueSetToExpand, null); // In-memory expansion. } @@ -450,7 +421,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { ValueSetExpansionOptions expansionOptions = provideExpansionOptions(theExpansionOptions); int offset = expansionOptions.getOffset(); int count = expansionOptions.getCount(); - populateExpansionComponent(expansionComponent, termValueSetVersion, offset, count, termValueSet.getUrl()); + populateExpansionComponent(expansionComponent, termValueSet, offset, count, termValueSet.getUrl()); ValueSet valueSet = new ValueSet(); valueSet.setStatus(Enumerations.PublicationStatus.ACTIVE); @@ -459,8 +430,8 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { return valueSet; } - private void populateExpansionComponent(ValueSet.ValueSetExpansionComponent theExpansionComponent, TermValueSetVersion theTermValueSetVersion, int theOffset, int theCount, String theValueSetUrl) { - int total = theTermValueSetVersion.getTotalConcepts().intValue(); + private void populateExpansionComponent(ValueSet.ValueSetExpansionComponent theExpansionComponent, TermValueSet theTermValueSet, int theOffset, int theCount, String theValueSetUrl) { + int total = theTermValueSet.getTotalConcepts().intValue(); theExpansionComponent.setTotal(total); theExpansionComponent.setOffset(theOffset); theExpansionComponent.addParameter().setName("offset").setValue(new IntegerType(theOffset)); @@ -470,14 +441,14 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { return; } - expandConcepts(theExpansionComponent, theTermValueSetVersion, theOffset, theCount, theValueSetUrl); + expandConcepts(theExpansionComponent, theTermValueSet, theOffset, theCount, theValueSetUrl); } - private void expandConcepts(ValueSet.ValueSetExpansionComponent theExpansionComponent, TermValueSetVersion theTermValueSetVersion, int theOffset, int theCount, String theValueSetUrl) { + private void expandConcepts(ValueSet.ValueSetExpansionComponent theExpansionComponent, TermValueSet theTermValueSet, int theOffset, int theCount, String theValueSetUrl) { int conceptsExpanded = 0; int designationsExpanded = 0; int toIndex = theOffset + theCount; - Collection conceptViews = myTermValueSetConceptViewDao.findByTermValueSetId(theOffset, toIndex, theTermValueSetVersion.getId()); + Collection conceptViews = myTermValueSetConceptViewDao.findByTermValueSetId(theOffset, toIndex, theTermValueSet.getId()); if (conceptViews.isEmpty()) { logConceptsExpanded("No concepts to expand. ", theValueSetUrl, conceptsExpanded); @@ -1273,17 +1244,10 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { } TermValueSet termValueSet = optionalTermValueSet.get(); - TermValueSetVersion termValueSetVersion; - String valueSetVersion = theValueSet.getVersion(); - if (valueSetVersion != null) { - termValueSetVersion = myValueSetVersionDao.findByValueSetPidAndVersion(termValueSet.getId(), valueSetVersion); - } else { - termValueSetVersion = myValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - } - if (termValueSetVersion.getExpansionStatus() != TermValueSetPreExpansionStatusEnum.EXPANDED) { + if (termValueSet.getExpansionStatus() != TermValueSetPreExpansionStatusEnum.EXPANDED) { ourLog.warn("{} is present in terminology tables but not ready for persistence-backed invocation of operation $validation-code. Will perform in-memory code validation. Current status: {} | {}", - getValueSetInfo(theValueSet), termValueSetVersion.getExpansionStatus().name(), termValueSetVersion.getExpansionStatus().getDescription()); + getValueSetInfo(theValueSet), termValueSet.getExpansionStatus().name(), termValueSet.getExpansionStatus().getDescription()); return false; } @@ -1698,15 +1662,15 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { while (true) { StopWatch sw = new StopWatch(); - TermValueSetVersion valueSetToExpand = txTemplate.execute(t -> { - Optional optionalTermValueSetVersion = getNextTermValueSetNotExpanded(); - if (!optionalTermValueSetVersion.isPresent()) { + TermValueSet valueSetToExpand = txTemplate.execute(t -> { + Optional optionalTermValueSet = getNextTermValueSetNotExpanded(); + if (!optionalTermValueSet.isPresent()) { return null; } - TermValueSetVersion termValueSetVersion = optionalTermValueSetVersion.get(); - termValueSetVersion.setExpansionStatus(TermValueSetPreExpansionStatusEnum.EXPANSION_IN_PROGRESS); - return myValueSetVersionDao.saveAndFlush(termValueSetVersion); + TermValueSet termValueSet = optionalTermValueSet.get(); + termValueSet.setExpansionStatus(TermValueSetPreExpansionStatusEnum.EXPANSION_IN_PROGRESS); + return myValueSetDao.saveAndFlush(termValueSet); }); if (valueSetToExpand == null) { return; @@ -1715,18 +1679,17 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { // We have a ValueSet to pre-expand. try { ValueSet valueSet = txTemplate.execute(t -> { - TermValueSetVersion refreshedValueSetVersionToExpand = myValueSetVersionDao.findById(valueSetToExpand.getId()).get(); - return getValueSetFromResourceTable(refreshedValueSetVersionToExpand.getResource()); + TermValueSet refreshedValueSetToExpand = myValueSetDao.findById(valueSetToExpand.getId()).get(); + return getValueSetFromResourceTable(refreshedValueSetToExpand.getResource()); }); - ValueSetConceptAccumulator accumulator = new ValueSetConceptAccumulator(valueSetToExpand, myValueSetVersionDao, myValueSetDao, myValueSetConceptDao, myValueSetConceptDesignationDao); + ValueSetConceptAccumulator accumulator = new ValueSetConceptAccumulator(valueSetToExpand, myValueSetDao, myValueSetConceptDao, myValueSetConceptDesignationDao); expandValueSet(null, valueSet, accumulator); // We are done with this ValueSet. txTemplate.execute(t -> { - TermValueSetVersion finalValueSetToExpand = myValueSetVersionDao.findById(valueSetToExpand.getId()).get(); - finalValueSetToExpand.setExpansionStatus(TermValueSetPreExpansionStatusEnum.EXPANDED); - myValueSetVersionDao.saveAndFlush(finalValueSetToExpand); + valueSetToExpand.setExpansionStatus(TermValueSetPreExpansionStatusEnum.EXPANDED); + myValueSetDao.saveAndFlush(valueSetToExpand); return null; }); @@ -1736,7 +1699,7 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { ourLog.error("Failed to pre-expand ValueSet: " + e.getMessage(), e); txTemplate.execute(t -> { valueSetToExpand.setExpansionStatus(TermValueSetPreExpansionStatusEnum.FAILED_TO_EXPAND); - myValueSetVersionDao.saveAndFlush(valueSetToExpand); + myValueSetDao.saveAndFlush(valueSetToExpand); return null; }); } @@ -1801,9 +1764,9 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { protected abstract ValueSet getValueSetFromResourceTable(ResourceTable theResourceTable); - private Optional getNextTermValueSetNotExpanded() { - Optional retVal = Optional.empty(); - Slice page = myValueSetVersionDao.findByExpansionStatus(PageRequest.of(0, 1), TermValueSetPreExpansionStatusEnum.NOT_EXPANDED); + private Optional getNextTermValueSetNotExpanded() { + Optional retVal = Optional.empty(); + Slice page = myValueSetDao.findByExpansionStatus(PageRequest.of(0, 1), TermValueSetPreExpansionStatusEnum.NOT_EXPANDED); if (!page.getContent().isEmpty()) { retVal = Optional.of(page.getContent().get(0)); @@ -1823,7 +1786,11 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { /* * Get CodeSystem and validate CodeSystemVersion */ - TermValueSet termValueSet = getOrCreateDistinctTermValueSet(theResourceTable.getPersistentId(), theValueSet.getUrl(), theValueSet.getName(), theValueSet.getVersion(), theResourceTable); + TermValueSet termValueSet = new TermValueSet(); + termValueSet.setResource(theResourceTable); + termValueSet.setUrl(theValueSet.getUrl()); + termValueSet.setVersion(theValueSet.getVersion()); + termValueSet.setName(theValueSet.hasName() ? theValueSet.getName() : null); // Delete version being replaced deleteValueSetForResource(theResourceTable); @@ -1831,77 +1798,31 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc { /* * Do the upload. */ - TermValueSetVersion termValueSetVersion = termValueSet.getCurrentVersion(); - if (termValueSetVersion == null) { - termValueSetVersion = new TermValueSetVersion(); - } - - termValueSetVersion.setResource(theResourceTable); - termValueSetVersion.setValueSetVersionId(theValueSet.getVersion()); - termValueSetVersion.setValueSet(termValueSet); - - termValueSetVersion = myValueSetVersionDao.saveAndFlush(termValueSetVersion); - - termValueSet.setCurrentVersion(termValueSetVersion); - termValueSet = myValueSetDao.saveAndFlush(termValueSet); - - ourLog.info("Done storing TermValueSet[{}] for {}", termValueSet.getId(), theValueSet.getIdElement().toVersionless().getValueAsString()); - } - - - @Nonnull - private TermValueSet getOrCreateDistinctTermValueSet(ResourcePersistentId theValueSetResourcePid, String theSystemUri, String theSystemName, String theSystemVersionId, ResourceTable theValueSetResourceTable) { - Optional termValueSetOptional = myValueSetDao.findByUrl(theSystemUri); - TermValueSet termValueSet; - if (!termValueSetOptional.isPresent()) { - termValueSetOptional = myValueSetDao.findByResourcePid(theValueSetResourcePid.getIdAsLong()); - if (!termValueSetOptional.isPresent()) { - termValueSet = new TermValueSet(); - } else { - termValueSet = termValueSetOptional.get(); - } + String url = termValueSet.getUrl(); + String version = termValueSet.getVersion(); + Optional optionalExistingTermValueSetByUrl; + if (version != null) { + optionalExistingTermValueSetByUrl = myValueSetDao.findTermValueSetByUrlAndVersion(url, version); } else { - termValueSet = termValueSetOptional.get(); + optionalExistingTermValueSetByUrl = myValueSetDao.findTermValueSetByUrlAndNullVersion(url); } - - termValueSet.setResource(theValueSetResourceTable); - termValueSet.setUrl(theSystemUri); - termValueSet.setName(theSystemName); - termValueSet = myValueSetDao.save(termValueSet); - checkForValueSetVersionDuplicate(termValueSet,theSystemUri, theSystemVersionId, theValueSetResourceTable); - return termValueSet; - } - - - private void checkForValueSetVersionDuplicate(TermValueSet theValueSet, String theSystemUri, String theSystemVersionId, ResourceTable theValueSetResourceTable) { - // Check if TermValueSetVersion entity already exists. - TermValueSetVersion valueSetVersionEntity; - String msg = null; - if (theSystemVersionId == null) { - // Check if a non-versioned TermValueSetVersion entity already exists for this TermValueSet. - valueSetVersionEntity = myValueSetVersionDao.findByValueSetPidAndNullVersion(theValueSet.getId()); - if (valueSetVersionEntity != null) { - msg = myContext.getLocalizer().getMessage(BaseTermReadSvcImpl.class, "cannotCreateDuplicateValueSetUrl", theSystemUri, valueSetVersionEntity.getResource().getIdDt().toUnqualifiedVersionless().getValue()); - } + if (!optionalExistingTermValueSetByUrl.isPresent()) { + myValueSetDao.save(termValueSet); } else { - // Check if a TermValueSetVersion entity already exists for this TermValueSet and version. - valueSetVersionEntity = myValueSetVersionDao.findByValueSetPidAndVersion(theValueSet.getId(), theSystemVersionId); - if (valueSetVersionEntity != null) { - msg = myContext.getLocalizer().getMessage(BaseTermReadSvcImpl.class, "cannotCreateDuplicateValueSetUrlAndVersion", theSystemUri, theSystemVersionId, valueSetVersionEntity.getResource().getIdDt().toUnqualifiedVersionless().getValue()); + TermValueSet existingTermValueSet = optionalExistingTermValueSetByUrl.get(); + String msg; + if (version != null) { + msg = myContext.getLocalizer().getMessage( + BaseTermReadSvcImpl.class, + "cannotCreateDuplicateValueSetUrlAndVersion", + url, version, existingTermValueSet.getResource().getIdDt().toUnqualifiedVersionless().getValue()); } else { - // Check if a TermValueSetVersion entity already exists for this ValueSet resource (i.e. with a different version or URL) - Optional valueSetVersionEntityOptional = myValueSetVersionDao.findByResourcePid(theValueSetResourceTable.getId()); - if (valueSetVersionEntityOptional.isPresent()) { - msg = myContext.getLocalizer().getMessage(BaseTermReadSvcImpl.class, "cannotUpdateUrlOrVersionForValueSetResource", theSystemUri, theSystemVersionId, valueSetVersionEntity.getResource().getIdDt().toUnqualifiedVersionless().getValue()); - throw new UnprocessableEntityException(msg); - } - } - } - // Throw exception if the TermValueSet version is being duplicated. - if (valueSetVersionEntity != null) { - if (!ObjectUtil.equals(valueSetVersionEntity.getResource().getId(), theValueSetResourceTable.getId())) { - throw new UnprocessableEntityException(msg); + msg = myContext.getLocalizer().getMessage( + BaseTermReadSvcImpl.class, + "cannotCreateDuplicateValueSetUrl", + url, existingTermValueSet.getResource().getIdDt().toUnqualifiedVersionless().getValue()); } + throw new UnprocessableEntityException(msg); } } 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 2098fbbce5f..ac19b652593 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 @@ -715,7 +715,7 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc { // Check if a TermCodeSystemVersion entity already exists for this CodeSystem resource (i.e. with a different version or URL) codeSystemVersionEntity = myCodeSystemVersionDao.findByCodeSystemResourcePid(theCodeSystemResourceTable.getId()); if (codeSystemVersionEntity != null) { - msg = myContext.getLocalizer().getMessage(BaseTermReadSvcImpl.class, "cannotUpdateUrlOrVersionForCodeSystemResource", theSystemUri, theSystemVersionId, codeSystemVersionEntity.getResource().getIdDt().toUnqualifiedVersionless().getValue()); + msg = myContext.getLocalizer().getMessage(BaseTermReadSvcImpl.class, "cannotUpdateUrlOrVersionForCodeSystemResource", codeSystemVersionEntity.getResource().getIdDt().toUnqualifiedVersionless().getValue(), theSystemUri, theSystemVersionId); throw new UnprocessableEntityException(msg); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImpl.java index 5c5fe0c5a07..e27177f3f1a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImpl.java @@ -227,6 +227,7 @@ public class TermDeferredStorageSvcImpl implements ITermDeferredStorageSvc { myDeferredConceptMaps.clear(); myDeferredConcepts.clear(); myDefferedCodeSystemsDeletions.clear(); + myConceptLinksToSaveLater.clear(); } @Transactional(propagation = Propagation.NEVER) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulator.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulator.java index 5b444ee6a5a..fda53d03c5e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulator.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulator.java @@ -23,12 +23,10 @@ package ca.uhn.fhir.jpa.term; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDesignationDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetDao; -import ca.uhn.fhir.jpa.dao.data.ITermValueSetVersionDao; import ca.uhn.fhir.jpa.entity.TermConceptDesignation; import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation; -import ca.uhn.fhir.jpa.entity.TermValueSetVersion; import ca.uhn.fhir.util.ValidateUtil; import javax.annotation.Nonnull; @@ -43,8 +41,7 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValueSetConceptAccumulator.class); - private TermValueSetVersion myTermValueSetVersion; - final private ITermValueSetVersionDao myValueSetVersionDao; + private TermValueSet myTermValueSet; final private ITermValueSetDao myValueSetDao; final private ITermValueSetConceptDao myValueSetConceptDao; final private ITermValueSetConceptDesignationDao myValueSetConceptDesignationDao; @@ -52,9 +49,8 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator { private int myDesignationsSaved; private int myConceptsExcluded; - public ValueSetConceptAccumulator(@Nonnull TermValueSetVersion theTermValueSetVersion, @Nonnull ITermValueSetVersionDao theValueSetVersionDao, @Nonnull ITermValueSetDao theValueSetDao, @Nonnull ITermValueSetConceptDao theValueSetConceptDao, @Nonnull ITermValueSetConceptDesignationDao theValueSetConceptDesignationDao) { - myTermValueSetVersion = theTermValueSetVersion; - myValueSetVersionDao = theValueSetVersionDao; + public ValueSetConceptAccumulator(@Nonnull TermValueSet theTermValueSet, @Nonnull ITermValueSetDao theValueSetDao, @Nonnull ITermValueSetConceptDao theValueSetConceptDao, @Nonnull ITermValueSetConceptDesignationDao theValueSetConceptDesignationDao) { + myTermValueSet = theTermValueSet; myValueSetDao = theValueSetDao; myValueSetConceptDao = theValueSetConceptDao; myValueSetConceptDesignationDao = theValueSetConceptDesignationDao; @@ -91,23 +87,23 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator { } // Get existing entity so it can be deleted. - Optional optionalConcept = myValueSetConceptDao.findByTermValueSetIdSystemAndCode(myTermValueSetVersion.getId(), theSystem, theCode); + Optional optionalConcept = myValueSetConceptDao.findByTermValueSetIdSystemAndCode(myTermValueSet.getId(), theSystem, theCode); if (optionalConcept.isPresent()) { TermValueSetConcept concept = optionalConcept.get(); - ourLog.debug("Excluding [{}|{}] from ValueSet[{}]", concept.getSystem(), concept.getCode(), myTermValueSetVersion.getValueSet().getUrl()); + ourLog.debug("Excluding [{}|{}] from ValueSet[{}]", concept.getSystem(), concept.getCode(), myTermValueSet.getUrl()); for (TermValueSetConceptDesignation designation : concept.getDesignations()) { myValueSetConceptDesignationDao.deleteById(designation.getId()); - myTermValueSetVersion.decrementTotalConceptDesignations(); + myTermValueSet.decrementTotalConceptDesignations(); } myValueSetConceptDao.deleteById(concept.getId()); - myTermValueSetVersion.decrementTotalConcepts(); - myValueSetVersionDao.save(myTermValueSetVersion); - ourLog.debug("Done excluding [{}|{}] from ValueSet[{}]", concept.getSystem(), concept.getCode(), myTermValueSetVersion.getValueSet().getUrl()); + myTermValueSet.decrementTotalConcepts(); + myValueSetDao.save(myTermValueSet); + ourLog.debug("Done excluding [{}|{}] from ValueSet[{}]", concept.getSystem(), concept.getCode(), myTermValueSet.getUrl()); if (++myConceptsExcluded % 250 == 0) { - ourLog.info("Have excluded {} concepts from ValueSet[{}]", myConceptsExcluded, myTermValueSetVersion.getValueSet().getUrl()); + ourLog.info("Have excluded {} concepts from ValueSet[{}]", myConceptsExcluded, myTermValueSet.getUrl()); } } } @@ -116,9 +112,8 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator { ValidateUtil.isNotBlankOrThrowInvalidRequest(theSystem, "ValueSet contains a concept with no system value"); ValidateUtil.isNotBlankOrThrowInvalidRequest(theCode, "ValueSet contains a concept with no code value"); - myTermValueSetVersion = myValueSetVersionDao.findById(myTermValueSetVersion.getId()).get(); TermValueSetConcept concept = new TermValueSetConcept(); - concept.setValueSet(myTermValueSetVersion.getValueSet()); + concept.setValueSet(myTermValueSet); concept.setOrder(myConceptsSaved); concept.setSystem(theSystem); concept.setCode(theCode); @@ -126,23 +121,21 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator { concept.setDisplay(theDisplay); } myValueSetConceptDao.save(concept); - myTermValueSetVersion.incrementTotalConcepts(); - myValueSetVersionDao.save(myTermValueSetVersion); + myValueSetDao.save(myTermValueSet.incrementTotalConcepts()); if (++myConceptsSaved % 250 == 0) { - ourLog.info("Have pre-expanded {} concepts in ValueSet[{}]", myConceptsSaved, myTermValueSetVersion.getValueSet().getUrl()); + ourLog.info("Have pre-expanded {} concepts in ValueSet[{}]", myConceptsSaved, myTermValueSet.getUrl()); } return concept; } - private void saveConceptDesignation(TermValueSetConcept theConcept, TermConceptDesignation theDesignation) { + private TermValueSetConceptDesignation saveConceptDesignation(TermValueSetConcept theConcept, TermConceptDesignation theDesignation) { ValidateUtil.isNotBlankOrThrowInvalidRequest(theDesignation.getValue(), "ValueSet contains a concept designation with no value"); TermValueSetConceptDesignation designation = new TermValueSetConceptDesignation(); designation.setConcept(theConcept); - myTermValueSetVersion = myValueSetVersionDao.findById(myTermValueSetVersion.getId()).get(); - designation.setValueSet(myTermValueSetVersion.getValueSet()); + designation.setValueSet(myTermValueSet); designation.setLanguage(theDesignation.getLanguage()); if (isNoneBlank(theDesignation.getUseSystem(), theDesignation.getUseCode())) { designation.setUseSystem(theDesignation.getUseSystem()); @@ -153,12 +146,13 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator { } designation.setValue(theDesignation.getValue()); myValueSetConceptDesignationDao.save(designation); - myValueSetVersionDao.save(myTermValueSetVersion.incrementTotalConceptDesignations()); + myValueSetDao.save(myTermValueSet.incrementTotalConceptDesignations()); if (++myDesignationsSaved % 250 == 0) { - ourLog.debug("Have pre-expanded {} designations for Concept[{}|{}] in ValueSet[{}]", myDesignationsSaved, theConcept.getSystem(), theConcept.getCode(), myTermValueSetVersion.getValueSet().getUrl()); + ourLog.debug("Have pre-expanded {} designations for Concept[{}|{}] in ValueSet[{}]", myDesignationsSaved, theConcept.getSystem(), theConcept.getCode(), myTermValueSet.getUrl()); } + return designation; } public Boolean removeGapsFromConceptOrder() { @@ -166,13 +160,13 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator { return false; } - ourLog.info("Removing gaps from concept order for ValueSet[{}]", myTermValueSetVersion.getValueSet().getUrl()); + ourLog.info("Removing gaps from concept order for ValueSet[{}]", myTermValueSet.getUrl()); int order = 0; - List conceptIds = myValueSetConceptDao.findIdsByTermValueSetId(myTermValueSetVersion.getId()); + List conceptIds = myValueSetConceptDao.findIdsByTermValueSetId(myTermValueSet.getId()); for (Long conceptId : conceptIds) { myValueSetConceptDao.updateOrderById(conceptId, order++); } - ourLog.info("Have removed gaps from concept order for {} concepts in ValueSet[{}]", conceptIds.size(), myTermValueSetVersion.getValueSet().getUrl()); + ourLog.info("Have removed gaps from concept order for {} concepts in ValueSet[{}]", conceptIds.size(), myTermValueSet.getUrl()); return true; } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java index 0484f6e1ae5..7c8a52d6a48 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java @@ -29,7 +29,6 @@ import ca.uhn.fhir.jpa.dao.data.ITermConceptDao; import ca.uhn.fhir.jpa.dao.data.ITermConceptMapDao; import ca.uhn.fhir.jpa.dao.data.ITermConceptMapGroupElementTargetDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetDao; -import ca.uhn.fhir.jpa.dao.data.ITermValueSetVersionDao; import ca.uhn.fhir.jpa.dao.dstu2.FhirResourceDaoDstu2SearchNoFtTest; import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.jpa.model.entity.ModelConfig; @@ -53,7 +52,6 @@ import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.provider.ResourceProviderFactory; -import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; import org.apache.commons.io.IOUtils; import org.hibernate.search.jpa.FullTextEntityManager; @@ -344,8 +342,6 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { private IBulkDataExportSvc myBulkDataExportSvc; @Autowired protected ITermValueSetDao myTermValueSetDao; - @Autowired - protected ITermValueSetVersionDao myTermValueSetVersionDao; @AfterEach() public void afterCleanupDao() { 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 d34393b7b61..7c21676735e 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 @@ -80,6 +80,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { private CodeSystem createExternalCs() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(URL_MY_CODE_SYSTEM); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); codeSystem.setName("ACME Codes"); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); @@ -124,6 +125,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { private void createExternalCsLarge() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(URL_MY_CODE_SYSTEM); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); @@ -165,6 +167,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { private CodeSystem createExternalCsDogs() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(URL_MY_CODE_SYSTEM); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); @@ -698,6 +701,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { public void testLookupSnomed() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl("http://snomed.info/sct"); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValueSetTest.java index ca5e887afad..9500b926ac7 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValueSetTest.java @@ -3,7 +3,6 @@ package ca.uhn.fhir.jpa.dao.dstu3; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; -import ca.uhn.fhir.jpa.entity.TermValueSetVersion; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.CodeType; @@ -23,6 +22,7 @@ import org.springframework.transaction.annotation.Transactional; import java.io.IOException; +import static org.awaitility.Awaitility.await; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; @@ -59,9 +59,7 @@ public class FhirResourceDaoDstu3ValueSetTest extends BaseJpaDstu3Test { runInTransaction(() -> { TermValueSet vsEntity = myTermValueSetDao.findByUrl("http://decor.nictiz.nl/fhir/ValueSet/2.16.840.1.113883.2.4.3.11.60.40.2.20.5.2--20171231000000").orElseThrow(() -> new IllegalStateException()); - Long valueSetId = vsEntity.getId(); - TermValueSetVersion vsvEntity = myTermValueSetVersionDao.findByValueSetPid(valueSetId).get(0); - assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsvEntity.getExpansionStatus()); + assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsEntity.getExpansionStatus()); }); IValidationSupport.CodeValidationResult validationOutcome; @@ -79,12 +77,12 @@ public class FhirResourceDaoDstu3ValueSetTest extends BaseJpaDstu3Test { validationOutcome = myValueSetDao.validateCode(vsIdentifier, null, code, system, null, null, null, mySrd); assertEquals(false, validationOutcome.isOk()); + await().until(() -> clearDeferredStorageQueue()); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); runInTransaction(() -> { TermValueSet vsEntity = myTermValueSetDao.findByUrl("http://decor.nictiz.nl/fhir/ValueSet/2.16.840.1.113883.2.4.3.11.60.40.2.20.5.2--20171231000000").orElseThrow(() -> new IllegalStateException()); - TermValueSetVersion vsvEntity = myTermValueSetVersionDao.findByValueSetPid(vsEntity.getId()).get(0); - assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, vsvEntity.getExpansionStatus()); + assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, vsEntity.getExpansionStatus()); }); // Validate good @@ -99,6 +97,16 @@ public class FhirResourceDaoDstu3ValueSetTest extends BaseJpaDstu3Test { } + private boolean clearDeferredStorageQueue() { + + if(!myTerminologyDeferredStorageSvc.isStorageQueueEmpty()) { + myTerminologyDeferredStorageSvc.saveAllDeferred(); + return false; + } else { + return true; + } + + } @Test @Disabled diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4Test.java index 5fe669b636a..12ef9a2206a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4Test.java @@ -47,7 +47,6 @@ import ca.uhn.fhir.jpa.dao.data.ITermConceptParentChildLinkDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDesignationDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetDao; -import ca.uhn.fhir.jpa.dao.data.ITermValueSetVersionDao; import ca.uhn.fhir.jpa.dao.dstu2.FhirResourceDaoDstu2SearchNoFtTest; import ca.uhn.fhir.jpa.dao.index.IdHelperService; import ca.uhn.fhir.jpa.entity.TermCodeSystem; @@ -65,7 +64,6 @@ import ca.uhn.fhir.jpa.search.IStaleSearchDeletingSvc; import ca.uhn.fhir.jpa.search.reindex.IResourceReindexingSvc; import ca.uhn.fhir.jpa.search.warm.ICacheWarmingSvc; import ca.uhn.fhir.jpa.searchparam.registry.SearchParamRegistryImpl; -import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; import ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl; import ca.uhn.fhir.jpa.term.TermDeferredStorageSvcImpl; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; @@ -82,7 +80,6 @@ import ca.uhn.fhir.rest.server.BasePagingProvider; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.provider.ResourceProviderFactory; import ca.uhn.fhir.test.utilities.ITestDataBuilder; -import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.ValidationResult; @@ -439,8 +436,6 @@ public abstract class BaseJpaR4Test extends BaseJpaTest implements ITestDataBuil @Autowired protected ITermValueSetDao myTermValueSetDao; @Autowired - protected ITermValueSetVersionDao myTermValueSetVersionDao; - @Autowired protected ITermValueSetConceptDao myTermValueSetConceptDao; @Autowired protected ITermValueSetConceptDesignationDao myTermValueSetConceptDesignationDao; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java index 2139b93b543..1b614aa7d04 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java @@ -209,6 +209,7 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest { private CodeSystem createExternalCs() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(URL_MY_CODE_SYSTEM); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystem.CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyElasticsearchIT.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyElasticsearchIT.java index e5c298a8011..098754e33ea 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyElasticsearchIT.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyElasticsearchIT.java @@ -85,6 +85,7 @@ public class FhirResourceDaoR4TerminologyElasticsearchIT extends BaseJpaTest { public void testExpandWithIncludeContainingDashesInInclude() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(URL_MY_CODE_SYSTEM); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java index 63b88299e1b..90d30645a5b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java @@ -80,6 +80,7 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { private CodeSystem createExternalCs() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(URL_MY_CODE_SYSTEM); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); @@ -129,6 +130,7 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { private CodeSystem createExternalCsDogs() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(URL_MY_CODE_SYSTEM); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); @@ -159,6 +161,7 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { private void createExternalCsLarge() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(URL_MY_CODE_SYSTEM); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); @@ -473,6 +476,7 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { public void testExpandWithIncludeContainingDashesInInclude() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(URL_MY_CODE_SYSTEM); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); @@ -815,6 +819,7 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { public void testLookupSnomed() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl("http://snomed.info/sct"); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java index 0cf1bc2d874..0ef54220a16 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java @@ -7,11 +7,8 @@ import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; -import ca.uhn.fhir.jpa.entity.TermValueSetVersion; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl; -import ca.uhn.fhir.jpa.term.TerminologyLoaderSvcLoincTest; -import ca.uhn.fhir.jpa.term.ZipCollectionBuilder; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc; import ca.uhn.fhir.jpa.term.api.ITermReadSvc; @@ -81,7 +78,6 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -212,9 +208,10 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { myStructureDefinitionDao.create(loadResourceFromClasspath(StructureDefinition.class, "/r4/bl/bb-sd.json")); runInTransaction(() -> { - TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException()); - TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId()); - assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsv.getExpansionStatus()); + TermValueSet vs = myTermValueSetDao.findTermValueSetByUrlAndVersion("https://bb/ValueSet/BBDemographicAgeUnit","20190731").orElseThrow(() -> new IllegalArgumentException()); +// TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId()); +// assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsv.getExpansionStatus()); + assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vs.getExpansionStatus()); }); OperationOutcome outcome; @@ -242,17 +239,19 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { // Before, the VS wasn't pre-expanded. Try again with it pre-expanded runInTransaction(() -> { - TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException()); - TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId()); - assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsv.getExpansionStatus()); + TermValueSet vs = myTermValueSetDao.findTermValueSetByUrlAndVersion("https://bb/ValueSet/BBDemographicAgeUnit","20190731").orElseThrow(() -> new IllegalArgumentException()); +// TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId()); +// assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsv.getExpansionStatus()); + assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vs.getExpansionStatus()); }); myTermReadSvc.preExpandDeferredValueSetsToTerminologyTables(); runInTransaction(() -> { - TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException()); - TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId()); - assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, vsv.getExpansionStatus()); + TermValueSet vs = myTermValueSetDao.findTermValueSetByUrlAndVersion("https://bb/ValueSet/BBDemographicAgeUnit", "20190731").orElseThrow(() -> new IllegalArgumentException()); +// TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId()); +// assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, vsv.getExpansionStatus()); + assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, vs.getExpansionStatus()); }); // Use a code that's in the ValueSet @@ -285,9 +284,10 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { myStructureDefinitionDao.create(loadResourceFromClasspath(StructureDefinition.class, "/r4/bl/bb-sd.json")); runInTransaction(() -> { - TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException()); - TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId()); - assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsv.getExpansionStatus()); + TermValueSet vs = myTermValueSetDao.findTermValueSetByUrlAndVersion("https://bb/ValueSet/BBDemographicAgeUnit", "20190731").orElseThrow(() -> new IllegalArgumentException()); +// TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId()); +// assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsv.getExpansionStatus()); + assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vs.getExpansionStatus()); }); OperationOutcome outcome; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/BaseJpaR5Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/BaseJpaR5Test.java index e3967c118b4..9cd0bb49e5a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/BaseJpaR5Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/BaseJpaR5Test.java @@ -44,7 +44,6 @@ import ca.uhn.fhir.jpa.dao.data.ITermConceptParentChildLinkDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDesignationDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetDao; -import ca.uhn.fhir.jpa.dao.data.ITermValueSetVersionDao; import ca.uhn.fhir.jpa.dao.dstu2.FhirResourceDaoDstu2SearchNoFtTest; import ca.uhn.fhir.jpa.interceptor.PerformanceTracingLoggingInterceptor; import ca.uhn.fhir.jpa.model.entity.ModelConfig; @@ -70,7 +69,6 @@ import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.server.BasePagingProvider; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.provider.ResourceProviderFactory; -import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.ValidationResult; @@ -385,8 +383,8 @@ public abstract class BaseJpaR5Test extends BaseJpaTest { protected IFhirResourceDaoValueSet myValueSetDao; @Autowired protected ITermValueSetDao myTermValueSetDao; - @Autowired - protected ITermValueSetVersionDao myTermValueSetVersionDao; +// @Autowired +// protected ITermValueSetVersionDao myTermValueSetVersionDao; @Autowired protected ITermValueSetConceptDao myTermValueSetConceptDao; @Autowired diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java index 0468e5176b8..e7ee8efdc5c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java @@ -137,6 +137,7 @@ public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3 runInTransaction(() -> { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(CS_URL); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java index 0ed780b76e4..48986d9b46c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java @@ -25,9 +25,6 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test CodeSystem cs = loadResourceFromClasspath(CodeSystem.class, "/extensional-case-3-cs.xml"); myCodeSystemDao.create(cs, mySrd); - ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); - myValueSetDao.create(upload, mySrd).getId().toUnqualifiedVersionless(); - CodeSystem parentChildCs = new CodeSystem(); parentChildCs.setUrl(SYSTEM_PARENTCHILD); parentChildCs.setStatus(Enumerations.PublicationStatus.ACTIVE); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemVersionedTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemVersionedTest.java index d6cce634524..8853d23a439 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemVersionedTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemVersionedTest.java @@ -37,9 +37,6 @@ public class ResourceProviderR4CodeSystemVersionedTest extends BaseResourceProvi cs = loadResourceFromClasspath(CodeSystem.class, "/extensional-case-3-cs-v2.xml"); myCodeSystemDao.create(cs, mySrd); - ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); - myValueSetDao.create(upload, mySrd).getId().toUnqualifiedVersionless(); - CodeSystem parentChildCs = new CodeSystem(); parentChildCs.setUrl(SYSTEM_PARENTCHILD); parentChildCs.setVersion("1"); 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 5780bc2c54f..6cb278e6bc8 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 @@ -10,14 +10,12 @@ import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation; import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; -import ca.uhn.fhir.jpa.entity.TermValueSetVersion; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; -import ca.uhn.fhir.util.ParametersUtil; import ca.uhn.fhir.util.UrlUtil; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; @@ -809,9 +807,11 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals(theValueSetName, termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(0, termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(0, termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(0, termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); }); } @@ -828,11 +828,14 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals(theValueSetName, termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(theCodeSystem.getConcept().size(), termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(theCodeSystem.getConcept().size(), termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(theCodeSystem.getConcept().size(), termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); - TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); +// TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); + TermValueSetConcept concept = termValueSet.getConcepts().get(0); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8450-9", concept.getCode()); @@ -854,7 +857,8 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(1); +// concept = termValueSetVersion.getConcepts().get(1); + concept = termValueSet.getConcepts().get(1); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("11378-7", concept.getCode()); @@ -864,7 +868,8 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { // ... - concept = termValueSetVersion.getConcepts().get(22); +// concept = termValueSetVersion.getConcepts().get(22); + concept = termValueSet.getConcepts().get(22); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8491-3", concept.getCode()); @@ -879,7 +884,8 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(23); +// concept = termValueSetVersion.getConcepts().get(23); + concept = termValueSet.getConcepts().get(23); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8492-1", concept.getCode()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java index 5dc82c5fbc1..f1aa18de3ff 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java @@ -106,7 +106,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes ourLog.info(resp); assertThat(((IntegerType) respParam.getParameter().get(1).getValue()).getValue(), greaterThan(1)); - assertThat(((Reference) respParam.getParameter().get(2).getValue()).getReference(), matchesPattern("CodeSystem\\/[a-zA-Z0-9]+")); + assertThat(((Reference) respParam.getParameter().get(2).getValue()).getReference(), matchesPattern("CodeSystem\\/[a-zA-Z0-9\\.\\-]+")); /* * Try uploading a second time diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ValueSetTest.java index f94754d8d6f..8577c366884 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ValueSetTest.java @@ -1120,9 +1120,11 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals(theValueSetName, termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(0, termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(0, termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(0, termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); }); } @@ -1139,11 +1141,14 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals(theValueSetName, termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(theCodeSystem.getConcept().size(), termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(theCodeSystem.getConcept().size(), termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(theCodeSystem.getConcept().size(), termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); - TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); +// TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); + TermValueSetConcept concept = termValueSet.getConcepts().get(0); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8450-9", concept.getCode()); @@ -1165,7 +1170,8 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(1); +// concept = termValueSetVersion.getConcepts().get(1); + concept = termValueSet.getConcepts().get(1); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("11378-7", concept.getCode()); @@ -1175,7 +1181,8 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { // ... - concept = termValueSetVersion.getConcepts().get(22); +// concept = termValueSetVersion.getConcepts().get(22); + concept = termValueSet.getConcepts().get(22); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8491-3", concept.getCode()); @@ -1190,7 +1197,8 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(23); +// concept = termValueSetVersion.getConcepts().get(23); + concept = termValueSet.getConcepts().get(23); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8492-1", concept.getCode()); @@ -1408,6 +1416,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { public static CodeSystem createExternalCs(IFhirResourceDao theCodeSystemDao, IResourceTableDao theResourceTableDao, ITermCodeSystemStorageSvc theTermCodeSystemStorageSvc, ServletRequestDetails theRequestDetails) { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(URL_MY_CODE_SYSTEM); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = theCodeSystemDao.create(codeSystem, theRequestDetails).getId().toUnqualified(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java index c3787c589b0..0ffe92d13bb 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java @@ -63,6 +63,7 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { codeSystem.setUrl(CS_URL); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); codeSystem.setName("SYSTEM NAME"); + codeSystem.setVersion("SYSTEM VERSION"); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); ResourceTable table = myResourceTableDao.findById(id.getIdPartAsLong()).orElseThrow(IllegalArgumentException::new); @@ -116,6 +117,7 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { private void createCodeSystem2() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(CS_URL_2); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); @@ -135,6 +137,7 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { runInTransaction(() -> { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(LOINC_URI); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); @@ -204,6 +207,7 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { public void testCreateDuplicateCodeSystemUri() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(CS_URL); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); @@ -226,12 +230,13 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { // Try to update to a different resource codeSystem = new CodeSystem(); codeSystem.setUrl(CS_URL); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); try { myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); fail(); } catch (UnprocessableEntityException e) { - assertThat(e.getMessage(), containsString("Can not create multiple CodeSystem resources with CodeSystem.url \"http://example.com/my_code_system\", already have one with resource ID: CodeSystem/")); + assertThat(e.getMessage(), containsString("Can not create multiple CodeSystem resources with CodeSystem.url \"http://example.com/my_code_system\" and CodeSystem.version \"SYSTEM VERSION\", already have one with resource ID: CodeSystem/")); } } @@ -1813,6 +1818,7 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { public void testStoreCodeSystemInvalidCyclicLoop() { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(CS_URL); + codeSystem.setVersion("SYSTEM VERSION"); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); IIdType id = myCodeSystemDao.create(codeSystem, mySrd).getId().toUnqualified(); @@ -1834,7 +1840,7 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { child.addChild(parent, RelationshipTypeEnum.ISA); try { - myTermCodeSystemStorageSvc.storeNewCodeSystemVersion(table.getPersistentId(), "http://foo", "SYSTEM NAME", "SYSTEM VERSION", cs, table); + myTermCodeSystemStorageSvc.storeNewCodeSystemVersion(table.getPersistentId(), CS_URL, "SYSTEM NAME", "SYSTEM VERSION", cs, table); fail(); } catch (InvalidRequestException e) { assertEquals("CodeSystem contains circular reference around code parent", e.getMessage()); @@ -1948,6 +1954,7 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { CodeSystem cs = new CodeSystem(); cs.setUrl("http://codesystems-r-us"); + cs.setVersion("SYSTEM VERSION"); cs.setContent(CodeSystem.CodeSystemContentMode.NOTPRESENT); IIdType csId = myCodeSystemDao.create(cs).getId().toUnqualifiedVersionless(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java index 9029075718f..629037325fe 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java @@ -12,7 +12,6 @@ import ca.uhn.fhir.jpa.entity.TermConceptMapGroup; import ca.uhn.fhir.jpa.entity.TermConceptMapGroupElement; import ca.uhn.fhir.jpa.entity.TermConceptMapGroupElementTarget; import ca.uhn.fhir.jpa.entity.TermValueSet; -import ca.uhn.fhir.jpa.entity.TermValueSetVersion; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.CanonicalType; @@ -195,10 +194,12 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test { TermValueSet termValueSet = myTermValueSetDao.findByResourcePid(myExtensionalVsIdOnResourceTable).get(); Long termValueSetId = termValueSet.getId(); assertEquals(3, myTermValueSetConceptDesignationDao.countByTermValueSetId(termValueSetId).intValue()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(3, termValueSetVersion.getTotalConceptDesignations().intValue()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(3, termValueSetVersion.getTotalConceptDesignations().intValue()); + assertEquals(3, termValueSet.getTotalConceptDesignations().intValue()); assertEquals(24, myTermValueSetConceptDao.countByTermValueSetId(termValueSetId).intValue()); - assertEquals(24, termValueSetVersion.getTotalConcepts().intValue()); +// assertEquals(24, termValueSetVersion.getTotalConcepts().intValue()); + assertEquals(24, termValueSet.getTotalConcepts().intValue()); new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() { @Override @@ -233,10 +234,12 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test { TermValueSet termValueSet = myTermValueSetDao.findByResourcePid(myExtensionalVsIdOnResourceTable).get(); Long termValueSetId = termValueSet.getId(); assertEquals(3, myTermValueSetConceptDesignationDao.countByTermValueSetId(termValueSetId).intValue()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(3, termValueSetVersion.getTotalConceptDesignations().intValue()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(3, termValueSetVersion.getTotalConceptDesignations().intValue()); + assertEquals(3, termValueSet.getTotalConceptDesignations().intValue()); assertEquals(24, myTermValueSetConceptDao.countByTermValueSetId(termValueSetId).intValue()); - assertEquals(24, termValueSetVersion.getTotalConcepts().intValue()); +// assertEquals(24, termValueSetVersion.getTotalConcepts().intValue()); + assertEquals(24, termValueSet.getTotalConcepts().intValue()); new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() { @Override diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulatorTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulatorTest.java index e0480afcfa7..16d3dc3d930 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulatorTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulatorTest.java @@ -2,10 +2,10 @@ package ca.uhn.fhir.jpa.term; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDesignationDao; -import ca.uhn.fhir.jpa.dao.data.ITermValueSetVersionDao; +import ca.uhn.fhir.jpa.dao.data.ITermValueSetDao; +import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation; -import ca.uhn.fhir.jpa.entity.TermValueSetVersion; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -25,9 +25,9 @@ import static org.mockito.Mockito.when; public class ValueSetConceptAccumulatorTest { private ValueSetConceptAccumulator myAccumulator; - private TermValueSetVersion myValueSetVersion; + private TermValueSet myValueSet; @Mock - private ITermValueSetVersionDao myValueSetVersionDao; + private ITermValueSetDao myValueSetDao; @Mock private ITermValueSetConceptDesignationDao myValueSetDesignationDao; @Mock @@ -35,8 +35,8 @@ public class ValueSetConceptAccumulatorTest { @BeforeEach public void before() { - myValueSetVersion = new TermValueSetVersion(); - myAccumulator = new ValueSetConceptAccumulator(myValueSetVersion, myValueSetVersionDao, null, myValueSetConceptDao, myValueSetDesignationDao); + myValueSet = new TermValueSet(); + myAccumulator = new ValueSetConceptAccumulator(myValueSet, myValueSetDao, myValueSetConceptDao, myValueSetDesignationDao); } @Test diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4Test.java index 5dd8ac22d4f..7cc370d572a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4Test.java @@ -9,7 +9,6 @@ import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation; import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; -import ca.uhn.fhir.jpa.entity.TermValueSetVersion; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.term.custom.CustomTerminologySet; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; @@ -1166,9 +1165,11 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(0, termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(0, termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(0, termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); }); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); @@ -1185,11 +1186,14 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(codeSystem.getConcept().size(), termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(codeSystem.getConcept().size(), termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(codeSystem.getConcept().size(), termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); - TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); +// TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); + TermValueSetConcept concept = termValueSet.getConcepts().get(0); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8450-9", concept.getCode()); @@ -1211,7 +1215,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(1); +// concept = termValueSetVersion.getConcepts().get(1); + concept = termValueSet.getConcepts().get(1); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("11378-7", concept.getCode()); @@ -1221,7 +1226,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { // ... - concept = termValueSetVersion.getConcepts().get(22); +// concept = termValueSetVersion.getConcepts().get(22); + concept = termValueSet.getConcepts().get(22); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8491-3", concept.getCode()); @@ -1236,7 +1242,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(23); +// concept = termValueSetVersion.getConcepts().get(23); + concept = termValueSet.getConcepts().get(23); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8492-1", concept.getCode()); @@ -1270,9 +1277,11 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(0, termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(0, termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(0, termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); }); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); @@ -1289,11 +1298,14 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(codeSystem.getConcept().size(), termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(codeSystem.getConcept().size(), termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(codeSystem.getConcept().size(), termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); - TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); +// TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); + TermValueSetConcept concept = termValueSet.getConcepts().get(0); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8450-9", concept.getCode()); @@ -1315,7 +1327,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(1); +// concept = termValueSetVersion.getConcepts().get(1); + concept = termValueSet.getConcepts().get(1); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("11378-7", concept.getCode()); @@ -1325,7 +1338,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { // ... - concept = termValueSetVersion.getConcepts().get(22); +// concept = termValueSetVersion.getConcepts().get(22); + concept = termValueSet.getConcepts().get(22); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8491-3", concept.getCode()); @@ -1340,7 +1354,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(23); +// concept = termValueSetVersion.getConcepts().get(23); + concept = termValueSet.getConcepts().get(23); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8492-1", concept.getCode()); @@ -1374,9 +1389,11 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(0, termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(0, termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(0, termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); }); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); @@ -1393,11 +1410,14 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(codeSystem.getConcept().size() - 2, termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(codeSystem.getConcept().size() - 2, termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(codeSystem.getConcept().size() - 2, termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); - TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); +// TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); + TermValueSetConcept concept = termValueSet.getConcepts().get(0); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8450-9", concept.getCode()); @@ -1419,7 +1439,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(1); +// concept = termValueSetVersion.getConcepts().get(1); + concept = termValueSet.getConcepts().get(1); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("11378-7", concept.getCode()); @@ -1429,7 +1450,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { // ... - concept = termValueSetVersion.getConcepts().get(20); +// concept = termValueSetVersion.getConcepts().get(20); + concept = termValueSet.getConcepts().get(20); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8491-3", concept.getCode()); @@ -1444,7 +1466,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(21); +// concept = termValueSetVersion.getConcepts().get(21); + concept = termValueSet.getConcepts().get(21); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8492-1", concept.getCode()); @@ -1478,9 +1501,11 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(0, termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(0, termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(0, termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); }); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); @@ -1497,11 +1522,14 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { ourLog.info("ValueSet:\n" + termValueSet.toString()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); - TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); - assertEquals(codeSystem.getConcept().size() - 2, termValueSetVersion.getConcepts().size()); - assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); +// TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId()); +// assertEquals(codeSystem.getConcept().size() - 2, termValueSetVersion.getConcepts().size()); +// assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus()); + assertEquals(codeSystem.getConcept().size() - 2, termValueSet.getConcepts().size()); + assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); - TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); +// TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0); + TermValueSetConcept concept = termValueSet.getConcepts().get(0); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8450-9", concept.getCode()); @@ -1523,7 +1551,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(1); +// concept = termValueSetVersion.getConcepts().get(1); + concept = termValueSet.getConcepts().get(1); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("11378-7", concept.getCode()); @@ -1533,7 +1562,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { // ... - concept = termValueSetVersion.getConcepts().get(20); +// concept = termValueSetVersion.getConcepts().get(20); + concept = termValueSet.getConcepts().get(20); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8491-3", concept.getCode()); @@ -1548,7 +1578,8 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); - concept = termValueSetVersion.getConcepts().get(21); +// concept = termValueSetVersion.getConcepts().get(21); + concept = termValueSet.getConcepts().get(21); ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8492-1", concept.getCode());