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

Use subject's Related Entity Location meta tag on related resources #3097

Merged
merged 5 commits into from
Feb 26, 2024
Merged
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 @@ -330,7 +330,9 @@ constructor(
this.id = questionnaireResponse.subject.extractId()
} else if (
extractedResourceUniquePropertyExpressionsMap.containsKey(resourceType) &&
previouslyExtractedResources.containsKey(resourceType)
previouslyExtractedResources.containsKey(
resourceType,
)
) {
val fhirPathExpression =
extractedResourceUniquePropertyExpressionsMap
Expand Down Expand Up @@ -366,7 +368,7 @@ constructor(
}

// Set the Group's Related Entity Location metadata tag on Resource before saving.
this.applyRelatedEntityLocationMetaTag(questionnaireConfig, context)
this.applyRelatedEntityLocationMetaTag(questionnaireConfig, context, subjectType)

defaultRepository.addOrUpdate(true, resource = this)

Expand Down Expand Up @@ -403,6 +405,7 @@ constructor(
questionnaireResponse.applyRelatedEntityLocationMetaTag(
questionnaireConfig,
context,
subjectType,
)
defaultRepository.addOrUpdate(resource = questionnaireResponse)
}
Expand All @@ -411,23 +414,30 @@ constructor(
private suspend fun Resource.applyRelatedEntityLocationMetaTag(
questionnaireConfig: QuestionnaireConfig,
context: Context,
subjectType: ResourceType?,
) {
questionnaireConfig.groupResource?.let {
if (it.groupIdentifier.isNotEmpty() && !it.removeGroup && !it.removeMember) {
val group =
loadResource(
ResourceType.Group,
it.groupIdentifier.extractLogicalIdUuid(),
)
as Group?
if (group != null) {
val system =
context.getString(
org.smartregister.fhircore.engine.R.string
.sync_strategy_related_entity_location_system,
)
group.meta.tag.filter { coding -> coding.system == system }.forEach(this.meta::addTag)
val resourceIdPair =
when {
!questionnaireConfig.resourceIdentifier.isNullOrEmpty() && subjectType != null -> {
Pair(subjectType, questionnaireConfig.resourceIdentifier!!)
}
!questionnaireConfig.groupResource?.groupIdentifier.isNullOrEmpty() &&
questionnaireConfig.groupResource?.removeGroup != true &&
questionnaireConfig.groupResource?.removeMember != true -> {
Pair(ResourceType.Group, questionnaireConfig.groupResource!!.groupIdentifier)
}
else -> null
}
if (resourceIdPair != null) {
val (resourceType, resourceId) = resourceIdPair
val group =
loadResource(resourceType = resourceType, resourceIdentifier = resourceId) as Group?
if (group != null) {
val system =
context.getString(
org.smartregister.fhircore.engine.R.string.sync_strategy_related_entity_location_system,
)
group.meta.tag.filter { coding -> coding.system == system }.forEach(this.meta::addTag)
}
Copy link
Member

Choose a reason for hiding this comment

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

@ellykits how do we handle the situation where we do not want to propagate the Group REL (Related Entity location) to the patient resources?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Group's REL only propagates if the Questionnaire has a groupResource (should only happen when adding Group member) config. If we do not want to propagate the group's REL two options:

  1. Do not configure groupResource on resource
  2. Provide configurations for extracting location ID from QuestionnaireResponse when launching the questionnaire. The location ID will be used on the subject and related resources extracted from the questionnaire submission. (To be used when you want the configured locationId to override the subject's)

The subject resource's REL is given precedence over the Group's REL because, if the subject were added as a member of the Group it would have the Group's REL anyway.

Copy link
Member

Choose a reason for hiding this comment

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

@ellykits I assume point 2 is going to handle the situation where a Familly member does not leave in the same place as the rest of the family, right ?

Copy link
Collaborator Author

@ellykits ellykits Feb 26, 2024

Choose a reason for hiding this comment

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

Yes, that's correct.

}
}
Expand Down Expand Up @@ -497,7 +507,11 @@ constructor(
): ResourceType? {
val questionnaireSubjectType = questionnaire.subjectType.firstOrNull()?.code
return questionnaireConfig.resourceType
?: questionnaireSubjectType?.let { ResourceType.valueOf(it) }
?: questionnaireSubjectType?.let {
ResourceType.valueOf(
it,
)
}
}

private fun Resource?.applyResourceMetadata(
Expand Down Expand Up @@ -673,7 +687,12 @@ constructor(

if (libraryFilters.isNotEmpty()) {
defaultRepository.fhirEngine
.search<Library> { filter(Resource.RES_ID, *libraryFilters.toTypedArray()) }
.search<Library> {
filter(
Resource.RES_ID,
*libraryFilters.toTypedArray(),
)
}
.forEach { librarySearchResult ->
val result: Parameters =
fhirOperator.evaluateLibrary(
Expand All @@ -696,7 +715,11 @@ constructor(

if (BuildConfig.DEBUG) {
Timber.d(
"CQL :: Param found: ${cqlResultParameterComponent.name} with value: ${getStringRepresentation(resultParameterResource)}",
"CQL :: Param found: ${cqlResultParameterComponent.name} with value: ${
getStringRepresentation(
resultParameterResource,
)
}",
)
}
}
Expand Down
Loading