Skip to content

Commit

Permalink
Fix ClassCastException when value is of type DvText (#644)
Browse files Browse the repository at this point in the history
Use instanceof to check types before casting them.
Also add a method to handle DvText
  • Loading branch information
askask authored Nov 19, 2024
1 parent 2833e64 commit 4332a48
Showing 1 changed file with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.nedap.archie.rm.RMObject;
import com.nedap.archie.rm.datavalues.DvBoolean;
import com.nedap.archie.rm.datavalues.DvCodedText;
import com.nedap.archie.rm.datavalues.DvText;
import com.nedap.archie.rm.datavalues.SingleValuedDataValue;
import com.nedap.archie.rm.datavalues.quantity.DvCount;
import com.nedap.archie.rm.datavalues.quantity.DvOrdinal;
Expand Down Expand Up @@ -141,27 +142,29 @@ private ParameterOptionsDto getParameters(String aqlPath, String archetypeId, St
(SingleValuedDataValue<?>)
buildAqlObjectMapper().readValue(rowString, RMObject.class);
if (Objects.nonNull(element.getValue())) {
if (element.getValue().getClass().isAssignableFrom(DvCodedText.class)) {
if (element.getValue() instanceof DvCodedText) {
convertDvCodedText((DvCodedText) element.getValue(), parameterOptions, postfix);
} else if (element.getValue().getClass().isAssignableFrom(DvQuantity.class)) {
} else if (element.getValue() instanceof DvText) {
convertDvText((DvText) element.getValue(), parameterOptions, postfix);
} else if (element.getValue() instanceof DvQuantity) {
convertDvQuantity((DvQuantity) element.getValue(), parameterOptions, postfix);
} else if (element.getValue().getClass().isAssignableFrom(DvOrdinal.class)) {
} else if (element.getValue() instanceof DvOrdinal) {
convertDvOrdinal((DvOrdinal) element.getValue(), parameterOptions, postfix);
} else if (element.getValue().getClass().isAssignableFrom(DvBoolean.class)) {
} else if (element.getValue() instanceof DvBoolean) {
convertDvBoolean(parameterOptions);
} else if (element.getValue().getClass().isAssignableFrom(DvDate.class)) {
} else if (element.getValue() instanceof DvDate) {
convertDvDate(parameterOptions);
} else if (element.getValue().getClass().isAssignableFrom(DvDateTime.class)) {
} else if (element.getValue() instanceof DvDateTime) {
convertDvDateTime(parameterOptions);
} else if (element.getValue().getClass().isAssignableFrom(DvTime.class)) {
} else if (element.getValue() instanceof DvTime) {
convertTime(parameterOptions);
} else if (element.getClass().isAssignableFrom(DvDateTime.class)) {
} else if (element instanceof DvDateTime) {
// workaround for openEHR-EHR-OBSERVATION.blood_pressure.v2 and aqlPath:
///data[at0001]/events[at0006]/time/value
convertDvDateTime(parameterOptions);
} else if (element.getValue().getClass().isAssignableFrom(DvCount.class)) {
} else if (element.getValue() instanceof DvCount) {
parameterOptions.setType("DV_COUNT");
} else if (element.getValue().getClass().isAssignableFrom(DvDuration.class)) {
} else if (element.getValue() instanceof DvDuration) {
parameterOptions.setType("DV_DURATION");
}
}
Expand Down Expand Up @@ -231,6 +234,14 @@ private void convertDvCodedText(DvCodedText data, ParameterOptionsDto dto, Strin
dto.getOptions().put(data.getDefiningCode().getCodeString(), data.getValue());
}

private void convertDvText(DvText data, ParameterOptionsDto dto, String postfix) {
if (VALUE_MAGNITUDE.equals(postfix)) {
return;
}
dto.setType("DV_TEXT");
dto.getOptions().put(data.getValue(), data.getValue());
}

private void convertDvQuantity(DvQuantity data, ParameterOptionsDto dto, String postfix) {
if (VALUE_DEFINING_CODE.equals(postfix)) {
return;
Expand Down

0 comments on commit 4332a48

Please sign in to comment.