-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ANC module setup and Basic Flow (#504)
* ANC module setup and Basic Flow * Spotless apply * Delete QuestionnaireActivityTest.kt * Delete QuestionnaireViewModelTest.kt * Delete QuestionnaireUtilsTest.kt * Spotless Apply * QuestionnaireViewModelTest fix * Resolve feedback * Spotless Apply * Add theme and styles * ANC Register list view loaded * Update version number
- Loading branch information
Showing
44 changed files
with
1,376 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"registerTitle": "ANC", | ||
"registrationQuestionnaireIdentifier": "207", | ||
"registrationQuestionnaireTitle": "Add ANC Patient", | ||
"pregnancyLogQuestionnaireIdentifier": "???", | ||
"pregnancyLogQuestionnaireTitle": "Log Pregnancy", | ||
"deliveryLogQuestionnaireIdentifier": "???", | ||
"deliveryLogQuestionnaireTitle": "Log Delivery" | ||
} |
99 changes: 99 additions & 0 deletions
99
android/anc/src/main/java/org/smartregister/fhircore/anc/AncApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2021 Ona Systems, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.smartregister.fhircore.anc | ||
|
||
import android.app.Application | ||
import androidx.work.Constraints | ||
import com.google.android.fhir.FhirEngine | ||
import com.google.android.fhir.FhirEngineBuilder | ||
import com.google.android.fhir.sync.PeriodicSyncConfiguration | ||
import com.google.android.fhir.sync.RepeatInterval | ||
import com.google.android.fhir.sync.Sync | ||
import java.util.concurrent.TimeUnit | ||
import org.hl7.fhir.r4.model.ResourceType | ||
import org.smartregister.fhircore.engine.auth.AuthenticationService | ||
import org.smartregister.fhircore.engine.configuration.app.ApplicationConfiguration | ||
import org.smartregister.fhircore.engine.configuration.app.ConfigurableApplication | ||
import org.smartregister.fhircore.engine.configuration.app.applicationConfigurationOf | ||
import org.smartregister.fhircore.engine.util.SecureSharedPreference | ||
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper | ||
import timber.log.Timber | ||
|
||
class AncApplication : Application(), ConfigurableApplication { | ||
override val applicationConfiguration: ApplicationConfiguration by lazy { | ||
constructConfiguration() | ||
} | ||
|
||
override val authenticationService: AuthenticationService | ||
get() = AncAuthenticationService(applicationContext) | ||
|
||
override val fhirEngine: FhirEngine by lazy { constructFhirEngine() } | ||
|
||
override val secureSharedPreference: SecureSharedPreference | ||
get() = SecureSharedPreference(applicationContext) | ||
|
||
override val resourceSyncParams: Map<ResourceType, Map<String, String>> | ||
get() = | ||
mapOf( | ||
ResourceType.Patient to emptyMap(), | ||
ResourceType.Questionnaire to emptyMap(), | ||
ResourceType.StructureMap to mapOf(), | ||
ResourceType.RelatedPerson to mapOf() | ||
) | ||
|
||
private fun constructFhirEngine(): FhirEngine { | ||
Sync.periodicSync<AncFhirSyncWorker>( | ||
this, | ||
PeriodicSyncConfiguration( | ||
syncConstraints = Constraints.Builder().build(), | ||
repeat = RepeatInterval(interval = 1, timeUnit = TimeUnit.HOURS) | ||
) | ||
) | ||
|
||
return FhirEngineBuilder(this).build() | ||
} | ||
|
||
private fun constructConfiguration(): ApplicationConfiguration { | ||
return applicationConfigurationOf( | ||
oauthServerBaseUrl = BuildConfig.OAUTH_BASE_URL, | ||
fhirServerBaseUrl = BuildConfig.FHIR_BASE_URL, | ||
clientId = BuildConfig.OAUTH_CIENT_ID, | ||
clientSecret = BuildConfig.OAUTH_CLIENT_SECRET, | ||
languages = listOf("en", "sw") | ||
) | ||
} | ||
|
||
override fun configureApplication(applicationConfiguration: ApplicationConfiguration) { | ||
throw UnsupportedOperationException("Can not override existing configuration") | ||
} | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
SharedPreferencesHelper.init(this) | ||
ancApplication = this | ||
|
||
if (BuildConfig.DEBUG) { | ||
Timber.plant(Timber.DebugTree()) | ||
} | ||
} | ||
|
||
companion object { | ||
private lateinit var ancApplication: AncApplication | ||
|
||
fun getContext() = ancApplication | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
android/anc/src/main/java/org/smartregister/fhircore/anc/AncAuthAndroidService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2021 Ona Systems, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.smartregister.fhircore.anc | ||
|
||
import android.app.Service | ||
import android.content.Intent | ||
import android.os.IBinder | ||
import org.smartregister.fhircore.engine.auth.AccountAuthenticator | ||
|
||
class AncAuthAndroidService : Service() { | ||
|
||
private lateinit var authenticator: AccountAuthenticator | ||
|
||
override fun onCreate() { | ||
authenticator = AccountAuthenticator(this, AncAuthenticationService(this)) | ||
} | ||
|
||
override fun onBind(intent: Intent?): IBinder { | ||
return authenticator.iBinder | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
android/anc/src/main/java/org/smartregister/fhircore/anc/AncAuthenticationService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2021 Ona Systems, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.smartregister.fhircore.anc | ||
|
||
import android.content.Context | ||
import org.smartregister.fhircore.anc.ui.login.LoginActivity | ||
import org.smartregister.fhircore.engine.auth.AuthenticationService | ||
|
||
class AncAuthenticationService(override val context: Context) : AuthenticationService(context) { | ||
private val applicationConfiguration = AncApplication.getContext().applicationConfiguration | ||
|
||
override fun skipLogin() = BuildConfig.DEBUG && BuildConfig.SKIP_AUTH_CHECK | ||
|
||
override fun getLoginActivityClass() = LoginActivity::class.java | ||
|
||
override fun getAccountType() = context.getString(R.string.authenticator_account_type) | ||
|
||
override fun clientSecret() = applicationConfiguration.clientSecret | ||
|
||
override fun clientId() = applicationConfiguration.clientId | ||
|
||
override fun providerScope() = applicationConfiguration.scope | ||
|
||
override fun getApplicationConfigurations() = applicationConfiguration | ||
} |
34 changes: 34 additions & 0 deletions
34
android/anc/src/main/java/org/smartregister/fhircore/anc/AncFhirSyncWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2021 Ona Systems, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.smartregister.fhircore.anc | ||
|
||
import android.content.Context | ||
import androidx.work.WorkerParameters | ||
import com.google.android.fhir.sync.FhirSyncWorker | ||
import org.smartregister.fhircore.engine.util.extension.buildDatasource | ||
|
||
class AncFhirSyncWorker(appContext: Context, workerParams: WorkerParameters) : | ||
FhirSyncWorker(appContext, workerParams) { | ||
|
||
override fun getSyncData() = AncApplication.getContext().resourceSyncParams | ||
|
||
override fun getDataSource() = | ||
AncApplication.getContext() | ||
.buildDatasource(AncApplication.getContext().applicationConfiguration) | ||
|
||
override fun getFhirEngine() = AncApplication.getContext().fhirEngine | ||
} |
48 changes: 48 additions & 0 deletions
48
...id/anc/src/main/java/org/smartregister/fhircore/anc/data/AncPatientPaginatedDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2021 Ona Systems, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.smartregister.fhircore.anc.data | ||
|
||
import com.google.android.fhir.FhirEngine | ||
import com.google.android.fhir.search.Search | ||
import com.google.android.fhir.search.StringFilterModifier | ||
import org.hl7.fhir.r4.model.Patient | ||
import org.smartregister.fhircore.anc.data.model.AncPatientItem | ||
import org.smartregister.fhircore.engine.data.domain.util.DomainMapper | ||
import org.smartregister.fhircore.engine.data.domain.util.PaginatedDataSource | ||
|
||
class AncPatientPaginatedDataSource( | ||
val fhirEngine: FhirEngine, | ||
domainMapper: DomainMapper<Patient, AncPatientItem> | ||
) : PaginatedDataSource<Patient, AncPatientItem>(AncPatientRepository(fhirEngine, domainMapper)) { | ||
|
||
private var query: String = "" | ||
|
||
override suspend fun loadData(pageNumber: Int): List<AncPatientItem> { | ||
return registerRepository.loadData( | ||
pageNumber = pageNumber, | ||
query = query, | ||
primaryFilterCallback = { search: Search -> search.filter(Patient.ACTIVE, true) }, | ||
secondaryFilterCallbacks = | ||
arrayOf({ filterQuery: String, search: Search -> | ||
search.filter(Patient.NAME) { | ||
modifier = StringFilterModifier.CONTAINS | ||
value = filterQuery.trim() | ||
} | ||
}) | ||
) | ||
} | ||
} |
Oops, something went wrong.