Revised approach for versioning of ValueSet.

This commit is contained in:
ianmarshall 2020-09-15 10:21:42 -04:00
parent d00db11586
commit cd104ad635
31 changed files with 388 additions and 638 deletions

View File

@ -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<TermValueSet, Long> {
@Query("SELECT vs FROM TermValueSet vs WHERE vs.myResourcePid = :resource_pid")
Optional<TermValueSet> findByResourcePid(@Param("resource_pid") Long theResourcePid);
@Query("SELECT vs FROM TermValueSet vs WHERE vs.myUrl = :url")
Optional<TermValueSet> findByUrl(@Param("url") String theUrl);
@Query("SELECT vs FROM TermValueSet vs WHERE vs.myCurrentVersion.myId = :vsv_pid")
Optional<TermValueSet> findWithCodeSystemVersionAsCurrentVersion(@Param("vsv_pid") Long theValueSetVersionPid);
@Query("SELECT vs FROM TermValueSet vs WHERE vs.myExpansionStatus = :expansion_status")
Slice<TermValueSet> 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<TermValueSet> findTermValueSetByUrl(Pageable thePage, @Param("url") String theUrl);
@Query("SELECT vs FROM TermValueSet vs WHERE vs.myUrl = :url AND vs.myVersion IS NULL")
Optional<TermValueSet> findTermValueSetByUrlAndNullVersion(@Param("url") String theUrl);
@Query("SELECT vs FROM TermValueSet vs WHERE vs.myUrl = :url AND vs.myVersion = :version")
Optional<TermValueSet> findTermValueSetByUrlAndVersion(@Param("url") String theUrl, @Param("version") String theVersion);
}

View File

@ -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<TermValueSetVersion, Long> {
@Query("SELECT vsv FROM TermValueSetVersion vsv WHERE vsv.myResourcePid = :resource_pid")
Optional<TermValueSetVersion> 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<TermValueSetVersion> findByExpansionStatus(Pageable pageable, @Param("expansion_status") TermValueSetPreExpansionStatusEnum theExpansionStatus);
@Query("SELECT vsv FROM TermValueSetVersion vsv WHERE vsv.myValueSetPid = :valueset_pid")
List<TermValueSetVersion> findByValueSetPid(@Param("valueset_pid") Long theValueSetPid);
}

View File

@ -65,9 +65,6 @@ import static org.hl7.fhir.convertors.conv30_40.ValueSet30_40.convertValueSet;
public class FhirResourceDaoValueSetDstu3 extends BaseHapiFhirResourceDao<ValueSet> implements IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> {
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<ValueS
try {
ValueSet valueSet = (ValueSet) theResource;
org.hl7.fhir.r4.model.ValueSet converted = convertValueSet(valueSet);
myHapiTerminologySvc.storeTermValueSet(retVal, converted);
myTerminologySvc.storeTermValueSet(retVal, converted);
} catch (FHIRException fe) {
throw new InternalErrorException(fe);
}
} else {
myHapiTerminologySvc.deleteValueSetAndChildren(retVal);
myTerminologySvc.deleteValueSetAndChildren(retVal);
}
}

View File

@ -40,7 +40,6 @@ import ca.uhn.fhir.jpa.entity.TermConceptProperty;
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.jpa.model.entity.ForcedId;
import ca.uhn.fhir.jpa.model.entity.NpmPackageEntity;
import ca.uhn.fhir.jpa.model.entity.NpmPackageVersionEntity;
@ -118,10 +117,10 @@ public class ExpungeEverythingService {
counter.addAndGet(doExpungeEverythingQuery("UPDATE " + TermCodeSystem.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;
});
// 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));

View File

@ -60,9 +60,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
public class FhirResourceDaoValueSetR4 extends BaseHapiFhirResourceDao<ValueSet> implements IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> {
@Autowired
private ITermReadSvc myHapiTerminologySvc;
@Autowired
private DefaultProfileValidationSupport myDefaultProfileValidationSupport;
@ -113,17 +110,14 @@ public class FhirResourceDaoValueSetR4 extends BaseHapiFhirResourceDao<ValueSet>
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>
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<ValueSet>
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);
}
}

View File

@ -64,9 +64,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
public class FhirResourceDaoValueSetR5 extends BaseHapiFhirResourceDao<ValueSet> implements IFhirResourceDaoValueSet<ValueSet, Coding, CodeableConcept> {
@Autowired
private ITermReadSvc myHapiTerminologySvc;
@Autowired
@Qualifier("myDefaultProfileValidationSupport")
private IValidationSupport myDefaultProfileValidationSupport;
@ -267,9 +264,9 @@ public class FhirResourceDaoValueSetR5 extends BaseHapiFhirResourceDao<ValueSet>
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);
}
}

View File

@ -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<TermValueSetConcept> 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<TermValueSetConcept> 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();
}
}

View File

@ -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<TermValueSetConcept> 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<TermValueSetConcept> 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();
}
}

View File

@ -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<TermValueSetVersion> optionalExistingTermValueSetVersionById = myValueSetVersionDao.findByResourcePid(theResourceTable.getId());
Optional<TermValueSet> 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<TermValueSet> 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<TermValueSetConceptView> conceptViews = myTermValueSetConceptViewDao.findByTermValueSetId(theOffset, toIndex, theTermValueSetVersion.getId());
Collection<TermValueSetConceptView> 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<TermValueSetVersion> optionalTermValueSetVersion = getNextTermValueSetNotExpanded();
if (!optionalTermValueSetVersion.isPresent()) {
TermValueSet valueSetToExpand = txTemplate.execute(t -> {
Optional<TermValueSet> 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<TermValueSetVersion> getNextTermValueSetNotExpanded() {
Optional<TermValueSetVersion> retVal = Optional.empty();
Slice<TermValueSetVersion> page = myValueSetVersionDao.findByExpansionStatus(PageRequest.of(0, 1), TermValueSetPreExpansionStatusEnum.NOT_EXPANDED);
private Optional<TermValueSet> getNextTermValueSetNotExpanded() {
Optional<TermValueSet> retVal = Optional.empty();
Slice<TermValueSet> 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<TermValueSet> 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<TermValueSet> 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<TermValueSetVersion> 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);
}
}

View File

@ -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);
}
}

View File

@ -227,6 +227,7 @@ public class TermDeferredStorageSvcImpl implements ITermDeferredStorageSvc {
myDeferredConceptMaps.clear();
myDeferredConcepts.clear();
myDefferedCodeSystemsDeletions.clear();
myConceptLinksToSaveLater.clear();
}
@Transactional(propagation = Propagation.NEVER)

View File

@ -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<TermValueSetConcept> optionalConcept = myValueSetConceptDao.findByTermValueSetIdSystemAndCode(myTermValueSetVersion.getId(), theSystem, theCode);
Optional<TermValueSetConcept> 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<Long> conceptIds = myValueSetConceptDao.findIdsByTermValueSetId(myTermValueSetVersion.getId());
List<Long> 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;
}

View File

@ -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() {

View File

@ -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();

View File

@ -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

View File

@ -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;

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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;

View File

@ -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<ValueSet, Coding, CodeableConcept> myValueSetDao;
@Autowired
protected ITermValueSetDao myTermValueSetDao;
@Autowired
protected ITermValueSetVersionDao myTermValueSetVersionDao;
// @Autowired
// protected ITermValueSetVersionDao myTermValueSetVersionDao;
@Autowired
protected ITermValueSetConceptDao myTermValueSetConceptDao;
@Autowired

View File

@ -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();

View File

@ -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);

View File

@ -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");

View File

@ -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());

View File

@ -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

View File

@ -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<CodeSystem> 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();

View File

@ -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();

View File

@ -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

View File

@ -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

View File

@ -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());