Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ndegwamartin committed Feb 14, 2024
1 parent 5378afc commit 7b27cb0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ define "GetSingleDose":
where exists(I.protocolApplied)
and exists(I.protocolApplied.doseNumber.value)
and not exists(I.protocolApplied.seriesDoses.value)

define "GetFinalDoseWithLocationData":
[Immunization] I
with [Location] L
such that I.location.reference.value = 'Location/'+ L.id
and I.protocolApplied.doseNumber.value = I.protocolApplied.seriesDoses.value

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
"doseNumberPositiveInt": 2,
"seriesDosesPositiveInt": 2
}
]
],
"location": {
"reference": "Location/nairobi-047"
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import kotlinx.coroutines.runBlocking
import org.hl7.fhir.instance.model.api.IBaseResource
import org.hl7.fhir.r4.model.Bundle
import org.hl7.fhir.r4.model.Library
import org.hl7.fhir.r4.model.Location
import org.hl7.fhir.r4.model.Parameters
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -133,6 +134,58 @@ class FhirOperatorLibraryEvaluateTest {
assertThat(results.getParameterBool("CompletedImmunization")).isTrue()
}

@Test
fun evaluateImmunityCheckWithAdditionalData() = runBlocking {
val patientImmunizationHistory = load("/immunity-check/ImmunizationHistory.json") as Bundle
for (entry in patientImmunizationHistory.entry) {
fhirEngine.create(entry.resource)
}

// Load Library that checks if Patient has taken a vaccine
knowledgeManager.install(copy("/immunity-check/ImmunityCheck.json"))
knowledgeManager.install(copy("/immunity-check/FhirHelpers.json"))

val location =
"""
{
"resourceType": "Location",
"id": "nairobi-047",
"status": "active",
"name": "Arundel mobile clinic",
"mode": "instance",
"physicalType": {
"coding": [ {
"system": "http://terminology.hl7.org/CodeSystem/location-physical-type",
"code": "bu",
"display": "Arundel mobile clinic"
} ]
}
}
"""
.trimIndent()

val additionalDataBundle =
Bundle().apply {
addEntry(
Bundle.BundleEntryComponent().apply {
resource = jsonParser.parseResource(location) as Location
},
)
}

// Evaluates a specific Patient
val results =
fhirOperator.evaluateLibrary(
"http://localhost/Library/ImmunityCheck|1.0.0",
"d4d35004-24f8-40e4-8084-1ad75924514f",
null,
additionalDataBundle,
null,
) as Parameters

assertThat(results.hasParameter("GetFinalDoseWithLocationData")).isTrue()
}

@Test
fun evaluateImmunityCheck_shouldReturn_allEvaluatedVariables() = runBlocking {
val patientImmunizationHistory = load("/immunity-check/ImmunizationHistory.json") as Bundle
Expand Down

0 comments on commit 7b27cb0

Please sign in to comment.