Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -166,7 +168,8 @@ constructor(
conditions = patient.activeConditions(),
otherPatients = patient.otherChildren(),
guardians = patient.guardians(),
observations = patient.observations()
observations = patient.observations(),
practitioners = patient.practitioners()
)
}

Expand Down Expand Up @@ -293,6 +296,18 @@ constructor(
subjectParam = CarePlan.SUBJECT
)

internal suspend fun Patient.practitioners(): List<Practitioner> {
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<Resource> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,6 +99,7 @@ sealed class ProfileData(open val logicalId: String, open val name: String) {
val conditions: List<Condition> = emptyList(),
val otherPatients: List<Resource> = listOf(),
val guardians: List<Guardian> = emptyList(),
val observations: List<Observation> = emptyList()
val observations: List<Observation> = emptyList(),
val practitioners: List<Practitioner> = emptyList()
) : ProfileData(logicalId = logicalId, name = name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,7 +57,8 @@ sealed class ProfileViewData(
val otherPatients: List<Resource> = emptyList(),
val viewChildText: String = "",
val guardians: List<Guardian> = emptyList(),
val observations: List<Observation> = emptyList()
val observations: List<Observation> = emptyList(),
val practitioners: List<Practitioner> = emptyList()
) : ProfileViewData(name = name, logicalId = logicalId, identifier = identifier) {
val tasksCompleted =
carePlans.isNotEmpty() &&
Expand All @@ -69,6 +71,7 @@ sealed class ProfileViewData(
val resources = conditions + guardiansRelatedPersonResource + observations
val resourcesAsBundle = Bundle().apply { resources.map { this.addEntry().resource = it } }
arrayListOf(*carePlans.toTypedArray(), resourcesAsBundle)
arrayListOf(*practitioners.toTypedArray(), resourcesAsBundle)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returned list seems to not include careplans from previous line. Maybe merge to return all in a single list

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class ProfileViewDataMapperTest : RobolectricTest() {
Assert.assertEquals("5y", age)
Assert.assertEquals(emptyList<PatientProfileRowItem>(), upcomingServices)
Assert.assertEquals(emptyList<PatientProfileRowItem>(), tasks)
Assert.assertEquals(emptyList<PatientProfileRowItem>(), practitioners)
}
}

Expand All @@ -112,6 +113,7 @@ class ProfileViewDataMapperTest : RobolectricTest() {
Assert.assertEquals(true, tasks.isEmpty())
Assert.assertEquals(true, upcomingServices.isEmpty())
Assert.assertEquals(emptyList<PatientProfileRowItem>(), tasks)
Assert.assertEquals(emptyList<PatientProfileRowItem>(), practitioners)
}
}

Expand Down