diff --git a/vehr-integration-tests/src/test/java/com/ethercis/vehr/AqlFeaturesSteps.java b/vehr-integration-tests/src/test/java/com/ethercis/vehr/AqlFeaturesSteps.java index c52970e..528979f 100644 --- a/vehr-integration-tests/src/test/java/com/ethercis/vehr/AqlFeaturesSteps.java +++ b/vehr-integration-tests/src/test/java/com/ethercis/vehr/AqlFeaturesSteps.java @@ -1,7 +1,9 @@ package com.ethercis.vehr; +import com.jayway.restassured.path.json.JsonPath; import com.jayway.restassured.response.Response; import cucumber.api.DataTable; +import cucumber.api.PendingException; import cucumber.api.java.en.And; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; @@ -25,6 +27,7 @@ import static org.junit.Assert.*; public class AqlFeaturesSteps { + private final String SELECT_COMPLETE_INSTRUCTION_AQL = "select_complete_instruction.aql"; private final String ARCHETYPE_NODE_ID_AND_NAME_PATTERN = "\\[at\\d{4} *, *\\'[\\w\\s]*\\'\\]"; private final String SELECT_COMPLETE_COMPOSITION_AQL = "select_complete_composition.aql"; private final String SELECT_DATA_ITEM_NODE_ID_NAME_AQL = "select_data_item_node_id_and_name.aql"; @@ -175,14 +178,15 @@ public void dataItemsWithSameNodeIdShouldHaveDifferentValuesIfTheyHaveDifferentN public void aAnAQLQueryThatDescribesAnCompositionUnderAnEHRIsCreated() throws Throwable { String fullFilepath = bg.resourcesRootPath + CODE4HEALTH_QUERY_DIR + SELECT_COMPLETE_COMPOSITION_AQL; _aqlQuery = readFile(fullFilepath); - //set ehr id - theQueryContainsEHRIdCriteria(); } @Then("^The results should be composition instances$") public void theResultsShouldBeCompositionInstances() throws Throwable { _aqlResultSet = bg.extractAqlResults(bg.getAqlResponse(_aqlQuery)); assertTrue(_aqlResultSet.size() > 0); + + _aqlResultSet.forEach( + map -> assertArchetypeNodeId(map, "composition", COMPOSITION_ARCH_ID)); } private String readFile(String fullFilePath) throws FileNotFoundException { @@ -190,4 +194,27 @@ private String readFile(String fullFilePath) throws FileNotFoundException { .useDelimiter("\\A") .next(); } + + @Then("^The results should be instruction instances$") + public void theResultsShouldBeInstructionInstances() throws Throwable { + _aqlResultSet = bg.extractAqlResults(bg.getAqlResponse(_aqlQuery)); + assertTrue(_aqlResultSet.size() > 0); + + _aqlResultSet.forEach( + map -> assertArchetypeNodeId(map, "instruction", INSTRUCTION_ARCH_ID)); + } + + private void assertArchetypeNodeId(Map map, + String nodeAliasInAqlSelectClause, + String archetypeNodeId){ + String instructionJson = map.get(nodeAliasInAqlSelectClause); + JsonPath path = new JsonPath(instructionJson); + String node_id = path.getString("archetype_node_id"); + assertEquals(node_id, archetypeNodeId); + } + + @When("^A an AQL query that describes an instruction under an EHR is created$") + public void aAnAQLQueryThatDescribesAnInstructionUnderAnEHRIsCreated() throws Throwable { + _aqlQuery = readFile(bg.resourcesRootPath + CODE4HEALTH_QUERY_DIR + SELECT_COMPLETE_INSTRUCTION_AQL); + } } diff --git a/vehr-integration-tests/src/test/resources/features/code4health/Aql.feature b/vehr-integration-tests/src/test/resources/features/code4health/Aql.feature index a5b9e67..3cb3c68 100644 --- a/vehr-integration-tests/src/test/resources/features/code4health/Aql.feature +++ b/vehr-integration-tests/src/test/resources/features/code4health/Aql.feature @@ -120,3 +120,16 @@ Feature: Support for openEHR Archetype Query Language And Composition archetype id criteria And Composition name criteria using WHERE clause Then The results should be composition instances + + Scenario: Select instruction + A composition with an instruction is queried. The composition sits under the EHR. + AQL query specifies EHR id, Composition archetype node id and instruction archetype node id. + The query uses WHERE clause to add Composition name as an extra criteria. The SELECT clause + selects the complete instruction instance + + When A an AQL query that describes an instruction under an EHR is created + And The query contains EHR id criteria + And Composition archetype id criteria + And Composition name criteria using WHERE clause + And Instruction archetype id criteria + Then The results should be instruction instances diff --git a/vehr-integration-tests/src/test/resources/test_data/code4health/queries/population-composition-evaluation.aql b/vehr-integration-tests/src/test/resources/test_data/code4health/queries/population-composition-evaluation.aql new file mode 100644 index 0000000..938854d --- /dev/null +++ b/vehr-integration-tests/src/test/resources/test_data/code4health/queries/population-composition-evaluation.aql @@ -0,0 +1,35 @@ +select +e/ehr_id/value as ehrId, + e/ehr_status/subject/external_ref/id/value as subjectId, + e/ehr_status/subject/external_ref/namespace as subjectNamespace, + + a/context/start_time/value as compositionStartTime, + a/uid/value as compositionId, + a/composer/name as composerName, + a/composer/external_ref/id/value as composerId, + a/composer/external_ref/namespace as composerNamespace, + + b_a/uid/value as entryId, + b_a/protocol[at0042]/items[at0062]/value/value as AssertedDate, + b_a/data[at0001]/items[at0002] as Causative_agent, + b_a/data[at0001]/items[at0063]/value/defining_code/code_string as Status_code, + b_a/data[at0001]/items[at0101]/value/defining_code/code_string as Criticality_code, + b_a/data[at0001]/items[at0120]/value/defining_code/code_string as Category_code, + b_a/data[at0001]/items[at0117]/value/value as Onset_of_last_reaction, + b_a/data[at0001]/items[at0058]/value/defining_code/code_string as Reaction_mechanism_code, + b_a/data[at0001]/items[at0006]/value/value as Comment, + b_a/data[at0001]/items[at0009]/items[at0010] as Specific_substance, + b_a/data[at0001]/items[at0009]/items[at0021]/value/defining_code/code_string as Certainty_code, + b_a/data[at0001]/items[at0009]/items[at0011] as Manifestation, + b_a/data[at0001]/items[at0009]/items[at0012]/value/value as Reaction_description, + b_a/data[at0001]/items[at0009]/items[at0027]/value/value as Onset_of_reaction, + b_a/data[at0001]/items[at0009]/items[at0089]/value/defining_code/code_string as Severity_code, + b_a/data[at0001]/items[at0009]/items[at0106] as Route_of_exposure, + b_a/data[at0001]/items[at0009]/items[at0032]/value/value as Adverse_reaction_risk_Comment + + from EHR e + contains COMPOSITION a[openEHR-EHR-COMPOSITION.adverse_reaction_list.v1] + + contains EVALUATION b_a[openEHR-EHR-EVALUATION.adverse_reaction_risk.v1] + + where a/name/value='Adverse reaction list' \ No newline at end of file diff --git a/vehr-integration-tests/src/test/resources/test_data/code4health/queries/select_complete_composition.aql b/vehr-integration-tests/src/test/resources/test_data/code4health/queries/select_complete_composition.aql index eebde64..250d41b 100644 --- a/vehr-integration-tests/src/test/resources/test_data/code4health/queries/select_complete_composition.aql +++ b/vehr-integration-tests/src/test/resources/test_data/code4health/queries/select_complete_composition.aql @@ -1,5 +1,5 @@ SELECT - a + a composition FROM EHR e [ehr_id/value = '{{ehrId}}'] CONTAINS COMPOSITION a[{{compositionArchetypeIdId}}] diff --git a/vehr-integration-tests/src/test/resources/test_data/code4health/queries/select_complete_instruction.aql b/vehr-integration-tests/src/test/resources/test_data/code4health/queries/select_complete_instruction.aql new file mode 100644 index 0000000..f8e40f5 --- /dev/null +++ b/vehr-integration-tests/src/test/resources/test_data/code4health/queries/select_complete_instruction.aql @@ -0,0 +1,10 @@ +SELECT + b_a as instruction + FROM + EHR e [ehr_id/value = '{{ehrId}}'] + + CONTAINS COMPOSITION a[{{compositionArchetypeIdId}}] + + CONTAINS INSTRUCTION b_a[{{instructionArchetypeId}}] +WHERE + a/name/value='{{compositionName}}' \ No newline at end of file