Skip to content

Commit

Permalink
fix composition instance check in step, add scenario for select instr…
Browse files Browse the repository at this point in the history
…uction
  • Loading branch information
serefarikan committed Feb 13, 2018
1 parent f6e2964 commit e187924
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
@@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -175,19 +178,43 @@ 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 {
return new Scanner(new FileInputStream(fullFilePath))
.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<String,String> 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);
}
}
Expand Up @@ -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
@@ -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'
@@ -1,5 +1,5 @@
SELECT
a
a composition
FROM
EHR e [ehr_id/value = '{{ehrId}}']
CONTAINS COMPOSITION a[{{compositionArchetypeIdId}}]
Expand Down
@@ -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}}'

0 comments on commit e187924

Please sign in to comment.