Skip to content

Commit

Permalink
Merge branch 'main' of github.com:opensrp/fhircore into 3489-and-3490…
Browse files Browse the repository at this point in the history
…-and-refactor-pdf-config
  • Loading branch information
FikriMilano committed Sep 17, 2024
2 parents c5aab3a + 2f8055b commit 28b04d4
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ constructor(
*/
suspend fun updateResourcesRecursively(
resourceConfig: ResourceConfig,
subject: Resource,
subject: Resource? = null,
eventWorkflow: EventWorkflow,
) {
withContext(dispatcherProvider.io()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ constructor(

override suspend fun doWork(): Result {
return withContext(dispatcherProvider.io()) {
fhirResourceUtil.expireOverdueTasks()
fhirResourceUtil.closeResourcesRelatedToCompletedServiceRequests()
fhirResourceUtil.run {
expireOverdueTasks()
closeResourcesRelatedToCompletedServiceRequests()
closeFhirResources()
}
Result.success()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,22 @@ constructor(
closeRelatedResources(serviceRequest)
}
}

suspend fun closeFhirResources() {
val appRegistry =
configurationRegistry.retrieveConfiguration<ApplicationConfiguration>(
ConfigType.Application,
)

appRegistry.eventWorkflows
.filter { it.eventType == EventType.RESOURCE_CLOSURE }
.forEach { eventWorkFlow ->
eventWorkFlow.eventResources.forEach { eventResource ->
defaultRepository.updateResourcesRecursively(
resourceConfig = eventResource,
eventWorkflow = eventWorkFlow,
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ import org.hl7.fhir.r4.model.Coding
import org.hl7.fhir.r4.model.Condition
import org.hl7.fhir.r4.model.ContactPoint
import org.hl7.fhir.r4.model.DateTimeType
import org.hl7.fhir.r4.model.Encounter
import org.hl7.fhir.r4.model.Enumerations
import org.hl7.fhir.r4.model.Group
import org.hl7.fhir.r4.model.HumanName
import org.hl7.fhir.r4.model.Location
import org.hl7.fhir.r4.model.Organization
import org.hl7.fhir.r4.model.Patient
import org.hl7.fhir.r4.model.Period
import org.hl7.fhir.r4.model.Procedure
import org.hl7.fhir.r4.model.Reference
import org.hl7.fhir.r4.model.RelatedPerson
Expand All @@ -80,6 +82,7 @@ import org.smartregister.fhircore.engine.app.fakes.Faker
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.UniqueIdAssignmentConfig
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.configuration.event.EventTriggerCondition
import org.smartregister.fhircore.engine.configuration.event.EventWorkflow
import org.smartregister.fhircore.engine.configuration.event.UpdateWorkflowValueConfig
import org.smartregister.fhircore.engine.configuration.profile.ManagingEntityConfig
Expand Down Expand Up @@ -887,6 +890,90 @@ class DefaultRepositoryTest : RobolectricTest() {
coVerify(exactly = 0) { fhirEngine.update(any()) }
}

@Test
fun testNonCareplanRelatedResourcesUpdatedCorrectlyAndWithNoSpecifiedBaseResource() = runTest {
val encounter =
Encounter().apply {
id = "test-Encounter"
period = Period().apply { start = Date().plusDays(-2) }
status = Encounter.EncounterStatus.INPROGRESS
type =
listOf(
CodeableConcept().apply {
coding =
listOf(
Coding().apply {
system = "http://smartregister.org/"
code = "SVISIT"
display = "Service Point Visit"
},
)
text = "Service Point Visit"
},
)
}
val eventWorkflow =
EventWorkflow(
triggerConditions =
listOf(
EventTriggerCondition(
eventResourceId = "encounterToBeClosed",
matchAll = false,
conditionalFhirPathExpressions =
listOf(
"true",
),
),
),
eventResources =
listOf(
ResourceConfig(
id = "encounterToBeClosed",
resource = ResourceType.Encounter,
configRules = listOf(),
dataQueries =
listOf(
DataQuery(
paramName = "reason-code",
filterCriteria =
listOf(
FilterCriterionConfig.TokenFilterCriterionConfig(
dataType = Enumerations.DataType.CODEABLECONCEPT,
value = Code(system = "http://smartregister.org/", code = "SVISIT"),
),
),
),
),
),
),
updateValues =
listOf(
UpdateWorkflowValueConfig(
jsonPathExpression = "Encounter.status",
value = JsonPrimitive("finished"),
resourceType = ResourceType.Encounter,
),
),
resourceFilterExpressions =
listOf(
ResourceFilterExpression(
conditionalFhirPathExpressions = listOf("Encounter.period.end < now()"),
matchAll = true,
),
),
)
fhirEngine.create(encounter)
defaultRepository.updateResourcesRecursively(
resourceConfig = eventWorkflow.eventResources[0],
eventWorkflow = eventWorkflow,
)
val resourceSlot = slot<Encounter>()
val captured = resourceSlot.captured
coVerify { fhirEngine.update(capture(resourceSlot)) }
Assert.assertEquals("test-Encounter", captured.id)
Assert.assertEquals(Encounter.EncounterStatus.FINISHED, captured.status)
}

@Test
fun testUpdateResourcesRecursivelyClosesResource() = runTest {
val patient =
Expand Down
7 changes: 7 additions & 0 deletions android/quest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,13 @@ android {
versionNameSuffix = "-contigo"
manifestPlaceholders["appLabel"] = "Contigo"
}

create("minsaEir") {
dimension = "apps"
applicationIdSuffix = ".minsaEir"
versionNameSuffix = "-minsaEir"
manifestPlaceholders["appLabel"] = "Minsa EIR"
}
}

applicationVariants.all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import org.smartregister.fhircore.engine.domain.model.Code
import org.smartregister.fhircore.engine.domain.model.DataQuery
import org.smartregister.fhircore.engine.domain.model.FhirResourceConfig
import org.smartregister.fhircore.engine.domain.model.FilterCriterionConfig
import org.smartregister.fhircore.engine.domain.model.NestedSearchConfig
import org.smartregister.fhircore.engine.domain.model.ResourceConfig
import org.smartregister.fhircore.engine.domain.model.ResourceData
import org.smartregister.fhircore.engine.domain.model.SnackBarMessageConfig
Expand Down Expand Up @@ -244,15 +245,19 @@ constructor(
baseResource.copy(
dataQueries = newBaseResourceDataQueries ?: baseResource.dataQueries,
nestedSearchResources =
baseResourceRegisterFilterField?.nestedSearchResources?.map { nestedSearchConfig ->
nestedSearchConfig.copy(
dataQueries =
createQueriesForRegisterFilter(
dataQueries = nestedSearchConfig.dataQueries,
qrItemMap = qrItemMap,
),
getValidatedNestedSearchResources(
baseResourceRegisterFilterField?.nestedSearchResources,
qrItemMap,
)
} ?: baseResource.nestedSearchResources,
?.map { nestedSearchConfig ->
nestedSearchConfig.copy(
dataQueries =
createQueriesForRegisterFilter(
dataQueries = nestedSearchConfig.dataQueries,
qrItemMap = qrItemMap,
),
)
} ?: baseResource.nestedSearchResources,
),
relatedResources = newRelatedResources,
)
Expand All @@ -264,6 +269,19 @@ constructor(
Timber.i("New ResourceConfig for register data filter: ${fhirResourceConfig.encodeJson()}")
}

private fun getValidatedNestedSearchResources(
nestedSearchResources: List<NestedSearchConfig>?,
qrItemMap: Map<String, QuestionnaireResponse.QuestionnaireResponseItemComponent>,
) =
nestedSearchResources?.filter { nestedSearchConfig ->
nestedSearchConfig.dataQueries?.any { dataQuery ->
dataQuery.filterCriteria.any { filterCriterionConfig ->
filterCriterionConfig.dataFilterLinkId.isNullOrEmpty() ||
qrItemMap[filterCriterionConfig.dataFilterLinkId]?.answer?.isNotEmpty() == true
}
} ?: false
}

private fun createFilterRelatedResources(
registerDataFilterFieldsMap: Map<String, RegisterFilterField>?,
relatedResources: List<ResourceConfig>,
Expand Down
36 changes: 36 additions & 0 deletions android/quest/src/minsaEir/res/drawable/ic_app_logo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="407dp"
android:height="80dp"
android:viewportWidth="407"
android:viewportHeight="80">
<path
android:pathData="M13.33,36.04C13.33,21.42 19.47,12.02 34.19,12.02C48.91,12.02 55.04,21.42 55.04,36.04C55.04,50.66 48.9,60.04 34.18,60.04C19.46,60.04 13.33,50.66 13.33,36.04ZM21.79,36.04C21.79,44.83 24.24,52.32 34.18,52.32C44.13,52.32 46.52,44.83 46.52,36.04C46.52,27.24 44.14,19.75 34.18,19.75C24.24,19.75 21.79,27.24 21.79,36.04Z"
android:fillColor="#40A1DA"/>
<path
android:pathData="M71.79,59.21H63.44V12.86H81.08C88.82,12.86 96.99,15.71 96.99,27.3C96.99,38.95 88.94,41.8 81.14,41.8H71.79V59.21ZM81.73,20.58H71.79V34.01H81.73C84.59,34.01 88.41,33.19 88.41,27.3C88.41,21.42 84.6,20.58 81.73,20.58Z"
android:fillColor="#40A1DA"/>
<path
android:pathData="M138.05,12.86V20.58H113.44V31.64H135.25V39.37H113.44V51.5H139.18V59.22H105.11V12.86H138.05Z"
android:fillColor="#40A1DA"/>
<path
android:pathData="M160.69,35.32L156.1,28.19L156.22,39.31V59.21H147.87V12.86H155.56L171.59,36.75L176.18,43.88L176.06,32.76V12.86H184.41V59.21H176.72L160.69,35.32Z"
android:fillColor="#40A1DA"/>
<path
android:pathData="M196.69,45.84L205.16,44.96C205.81,50.36 209.14,52.33 215.46,52.33C220.11,52.27 225.35,50.55 225.35,45.43C225.35,41.39 222.91,39.66 215.22,38.95C206.7,38.24 198.36,36.05 198.3,26.12C198.24,16.37 206.04,12.03 215.04,12.03C227.2,12.03 232.74,17.38 233.57,26.17L225.11,27.07C224.45,21.6 221.35,19.76 215.04,19.76C211.88,19.81 206.63,20.94 206.63,26.17C206.69,29.38 208.48,30.75 215.63,31.47C227.01,32.48 233.56,34.56 233.63,45.43C233.69,55.77 224.69,60.05 215.45,60.05C202.88,60.04 197.65,55.05 196.69,45.84Z"
android:fillColor="#32647D"/>
<path
android:pathData="M251.45,59.21H243.11V12.86H262.3C270.34,12.86 278.08,15.53 278.08,26.94C278.08,35.14 274.09,38.77 268.91,40.13L280.17,59.21H270.4L259.97,41.03H251.45V59.21ZM262.83,33.24C265.75,33.24 269.56,32.7 269.56,26.93C269.56,21.11 265.75,20.57 262.83,20.57H251.45V33.24H262.83Z"
android:fillColor="#32647D"/>
<path
android:pathData="M296.51,59.21H288.16V12.86H305.8C313.54,12.86 321.71,15.71 321.71,27.3C321.71,38.95 313.66,41.8 305.86,41.8H296.51V59.21ZM306.45,20.58H296.51V34.01H306.45C309.31,34.01 313.13,33.19 313.13,27.3C313.13,21.42 309.31,20.58 306.45,20.58Z"
android:fillColor="#32647D"/>
<path
android:pathData="M362.87,71.68L382.82,58.85H342.91L362.87,71.68Z"
android:fillColor="#8EC641"/>
<path
android:pathData="M393.33,17.68L376.3,13.06C380.29,15.58 382.87,19.59 382.87,25.12C382.87,34.79 375.13,37.68 367.37,40.88C359.75,44.03 354.96,44.85 354.84,48.62H383.43V58.46L393.33,52.1V17.68Z"
android:fillColor="#40A1DA"/>
<path
android:pathData="M361.58,32.41C368.63,30.02 371.34,28.58 371.34,25.12C371.34,21.35 367.93,20.22 363.78,20.22C357.99,20.22 355.52,22.11 355.4,27.7L343.56,26.25C343.64,20.09 346.07,15.41 350.92,12.65L332.39,17.67V52.09L342.29,58.45C342.17,38.6 350.76,36.1 361.58,32.41Z"
android:fillColor="#8FD1EC"/>
</vector>
16 changes: 16 additions & 0 deletions android/quest/src/minsaEir/res/drawable/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="80dp"
android:height="80dp"
android:viewportWidth="80"
android:viewportHeight="80">
<path
android:pathData="M59.054,70H20.958V55.552H59.054V70Z"
android:fillColor="#8DC541"
android:fillType="evenOdd"/>
<path
android:pathData="M20.958,47.221H59.054V32.773H20.958V47.221Z"
android:fillColor="#40A1D9"/>
<path
android:pathData="M20.958,24.448H59.054V10H20.958V24.448Z"
android:fillColor="#8ED0EA"/>
</vector>
48 changes: 48 additions & 0 deletions android/quest/src/test/assets/configs/app/application_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,54 @@
"QuestionnaireResponse"
]
},
"eventWorkflows": [
{
"eventType": "RESOURCE_CLOSURE",
"triggerConditions": [
{
"eventResourceId": "encounterToBeClosed",
"matchAll": false,
"conditionalFhirPathExpressions": [
"true"
]
}
],
"eventResources": [
{
"id": "encounterToBeClosed",
"resource": "Encounter",
"configRules": [],
"dataQueries": [
{
"paramName": "reason-code",
"filterCriteria": [
{
"dataType": "CODEABLECONCEPT",
"value": {
"system": "http://smartregister.org/",
"code": "SVISIT"
}
}
]
}
]
}
],
"updateValues": [
{
"jsonPathExpression": "Encounter.status",
"value": "finished",
"resourceType": "Encounter"
}
],
"resourceFilterExpression": {
"conditionalFhirPathExpressions": [
"Encounter.period.end < now()"
],
"matchAll": true
}
}
],
"logGpsLocation": [
"QUESTIONNAIRE"
]
Expand Down

0 comments on commit 28b04d4

Please sign in to comment.