Initial changes to support multi-version ValueSets

This commit is contained in:
ianmarshall 2020-09-03 22:36:15 -04:00
parent 94440c849f
commit 5f005120c9
27 changed files with 568 additions and 182 deletions

View File

@ -142,10 +142,12 @@ ca.uhn.fhir.jpa.binstore.BinaryAccessProvider.unknownType=Content in resource of
ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateCodeSystemUrl=Can not create multiple CodeSystem resources with CodeSystem.url "{0}", already have one with resource ID: {1} ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateCodeSystemUrl=Can not create multiple CodeSystem resources with CodeSystem.url "{0}", already have one with resource ID: {1}
ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateCodeSystemUrlAndVersion=Can not create multiple CodeSystem resources with CodeSystem.url "{0}" and CodeSystem.version "{1}", already have one with resource ID: {2} ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateCodeSystemUrlAndVersion=Can not create multiple CodeSystem resources with CodeSystem.url "{0}" and CodeSystem.version "{1}", already have one with resource ID: {2}
ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotUpdateVersionForExistingCodeSystemVersion=Updated CodeSystem has wrong version id. Existing CodeSystem resource has CodeSystem.url "{0}" and CodeSystem.version "{1}", already have one with resource ID: {2} ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotUpdateUrlOrVersionForCodeSystemResource=Cannot update URL or version for CodeSystem resource. Existing CodeSystem resource with resource ID {0} found with CodeSystem.url "{1}" and CodeSystem.version "{2}"
ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateConceptMapUrl=Can not create multiple ConceptMap resources with ConceptMap.url "{0}", already have one with resource ID: {1} ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateConceptMapUrl=Can not create multiple ConceptMap resources with ConceptMap.url "{0}", already have one with resource ID: {1}
ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateValueSetUrl=Can not create multiple ValueSet resources with ValueSet.url "{0}", already have one with resource ID: {1} ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateValueSetUrl=Can not create multiple ValueSet resources with ValueSet.url "{0}", already have one with resource ID: {1}
ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.expansionTooLarge=Expansion of ValueSet produced too many codes (maximum {0}) - Operation aborted! ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.expansionTooLarge=Expansion of ValueSet produced too many codes (maximum {0}) - Operation aborted!
ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotCreateDuplicateValueSetUrlAndVersion=Can not create multiple CodeSystem resources with CodeSystem.url "{0}" and CodeSystem.version "{1}", already have one with resource ID: {2}
ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl.cannotUpdateUrlOrVersionForValueSetResource=Cannot update URL or version for ValueSet resource. Existing ValueSet resource with resource ID {0} found with ValueSet.url "{1}" and ValueSet.version "{2}"
ca.uhn.fhir.jpa.patch.JsonPatchUtils.failedToApplyPatch=Failed to apply JSON patch to {0}: {1} ca.uhn.fhir.jpa.patch.JsonPatchUtils.failedToApplyPatch=Failed to apply JSON patch to {0}: {1}

View File

@ -1,28 +0,0 @@
package ca.uhn.fhir.jpa.dao;
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemDao;
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemVersionDao;
import ca.uhn.fhir.jpa.entity.TermCodeSystem;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
public class HapiFhirResourceDaoCodeSystemUtil {
static public void deleteCodeSystemEntities(ITermCodeSystemDao theCsDao, ITermCodeSystemVersionDao theCsvDao,
ITermDeferredStorageSvc theTermDeferredStorageSvc, String theCodeSystemUrl,
String theCodeSystemVersion) {
if (isNotBlank(theCodeSystemUrl)) {
TermCodeSystem persCs = theCsDao.findByCodeSystemUri(theCodeSystemUrl);
if (persCs != null) {
if (theCodeSystemVersion != null) {
TermCodeSystemVersion persCsVersion = theCsvDao.findByCodeSystemPidAndVersion(persCs.getPid(), theCodeSystemVersion);
theTermDeferredStorageSvc.deleteCodeSystemVersion(persCsVersion);
} else {
theTermDeferredStorageSvc.deleteCodeSystem(persCs);
}
}
}
}
}

View File

@ -20,6 +20,7 @@ package ca.uhn.fhir.jpa.dao.data;
* #L% * #L%
*/ */
import ca.uhn.fhir.jpa.entity.TermCodeSystem;
import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSet;
import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -38,7 +39,8 @@ public interface ITermValueSetDao extends JpaRepository<TermValueSet, Long> {
@Query("SELECT vs FROM TermValueSet vs WHERE vs.myUrl = :url") @Query("SELECT vs FROM TermValueSet vs WHERE vs.myUrl = :url")
Optional<TermValueSet> findByUrl(@Param("url") String theUrl); Optional<TermValueSet> findByUrl(@Param("url") String theUrl);
@Query("SELECT vs FROM TermValueSet vs WHERE vs.myExpansionStatus = :expansion_status") @Query("SELECT vs FROM TermValueSet vs WHERE vs.myCurrentVersion.myId = :vsv_pid")
Slice<TermValueSet> findByExpansionStatus(Pageable pageable, @Param("expansion_status") TermValueSetPreExpansionStatusEnum theExpansionStatus); Optional<TermValueSet> findWithCodeSystemVersionAsCurrentVersion(@Param("vsv_pid") Long theValueSetVersionPid);
} }

View File

@ -0,0 +1,52 @@
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

@ -25,10 +25,6 @@ import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.context.support.ValidationSupportContext;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem;
import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
import ca.uhn.fhir.jpa.dao.HapiFhirResourceDaoCodeSystemUtil;
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemDao;
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemVersionDao;
import ca.uhn.fhir.jpa.entity.TermCodeSystem;
import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource; import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource;
import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
@ -67,10 +63,6 @@ public class FhirResourceDaoCodeSystemDstu3 extends BaseHapiFhirResourceDao<Code
@Autowired @Autowired
protected ITermDeferredStorageSvc myTermDeferredStorageSvc; protected ITermDeferredStorageSvc myTermDeferredStorageSvc;
@Autowired @Autowired
private ITermCodeSystemDao myCsDao;
@Autowired
private ITermCodeSystemVersionDao myCsvDao;
@Autowired
private IValidationSupport myValidationSupport; private IValidationSupport myValidationSupport;
@Autowired @Autowired
private FhirContext myFhirContext; private FhirContext myFhirContext;
@ -155,8 +147,7 @@ public class FhirResourceDaoCodeSystemDstu3 extends BaseHapiFhirResourceDao<Code
protected void preDelete(CodeSystem theResourceToDelete, ResourceTable theEntityToDelete) { protected void preDelete(CodeSystem theResourceToDelete, ResourceTable theEntityToDelete) {
super.preDelete(theResourceToDelete, theEntityToDelete); super.preDelete(theResourceToDelete, theEntityToDelete);
HapiFhirResourceDaoCodeSystemUtil.deleteCodeSystemEntities(myCsDao, myCsvDao, myTermDeferredStorageSvc, theResourceToDelete.getUrl(), myTermDeferredStorageSvc.deleteCodeSystemForResource(theEntityToDelete);
theResourceToDelete.getVersion());
} }

View File

@ -40,6 +40,7 @@ import ca.uhn.fhir.jpa.entity.TermConceptProperty;
import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSet;
import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetConcept;
import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation; 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.ForcedId;
import ca.uhn.fhir.jpa.model.entity.NpmPackageEntity; import ca.uhn.fhir.jpa.model.entity.NpmPackageEntity;
import ca.uhn.fhir.jpa.model.entity.NpmPackageVersionEntity; import ca.uhn.fhir.jpa.model.entity.NpmPackageVersionEntity;
@ -117,6 +118,10 @@ public class ExpungeEverythingService {
counter.addAndGet(doExpungeEverythingQuery("UPDATE " + TermCodeSystem.class.getSimpleName() + " d SET d.myCurrentVersion = null")); counter.addAndGet(doExpungeEverythingQuery("UPDATE " + TermCodeSystem.class.getSimpleName() + " d SET d.myCurrentVersion = null"));
return 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(NpmPackageVersionResourceEntity.class));
counter.addAndGet(expungeEverythingByType(NpmPackageVersionEntity.class)); counter.addAndGet(expungeEverythingByType(NpmPackageVersionEntity.class));
counter.addAndGet(expungeEverythingByType(NpmPackageEntity.class)); counter.addAndGet(expungeEverythingByType(NpmPackageEntity.class));
@ -135,6 +140,7 @@ public class ExpungeEverythingService {
counter.addAndGet(expungeEverythingByType(SearchInclude.class)); counter.addAndGet(expungeEverythingByType(SearchInclude.class));
counter.addAndGet(expungeEverythingByType(TermValueSetConceptDesignation.class)); counter.addAndGet(expungeEverythingByType(TermValueSetConceptDesignation.class));
counter.addAndGet(expungeEverythingByType(TermValueSetConcept.class)); counter.addAndGet(expungeEverythingByType(TermValueSetConcept.class));
counter.addAndGet(expungeEverythingByType(TermValueSetVersion.class));
counter.addAndGet(expungeEverythingByType(TermValueSet.class)); counter.addAndGet(expungeEverythingByType(TermValueSet.class));
counter.addAndGet(expungeEverythingByType(TermConceptParentChildLink.class)); counter.addAndGet(expungeEverythingByType(TermConceptParentChildLink.class));
counter.addAndGet(expungeEverythingByType(TermConceptMapGroupElementTarget.class)); counter.addAndGet(expungeEverythingByType(TermConceptMapGroupElementTarget.class));

View File

@ -25,10 +25,6 @@ import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.context.support.ValidationSupportContext;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem;
import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
import ca.uhn.fhir.jpa.dao.HapiFhirResourceDaoCodeSystemUtil;
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemDao;
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemVersionDao;
import ca.uhn.fhir.jpa.entity.TermCodeSystem;
import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource; import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource;
import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
@ -60,10 +56,6 @@ public class FhirResourceDaoCodeSystemR4 extends BaseHapiFhirResourceDao<CodeSys
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoCodeSystemR4.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoCodeSystemR4.class);
@Autowired
private ITermCodeSystemDao myCsDao;
@Autowired
private ITermCodeSystemVersionDao myCsvDao;
@Autowired @Autowired
private IValidationSupport myValidationSupport; private IValidationSupport myValidationSupport;
@Autowired @Autowired
@ -153,8 +145,7 @@ public class FhirResourceDaoCodeSystemR4 extends BaseHapiFhirResourceDao<CodeSys
protected void preDelete(CodeSystem theResourceToDelete, ResourceTable theEntityToDelete) { protected void preDelete(CodeSystem theResourceToDelete, ResourceTable theEntityToDelete) {
super.preDelete(theResourceToDelete, theEntityToDelete); super.preDelete(theResourceToDelete, theEntityToDelete);
HapiFhirResourceDaoCodeSystemUtil.deleteCodeSystemEntities(myCsDao, myCsvDao, myTermDeferredStorageSvc, theResourceToDelete.getUrl(), myTermDeferredStorageSvc.deleteCodeSystemForResource(theEntityToDelete);
theResourceToDelete.getVersion());
} }

View File

@ -25,11 +25,7 @@ import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.context.support.ValidationSupportContext;
import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem;
import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao;
import ca.uhn.fhir.jpa.dao.HapiFhirResourceDaoCodeSystemUtil;
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemDao;
import ca.uhn.fhir.jpa.dao.data.ITermCodeSystemVersionDao;
import ca.uhn.fhir.jpa.dao.index.IdHelperService; import ca.uhn.fhir.jpa.dao.index.IdHelperService;
import ca.uhn.fhir.jpa.entity.TermCodeSystem;
import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource; import ca.uhn.fhir.jpa.model.cross.IBasePersistedResource;
import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
@ -65,10 +61,6 @@ public class FhirResourceDaoCodeSystemR5 extends BaseHapiFhirResourceDao<CodeSys
@Autowired @Autowired
protected IdHelperService myIdHelperService; protected IdHelperService myIdHelperService;
@Autowired @Autowired
private ITermCodeSystemDao myCsDao;
@Autowired
private ITermCodeSystemVersionDao myCsvDao;
@Autowired
private IValidationSupport myValidationSupport; private IValidationSupport myValidationSupport;
@Autowired @Autowired
private FhirContext myFhirContext; private FhirContext myFhirContext;
@ -155,8 +147,7 @@ public class FhirResourceDaoCodeSystemR5 extends BaseHapiFhirResourceDao<CodeSys
protected void preDelete(CodeSystem theResourceToDelete, ResourceTable theEntityToDelete) { protected void preDelete(CodeSystem theResourceToDelete, ResourceTable theEntityToDelete) {
super.preDelete(theResourceToDelete, theEntityToDelete); super.preDelete(theResourceToDelete, theEntityToDelete);
HapiFhirResourceDaoCodeSystemUtil.deleteCodeSystemEntities(myCsDao, myCsvDao, myTermDeferredStorageSvc, theResourceToDelete.getUrl(), myTermDeferredStorageSvc.deleteCodeSystemForResource(theEntityToDelete);
theResourceToDelete.getVersion());
} }

View File

@ -47,6 +47,12 @@ public class TermValueSet implements Serializable {
public static final int MAX_NAME_LENGTH = 200; public static final int MAX_NAME_LENGTH = 200;
public static final int MAX_URL_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;
@Id() @Id()
@SequenceGenerator(name = "SEQ_VALUESET_PID", sequenceName = "SEQ_VALUESET_PID") @SequenceGenerator(name = "SEQ_VALUESET_PID", sequenceName = "SEQ_VALUESET_PID")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_VALUESET_PID") @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_VALUESET_PID")
@ -125,6 +131,15 @@ public class TermValueSet implements Serializable {
return this; return this;
} }
public TermValueSetVersion getCurrentVersion() {
return myCurrentVersion;
}
public TermValueSet setCurrentVersion(TermValueSetVersion theCurrentVersion) {
myCurrentVersion = theCurrentVersion;
return this;
}
public List<TermValueSetConcept> getConcepts() { public List<TermValueSetConcept> getConcepts() {
if (myConcepts == null) { if (myConcepts == null) {
myConcepts = new ArrayList<>(); myConcepts = new ArrayList<>();

View File

@ -0,0 +1,249 @@
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

@ -81,6 +81,7 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import ca.uhn.fhir.util.CoverageIgnore; import ca.uhn.fhir.util.CoverageIgnore;
import ca.uhn.fhir.util.ObjectUtil;
import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.util.StopWatch;
import ca.uhn.fhir.util.UrlUtil; import ca.uhn.fhir.util.UrlUtil;
import ca.uhn.fhir.util.ValidateUtil; import ca.uhn.fhir.util.ValidateUtil;
@ -331,25 +332,47 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
deleteConceptMap(theResourceTable); deleteConceptMap(theResourceTable);
} }
public void deleteValueSet(ResourceTable theResourceTable) { public void deleteValueSetForResource(ResourceTable theResourceTable) {
// Get existing entity so it can be deleted. // Get existing entity so it can be deleted.
Optional<TermValueSet> optionalExistingTermValueSetById = myValueSetDao.findByResourcePid(theResourceTable.getId()); Optional<TermValueSetVersion> optionalExistingTermValueSetVersionById = myValueSetVersionDao.findByResourcePid(theResourceTable.getId());
if (optionalExistingTermValueSetById.isPresent()) { if (optionalExistingTermValueSetVersionById.isPresent()) {
TermValueSet existingTermValueSet = optionalExistingTermValueSetById.get(); TermValueSetVersion existingTermValueSetVersion = optionalExistingTermValueSetVersionById.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());
} }
} }
@Override @Override
@Transactional @Transactional
public void deleteValueSetAndChildren(ResourceTable theResourceTable) { public void deleteValueSetAndChildren(ResourceTable theResourceTable) {
deleteValueSet(theResourceTable); deleteValueSetForResource(theResourceTable);
} }
private ValueSet expandValueSetInMemory(ValueSetExpansionOptions theExpansionOptions, ValueSet theValueSetToExpand, VersionIndependentConcept theWantConceptOrNull) { private ValueSet expandValueSetInMemory(ValueSetExpansionOptions theExpansionOptions, ValueSet theValueSetToExpand, VersionIndependentConcept theWantConceptOrNull) {
@ -1674,17 +1697,18 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
// We have a ValueSet to pre-expand. // We have a ValueSet to pre-expand.
try { try {
ValueSet valueSet = txTemplate.execute(t -> { ValueSet valueSet = txTemplate.execute(t -> {
TermValueSet refreshedValueSetToExpand = myValueSetDao.findById(valueSetToExpand.getId()).get(); TermValueSetVersion refreshedValueSetVersionToExpand = myValueSetVersionDao.findById(valueSetToExpand.getId()).get();
return getValueSetFromResourceTable(refreshedValueSetToExpand.getResource()); return getValueSetFromResourceTable(refreshedValueSetVersionToExpand.getResource());
}); });
ValueSetConceptAccumulator accumulator = new ValueSetConceptAccumulator(valueSetToExpand, myValueSetDao, myValueSetConceptDao, myValueSetConceptDesignationDao); ValueSetConceptAccumulator accumulator = new ValueSetConceptAccumulator(valueSetToExpand, myValueSetVersionDao, myValueSetDao, myValueSetConceptDao, myValueSetConceptDesignationDao);
expandValueSet(null, valueSet, accumulator); expandValueSet(null, valueSet, accumulator);
// We are done with this ValueSet. // We are done with this ValueSet.
txTemplate.execute(t -> { txTemplate.execute(t -> {
valueSetToExpand.setExpansionStatus(TermValueSetPreExpansionStatusEnum.EXPANDED); TermValueSetVersion finalValueSetToExpand = myValueSetVersionDao.findById(valueSetToExpand.getId()).get();
myValueSetDao.saveAndFlush(valueSetToExpand); finalValueSetToExpand.setExpansionStatus(TermValueSetPreExpansionStatusEnum.EXPANDED);
myValueSetVersionDao.saveAndFlush(finalValueSetToExpand);
return null; return null;
}); });
@ -1778,38 +1802,92 @@ public abstract class BaseTermReadSvcImpl implements ITermReadSvc {
ValidateUtil.isTrueOrThrowInvalidRequest(theResourceTable != null, "No resource supplied"); ValidateUtil.isTrueOrThrowInvalidRequest(theResourceTable != null, "No resource supplied");
ValidateUtil.isNotBlankOrThrowUnprocessableEntity(theValueSet.getUrl(), "ValueSet has no value for ValueSet.url"); ValidateUtil.isNotBlankOrThrowUnprocessableEntity(theValueSet.getUrl(), "ValueSet has no value for ValueSet.url");
TermValueSet termValueSet = new TermValueSet(); /*
termValueSet.setResource(theResourceTable); * Get CodeSystem and validate CodeSystemVersion
termValueSet.setUrl(theValueSet.getUrl()); */
termValueSet.setName(theValueSet.hasName() ? theValueSet.getName() : null); TermValueSet termValueSet = getOrCreateDistinctTermValueSet(theResourceTable.getPersistentId(), theValueSet.getUrl(), theValueSet.getName(), theValueSet.getVersion(), theResourceTable);
// We delete old versions; we don't support versioned ValueSets. // Delete version being replaced
deleteValueSet(theResourceTable); deleteValueSetForResource(theResourceTable);
/* /*
* Do the upload. * Do the upload.
*/ */
String url = termValueSet.getUrl(); TermValueSetVersion termValueSetVersion = termValueSet.getCurrentVersion();
Optional<TermValueSet> optionalExistingTermValueSetByUrl = myValueSetDao.findByUrl(url); if (termValueSetVersion == null) {
if (!optionalExistingTermValueSetByUrl.isPresent()) { termValueSetVersion = new TermValueSetVersion();
termValueSet = myValueSetDao.save(termValueSet);
} else {
TermValueSet existingTermValueSet = optionalExistingTermValueSetByUrl.get();
String msg = myContext.getLocalizer().getMessage(
BaseTermReadSvcImpl.class,
"cannotCreateDuplicateValueSetUrl",
url,
existingTermValueSet.getResource().getIdDt().toUnqualifiedVersionless().getValue());
throw new UnprocessableEntityException(msg);
} }
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()); 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();
}
} else {
termValueSet = termValueSetOptional.get();
}
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());
}
} 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());
} 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);
}
}
}
@Override @Override
public IFhirResourceDaoCodeSystem.SubsumesResult subsumes(IPrimitiveType<String> theCodeA, IPrimitiveType<String> theCodeB, public IFhirResourceDaoCodeSystem.SubsumesResult subsumes(IPrimitiveType<String> theCodeA, IPrimitiveType<String> theCodeB,
IPrimitiveType<String> theSystem, IBaseCoding theCodingA, IBaseCoding theCodingB) { IPrimitiveType<String> theSystem, IBaseCoding theCodingA, IBaseCoding theCodingB) {

View File

@ -238,17 +238,6 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc {
ourLog.info(" * Deleting code system version {}", theCodeSystemVersion.getCodeSystemVersionId()); ourLog.info(" * Deleting code system version {}", theCodeSystemVersion.getCodeSystemVersionId());
deleteCodeSystemVersion(theCodeSystemVersion.getPid()); deleteCodeSystemVersion(theCodeSystemVersion.getPid());
// Check if the version deleted is the current version. If so, delete TermCodeSystem as well.
TermCodeSystem termCodeSystem = theCodeSystemVersion.getCodeSystem();
TransactionTemplate txTemplate = new TransactionTemplate(myTransactionManager);
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
txTemplate.executeWithoutResult(t -> {
if (myCodeSystemVersionDao.findByCodeSystemPid(termCodeSystem.getPid()).size() == 0) {
ourLog.info(" * Deleting code system {}", termCodeSystem.getPid());
deleteCodeSystem(termCodeSystem);
}
});
} }
/** /**
@ -709,27 +698,29 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc {
} }
private void checkForCodeSystemVersionDuplicate(TermCodeSystem theCodeSystem, String theSystemUri, String theSystemVersionId, ResourceTable theCodeSystemResourceTable) { private void checkForCodeSystemVersionDuplicate(TermCodeSystem theCodeSystem, String theSystemUri, String theSystemVersionId, ResourceTable theCodeSystemResourceTable) {
// Check if CodeSystemVersion entity already exists.
TermCodeSystemVersion codeSystemVersionEntity; TermCodeSystemVersion codeSystemVersionEntity;
String msg = null; String msg = null;
if (theSystemVersionId == null) { if (theSystemVersionId == null) {
// Check if a non-versioned TermCodeSystemVersion entity already exists for this TermCodeSystem.
codeSystemVersionEntity = myCodeSystemVersionDao.findByCodeSystemPidVersionIsNull(theCodeSystem.getPid()); codeSystemVersionEntity = myCodeSystemVersionDao.findByCodeSystemPidVersionIsNull(theCodeSystem.getPid());
if (codeSystemVersionEntity != null) { if (codeSystemVersionEntity != null) {
msg = myContext.getLocalizer().getMessage(BaseTermReadSvcImpl.class, "cannotCreateDuplicateCodeSystemUrl", theSystemUri, codeSystemVersionEntity.getResource().getIdDt().toUnqualifiedVersionless().getValue()); msg = myContext.getLocalizer().getMessage(BaseTermReadSvcImpl.class, "cannotCreateDuplicateCodeSystemUrl", theSystemUri, codeSystemVersionEntity.getResource().getIdDt().toUnqualifiedVersionless().getValue());
} }
} else { } else {
// Check if a TermCodeSystemVersion entity already exists for this TermCodeSystem and version.
codeSystemVersionEntity = myCodeSystemVersionDao.findByCodeSystemPidAndVersion(theCodeSystem.getPid(), theSystemVersionId); codeSystemVersionEntity = myCodeSystemVersionDao.findByCodeSystemPidAndVersion(theCodeSystem.getPid(), theSystemVersionId);
if (codeSystemVersionEntity != null) { if (codeSystemVersionEntity != null) {
msg = myContext.getLocalizer().getMessage(BaseTermReadSvcImpl.class, "cannotCreateDuplicateCodeSystemUrlAndVersion", theSystemUri, theSystemVersionId, codeSystemVersionEntity.getResource().getIdDt().toUnqualifiedVersionless().getValue()); msg = myContext.getLocalizer().getMessage(BaseTermReadSvcImpl.class, "cannotCreateDuplicateCodeSystemUrlAndVersion", theSystemUri, theSystemVersionId, codeSystemVersionEntity.getResource().getIdDt().toUnqualifiedVersionless().getValue());
} else { } else {
// Check if a TermCodeSystemVersion entity already exists for this CodeSystem resource (i.e. with a different version or URL)
codeSystemVersionEntity = myCodeSystemVersionDao.findByCodeSystemResourcePid(theCodeSystemResourceTable.getId()); codeSystemVersionEntity = myCodeSystemVersionDao.findByCodeSystemResourcePid(theCodeSystemResourceTable.getId());
if (codeSystemVersionEntity != null) { if (codeSystemVersionEntity != null) {
msg = myContext.getLocalizer().getMessage(BaseTermReadSvcImpl.class, "cannotCreateDuplicateCodeSystemUrlAndVersion", theSystemUri, theSystemVersionId, codeSystemVersionEntity.getResource().getIdDt().toUnqualifiedVersionless().getValue()); msg = myContext.getLocalizer().getMessage(BaseTermReadSvcImpl.class, "cannotUpdateUrlOrVersionForCodeSystemResource", theSystemUri, theSystemVersionId, codeSystemVersionEntity.getResource().getIdDt().toUnqualifiedVersionless().getValue());
throw new UnprocessableEntityException(msg); throw new UnprocessableEntityException(msg);
} }
} }
} }
// Throw exception if the CodeSystemVersion is being duplicated. // Throw exception if the TermCodeSystemVersion is being duplicated.
if (codeSystemVersionEntity != null) { if (codeSystemVersionEntity != null) {
if (!ObjectUtil.equals(codeSystemVersionEntity.getResource().getId(), theCodeSystemResourceTable.getId())) { if (!ObjectUtil.equals(codeSystemVersionEntity.getResource().getId(), theCodeSystemResourceTable.getId())) {
throw new UnprocessableEntityException(msg); throw new UnprocessableEntityException(msg);

View File

@ -29,6 +29,7 @@ import ca.uhn.fhir.jpa.entity.TermCodeSystem;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.jpa.entity.TermConcept;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink; import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.jpa.model.sched.HapiJob;
import ca.uhn.fhir.jpa.model.sched.ISchedulerService; import ca.uhn.fhir.jpa.model.sched.ISchedulerService;
import ca.uhn.fhir.jpa.model.sched.ScheduledJobDefinition; import ca.uhn.fhir.jpa.model.sched.ScheduledJobDefinition;
@ -119,8 +120,15 @@ public class TermDeferredStorageSvcImpl implements ITermDeferredStorageSvc {
@Override @Override
@Transactional @Transactional
public void deleteCodeSystemVersion(TermCodeSystemVersion theCodeSystemVersion) { public void deleteCodeSystemForResource(ResourceTable theCodeSystemToDelete) {
myDefferedCodeSystemVersionsDeletions.add(theCodeSystemVersion); TermCodeSystemVersion codeSystemVersionToDelete = myCodeSystemVersionDao.findByCodeSystemResourcePid(theCodeSystemToDelete.getResourceId());
if (codeSystemVersionToDelete != null) {
myDefferedCodeSystemVersionsDeletions.add(codeSystemVersionToDelete);
}
TermCodeSystem codeSystemToDelete = myCodeSystemDao.findByResourcePid(theCodeSystemToDelete.getResourceId());
if (codeSystemToDelete != null) {
deleteCodeSystem(codeSystemToDelete);
}
} }
@Override @Override

View File

@ -113,6 +113,7 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator {
ValidateUtil.isNotBlankOrThrowInvalidRequest(theSystem, "ValueSet contains a concept with no system value"); ValidateUtil.isNotBlankOrThrowInvalidRequest(theSystem, "ValueSet contains a concept with no system value");
ValidateUtil.isNotBlankOrThrowInvalidRequest(theCode, "ValueSet contains a concept with no code value"); ValidateUtil.isNotBlankOrThrowInvalidRequest(theCode, "ValueSet contains a concept with no code value");
myTermValueSetVersion = myValueSetVersionDao.findById(myTermValueSetVersion.getId()).get();
TermValueSetConcept concept = new TermValueSetConcept(); TermValueSetConcept concept = new TermValueSetConcept();
concept.setValueSet(myTermValueSet); concept.setValueSet(myTermValueSet);
concept.setOrder(myConceptsSaved); concept.setOrder(myConceptsSaved);

View File

@ -24,6 +24,7 @@ import ca.uhn.fhir.jpa.entity.TermCodeSystem;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.jpa.entity.TermConcept;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink; import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import org.hl7.fhir.r4.model.ConceptMap; import org.hl7.fhir.r4.model.ConceptMap;
import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.model.ValueSet;
@ -55,7 +56,7 @@ public interface ITermDeferredStorageSvc {
void deleteCodeSystem(TermCodeSystem theCodeSystem); void deleteCodeSystem(TermCodeSystem theCodeSystem);
void deleteCodeSystemVersion(TermCodeSystemVersion theCodeSystemVersion); void deleteCodeSystemForResource(ResourceTable theCodeSystemResourceToDelete);
/** /**
* This is mostly here for unit tests - Saves any and all deferred concepts and links * This is mostly here for unit tests - Saves any and all deferred concepts and links

View File

@ -29,6 +29,7 @@ import ca.uhn.fhir.jpa.dao.data.ITermConceptDao;
import ca.uhn.fhir.jpa.dao.data.ITermConceptMapDao; import ca.uhn.fhir.jpa.dao.data.ITermConceptMapDao;
import ca.uhn.fhir.jpa.dao.data.ITermConceptMapGroupElementTargetDao; import ca.uhn.fhir.jpa.dao.data.ITermConceptMapGroupElementTargetDao;
import ca.uhn.fhir.jpa.dao.data.ITermValueSetDao; 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.dstu2.FhirResourceDaoDstu2SearchNoFtTest;
import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test;
import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.model.entity.ModelConfig;
@ -343,6 +344,8 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest {
private IBulkDataExportSvc myBulkDataExportSvc; private IBulkDataExportSvc myBulkDataExportSvc;
@Autowired @Autowired
protected ITermValueSetDao myTermValueSetDao; protected ITermValueSetDao myTermValueSetDao;
@Autowired
protected ITermValueSetVersionDao myTermValueSetVersionDao;
@AfterEach() @AfterEach()
public void afterCleanupDao() { public void afterCleanupDao() {

View File

@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.dao.dstu3;
import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.IValidationSupport;
import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSet;
import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum;
import ca.uhn.fhir.jpa.entity.TermValueSetVersion;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.CodeSystem;
import org.hl7.fhir.dstu3.model.CodeType; import org.hl7.fhir.dstu3.model.CodeType;
@ -58,7 +59,9 @@ public class FhirResourceDaoDstu3ValueSetTest extends BaseJpaDstu3Test {
runInTransaction(() -> { 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()); 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());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsEntity.getExpansionStatus()); Long valueSetId = vsEntity.getId();
TermValueSetVersion vsvEntity = myTermValueSetVersionDao.findByValueSetPid(valueSetId).get(0);
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsvEntity.getExpansionStatus());
}); });
IValidationSupport.CodeValidationResult validationOutcome; IValidationSupport.CodeValidationResult validationOutcome;
@ -80,7 +83,8 @@ public class FhirResourceDaoDstu3ValueSetTest extends BaseJpaDstu3Test {
runInTransaction(() -> { 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()); 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());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, vsEntity.getExpansionStatus()); TermValueSetVersion vsvEntity = myTermValueSetVersionDao.findByValueSetPid(vsEntity.getId()).get(0);
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, vsvEntity.getExpansionStatus());
}); });
// Validate good // Validate good

View File

@ -47,6 +47,7 @@ import ca.uhn.fhir.jpa.dao.data.ITermConceptParentChildLinkDao;
import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDao;
import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDesignationDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDesignationDao;
import ca.uhn.fhir.jpa.dao.data.ITermValueSetDao; 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.dstu2.FhirResourceDaoDstu2SearchNoFtTest;
import ca.uhn.fhir.jpa.dao.index.IdHelperService; import ca.uhn.fhir.jpa.dao.index.IdHelperService;
import ca.uhn.fhir.jpa.entity.TermCodeSystem; import ca.uhn.fhir.jpa.entity.TermCodeSystem;
@ -438,6 +439,8 @@ public abstract class BaseJpaR4Test extends BaseJpaTest implements ITestDataBuil
@Autowired @Autowired
protected ITermValueSetDao myTermValueSetDao; protected ITermValueSetDao myTermValueSetDao;
@Autowired @Autowired
protected ITermValueSetVersionDao myTermValueSetVersionDao;
@Autowired
protected ITermValueSetConceptDao myTermValueSetConceptDao; protected ITermValueSetConceptDao myTermValueSetConceptDao;
@Autowired @Autowired
protected ITermValueSetConceptDesignationDao myTermValueSetConceptDesignationDao; protected ITermValueSetConceptDesignationDao myTermValueSetConceptDesignationDao;

View File

@ -136,10 +136,10 @@ public class FhirResourceDaoR4CodeSystemTest extends BaseJpaR4Test {
// Attempt to delete second version // Attempt to delete second version
myCodeSystemDao.delete(id_second, mySrd); myCodeSystemDao.delete(id_second, mySrd);
// Only the resource will be deleted initially // Only the resource will be deleted initially, but the URL for the TermCodeSystem will be cleared and not searchable.
runInTransaction(() -> { runInTransaction(() -> {
assertEquals(1, myTermCodeSystemDao.count()); assertEquals(1, myTermCodeSystemDao.count());
assertNotNull(myTermCodeSystemDao.findByCodeSystemUri("http://foo")); assertNull(myTermCodeSystemDao.findByCodeSystemUri("http://foo"));
assertEquals(1, myTermCodeSystemVersionDao.count()); assertEquals(1, myTermCodeSystemVersionDao.count());
assertEquals(222, myTermConceptDao.count()); assertEquals(222, myTermConceptDao.count());
List<ResourceTable> resourceList = myResourceTableDao.findAll(); List<ResourceTable> resourceList = myResourceTableDao.findAll();

View File

@ -7,6 +7,7 @@ import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSet;
import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; 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.entity.ResourceTable;
import ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl; import ca.uhn.fhir.jpa.term.BaseTermReadSvcImpl;
import ca.uhn.fhir.jpa.term.TerminologyLoaderSvcLoincTest; import ca.uhn.fhir.jpa.term.TerminologyLoaderSvcLoincTest;
@ -212,7 +213,8 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test {
runInTransaction(() -> { runInTransaction(() -> {
TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException()); TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vs.getExpansionStatus()); TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsv.getExpansionStatus());
}); });
OperationOutcome outcome; OperationOutcome outcome;
@ -241,14 +243,16 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test {
// Before, the VS wasn't pre-expanded. Try again with it pre-expanded // Before, the VS wasn't pre-expanded. Try again with it pre-expanded
runInTransaction(() -> { runInTransaction(() -> {
TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException()); TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vs.getExpansionStatus()); TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsv.getExpansionStatus());
}); });
myTermReadSvc.preExpandDeferredValueSetsToTerminologyTables(); myTermReadSvc.preExpandDeferredValueSetsToTerminologyTables();
runInTransaction(() -> { runInTransaction(() -> {
TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException()); TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, vs.getExpansionStatus()); TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, vsv.getExpansionStatus());
}); });
// Use a code that's in the ValueSet // Use a code that's in the ValueSet
@ -282,7 +286,8 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test {
runInTransaction(() -> { runInTransaction(() -> {
TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException()); TermValueSet vs = myTermValueSetDao.findByUrl("https://bb/ValueSet/BBDemographicAgeUnit").orElseThrow(() -> new IllegalArgumentException());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vs.getExpansionStatus()); TermValueSetVersion vsv = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(vs.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, vsv.getExpansionStatus());
}); });
OperationOutcome outcome; OperationOutcome outcome;

View File

@ -44,6 +44,7 @@ import ca.uhn.fhir.jpa.dao.data.ITermConceptParentChildLinkDao;
import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDao;
import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDesignationDao; import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDesignationDao;
import ca.uhn.fhir.jpa.dao.data.ITermValueSetDao; 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.dstu2.FhirResourceDaoDstu2SearchNoFtTest;
import ca.uhn.fhir.jpa.interceptor.PerformanceTracingLoggingInterceptor; import ca.uhn.fhir.jpa.interceptor.PerformanceTracingLoggingInterceptor;
import ca.uhn.fhir.jpa.model.entity.ModelConfig; import ca.uhn.fhir.jpa.model.entity.ModelConfig;
@ -385,6 +386,8 @@ public abstract class BaseJpaR5Test extends BaseJpaTest {
@Autowired @Autowired
protected ITermValueSetDao myTermValueSetDao; protected ITermValueSetDao myTermValueSetDao;
@Autowired @Autowired
protected ITermValueSetVersionDao myTermValueSetVersionDao;
@Autowired
protected ITermValueSetConceptDao myTermValueSetConceptDao; protected ITermValueSetConceptDao myTermValueSetConceptDao;
@Autowired @Autowired
protected ITermValueSetConceptDesignationDao myTermValueSetConceptDesignationDao; protected ITermValueSetConceptDesignationDao myTermValueSetConceptDesignationDao;

View File

@ -823,7 +823,7 @@ public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3
codeSystem.setUrl(URL_MY_CODE_SYSTEM); codeSystem.setUrl(URL_MY_CODE_SYSTEM);
codeSystem.setContent(CodeSystemContentMode.NOTPRESENT); codeSystem.setContent(CodeSystemContentMode.NOTPRESENT);
codeSystem.setName("ACME Codes"); codeSystem.setName("ACME Codes");
codeSystem.setVersion("1.2.3.4"); codeSystem.setVersion("SYSTEM VERSION");
IIdType id = theCodeSystemDao.create(codeSystem, theRequestDetails).getId().toUnqualified(); IIdType id = theCodeSystemDao.create(codeSystem, theRequestDetails).getId().toUnqualified();
ResourceTable table = theResourceTableDao.findById(id.getIdPartAsLong()).orElseThrow(IllegalStateException::new); ResourceTable table = theResourceTableDao.findById(id.getIdPartAsLong()).orElseThrow(IllegalStateException::new);

View File

@ -10,6 +10,7 @@ import ca.uhn.fhir.jpa.entity.TermValueSet;
import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetConcept;
import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation; import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation;
import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; 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.entity.ResourceTable;
import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
@ -808,8 +809,9 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals(theValueSetName, termValueSet.getName()); assertEquals(theValueSetName, termValueSet.getName());
assertEquals(0, termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); assertEquals(0, termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus());
}); });
} }
@ -826,10 +828,11 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals(theValueSetName, termValueSet.getName()); assertEquals(theValueSetName, termValueSet.getName());
assertEquals(theCodeSystem.getConcept().size(), termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); assertEquals(theCodeSystem.getConcept().size(), termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus());
TermValueSetConcept concept = termValueSet.getConcepts().get(0); TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8450-9", concept.getCode()); assertEquals("8450-9", concept.getCode());
@ -851,7 +854,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue());
concept = termValueSet.getConcepts().get(1); concept = termValueSetVersion.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("11378-7", concept.getCode()); assertEquals("11378-7", concept.getCode());
@ -861,7 +864,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
// ... // ...
concept = termValueSet.getConcepts().get(22); concept = termValueSetVersion.getConcepts().get(22);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8491-3", concept.getCode()); assertEquals("8491-3", concept.getCode());
@ -876,7 +879,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue());
concept = termValueSet.getConcepts().get(23); concept = termValueSetVersion.getConcepts().get(23);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8492-1", concept.getCode()); assertEquals("8492-1", concept.getCode());

View File

@ -10,6 +10,7 @@ import ca.uhn.fhir.jpa.entity.TermValueSet;
import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetConcept;
import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation; import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation;
import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; 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.entity.ResourceTable;
import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermReadSvc; import ca.uhn.fhir.jpa.term.api.ITermReadSvc;
@ -1119,8 +1120,9 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals(theValueSetName, termValueSet.getName()); assertEquals(theValueSetName, termValueSet.getName());
assertEquals(0, termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); assertEquals(0, termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus());
}); });
} }
@ -1137,10 +1139,11 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals(theValueSetName, termValueSet.getName()); assertEquals(theValueSetName, termValueSet.getName());
assertEquals(theCodeSystem.getConcept().size(), termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); assertEquals(theCodeSystem.getConcept().size(), termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus());
TermValueSetConcept concept = termValueSet.getConcepts().get(0); TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8450-9", concept.getCode()); assertEquals("8450-9", concept.getCode());
@ -1162,7 +1165,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue());
concept = termValueSet.getConcepts().get(1); concept = termValueSetVersion.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("11378-7", concept.getCode()); assertEquals("11378-7", concept.getCode());
@ -1172,7 +1175,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test {
// ... // ...
concept = termValueSet.getConcepts().get(22); concept = termValueSetVersion.getConcepts().get(22);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8491-3", concept.getCode()); assertEquals("8491-3", concept.getCode());
@ -1187,7 +1190,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue());
concept = termValueSet.getConcepts().get(23); concept = termValueSetVersion.getConcepts().get(23);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8492-1", concept.getCode()); assertEquals("8492-1", concept.getCode());

View File

@ -12,6 +12,7 @@ import ca.uhn.fhir.jpa.entity.TermConceptMapGroup;
import ca.uhn.fhir.jpa.entity.TermConceptMapGroupElement; import ca.uhn.fhir.jpa.entity.TermConceptMapGroupElement;
import ca.uhn.fhir.jpa.entity.TermConceptMapGroupElementTarget; import ca.uhn.fhir.jpa.entity.TermConceptMapGroupElementTarget;
import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSet;
import ca.uhn.fhir.jpa.entity.TermValueSetVersion;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.CanonicalType; import org.hl7.fhir.r4.model.CanonicalType;
@ -194,9 +195,10 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test {
TermValueSet termValueSet = myTermValueSetDao.findByResourcePid(myExtensionalVsIdOnResourceTable).get(); TermValueSet termValueSet = myTermValueSetDao.findByResourcePid(myExtensionalVsIdOnResourceTable).get();
Long termValueSetId = termValueSet.getId(); Long termValueSetId = termValueSet.getId();
assertEquals(3, myTermValueSetConceptDesignationDao.countByTermValueSetId(termValueSetId).intValue()); assertEquals(3, myTermValueSetConceptDesignationDao.countByTermValueSetId(termValueSetId).intValue());
assertEquals(3, termValueSet.getTotalConceptDesignations().intValue()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(3, termValueSetVersion.getTotalConceptDesignations().intValue());
assertEquals(24, myTermValueSetConceptDao.countByTermValueSetId(termValueSetId).intValue()); assertEquals(24, myTermValueSetConceptDao.countByTermValueSetId(termValueSetId).intValue());
assertEquals(24, termValueSet.getTotalConcepts().intValue()); assertEquals(24, termValueSetVersion.getTotalConcepts().intValue());
new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() { new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() {
@Override @Override
@ -231,9 +233,10 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test {
TermValueSet termValueSet = myTermValueSetDao.findByResourcePid(myExtensionalVsIdOnResourceTable).get(); TermValueSet termValueSet = myTermValueSetDao.findByResourcePid(myExtensionalVsIdOnResourceTable).get();
Long termValueSetId = termValueSet.getId(); Long termValueSetId = termValueSet.getId();
assertEquals(3, myTermValueSetConceptDesignationDao.countByTermValueSetId(termValueSetId).intValue()); assertEquals(3, myTermValueSetConceptDesignationDao.countByTermValueSetId(termValueSetId).intValue());
assertEquals(3, termValueSet.getTotalConceptDesignations().intValue()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(3, termValueSetVersion.getTotalConceptDesignations().intValue());
assertEquals(24, myTermValueSetConceptDao.countByTermValueSetId(termValueSetId).intValue()); assertEquals(24, myTermValueSetConceptDao.countByTermValueSetId(termValueSetId).intValue());
assertEquals(24, termValueSet.getTotalConcepts().intValue()); assertEquals(24, termValueSetVersion.getTotalConcepts().intValue());
new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() { new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() {
@Override @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.ITermValueSetConceptDao;
import ca.uhn.fhir.jpa.dao.data.ITermValueSetConceptDesignationDao; 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.TermValueSet;
import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetConcept;
import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation; 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.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -25,9 +25,9 @@ import static org.mockito.Mockito.when;
public class ValueSetConceptAccumulatorTest { public class ValueSetConceptAccumulatorTest {
private ValueSetConceptAccumulator myAccumulator; private ValueSetConceptAccumulator myAccumulator;
private TermValueSet myValueSet; private TermValueSetVersion myValueSetVersion;
@Mock @Mock
private ITermValueSetDao myValueSetDao; private ITermValueSetVersionDao myValueSetVersionDao;
@Mock @Mock
private ITermValueSetConceptDesignationDao myValueSetDesignationDao; private ITermValueSetConceptDesignationDao myValueSetDesignationDao;
@Mock @Mock
@ -35,8 +35,8 @@ public class ValueSetConceptAccumulatorTest {
@BeforeEach @BeforeEach
public void before() { public void before() {
myValueSet = new TermValueSet(); myValueSetVersion = new TermValueSetVersion();
myAccumulator = new ValueSetConceptAccumulator(myValueSet, myValueSetDao, myValueSetConceptDao, myValueSetDesignationDao); myAccumulator = new ValueSetConceptAccumulator(myValueSetVersion, myValueSetVersionDao, null, myValueSetConceptDao, myValueSetDesignationDao);
} }
@Test @Test

View File

@ -9,6 +9,7 @@ import ca.uhn.fhir.jpa.entity.TermValueSet;
import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetConcept;
import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation; import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation;
import ca.uhn.fhir.jpa.entity.TermValueSetPreExpansionStatusEnum; 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.entity.ResourceTable;
import ca.uhn.fhir.jpa.term.custom.CustomTerminologySet; import ca.uhn.fhir.jpa.term.custom.CustomTerminologySet;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@ -1165,8 +1166,9 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName());
assertEquals(0, termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); assertEquals(0, termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus());
}); });
myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
@ -1183,10 +1185,11 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName());
assertEquals(codeSystem.getConcept().size(), termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); assertEquals(codeSystem.getConcept().size(), termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus());
TermValueSetConcept concept = termValueSet.getConcepts().get(0); TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8450-9", concept.getCode()); assertEquals("8450-9", concept.getCode());
@ -1208,7 +1211,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue());
concept = termValueSet.getConcepts().get(1); concept = termValueSetVersion.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("11378-7", concept.getCode()); assertEquals("11378-7", concept.getCode());
@ -1218,7 +1221,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
// ... // ...
concept = termValueSet.getConcepts().get(22); concept = termValueSetVersion.getConcepts().get(22);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8491-3", concept.getCode()); assertEquals("8491-3", concept.getCode());
@ -1233,7 +1236,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue());
concept = termValueSet.getConcepts().get(23); concept = termValueSetVersion.getConcepts().get(23);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8492-1", concept.getCode()); assertEquals("8492-1", concept.getCode());
@ -1267,8 +1270,9 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName());
assertEquals(0, termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); assertEquals(0, termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus());
}); });
myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
@ -1285,10 +1289,11 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName());
assertEquals(codeSystem.getConcept().size(), termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); assertEquals(codeSystem.getConcept().size(), termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus());
TermValueSetConcept concept = termValueSet.getConcepts().get(0); TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8450-9", concept.getCode()); assertEquals("8450-9", concept.getCode());
@ -1310,7 +1315,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue());
concept = termValueSet.getConcepts().get(1); concept = termValueSetVersion.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("11378-7", concept.getCode()); assertEquals("11378-7", concept.getCode());
@ -1320,7 +1325,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
// ... // ...
concept = termValueSet.getConcepts().get(22); concept = termValueSetVersion.getConcepts().get(22);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8491-3", concept.getCode()); assertEquals("8491-3", concept.getCode());
@ -1335,7 +1340,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue());
concept = termValueSet.getConcepts().get(23); concept = termValueSetVersion.getConcepts().get(23);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8492-1", concept.getCode()); assertEquals("8492-1", concept.getCode());
@ -1369,8 +1374,9 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName());
assertEquals(0, termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); assertEquals(0, termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus());
}); });
myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
@ -1387,10 +1393,11 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName());
assertEquals(codeSystem.getConcept().size() - 2, termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); assertEquals(codeSystem.getConcept().size() - 2, termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus());
TermValueSetConcept concept = termValueSet.getConcepts().get(0); TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8450-9", concept.getCode()); assertEquals("8450-9", concept.getCode());
@ -1412,7 +1419,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue());
concept = termValueSet.getConcepts().get(1); concept = termValueSetVersion.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("11378-7", concept.getCode()); assertEquals("11378-7", concept.getCode());
@ -1422,7 +1429,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
// ... // ...
concept = termValueSet.getConcepts().get(20); concept = termValueSetVersion.getConcepts().get(20);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8491-3", concept.getCode()); assertEquals("8491-3", concept.getCode());
@ -1437,7 +1444,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue());
concept = termValueSet.getConcepts().get(21); concept = termValueSetVersion.getConcepts().get(21);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8492-1", concept.getCode()); assertEquals("8492-1", concept.getCode());
@ -1471,8 +1478,9 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName());
assertEquals(0, termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSet.getExpansionStatus()); assertEquals(0, termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.NOT_EXPANDED, termValueSetVersion.getExpansionStatus());
}); });
myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); myTermSvc.preExpandDeferredValueSetsToTerminologyTables();
@ -1489,10 +1497,11 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
ourLog.info("ValueSet:\n" + termValueSet.toString()); ourLog.info("ValueSet:\n" + termValueSet.toString());
assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl()); assertEquals("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", termValueSet.getUrl());
assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName()); assertEquals("Terminology Services Connectation #1 Extensional case #2", termValueSet.getName());
assertEquals(codeSystem.getConcept().size() - 2, termValueSet.getConcepts().size()); TermValueSetVersion termValueSetVersion = myTermValueSetVersionDao.findByValueSetPidAndNullVersion(termValueSet.getId());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); assertEquals(codeSystem.getConcept().size() - 2, termValueSetVersion.getConcepts().size());
assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSetVersion.getExpansionStatus());
TermValueSetConcept concept = termValueSet.getConcepts().get(0); TermValueSetConcept concept = termValueSetVersion.getConcepts().get(0);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8450-9", concept.getCode()); assertEquals("8450-9", concept.getCode());
@ -1514,7 +1523,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); assertEquals("Systoliskt blodtryck - utgång", designation.getValue());
concept = termValueSet.getConcepts().get(1); concept = termValueSetVersion.getConcepts().get(1);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("11378-7", concept.getCode()); assertEquals("11378-7", concept.getCode());
@ -1524,7 +1533,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
// ... // ...
concept = termValueSet.getConcepts().get(20); concept = termValueSetVersion.getConcepts().get(20);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8491-3", concept.getCode()); assertEquals("8491-3", concept.getCode());
@ -1539,7 +1548,7 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test {
assertEquals("Synonym", designation.getUseDisplay()); assertEquals("Synonym", designation.getUseDisplay());
assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue());
concept = termValueSet.getConcepts().get(21); concept = termValueSetVersion.getConcepts().get(21);
ourLog.info("Concept:\n" + concept.toString()); ourLog.info("Concept:\n" + concept.toString());
assertEquals("http://acme.org", concept.getSystem()); assertEquals("http://acme.org", concept.getSystem());
assertEquals("8492-1", concept.getCode()); assertEquals("8492-1", concept.getCode());