Cleanup following paired programming with JA.

This commit is contained in:
Diederik Muylwyk 2019-09-06 17:56:56 -04:00
parent 6ec991cd39
commit 4fc0ad6f0a
8 changed files with 107 additions and 124 deletions

View File

@ -149,7 +149,7 @@ public class DaoConfig {
/**
* EXPERIMENTAL - Do not use in production! Do not change default of {@code false}!
*/
private boolean myPreExpandValueSetsExperimental = true; // FIXME: DM 2019-09-03 - Return to false.
private boolean myPreExpandValueSetsExperimental = true; // FIXME: DM 2019-09-03 - Return to false before merging into master.
private boolean myFilterParameterEnabled = false;
private StoreMetaSourceInformationEnum myStoreMetaSourceInformation = StoreMetaSourceInformationEnum.SOURCE_URI_AND_REQUEST_ID;
/**

View File

@ -21,8 +21,6 @@ package ca.uhn.fhir.jpa.dao.data;
*/
import ca.uhn.fhir.jpa.entity.TermValueSetConcept;
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.Modifying;
import org.springframework.data.jpa.repository.Query;
@ -40,13 +38,6 @@ public interface ITermValueSetConceptDao extends JpaRepository<TermValueSetConce
@Modifying
void deleteByTermValueSetId(@Param("pid") Long theValueSetId);
// FIXME: DM 2019-09-05 - Let's try removing the pre-fetch and the code in BaseHapiTerminologySvcImpl that handles designations so we can compare the processing time. 1/2
// @Query("SELECT vsc from TermValueSetConcept vsc WHERE vsc.myValueSetPid = :pid ORDER BY vsc.myOrder")
// Slice<TermValueSetConcept> findByTermValueSetIdAndPreFetchDesignations(Pageable thePage, @Param("pid") Long theValueSetId);
@Query("SELECT vsc from TermValueSetConcept vsc LEFT OUTER JOIN FETCH vsc.myDesignations WHERE vsc.myValueSetPid = :pid ORDER BY vsc.myOrder")
Slice<TermValueSetConcept> findByTermValueSetIdAndPreFetchDesignations(Pageable thePage, @Param("pid") Long theValueSetId);
@Query("SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSetPid = :pid AND vsc.mySystem = :system_url AND vsc.myCode = :codeval")
Optional<TermValueSetConcept> findByTermValueSetIdSystemAndCode(@Param("pid") Long theValueSetId, @Param("system_url") String theSystem, @Param("codeval") String theCode);

View File

@ -1,13 +1,10 @@
package ca.uhn.fhir.jpa.dao.data;
import ca.uhn.fhir.jpa.entity.ResourceSearchView;
import ca.uhn.fhir.jpa.entity.TermValueSetConceptView;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Collection;
import java.util.List;
/*
@ -33,6 +30,6 @@ import java.util.List;
public interface ITermValueSetConceptViewDao extends JpaRepository<TermValueSetConceptView, Long> {
@Query("SELECT v FROM TermValueSetConceptView v WHERE v.myConceptValueSetPid = :pid AND v.myConceptOrder >= :from AND v.myConceptOrder < :to ORDER BY v.myConceptOrder")
List<TermValueSetConceptView> findConceptsByValueSetPid(@Param("from") int theOffset, @Param("to") int theToIndex, @Param("pid") Long thePid);
List<TermValueSetConceptView> findByTermValueSetId(@Param("from") int theFrom, @Param("to") int theTo, @Param("pid") Long theValueSetId);
}

View File

@ -23,7 +23,6 @@ package ca.uhn.fhir.jpa.entity;
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;
@ -67,7 +66,7 @@ public class TermValueSet implements Serializable {
@Column(name = "VSNAME", nullable = true, length = MAX_NAME_LENGTH)
private String myName;
@OneToMany(mappedBy = "myValueSet")
@OneToMany(mappedBy = "myValueSet", fetch = FetchType.LAZY)
private List<TermValueSetConcept> myConcepts;
@Column(name = "TOTAL_CONCEPTS", nullable = false)
@ -82,6 +81,9 @@ public class TermValueSet implements Serializable {
@Column(name = "EXPANSION_STATUS", nullable = false, length = MAX_EXPANSION_STATUS_LENGTH)
private TermValueSetPreExpansionStatusEnum myExpansionStatus;
@Transient
private transient Integer myHashCode;
public TermValueSet() {
super();
myExpansionStatus = TermValueSetPreExpansionStatusEnum.NOT_EXPANDED;
@ -196,7 +198,10 @@ public class TermValueSet implements Serializable {
@Override
public int hashCode() {
return getUrl().hashCode();
if (myHashCode == null) {
myHashCode = getUrl().hashCode();
}
return myHashCode;
}
@Override

View File

@ -194,15 +194,15 @@ public class TermValueSetConcept implements Serializable {
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("myId", myId)
// .append(myValueSet != null ? ("myValueSet - id=" + myValueSet.getId()) : ("myValueSet=(null)"))
.append(myValueSet != null ? ("myValueSet - id=" + myValueSet.getId()) : ("myValueSet=(null)"))
.append("myValueSetPid", myValueSetPid)
.append("myOrder", myOrder)
// .append("myValueSetUrl", this.getValueSetUrl())
// .append("myValueSetName", this.getValueSetName())
.append("myValueSetUrl", this.getValueSetUrl())
.append("myValueSetName", this.getValueSetName())
.append("mySystem", mySystem)
.append("myCode", myCode)
.append("myDisplay", myDisplay)
// .append(myDesignations != null ? ("myDesignations - size=" + myDesignations.size()) : ("myDesignations=(null)"))
.append(myDesignations != null ? ("myDesignations - size=" + myDesignations.size()) : ("myDesignations=(null)"))
.toString();
}
}

View File

@ -213,12 +213,12 @@ public class TermValueSetConceptDesignation implements Serializable {
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("myId", myId)
// .append(myConcept != null ? ("myConcept - id=" + myConcept.getId()) : ("myConcept=(null)"))
.append(myConcept != null ? ("myConcept - id=" + myConcept.getId()) : ("myConcept=(null)"))
.append("myConceptPid", myConceptPid)
// .append(myValueSet != null ? ("myValueSet - id=" + myValueSet.getId()) : ("myValueSet=(null)"))
.append(myValueSet != null ? ("myValueSet - id=" + myValueSet.getId()) : ("myValueSet=(null)"))
.append("myValueSetPid", myValueSetPid)
// .append("myValueSetUrl", this.getValueSetUrl())
// .append("myValueSetName", this.getValueSetName())
.append("myValueSetUrl", this.getValueSetUrl())
.append("myValueSetName", this.getValueSetName())
.append("myLanguage", myLanguage)
.append("myUseSystem", myUseSystem)
.append("myUseCode", myUseCode)

View File

@ -30,25 +30,22 @@ import java.io.Serializable;
@Entity
@Immutable
@Subselect("select " +
" CONCAT(vsc.PID, ' ', cd.PID) as PID," +
" vsc.PID as CONCEPT_PID, " +
" cd.PID as DESIG_PID, " +
" vsc.CODEVAL as CONCEPT_CODE, " +
" vsc.DISPLAY as CONCEPT_DISPLAY, " +
" vsc.VALUESET_ORDER as CONCEPT_ORDER, " +
" vsc.SYSTEM_URL as CONCEPT_SYSTEM_URL, " +
" vsc.VALUESET_PID as CONCEPT_VS_PID, " +
// " cd.VALUESET_CONCEPT_PID as VALUESET2_35_1_, " +
" cd.LANG as DESIG_LANG, " +
" cd.USE_CODE as DESIG_USE_CODE, " +
" cd.USE_DISPLAY as DESIG_USE_DISPLAY, " +
" cd.USE_SYSTEM as DESIG_USE_SYSTEM, " +
" cd.VAL as DESIG_VAL " +
" from TRM_VALUESET_CONCEPT vsc " +
" left outer join TRM_VALUESET_C_DESIGNATION cd on vsc.PID=cd.VALUESET_CONCEPT_PID "
// +
// " order by vsc.VALUESET_ORDER"
@Subselect(
"SELECT CONCAT(vsc.PID, ' ', vscd.PID) AS PID, " +
" vsc.PID AS CONCEPT_PID, " +
" vsc.VALUESET_PID AS CONCEPT_VALUESET_PID, " +
" vsc.VALUESET_ORDER AS CONCEPT_VALUESET_ORDER, " +
" vsc.SYSTEM_URL AS CONCEPT_SYSTEM_URL, " +
" vsc.CODEVAL AS CONCEPT_CODEVAL, " +
" vsc.DISPLAY AS CONCEPT_DISPLAY, " +
" vscd.PID AS DESIGNATION_PID, " +
" vscd.LANG AS DESIGNATION_LANG, " +
" vscd.USE_SYSTEM AS DESIGNATION_USE_SYSTEM, " +
" vscd.USE_CODE AS DESIGNATION_USE_CODE, " +
" vscd.USE_DISPLAY AS DESIGNATION_USE_DISPLAY, " +
" vscd.VAL AS DESIGNATION_VAL " +
"FROM TRM_VALUESET_CONCEPT vsc " +
" LEFT OUTER JOIN TRM_VALUESET_C_DESIGNATION vscd ON vsc.PID = vscd.VALUESET_CONCEPT_PID"
)
public class TermValueSetConceptView implements Serializable {
@ -57,38 +54,50 @@ public class TermValueSetConceptView implements Serializable {
@Id
@Column(name="PID")
private String myPid;
@Column(name = "CONCEPT_PID")
private Long myConceptPid;
@Column(name = "DESIG_PID")
private Long myDesigPid;
@Column(name = "CONCEPT_CODE")
private String myConceptCode;
@Column(name = "CONCEPT_DISPLAY")
private String myConceptDisplay;
@Column(name = "CONCEPT_ORDER")
@Column(name = "CONCEPT_VALUESET_PID")
private Long myConceptValueSetPid;
@Column(name = "CONCEPT_VALUESET_ORDER")
private int myConceptOrder;
@Column(name = "CONCEPT_SYSTEM_URL")
private String myConceptSystemUrl;
@Column(name = "CONCEPT_VS_PID")
private Long myConceptValueSetPid;
@Column(name = "DESIG_LANG")
private String myDesigLang;
@Column(name = "DESIG_USE_CODE")
private String myDesigUseCode;
@Column(name = "DESIG_USE_DISPLAY")
private String myDesigUseDisplay;
@Column(name = "DESIG_USE_SYSTEM")
private String myDesigUseSystem;
@Column(name = "DESIG_VAL")
private String myDesigVal;
@Column(name = "CONCEPT_CODEVAL")
private String myConceptCode;
@Column(name = "CONCEPT_DISPLAY")
private String myConceptDisplay;
@Column(name = "DESIGNATION_PID")
private Long myDesignationPid;
@Column(name = "DESIGNATION_LANG")
private String myDesignationLang;
@Column(name = "DESIGNATION_USE_SYSTEM")
private String myDesignationUseSystem;
@Column(name = "DESIGNATION_USE_CODE")
private String myDesignationUseCode;
@Column(name = "DESIGNATION_USE_DISPLAY")
private String myDesignationUseDisplay;
@Column(name = "DESIGNATION_VAL")
private String myDesignationVal;
public Long getConceptPid() {
return myConceptPid;
}
public Long getDesigPid() {
return myDesigPid;
public String getConceptSystemUrl() {
return myConceptSystemUrl;
}
public String getConceptCode() {
@ -99,35 +108,27 @@ public class TermValueSetConceptView implements Serializable {
return myConceptDisplay;
}
public int getConceptOrder() {
return myConceptOrder;
public Long getDesignationPid() {
return myDesignationPid;
}
public String getConceptSystemUrl() {
return myConceptSystemUrl;
public String getDesignationLang() {
return myDesignationLang;
}
public Long getConceptValueSetPid() {
return myConceptValueSetPid;
public String getDesignationUseSystem() {
return myDesignationUseSystem;
}
public String getDesigLang() {
return myDesigLang;
public String getDesignationUseCode() {
return myDesignationUseCode;
}
public String getDesigUseCode() {
return myDesigUseCode;
public String getDesignationUseDisplay() {
return myDesignationUseDisplay;
}
public String getDesigUseDisplay() {
return myDesigUseDisplay;
}
public String getDesigUseSystem() {
return myDesigUseSystem;
}
public String getDesigVal() {
return myDesigVal;
public String getDesignationVal() {
return myDesignationVal;
}
}

View File

@ -28,7 +28,6 @@ import ca.uhn.fhir.jpa.dao.data.*;
import ca.uhn.fhir.jpa.entity.*;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink.RelationshipTypeEnum;
import ca.uhn.fhir.jpa.model.entity.ResourceTable;
import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl;
import ca.uhn.fhir.jpa.util.ScrollableResultsIterator;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@ -68,7 +67,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.scheduling.annotation.Scheduled;
@ -530,75 +528,64 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
private void expandConcepts(ValueSet.ValueSetExpansionComponent theExpansionComponent, TermValueSet theTermValueSet, int theOffset, int theCount) {
int conceptsExpanded = 0;
int designationsExpanded = 0;
int toIndex = theOffset + theCount;
Collection<TermValueSetConceptView> conceptViews = myTermValueSetConceptViewDao.findByTermValueSetId(theOffset, toIndex, theTermValueSet.getId());
// Slice<TermValueSetConcept> slice = myValueSetConceptDao.findByTermValueSetIdAndPreFetchDesignations(SearchCoordinatorSvcImpl.toPage(theOffset, toIndex), theTermValueSet.getId());
Pageable page = SearchCoordinatorSvcImpl.toPage(theOffset, toIndex);
Collection<TermValueSetConceptView> slice = myTermValueSetConceptViewDao.findConceptsByValueSetPid(theOffset, toIndex, theTermValueSet.getId());
if (slice.isEmpty()) {
logConceptsExpanded(theTermValueSet, conceptsExpanded);
if (conceptViews.isEmpty()) {
logConceptsExpanded("No concepts to expand. ", theTermValueSet, conceptsExpanded);
return;
}
Map<Long, ValueSet.ValueSetExpansionContainsComponent> pidToConcept = new HashMap<>();
for (TermValueSetConceptView conceptView : conceptViews) {
int designationsExpanded = 0;
for (TermValueSetConceptView concept : slice) {
Long conceptPid = concept.getConceptPid();
Long conceptPid = conceptView.getConceptPid();
ValueSet.ValueSetExpansionContainsComponent containsComponent;
if (!pidToConcept.containsKey(conceptPid)) {
containsComponent = theExpansionComponent.addContains();
containsComponent.setSystem(concept.getConceptSystemUrl());
containsComponent.setCode(concept.getConceptCode());
containsComponent.setDisplay(concept.getConceptDisplay());
containsComponent.setSystem(conceptView.getConceptSystemUrl());
containsComponent.setCode(conceptView.getConceptCode());
containsComponent.setDisplay(conceptView.getConceptDisplay());
pidToConcept.put(conceptPid, containsComponent);
} else {
containsComponent = pidToConcept.get(conceptPid);
}
if (concept.getDesigPid() != null) {
// TODO: DM 2019-08-17 - Implement includeDesignations parameter for $expand operation to designations optional.
if (conceptView.getDesignationPid() != null) {
ValueSet.ConceptReferenceDesignationComponent designationComponent = containsComponent.addDesignation();
designationComponent.setLanguage(concept.getDesigLang());
designationComponent.setLanguage(conceptView.getDesignationLang());
designationComponent.setUse(new Coding(
concept.getDesigUseSystem(),
concept.getDesigUseCode(),
concept.getDesigUseDisplay()));
designationComponent.setValue(concept.getDesigVal());
conceptView.getDesignationUseSystem(),
conceptView.getDesignationUseCode(),
conceptView.getDesignationUseDisplay()));
designationComponent.setValue(conceptView.getDesignationVal());
if (++designationsExpanded % 250 == 0) {
logDesignationsExpanded(theTermValueSet, designationsExpanded);
logDesignationsExpanded("Expansion of designations in progress. ", theTermValueSet, designationsExpanded);
}
logDesignationsExpanded(theTermValueSet, designationsExpanded);
}
// TODO: DM 2019-08-17 - Implement includeDesignations parameter for $expand operation to make this optional.
// FIXME: DM 2019-09-05 - Let's try removing the pre-fetch and the code in BaseHapiTerminologySvcImpl that handles designations so we can compare the processing time. 2/2
// expandDesignations(theTermValueSet, concept, containsComponent);
if (++conceptsExpanded % 250 == 0) {
logConceptsExpanded(theTermValueSet, conceptsExpanded);
logConceptsExpanded("Expansion of concepts in progress. ", theTermValueSet, conceptsExpanded);
}
}
logConceptsExpanded(theTermValueSet, conceptsExpanded);
logDesignationsExpanded("Finished expanding designations. ", theTermValueSet, designationsExpanded);
logConceptsExpanded("Finished expanding concepts. ", theTermValueSet, conceptsExpanded);
}
private void logConceptsExpanded(TermValueSet theTermValueSet, int theConceptsExpanded) {
private void logConceptsExpanded(String thePrefix, TermValueSet theTermValueSet, int theConceptsExpanded) {
if (theConceptsExpanded > 0) {
// FIXME: DM 2019-09-05 - Account for in progress vs. total.
ourLog.info("Have expanded {} concepts in ValueSet[{}]", theConceptsExpanded, theTermValueSet.getUrl());
ourLog.info("{}Have expanded {} concepts in ValueSet[{}]", thePrefix, theConceptsExpanded, theTermValueSet.getUrl());
}
}
private void logDesignationsExpanded(TermValueSet theValueSet, int theDesignationsExpanded) {
private void logDesignationsExpanded(String thePrefix, TermValueSet theTermValueSet, int theDesignationsExpanded) {
if (theDesignationsExpanded > 0) {
// FIXME: DM 2019-09-05 - Account for in progress vs. total.
// FIXME: DM 2019-09-06 - Change to debug.
ourLog.info("Have expanded {} designations in ValueSet[{}]", theDesignationsExpanded, theValueSet.getUrl());
ourLog.info("{}Have expanded {} designations in ValueSet[{}]", thePrefix, theDesignationsExpanded, theTermValueSet.getUrl());
}
}
@ -646,6 +633,8 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
}
}
// FIXME: DM 2019-09-06 - After handling excludes, we need to adjust TermValueSetConcept.myOrder to account for any gaps.
ourLog.info("Done working with {} in {}ms", valueSetInfo, sw.getMillis());
}
@ -1838,8 +1827,8 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
ourLog.info("Done storing TermConceptMap[{}]", termConceptMap.getId());
}
// FIXME: DM 2019-09-05 - Return to 600000
@Scheduled(fixedDelay = 600000) // 10 minutes.
// FIXME: DM 2019-09-05 - Return to 600000 before merging into master.
@Scheduled(fixedDelay = 6000) // 10 minutes.
@Override
public synchronized void preExpandDeferredValueSetsToTerminologyTables() {
if (isNotSafeToPreExpandValueSets()) {