Skip to content

Commit

Permalink
[MWCore] Data Clerk fixes (#2654)
Browse files Browse the repository at this point in the history
* updated pagination

* add search

* update edit profile

* catch generic errors

* update

* update
  • Loading branch information
sevenreup authored Aug 14, 2023
1 parent 5a62272 commit 6080e14
Show file tree
Hide file tree
Showing 15 changed files with 432 additions and 35 deletions.
6 changes: 3 additions & 3 deletions android/dataclerk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ android {
applicationId "org.dtree.fhircore.dataclerk"
minSdkVersion sdk_versions.min_sdk
targetSdkVersion sdk_versions.target_sdk
versionCode 3
versionName "1.0.0"
versionCode 4
versionName "1.0.1"
multiDexEnabled true

buildConfigField("boolean", 'SKIP_AUTH_CHECK', "false")
Expand Down Expand Up @@ -154,7 +154,7 @@ dependencies {
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
implementation "androidx.paging:paging-compose:3.2.0-rc01"
implementation "androidx.paging:paging-compose:3.2.0"

//Hilt - Dependency Injection
implementation "com.google.dagger:hilt-android:$hiltVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.BugReport
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material.icons.filled.Search
import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down Expand Up @@ -62,7 +63,8 @@ fun HomeScreen(
appMainViewModel: AppMainViewModel,
homeViewModel: HomeViewModel = hiltViewModel(),
sync: () -> Unit,
openPatient: (PatientItem) -> Unit
search: () -> Unit,
openPatient: (PatientItem) -> Unit,
) {
val appState by appMainViewModel.appMainUiState
val context = LocalContext.current
Expand Down Expand Up @@ -121,6 +123,12 @@ fun HomeScreen(
contentDescription = "Debug",
)
}
IconButton(onClick = { search() }) {
Icon(
imageVector = Icons.Default.Search,
contentDescription = "Search",
)
}
}
)
SyncStatusBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ fun PatientList(viewModel: HomeViewModel, navigate: (PatientItem) -> Unit) {

LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(8.dp)
contentPadding = PaddingValues(8.dp),
) {
items(items = removeDuplicates(patients.itemSnapshotList.items)) { patient ->
items(items = patients.itemSnapshotList.items) { patient ->
PatientItemCard(patient, onClick = { navigate(patient) })
}
when (val state = patients.loadState.refresh) { // FIRST LOAD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.paging.PagingSource
import androidx.paging.PagingState
import org.dtree.fhircore.dataclerk.ui.main.AppDataStore
import org.dtree.fhircore.dataclerk.ui.main.PatientItem
import timber.log.Timber

class PatientPagingSource(private val dataStore: AppDataStore) : PagingSource<Int, PatientItem>() {
override fun getRefreshKey(state: PagingState<Int, PatientItem>): Int? {
Expand All @@ -33,11 +34,12 @@ class PatientPagingSource(private val dataStore: AppDataStore) : PagingSource<In
return try {
val page = params.key ?: 1
val response = dataStore.loadPatients(page = page)

val nextPage = if (response.isEmpty()) null else page.plus(1)
Timber.e("next page is $nextPage")
LoadResult.Page(
data = response,
prevKey = null,
nextKey = if (response.isEmpty()) null else page.plus(1),
nextKey = nextPage,
)
} catch (e: Exception) {
LoadResult.Error(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import ca.uhn.fhir.context.FhirVersionEnum
import com.google.android.fhir.FhirEngine
import com.google.android.fhir.get
import com.google.android.fhir.logicalId
import com.google.android.fhir.search.Operation
import com.google.android.fhir.search.Order
import com.google.android.fhir.search.Search
import com.google.android.fhir.search.StringFilterModifier
import com.google.android.fhir.search.search
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.Date
import javax.inject.Inject
import org.hl7.fhir.r4.model.Identifier
import org.hl7.fhir.r4.model.Patient
import org.hl7.fhir.r4.model.Reference
import org.hl7.fhir.r4.model.Resource
Expand Down Expand Up @@ -69,7 +72,7 @@ constructor(
from = (page - 1) * 20
}
.map { inputModel ->
Timber.e(jsonParser.encodeResourceToString(inputModel))
// Timber.e(jsonParser.encodeResourceToString(inputModel))
inputModel.toPatientItem(getApplicationConfiguration())
}
}
Expand All @@ -88,6 +91,26 @@ constructor(
Search(ResourceType.Patient).apply { filter(Patient.ACTIVE, { value = of(true) }) }
)
}

suspend fun search(text: String): List<PatientItem> {
return fhirEngine
.search<Patient> {
filter(
Patient.NAME,
{
modifier = StringFilterModifier.CONTAINS
value = text
}
)
filter(Patient.IDENTIFIER, { value = of(Identifier().apply { value = text }) })
operation = Operation.OR
sort(Patient.NAME, Order.ASCENDING)
}
.map { inputModel ->
// Timber.e(jsonParser.encodeResourceToString(inputModel))
inputModel.toPatientItem(getApplicationConfiguration())
}
}
}

data class PatientItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.navigation.navArgument
import org.dtree.fhircore.dataclerk.ui.home.HomeScreen
import org.dtree.fhircore.dataclerk.ui.home.HomeViewModel
import org.dtree.fhircore.dataclerk.ui.patient.PatientScreen
import org.dtree.fhircore.dataclerk.ui.search.SearchScreen

@Composable
fun AppScreen(
Expand All @@ -36,13 +37,18 @@ fun AppScreen(
val navController = rememberNavController()
NavHost(navController = navController, startDestination = "home") {
composable("home") {
HomeScreen(appMainViewModel = appMainViewModel, homeViewModel = homeViewModel, sync = sync) {
navController.navigate("patient/${it.resourceId}")
}
HomeScreen(
appMainViewModel = appMainViewModel,
homeViewModel = homeViewModel,
sync = sync,
search = { navController.navigate("search") }
) { navController.navigate("patient/${it.resourceId}") }
}
composable(
"patient/{patientId}",
arguments = listOf(navArgument("patientId") { type = NavType.StringType })
) { PatientScreen(navController, appMainViewModel = appMainViewModel) }

composable("search") { SearchScreen(navHostController = navController) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fun PatientScreen(
patientViewModel: PatientViewModel = hiltViewModel()
) {
val state by patientViewModel.screenState.collectAsState()
val list by patientViewModel.resourceMapStatus

val syncState by appMainViewModel.syncSharedFlow.collectAsState(initial = null)
val refreshKey by appMainViewModel.refreshHash

Expand Down Expand Up @@ -98,28 +98,37 @@ fun PatientScreen(
}
) { paddingValues ->
Column(Modifier.padding(paddingValues).fillMaxSize()) {
val context = LocalContext.current
if (state is PatientDetailScreenState.Success) {
LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(8.dp),
modifier = Modifier.fillMaxSize()
) {
items((state as PatientDetailScreenState.Success).detailsData) { data ->
when (data) {
is PatientDetailHeader -> PatientDetailsCardViewBinding(data)
is PatientDetailProperty -> PatientListItemViewBinding(data)
is PatientDetailOverview ->
PatientDetailsHeaderBinding(data) { patientViewModel.editPatient(context) }
is PatientReferenceProperty ->
list[data.patientProperty.value]?.let { PatientReferencePropertyBinding(data, it) }
}
}
PatientDetailsTab(state, patientViewModel)
}
}
}

@Composable
fun PatientDetailsTab(
state: PatientDetailScreenState,
patientViewModel: PatientViewModel = hiltViewModel()
) {
val list by patientViewModel.resourceMapStatus
val context = LocalContext.current
if (state is PatientDetailScreenState.Success) {
LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(8.dp),
modifier = Modifier.fillMaxSize()
) {
items(state.detailsData) { data ->
when (data) {
is PatientDetailHeader -> PatientDetailsCardViewBinding(data)
is PatientDetailProperty -> PatientListItemViewBinding(data)
is PatientDetailOverview ->
PatientDetailsHeaderBinding(data) { patientViewModel.editPatient(context) }
is PatientReferenceProperty ->
list[data.patientProperty.value]?.let { PatientReferencePropertyBinding(data, it) }
}
} else {
CircularProgressIndicator()
}
}
} else {
CircularProgressIndicator()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ constructor(
}

companion object {
const val EDIT_PROFILE_FORM = "edit-patient-profile"
const val EDIT_PROFILE_FORM = "patient-edit-profile"
}
}

Expand Down
Loading

0 comments on commit 6080e14

Please sign in to comment.