Skip to content

Commit c10043d

Browse files
authored
Merge branch 'master' into dependabot/maven/org.apache.parquet-parquet-avro-1.16.0
2 parents 596b53c + bca93eb commit c10043d

File tree

44 files changed

+322
-277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+322
-277
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ automated e2e/unit tests.
4040
code that was well tested you do not have to add tests)
4141
- [ ] I ran `mvn clean package` right before creating this pull request and
4242
added all formatting changes to my commit.
43-
- [ ] If I made any Python code changes, I ran `black .` and `pylint .` right
44-
before creating this pull request and added all formatting changes to my
45-
commit.
43+
- [ ] If I made any Python code changes, I ran `black .`, `pylint .` and
44+
`pyright` . right before creating this pull request and added all
45+
formatting changes to my commit.
4646
- [ ] All new and existing **tests passed**.
4747
- [ ] My pull request is **based on the latest changes** of the master branch.
4848

bunsen/bunsen-avro/src/main/java/com/cerner/bunsen/avro/AvroConverter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.avro.generic.IndexedRecord;
2323
import org.apache.commons.collections4.CollectionUtils;
2424
import org.hl7.fhir.instance.model.api.IBaseResource;
25+
import org.jspecify.annotations.Nullable;
2526

2627
/** Converter to change HAPI objects into Avro structures and vice versa. */
2728
public class AvroConverter {
@@ -74,6 +75,7 @@ private static AvroConverter visitResource(
7475
RuntimeResourceDefinition[] resources =
7576
new RuntimeResourceDefinition[1 + containedResourceTypeUrls.size()];
7677

78+
Preconditions.checkNotNull(converter.getElementType(), "Converter must have an element type");
7779
resources[0] = context.getResourceDefinition(converter.getElementType());
7880

7981
for (int i = 0; i < containedResourceTypeUrls.size(); i++) {
@@ -210,6 +212,7 @@ public static AvroConverter forResource(
210212
* @param resource the FHIR resource
211213
* @return the record.
212214
*/
215+
@Nullable
213216
public IndexedRecord resourceToAvro(IBaseResource resource) {
214217

215218
return (IndexedRecord) hapiToAvroConverter.fromHapi(resource);
@@ -221,6 +224,7 @@ public IndexedRecord resourceToAvro(IBaseResource resource) {
221224
* @param record the record
222225
* @return the FHIR resource.
223226
*/
227+
@Nullable
224228
public IBaseResource avroToResource(IndexedRecord record) {
225229

226230
return (IBaseResource) avroToHapiConverter.toHapi(record);
@@ -241,6 +245,7 @@ public Schema getSchema() {
241245
*
242246
* @return the FHIR type of the resource being converted.
243247
*/
248+
@Nullable
244249
public String getResourceType() {
245250
return hapiToAvroConverter.getElementType();
246251
}

bunsen/bunsen-avro/src/main/java/com/cerner/bunsen/avro/converters/DefinitionToAvroVisitor.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.apache.commons.lang3.StringUtils;
4545
import org.hl7.fhir.instance.model.api.IBase;
4646
import org.hl7.fhir.instance.model.api.IPrimitiveType;
47+
import org.jspecify.annotations.Nullable;
4748

4849
public class DefinitionToAvroVisitor implements DefinitionVisitor<HapiConverter<Schema>> {
4950

@@ -170,19 +171,19 @@ private static class CompositeToAvroConverter extends HapiCompositeConverter<Sch
170171
private final GenericData avroData = SpecificData.get();
171172

172173
CompositeToAvroConverter(
173-
String elementType,
174+
@Nullable String elementType,
174175
List<StructureField<HapiConverter<Schema>>> children,
175176
Schema structType,
176177
FhirConversionSupport fhirSupport) {
177178
this(elementType, children, structType, fhirSupport, null);
178179
}
179180

180181
CompositeToAvroConverter(
181-
String elementType,
182+
@Nullable String elementType,
182183
List<StructureField<HapiConverter<Schema>>> children,
183184
Schema structType,
184185
FhirConversionSupport fhirSupport,
185-
String extensionUrl) {
186+
@Nullable String extensionUrl) {
186187

187188
super(elementType, children, structType, fhirSupport, extensionUrl);
188189
}
@@ -629,6 +630,7 @@ private static class NoOpFieldSetter implements HapiFieldSetter, HapiObjectConve
629630
public void setField(
630631
IBase parentObject, BaseRuntimeChildDefinition fieldToSet, Object sparkObject) {}
631632

633+
@Nullable
632634
@Override
633635
public IBase toHapi(Object input) {
634636
return null;
@@ -646,6 +648,7 @@ private static class RelativeValueConverter extends HapiConverter<Schema> {
646648
this.prefix = prefix;
647649
}
648650

651+
@Nullable
649652
@Override
650653
public Object fromHapi(Object input) {
651654
String uri = ((IPrimitiveType) input).getValueAsString();
@@ -763,11 +766,6 @@ public HapiConverter<Schema> visitParentExtension(
763766
String extensionUrl,
764767
List<StructureField<HapiConverter<Schema>>> children) {
765768

766-
// Ignore extension fields that don't have declared content for now.
767-
if (children.isEmpty()) {
768-
return null;
769-
}
770-
771769
String recordNamespace = DefinitionVisitorsUtil.namespaceFor(basePackage, extensionUrl);
772770

773771
String localPart = extensionUrl.substring(extensionUrl.lastIndexOf('/') + 1);
@@ -850,13 +848,13 @@ public int getMaxDepth(String elementTypeUrl, String path) {
850848
}
851849

852850
private static HapiCompositeConverter createCompositeConverter(
853-
String elementType,
851+
@Nullable String elementType,
854852
String recordName,
855853
String doc,
856854
String namespace,
857855
List<StructureField<HapiConverter<Schema>>> children,
858856
FhirConversionSupport fhirSupport,
859-
String extensionUrl) {
857+
@Nullable String extensionUrl) {
860858

861859
List<Field> fields =
862860
children.stream()

bunsen/bunsen-avro/src/main/java/com/cerner/bunsen/avro/converters/NoOpConverter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import org.apache.avro.Schema;
99
import org.apache.avro.Schema.Type;
1010
import org.hl7.fhir.instance.model.api.IBase;
11+
import org.jspecify.annotations.Nullable;
1112

1213
public class NoOpConverter extends HapiConverter<Schema> {
1314

15+
@Nullable
1416
@Override
1517
public Object fromHapi(Object input) {
1618
return null;
@@ -26,6 +28,7 @@ private static class FieldSetter implements HapiFieldSetter, HapiObjectConverter
2628
@Override
2729
public void setField(IBase parentObject, BaseRuntimeChildDefinition fieldToSet, Object value) {}
2830

31+
@Nullable
2932
@Override
3033
public IBase toHapi(Object input) {
3134
return null;

bunsen/bunsen-avro/src/main/java/com/cerner/bunsen/avro/tools/GenerateAggregatedSchemas.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Map;
1919
import org.apache.avro.Schema;
2020
import org.apache.avro.SchemaFormatter;
21+
import org.jspecify.annotations.Nullable;
2122

2223
/** This class can be used to generate aggregated avro schemas for the FHIR profile extensions. */
2324
public class GenerateAggregatedSchemas {
@@ -75,10 +76,10 @@ private static Map<String, String> convertArgsToPairs(String[] args) {
7576
}
7677

7778
private static void generateAggregatedSchemas(
78-
FhirVersionEnum fhirVersionEnum,
79-
String structureDefinitionsPath,
80-
List<String> resourceTypes,
81-
String outputDir)
79+
@Nullable FhirVersionEnum fhirVersionEnum,
80+
@Nullable String structureDefinitionsPath,
81+
@Nullable List<String> resourceTypes,
82+
@Nullable String outputDir)
8283
throws ProfileException, IOException {
8384
Preconditions.checkNotNull(fhirVersionEnum, "%s cannot be empty", FHIR_VERSION);
8485
Preconditions.checkNotNull(
@@ -95,6 +96,15 @@ private static void generateAggregatedSchemas(
9596
List<String> resourceTypeURLs =
9697
ProfileMapperFhirContexts.getInstance()
9798
.getMappedProfilesForResource(FhirVersionEnum.R4, resourceType);
99+
if (resourceTypeURLs == null || resourceTypeURLs.isEmpty()) {
100+
System.out.printf(
101+
"No profiles found for resourceType=%s, skipping schema generation for this"
102+
+ " resourceType%n",
103+
resourceType);
104+
continue; // TODO confirm if we need to throw a new ProfileException exception here instead
105+
// of skipping
106+
}
107+
98108
AvroConverter aggregatedConverter =
99109
AvroConverter.forResources(fhirContext, resourceTypeURLs, 1);
100110
createOutputFile(resourceType, aggregatedConverter.getSchema(), outputDir);

bunsen/bunsen-avro/src/test/java/com/cerner/bunsen/avro/AvroConverterMergeTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ public void validateR4UsCoreResourceWithExtension() throws ProfileException, IOE
115115
Patient patient =
116116
(Patient)
117117
loadResource(fhirContext, "/r4-us-core-resources/patient_us_core.json", Patient.class);
118-
IndexedRecord avroRecord = patientConverter.resourceToAvro(patient);
119-
Patient patientDecoded = (Patient) patientConverter.avroToResource(avroRecord);
118+
IndexedRecord patientRecord = patientConverter.resourceToAvro(patient);
119+
Assert.assertNotNull(patientRecord);
120+
Patient patientDecoded = (Patient) patientConverter.avroToResource(patientRecord);
121+
Assert.assertNotNull(patientDecoded);
120122
Assert.assertTrue(
121123
patient.equalsDeep(
122124
(Base) TestUtil.encodeThenParse(patientDecoded, Patient.class, fhirContext)));
@@ -137,9 +139,11 @@ public void validateMergedStu3UsCoreResourceWithExtensions()
137139
fhirContext,
138140
"/stu3-us-core-resources/patient_us_core.json",
139141
org.hl7.fhir.dstu3.model.Patient.class);
140-
IndexedRecord avroRecord = patientConverter.resourceToAvro(patient);
142+
IndexedRecord patientRecord = patientConverter.resourceToAvro(patient);
143+
Assert.assertNotNull(patientRecord);
141144
org.hl7.fhir.dstu3.model.Patient patientDecoded =
142-
(org.hl7.fhir.dstu3.model.Patient) patientConverter.avroToResource(avroRecord);
145+
(org.hl7.fhir.dstu3.model.Patient) patientConverter.avroToResource(patientRecord);
146+
Assert.assertNotNull(patientDecoded);
143147
patientDecoded.setId(patient.getId());
144148
// TODO : The text field is not properly copied to the decoded object back, hence manually
145149
// copying it, check here for details https://github.com/google/fhir-data-pipes/issues/1014

bunsen/bunsen-avro/src/test/java/com/cerner/bunsen/avro/R4AvroConverterCustomProfileTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* This class tests the user-defined structure definitions which should also follow the HL7 FHIR
2525
* specifications. These are additional test cases beyond the regular US Core Profiles tests.
2626
*/
27+
28+
// Suppressing NullAway warnings for test code
29+
@SuppressWarnings("NullAway")
2730
public class R4AvroConverterCustomProfileTest {
2831

2932
private static final Patient testBunsenTestProfilePatient =

bunsen/bunsen-avro/src/test/java/com/cerner/bunsen/avro/R4AvroConverterUsCoreTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import org.junit.Test;
4747

4848
// TODO refactor the shared code with `Stu3AvroConverterUsCoreTest`.
49+
// Suppressing NullAway warnings for test code
50+
@SuppressWarnings("NullAway")
4951
public class R4AvroConverterUsCoreTest {
5052

5153
private static final Observation testObservation = TestData.newObservation();

bunsen/bunsen-avro/src/test/java/com/cerner/bunsen/avro/Stu3AvroConverterCustomProfileTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* <p>TODO: Refactor this and the R43AvroConverterCustomProfileTest.java to move the duplicate code
2525
* into a common class and add only relevant cases here
2626
*/
27+
// Suppressing NullAway warnings for test code
28+
@SuppressWarnings("NullAway")
2729
public class Stu3AvroConverterCustomProfileTest {
2830

2931
private static final Patient testBunsenTestProfilePatient =

bunsen/bunsen-avro/src/test/java/com/cerner/bunsen/avro/Stu3AvroConverterUsCoreTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import org.junit.BeforeClass;
4343
import org.junit.Test;
4444

45+
// Suppressing NullAway warnings for test code
46+
@SuppressWarnings("NullAway")
4547
public class Stu3AvroConverterUsCoreTest {
4648

4749
private static final Observation testObservation = TestData.newObservation();

0 commit comments

Comments
 (0)