From 780c6852fae5391d1f695d6a0eea1b64cb51faf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9line=20Pelletier?= <82821620+celinepelletier@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:52:13 -0400 Subject: [PATCH] fix: to exclude 2 value fields that are not real value[x] fields (#29) --- .../bio/ferlab/fhir/converter/FhirAvroConverter.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/bio/ferlab/fhir/converter/FhirAvroConverter.java b/src/main/java/bio/ferlab/fhir/converter/FhirAvroConverter.java index c09d8f3..944ef0f 100644 --- a/src/main/java/bio/ferlab/fhir/converter/FhirAvroConverter.java +++ b/src/main/java/bio/ferlab/fhir/converter/FhirAvroConverter.java @@ -11,10 +11,7 @@ import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericRecordBuilder; import org.apache.commons.text.WordUtils; -import org.hl7.fhir.r4.model.Base; -import org.hl7.fhir.r4.model.BaseResource; -import org.hl7.fhir.r4.model.Extension; -import org.hl7.fhir.r4.model.Property; +import org.hl7.fhir.r4.model.*; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; @@ -141,9 +138,13 @@ private static ByteBuffer bytesForString(String string) { return ByteBuffer.wrap(string.getBytes(StandardCharsets.UTF_8)); } + private static Boolean isRealValueXField(Base base, String fieldName) { + return !(base instanceof Device.DevicePropertyComponent) || (!fieldName.equals("valueQuantity") && !fieldName.equals("valueCode")); + } + private static Optional getProperty(Base base, Schema.Field field) { // Support value[x] notation. - if (Pattern.compile("value[a-zA-Z].*").matcher(field.name()).matches()) { + if (Pattern.compile("value[a-zA-Z].*").matcher(field.name()).matches() && isRealValueXField(base, field.name())) { Property property = base.getNamedProperty(Constant.VALUE); if (property != null && property.hasValues()) { // Try to find the valid corresponding value[x] by comparing the FhirType and the field name.