Skip to content

Commit

Permalink
Merge pull request #2823 from opensrp/2820-inject-libraryevaluator-wi…
Browse files Browse the repository at this point in the history
…th-provider

[MWCore] Inject Library with javax.inject.provider
  • Loading branch information
LZRS authored Oct 19, 2023
2 parents 303a210 + bd131ca commit 01cb077
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.res.stringResource
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import javax.inject.Provider
import kotlinx.coroutines.launch
import org.smartregister.fhircore.engine.R
import org.smartregister.fhircore.engine.auth.AccountAuthenticator
Expand All @@ -44,15 +45,15 @@ class AppSettingActivity : AppCompatActivity() {
@Inject lateinit var accountAuthenticator: AccountAuthenticator
@Inject lateinit var sharedPreferencesHelper: SharedPreferencesHelper
@Inject lateinit var dispatcherProvider: DispatcherProvider
@Inject lateinit var libraryEvaluator: LibraryEvaluator
@Inject lateinit var libraryEvaluatorProvider: Provider<LibraryEvaluator>
private val appSettingViewModel: AppSettingViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
super.onCreate(savedInstanceState)
val appSettingActivity = this@AppSettingActivity
setContent { AppTheme { LoaderDialog(dialogMessage = stringResource(R.string.initializing)) } }
lifecycleScope.launch(dispatcherProvider.io()) { libraryEvaluator.initialize() }
lifecycleScope.launch(dispatcherProvider.io()) { libraryEvaluatorProvider.get().initialize() }
val existingAppId =
sharedPreferencesHelper.read(SharedPreferenceKey.APP_ID.name, null)?.trimEnd()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ open class QuestionnaireActivity : BaseMultiLanguageActivity(), View.OnClickList
withContext(dispatcherProvider.io()) {
tracer.traceSuspend("Questionnaire.loadQuestionnaireAndConfig") {
loadQuestionnaireAndConfig(formName)
questionnaireViewModel.libraryEvaluator.initialize()
questionnaireViewModel.libraryEvaluatorProvider.get().initialize()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import java.util.Calendar
import java.util.Date
import java.util.UUID
import javax.inject.Inject
import javax.inject.Provider
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -108,7 +109,7 @@ constructor(
val transformSupportServices: TransformSupportServices,
val dispatcherProvider: DispatcherProvider,
val sharedPreferencesHelper: SharedPreferencesHelper,
val libraryEvaluator: LibraryEvaluator,
val libraryEvaluatorProvider: Provider<LibraryEvaluator>,
var tracer: PerformanceReporter
) : ViewModel() {
@Inject lateinit var fhirCarePlanGenerator: FhirCarePlanGenerator
Expand Down Expand Up @@ -416,7 +417,7 @@ constructor(
if (questionnaireResponse.hasSubject())
loadPatient(questionnaireResponse.subject.extractId())
else null
libraryEvaluator.runCqlLibrary(it, patient, data, defaultRepository)
libraryEvaluatorProvider.get().runCqlLibrary(it, patient, data, defaultRepository)
}
.forEach { output ->
if (output.isNotEmpty()) extractionProgressMessage.postValue(output.joinToString("\n"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import org.robolectric.Shadows.shadowOf
import org.robolectric.shadows.ShadowAlertDialog
import org.robolectric.util.ReflectionHelpers
import org.smartregister.fhircore.engine.R
import org.smartregister.fhircore.engine.cql.LibraryEvaluator
import org.smartregister.fhircore.engine.di.AnalyticsModule
import org.smartregister.fhircore.engine.di.CoreModule
import org.smartregister.fhircore.engine.robolectric.ActivityRobolectricTest
Expand Down Expand Up @@ -119,7 +120,7 @@ class QuestionnaireActivityTest : ActivityRobolectricTest() {
transformSupportServices = mockk(),
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = mockk(),
libraryEvaluator = mockk(),
libraryEvaluatorProvider = { mockk<LibraryEvaluator>() },
tracer = FakePerformanceReporter()
)
)
Expand All @@ -138,7 +139,7 @@ class QuestionnaireActivityTest : ActivityRobolectricTest() {
}

every { syncBroadcaster.runSync(any()) } just runs
coEvery { questionnaireViewModel.libraryEvaluator.initialize() } just runs
coEvery { questionnaireViewModel.libraryEvaluatorProvider.get().initialize() } just runs

val questionnaireConfig = QuestionnaireConfig("form", "title", "form-id")
coEvery { questionnaireViewModel.getQuestionnaireConfig(any(), any()) } returns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.hl7.fhir.r4.context.SimpleWorkerContext
import org.hl7.fhir.r4.model.Appointment
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.model.CanonicalType
import org.hl7.fhir.r4.model.CarePlan
Expand Down Expand Up @@ -175,7 +174,7 @@ class QuestionnaireViewModelTest : RobolectricTest() {
transformSupportServices = mockk(),
dispatcherProvider = defaultRepo.dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
libraryEvaluator = libraryEvaluator,
libraryEvaluatorProvider = { libraryEvaluator },
tracer = FakePerformanceReporter()
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.google.android.fhir.getLocalizedText
import com.google.android.fhir.logicalId
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import javax.inject.Provider
import kotlinx.coroutines.launch
import org.hl7.fhir.r4.model.Questionnaire
import org.hl7.fhir.r4.model.QuestionnaireResponse
Expand All @@ -47,7 +48,7 @@ constructor(
val patientRepository: PatientRepository,
val defaultRepository: DefaultRepository,
val patientItemMapper: PatientItemMapper,
val libraryEvaluator: LibraryEvaluator,
val libraryEvaluatorProvider: Provider<LibraryEvaluator>,
val fhirEngine: FhirEngine
) : ViewModel() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ListDataDetailViewModelTest : RobolectricTest() {
patientRepository = patientRepository,
defaultRepository = defaultRepository,
patientItemMapper = patientItemMapper,
libraryEvaluator = libraryEvaluator,
libraryEvaluatorProvider = { libraryEvaluator },
fhirEngine = fhirEngine
)
}
Expand Down

0 comments on commit 01cb077

Please sign in to comment.