diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt index 391edaa178..3e5265ac97 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/questionnaire/QuestionnaireViewModel.kt @@ -756,16 +756,18 @@ constructor( questionnaireConfig: QuestionnaireConfig, ) { questionnaireConfig.planDefinitions?.forEach { planId -> - kotlin - .runCatching { - fhirCarePlanGenerator.generateOrUpdateCarePlan( - planDefinitionId = planId, - subject = subject, - data = bundle, - generateCarePlanWithWorkflowApi = questionnaireConfig.generateCarePlanWithWorkflowApi, - ) - } - .onFailure { Timber.e(it) } + if (planId.isNotEmpty()) { + kotlin + .runCatching { + fhirCarePlanGenerator.generateOrUpdateCarePlan( + planDefinitionId = planId, + subject = subject, + data = bundle, + generateCarePlanWithWorkflowApi = questionnaireConfig.generateCarePlanWithWorkflowApi, + ) + } + .onFailure { Timber.e(it) } + } } }