opensrp / fhircore

FHIR Core / OpenSRP 2 is a Kotlin application for delivering offline-capable, mobile-first healthcare project implementations from local community to national and international scale using FHIR and WHO Smart Guidelines on Android.
https://smartregister.org
Apache License 2.0
51 stars 41 forks source link

Notice D mADX - Mismatched Reports in Reporting module and crash when generating reports #867

Closed f-odhiambo closed 2 years ago

f-odhiambo commented 2 years ago

Describe the bug

  1. App crashing when you innovate measure reporting
  2. Report titles and data not matching selected report types on final reporting page

To Reproduce Steps to reproduce the behaviour:

  1. Go to the ANC app
  2. Click on Reports
  3. Add criteria for measure Reporting
  4. Click on Generate report

Expected behaviour

  1. All reports should have the correct Report title and be based on a select patient or all patients in ANC that match the filter criteria
  2. Smooth loading of measures and generation of reports based on filter/ selected criteria

Screenshots

Smartphone (please complete the following information):

Additional context See Logcat crush on when you load the app afresh and invoke measureReporting

2021-12-14 09:57:39.308 6602-6602/org.smartregister.fhircore.anc E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.smartregister.fhircore.anc, PID: 6602
    java.lang.RuntimeException: Unable to start activity ComponentInfo{org.smartregister.fhircore.anc/org.smartregister.fhircore.anc.ui.family.register.FamilyRegisterActivity}: kotlin.UninitializedPropertyAccessException: lateinit property appId has not been initialized
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: kotlin.UninitializedPropertyAccessException: lateinit property appId has not been initialized
        at org.smartregister.fhircore.engine.configuration.ConfigurationRegistry.getAppId(ConfigurationRegistry.kt:51)
        at org.smartregister.fhircore.engine.configuration.ConfigurationRegistry.workflowPointName(ConfigurationRegistry.kt:145)
        at org.smartregister.fhircore.engine.ui.register.RegisterViewModel.<init>(RegisterViewModel.kt:137)
        at org.smartregister.fhircore.anc.DaggerAncApplication_HiltComponents_SingletonC$ViewModelCImpl.registerViewModel(DaggerAncApplication_HiltComponents_SingletonC.java:977)
        at org.smartregister.fhircore.anc.DaggerAncApplication_HiltComponents_SingletonC$ViewModelCImpl.access$3500(DaggerAncApplication_HiltComponents_SingletonC.java:884)
        at org.smartregister.fhircore.anc.DaggerAncApplication_HiltComponents_SingletonC$ViewModelCImpl$SwitchingProvider.get(DaggerAncApplication_HiltComponents_SingletonC.java:1063)
        at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory$1.create(HiltViewModelFactory.java:100)
        at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:69)
        at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:84)
        at dagger.hilt.android.internal.lifecycle.HiltViewModelFactory.create(HiltViewModelFactory.java:109)
        at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187)
        at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)
        at androidx.lifecycle.ViewModelLazy.getValue(ViewModelProvider.kt:54)
        at androidx.lifecycle.ViewModelLazy.getValue(ViewModelProvider.kt:41)
        at org.smartregister.fhircore.engine.ui.register.BaseRegisterActivity.getRegisterViewModel(BaseRegisterActivity.kt:111)
        at org.smartregister.fhircore.engine.ui.register.BaseRegisterActivity.runSync(BaseRegisterActivity.kt:438)
        at org.smartregister.fhircore.engine.sync.SyncBroadcaster.registerSyncInitiator(SyncHandlers.kt:56)
        at org.smartregister.fhircore.engine.ui.register.BaseRegisterActivity.onCreate(BaseRegisterActivity.kt:137)
        at org.smartregister.fhircore.anc.ui.family.register.FamilyRegisterActivity.onCreate(FamilyRegisterActivity.kt:50)
        at android.app.Activity.performCreate(Activity.java:7802)
        at android.app.Activity.performCreate(Activity.java:7791)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7356) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 
f-odhiambo commented 2 years ago

Relatedly check on

  1. Failing CI test cases
  2. Failing Engines tests for Measure Evaluate - I think due to the OutOfMemoryIssue reason the MeasureEvaluate test failing
f-odhiambo commented 2 years ago

Mismatched Labels

  1. Selected 4th Indicator
  2. Report shows 1st Indicator title

f-odhiambo commented 2 years ago

Search ANC register not working

AbdulWahabMemon commented 2 years ago

@f-odhiambo, I tried to resolve crash issue, did some refactoring within ReportFilterPage, ReportActivity and ReportViewModel class, for moving functionalities' calls from UI to viewmodel but while debugging I found that fhirResourceDataSource.loadData(patientURL) is not working inside fetchCQLPatientData()
detailed message shared on slacked group.

and for Search ANC register not working search filter for picking patient in reports module, is the pending issue to resolve from my side, and for that I had to connect with @ellykits, but we couldn't sync those days, on 3rd December Elly mentioned he would try resolving that with ANC Test refactoring , I was expecting Elly to guide/hint me resolving that issue.

maimoonak commented 2 years ago

@Abdul Wahab Thanks for guiding on this.

Problem is we are loading data from server and the issue is that the flow is unable to find Patient with given id ...

see ReportHomeActivity.loadCQLMeasurePatientData where it fetches patientId from lateinit var.

and this is updated from ReportHomeActivity.generateMeasureReport which actually updates it as per filter selected

So there are two edge cases and one bug we need to handle 1- If user has not selected a patientId we should show Toast that a patient MUST be selected and prevent it from getting further 2- (Problem) it loads data from server and would for sure fail or give erroneous results on a patient and data which is not syced yet. We need to handle this and show error after Retrofit call fails 3- The patientId is var and is updated on each time we select filter. This is val selectedPatient by remember { mutableStateOf(viewModel.selectedPatientItem.value) } and we need to ensure that it can not work with previous selection by any means. It always updates the selected filter (I selected a patient in other report and then came back to failing report and clicked 'All' and it didnot crash.. so despite working the flow is giving wrong results)

AbdulWahabMemon commented 2 years ago

@maimoonak Among the cases you mentioned , point-1 and point-3 has been resolved with issue #898, linked PR #901

cc: @kwasim , @f-odhiambo , @kimigxfoxy

f-odhiambo commented 2 years ago

NOT valid anymore as we are moving to the API implementation