Commit 44498182 authored by Georg Fette's avatar Georg Fette
Browse files

- fixed count tests by changing the type checking when being in a return

parent 19226dd6
......@@ -37,32 +37,31 @@ public class Concept {
private Concept() {
}
private Concept(Concept aParent, Model aModel, String name, boolean isArray) {
private Concept(Concept aParent, String parentName, Model aModel, String name, boolean isArray) {
this.name = name;
this.fields = new ArrayList<ConceptField>();
this.isArray = isArray;
if (aParent != null) {
this.parentConcept = aParent;
this.parent = aParent.name;
}
this.parentConcept = aParent;
this.parent = parentName;
this.model = aModel;
model.addConcept(this);
}
public Concept(Concept aParent, String name, boolean isArray) {
this(aParent, aParent.model, name, isArray);
this(aParent, aParent.name, aParent.model, name, isArray);
}
public Concept(Concept aParent, String name) {
this(aParent, aParent.model, name, false);
this(aParent, aParent.name, aParent.model, name, false);
}
public Concept(String name, Model aModel) {
this(null, aModel, name, false);
this(null, null, aModel, name, false);
}
public Concept copy(boolean isArray) {
Concept newConcept = new Concept(this.parentConcept, this.model, this.name, isArray);
Concept newConcept = new Concept(this.parentConcept, this.parent, this.model, this.name,
isArray);
for (ConceptField aField : fields) {
ConceptField conceptField = new ConceptField(aField, newConcept);
newConcept.fields.add(conceptField);
......
......@@ -47,7 +47,7 @@ public class FHIRModelInitializer extends Model {
}
public static Model loadModel() throws IOException {
String modelJSONFilePath = "classpath:models/FHIR_v3/model.json";
String modelJSONFilePath = "classpath:models/FHIR_v3/FHIR_model.json";
String modelJSONString = ResourceUtil.loadFileAsString(modelJSONFilePath);
Model model = Model.fromJSON(modelJSONString, FHIRModelInitializer.class);
return model;
......@@ -66,6 +66,6 @@ public class FHIRModelInitializer extends Model {
converter.convertStructureDefsBundle(profileTypesPath);
converter.convertStructureDefsBundle(profileResourcesPath);
String json = converter.model.toJSON();
FileUtilsUniWue.saveString2File(json, new File("D:\\tmp\\model.json"));
FileUtilsUniWue.saveString2File(json, new File("D:\\tmp\\FHIR_model.json"));
}
}
......@@ -97,7 +97,8 @@ public class Model {
for (Concept aConc : getConcepts()) {
aConc.model = this;
conceptMap.put(aConc.name, aConc);
arrayConceptMap.put(aConc.name, aConc.copy(true));
Concept listConcept = aConc.copy(true);
arrayConceptMap.put(aConc.name, listConcept);
}
if (!containsConcept("Element")) {
new Concept("Element", this);
......
......@@ -58,12 +58,16 @@ public class OpenEHRModelInitializer extends Model {
StructureDef2ModelConverter strDefConverter = new StructureDef2ModelConverter(ctx);
String profileTypesPath = "classpath:models/FHIR_v3/profiles-types.json";
strDefConverter.convertStructureDefsBundle(profileTypesPath);
Concept rootConcept = null;
for (Concept aConc : strDefConverter.model.getConcepts()) {
if (!Character.isLowerCase(aConc.name.charAt(0))) {
strDefConverter.model.removeConcept(aConc);
}
if (aConc.name.equals("Element")) {
rootConcept = aConc;
}
}
new Concept("DomainResource", strDefConverter.model);
new Concept(rootConcept, "DomainResource");
String structureDefsDir = "classpath:models/openEHR/StructureDefs_openEHR_RM";
Resource resource = ResourceUtil.getResource(structureDefsDir);
strDefConverter.convertStructureDefsDir(resource.getFile());
......
......@@ -7,10 +7,6 @@ public abstract class Expression {
// an identifier with which the expression can be identified inside the returned results
public String outputName;
public boolean isInResult;
public boolean optional;
public String alias;
public QueryOperator parent;
......
......@@ -238,15 +238,22 @@ public class OperatorType {
START = new OperatorType("START", new Concept[] { aModel.PERIOD }, aModel.DATETIME);
// aggregation
COUNT = new OperatorType("COUNT", new Concept[] { aModel.LIST_OF_ANY }, aModel.INTEGER,
COUNT = new OperatorType("COUNT", new Concept[] { aModel.ANY }, aModel.INTEGER,
new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
AVG = new OperatorType("AVG", new Concept[] { aModel.LIST_OF_NUMBER }, aModel.NUMBER,
new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
MIN = new OperatorType("MIN", new InterfaceFlags[] { InterfaceFlags.IsAggregateOp,
InterfaceFlags.AllParamsMayBeAllQuantityTypes });
MAX = new OperatorType("MAX", new InterfaceFlags[] { InterfaceFlags.IsAggregateOp,
InterfaceFlags.AllParamsMayBeAllQuantityTypes });
MEDIAN = new OperatorType("MEDIAN", new Concept[] { aModel.LIST_OF_NUMBER }, aModel.NUMBER,
new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
SUM = new OperatorType("SUM", new Concept[] { aModel.LIST_OF_NUMBER }, aModel.NUMBER,
new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
STDDEV = new OperatorType("STDDEV", new Concept[] { aModel.LIST_OF_NUMBER }, aModel.NUMBER,
new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
VARIANCE = new OperatorType("VARIANCE", new Concept[] { aModel.LIST_OF_NUMBER }, aModel.NUMBER,
new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
AVG = new OperatorType("AVG", new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
MIN = new OperatorType("MIN", new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
MAX = new OperatorType("MAX", new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
MEDIAN = new OperatorType("MEDIAN", new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
SUM = new OperatorType("SUM", new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
STDDEV = new OperatorType("STDDEV", new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
VARIANCE = new OperatorType("VARIANCE", new InterfaceFlags[] { InterfaceFlags.IsAggregateOp });
// arithmetics
POWER = new OperatorType("POWER", new Concept[] { aModel.NUMBER, aModel.NUMBER },
......@@ -518,11 +525,22 @@ public class OperatorType {
}
for (Expression aParam : anOp.getParameters()) {
Concept dataType = aParam.getDataType();
if (!dataType.inheritsFrom(anOp.getModel().NUMBER)
&& !dataType.inheritsFrom(anOp.getModel().QUANTITY)
&& !dataType.inheritsFrom(anOp.getModel().DATETIME)) {
anOp.addProblem(result, ProblemType.ParamTypeMismatch,
"not all params are of quantity type");
if (interfaceFlags.contains(InterfaceFlags.IsAggregateOp)) {
if (anOp.isContainedInReturn()) {
if (!dataType.inheritsFrom(anOp.getModel().NUMBER)
&& !dataType.inheritsFrom(anOp.getModel().QUANTITY)
&& !dataType.inheritsFrom(anOp.getModel().DATETIME)) {
anOp.addProblem(result, ProblemType.ParamTypeMismatch,
"not all params are of quantity type");
} else {
if (!dataType.inheritsFrom(anOp.getModel().LIST_OF_NUMBER)
&& !dataType.inheritsFrom(anOp.getModel().LIST_OF_QUANTITY)
&& !dataType.inheritsFrom(anOp.getModel().LIST_OF_DATETIME)) {
anOp.addProblem(result, ProblemType.ParamTypeMismatch,
"not all params are of quantity type");
}
}
}
}
}
Concept firstDataType = anOp.getParameters().get(0).getDataType();
......
......@@ -23,7 +23,6 @@ public class QueryAlias extends QueryOperator {
}
result.alias = alias;
result.outputName = outputName;
result.optional = optional;
return result;
}
......
......@@ -80,7 +80,6 @@ public class QueryOperator extends Expression {
}
result.alias = alias;
result.outputName = outputName;
result.optional = optional;
return result;
}
......
......@@ -38,11 +38,11 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
// TODO: fill
@SuppressWarnings("unchecked")
private Set<OperatorType> infixOps = new HashSet<OperatorType>(Arrays.asList(new OperatorType[] {
OperatorType.MORE_OR_EQUAL, OperatorType.MORE, OperatorType.LESS_OR_EQUAL, OperatorType.LESS,
OperatorType.AND, OperatorType.EQUALS, OperatorType.AFTER,
OperatorType.POWER, OperatorType.ADD, OperatorType.MULTIPLY, OperatorType.DIVIDE,
OperatorType.SUBTRACT, OperatorType.MATCHES_AQL }));
private Set<OperatorType> infixOps = new HashSet<OperatorType>(
Arrays.asList(new OperatorType[] { OperatorType.MORE_OR_EQUAL, OperatorType.MORE,
OperatorType.LESS_OR_EQUAL, OperatorType.LESS, OperatorType.AND, OperatorType.EQUALS,
OperatorType.AFTER, OperatorType.POWER, OperatorType.ADD, OperatorType.MULTIPLY,
OperatorType.DIVIDE, OperatorType.SUBTRACT, OperatorType.MATCHES_AQL }));
@SuppressWarnings("unchecked")
private Set<OperatorType> prefixOps = new HashSet<OperatorType>(Arrays.asList(new OperatorType[] {
......@@ -444,7 +444,9 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
for (QueryOperator aConc : rootConcepts) {
List<String> relationsStrings = writeRelations(aConc);
String relsString = StringUtilsUniWue.concat(relationsStrings, ", ");
result += ", " + relsString;
if (!relsString.isEmpty()) {
result += ", " + relsString;
}
}
return result;
}
......@@ -480,7 +482,7 @@ public class Graph_2_Cypher_Mapper extends Graph_2_System_Mapper {
continue;
}
String value = writeAggrOpWithPart(anOp);
result += "\nWITH\n" + value;
result += "\nWITH\n\t" + value;
}
}
return result;
......
......@@ -33,57 +33,75 @@
"parent" : "Element"
}, {
"name" : "base64Binary",
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "boolean",
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "code",
"fields" : [ ],
"parent" : "string"
}, {
"name" : "string",
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "date",
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "dateTime",
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "decimal",
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "id",
"fields" : [ ],
"parent" : "string"
}, {
"name" : "instant",
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "integer",
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "markdown",
"fields" : [ ],
"parent" : "string"
}, {
"name" : "oid",
"fields" : [ ],
"parent" : "uri"
}, {
"name" : "uri",
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "positiveInt",
"fields" : [ ],
"parent" : "integer"
}, {
"name" : "time",
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "unsignedInt",
"fields" : [ ],
"parent" : "integer"
}, {
"name" : "uuid",
"fields" : [ ],
"parent" : "uri"
}, {
"name" : "xhtml",
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "Address",
......@@ -2794,6 +2812,7 @@
"parent" : "Element"
}, {
"name" : "SimpleQuantity",
"fields" : [ ],
"parent" : "Quantity"
}, {
"name" : "Resource",
......@@ -73,7 +73,8 @@
"parent" : "Element"
}, {
"name" : "DomainResource",
"fields" : [ ]
"fields" : [ ],
"parent" : "Element"
}, {
"name" : "ARCHETYPE_ID",
"fields" : [ {
......@@ -24,7 +24,7 @@ public class Test_AQL_2_AQL {
initialize();
QueryManager queryManager = new QueryManager();
for (MultiQuery aMultiQuery : queryManager.queries) {
if (aMultiQuery.name.equals("query_AQL_matches")) {
if (aMultiQuery.name.equals("query_AQL_2Attrs_AND")) {
processQuery(aMultiQuery);
}
}
......@@ -51,6 +51,7 @@ public class Test_AQL_2_AQL {
}
private void processQuery(MultiQuery aMultiQuery) throws QueryParseException {
System.out.println("Processing query '" + aMultiQuery + "'");
String originalQuery = aMultiQuery.system2QueryString.get(langManager.getSystem());
QueryOperator query = langManager.parse(originalQuery);
String graphString = query.toString();
......@@ -73,6 +74,8 @@ public class Test_AQL_2_AQL {
public void testAQL_2_AQL() throws IOException, QueryParseException {
initialize();
QueryManager queryManager = getQueryManager("working_AQL_2_AQL");
System.out.println("Translating queries from " + langManager.getSystem() + " to "
+ langManager.getSystem());
for (MultiQuery aMultiQuery : queryManager.queries) {
processQuery(aMultiQuery);
}
......
......@@ -77,6 +77,8 @@ public class Test_AQL_2_Cypher {
public void testAQL_2_Cypher() throws IOException, QueryParseException {
initialize();
QueryManager queryManager = getQueryManager("working_AQL_2_Cypher");
System.out.println("Translating queries from " + aqlLangManager.getSystem() + " to "
+ cypherLangManager.getSystem());
for (MultiQuery aMultiQuery : queryManager.queries) {
processQuery(aMultiQuery);
}
......
......@@ -109,6 +109,8 @@ public class Test_AQL_2_i2b2_2_AQL {
public void testAQL_2_i2b2_2_AQL() throws QueryParseException, IOException {
QueryManager queryManager = new QueryManager("working_AQL_2_i2b2_and_back");
initialize();
System.out.println("Translating queries from " + aqlLangManager.getSystem() + " to "
+ i2b2LangManager.getSystem());
for (MultiQuery aMultiQuery : queryManager.queries) {
processQuery(aMultiQuery);
}
......
......@@ -39,6 +39,7 @@ public class Test_CQL_2_AQL {
}
private void processQuery(MultiQuery aMultiQuery) throws QueryParseException {
System.out.println("Processing query '" + aMultiQuery + "'");
String cql_query_string = aMultiQuery.system2QueryString.get(cqlLangManager.getSystem());
QueryOperator query = cqlLangManager.parse(cql_query_string);
......@@ -92,6 +93,8 @@ public class Test_CQL_2_AQL {
public void testAQL_2_i2b2_2_AQL() throws QueryParseException, IOException {
QueryManager queryManager = new QueryManager("working_CQL_2_AQL_and_back");
initialize();
System.out.println("Translating queries from " + cqlLangManager.getSystem() + " to "
+ aqlLangManager.getSystem());
for (MultiQuery aMultiQuery : queryManager.queries) {
processQuery(aMultiQuery);
}
......
......@@ -16,8 +16,8 @@ public class Test_CQL_2_CQL {
public static void main(String[] args) throws IOException, QueryParseException {
Test_CQL_2_CQL test = new Test_CQL_2_CQL();
// test.debugTest();
test.testCQL_2_CQL();
// test.debugTest();
test.testCQL_2_CQL();
}
public void debugTest() throws QueryParseException, IOException {
......@@ -57,6 +57,7 @@ public class Test_CQL_2_CQL {
}
private void processQuery(MultiQuery aMultiQuery) throws QueryParseException {
System.out.println("Processing query '" + aMultiQuery + "'");
String originalQuery = aMultiQuery.system2QueryString.get(langManager.getSystem());
if (originalQuery != null) {
QueryOperator query = langManager.parse(originalQuery);
......@@ -79,6 +80,8 @@ public class Test_CQL_2_CQL {
public void testCQL_2_CQL() throws IOException, QueryParseException {
initialize();
QueryManager queryManager = getQueryManager("working_CQL_2_CQL");
System.out.println("Translating queries from " + langManager.getSystem() + " to "
+ langManager.getSystem());
for (MultiQuery aMultiQuery : queryManager.queries) {
processQuery(aMultiQuery);
}
......
......@@ -20,35 +20,54 @@ public class Test_CQL_2_Cypher {
public static void main(String[] args) throws IOException, QueryParseException {
Test_CQL_2_Cypher test = new Test_CQL_2_Cypher();
// test.debugTest();
test.testCQL_2_Cypher();
// test.debugTest();
test.testCQL_2_Cypher();
}
public void debugTest() throws QueryParseException, IOException {
QueryManager queryManager = new QueryManager();
initialize();
for (MultiQuery aMultiQuery : queryManager.queries) {
if (aMultiQuery.name.equals("query_CQL_2_Cypher_Last")) {
if (aMultiQuery.name.equals("query_CQL_2_Cypher_Count2")) {
processQuery(aMultiQuery);
}
}
}
private String getDesiredCQLGraphString(MultiQuery aMultiQuery) {
String desiredCQL_graph_string = aMultiQuery.system2QueryString
.get(QueryMapper.graphSystemName);
if (desiredCQL_graph_string == null) {
desiredCQL_graph_string = aMultiQuery.system2QueryString
.get(QueryMapper.graphSystemName + "_" + cqlLangManager.getSystem());
}
return desiredCQL_graph_string;
}
private String getDesiredCypherGraphString(MultiQuery aMultiQuery) {
String desiredCQL_graph_string = aMultiQuery.system2QueryString
.get(QueryMapper.graphSystemName);
if (desiredCQL_graph_string == null) {
desiredCQL_graph_string = aMultiQuery.system2QueryString
.get(QueryMapper.graphSystemName + "_" + cypherLangManager.getSystem());
}
return desiredCQL_graph_string;
}
private void processQuery(MultiQuery aMultiQuery) throws QueryParseException {
System.out.println("Processing query '" + aMultiQuery + "'");
String original_cql_query_string = aMultiQuery.system2QueryString
.get(cqlLangManager.getSystem());
QueryOperator query = cqlLangManager.parse(original_cql_query_string);
String desiredCQL_graph_string = aMultiQuery.system2QueryString
.get(QueryMapper.graphSystemName + "_" + cqlLangManager.getSystem());
String desiredCQL_graph_string = getDesiredCQLGraphString(aMultiQuery);
String actualCQL_graph_string = query.toString();
if (!desiredCQL_graph_string.equals(actualCQL_graph_string)) {
throw new RuntimeException("CQL graph query strings not equal");
}
graphTransformer_cql_2_cypher.transform(query);
String desiredCypher_graph_string = aMultiQuery.system2QueryString
.get(QueryMapper.graphSystemName + "_" + cypherLangManager.getSystem());
String desiredCypher_graph_string = getDesiredCypherGraphString(aMultiQuery);
String actualCypher_graph_string = query.toString();
if (!desiredCypher_graph_string.equals(actualCypher_graph_string)) {
throw new RuntimeException("Cypher graph query strings not equal");
......@@ -74,6 +93,8 @@ public class Test_CQL_2_Cypher {
public void testCQL_2_Cypher() throws IOException, QueryParseException {
QueryManager queryManager = new QueryManager("working_CQL_2_Cypher");
initialize();
System.out.println("Translating queries from " + cqlLangManager.getSystem() + " to "
+ cypherLangManager.getSystem());
for (MultiQuery aMultiQuery : queryManager.queries) {
processQuery(aMultiQuery);
}
......
package de.uniwue.query;
public class Test_CQL_2_FHIRRest {
/*
CQL_2_Graph_Mapper cql_2_graph_mapper;
Graph_2_FHIRRest_Mapper graph_2_fhir_mapper;
FHIRRest_2_Graph_Mapper fhir_2_graph_mapper;
Graph_2_CQL_Mapper graph_2_cql_mapper;
public void debugTest() throws IOException, XMLStreamException, ParseException, JDOMException,
ParserConfigurationException, SAXException {
QueryManager queryManager = new QueryManager();
initialize();
for (MultiQuery aMultiQuery : queryManager.queries) {
if (aMultiQuery.name.equals("query_FHIR_where")) {
processQuery(aMultiQuery);
}
}
}
private void processQuery(MultiQuery aMultiQuery) throws ParseException, JDOMException,
IOException, XMLStreamException, ParserConfigurationException, SAXException {
String original_cql_query_string = aMultiQuery.system2QueryString
.get(CQL_2_Graph_Mapper.getSystem());
GraphQuery query = cql_2_graph_mapper.parse(original_cql_query_string);
String fhir_query_string = graph_2_fhir_mapper.visit(query);
GraphQuery query2 = fhir_2_graph_mapper.parse(fhir_query_string);
String result_cql_query_string = graph_2_cql_mapper.visit(query2);
Assert.assertEquals(original_cql_query_string, result_cql_query_string);
}
private void initialize() throws XMLStreamException, IOException {
cql_2_graph_mapper = new CQL_2_Graph_Mapper();
graph_2_fhir_mapper = new Graph_2_FHIRRest_Mapper();
fhir_2_graph_mapper = new FHIRRest_2_Graph_Mapper();
graph_2_cql_mapper = new Graph_2_CQL_Mapper();
}
public static void main(String[] args) throws IOException, XMLStreamException, ParseException,
JDOMException, ParserConfigurationException, SAXException {
Test_CQL_2_FHIRRest test = new Test_CQL_2_FHIRRest();
// test.debugTest();
test.testCQL_2_FHIRRest_2_CQL();
}
@Test
public void testCQL_2_FHIRRest_2_CQL() throws XMLStreamException, ParserConfigurationException,
SAXException, IOException, JDOMException, ParseException {
QueryManager queryManager = new QueryManager("working_CQL_2_FHIRRest_and_back");
initialize();
for (MultiQuery aMultiQuery : queryManager.queries) {
processQuery(aMultiQuery);
}
}
*/
}
......@@ -7,7 +7,12 @@ import de.uniwue.query.i2b2.I2B2_2_Graph_Mapper;
public class Test_i2B2_2_i2b2 {
// @Test
public static void main(String args[]) throws QueryParseException, IOException {
Test_i2B2_2_i2b2 test = new Test_i2B2_2_i2b2();
test.test_i2b2_2_i2b2();
}
// @Test
public void test_i2b2_2_i2b2() throws QueryParseException, IOException {
QueryManager queryManager = new QueryManager();
I2B2_2_Graph_Mapper mapper = new I2B2_2_Graph_Mapper(null);
......
*CQL
[Encounter] A where A.length > 120 days
*Comment
The resolution of the duration into two constraints leads to two independent links in Cypher. It could be checked using the model if the field is a non-array.
If this is the case, no multiple relations should be spanned in the match. As an alternative solution the usage of the Neo4J-Duration type could be tried.
*Cypher
MATCH
(A:Encounter)-[:length]->(B:Duration)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment