Skip to content

Commit

Permalink
fix: to exclude 2 value fields that are not real value[x] fields (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
celinepelletier authored Oct 3, 2024
1 parent c680776 commit 780c685
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/bio/ferlab/fhir/converter/FhirAvroConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Property> 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.
Expand Down

0 comments on commit 780c685

Please sign in to comment.