Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add facility report #105

Merged
merged 10 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val fhirAuthArray = arrayOf(
"FHIR_BASE_URL", "OAUTH_BASE_URL", "OAUTH_CIENT_ID", "OAUTH_CLIENT_SECRET", "OAUTH_SCOPE", "APP_ID"
"FHIR_BASE_URL", "OAUTH_BASE_URL", "OAUTH_CIENT_ID", "OAUTH_CLIENT_SECRET", "OAUTH_SCOPE", "APP_ID", "FHIR_HELPER_SERVICE"
)
//KEYSTORE CREDENTIALS
val keystoreAuthArray = arrayOf(
Expand Down
5 changes: 5 additions & 0 deletions android/dataclerk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ android {
""""${project.extra["OAUTH_CLIENT_SECRET"]}"""",
)
buildConfigField("String", "OAUTH_SCOPE", """"${project.extra["OAUTH_SCOPE"]}"""")
buildConfigField(
"String",
"FHIR_HELPER_SERVICE",
""""${project.extra["FHIR_HELPER_SERVICE"]}"""",
)

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables { useSupportLibrary = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class DataClerkConfigService @Inject constructor(@ApplicationContext val context
clientId = BuildConfig.OAUTH_CIENT_ID,
clientSecret = BuildConfig.OAUTH_CLIENT_SECRET,
accountType = BuildConfig.APPLICATION_ID,
fhirHelperServiceBaseUrl = BuildConfig.FHIR_HELPER_SERVICE,
)

override fun defineResourceTags() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ data class AuthConfiguration(
var fhirServerBaseUrl: String,
var clientId: String,
var clientSecret: String,
var fhirHelperServiceBaseUrl: String,
var accountType: String,
var scope: String = "openid",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.engine.data.remote.fhir.helper

import javax.inject.Inject
import org.smartregister.fhircore.engine.data.remote.model.helper.FacilityResultData
import timber.log.Timber

class FhirHelperRepository @Inject constructor(val fhirHelperService: FhirHelperService) {
suspend fun getFacilityStats(id: String): FacilityResultData {
try {
val response = fhirHelperService.fetchDailyFacilityStats(id)
if (!response.isSuccessful) {
throw Exception("Failed to fetch stats")
}
return response.body() ?: throw Exception("Failed to fetch stats")
} catch (e: Exception) {
Timber.e(e)
throw Exception("Failed to fetch stats")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.engine.data.remote.fhir.helper

import org.smartregister.fhircore.engine.data.remote.model.helper.FacilityResultData
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Path

interface FhirHelperService {
@GET("/stats/facility/{id}")
suspend fun fetchDailyFacilityStats(@Path("id") id: String): Response<FacilityResultData>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.engine.data.remote.model.helper

import java.time.LocalDate
import java.time.LocalDateTime

data class FacilityResultData(
val groups: List<GroupedSummaryItem>,
val date: LocalDate,
val generatedDate: LocalDateTime,
)

data class GroupedSummaryItem(
val groupKey: String,
val groupTitle: String,
val summaries: List<SummaryItem>,
val order: Int,
val startCollapsed: Boolean = false,
)

data class SummaryItem(val name: String, val value: Int)
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.TimeZone
import java.util.concurrent.TimeUnit
import javax.inject.Singleton
Expand All @@ -39,9 +41,12 @@ import okhttp3.logging.HttpLoggingInterceptor
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.data.remote.auth.KeycloakService
import org.smartregister.fhircore.engine.data.remote.auth.OAuthService
import org.smartregister.fhircore.engine.data.remote.fhir.helper.FhirHelperService
import org.smartregister.fhircore.engine.data.remote.fhir.resource.FhirConverterFactory
import org.smartregister.fhircore.engine.data.remote.fhir.resource.FhirResourceService
import org.smartregister.fhircore.engine.data.remote.shared.TokenAuthenticator
import org.smartregister.fhircore.engine.util.LocalDateAdapter
import org.smartregister.fhircore.engine.util.LocalDateTimeTypeAdapter
import org.smartregister.fhircore.engine.util.TimeZoneTypeAdapter
import org.smartregister.fhircore.engine.util.extension.getCustomJsonParser
import retrofit2.Retrofit
Expand Down Expand Up @@ -100,6 +105,8 @@ class NetworkModule {
GsonBuilder()
.setLenient()
.registerTypeAdapter(TimeZone::class.java, TimeZoneTypeAdapter().nullSafe())
.registerTypeAdapter(LocalDate::class.java, LocalDateAdapter())
.registerTypeAdapter(LocalDateTime::class.java, LocalDateTimeTypeAdapter())
.create()

@Provides fun provideParser(): IParser = FhirContext.forR4Cached().getCustomJsonParser()
Expand Down Expand Up @@ -168,6 +175,22 @@ class NetworkModule {
fun provideFhirResourceService(@RegularRetrofit retrofit: Retrofit): FhirResourceService =
retrofit.create(FhirResourceService::class.java)

@Provides
fun provideFhirHelperService(
@WithAuthorizationOkHttpClientQualifier okHttpClient: OkHttpClient,
configService: ConfigService,
gson: Gson,
parser: IParser,
): FhirHelperService {
val retrofit =
Retrofit.Builder()
.baseUrl(configService.provideAuthConfiguration().fhirHelperServiceBaseUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
return retrofit.create(FhirHelperService::class.java)
}

@Provides
fun providesGenericFhirClient(
@WithAuthorizationOkHttpClientQualifier okHttpClient: OkHttpClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.engine.ui.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import org.smartregister.fhircore.engine.domain.util.DataLoadState

@Composable
fun <T> DataFetchingContainer(
state: DataLoadState<T>,
modifier: Modifier = Modifier,
retry: () -> Unit,
success: @Composable (state: DataLoadState.Success<T>) -> Unit,
) {
Column(
modifier,
) {
when (state) {
is DataLoadState.Error ->
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxSize(),
) {
ErrorMessage(
message = "Something went wrong while fetching data..",
onClickRetry = retry,
)
}
is DataLoadState.Success -> success(state)
else ->
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
modifier = Modifier.fillMaxSize(),
) {
CircularProgressBar(
text = "Fetching data",
)
}
}
}
}
Loading
Loading