Skip to content

Commit 8931ccb

Browse files
authored
Fetch Identifier according to patient type (#64)
* Fetch Id according to patient type * Update SystemConstants.kt
1 parent 7ef56ef commit 8931ccb

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

android/engine/src/main/java/org/smartregister/fhircore/engine/ui/questionnaire/QuestionnaireItemViewHolderFactoryMatchersProviderFactoryImpl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class QuestionnaireItemViewHolderFactoryMatchersProviderFactoryImpl(
6161
it.value.asStringValue() in
6262
listOf(
6363
LocationPickerViewHolderFactory.WIDGET_TYPE,
64-
LocationPickerViewHolderFactory.WIDGET_TYPE_ALL
64+
LocationPickerViewHolderFactory.WIDGET_TYPE_ALL,
6565
)
6666
}
6767
},

android/engine/src/main/java/org/smartregister/fhircore/engine/ui/questionnaire/items/CustomQuestItemDataProvider.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CustomQuestItemDataProvider
3333
constructor(
3434
val sharedPreferencesHelper: SharedPreferencesHelper,
3535
val fhirEngine: FhirEngine,
36-
val gson: Gson
36+
val gson: Gson,
3737
) {
3838

3939
fun fetchCurrentFacilityLocationHierarchies(): List<LocationHierarchy> {

android/engine/src/main/java/org/smartregister/fhircore/engine/ui/questionnaire/items/LocationPickerViewHolderFactory.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class LocationPickerViewHolderFactory(
5252
questionnaireViewItem.questionnaireItem
5353
.getExtensionByUrl(WIDGET_EXTENSION)
5454
.value
55-
.asStringValue()
55+
.asStringValue(),
5656
)
5757
locationPickerView.setOnLocationChanged { value ->
5858
context.lifecycleScope.launch {

android/engine/src/main/java/org/smartregister/fhircore/engine/util/SystemConstants.kt

+15
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ object SystemConstants {
3333
const val QUESTIONNAIRE_REFERENCE_SYSTEM = "https://d-tree.org/fhir/procedure-code"
3434
const val LOCATION_TAG = "http://smartregister.org/fhir/location-tag"
3535
const val LOCATION_HIERARCHY_BINARY = "location-hierarchy"
36+
37+
fun getIdentifierSystemFromPatientType(patientType: String): String {
38+
return when (patientType) {
39+
"client-already-on-art",
40+
"newly-diagnosed-client", -> {
41+
"https://d-tree.org/fhir/patient-identifier-art"
42+
}
43+
"exposed-infant" -> {
44+
"https://d-tree.org/fhir/patient-identifier-hcc"
45+
}
46+
else -> {
47+
"https://d-tree.org/fhir/patient-identifier-hts"
48+
}
49+
}
50+
}
3651
}
3752

3853
object ReasonConstants {

android/engine/src/main/java/org/smartregister/fhircore/engine/util/extension/PatientExtension.kt

+19-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import org.smartregister.fhircore.engine.R
3939
import org.smartregister.fhircore.engine.data.domain.PregnancyStatus
4040
import org.smartregister.fhircore.engine.data.local.DefaultRepository
4141
import org.smartregister.fhircore.engine.domain.model.HealthStatus
42+
import org.smartregister.fhircore.engine.util.SystemConstants
4243
import timber.log.Timber
4344

4445
private const val RISK = "risk"
@@ -304,14 +305,27 @@ fun Patient.extractSecondaryIdentifier(): String? {
304305
return null
305306
}
306307

307-
fun Patient.extractOfficialIdentifier(): String? =
308-
if (this.hasIdentifier()) {
309-
this.identifier
310-
.lastOrNull { it.use == Identifier.IdentifierUse.OFFICIAL && it.system != "WHO-HCID" }
311-
?.value
308+
fun Patient.extractOfficialIdentifier(): String? {
309+
val patientType =
310+
this.meta.tag
311+
.firstOrNull { it.system == SystemConstants.PATIENT_TYPE_FILTER_TAG_VIA_META_CODINGS_SYSTEM }
312+
?.code
313+
return if (this.hasIdentifier() && patientType != null) {
314+
val actualId =
315+
this.identifier.lastOrNull {
316+
it.system == SystemConstants.getIdentifierSystemFromPatientType(patientType)
317+
}
318+
if (actualId != null) {
319+
actualId.value
320+
} else {
321+
this.identifier
322+
.lastOrNull { it.use == Identifier.IdentifierUse.OFFICIAL && it.system != "WHO-HCID" }
323+
?.value
324+
}
312325
} else {
313326
null
314327
}
328+
}
315329

316330
fun Coding.toHealthStatus(): HealthStatus {
317331
return try {

0 commit comments

Comments
 (0)