Skip to content

Commit

Permalink
Add new test to prove that library evaluation with parameters and ret…
Browse files Browse the repository at this point in the history
…urned sets works. (#623)

* Add new test to prove that library evaluation with parameters and returned sets works.

* Spotless.
  • Loading branch information
lukedegruchy authored Jan 9, 2025
1 parent 7916b7b commit 0a9eeab
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.OperationOutcome;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent;
import org.junit.jupiter.api.Test;

class LibraryEvaluationServiceTest {
Expand Down Expand Up @@ -115,6 +117,42 @@ void libraryEvaluationService_ErrorPrefetchParam() {
assertTrue(report.getParameterFirstRep().getResource() instanceof OperationOutcome);
}

@Test
void libraryEvaluationWithReturnedSets() {
Parameters params = parameters(stringPart("subject", "Patient/SimplePatient"));
var libId = new IdType("Library", "ReturnedSets");
var when = Library.given()
.repositoryFor("libraryeval")
.when()
.id(libId)
.parameters(params)
.evaluateLibrary();
var report = when.then().parameters();
assertNotNull(report);
assertTrue(report.hasParameter("Conditions"));
assertTrue(report.hasParameter("Encounters"));
assertTrue(report.hasParameter("Related Encounters"));

var relatedEncountersByName = report.getParameter("Related Encounters").getPart().stream()
.collect(Collectors.toMap(
ParametersParameterComponent::getName, ParametersParameterComponent::getResource));

assertEquals(
"Condition/SimpleCondition",
relatedEncountersByName
.get("condition")
.getIdElement()
.toUnqualifiedVersionless()
.getValue());
assertEquals(
"Encounter/SimpleEncounter",
relatedEncountersByName
.get("encounter")
.getIdElement()
.toUnqualifiedVersionless()
.getValue());
}

// ToDo: bundle test

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
library ReturnedSets

using FHIR version '4.0.1'

include FHIRHelpers version '4.0.1' called FHIRHelpers

parameter "Measurement Period" Interval<DateTime>

context Patient

define "Related Encounters":
from
"Encounters" Encounter,
"Conditions" Condition
return { condition: Condition, encounter: Encounter }

define "Encounters" :
[Encounter] Encounter

define "Conditions" :
[Condition] Condition
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"resourceType": "Library",
"id": "ReturnedSets",
"url": "http://example.com/Library/ReturnedSets",
"name": "ReturnedSets",
"status": "active",
"type": {
"coding": [ {
"system": "http://terminology.hl7.org/CodeSystem/library-type",
"code": "logic-library"
} ]
},
"content": [ {
"contentType": "text/cql",
"url": "../../cql/ReturnedSets.cql"
} ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"resourceType":"Encounter",
"id":"SimpleEncounter",
"meta":{
"profile":[
"http://hl7.org/fhir/us/qicore/StructureDefinition/qicore-encounter"
]
},
"status":"finished",
"class":{
"system":"http://terminology.hl7.org/CodeSystem/v3-ActCode",
"code":"AMB",
"display":"ambulatory"
},
"type":[
{
"coding":[
{
"system":"http://fhir.org/guides/who/anc-cds/CodeSystem/anc-care-codes",
"code":"ANC.Contact",
"display":"Antenatal care contact"
}
]
}
],
"subject":{
"reference":"Patient/SimplePatient"
},
"period":{
"start":"2021-01-26T08:11:12+00:00",
"end":"2021-01-26T08:15:30.000+00:00"
},
"reasonCode": [
{
"coding": [
{
"system": "http://fhir.org/guides/who/anc-cds/CodeSystem/anc-custom-codes",
"code": "ANC.B5.DE2",
"display": "First antenatal care contact"
}
]
}
]
}

0 comments on commit 0a9eeab

Please sign in to comment.