diff --git a/prime-router/src/main/kotlin/history/azure/DatabaseDeliveryAccess.kt b/prime-router/src/main/kotlin/history/azure/DatabaseDeliveryAccess.kt index 1169a0ab3d0..a32ccde7a2e 100644 --- a/prime-router/src/main/kotlin/history/azure/DatabaseDeliveryAccess.kt +++ b/prime-router/src/main/kotlin/history/azure/DatabaseDeliveryAccess.kt @@ -46,11 +46,15 @@ class DatabaseDeliveryAccess( val org = BaseEngine.settingsProviderSingleton.findOrganization(organization) var filter = if (org?.featureFlags?.contains("ELIMS_DATA") == true) { - REPORT_FILE.NEXT_ACTION.isNull - .and(REPORT_FILE.TRANSPORT_PARAMS.isNotNull) - .and(REPORT_FILE.TRANSPORT_RESULT.notLike("%downloadedBy%")) - .and(REPORT_FILE.SCHEMA_TOPIC.equalIgnoreCase(Topic.ELR_ELIMS.jsonVal)) - .and(REPORT_FILE.RECEIVING_ORG.eq(organization)) + REPORT_FILE.NEXT_ACTION.eq(TaskAction.send) + .and(REPORT_FILE.SCHEMA_TOPIC.notEqualIgnoreCase(Topic.ELR_ELIMS.jsonVal)) + .or( + REPORT_FILE.NEXT_ACTION.isNull + .and(REPORT_FILE.TRANSPORT_PARAMS.isNotNull) + .and(REPORT_FILE.TRANSPORT_RESULT.notLike("%downloadedBy%")) + .and(REPORT_FILE.SCHEMA_TOPIC.equalIgnoreCase(Topic.ELR_ELIMS.jsonVal)) + ) + .and(REPORT_FILE.RECEIVING_ORG.eq(organization)) } else { REPORT_FILE.NEXT_ACTION.eq(TaskAction.send) .and(REPORT_FILE.RECEIVING_ORG.eq(organization)) diff --git a/prime-router/src/test/kotlin/history/azure/HistoryDatabaseAccessTests.kt b/prime-router/src/test/kotlin/history/azure/HistoryDatabaseAccessTests.kt index 88afc04cd1e..fcacba365df 100644 --- a/prime-router/src/test/kotlin/history/azure/HistoryDatabaseAccessTests.kt +++ b/prime-router/src/test/kotlin/history/azure/HistoryDatabaseAccessTests.kt @@ -47,10 +47,18 @@ class HistoryDatabaseAccessTests { fun `test organizationFilter with feature flag`() { var conditionExpected = """ ( - "public"."report_file"."next_action" is null - and "public"."report_file"."transport_params" is not null - and "public"."report_file"."transport_result" not like '%downloadedBy%' - and lower(cast("public"."report_file"."schema_topic" as varchar)) = lower('elr-elims') + ( + ( + "public"."report_file"."next_action" = 'send' + and lower(cast("public"."report_file"."schema_topic" as varchar)) <> lower('elr-elims') + ) + or ( + "public"."report_file"."next_action" is null + and "public"."report_file"."transport_params" is not null + and "public"."report_file"."transport_result" not like '%downloadedBy%' + and lower(cast("public"."report_file"."schema_topic" as varchar)) = lower('elr-elims') + ) + ) and "public"."report_file"."receiving_org" = 'test' and "public"."report_file"."receiving_org_svc" = 'test' )