Skip to content

Commit

Permalink
add multi text check
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan committed Feb 22, 2024
1 parent b5184d6 commit 9f11657
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9f11657

Please sign in to comment.