diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java index a3e93390c8e..a50c382d95a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/DaoConfig.java @@ -149,7 +149,7 @@ public class DaoConfig { /** * EXPERIMENTAL - Do not use in production! Do not change default of {@code false}! */ - private boolean myPreExpandValueSetsExperimental = false; + private boolean myPreExpandValueSetsExperimental = true; private boolean myFilterParameterEnabled = false; private StoreMetaSourceInformationEnum myStoreMetaSourceInformation = StoreMetaSourceInformationEnum.SOURCE_URI_AND_REQUEST_ID; /** diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetConceptDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetConceptDao.java index 3f0f8a9e2a3..09a59729ff9 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetConceptDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/data/ITermValueSetConceptDao.java @@ -40,7 +40,7 @@ public interface ITermValueSetConceptDao extends JpaRepository findByTermValueSetIdAndPreFetchDesignations(Pageable thePage, @Param("pid") Long theValueSetId); @Query("SELECT vsc FROM TermValueSetConcept vsc WHERE vsc.myValueSet.myId = :pid AND vsc.mySystem = :system_url AND vsc.myCode = :codeval") diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetConcept.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetConcept.java index 4827e756d89..85ebf24a0ef 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetConcept.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetConcept.java @@ -40,7 +40,8 @@ import static org.apache.commons.lang3.StringUtils.length; * bork up migration tasks. */ @Table(name = "TRM_VALUESET_CONCEPT", uniqueConstraints = { - @UniqueConstraint(name = "IDX_VS_CONCEPT_CS_CD", columnNames = {"VALUESET_PID", "SYSTEM_URL", "CODEVAL"}) + @UniqueConstraint(name = "IDX_VS_CONCEPT_CS_CD", columnNames = {"VALUESET_PID", "SYSTEM_URL", "CODEVAL"}), + @UniqueConstraint(name = "IDX_VS_CONCEPT_ORDER", columnNames = {"VALUESET_PID", "VALUESET_ORDER"}) }) @Entity() public class TermValueSetConcept implements Serializable { @@ -56,6 +57,12 @@ public class TermValueSetConcept implements Serializable { @JoinColumn(name = "VALUESET_PID", referencedColumnName = "PID", nullable = false, foreignKey = @ForeignKey(name = "FK_TRM_VALUESET_PID")) private TermValueSet myValueSet; + @Column(name = "VALUESET_PID", insertable = false, updatable = false, nullable = false) + private Long myValueSetPid; + + @Column(name = "VALUESET_ORDER", nullable = false) + private int myOrder; + @Transient private String myValueSetUrl; @@ -87,6 +94,15 @@ public class TermValueSetConcept implements Serializable { return this; } + public int getOrder() { + return myOrder; + } + + public TermValueSetConcept setOrder(int theOrder) { + myOrder = theOrder; + return this; + } + public String getValueSetUrl() { if (myValueSetUrl == null) { myValueSetUrl = getValueSet().getUrl(); @@ -173,6 +189,8 @@ public class TermValueSetConcept implements Serializable { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) .append("myId", myId) .append(myValueSet != null ? ("myValueSet - id=" + myValueSet.getId()) : ("myValueSet=(null)")) + .append("myValueSetPid", myValueSetPid) + .append("myOrder", myOrder) .append("myValueSetUrl", this.getValueSetUrl()) .append("myValueSetName", this.getValueSetName()) .append("mySystem", mySystem) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetConceptDesignation.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetConceptDesignation.java index e3aa0c5196a..87e5ef2e8ec 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetConceptDesignation.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/entity/TermValueSetConceptDesignation.java @@ -52,10 +52,16 @@ public class TermValueSetConceptDesignation implements Serializable { @JoinColumn(name = "VALUESET_CONCEPT_PID", referencedColumnName = "PID", nullable = false, foreignKey = @ForeignKey(name = "FK_TRM_VALUESET_CONCEPT_PID")) private TermValueSetConcept myConcept; + @Column(name = "VALUESET_CONCEPT_PID", insertable = false, updatable = false, nullable = false) + private Long myConceptPid; + @ManyToOne() @JoinColumn(name = "VALUESET_PID", referencedColumnName = "PID", nullable = false, foreignKey = @ForeignKey(name = "FK_TRM_VSCD_VS_PID")) private TermValueSet myValueSet; + @Column(name = "VALUESET_PID", insertable = false, updatable = false, nullable = false) + private Long myValueSetPid; + @Transient private String myValueSetUrl; @@ -202,7 +208,9 @@ public class TermValueSetConceptDesignation implements Serializable { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) .append("myId", myId) .append(myConcept != null ? ("myConcept - id=" + myConcept.getId()) : ("myConcept=(null)")) + .append("myConceptPid", myConceptPid) .append(myValueSet != null ? ("myValueSet - id=" + myValueSet.getId()) : ("myValueSet=(null)")) + .append("myValueSetPid", myValueSetPid) .append("myValueSetUrl", this.getValueSetUrl()) .append("myValueSetName", this.getValueSetName()) .append("myLanguage", myLanguage) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulator.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulator.java index 24f41232fbe..5c7fd8911f4 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulator.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulator.java @@ -97,6 +97,7 @@ public class ValueSetConceptAccumulator implements IValueSetConceptAccumulator { TermValueSetConcept concept = new TermValueSetConcept(); concept.setValueSet(myTermValueSet); + concept.setOrder(myConceptsSaved); concept.setSystem(theSystem); concept.setCode(theCode); if (isNotBlank(theDisplay)) { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java index 599912cd965..de3e466a968 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java @@ -2097,11 +2097,12 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); TermValueSetConcept concept = termValueSet.getConcepts().get(0); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8450-9", concept.getCode()); assertEquals("Systolic blood pressure--expiration", concept.getDisplay()); assertEquals(2, concept.getDesignations().size()); + assertEquals(0, concept.getOrder()); TermValueSetConceptDesignation designation = concept.getDesignations().get(0); assertEquals("nl", designation.getLanguage()); @@ -2118,20 +2119,22 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); concept = termValueSet.getConcepts().get(1); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("11378-7", concept.getCode()); assertEquals("Systolic blood pressure at First encounter", concept.getDisplay()); assertEquals(0, concept.getDesignations().size()); + assertEquals(1, concept.getOrder()); // ... concept = termValueSet.getConcepts().get(22); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8491-3", concept.getCode()); assertEquals("Systolic blood pressure 1 hour minimum", concept.getDisplay()); assertEquals(1, concept.getDesignations().size()); + assertEquals(22, concept.getOrder()); designation = concept.getDesignations().get(0); assertEquals("nl", designation.getLanguage()); @@ -2141,11 +2144,12 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); concept = termValueSet.getConcepts().get(23); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8492-1", concept.getCode()); assertEquals("Systolic blood pressure 8 hour minimum", concept.getDisplay()); assertEquals(0, concept.getDesignations().size()); + assertEquals(23, concept.getOrder()); }); } @@ -2195,11 +2199,12 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); TermValueSetConcept concept = termValueSet.getConcepts().get(0); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8450-9", concept.getCode()); assertEquals("Systolic blood pressure--expiration", concept.getDisplay()); assertEquals(2, concept.getDesignations().size()); + assertEquals(0, concept.getOrder()); TermValueSetConceptDesignation designation = concept.getDesignations().get(0); assertEquals("nl", designation.getLanguage()); @@ -2216,20 +2221,22 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); concept = termValueSet.getConcepts().get(1); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("11378-7", concept.getCode()); assertEquals("Systolic blood pressure at First encounter", concept.getDisplay()); assertEquals(0, concept.getDesignations().size()); + assertEquals(1, concept.getOrder()); // ... concept = termValueSet.getConcepts().get(22); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8491-3", concept.getCode()); assertEquals("Systolic blood pressure 1 hour minimum", concept.getDisplay()); assertEquals(1, concept.getDesignations().size()); + assertEquals(22, concept.getOrder()); designation = concept.getDesignations().get(0); assertEquals("nl", designation.getLanguage()); @@ -2239,11 +2246,12 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); concept = termValueSet.getConcepts().get(23); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8492-1", concept.getCode()); assertEquals("Systolic blood pressure 8 hour minimum", concept.getDisplay()); assertEquals(0, concept.getDesignations().size()); + assertEquals(23, concept.getOrder()); }); } @@ -2293,11 +2301,12 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); TermValueSetConcept concept = termValueSet.getConcepts().get(0); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8450-9", concept.getCode()); assertEquals("Systolic blood pressure--expiration", concept.getDisplay()); assertEquals(2, concept.getDesignations().size()); + assertEquals(0, concept.getOrder()); TermValueSetConceptDesignation designation = concept.getDesignations().get(0); assertEquals("nl", designation.getLanguage()); @@ -2314,20 +2323,22 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); concept = termValueSet.getConcepts().get(1); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("11378-7", concept.getCode()); assertEquals("Systolic blood pressure at First encounter", concept.getDisplay()); assertEquals(0, concept.getDesignations().size()); + assertEquals(1, concept.getOrder()); // ... concept = termValueSet.getConcepts().get(22 - 2); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8491-3", concept.getCode()); assertEquals("Systolic blood pressure 1 hour minimum", concept.getDisplay()); assertEquals(1, concept.getDesignations().size()); + assertEquals(22, concept.getOrder()); designation = concept.getDesignations().get(0); assertEquals("nl", designation.getLanguage()); @@ -2337,11 +2348,12 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); concept = termValueSet.getConcepts().get(23 - 2); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8492-1", concept.getCode()); assertEquals("Systolic blood pressure 8 hour minimum", concept.getDisplay()); assertEquals(0, concept.getDesignations().size()); + assertEquals(23, concept.getOrder()); }); } @@ -2391,11 +2403,12 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals(TermValueSetPreExpansionStatusEnum.EXPANDED, termValueSet.getExpansionStatus()); TermValueSetConcept concept = termValueSet.getConcepts().get(0); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8450-9", concept.getCode()); assertEquals("Systolic blood pressure--expiration", concept.getDisplay()); assertEquals(2, concept.getDesignations().size()); + assertEquals(0, concept.getOrder()); TermValueSetConceptDesignation designation = concept.getDesignations().get(0); assertEquals("nl", designation.getLanguage()); @@ -2412,20 +2425,22 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals("Systoliskt blodtryck - utgång", designation.getValue()); concept = termValueSet.getConcepts().get(1); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("11378-7", concept.getCode()); assertEquals("Systolic blood pressure at First encounter", concept.getDisplay()); assertEquals(0, concept.getDesignations().size()); + assertEquals(1, concept.getOrder()); // ... concept = termValueSet.getConcepts().get(22 - 2); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8491-3", concept.getCode()); assertEquals("Systolic blood pressure 1 hour minimum", concept.getDisplay()); assertEquals(1, concept.getDesignations().size()); + assertEquals(22, concept.getOrder()); designation = concept.getDesignations().get(0); assertEquals("nl", designation.getLanguage()); @@ -2435,11 +2450,12 @@ public class TerminologySvcImplR4Test extends BaseJpaR4Test { assertEquals("Systolische bloeddruk minimaal 1 uur", designation.getValue()); concept = termValueSet.getConcepts().get(23 - 2); - ourLog.info("Code:\n" + concept.toString()); + ourLog.info("Concept:\n" + concept.toString()); assertEquals("http://acme.org", concept.getSystem()); assertEquals("8492-1", concept.getCode()); assertEquals("Systolic blood pressure 8 hour minimum", concept.getDisplay()); assertEquals(0, concept.getDesignations().size()); + assertEquals(23, concept.getOrder()); }); } diff --git a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java index 5574be04e90..b21e03dcba3 100644 --- a/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java +++ b/hapi-fhir-jpaserver-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasks.java @@ -93,6 +93,15 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks { Builder.BuilderWithTableName termValueSetTable = version.onTable("TRM_VALUESET"); termValueSetTable.addColumn("TOTAL_CONCEPTS").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); termValueSetTable.addColumn("TOTAL_CONCEPT_DESIGNATIONS").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.LONG); + + // TermValueSetConcept + version.startSectionWithMessage("Processing table: TRM_VALUESET_CONCEPT"); + Builder.BuilderWithTableName termValueSetConceptTable = version.onTable("TRM_VALUESET_CONCEPT"); + termValueSetConceptTable.addColumn("VALUESET_ORDER").nonNullable().type(BaseTableColumnTypeTask.ColumnTypeEnum.INT); + termValueSetConceptTable + .addIndex("IDX_VS_CONCEPT_ORDER") + .unique(true) + .withColumns("VALUESET_PID", "VALUESET_ORDER"); } protected void init400() {