Skip to content

Commit

Permalink
Fetch Practioner Location Id using Rules on the Configs from the Shar…
Browse files Browse the repository at this point in the history
…edPreferences (#3281)

* Load practitioner location Id from the shared prefs via rules engine service

* Add unit test for writing practitioner location id to shared preferences

* Run spotlessApply

* Update unit test

* Run spotless Apply
  • Loading branch information
Rkareko authored May 24, 2024
1 parent 2c7808f commit e88724e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ constructor(
SharedPreferenceKey.PRACTITIONER_LOCATION.name,
"",
)
SharedPreferenceKey.PRACTITIONER_LOCATION_ID ->
configurationRegistry.sharedPreferencesHelper.read(
SharedPreferenceKey.PRACTITIONER_LOCATION_ID.name,
"",
)
else -> ""
}
} catch (exception: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum class SharedPreferenceKey {
PRACTITIONER_DETAILS,
PRACTITIONER_LOCATION_HIERARCHIES,
PRACTITIONER_LOCATION,
PRACTITIONER_LOCATION_ID,
REMOTE_SYNC_RESOURCES,
LOGIN_CREDENTIAL_KEY,
LOGIN_PIN_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,23 @@ class RulesFactoryTest : RobolectricTest() {
@Test
fun testExtractSharedPrefValuesReturnsPractitionerLocation() {
val sharedPreferenceKey = "PRACTITIONER_LOCATION"
val expectedValue = "1234"
val expectedValue = "Demo Facility"
every {
configurationRegistry.sharedPreferencesHelper.read(
sharedPreferenceKey,
"",
)
} returns expectedValue
val result = rulesEngineService.extractPractitionerInfoFromSharedPrefs(sharedPreferenceKey)

verify { configurationRegistry.sharedPreferencesHelper.read(sharedPreferenceKey, "") }
Assert.assertEquals(expectedValue, result)
}

@Test
fun testExtractSharedPrefValuesReturnsPractitionerLocationId() {
val sharedPreferenceKey = "PRACTITIONER_LOCATION_ID"
val expectedValue = "ABCD1234"
every {
configurationRegistry.sharedPreferencesHelper.read(
sharedPreferenceKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ constructor(
)
}

private fun writePractitionerDetailsToShredPref(
fun writePractitionerDetailsToShredPref(
careTeam: List<String>,
organization: List<String>,
location: List<String>,
Expand Down Expand Up @@ -452,6 +452,10 @@ constructor(
key = SharedPreferenceKey.ORGANIZATION.name,
value = organization.joinToString(separator = ""),
)
sharedPreferences.write(
key = SharedPreferenceKey.PRACTITIONER_LOCATION_ID.name,
value = locations.joinToString(separator = ""),
)
}

fun downloadNowWorkflowConfigs(isInitialLogin: Boolean = true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import io.mockk.verify
import java.net.SocketTimeoutException
import java.net.UnknownHostException
import javax.inject.Inject
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import okhttp3.internal.http.RealResponseBody
Expand Down Expand Up @@ -638,6 +639,25 @@ internal class LoginViewModelTest : RobolectricTest() {
verify { workManager.enqueue(any<OneTimeWorkRequest>()) }
}

@Test
fun testWritePractitionerDetailsToShredPrefSavesPractitionerLocationId() {
val locationId = "ABCD123"
loginViewModel.writePractitionerDetailsToShredPref(
careTeams = listOf(""),
careTeam = listOf(""),
organization = listOf(""),
organizations = listOf(""),
location = listOf(""),
locations = listOf(locationId),
fhirPractitionerDetails = PractitionerDetails(),
locationHierarchies = listOf(LocationHierarchy()),
)
assertEquals(
locationId,
sharedPreferencesHelper.read(SharedPreferenceKey.PRACTITIONER_LOCATION_ID.name),
)
}

private fun updateCredentials() {
loginViewModel.run {
onUsernameUpdated(thisUsername)
Expand Down

0 comments on commit e88724e

Please sign in to comment.