Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch Identifier according to patient type #64

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -61,7 +61,7 @@ class QuestionnaireItemViewHolderFactoryMatchersProviderFactoryImpl(
it.value.asStringValue() in
listOf(
LocationPickerViewHolderFactory.WIDGET_TYPE,
LocationPickerViewHolderFactory.WIDGET_TYPE_ALL
LocationPickerViewHolderFactory.WIDGET_TYPE_ALL,
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CustomQuestItemDataProvider
constructor(
val sharedPreferencesHelper: SharedPreferencesHelper,
val fhirEngine: FhirEngine,
val gson: Gson
val gson: Gson,
) {

fun fetchCurrentFacilityLocationHierarchies(): List<LocationHierarchy> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class LocationPickerViewHolderFactory(
questionnaireViewItem.questionnaireItem
.getExtensionByUrl(WIDGET_EXTENSION)
.value
.asStringValue()
.asStringValue(),
)
locationPickerView.setOnLocationChanged { value ->
context.lifecycleScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ object SystemConstants {
const val QUESTIONNAIRE_REFERENCE_SYSTEM = "https://d-tree.org/fhir/procedure-code"
const val LOCATION_TAG = "http://smartregister.org/fhir/location-tag"
const val LOCATION_HIERARCHY_BINARY = "location-hierarchy"

fun getIdentifierSystemFromPatientType(patientType: String): String {
return when (patientType) {
"client-already-on-art",
"newly-diagnosed-client", -> {
"https://d-tree.org/fhir/patient-identifier-art"
}
"exposed-infant" -> {
"https://d-tree.org/fhir/patient-identifier-hcc"
}
else -> {
"https://d-tree.org/fhir/patient-identifier-hts"
}
}
}
}

object ReasonConstants {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.smartregister.fhircore.engine.R
import org.smartregister.fhircore.engine.data.domain.PregnancyStatus
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.domain.model.HealthStatus
import org.smartregister.fhircore.engine.util.SystemConstants
import timber.log.Timber

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

fun Patient.extractOfficialIdentifier(): String? =
if (this.hasIdentifier()) {
this.identifier
.lastOrNull { it.use == Identifier.IdentifierUse.OFFICIAL && it.system != "WHO-HCID" }
?.value
fun Patient.extractOfficialIdentifier(): String? {
val patientType =
this.meta.tag
.firstOrNull { it.system == SystemConstants.PATIENT_TYPE_FILTER_TAG_VIA_META_CODINGS_SYSTEM }
?.code
return if (this.hasIdentifier() && patientType != null) {
val actualId =
this.identifier.lastOrNull {
it.system == SystemConstants.getIdentifierSystemFromPatientType(patientType)
}
if (actualId != null) {
actualId.value
} else {
this.identifier
.lastOrNull { it.use == Identifier.IdentifierUse.OFFICIAL && it.system != "WHO-HCID" }
?.value
}
} else {
null
}
}

fun Coding.toHealthStatus(): HealthStatus {
return try {
Expand Down