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

[MWCore] Add Resource Tagging #2499

Merged
merged 45 commits into from
Aug 1, 2023
Merged
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
3e90564
rework auth items
sevenreup Apr 26, 2023
1d2b0e0
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
sevenreup May 26, 2023
3ed6fb2
init tagging
sevenreup Jun 5, 2023
ffff742
update register
sevenreup Jun 6, 2023
a4224b4
update
sevenreup Jun 6, 2023
6aaa2fd
update sync
sevenreup Jun 9, 2023
0b05614
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
sevenreup Jun 9, 2023
39564ac
update sync key
sevenreup Jun 9, 2023
dc34c49
fix location syncs
sevenreup Jun 18, 2023
639c7af
fix activity listener
sevenreup Jun 21, 2023
92536ca
test fixes
sevenreup Jun 26, 2023
c638406
fixes
sevenreup Jun 26, 2023
cea8e95
replace app with default
sevenreup Jun 27, 2023
7e5da06
tests fixed
sevenreup Jun 27, 2023
a72ff10
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
sevenreup Jun 27, 2023
2a34a3e
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
sevenreup Jun 27, 2023
2a28a52
stuff
sevenreup Jun 27, 2023
9991c0b
test fixes
sevenreup Jun 27, 2023
a525453
Merge branch 'mwcore-migrate-auth-code' of github.com:opensrp/fhircor…
sevenreup Jun 27, 2023
067b2ca
Update CqlContentTest.kt
sevenreup Jun 27, 2023
79f8267
add tests
sevenreup Jun 28, 2023
3718c03
add tests
sevenreup Jun 28, 2023
d0c116a
update appsettings
sevenreup Jun 29, 2023
cbef459
update
sevenreup Jul 4, 2023
9c2b9e9
update
sevenreup Jul 5, 2023
5b8c799
update QuestViewmodel
sevenreup Jul 11, 2023
b99b092
Update QuestionnaireActivity.kt
sevenreup Jul 12, 2023
eee0185
Update LoginViewModel.kt
sevenreup Jul 12, 2023
3807eb9
Update TokenAuthenticator.kt
sevenreup Jul 13, 2023
cf69b88
update auth
sevenreup Jul 17, 2023
39695d3
Update AppSettingActivityTest.kt
sevenreup Jul 17, 2023
c1de593
updates
sevenreup Jul 18, 2023
2d0962b
update resource tags
sevenreup Jul 20, 2023
cb62edf
block to finish saving data
sevenreup Jul 26, 2023
1c099a5
update
sevenreup Jul 26, 2023
518b38a
spotless run
sevenreup Jul 26, 2023
59d95d4
Update network_security_config.xml
sevenreup Jul 28, 2023
49fc301
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
LZRS Jul 28, 2023
183cc6a
Fix failed AppNotIdleException for some Compose tests
LZRS Jul 30, 2023
3c91f1b
Disable catching of non-test related exceptions
LZRS Jul 30, 2023
875eb8f
add tests
sevenreup Jul 31, 2023
0631d83
Update SharedPreferencesHelperTest.kt
sevenreup Jul 31, 2023
1002bc7
Merge branch 'mwcore-dev' into mwcore-migrate-auth-code
sevenreup Jul 31, 2023
7885fa2
Update AndroidExtensions.kt
sevenreup Jul 31, 2023
3449870
update tests
sevenreup Aug 1, 2023
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
Prev Previous commit
Next Next commit
Update CqlContentTest.kt
  • Loading branch information
sevenreup committed Jun 27, 2023
commit 067b2ca43408dd6a021a54f1768885b494afa08b
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ import org.smartregister.fhircore.quest.robolectric.RobolectricTest

@HiltAndroidTest
class CqlContentTest : RobolectricTest() {
@get:Rule
var hiltRule = HiltAndroidRule(this)
@get:Rule var hiltRule = HiltAndroidRule(this)
val fhirContext: FhirContext = FhirContext.forCached(FhirVersionEnum.R4)
val parser = fhirContext.newJsonParser()!!
val evaluator = LibraryEvaluator().apply { initialize() }
Expand All @@ -68,58 +67,58 @@ class CqlContentTest : RobolectricTest() {

val cqlElm = toJsonElm(cql).readStringToBase64Encoded()
val cqlLibrary =
parser.parseResource(
"$resourceDir/library.json".readFile().replace("#library-elm.json", cqlElm)
) as
Library
parser.parseResource(
"$resourceDir/library.json".readFile().replace("#library-elm.json", cqlElm)
) as
Library

println(cqlLibrary.convertToString(false) as String)

val fhirHelpersLibrary = "cql-common/helper.json".parseSampleResourceFromFile() as Library

val patient =
"patient-registration-questionnaire/sample/patient.json".parseSampleResourceFromFile() as
Patient
"patient-registration-questionnaire/sample/patient.json".parseSampleResourceFromFile() as
Patient
val dataBundle =
Bundle().apply {
// output of test results extraction is input of this cql
"test-results-questionnaire/sample"
.readDir()
.map { it.parseSampleResource() as Resource }
.forEach { addEntry().apply { resource = it } }

// output of test results cql is also added to input of this cql
"cql/test-results/sample".readDir().map { it.parseSampleResource() as Resource }.forEach {
addEntry().apply { resource = it }
}
}
Bundle().apply {
// output of test results extraction is input of this cql
"test-results-questionnaire/sample"
.readDir()
.map { it.parseSampleResource() as Resource }
.forEach { addEntry().apply { resource = it } }

// output of test results cql is also added to input of this cql
"cql/test-results/sample".readDir().map { it.parseSampleResource() as Resource }.forEach {
addEntry().apply { resource = it }
}
}

val fhirEngine = mockk<FhirEngine>()
val defaultRepository = mockk<DefaultRepository>()

coEvery { fhirEngine.get(ResourceType.Library, cqlLibrary.logicalId) } returns cqlLibrary
coEvery { fhirEngine.get(ResourceType.Library, fhirHelpersLibrary.logicalId) } returns
fhirHelpersLibrary
fhirHelpersLibrary
every { defaultRepository.fhirEngine } returns fhirEngine
coEvery { defaultRepository.save(any()) } just runs
coEvery { defaultRepository.search(any()) } returns listOf()

val result = runBlocking {
evaluator.runCqlLibrary(
cqlLibrary.logicalId,
patient,
dataBundle.apply {
this.entry.removeIf { it.resource.resourceType == ResourceType.Patient }
},
defaultRepository,
true
cqlLibrary.logicalId,
patient,
dataBundle.apply {
this.entry.removeIf { it.resource.resourceType == ResourceType.Patient }
},
defaultRepository,
true
)
}

assertOutput(
"$resourceDir/output_medication_request.json",
result,
ResourceType.MedicationRequest
"$resourceDir/output_medication_request.json",
result,
ResourceType.MedicationRequest
)

coVerify { defaultRepository.save(any()) }
Expand All @@ -132,59 +131,59 @@ class CqlContentTest : RobolectricTest() {

val cqlElm = toJsonElm(cql).readStringToBase64Encoded()
val cqlLibrary =
parser.parseResource(
"$resourceDir/library.json".readFile().replace("#library-elm.json", cqlElm)
) as
Library
parser.parseResource(
"$resourceDir/library.json".readFile().replace("#library-elm.json", cqlElm)
) as
Library

println(cqlLibrary.convertToString(false) as String)

val fhirHelpersLibrary = "cql-common/helper.json".parseSampleResourceFromFile() as Library

val patient =
"patient-registration-questionnaire/sample/patient.json".parseSampleResourceFromFile() as
Patient
"patient-registration-questionnaire/sample/patient.json".parseSampleResourceFromFile() as
Patient
val dataBundle =
Bundle().apply {
// output of test results extraction is input of this cql
"test-results-questionnaire/sample"
.readDir()
.map { it.parseSampleResource() as Resource }
.forEach { addEntry().apply { resource = it } }
}
Bundle().apply {
// output of test results extraction is input of this cql
"test-results-questionnaire/sample"
.readDir()
.map { it.parseSampleResource() as Resource }
.forEach { addEntry().apply { resource = it } }
}

val fhirEngine = mockk<FhirEngine>()
val defaultRepository = mockk<DefaultRepository>()

coEvery { fhirEngine.get(ResourceType.Library, cqlLibrary.logicalId) } returns cqlLibrary
coEvery { fhirEngine.get(ResourceType.Library, fhirHelpersLibrary.logicalId) } returns
fhirHelpersLibrary
fhirHelpersLibrary
coEvery { defaultRepository.save(any()) } just runs
every { defaultRepository.fhirEngine } returns fhirEngine
coEvery { defaultRepository.search(any()) } returns listOf()

val result = runBlocking {
evaluator.runCqlLibrary(
cqlLibrary.logicalId,
patient,
dataBundle.apply {
this.entry.removeIf { it.resource.resourceType == ResourceType.Patient }
},
defaultRepository,
true
cqlLibrary.logicalId,
patient,
dataBundle.apply {
this.entry.removeIf { it.resource.resourceType == ResourceType.Patient }
},
defaultRepository,
true
)
}

assertOutput("$resourceDir/sample/output_condition.json", result, ResourceType.Condition)
assertOutput(
"$resourceDir/sample/output_service_request.json",
result,
ResourceType.ServiceRequest
"$resourceDir/sample/output_service_request.json",
result,
ResourceType.ServiceRequest
)
assertOutput(
"$resourceDir/sample/output_diagnostic_report.json",
result,
ResourceType.DiagnosticReport
"$resourceDir/sample/output_diagnostic_report.json",
result,
ResourceType.DiagnosticReport
)

coVerify(exactly = 3) { defaultRepository.save(any()) }
Expand All @@ -197,31 +196,31 @@ class CqlContentTest : RobolectricTest() {

val cqlElm = toJsonElm(cql).readStringToBase64Encoded()
val cqlLibrary =
parser.parseResource(
"$resourceDir/library.json".readFile().replace("#library-elm.json", cqlElm)
) as
Library
parser.parseResource(
"$resourceDir/library.json".readFile().replace("#library-elm.json", cqlElm)
) as
Library

println(cqlLibrary.convertToString(false) as String)

val fhirHelpersLibrary = "cql-common/helper.json".parseSampleResourceFromFile() as Library

val dataBundle =
Bundle().apply {
addEntry().apply {
// questionnaire-response of test results is input of this cql
resource =
"test-results-questionnaire/questionnaire-response.json".parseSampleResourceFromFile() as
Resource
}
}
Bundle().apply {
addEntry().apply {
// questionnaire-response of test results is input of this cql
resource =
"test-results-questionnaire/questionnaire-response.json".parseSampleResourceFromFile() as
Resource
}
}

val fhirEngine = mockk<FhirEngine>()
val defaultRepository = mockk<DefaultRepository>()

coEvery { fhirEngine.get(ResourceType.Library, cqlLibrary.logicalId) } returns cqlLibrary
coEvery { fhirEngine.get(ResourceType.Library, fhirHelpersLibrary.logicalId) } returns
fhirHelpersLibrary
fhirHelpersLibrary
every { defaultRepository.fhirEngine } returns fhirEngine
coEvery { defaultRepository.save(any()) } just runs
coEvery { defaultRepository.search(any<DataRequirement>()) } returns listOf()
Expand All @@ -234,23 +233,23 @@ class CqlContentTest : RobolectricTest() {

Assert.assertTrue(result.contains("OUTPUT -> Correct Result"))
Assert.assertTrue(
result.contains(
"OUTPUT -> \nDetails:\n" +
"Value (3.0) is in Normal G6PD Range 0-3\n" +
"Value (11.0) is in Normal Haemoglobin Range 8-12"
)
result.contains(
"OUTPUT -> \nDetails:\n" +
"Value (3.0) is in Normal G6PD Range 0-3\n" +
"Value (11.0) is in Normal Haemoglobin Range 8-12"
)
)

val observationSlot = slot<Observation>()
coVerify { defaultRepository.save(capture(observationSlot)) }

Assert.assertEquals(
"QuestionnaireResponse/TEST_QUESTIONNAIRE_RESPONSE",
observationSlot.captured.focusFirstRep.reference
"QuestionnaireResponse/TEST_QUESTIONNAIRE_RESPONSE",
observationSlot.captured.focusFirstRep.reference
)
Assert.assertEquals(
"Correct Result",
observationSlot.captured.valueCodeableConcept.codingFirstRep.display
"Correct Result",
observationSlot.captured.valueCodeableConcept.codingFirstRep.display
)
Assert.assertEquals("Device Operation", observationSlot.captured.code.codingFirstRep.display)
}
Expand All @@ -260,7 +259,7 @@ class CqlContentTest : RobolectricTest() {
libraryManager.librarySourceLoader.registerProvider(FhirLibrarySourceProvider())

val translator: CqlTranslator =
CqlTranslator.fromText(cql, evaluator.modelManager, libraryManager)
CqlTranslator.fromText(cql, evaluator.modelManager, libraryManager)

return translator.toJxson().also { println(it.replace("\n", "").replace(" ", "")) }
}
Expand All @@ -270,12 +269,12 @@ class CqlContentTest : RobolectricTest() {

val expectedResource = resource.parseSampleResourceFromFile().convertToString(true)
val cqlResultStr =
cqlResult.find { it.startsWith("OUTPUT") && it.contains("\"resourceType\":\"$type\"") }!!
.replaceTimePart()
cqlResult.find { it.startsWith("OUTPUT") && it.contains("\"resourceType\":\"$type\"") }!!
.replaceTimePart()

println(cqlResultStr)
println(expectedResource as String)

Assert.assertTrue(cqlResultStr.contains("OUTPUT -> $expectedResource"))
}
}
}