Skip to content

Commit

Permalink
Merge pull request #21 from MeasureAuthoringTool/MAT-7897_FhirOrderin…
Browse files Browse the repository at this point in the history
…gDuplicates

MAT-7897: Fixing equals check so that libraries aren't discarded when…
  • Loading branch information
gregory-akins authored Nov 27, 2024
2 parents d48c4d9 + ce30d5c commit 833753a
Show file tree
Hide file tree
Showing 10 changed files with 422 additions and 48 deletions.
92 changes: 52 additions & 40 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gov.cms.madie</groupId>
<artifactId>madie-translator-commons</artifactId>
Expand All @@ -25,12 +26,13 @@
<com.jayway.jsonpath.version>2.9.0</com.jayway.jsonpath.version>
</properties>
<distributionManagement>
<repository>
<id>github</id>
<name>MeasureAuthoringTool madie translator commons Package</name>
<url>https://maven.pkg.github.com/measureauthoringtool/madie-translator-commons</url>
</repository>
</distributionManagement>
<repository>
<id>github</id>
<name>MeasureAuthoringTool madie translator commons Package</name>
<url>
https://maven.pkg.github.com/measureauthoringtool/madie-translator-commons</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down Expand Up @@ -78,7 +80,14 @@
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>4.0.2</version>
<scope>test</scope>
</dependency>
<!--
https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -99,14 +108,16 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter -->
<!--
https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api -->
<!--
https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
Expand All @@ -119,12 +130,12 @@
<version>${jaxb.api.version}</version>
</dependency>
<!-- JAXB RI -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>4.0.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>4.0.4</version>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
Expand All @@ -133,29 +144,29 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>gov.cms.madie</groupId>
<artifactId>madie-java-models</artifactId>
<version>${gov.cms.madie.models.version}</version>
<exclusions>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${com.jayway.jsonpath.version}</version>
</dependency>
<groupId>gov.cms.madie</groupId>
<artifactId>madie-java-models</artifactId>
<version>${gov.cms.madie.models.version}</version>
<exclusions>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>${com.jayway.jsonpath.version}</version>
</dependency>
</dependencies>
<!-- Required to fetch artifacts from repositories other than maven central -->
<repositories>
Expand All @@ -165,7 +176,8 @@
</releases>
<id>github</id>
<name>Github madie rest commons</name>
<url>https://maven.pkg.github.com/MeasureAuthoringTool/madie-rest-commons</url>
<url>
https://maven.pkg.github.com/MeasureAuthoringTool/madie-rest-commons</url>
</repository>
</repositories>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import java.util.Set;

import org.apache.commons.lang3.StringUtils;

@Data
@Builder
public class CqlBuilderLookup {
Expand All @@ -20,5 +22,21 @@ public static class Lookup {
private String libraryName;
private String libraryAlias;
private String logic;
private int startLine;

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
CqlBuilderLookup.Lookup lookup = (CqlBuilderLookup.Lookup) o;

if (StringUtils.equals(lookup.getName(), this.getName())
&& StringUtils.equals(lookup.getLibraryAlias(), this.getLibraryAlias())
&& lookup.getLibraryName().equals(this.getLibraryName())) {
return true;
}
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package gov.cms.madie.cql_elm_translator.dto;

import java.util.Comparator;

import org.apache.commons.lang3.StringUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class CqlBuilderLookupComparator<T> implements Comparator<CqlBuilderLookup.Lookup> {

/***
* This is required because the name/line numbers can conflict between line
* numbers
*/
public int compare(CqlBuilderLookup.Lookup lookup1, CqlBuilderLookup.Lookup lookup2) {

int result;

if (StringUtils.equalsIgnoreCase(lookup1.getName(), lookup2.getName())
&& StringUtils.equalsIgnoreCase(lookup1.getLibraryAlias(), lookup2.getLibraryAlias())) {
result = 0;
} else if (lookup1.getStartLine() == lookup2.getStartLine()) {
// if the names are different but the lines are the same
result = lookup1.getStartLine() - lookup2.getStartLine() + 1;
} else {
result = lookup1.getStartLine() - lookup2.getStartLine();
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.*;

import lombok.Getter;

import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
Expand Down Expand Up @@ -131,9 +132,10 @@ public void generate() throws IOException {

TranslationResource translationResource =
TranslationResource.getInstance(
usingProperties.getLibraryType() == "FHIR"
|| usingProperties.getLibraryType()
== "QICore"); // <-- BADDDDD!!!! Defaults to fhir
usingProperties.getLibraryType().equals("FHIR")
|| usingProperties
.getLibraryType()
.equals("QICore")); // <-- BADDDDD!!!! Defaults to fhir

CqlPreprocessorElmCommonVisitor preprocessor =
new CqlPreprocessorElmCommonVisitor(
Expand All @@ -143,8 +145,8 @@ public void generate() throws IOException {
preprocessor.visit(tree);
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(listener, tree);

definitionContents.addAll(listener.getDefinitionContents());

allParameters.addAll(listener.getParameters()); // MAT-7450
callstack = graph.getAdjacencyList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,11 @@ public void enterExpressionDefinition(@NotNull cqlParser.ExpressionDefinitionCon
.getInputStream()
.getText(new Interval(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex()));
definitionContents.add(
DefinitionContent.builder().name(currentContext).content(content).build());
DefinitionContent.builder()
.startLine(ctx.getStart().getLine())
.name(currentContext)
.content(content)
.build());
graph.addNode(currentContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Objects;

@Slf4j
@Data
@Builder(toBuilder = true)
@AllArgsConstructor
Expand All @@ -17,15 +19,16 @@ public class CQLDefinition implements CQLExpression {
private String uuid;
private String definitionName;
private String definitionLogic;
private String context = "Patient";
@Builder.Default private String context = "Patient";
private boolean supplDataElement;
private boolean popDefinition;
private String commentString = "";
@Builder.Default private String commentString = "";
private String returnType;
private String parentLibrary;
private String libraryDisplayName;
private String libraryVersion;
private boolean isFunction;
private int startLine;
private List<CQLFunctionArgument> functionArguments;

public static class Comparator implements java.util.Comparator<CQLDefinition> {
Expand Down Expand Up @@ -83,6 +86,15 @@ public boolean equals(Object o) {
return false;
}
CQLDefinition that = (CQLDefinition) o;
return Objects.equals(definitionName, that.definitionName);
boolean result =
Objects.equals(definitionName, that.definitionName)
&& Objects.equals(libraryDisplayName, that.libraryDisplayName);

return result;
}

@Override
public int hashCode() {
return Objects.hash(uuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public class DefinitionContent {
private String content;
private List<CQLFunctionArgument> functionArguments;
private boolean function; // MAT-7450
private int startLine; // MAT-7897
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package gov.cms.madie.cql_elm_translator.dto;

import static org.junit.jupiter.api.Assertions.*;

import java.util.Set;
import java.util.TreeSet;

import org.junit.jupiter.api.Test;

class CqlBuilderLookupComparatorTest {

@Test
void testAddOne() {

CqlBuilderLookup.Lookup lookup =
CqlBuilderLookup.Lookup.builder()
.name("SDE Race")
.libraryAlias("SDE")
.libraryName("Supplemental Data")
.startLine(11)
.build();

Set<CqlBuilderLookup.Lookup> definitions =
new TreeSet<CqlBuilderLookup.Lookup>(
new CqlBuilderLookupComparator<CqlBuilderLookup.Lookup>());

definitions.add(lookup);
assertEquals(definitions.size(), 1);
}

@Test
void testAddTwoIdentical() {

CqlBuilderLookup.Lookup lookup =
CqlBuilderLookup.Lookup.builder()
.name("SDE Race")
.libraryAlias("SDE")
.libraryName("Supplemental Data")
.startLine(11)
.build();

CqlBuilderLookup.Lookup lookup2 =
CqlBuilderLookup.Lookup.builder()
.name("SDE Race")
.libraryAlias("SDE")
.libraryName("Supplemental Data")
.startLine(11)
.build();

Set<CqlBuilderLookup.Lookup> definitions =
new TreeSet<CqlBuilderLookup.Lookup>(
new CqlBuilderLookupComparator<CqlBuilderLookup.Lookup>());

definitions.add(lookup);
definitions.add(lookup2);
assertEquals(definitions.size(), 1);
}

@Test
void testSameNameDifferentAlias() {

CqlBuilderLookup.Lookup lookup =
CqlBuilderLookup.Lookup.builder()
.name("SDE Race")
.libraryAlias("SDE")
.libraryName("Supplemental Data")
.startLine(11)
.build();

CqlBuilderLookup.Lookup lookup2 =
CqlBuilderLookup.Lookup.builder()
.name("SDE Race")
.libraryName("Supplemental Data")
.startLine(11)
.build();

Set<CqlBuilderLookup.Lookup> definitions =
new TreeSet<CqlBuilderLookup.Lookup>(
new CqlBuilderLookupComparator<CqlBuilderLookup.Lookup>());

definitions.add(lookup);
definitions.add(lookup2);
assertEquals(2, definitions.size());
}
}
Loading

0 comments on commit 833753a

Please sign in to comment.