Skip to content

Commit

Permalink
Merge branch 'main' into Fix/Close-custom-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Lentumunai-Mark authored Sep 12, 2024
2 parents 10fd2ea + 4d5248e commit 8c0cb27
Showing 1 changed file with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import org.smartregister.fhircore.engine.domain.model.Code
import org.smartregister.fhircore.engine.domain.model.DataQuery
import org.smartregister.fhircore.engine.domain.model.FhirResourceConfig
import org.smartregister.fhircore.engine.domain.model.FilterCriterionConfig
import org.smartregister.fhircore.engine.domain.model.NestedSearchConfig
import org.smartregister.fhircore.engine.domain.model.ResourceConfig
import org.smartregister.fhircore.engine.domain.model.ResourceData
import org.smartregister.fhircore.engine.domain.model.SnackBarMessageConfig
Expand Down Expand Up @@ -244,15 +245,19 @@ constructor(
baseResource.copy(
dataQueries = newBaseResourceDataQueries ?: baseResource.dataQueries,
nestedSearchResources =
baseResourceRegisterFilterField?.nestedSearchResources?.map { nestedSearchConfig ->
nestedSearchConfig.copy(
dataQueries =
createQueriesForRegisterFilter(
dataQueries = nestedSearchConfig.dataQueries,
qrItemMap = qrItemMap,
),
getValidatedNestedSearchResources(
baseResourceRegisterFilterField?.nestedSearchResources,
qrItemMap,
)
} ?: baseResource.nestedSearchResources,
?.map { nestedSearchConfig ->
nestedSearchConfig.copy(
dataQueries =
createQueriesForRegisterFilter(
dataQueries = nestedSearchConfig.dataQueries,
qrItemMap = qrItemMap,
),
)
} ?: baseResource.nestedSearchResources,
),
relatedResources = newRelatedResources,
)
Expand All @@ -264,6 +269,19 @@ constructor(
Timber.i("New ResourceConfig for register data filter: ${fhirResourceConfig.encodeJson()}")
}

private fun getValidatedNestedSearchResources(
nestedSearchResources: List<NestedSearchConfig>?,
qrItemMap: Map<String, QuestionnaireResponse.QuestionnaireResponseItemComponent>,
) =
nestedSearchResources?.filter { nestedSearchConfig ->
nestedSearchConfig.dataQueries?.any { dataQuery ->
dataQuery.filterCriteria.any { filterCriterionConfig ->
filterCriterionConfig.dataFilterLinkId.isNullOrEmpty() ||
qrItemMap[filterCriterionConfig.dataFilterLinkId]?.answer?.isNotEmpty() == true
}
} ?: false
}

private fun createFilterRelatedResources(
registerDataFilterFieldsMap: Map<String, RegisterFilterField>?,
relatedResources: List<ResourceConfig>,
Expand Down

0 comments on commit 8c0cb27

Please sign in to comment.