From 9f1165766c759e4794383780d310b28f6c52a93a Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 22 Feb 2024 12:51:47 +0100 Subject: [PATCH] add multi text check Signed-off-by: Pablo --- .../java/org/dhis2/commons/bindings/ValueExtensions.kt | 7 +++---- .../java/org/dhis2/form/ui/FieldViewModelFactoryImpl.kt | 8 +++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt b/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt index 2c067401b4..fff9e1d235 100644 --- a/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt +++ b/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt @@ -22,7 +22,7 @@ fun TrackedEntityAttributeValue.userFriendlyValue(d2: D2): String? { } if (check(d2, attribute.valueType(), attribute.optionSet()?.uid(), value()!!)) { - attribute.optionSet()?.let { + attribute.optionSet()?.takeIf { attribute.valueType() != ValueType.MULTI_TEXT }?.let { return checkOptionSetValue(d2, it.uid(), value()!!) } ?: return checkValueTypeValue(d2, attribute.valueType(), value()!!) } else { @@ -45,7 +45,7 @@ fun TrackedEntityDataValue?.userFriendlyValue(d2: D2): String? { if (dataElement == null) { return null } else if (check(d2, dataElement.valueType(), dataElement.optionSet()?.uid(), value()!!)) { - dataElement.optionSet()?.let { + dataElement.optionSet()?.takeIf { dataElement.valueType() != ValueType.MULTI_TEXT }?.let { return checkOptionSetValue(d2, it.uid(), value()!!) } ?: return checkValueTypeValue(d2, dataElement.valueType(), value()!!) } else { @@ -191,14 +191,13 @@ fun TrackedEntityDataValueObjectRepository.blockingGetValueCheck( private fun check(d2: D2, valueType: ValueType?, optionSetUid: String?, value: String): Boolean { return when { - optionSetUid != null -> { + valueType!= ValueType.MULTI_TEXT && optionSetUid != null -> { val optionByCodeExist = d2.optionModule().options().byOptionSetUid().eq(optionSetUid) .byCode().eq(value).one().blockingExists() val optionByNameExist = d2.optionModule().options().byOptionSetUid().eq(optionSetUid) .byDisplayName().eq(value).one().blockingExists() optionByCodeExist || optionByNameExist } - valueType != null -> { if (valueType.isNumeric) { try { diff --git a/form/src/main/java/org/dhis2/form/ui/FieldViewModelFactoryImpl.kt b/form/src/main/java/org/dhis2/form/ui/FieldViewModelFactoryImpl.kt index 83eeb7daad..2ebd582d3d 100644 --- a/form/src/main/java/org/dhis2/form/ui/FieldViewModelFactoryImpl.kt +++ b/form/src/main/java/org/dhis2/form/ui/FieldViewModelFactoryImpl.kt @@ -79,9 +79,9 @@ class FieldViewModelFactoryImpl( style = uiStyleProvider.provideStyle(valueType), hint = hintProvider.provideDateHint(valueType), description = description, - valueType = valueType, + valueType = if (optionSet != null && valueType == ValueType.TEXT) ValueType.MULTI_TEXT else valueType, legend = legendValueProvider.provideLegendValue(id, value), - optionSet = optionSet, + optionSet = if(valueType == ValueType.MULTI_TEXT) null else optionSet, allowFutureDates = allowFutureDates, uiEventFactory = UiEventFactoryImpl( id, @@ -113,10 +113,12 @@ class FieldViewModelFactoryImpl( optionSetConfiguration: OptionSetConfiguration?, ): FieldUiModel { isNull(trackedEntityAttribute.valueType(), "type must be supplied") + val optionSet = trackedEntityAttribute.optionSet() + val valueType = trackedEntityAttribute.valueType() return create( id = trackedEntityAttribute.uid(), label = trackedEntityAttribute.displayFormName() ?: "", - valueType = trackedEntityAttribute.valueType()!!, + valueType = if (optionSet != null && valueType == ValueType.TEXT) ValueType.MULTI_TEXT else valueType!!, mandatory = programTrackedEntityAttribute?.mandatory() == true, optionSet = trackedEntityAttribute.optionSet()?.uid(), value = value,