Skip to content

Commit

Permalink
More Sonar.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukedegruchy committed Mar 7, 2025
1 parent f55f567 commit d28647b
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 418 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
public class DynamicValueProcessor {
private static final Logger logger = LoggerFactory.getLogger(DynamicValueProcessor.class);

public DynamicValueProcessor() {}
private static final String EXPRESSION = "expression";

/**
* Processes all dynamicValues on a definition element and sets the resulting values to the corresponding path on the resource passed in
Expand All @@ -26,7 +25,7 @@ public DynamicValueProcessor() {}
* @param definitionElement the definition of the dynamicValue containing the expression and path
*/
public void processDynamicValues(ICpgRequest request, IBaseResource resource, IElement definitionElement) {
var context = definitionElement instanceof IBaseResource ? (IBaseResource) definitionElement : resource;
var context = definitionElement instanceof IBaseResource baseResource ? baseResource : resource;
processDynamicValues(request, context, resource, definitionElement, null);
}

Expand Down Expand Up @@ -64,15 +63,15 @@ protected CqfExpression getDynamicValueExpression(ICpgRequest request, IBaseBack
case DSTU3:
return new CqfExpression(
request.resolvePathString(dynamicValue, "language"),
request.resolvePathString(dynamicValue, "expression"),
request.resolvePathString(dynamicValue, EXPRESSION),
request.getDefaultLibraryUrl());
case R4:
return CqfExpression.of(
request.resolvePath(dynamicValue, "expression", org.hl7.fhir.r4.model.Expression.class),
request.resolvePath(dynamicValue, EXPRESSION, org.hl7.fhir.r4.model.Expression.class),
request.getDefaultLibraryUrl());
case R5:
return CqfExpression.of(
request.resolvePath(dynamicValue, "expression", org.hl7.fhir.r5.model.Expression.class),
request.resolvePath(dynamicValue, EXPRESSION, org.hl7.fhir.r5.model.Expression.class),
request.getDefaultLibraryUrl());
default:
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opencds.cqf.fhir.utility.r4.Parameters.datePart;
import static org.opencds.cqf.fhir.utility.r4.Parameters.parameters;
Expand All @@ -15,22 +16,26 @@
class CqlEvaluationServiceTest {
@Test
void libraryEvaluationService_inlineAsthma() {
var content = "library AsthmaTest version '1.0.0'\n" + "\n"
+ "using FHIR version '4.0.1'\n"
+ "\n"
+ "include FHIRHelpers version '4.0.1'\n"
+ "\n"
+ "codesystem \"SNOMED\": 'http://snomed.info/sct'\n"
+ "\n"
+ "code \"Asthma\": '195967001' from \"SNOMED\"\n"
+ "\n"
+ "context Patient\n"
+ "\n"
+ "define \"Asthma Diagnosis\":\n"
+ " [Condition: \"Asthma\"]\n"
+ "\n"
+ "define \"Has Asthma Diagnosis\":\n"
+ " exists(\"Asthma Diagnosis\")\n";
var content =
"""
library AsthmaTest version '1.0.0'
using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1'
codesystem "SNOMED": 'http://snomed.info/sct'
code "Asthma": '195967001' from "SNOMED"
context Patient
define "Asthma Diagnosis"
[Condition: "Asthma"]
define "Has Asthma Diagnosis":
exists("Asthma Diagnosis")
""";
var when = Library.given()
.repositoryFor("libraryeval")
.when()
Expand All @@ -44,24 +49,28 @@ void libraryEvaluationService_inlineAsthma() {

@Test
void libraryEvaluationService_contentAndExpression() {
var content = "library SimpleR4Library\n" + "\n"
+ "using FHIR version '4.0.1'\n"
+ "\n"
+ "include FHIRHelpers version '4.0.1' called FHIRHelpers\n"
+ "\n"
+ "context Patient\n"
+ "\n"
+ "define simpleBooleanExpression: true\n"
+ "\n"
+ "define observationRetrieve: [Observation]\n"
+ "\n"
+ "define observationHasCode: not IsNull(([Observation]).code)\n"
+ "\n"
+ "define \"Initial Population\": observationHasCode\n"
+ "\n"
+ "define \"Denominator\": \"Initial Population\"\n"
+ "\n"
+ "define \"Numerator\": \"Denominator\"";
var content =
"""
library SimpleR4Library
using FHIR version '4.0.1'
include FHIRHelpers version '4.0.1' called FHIRHelpers
context Patient
define simpleBooleanExpression: true
define observationRetrieve: [Observation]
define observationHasCode: not IsNull(([Observation]).code)
define "Initial Population": observationHasCode
define "Denominator": "Initial Population"
define "Numerator": "Denominator"";
""";
var when = Library.given()
.repositoryFor("libraryeval")
.when()
Expand All @@ -72,9 +81,8 @@ void libraryEvaluationService_contentAndExpression() {
var results = when.then().parameters();
assertFalse(results.isEmpty());
assertEquals(1, results.getParameter().size());
assertTrue(results.getParameter("Numerator").getValue() instanceof BooleanType);
assertInstanceOf(BooleanType.class, results.getParameter("Numerator").getValue());
assertTrue(((BooleanType) results.getParameter("Numerator").getValue()).booleanValue());
;
}

@Test
Expand All @@ -85,7 +93,7 @@ void libraryEvaluationService_arithmetic() {
.expression("5*5")
.evaluateCql();
var results = when.then().parameters();
assertTrue(results.getParameter("return").getValue() instanceof IntegerType);
assertInstanceOf(IntegerType.class, results.getParameter("return").getValue());
assertEquals("25", ((IntegerType) results.getParameter("return").getValue()).asStringValue());
}

Expand All @@ -100,7 +108,7 @@ void libraryEvaluationService_paramsAndExpression() {
.expression("year from %inputDate before 2020")
.evaluateCql();
var results = when.then().parameters();
assertTrue(results.getParameter("return").getValue() instanceof BooleanType);
assertInstanceOf(BooleanType.class, results.getParameter("return").getValue());
assertTrue(((BooleanType) results.getParameter("return").getValue()).booleanValue());
}

Expand All @@ -117,7 +125,7 @@ void libraryEvaluationService_ErrorLibrary() {
assertTrue(report.getParameterFirstRep().hasName());
assertEquals("evaluation error", report.getParameterFirstRep().getName());
assertTrue(report.getParameterFirstRep().hasResource());
assertTrue(report.getParameterFirstRep().getResource() instanceof OperationOutcome);
assertInstanceOf(OperationOutcome.class, report.getParameterFirstRep().getResource());
assertEquals(
"Unsupported interval point type for FHIR conversion java.lang.Integer",
((OperationOutcome) report.getParameterFirstRep().getResource())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public Library.When when() {
}

public static class When {
// private final R4MeasureProcessor processor;
private final R4CqlExecutionService cqlService;
private final R4LibraryEvaluationService libraryEvalService;

Expand Down Expand Up @@ -231,14 +230,14 @@ public Library.SelectedParameters then() {
"No operation was selected as part of 'when'. Choose an operation to invoke by adding one, such as 'evaluate' to the method chain.");
}

Parameters parameters;
Parameters parametersInner;
try {
parameters = this.operation.get();
parametersInner = this.operation.get();
} catch (Exception e) {
throw new IllegalStateException("error when running 'then' and invoking the chosen operation", e);
}

return new Library.SelectedParameters(parameters);
return new Library.SelectedParameters(parametersInner);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String cql_with_dateTime() {

public String library_header() {
return String.format(
"library Test version '1.0.0'\n\nusing FHIR version '%1$s'\ninclude FHIRHelpers version '%1$s'\n\n",
"library Test version '1.0.0'%n%nusing FHIR version '%1$s'%ninclude FHIRHelpers version '%1$s'%n%n",
getFhirVersion());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import jakarta.annotation.Nullable;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.r4.model.DateTimeType;
import org.hl7.fhir.r4.model.Parameters;
Expand All @@ -15,6 +16,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.opencds.cqf.cql.engine.fhir.converter.FhirTypeConverter;
import org.opencds.cqf.cql.engine.fhir.converter.FhirTypeConverterFactory;
import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory;
Expand Down Expand Up @@ -145,38 +148,13 @@ void overrideMeasurementPeriod() {
assertTrue(expected.equalsDeep(actual));
}

@Test
void nullMeasurementPeriod() {

Parameters parameters = new Parameters();

measureOperationParameterConverter.addMeasurementPeriod(parameters, null, null);

long actualCount = parameters.getParameter().stream()
.filter(x -> x.getName().equals("Measurement Period"))
.count();
assertEquals(0, actualCount);
}

@Test
void nullMeasurementPeriodStart() {

Parameters parameters = new Parameters();

measureOperationParameterConverter.addMeasurementPeriod(parameters, "2019-01-01", null);

long actualCount = parameters.getParameter().stream()
.filter(x -> x.getName().equals("Measurement Period"))
.count();
assertEquals(0, actualCount);
}

@Test
void nullMeasurementPeriodEnd() {
@ParameterizedTest
@CsvSource({",", "2019-01-01,", ",2020-01-01"})
void nullMeasurementPeriod(@Nullable String periodStart, @Nullable String periodEnd) {

Parameters parameters = new Parameters();

measureOperationParameterConverter.addMeasurementPeriod(parameters, null, "2020-01-01");
measureOperationParameterConverter.addMeasurementPeriod(parameters, periodStart, periodEnd);

long actualCount = parameters.getParameter().stream()
.filter(x -> x.getName().equals("Measurement Period"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* This test is to verify and confirm that unsupported reportType value is appropriately handled
* invalid reportType value
*/
@SuppressWarnings("squid:S2699")
class MeasureReportTypeInvalidTest {
private static final String CLASS_PATH = "org/opencds/cqf/fhir/cr/measure/r4";
private static final Repository repository = new IgRepository(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* has status
* has period
*/
@SuppressWarnings("squid:S2699")
class MeasureReportTypeSubjectListTest {
private static final String CLASS_PATH = "org/opencds/cqf/fhir/cr/measure/r4";
private static final Repository repository = new IgRepository(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/**
* the purpose of this test is to validate the output and required fields for evaluating MeasureScoring type Cohort
*/
@SuppressWarnings("squid:S2699")
class MeasureScoringTypeCohortTest {
// req'd populations
// exception works
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/**
* the purpose of this test is to validate the output and required fields for evaluating MeasureScoring type Ratio
*/
@SuppressWarnings("squid:S2699")
class MeasureScoringTypeRatioTest {
// req'd populations
// exception works
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.jupiter.api.Test;
import org.opencds.cqf.fhir.cr.measure.r4.Measure.Given;

@SuppressWarnings("squid:S2699")
class MultipleRateMeasureProcessorTest {

protected static Given given = Measure.given().repositoryFor("FHIR347");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.opencds.cqf.fhir.utility.Ids;
import org.opencds.cqf.fhir.utility.repository.ig.IgRepository;

@SuppressWarnings("squid:S2699")
class ValueSetProcessorTests {
private final FhirContext fhirContextDstu3 = FhirContext.forDstu3Cached();
private final FhirContext fhirContextR4 = FhirContext.forR4Cached();
Expand Down
Loading

0 comments on commit d28647b

Please sign in to comment.