Skip to content

Commit f4c02e2

Browse files
author
leif stawnyczy
committed
Merge branch 'rel_8_2' into 6564-default-partition-id-bug
2 parents 212ff9d + 85385c3 commit f4c02e2

File tree

7 files changed

+156
-319
lines changed

7 files changed

+156
-319
lines changed

hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/canonical/VersionCanonicalizer.java

+62-6
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
192192
return myStrategy.valueSetFromCanonical(theValueSet);
193193
}
194194

195+
/**
196+
* Canonical version: R4
197+
*/
198+
public IBaseResource codeSystemFromCanonical(CodeSystem theCodeSystem) {
199+
return myStrategy.codeSystemFromCanonical(theCodeSystem);
200+
}
201+
195202
/**
196203
* Canonical version: R4
197204
*/
@@ -322,6 +329,8 @@ private interface IStrategy {
322329

323330
IBaseResource valueSetFromCanonical(ValueSet theValueSet);
324331

332+
IBaseResource codeSystemFromCanonical(CodeSystem theCodeSystem);
333+
325334
ConceptMap conceptMapToCanonical(IBaseResource theConceptMap);
326335

327336
SearchParameter searchParameterToCanonical(IBaseResource theSearchParameter);
@@ -443,6 +452,13 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
443452
return reencodeFromHl7Org(valueSetDstu2Hl7Org);
444453
}
445454

455+
@Override
456+
public IBaseResource codeSystemFromCanonical(CodeSystem theCodeSystem) {
457+
Resource codeSystemDstu2Hl7Org =
458+
VersionConvertorFactory_10_40.convertResource(theCodeSystem, ADVISOR_10_40);
459+
return reencodeFromHl7Org(codeSystemDstu2Hl7Org);
460+
}
461+
446462
@Override
447463
public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
448464
org.hl7.fhir.dstu2.model.Resource reencoded = reencodeToHl7Org(theConceptMap);
@@ -524,21 +540,34 @@ public IBaseConformance capabilityStatementFromCanonical(CapabilityStatement the
524540
}
525541

526542
private Resource reencodeToHl7Org(IBaseResource theInput) {
543+
if (theInput == null) {
544+
return null;
545+
}
527546
if (myHl7OrgStructures) {
528547
return (Resource) theInput;
529548
}
530-
return (Resource) myDstu2Hl7OrgContext
531-
.newJsonParser()
532-
.parseResource(myDstu2Context.newJsonParser().encodeResourceToString(theInput));
549+
return (Resource) myDstu2Hl7OrgContext.newJsonParser().parseResource(encodeAsString(theInput));
533550
}
534551

535552
private IBaseResource reencodeFromHl7Org(Resource theInput) {
553+
if (theInput == null) {
554+
return null;
555+
}
536556
if (myHl7OrgStructures) {
537557
return theInput;
538558
}
539-
return myDstu2Context
540-
.newJsonParser()
541-
.parseResource(myDstu2Hl7OrgContext.newJsonParser().encodeResourceToString(theInput));
559+
return myDstu2Context.newJsonParser().parseResource(encodeAsString(theInput));
560+
}
561+
562+
private String encodeAsString(IBaseResource theResource) {
563+
FhirVersionEnum version = theResource.getStructureFhirVersionEnum();
564+
if (myDstu2Context.getVersion().getVersion().equals(version)) {
565+
return myDstu2Context.newJsonParser().encodeResourceToString(theResource);
566+
} else if (myDstu2Hl7OrgContext.getVersion().getVersion().equals(version)) {
567+
return myDstu2Hl7OrgContext.newJsonParser().encodeResourceToString(theResource);
568+
} else {
569+
throw new IllegalArgumentException("Cannot encode resource with version: %s".formatted(version));
570+
}
542571
}
543572
}
544573

@@ -579,6 +608,11 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
579608
return VersionConvertorFactory_14_40.convertResource(theValueSet, ADVISOR_14_40);
580609
}
581610

611+
@Override
612+
public IBaseResource codeSystemFromCanonical(CodeSystem theCodeSystem) {
613+
return VersionConvertorFactory_14_40.convertResource(theCodeSystem, ADVISOR_14_40);
614+
}
615+
582616
@Override
583617
public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
584618
return (ConceptMap) VersionConvertorFactory_14_40.convertResource(
@@ -683,6 +717,11 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
683717
return VersionConvertorFactory_30_40.convertResource(theValueSet, ADVISOR_30_40);
684718
}
685719

720+
@Override
721+
public IBaseResource codeSystemFromCanonical(CodeSystem theCodeSystem) {
722+
return VersionConvertorFactory_30_40.convertResource(theCodeSystem, ADVISOR_30_40);
723+
}
724+
686725
@Override
687726
public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
688727
return (ConceptMap) VersionConvertorFactory_30_40.convertResource(
@@ -782,6 +821,11 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
782821
return theValueSet;
783822
}
784823

824+
@Override
825+
public IBaseResource codeSystemFromCanonical(CodeSystem theCodeSystem) {
826+
return theCodeSystem;
827+
}
828+
785829
@Override
786830
public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
787831
return (ConceptMap) theConceptMap;
@@ -897,6 +941,13 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
897941
return VersionConvertorFactory_43_50.convertResource(valueSetR5, ADVISOR_43_50);
898942
}
899943

944+
@Override
945+
public IBaseResource codeSystemFromCanonical(CodeSystem theCodeSystem) {
946+
org.hl7.fhir.r5.model.CodeSystem codeSystemR5 = (org.hl7.fhir.r5.model.CodeSystem)
947+
VersionConvertorFactory_40_50.convertResource(theCodeSystem, ADVISOR_40_50);
948+
return VersionConvertorFactory_43_50.convertResource(codeSystemR5, ADVISOR_43_50);
949+
}
950+
900951
@Override
901952
public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
902953
org.hl7.fhir.r5.model.ConceptMap conceptMapR5 =
@@ -1006,6 +1057,11 @@ public IBaseResource valueSetFromCanonical(ValueSet theValueSet) {
10061057
return VersionConvertorFactory_40_50.convertResource(theValueSet, ADVISOR_40_50);
10071058
}
10081059

1060+
@Override
1061+
public IBaseResource codeSystemFromCanonical(CodeSystem theCodeSystem) {
1062+
return VersionConvertorFactory_40_50.convertResource(theCodeSystem, ADVISOR_40_50);
1063+
}
1064+
10091065
@Override
10101066
public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
10111067
return (ConceptMap) VersionConvertorFactory_40_50.convertResource(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: fix
3+
issue: 6652
4+
title: "A failure in the migrator has been corrected when applying the SQL migrator's drop
5+
primary key task on MSSQL. Thanks to Craig McClendon for the analysis and fix!"

hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTableColumnTypeTask.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public BaseTableColumnTask setColumnType(ColumnTypeEnum theColumnType) {
6464
@Override
6565
public void validate() {
6666
super.validate();
67-
Validate.notNull(myColumnType);
68-
Validate.notNull(myNullable);
67+
Validate.notNull(myColumnType, "myColumnType must not be null");
68+
Validate.notNull(myNullable, "myNullable must not be null");
6969

7070
if (myColumnType == ColumnTypeEnum.STRING) {
7171
Validate.notNull(

hapi-fhir-sql-migrate/src/main/java/ca/uhn/fhir/jpa/migrate/taskdef/DropPrimaryKeyTask.java

-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ private String generatePrimaryKeyNameSql() {
124124
+ "AND table_name = ?";
125125
case MSSQL_2012:
126126
return "SELECT tc.constraint_name " + "FROM information_schema.table_constraints tc "
127-
+ "JOIN information_schema.constraint_column_usage ccu ON tc.constraint_name = ccu.constraint_name "
128127
+ "WHERE tc.constraint_type = 'PRIMARY KEY' "
129128
+ "AND tc.table_name = ?";
130129
default:

hapi-fhir-sql-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTaskITTestSuite.java

+47-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
import ca.uhn.fhir.jpa.migrate.JdbcUtils;
44
import ca.uhn.fhir.jpa.migrate.taskdef.containertests.BaseMigrationTaskTestSuite;
55
import ca.uhn.fhir.jpa.migrate.tasks.api.Builder;
6-
import org.assertj.core.api.Assertions;
76
import org.awaitility.Awaitility;
87
import org.junit.jupiter.api.Test;
98

109
import java.sql.SQLException;
10+
import java.util.Locale;
11+
import java.util.Set;
1112
import java.util.concurrent.TimeUnit;
13+
import java.util.stream.Collectors;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
1216

1317
/**
1418
* Integration tests for AddIndexTask.
@@ -37,7 +41,48 @@ default void testAddIndexOnline_createsIndex() throws SQLException {
3741

3842
// we wait since the ONLINE path is async.
3943
Awaitility.await("index FOO exists").atMost(10, TimeUnit.SECONDS).untilAsserted(
40-
() -> Assertions.assertThat(JdbcUtils.getIndexNames(getSupport().getConnectionProperties(), tableName)).contains("FOO"));
44+
() -> assertThat(JdbcUtils.getIndexNames(getSupport().getConnectionProperties(), tableName)).contains("FOO"));
45+
}
46+
47+
48+
@Test
49+
default void testDropAndAddPrimaryKeyTest() throws SQLException {
50+
// Setup
51+
Builder builder = getSupport().getBuilder();
52+
String tableName = "table_drop_add_pk_" + System.currentTimeMillis();
53+
Builder.BuilderAddTableByColumns tableBuilder = builder.addTableByColumns("1", tableName, "col_a", "col_b");
54+
tableBuilder.addColumn("col_a").nonNullable().type(ColumnTypeEnum.INT);
55+
tableBuilder.addColumn("col_b").nonNullable().type(ColumnTypeEnum.INT);
56+
tableBuilder.addColumn("col_c").nonNullable().type(ColumnTypeEnum.INT);
57+
getSupport().executeAndClearPendingTasks();
58+
assertThat(toUpper(JdbcUtils.getPrimaryKeyColumns(getSupport().getConnectionProperties(), tableName)))
59+
.contains("COL_A", "COL_B");
60+
61+
// Test - Drop PK
62+
builder.onTable(tableName)
63+
.dropPrimaryKey("2");
64+
getSupport().executeAndClearPendingTasks();
65+
66+
// Verify - PK should reflect the new one
67+
assertThat(toUpper(JdbcUtils.getPrimaryKeyColumns(getSupport().getConnectionProperties(), tableName)))
68+
.isEmpty();
69+
70+
// Test - Add New PK
71+
builder.onTable(tableName)
72+
.addPrimaryKey("3", "col_b", "col_c");
73+
getSupport().executeAndClearPendingTasks();
74+
75+
// Verify - PK should reflect the new one
76+
assertThat(toUpper(JdbcUtils.getPrimaryKeyColumns(getSupport().getConnectionProperties(), tableName)))
77+
.contains("COL_B", "COL_C");
78+
}
79+
80+
default Set<String> toUpper(Set<String> theInput) {
81+
return theInput
82+
.stream()
83+
.map(t->t.toUpperCase(Locale.ROOT))
84+
.collect(Collectors.toSet());
4185
}
4286

87+
4388
}

hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyService.java

+8-29
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,10 @@
2020
import org.apache.commons.lang3.StringUtils;
2121
import org.fhir.ucum.UcumEssenceService;
2222
import org.fhir.ucum.UcumException;
23-
import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40;
24-
import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_40_50;
25-
import org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_43_50;
26-
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_30_40;
27-
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
28-
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_43_50;
2923
import org.hl7.fhir.dstu2.model.ValueSet;
3024
import org.hl7.fhir.instance.model.api.IBaseResource;
3125
import org.hl7.fhir.r4.model.CodeSystem;
3226
import org.hl7.fhir.r4.model.CodeSystem.CodeSystemContentMode;
33-
import org.hl7.fhir.r5.model.Resource;
3427
import org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent;
3528
import org.slf4j.Logger;
3629

@@ -41,6 +34,7 @@
4134
import java.util.Map;
4235
import java.util.Objects;
4336
import java.util.Optional;
37+
import java.util.Set;
4438

4539
import static org.apache.commons.lang3.StringUtils.defaultString;
4640
import static org.apache.commons.lang3.StringUtils.isBlank;
@@ -443,30 +437,15 @@ public IBaseResource fetchCodeSystem(String theSystem) {
443437
retVal.addConcept().setCode(nextEntry.getKey()).setDisplay(nextEntry.getValue());
444438
}
445439

446-
IBaseResource normalized = null;
447-
switch (getFhirContext().getVersion().getVersion()) {
448-
case DSTU2:
449-
case DSTU2_HL7ORG:
450-
case DSTU2_1:
451-
return null;
452-
case DSTU3:
453-
normalized = VersionConvertorFactory_30_40.convertResource(retVal, new BaseAdvisor_30_40(false));
454-
break;
455-
case R4:
456-
normalized = retVal;
457-
break;
458-
case R4B:
459-
Resource normalized50 =
460-
VersionConvertorFactory_40_50.convertResource(retVal, new BaseAdvisor_40_50(false));
461-
normalized = VersionConvertorFactory_43_50.convertResource(normalized50, new BaseAdvisor_43_50());
462-
break;
463-
case R5:
464-
normalized = VersionConvertorFactory_40_50.convertResource(retVal, new BaseAdvisor_40_50(false));
465-
break;
440+
IBaseResource normalized = myVersionCanonicalizer.codeSystemFromCanonical(retVal);
441+
Set<FhirVersionEnum> nullableVersions =
442+
Set.of(FhirVersionEnum.DSTU2, FhirVersionEnum.DSTU2_HL7ORG, FhirVersionEnum.DSTU2_1);
443+
boolean isNullableVersion =
444+
nullableVersions.contains(getFhirContext().getVersion().getVersion());
445+
if (!isNullableVersion) {
446+
Objects.requireNonNull(normalized);
466447
}
467448

468-
Objects.requireNonNull(normalized);
469-
470449
return normalized;
471450
}
472451

0 commit comments

Comments
 (0)