From 53c5804c5c2bbdd2ab040c743e1104528fb535ba Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 4 Nov 2024 12:00:00 +0100 Subject: [PATCH] Fix ClassCastException when value is of type DvText Use instanceof to check types before casting them. Also add a method to handle DvText --- .../service/ehrbase/ParameterService.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/highmed/numportal/service/ehrbase/ParameterService.java b/src/main/java/org/highmed/numportal/service/ehrbase/ParameterService.java index 939a473e..bd1cc3ab 100644 --- a/src/main/java/org/highmed/numportal/service/ehrbase/ParameterService.java +++ b/src/main/java/org/highmed/numportal/service/ehrbase/ParameterService.java @@ -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; @@ -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"); } } @@ -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;