Skip to content

Commit

Permalink
fixed NoSuchElementException when list has no item (#2804)
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Lubell-Doughtie <[email protected]>
  • Loading branch information
owais-vd and pld authored Oct 10, 2023
1 parent ace5140 commit b886649
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ constructor(
resourceIds.forEach {
val responseBundle =
fhirResourceDataSource.getResource("$resourceType?${Composition.SP_RES_ID}=$it")
responseBundle?.let {
responseBundle.let {
bundleEntryComponents.add(
Bundle.BundleEntryComponent().apply {
resource = responseBundle.entry?.first()?.resource
resource = responseBundle.entry?.firstOrNull()?.resource
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ constructor(
} else {
// The assumption here is that only 1 practitioner is returned from the server in the
// practitioner details
practitioners.first().identifier.forEach { identifier ->
practitioners.firstOrNull()?.identifier?.forEach { identifier ->
if (
identifier.hasUse() &&
identifier.use == org.hl7.fhir.r4.model.Identifier.IdentifierUse.SECONDARY &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,42 @@ internal class LoginViewModelTest : RobolectricTest() {
)
}

@Test
fun testSavePractitionerDetailsChaRoleWithIdentifier() {
coEvery { defaultRepository.createRemote(true, any()) } just runs
loginViewModel.savePractitionerDetails(
Bundle()
.addEntry(
Bundle.BundleEntryComponent().apply {
resource =
practitionerDetails().apply {
fhirPractitionerDetails =
FhirPractitionerDetails().apply {
practitioners =
listOf(
Practitioner().apply {
identifier =
listOf(
Identifier().apply {
use = Identifier.IdentifierUse.SECONDARY
value = "cha"
},
)
},
)
}
}
},
),
UserInfo(
keycloakUuid = "cha",
),
) {}
Assert.assertNotNull(
sharedPreferencesHelper.read(SharedPreferenceKey.PRACTITIONER_DETAILS.name),
)
}

@Test
fun testSavePractitionerDetailsSupervisorRole() {
coEvery { defaultRepository.createRemote(false, any()) } just runs
Expand Down

0 comments on commit b886649

Please sign in to comment.