forked from opensrp/fhircore
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Init stats fetch * update UI * Update build.gradle.kts * Update build.gradle.kts * Update build.gradle.kts Update build.gradle.kts * Update report UI * spotless * spotless * Make collapsible
- Loading branch information
Showing
17 changed files
with
585 additions
and
13 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
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
36 changes: 36 additions & 0 deletions
36
...in/java/org/smartregister/fhircore/engine/data/remote/fhir/helper/FhirHelperRepository.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,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") | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
.../main/java/org/smartregister/fhircore/engine/data/remote/fhir/helper/FhirHelperService.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,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> | ||
} |
36 changes: 36 additions & 0 deletions
36
...ain/java/org/smartregister/fhircore/engine/data/remote/model/helper/FacilityResultData.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,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) |
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
62 changes: 62 additions & 0 deletions
62
...ne/src/main/java/org/smartregister/fhircore/engine/ui/components/DataFetchingContainer.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,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", | ||
) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.