diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/register/dao/HivRegisterDao.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/register/dao/HivRegisterDao.kt index 5d7a76f918..bc37574507 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/register/dao/HivRegisterDao.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/data/local/register/dao/HivRegisterDao.kt @@ -29,6 +29,7 @@ import org.hl7.fhir.r4.model.Condition import org.hl7.fhir.r4.model.Identifier import org.hl7.fhir.r4.model.Observation import org.hl7.fhir.r4.model.Patient +import org.hl7.fhir.r4.model.Practitioner import org.hl7.fhir.r4.model.Reference import org.hl7.fhir.r4.model.RelatedPerson import org.hl7.fhir.r4.model.Resource @@ -63,6 +64,7 @@ import org.smartregister.fhircore.engine.util.extension.hasActivePregnancy import org.smartregister.fhircore.engine.util.extension.loadResource import org.smartregister.fhircore.engine.util.extension.toAgeDisplay import org.smartregister.fhircore.engine.util.extension.yearsPassed +import timber.log.Timber @Singleton class HivRegisterDao @@ -166,7 +168,8 @@ constructor( conditions = patient.activeConditions(), otherPatients = patient.otherChildren(), guardians = patient.guardians(), - observations = patient.observations() + observations = patient.observations(), + practitioners = patient.practitioners() ) } @@ -293,6 +296,18 @@ constructor( subjectParam = CarePlan.SUBJECT ) + internal suspend fun Patient.practitioners(): List { + return generalPractitioner.mapNotNull { + try { + val id = it.reference.replace("Practitioner/", "") + fhirEngine.get(ResourceType.Practitioner, id) as Practitioner + } catch (e: Exception) { + Timber.e(e) + null + } + } + } + internal suspend fun Patient.otherPatients() = this.fetchOtherPatients(this.logicalId) internal suspend fun Patient.otherChildren(): List { diff --git a/android/engine/src/main/java/org/smartregister/fhircore/engine/domain/model/ProfileData.kt b/android/engine/src/main/java/org/smartregister/fhircore/engine/domain/model/ProfileData.kt index 094e8bd7df..33bd3598bf 100644 --- a/android/engine/src/main/java/org/smartregister/fhircore/engine/domain/model/ProfileData.kt +++ b/android/engine/src/main/java/org/smartregister/fhircore/engine/domain/model/ProfileData.kt @@ -23,6 +23,7 @@ import org.hl7.fhir.r4.model.Encounter import org.hl7.fhir.r4.model.Enumerations import org.hl7.fhir.r4.model.Flag import org.hl7.fhir.r4.model.Observation +import org.hl7.fhir.r4.model.Practitioner import org.hl7.fhir.r4.model.QuestionnaireResponse import org.hl7.fhir.r4.model.Reference import org.hl7.fhir.r4.model.Resource @@ -98,6 +99,7 @@ sealed class ProfileData(open val logicalId: String, open val name: String) { val conditions: List = emptyList(), val otherPatients: List = listOf(), val guardians: List = emptyList(), - val observations: List = emptyList() + val observations: List = emptyList(), + val practitioners: List = emptyList() ) : ProfileData(logicalId = logicalId, name = name) } diff --git a/android/engine/src/test/java/org/smartregister/fhircore/engine/domain/model/ProfileDataTest.kt b/android/engine/src/test/java/org/smartregister/fhircore/engine/domain/model/ProfileDataTest.kt index df43b8cbff..c2c41d1437 100644 --- a/android/engine/src/test/java/org/smartregister/fhircore/engine/domain/model/ProfileDataTest.kt +++ b/android/engine/src/test/java/org/smartregister/fhircore/engine/domain/model/ProfileDataTest.kt @@ -53,6 +53,7 @@ class ProfileDataTest : RobolectricTest() { Assert.assertEquals(Enumerations.AdministrativeGender.MALE, gender) Assert.assertTrue(services.size == 2) Assert.assertTrue(conditions.isEmpty()) + Assert.assertTrue(practitioners.isEmpty()) Assert.assertEquals("referenceKey", chwAssigned.reference) } } @@ -122,7 +123,8 @@ class ProfileDataTest : RobolectricTest() { chwAssigned = Reference("referenceKey"), healthStatus = HealthStatus.EXPOSED_INFANT, services = buildCarePlanServices(), - conditions = emptyList() + conditions = emptyList(), + practitioners = emptyList() ) HealthModule.HOME_TRACING, HealthModule.PHONE_TRACING -> ProfileData.DefaultProfileData( diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/models/PatientProfileViewData.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/models/PatientProfileViewData.kt index 8fad19b15c..cb69abd01d 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/models/PatientProfileViewData.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/ui/shared/models/PatientProfileViewData.kt @@ -20,6 +20,7 @@ import org.hl7.fhir.r4.model.Bundle import org.hl7.fhir.r4.model.CarePlan import org.hl7.fhir.r4.model.Condition import org.hl7.fhir.r4.model.Observation +import org.hl7.fhir.r4.model.Practitioner import org.hl7.fhir.r4.model.RelatedPerson import org.hl7.fhir.r4.model.Resource import org.hl7.fhir.r4.model.Task @@ -56,7 +57,8 @@ sealed class ProfileViewData( val otherPatients: List = emptyList(), val viewChildText: String = "", val guardians: List = emptyList(), - val observations: List = emptyList() + val observations: List = emptyList(), + val practitioners: List = emptyList() ) : ProfileViewData(name = name, logicalId = logicalId, identifier = identifier) { val tasksCompleted = carePlans.isNotEmpty() && @@ -68,7 +70,7 @@ sealed class ProfileViewData( val populationResources: ArrayList by lazy { val resources = conditions + guardiansRelatedPersonResource + observations val resourcesAsBundle = Bundle().apply { resources.map { this.addEntry().resource = it } } - arrayListOf(*carePlans.toTypedArray(), resourcesAsBundle) + arrayListOf(*carePlans.toTypedArray(), *practitioners.toTypedArray(), resourcesAsBundle) } } diff --git a/android/quest/src/main/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapper.kt b/android/quest/src/main/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapper.kt index 2cdc3e38f8..edd747a2e7 100644 --- a/android/quest/src/main/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapper.kt +++ b/android/quest/src/main/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapper.kt @@ -102,7 +102,8 @@ class ProfileViewDataMapper @Inject constructor(@ApplicationContext val context: actionButtonText = it.description, subtitleStatus = it.status.name ) - } + }, + practitioners = inputModel.practitioners ) is ProfileData.DefaultProfileData -> ProfileViewData.PatientProfileViewData( diff --git a/android/quest/src/test/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapperTest.kt b/android/quest/src/test/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapperTest.kt index c0563282e4..2fe9baaf72 100644 --- a/android/quest/src/test/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapperTest.kt +++ b/android/quest/src/test/java/org/smartregister/fhircore/quest/util/mappers/ProfileViewDataMapperTest.kt @@ -95,6 +95,7 @@ class ProfileViewDataMapperTest : RobolectricTest() { Assert.assertEquals("5y", age) Assert.assertEquals(emptyList(), upcomingServices) Assert.assertEquals(emptyList(), tasks) + Assert.assertEquals(emptyList(), practitioners) } } @@ -112,6 +113,7 @@ class ProfileViewDataMapperTest : RobolectricTest() { Assert.assertEquals(true, tasks.isEmpty()) Assert.assertEquals(true, upcomingServices.isEmpty()) Assert.assertEquals(emptyList(), tasks) + Assert.assertEquals(emptyList(), practitioners) } }