diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/Parameters.java b/core/src/main/java/org/opencds/cqf/ruler/utility/Parameters.java new file mode 100644 index 000000000..323a8a97e --- /dev/null +++ b/core/src/main/java/org/opencds/cqf/ruler/utility/Parameters.java @@ -0,0 +1,193 @@ +package org.opencds.cqf.ruler.utility; + +import ca.uhn.fhir.context.BaseRuntimeChildDefinition; +import ca.uhn.fhir.context.BaseRuntimeElementDefinition; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.util.ParametersUtil; +import org.hl7.fhir.instance.model.api.IBase; +import org.hl7.fhir.instance.model.api.IBaseDatatype; +import org.hl7.fhir.instance.model.api.IBaseParameters; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; + +import java.util.List; +import java.util.Objects; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class Parameters { + + private Parameters() { + } + + private static BaseRuntimeChildDefinition getParameterChild(FhirContext fhirContext) { + return fhirContext.getResourceDefinition("Parameters").getChildByName("parameter"); + } + + private static BaseRuntimeElementDefinition getParameterElement(FhirContext fhirContext) { + return getParameterChild(fhirContext).getChildByName("parameter"); + } + + private static BaseRuntimeChildDefinition.IMutator getValueMutator(FhirContext fhirContext) { + return getParameterElement(fhirContext) + .getChildByName("value[x]").getMutator(); + } + + private static void validateNameAndValue(String name, Object value) { + checkNotNull(name); + checkNotNull(value); + } + + public static IBaseParameters newParameters(FhirContext fhirContext, IIdType theId, IBase... parts) { + checkNotNull(theId); + IBaseParameters newParameters = ParametersUtil.newInstance(fhirContext); + newParameters.setId(theId); + BaseRuntimeChildDefinition.IMutator mutator = getParameterChild(fhirContext).getMutator(); + for (IBase part : parts) { + mutator.addValue(newParameters, part); + } + return newParameters; + } + + public static IBaseParameters newParameters(FhirContext fhirContext, String theId, IBase... parts) { + checkNotNull(theId); + IIdType id = (IIdType) Objects.requireNonNull(fhirContext.getElementDefinition("id")).newInstance(); + id.setValue(theId); + return newParameters(fhirContext, id, parts); + } + + public static IBaseParameters newParameters(FhirContext fhirContext, IBase... parts) { + IBaseParameters newParameters = ParametersUtil.newInstance(fhirContext); + BaseRuntimeChildDefinition.IMutator mutator = getParameterChild(fhirContext).getMutator(); + for (IBase part : parts) { + mutator.addValue(newParameters, part); + } + return newParameters; + } + + public static IBase newPart(FhirContext fhirContext, String name, IBase... parts) { + checkNotNull(name); + BaseRuntimeChildDefinition.IMutator nameMutator = getParameterElement(fhirContext) + .getChildByName("name").getMutator(); + BaseRuntimeChildDefinition.IMutator partMutator = getParameterElement(fhirContext) + .getChildByName("part").getMutator(); + IBase parameterBase = getParameterElement(fhirContext).newInstance(); + IBase theName = Objects.requireNonNull(fhirContext.getElementDefinition("string")).newInstance(name); + nameMutator.setValue(parameterBase, theName); + for (IBase part : parts) { + partMutator.addValue(parameterBase, part); + } + return parameterBase; + } + + public static IBase newPart(FhirContext fhirContext, Class type, + String name, Object value, IBase... parts) { + validateNameAndValue(name, value); + IBase newPpc = newPart(fhirContext, name, parts); + IBase typeValue = Objects.requireNonNull(fhirContext.getElementDefinition(type)).newInstance(value); + getValueMutator(fhirContext).setValue(newPpc, typeValue); + return newPpc; + } + + public static IBase newPart(FhirContext fhirContext, String typeName, + String name, Object value, IBase... parts) { + validateNameAndValue(name, value); + IBase newPpc = newPart(fhirContext, name, parts); + IBase typeValue = Objects.requireNonNull(fhirContext.getElementDefinition(typeName)).newInstance(value.toString()); + getValueMutator(fhirContext).setValue(newPpc, typeValue); + return newPpc; + } + + public static IBase newPart(FhirContext fhirContext, String name, IBaseResource value, IBase... parts) { + validateNameAndValue(name, value); + IBase newPpc = newPart(fhirContext, name, parts); + getParameterElement(fhirContext).getChildByName("resource").getMutator().setValue(newPpc, value); + return newPpc; + } + + public static List getPartsByName(FhirContext fhirContext, IBaseResource parameters, String name) { + checkNotNull(parameters); + checkNotNull(name); + return ParametersUtil.getNamedParameters(fhirContext, parameters, name); + } + + public static IBase newBase64BinaryPart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "base64binary", name, value, parts); + } + + public static IBase newBooleanPart(FhirContext fhirContext, String name, boolean value, IBase... parts) { + return newPart(fhirContext, "boolean", name, value, parts); + } + + public static IBase newCanonicalPart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "canonical", name, value, parts); + } + + public static IBase newCodePart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "code", name, value, parts); + } + + public static IBase newDatePart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "date", name, value, parts); + } + + public static IBase newDateTimePart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "datetime", name, value, parts); + } + + public static IBase newDecimalPart(FhirContext fhirContext, String name, double value, IBase... parts) { + return newPart(fhirContext, "decimal", name, value, parts); + } + + public static IBase newIdPart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "id", name, value, parts); + } + + public static IBase newInstantPart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "instant", name, value, parts); + } + + public static IBase newIntegerPart(FhirContext fhirContext, String name, int value, IBase... parts) { + return newPart(fhirContext, "integer", name, value, parts); + } + + public static IBase newInteger64Part(FhirContext fhirContext, String name, long value, IBase... parts) { + return newPart(fhirContext, "integer64", name, value, parts); + } + + public static IBase newMarkdownPart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "markdown", name, value, parts); + } + + public static IBase newOidPart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "oid", name, value, parts); + } + + public static IBase newPositiveIntPart(FhirContext fhirContext, String name, int value, IBase... parts) { + return newPart(fhirContext, "positiveint", name, value, parts); + } + + public static IBase newStringPart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "string", name, value, parts); + } + + public static IBase newTimePart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "time", name, value, parts); + } + + public static IBase newUnsignedIntPart(FhirContext fhirContext, String name, int value, IBase... parts) { + return newPart(fhirContext, "unsignedint", name, value, parts); + } + + public static IBase newUriPart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "uri", name, value, parts); + } + + public static IBase newUrlPart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "url", name, value, parts); + } + + public static IBase newUuidPart(FhirContext fhirContext, String name, String value, IBase... parts) { + return newPart(fhirContext, "uuid", name, value, parts); + } +} diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/dstu3/Parameters.java b/core/src/main/java/org/opencds/cqf/ruler/utility/dstu3/Parameters.java index f64e5441a..88149c3ad 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/dstu3/Parameters.java +++ b/core/src/main/java/org/opencds/cqf/ruler/utility/dstu3/Parameters.java @@ -5,8 +5,21 @@ import java.util.List; import java.util.stream.Collectors; +import org.hl7.fhir.dstu3.model.Base64BinaryType; +import org.hl7.fhir.dstu3.model.BooleanType; +import org.hl7.fhir.dstu3.model.CodeType; +import org.hl7.fhir.dstu3.model.DateTimeType; +import org.hl7.fhir.dstu3.model.DateType; +import org.hl7.fhir.dstu3.model.DecimalType; import org.hl7.fhir.dstu3.model.IdType; +import org.hl7.fhir.dstu3.model.InstantType; +import org.hl7.fhir.dstu3.model.IntegerType; +import org.hl7.fhir.dstu3.model.OidType; +import org.hl7.fhir.dstu3.model.PositiveIntType; import org.hl7.fhir.dstu3.model.StringType; +import org.hl7.fhir.dstu3.model.TimeType; +import org.hl7.fhir.dstu3.model.UnsignedIntType; +import org.hl7.fhir.dstu3.model.UriType; import org.opencds.cqf.ruler.utility.Ids; public class Parameters { @@ -14,73 +27,65 @@ public class Parameters { private Parameters() { } - public static org.hl7.fhir.dstu3.model.Parameters newParameters(IdType theId, - org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.dstu3.model.Parameters parameters( + IdType theId, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(theId); - - org.hl7.fhir.dstu3.model.Parameters p = newParameters(parts); + org.hl7.fhir.dstu3.model.Parameters p = parameters(parts); p.setId(theId); return p; } - public static org.hl7.fhir.dstu3.model.Parameters newParameters(String theIdPart, - org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.dstu3.model.Parameters parameters( + String theIdPart, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(theIdPart); - - return newParameters((IdType) Ids.newId(org.hl7.fhir.dstu3.model.Parameters.class, theIdPart), parts); + return parameters((IdType) Ids.newId(org.hl7.fhir.dstu3.model.Parameters.class, theIdPart), parts); } - public static org.hl7.fhir.dstu3.model.Parameters newParameters( + public static org.hl7.fhir.dstu3.model.Parameters parameters( org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { org.hl7.fhir.dstu3.model.Parameters p = new org.hl7.fhir.dstu3.model.Parameters(); for (org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c : parts) { p.addParameter(c); } - return p; } - public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent newPart(String name, - String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent part( + String name, String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); checkNotNull(value); - - org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = newPart(name, parts); + org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = part(name, parts); c.setValue(new StringType(value)); return c; } - public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent newPart(String name, - org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent part( + String name, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); - org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = new org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent(); c.setName(name); for (org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent p : parts) { c.addPart(p); } - return c; } - public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent newPart(String name, - org.hl7.fhir.dstu3.model.Type value, + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent part( + String name, org.hl7.fhir.dstu3.model.Type value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); checkNotNull(value); - - org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = newPart(name, parts); + org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = part(name, parts); c.setValue(value); return c; } - public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent newPart(String name, - org.hl7.fhir.dstu3.model.Resource resource, + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent part( + String name, org.hl7.fhir.dstu3.model.Resource resource, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); checkNotNull(resource); - - org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = newPart(name, parts); + org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = part(name, parts); c.setResource(resource); return c; } @@ -89,7 +94,81 @@ public static List name.equals(x.getName())).collect(Collectors.toList()); } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent base64BinaryPart( + String name, String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new Base64BinaryType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent booleanPart( + String name, boolean value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new BooleanType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent codePart( + String name, String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new CodeType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent datePart( + String name, String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new DateType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent dateTimePart( + String name, String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new DateTimeType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent decimalPart( + String name, double value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new DecimalType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent idPart( + String name, String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new IdType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent instantPart( + String name, String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new InstantType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent integerPart( + String name, int value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new IntegerType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent oidPart( + String name, String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new OidType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent positiveIntPart( + String name, int value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new PositiveIntType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent stringPart( + String name, String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new StringType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent timePart( + String name, String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new TimeType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent unsignedIntPart( + String name, int value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new UnsignedIntType(value), parts); + } + + public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent uriPart( + String name, String value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new UriType(value), parts); + } } diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/r4/Parameters.java b/core/src/main/java/org/opencds/cqf/ruler/utility/r4/Parameters.java index 6b79b2e67..525cf4f75 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/r4/Parameters.java +++ b/core/src/main/java/org/opencds/cqf/ruler/utility/r4/Parameters.java @@ -5,8 +5,25 @@ import java.util.List; import java.util.stream.Collectors; +import org.hl7.fhir.r4.model.Base64BinaryType; +import org.hl7.fhir.r4.model.BooleanType; +import org.hl7.fhir.r4.model.CanonicalType; +import org.hl7.fhir.r4.model.CodeType; +import org.hl7.fhir.r4.model.DateTimeType; +import org.hl7.fhir.r4.model.DateType; +import org.hl7.fhir.r4.model.DecimalType; import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.InstantType; +import org.hl7.fhir.r4.model.IntegerType; +import org.hl7.fhir.r4.model.MarkdownType; +import org.hl7.fhir.r4.model.OidType; +import org.hl7.fhir.r4.model.PositiveIntType; import org.hl7.fhir.r4.model.StringType; +import org.hl7.fhir.r4.model.TimeType; +import org.hl7.fhir.r4.model.UnsignedIntType; +import org.hl7.fhir.r4.model.UriType; +import org.hl7.fhir.r4.model.UrlType; +import org.hl7.fhir.r4.model.UuidType; import org.opencds.cqf.ruler.utility.Ids; public class Parameters { @@ -14,72 +31,64 @@ public class Parameters { private Parameters() { } - public static org.hl7.fhir.r4.model.Parameters newParameters(IdType theId, - org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.r4.model.Parameters parameters( + IdType theId, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(theId); - - org.hl7.fhir.r4.model.Parameters p = newParameters(parts); + org.hl7.fhir.r4.model.Parameters p = parameters(parts); p.setId(theId); return p; } - public static org.hl7.fhir.r4.model.Parameters newParameters(String theIdPart, - org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.r4.model.Parameters parameters( + String theIdPart, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(theIdPart); - - return newParameters((IdType) Ids.newId(org.hl7.fhir.r4.model.Parameters.class, theIdPart), parts); + return parameters((IdType) Ids.newId(org.hl7.fhir.r4.model.Parameters.class, theIdPart), parts); } - public static org.hl7.fhir.r4.model.Parameters newParameters( + public static org.hl7.fhir.r4.model.Parameters parameters( org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { org.hl7.fhir.r4.model.Parameters p = new org.hl7.fhir.r4.model.Parameters(); for (org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c : parts) { p.addParameter(c); } - return p; } - public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent newPart(String name, - org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent part( + String name, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); - org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c = new org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent(); c.setName(name); for (org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent p : parts) { c.addPart(p); } - return c; } - public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent newPart(String name, - String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent part( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); checkNotNull(value); - - org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c = newPart(name, parts); + org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c = part(name, parts); c.setValue(new StringType(value)); return c; } - public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent newPart(String name, - org.hl7.fhir.r4.model.Type value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent part( + String name, org.hl7.fhir.r4.model.Type value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); checkNotNull(value); - - org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c = newPart(name, parts); + org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c = part(name, parts); c.setValue(value); return c; } - public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent newPart(String name, - org.hl7.fhir.r4.model.Resource resource, + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent part( + String name, org.hl7.fhir.r4.model.Resource resource, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); checkNotNull(resource); - - org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c = newPart(name, parts); + org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent c = part(name, parts); c.setResource(resource); return c; } @@ -88,7 +97,101 @@ public static List name.equals(x.getName())).collect(Collectors.toList()); } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent base64BinaryPart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new Base64BinaryType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent booleanPart( + String name, boolean value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new BooleanType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent canonicalPart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new CanonicalType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent codePart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new CodeType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent datePart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new DateType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent dateTimePart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new DateTimeType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent decimalPart( + String name, double value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new DecimalType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent idPart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new IdType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent instantPart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new InstantType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent integerPart( + String name, int value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new IntegerType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent markdownPart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new MarkdownType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent oidPart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new OidType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent positiveIntPart( + String name, int value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new PositiveIntType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent stringPart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new StringType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent timePart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new TimeType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent unsignedIntPart( + String name, int value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new UnsignedIntType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent uriPart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new UriType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent urlPart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new UrlType(value), parts); + } + + public static org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent uuidPart( + String name, String value, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new UuidType(value), parts); + } } diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/r5/Parameters.java b/core/src/main/java/org/opencds/cqf/ruler/utility/r5/Parameters.java index 19a484ac9..4d5cdc967 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/r5/Parameters.java +++ b/core/src/main/java/org/opencds/cqf/ruler/utility/r5/Parameters.java @@ -5,8 +5,26 @@ import java.util.List; import java.util.stream.Collectors; +import org.hl7.fhir.r5.model.Base64BinaryType; +import org.hl7.fhir.r5.model.BooleanType; +import org.hl7.fhir.r5.model.CanonicalType; +import org.hl7.fhir.r5.model.CodeType; +import org.hl7.fhir.r5.model.DateTimeType; +import org.hl7.fhir.r5.model.DateType; +import org.hl7.fhir.r5.model.DecimalType; import org.hl7.fhir.r5.model.IdType; +import org.hl7.fhir.r5.model.InstantType; +import org.hl7.fhir.r5.model.Integer64Type; +import org.hl7.fhir.r5.model.IntegerType; +import org.hl7.fhir.r5.model.MarkdownType; +import org.hl7.fhir.r5.model.OidType; +import org.hl7.fhir.r5.model.PositiveIntType; import org.hl7.fhir.r5.model.StringType; +import org.hl7.fhir.r5.model.TimeType; +import org.hl7.fhir.r5.model.UnsignedIntType; +import org.hl7.fhir.r5.model.UriType; +import org.hl7.fhir.r5.model.UrlType; +import org.hl7.fhir.r5.model.UuidType; import org.opencds.cqf.ruler.utility.Ids; public class Parameters { @@ -14,72 +32,64 @@ public class Parameters { private Parameters() { } - public static org.hl7.fhir.r5.model.Parameters newParameters(IdType theId, - org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.r5.model.Parameters parameters( + IdType theId, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(theId); - - org.hl7.fhir.r5.model.Parameters p = newParameters(parts); + org.hl7.fhir.r5.model.Parameters p = parameters(parts); p.setId(theId); return p; } - public static org.hl7.fhir.r5.model.Parameters newParameters(String theIdPart, - org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.r5.model.Parameters parameters( + String theIdPart, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(theIdPart); - - return newParameters((IdType) Ids.newId(org.hl7.fhir.r5.model.Parameters.class, theIdPart), parts); + return parameters((IdType) Ids.newId(org.hl7.fhir.r5.model.Parameters.class, theIdPart), parts); } - public static org.hl7.fhir.r5.model.Parameters newParameters( + public static org.hl7.fhir.r5.model.Parameters parameters( org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { org.hl7.fhir.r5.model.Parameters p = new org.hl7.fhir.r5.model.Parameters(); for (org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c : parts) { p.addParameter(c); } - return p; } - public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent newPart(String name, - org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent part( + String name, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); - org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c = new org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent(); c.setName(name); for (org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent p : parts) { c.addPart(p); } - return c; } - public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent newPart(String name, - String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent part( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); checkNotNull(value); - - org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c = newPart(name, parts); + org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c = part(name, parts); c.setValue(new StringType(value)); return c; } - public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent newPart(String name, - org.hl7.fhir.r5.model.DataType value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent part( + String name, org.hl7.fhir.r5.model.DataType value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); checkNotNull(value); - - org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c = newPart(name, parts); + org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c = part(name, parts); c.setValue(value); return c; } - public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent newPart(String name, - org.hl7.fhir.r5.model.Resource resource, + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent part( + String name, org.hl7.fhir.r5.model.Resource resource, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { checkNotNull(name); checkNotNull(resource); - - org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c = newPart(name, parts); + org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent c = part(name, parts); c.setResource(resource); return c; } @@ -88,7 +98,106 @@ public static List name.equals(x.getName())).collect(Collectors.toList()); } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent base64BinaryPart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new Base64BinaryType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent booleanPart( + String name, boolean value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new BooleanType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent canonicalPart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new CanonicalType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent codePart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new CodeType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent datePart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new DateType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent dateTimePart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new DateTimeType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent decimalPart( + String name, double value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new DecimalType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent idPart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new IdType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent instantPart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new InstantType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent integerPart( + String name, int value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new IntegerType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent integer64Part( + String name, long value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new Integer64Type(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent markdownPart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new MarkdownType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent oidPart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new OidType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent positiveIntPart( + String name, int value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new PositiveIntType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent stringPart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new StringType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent timePart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new TimeType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent unsignedIntPart( + String name, int value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new UnsignedIntType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent uriPart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new UriType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent urlPart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new UrlType(value), parts); + } + + public static org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent uuidPart( + String name, String value, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { + return part(name, new UuidType(value), parts); + } } diff --git a/core/src/test/java/org/opencds/cqf/ruler/ExampleServerDstu3IT.java b/core/src/test/java/org/opencds/cqf/ruler/ExampleServerDstu3IT.java index a2dbfc405..bd21053f9 100644 --- a/core/src/test/java/org/opencds/cqf/ruler/ExampleServerDstu3IT.java +++ b/core/src/test/java/org/opencds/cqf/ruler/ExampleServerDstu3IT.java @@ -16,15 +16,14 @@ import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Application.class, properties = { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = Application.class, properties = { "spring.datasource.url=jdbc:hsqldb:mem:dbr3", "hapi.fhir.fhir_version=dstu3", "hapi.fhir.subscription.websocket_enabled=true", "hapi.fhir.allow_external_references=true", - "hapi.fhir.allow_placeholder_references=true" -}) - -public class ExampleServerDstu3IT { + "hapi.fhir.allow_placeholder_references=true"}) +class ExampleServerDstu3IT { private IGenericClient ourClient; @Autowired @@ -46,8 +45,7 @@ void beforeEach() { } @Test - public void testCreateAndRead() { - + void testCreateAndRead() { String methodName = "testCreateResourceConditional"; Patient pt = new Patient(); diff --git a/core/src/test/java/org/opencds/cqf/ruler/utility/ParametersTest.java b/core/src/test/java/org/opencds/cqf/ruler/utility/ParametersTest.java new file mode 100644 index 000000000..8552ece1a --- /dev/null +++ b/core/src/test/java/org/opencds/cqf/ruler/utility/ParametersTest.java @@ -0,0 +1,91 @@ +package org.opencds.cqf.ruler.utility; + +import ca.uhn.fhir.context.FhirContext; +import org.hl7.fhir.instance.model.api.IBase; +import org.hl7.fhir.instance.model.api.IBaseParameters; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opencds.cqf.ruler.utility.Parameters.getPartsByName; +import static org.opencds.cqf.ruler.utility.Parameters.newParameters; +import static org.opencds.cqf.ruler.utility.Parameters.newPart; + +class ParametersTest { + + @Test + void testStu3Parameters() { + FhirContext fhirContext = FhirContext.forDstu3Cached(); + IBaseParameters parameters = newParameters(fhirContext); + assertTrue(parameters instanceof org.hl7.fhir.dstu3.model.Parameters); + parameters = newParameters(fhirContext, "stu3ParameterIdString"); + assertEquals("stu3ParameterIdString", parameters.getIdElement().getIdPart()); + parameters = newParameters(fhirContext, new org.hl7.fhir.dstu3.model.IdType("stu3ParameterIdType")); + assertEquals("stu3ParameterIdType", parameters.getIdElement().getIdPart()); + } + + @Test + void testStu3ParametersPartName() { + FhirContext fhirContext = FhirContext.forDstu3Cached(); + IBaseParameters parameters = newParameters(fhirContext, newPart(fhirContext, "stu3ParameterName")); + assertTrue(parameters instanceof org.hl7.fhir.dstu3.model.Parameters); + org.hl7.fhir.dstu3.model.Parameters stu3Parameters = (org.hl7.fhir.dstu3.model.Parameters) parameters; + assertEquals("stu3ParameterName", stu3Parameters.getParameterFirstRep().getName()); + } + + @Test + void testR4Parameters() { + FhirContext fhirContext = FhirContext.forR4Cached(); + IBaseParameters parameters = newParameters(fhirContext); + assertTrue(parameters instanceof org.hl7.fhir.r4.model.Parameters); + parameters = newParameters(fhirContext, "r4ParameterIdString"); + assertEquals("r4ParameterIdString", parameters.getIdElement().getIdPart()); + parameters = newParameters(fhirContext, new org.hl7.fhir.r4.model.IdType("r4ParameterIdType")); + assertEquals("r4ParameterIdType", parameters.getIdElement().getIdPart()); + } + + @Test + void testR4ParametersPartName() { + FhirContext fhirContext = FhirContext.forR4Cached(); + IBaseParameters parameters = newParameters(fhirContext, newPart(fhirContext, "r4ParameterName")); + assertTrue(parameters instanceof org.hl7.fhir.r4.model.Parameters); + org.hl7.fhir.r4.model.Parameters r4Parameters = (org.hl7.fhir.r4.model.Parameters) parameters; + assertEquals("r4ParameterName", r4Parameters.getParameterFirstRep().getName()); + } + + @Test + void testR5Parameters() { + FhirContext fhirContext = FhirContext.forR5Cached(); + IBaseParameters parameters = newParameters(fhirContext); + assertTrue(parameters instanceof org.hl7.fhir.r5.model.Parameters); + parameters = newParameters(fhirContext, "r5ParameterIdString"); + assertEquals("r5ParameterIdString", parameters.getIdElement().getIdPart()); + parameters = newParameters(fhirContext, new org.hl7.fhir.r5.model.IdType("r5ParameterIdType")); + assertEquals("r5ParameterIdType", parameters.getIdElement().getIdPart()); + } + + @Test + void testR5ParametersPartName() { + FhirContext fhirContext = FhirContext.forR5Cached(); + IBaseParameters parameters = newParameters(fhirContext, newPart(fhirContext, "r5ParameterName")); + assertTrue(parameters instanceof org.hl7.fhir.r5.model.Parameters); + org.hl7.fhir.r5.model.Parameters r5Parameters = (org.hl7.fhir.r5.model.Parameters) parameters; + assertEquals("r5ParameterName", r5Parameters.getParameterFirstRep().getName()); + } + + @Test + void getPartsByNameTest() { + FhirContext fhirContext = FhirContext.forR5Cached(); + IBaseParameters parameters = newParameters(fhirContext, + newPart(fhirContext, "r5ParameterName"), + newPart(fhirContext, "r5ParameterName1"), + newPart(fhirContext, "r5ParameterName1")); + List parts = getPartsByName(fhirContext, parameters, "r5ParameterName"); + assertEquals(1, parts.size()); + + parts = getPartsByName(fhirContext, parameters, "r5ParameterName1"); + assertEquals(2, parts.size()); + } +} diff --git a/core/src/test/java/org/opencds/cqf/ruler/utility/dstu3/ParametersTest.java b/core/src/test/java/org/opencds/cqf/ruler/utility/dstu3/ParametersTest.java new file mode 100644 index 000000000..4bd3c7571 --- /dev/null +++ b/core/src/test/java/org/opencds/cqf/ruler/utility/dstu3/ParametersTest.java @@ -0,0 +1,145 @@ +package org.opencds.cqf.ruler.utility.dstu3; + +import org.hl7.fhir.dstu3.model.Base64BinaryType; +import org.hl7.fhir.dstu3.model.BooleanType; +import org.hl7.fhir.dstu3.model.CodeType; +import org.hl7.fhir.dstu3.model.DateTimeType; +import org.hl7.fhir.dstu3.model.DateType; +import org.hl7.fhir.dstu3.model.DecimalType; +import org.hl7.fhir.dstu3.model.IdType; +import org.hl7.fhir.dstu3.model.InstantType; +import org.hl7.fhir.dstu3.model.IntegerType; +import org.hl7.fhir.dstu3.model.OidType; +import org.hl7.fhir.dstu3.model.PositiveIntType; +import org.hl7.fhir.dstu3.model.StringType; +import org.hl7.fhir.dstu3.model.TimeType; +import org.hl7.fhir.dstu3.model.UnsignedIntType; +import org.hl7.fhir.dstu3.model.UriType; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.getPartsByName; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.base64BinaryPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.booleanPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.codePart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.datePart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.dateTimePart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.decimalPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.idPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.instantPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.integerPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.oidPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.positiveIntPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.stringPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.timePart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.unsignedIntPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.uriPart; + +class ParametersTest { + @Test + void testParametersPartTypes() { + org.hl7.fhir.dstu3.model.Parameters parameters = parameters( + base64BinaryPart("stu3Base64BinaryPart", "SGVsbG8gV29ybGQh"), + booleanPart("stu3BooleanPart", true), + codePart("stu3CodePart", "active"), + datePart("stu3DatePart", "2012-12-31"), + dateTimePart("stu3DateTimePart", "2015-02-07T13:28:17-05:00"), + decimalPart("stu3DecimalPart", 72.42), + idPart("stu3IdPart", "example-id"), + instantPart("stu3InstantPart", "2015-02-07T13:28:17.239+02:00"), + integerPart("stu3IntegerPart", 72), + oidPart("stu3OidPart", "urn:oid:1.2.3.4.5"), + positiveIntPart("stu3PositiveIntPart", 1), + stringPart("stu3StringPart", "example string"), + timePart("stu3TimePart", "12:30:30.500"), + unsignedIntPart("stu3UnsignedIntPart", 0), + uriPart("stu3UriPart", "news:comp.infosystems.www.servers.unix")); + + for (org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent stu3Component : parameters.getParameter()) { + if (stu3Component.getName().equals("stu3Base64BinaryPart")) { + assertTrue(stu3Component.getValue() instanceof Base64BinaryType); + assertEquals("SGVsbG8gV29ybGQh", ((Base64BinaryType) stu3Component.getValue()).getValueAsString()); + } + else if (stu3Component.getName().equals("stu3BooleanPart")) { + assertTrue(stu3Component.getValue() instanceof BooleanType); + assertTrue(((BooleanType) stu3Component.getValue()).getValue()); + } + else if (stu3Component.getName().equals("stu3CodePart")) { + assertTrue(stu3Component.getValue() instanceof CodeType); + assertEquals("active", ((CodeType) stu3Component.getValue()).getValueAsString()); + } + else if (stu3Component.getName().equals("stu3DatePart")) { + assertTrue(stu3Component.getValue() instanceof DateType); + assertEquals("2012-12-31", ((DateType) stu3Component.getValue()).getValueAsString()); + } + else if (stu3Component.getName().equals("stu3DateTimePart")) { + assertTrue(stu3Component.getValue() instanceof DateTimeType); + assertEquals("2015-02-07T13:28:17-05:00", ((DateTimeType) stu3Component.getValue()).getValueAsString()); + } + else if (stu3Component.getName().equals("stu3DecimalPart")) { + assertTrue(stu3Component.getValue() instanceof DecimalType); + assertEquals("72.42", ((DecimalType) stu3Component.getValue()).getValueAsString()); + } + else if (stu3Component.getName().equals("stu3IdPart")) { + assertTrue(stu3Component.getValue() instanceof IdType); + assertEquals("example-id", ((IdType) stu3Component.getValue()).getValueAsString()); + } + else if (stu3Component.getName().equals("stu3InstantPart")) { + assertTrue(stu3Component.getValue() instanceof InstantType); + assertEquals("2015-02-07T13:28:17.239+02:00", ((InstantType) stu3Component.getValue()).getValueAsString()); + } + else if (stu3Component.getName().equals("stu3IntegerPart")) { + assertTrue(stu3Component.getValue() instanceof IntegerType); + assertEquals(72, ((IntegerType) stu3Component.getValue()).getValue()); + } + else if (stu3Component.getName().equals("stu3OidPart")) { + assertTrue(stu3Component.getValue() instanceof OidType); + assertEquals("urn:oid:1.2.3.4.5", ((OidType) stu3Component.getValue()).getValueAsString()); + } + else if (stu3Component.getName().equals("stu3PositiveIntPart")) { + assertTrue(stu3Component.getValue() instanceof PositiveIntType); + assertEquals(1, ((PositiveIntType) stu3Component.getValue()).getValue()); + } + else if (stu3Component.getName().equals("stu3StringPart")) { + assertTrue(stu3Component.getValue() instanceof StringType); + assertEquals("example string", ((StringType) stu3Component.getValue()).getValueAsString()); + } + else if (stu3Component.getName().equals("stu3TimePart")) { + assertTrue(stu3Component.getValue() instanceof TimeType); + assertEquals("12:30:30.500", ((TimeType) stu3Component.getValue()).getValueAsString()); + } + else if (stu3Component.getName().equals("stu3UnsignedIntPart")) { + assertTrue(stu3Component.getValue() instanceof UnsignedIntType); + assertEquals(0, ((UnsignedIntType) stu3Component.getValue()).getValue()); + } + else if (stu3Component.getName().equals("stu3UriPart")) { + assertTrue(stu3Component.getValue() instanceof UriType); + assertEquals("news:comp.infosystems.www.servers.unix", ((UriType) stu3Component.getValue()).getValueAsString()); + } + } + } + + @Test + void getParameterByNameTest() { + org.hl7.fhir.dstu3.model.Parameters parameters = parameters( + stringPart("testName", "testValue"), + stringPart("testName1", "testValue1") + ); + + List parts = getPartsByName(parameters, "testName"); + assertEquals(1, parts.size()); + + parameters = parameters( + stringPart("testName", "testValue"), + stringPart("testName", "testValue"), + stringPart("testName1", "testValue1") + ); + + parts = getPartsByName(parameters, "testName"); + assertEquals(2, parts.size()); + } +} diff --git a/core/src/test/java/org/opencds/cqf/ruler/utility/r4/ParametersTest.java b/core/src/test/java/org/opencds/cqf/ruler/utility/r4/ParametersTest.java new file mode 100644 index 000000000..040407d7a --- /dev/null +++ b/core/src/test/java/org/opencds/cqf/ruler/utility/r4/ParametersTest.java @@ -0,0 +1,171 @@ +package org.opencds.cqf.ruler.utility.r4; + +import org.hl7.fhir.r4.model.Base64BinaryType; +import org.hl7.fhir.r4.model.BooleanType; +import org.hl7.fhir.r4.model.CanonicalType; +import org.hl7.fhir.r4.model.CodeType; +import org.hl7.fhir.r4.model.DateTimeType; +import org.hl7.fhir.r4.model.DateType; +import org.hl7.fhir.r4.model.DecimalType; +import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.InstantType; +import org.hl7.fhir.r4.model.IntegerType; +import org.hl7.fhir.r4.model.MarkdownType; +import org.hl7.fhir.r4.model.OidType; +import org.hl7.fhir.r4.model.PositiveIntType; +import org.hl7.fhir.r4.model.StringType; +import org.hl7.fhir.r4.model.TimeType; +import org.hl7.fhir.r4.model.Type; +import org.hl7.fhir.r4.model.UnsignedIntType; +import org.hl7.fhir.r4.model.UriType; +import org.hl7.fhir.r4.model.UrlType; +import org.hl7.fhir.r4.model.UuidType; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opencds.cqf.ruler.utility.r4.Parameters.getPartsByName; +import static org.opencds.cqf.ruler.utility.r4.Parameters.base64BinaryPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.booleanPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.canonicalPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.codePart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.datePart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.dateTimePart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.decimalPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.idPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.instantPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.integerPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.markdownPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.oidPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.positiveIntPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.timePart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.unsignedIntPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.uriPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.urlPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.uuidPart; + +class ParametersTest { + @Test + void testParametersPartTypes() { + org.hl7.fhir.r4.model.Parameters parameters = parameters( + base64BinaryPart("r4Base64BinaryPart", "SGVsbG8gV29ybGQh"), + booleanPart("r4BooleanPart", true), + canonicalPart("r4CanonicalPart", "https://example.com/Library/example-library"), + codePart("r4CodePart", "active"), + datePart("r4DatePart", "2012-12-31"), + dateTimePart("r4DateTimePart", "2015-02-07T13:28:17-05:00"), + decimalPart("r4DecimalPart", 72.42), + idPart("r4IdPart", "example-id"), + instantPart("r4InstantPart", "2015-02-07T13:28:17.239+02:00"), + integerPart("r4IntegerPart", 72), + markdownPart("r4MarkdownPart", "## Markdown Title"), + oidPart("r4OidPart", "urn:oid:1.2.3.4.5"), + positiveIntPart("r4PositiveIntPart", 1), + stringPart("r4StringPart", "example string"), + timePart("r4TimePart", "12:30:30.500"), + unsignedIntPart("r4UnsignedIntPart", 0), + uriPart("r4UriPart", "s:comp.infosystems.www.servers.unix"), + urlPart("r4UrlPart", "https://example.com"), + uuidPart("r4UuidPart", "urn:uuid:c757873d-ec9a-4326-a141-556f43239520")); + + Type r4Type = parameters.getParameter("r4Base64BinaryPart"); + assertTrue(r4Type instanceof Base64BinaryType); + assertEquals("SGVsbG8gV29ybGQh", ((Base64BinaryType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4BooleanPart"); + assertTrue(r4Type instanceof BooleanType); + assertTrue(((BooleanType) r4Type).getValue()); + + r4Type = parameters.getParameter("r4CanonicalPart"); + assertTrue(r4Type instanceof CanonicalType); + assertEquals("https://example.com/Library/example-library", ((CanonicalType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4CodePart"); + assertTrue(r4Type instanceof CodeType); + assertEquals("active", ((CodeType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4DatePart"); + assertTrue(r4Type instanceof DateType); + assertEquals("2012-12-31", ((DateType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4DateTimePart"); + assertTrue(r4Type instanceof DateTimeType); + assertEquals("2015-02-07T13:28:17-05:00", ((DateTimeType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4DecimalPart"); + assertTrue(r4Type instanceof DecimalType); + assertEquals("72.42", ((DecimalType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4IdPart"); + assertTrue(r4Type instanceof IdType); + assertEquals("example-id", ((IdType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4InstantPart"); + assertTrue(r4Type instanceof InstantType); + assertEquals("2015-02-07T13:28:17.239+02:00", ((InstantType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4IntegerPart"); + assertTrue(r4Type instanceof IntegerType); + assertEquals(72, ((IntegerType) r4Type).getValue()); + + r4Type = parameters.getParameter("r4MarkdownPart"); + assertTrue(r4Type instanceof MarkdownType); + assertEquals("## Markdown Title", ((MarkdownType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4OidPart"); + assertTrue(r4Type instanceof OidType); + assertEquals("urn:oid:1.2.3.4.5", ((OidType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4PositiveIntPart"); + assertTrue(r4Type instanceof PositiveIntType); + assertEquals(1, ((PositiveIntType) r4Type).getValue()); + + r4Type = parameters.getParameter("r4StringPart"); + assertTrue(r4Type instanceof StringType); + assertEquals("example string", ((StringType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4TimePart"); + assertTrue(r4Type instanceof TimeType); + assertEquals("12:30:30.500", ((TimeType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4UnsignedIntPart"); + assertTrue(r4Type instanceof UnsignedIntType); + assertEquals(0, ((UnsignedIntType) r4Type).getValue()); + + r4Type = parameters.getParameter("r4UriPart"); + assertTrue(r4Type instanceof UriType); + assertEquals("s:comp.infosystems.www.servers.unix", ((UriType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4UrlPart"); + assertTrue(r4Type instanceof UrlType); + assertEquals("https://example.com", ((UrlType) r4Type).getValueAsString()); + + r4Type = parameters.getParameter("r4UuidPart"); + assertTrue(r4Type instanceof UuidType); + assertEquals("urn:uuid:c757873d-ec9a-4326-a141-556f43239520", ((UuidType) r4Type).getValueAsString()); + } + + @Test + void getParameterByNameTest() { + org.hl7.fhir.r4.model.Parameters parameters = parameters( + stringPart("testName", "testValue"), + stringPart("testName1", "testValue1") + ); + + List parts = getPartsByName(parameters, "testName"); + assertEquals(1, parts.size()); + + parameters = parameters( + stringPart("testName", "testValue"), + stringPart("testName", "testValue"), + stringPart("testName1", "testValue1") + ); + + parts = getPartsByName(parameters, "testName"); + assertEquals(2, parts.size()); + } +} diff --git a/core/src/test/java/org/opencds/cqf/ruler/utility/r5/ParametersTest.java b/core/src/test/java/org/opencds/cqf/ruler/utility/r5/ParametersTest.java new file mode 100644 index 000000000..ff307a510 --- /dev/null +++ b/core/src/test/java/org/opencds/cqf/ruler/utility/r5/ParametersTest.java @@ -0,0 +1,157 @@ +package org.opencds.cqf.ruler.utility.r5; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opencds.cqf.ruler.utility.r5.Parameters.getPartsByName; +import static org.opencds.cqf.ruler.utility.r5.Parameters.base64BinaryPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.booleanPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.canonicalPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.codePart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.datePart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.dateTimePart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.decimalPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.idPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.instantPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.integer64Part; +import static org.opencds.cqf.ruler.utility.r5.Parameters.integerPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.markdownPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.oidPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r5.Parameters.positiveIntPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.stringPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.timePart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.unsignedIntPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.uriPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.urlPart; +import static org.opencds.cqf.ruler.utility.r5.Parameters.uuidPart; + +class ParametersTest { + @Test + void testParametersPartTypes() { + org.hl7.fhir.r5.model.Parameters parameters = parameters( + base64BinaryPart("r5Base64BinaryPart", "SGVsbG8gV29ybGQh"), + booleanPart("r5BooleanPart", true), + canonicalPart("r5CanonicalPart", "https://example.com/Library/example-library"), + codePart("r5CodePart", "active"), + datePart("r5DatePart", "2012-12-31"), + dateTimePart("r5DateTimePart", "2015-02-07T13:28:17-05:00"), + decimalPart("r5DecimalPart", 72.42), + idPart("r5IdPart", "example-id"), + instantPart("r5InstantPart", "2015-02-07T13:28:17.239+02:00"), + integerPart("r5IntegerPart", 72), + integer64Part("r5Integer64Part", 9223372036854775807L), + markdownPart("r5MarkdownPart", "## Markdown Title"), + oidPart("r5OidPart", "urn:oid:1.2.3.4.5"), + positiveIntPart("r5PositiveIntPart", 1), + stringPart("r5StringPart", "example string"), + timePart("r5TimePart", "12:30:30.500"), + unsignedIntPart("r5UnsignedIntPart", 0), + uriPart("r5UriPart", "s:comp.infosystems.www.servers.unix"), + urlPart("r5UrlPart", "https://example.com"), + uuidPart("r5UuidPart", "urn:uuid:c757873d-ec9a-4326-a141-556f43239520")); + + org.hl7.fhir.r5.model.DataType r5Type = parameters.getParameter("r5Base64BinaryPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.Base64BinaryType); + assertEquals("SGVsbG8gV29ybGQh", ((org.hl7.fhir.r5.model.Base64BinaryType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5BooleanPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.BooleanType); + assertTrue(((org.hl7.fhir.r5.model.BooleanType) r5Type).getValue()); + + r5Type = parameters.getParameter("r5CanonicalPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.CanonicalType); + assertEquals("https://example.com/Library/example-library", ((org.hl7.fhir.r5.model.CanonicalType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5CodePart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.CodeType); + assertEquals("active", ((org.hl7.fhir.r5.model.CodeType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5DatePart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.DateType); + assertEquals("2012-12-31", ((org.hl7.fhir.r5.model.DateType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5DateTimePart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.DateTimeType); + assertEquals("2015-02-07T13:28:17-05:00", ((org.hl7.fhir.r5.model.DateTimeType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5DecimalPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.DecimalType); + assertEquals("72.42", ((org.hl7.fhir.r5.model.DecimalType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5IdPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.IdType); + assertEquals("example-id", ((org.hl7.fhir.r5.model.IdType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5InstantPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.InstantType); + assertEquals("2015-02-07T13:28:17.239+02:00", ((org.hl7.fhir.r5.model.InstantType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5IntegerPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.IntegerType); + assertEquals(72, ((org.hl7.fhir.r5.model.IntegerType) r5Type).getValue()); + + r5Type = parameters.getParameter("r5Integer64Part"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.Integer64Type); + assertEquals(9223372036854775807L, ((org.hl7.fhir.r5.model.Integer64Type) r5Type).getValue()); + + r5Type = parameters.getParameter("r5MarkdownPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.MarkdownType); + assertEquals("## Markdown Title", ((org.hl7.fhir.r5.model.MarkdownType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5OidPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.OidType); + assertEquals("urn:oid:1.2.3.4.5", ((org.hl7.fhir.r5.model.OidType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5PositiveIntPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.PositiveIntType); + assertEquals(1, ((org.hl7.fhir.r5.model.PositiveIntType) r5Type).getValue()); + + r5Type = parameters.getParameter("r5StringPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.StringType); + assertEquals("example string", ((org.hl7.fhir.r5.model.StringType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5TimePart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.TimeType); + assertEquals("12:30:30.500", ((org.hl7.fhir.r5.model.TimeType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5UnsignedIntPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.UnsignedIntType); + assertEquals(0, ((org.hl7.fhir.r5.model.UnsignedIntType) r5Type).getValue()); + + r5Type = parameters.getParameter("r5UriPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.UriType); + assertEquals("s:comp.infosystems.www.servers.unix", ((org.hl7.fhir.r5.model.UriType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5UrlPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.UrlType); + assertEquals("https://example.com", ((org.hl7.fhir.r5.model.UrlType) r5Type).getValueAsString()); + + r5Type = parameters.getParameter("r5UuidPart"); + assertTrue(r5Type instanceof org.hl7.fhir.r5.model.UuidType); + assertEquals("urn:uuid:c757873d-ec9a-4326-a141-556f43239520", ((org.hl7.fhir.r5.model.UuidType) r5Type).getValueAsString()); + } + + @Test + void getParameterByNameTest() { + org.hl7.fhir.r5.model.Parameters parameters = parameters( + stringPart("testName", "testValue"), + stringPart("testName1", "testValue1") + ); + + List parts = getPartsByName(parameters, "testName"); + assertEquals(1, parts.size()); + + parameters = parameters( + stringPart("testName", "testValue"), + stringPart("testName", "testValue"), + stringPart("testName1", "testValue1") + ); + + parts = getPartsByName(parameters, "testName"); + assertEquals(2, parts.size()); + } +} diff --git a/example/src/test/java/com/example/HelloWorldProviderIT.java b/example/src/test/java/com/example/HelloWorldProviderIT.java index fff5b08d4..62c86e794 100644 --- a/example/src/test/java/com/example/HelloWorldProviderIT.java +++ b/example/src/test/java/com/example/HelloWorldProviderIT.java @@ -6,18 +6,17 @@ import org.hl7.fhir.r4.model.OperationOutcome; import org.hl7.fhir.r4.model.Parameters; import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { HelloWorldProviderIT.class, - HelloWorldConfig.class }, properties = { - "hapi.fhir.fhir_version=r4", - "hello.world.message=Howdy" - }) -public class HelloWorldProviderIT extends RestIntegrationTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { HelloWorldProviderIT.class, HelloWorldConfig.class }, + properties = { "hapi.fhir.fhir_version=r4", "hello.world.message=Howdy" }) +class HelloWorldProviderIT extends RestIntegrationTest { // @Test @Disabled(value = "There's a database configuration error that needs to be sorted out") - public void testHelloWorldConfig() { + void testHelloWorldConfig() { var outcome = getClient() .operation() .onServer() diff --git a/plugin/case-reporting/src/test/java/org/opencds/cqf/ruler/casereporting/r4/MeasureDataProcessProviderIT.java b/plugin/case-reporting/src/test/java/org/opencds/cqf/ruler/casereporting/r4/MeasureDataProcessProviderIT.java index 2c1c67fb4..d212dc9eb 100644 --- a/plugin/case-reporting/src/test/java/org/opencds/cqf/ruler/casereporting/r4/MeasureDataProcessProviderIT.java +++ b/plugin/case-reporting/src/test/java/org/opencds/cqf/ruler/casereporting/r4/MeasureDataProcessProviderIT.java @@ -1,8 +1,8 @@ package org.opencds.cqf.ruler.casereporting.r4; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.io.IOException; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.MeasureReport; @@ -12,30 +12,26 @@ import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { MeasureDataProcessProviderIT.class, - CaseReportingConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) -public class MeasureDataProcessProviderIT extends RestIntegrationTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { MeasureDataProcessProviderIT.class, CaseReportingConfig.class }, + properties = { "hapi.fhir.fhir_version=r4" }) +class MeasureDataProcessProviderIT extends RestIntegrationTest { @Test - public void testMeasureReportExtractLineListData() throws IOException { - - String packagePrefix = "org/opencds/cqf/ruler/casereporting/r4/"; - loadResource(packagePrefix + "Patient-ra-patient01.json"); - loadResource(packagePrefix + "Patient-ra-patient02.json"); - loadResource(packagePrefix + "Patient-ra-patient03.json"); - loadResource(packagePrefix + "Group-ra-group00.json"); - loadResource(packagePrefix + "Group-ra-group01.json"); - loadResource(packagePrefix + "Group-ra-group02.json"); - loadResource(packagePrefix + "MeasureReport-ra-measurereport01.json"); - - MeasureReport measureReport = getClient().read().resource(MeasureReport.class).withId("ra-measurereport01") - .execute(); + void testMeasureReportExtractLineListData() { + loadResource("Patient-ra-patient01.json"); + loadResource("Patient-ra-patient02.json"); + loadResource("Patient-ra-patient03.json"); + loadResource("Group-ra-group00.json"); + loadResource("Group-ra-group01.json"); + loadResource("Group-ra-group02.json"); + loadResource("MeasureReport-ra-measurereport01.json"); + + MeasureReport measureReport = getClient().read().resource(MeasureReport.class) + .withId("ra-measurereport01").execute(); assertNotNull(measureReport); - Parameters params = new Parameters(); - params.addParameter().setName("measureReport").setResource(measureReport); - params.addParameter().setName("subjectList").setValue(null); + Parameters params = parameters(part("measureReport", measureReport)); Bundle returnBundle = getClient().operation().onType(MeasureReport.class) .named("$extract-line-list-data") diff --git a/plugin/case-reporting/src/test/java/org/opencds/cqf/ruler/casereporting/r4/ProcessMessageProviderIT.java b/plugin/case-reporting/src/test/java/org/opencds/cqf/ruler/casereporting/r4/ProcessMessageProviderIT.java index 81d075ac6..398a590f3 100644 --- a/plugin/case-reporting/src/test/java/org/opencds/cqf/ruler/casereporting/r4/ProcessMessageProviderIT.java +++ b/plugin/case-reporting/src/test/java/org/opencds/cqf/ruler/casereporting/r4/ProcessMessageProviderIT.java @@ -2,8 +2,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; -import java.io.IOException; - import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Encounter; import org.hl7.fhir.r4.model.MeasureReport; @@ -14,16 +12,13 @@ import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { ProcessMessageProviderIT.class, - CaseReportingConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) -public class ProcessMessageProviderIT extends RestIntegrationTest { - +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { ProcessMessageProviderIT.class, CaseReportingConfig.class }, + properties = { "hapi.fhir.fhir_version=r4" }) +class ProcessMessageProviderIT extends RestIntegrationTest { @Test - public void testProcessMessage() throws IOException { - - String packagePrefix = "org/opencds/cqf/ruler/casereporting/r4/"; - - Bundle bundle = (Bundle) loadResource(packagePrefix + "example-eicr.json"); + void testProcessMessage() { + Bundle bundle = (Bundle) loadResource("example-eicr.json"); Bundle returnBundle = getClient().operation().onServer() .named("$process-message-bundle") @@ -32,12 +27,8 @@ public void testProcessMessage() throws IOException { .execute(); assertNotNull(returnBundle); - assertNotNull( - getClient().read().resource(Patient.class).withId("patient-12742542").execute()); - assertNotNull( - getClient().read().resource(Encounter.class).withId("encounter-97953898").execute()); - assertNotNull( - getClient().read().resource(MeasureReport.class).withId("diabetes-mp").execute()); + assertNotNull(getClient().read().resource(Patient.class).withId("patient-12742542").execute()); + assertNotNull(getClient().read().resource(Encounter.class).withId("encounter-97953898").execute()); + assertNotNull(getClient().read().resource(MeasureReport.class).withId("diabetes-mp").execute()); } - } diff --git a/plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Group-ra-group00.json b/plugin/case-reporting/src/test/resources/Group-ra-group00.json similarity index 100% rename from plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Group-ra-group00.json rename to plugin/case-reporting/src/test/resources/Group-ra-group00.json diff --git a/plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Group-ra-group01.json b/plugin/case-reporting/src/test/resources/Group-ra-group01.json similarity index 100% rename from plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Group-ra-group01.json rename to plugin/case-reporting/src/test/resources/Group-ra-group01.json diff --git a/plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Group-ra-group02.json b/plugin/case-reporting/src/test/resources/Group-ra-group02.json similarity index 100% rename from plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Group-ra-group02.json rename to plugin/case-reporting/src/test/resources/Group-ra-group02.json diff --git a/plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/MeasureReport-ra-measurereport01.json b/plugin/case-reporting/src/test/resources/MeasureReport-ra-measurereport01.json similarity index 100% rename from plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/MeasureReport-ra-measurereport01.json rename to plugin/case-reporting/src/test/resources/MeasureReport-ra-measurereport01.json diff --git a/plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Observation-ra-obs21pat01.json b/plugin/case-reporting/src/test/resources/Observation-ra-obs21pat01.json similarity index 100% rename from plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Observation-ra-obs21pat01.json rename to plugin/case-reporting/src/test/resources/Observation-ra-obs21pat01.json diff --git a/plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Patient-ra-patient01.json b/plugin/case-reporting/src/test/resources/Patient-ra-patient01.json similarity index 100% rename from plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Patient-ra-patient01.json rename to plugin/case-reporting/src/test/resources/Patient-ra-patient01.json diff --git a/plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Patient-ra-patient02.json b/plugin/case-reporting/src/test/resources/Patient-ra-patient02.json similarity index 100% rename from plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Patient-ra-patient02.json rename to plugin/case-reporting/src/test/resources/Patient-ra-patient02.json diff --git a/plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Patient-ra-patient03.json b/plugin/case-reporting/src/test/resources/Patient-ra-patient03.json similarity index 100% rename from plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Patient-ra-patient03.json rename to plugin/case-reporting/src/test/resources/Patient-ra-patient03.json diff --git a/plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Practitioner-ra-prac01pat01.json b/plugin/case-reporting/src/test/resources/Practitioner-ra-prac01pat01.json similarity index 100% rename from plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/Practitioner-ra-prac01pat01.json rename to plugin/case-reporting/src/test/resources/Practitioner-ra-prac01pat01.json diff --git a/plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/example-eicr.json b/plugin/case-reporting/src/test/resources/example-eicr.json similarity index 100% rename from plugin/case-reporting/src/test/resources/org/opencds/cqf/ruler/casereporting/r4/example-eicr.json rename to plugin/case-reporting/src/test/resources/example-eicr.json diff --git a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/dstu3/CdsHooksUtil.java b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/dstu3/CdsHooksUtil.java index 7b7148ee1..d27e812eb 100644 --- a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/dstu3/CdsHooksUtil.java +++ b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/dstu3/CdsHooksUtil.java @@ -20,18 +20,21 @@ import java.util.HashSet; import java.util.ArrayList; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.part; public class CdsHooksUtil { + private CdsHooksUtil() { + } + // NOTE: Making an assumption here that the parameter in the CQL will be named "ContextPrescriptions" public static Parameters getParameters(JsonObject contextResources) { - Parameters parameters = newParameters(); + Parameters parameters = parameters(); Bundle contextBundle = new JsonParser(FhirContext.forDstu3Cached(), new LenientErrorHandler()) .parseResource(Bundle.class, contextResources.toString()); contextBundle.getEntry().forEach( - x -> parameters.addParameter(newPart("ContextPrescriptions", x.getResource()))); + x -> parameters.addParameter(part("ContextPrescriptions", x.getResource()))); if (parameters.getParameter().size() == 1) { Extension listExtension = new Extension( "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-parameterDefinition", diff --git a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/r4/CdsHooksUtil.java b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/r4/CdsHooksUtil.java index 47940e345..386795c1e 100644 --- a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/r4/CdsHooksUtil.java +++ b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/r4/CdsHooksUtil.java @@ -20,18 +20,21 @@ import java.util.HashSet; import java.util.ArrayList; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; public class CdsHooksUtil { + private CdsHooksUtil() { + } + // NOTE: Making an assumption here that the parameter in the CQL will be named "ContextPrescriptions" public static Parameters getParameters(JsonObject contextResources) { - Parameters parameters = newParameters(); + Parameters parameters = parameters(); Bundle contextBundle = new JsonParser(FhirContext.forR4Cached(), new LenientErrorHandler()) .parseResource(Bundle.class, contextResources.toString()); contextBundle.getEntry().forEach( - x -> parameters.addParameter(newPart("ContextPrescriptions", x.getResource()))); + x -> parameters.addParameter(part("ContextPrescriptions", x.getResource()))); if (parameters.getParameter().size() == 1) { Extension listExtension = new Extension( "http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-parameterDefinition", diff --git a/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/dstu3/CdsHooksServletIT.java b/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/dstu3/CdsHooksServletIT.java index 030f3287f..44237081f 100644 --- a/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/dstu3/CdsHooksServletIT.java +++ b/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/dstu3/CdsHooksServletIT.java @@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, @@ -49,15 +50,18 @@ void beforeEach() { } @Test - void testGetCdsServices() throws IOException { - CloseableHttpClient httpClient = HttpClients.createDefault(); - HttpGet request = new HttpGet(ourCdsBase); - request.addHeader("Content-Type", "application/json"); - assertEquals(200, httpClient.execute(request).getStatusLine().getStatusCode()); + void testGetCdsServices() { + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpGet request = new HttpGet(ourCdsBase); + request.addHeader("Content-Type", "application/json"); + assertEquals(200, httpClient.execute(request).getStatusLine().getStatusCode()); + } catch (IOException ioe) { + fail(ioe.getMessage()); + } } @Test - void testCdsServicesRequest() throws IOException { + void testCdsServicesRequest() { // Server Load loadTransaction("HelloWorldPatientView-bundle.json"); loadResource("hello-world-patient-view-patient.json"); @@ -96,42 +100,45 @@ void testCdsServicesRequest() throws IOException { jsonRequestObject.addProperty("fhirServer", getServerBase()); // Setup Client - CloseableHttpClient httpClient = HttpClients.createDefault(); - HttpPost request = new HttpPost(ourCdsBase + "/hello-world-patient-view"); - request.setEntity(new StringEntity(jsonRequestObject.toString())); - request.addHeader("Content-Type", "application/json"); - - CloseableHttpResponse response = httpClient.execute(request); - String result = EntityUtils.toString(response.getEntity()); - - Gson gsonResponse = new Gson(); - JsonObject jsonResponseObject = gsonResponse.fromJson(result, JsonObject.class); - - // Ensure Cards - assertNotNull(jsonResponseObject.get("cards")); - JsonArray cards = jsonResponseObject.get("cards").getAsJsonArray(); - - // Ensure Patient Detail - assertNotNull(cards.get(0).getAsJsonObject().get("detail")); - String patientName = cards.get(0).getAsJsonObject().get("detail").getAsString(); - assertEquals("The CDS Service is alive and communicating successfully!", patientName); - - // Ensure Summary - assertNotNull(cards.get(0)); - assertNotNull(cards.get(0).getAsJsonObject().get("summary")); - String summary = cards.get(0).getAsJsonObject().get("summary").getAsString(); - assertEquals("Hello World!", summary); - - // Ensure Activity Definition / Suggestions - assertNotNull(cards.get(0).getAsJsonObject().get("suggestions")); - JsonArray suggestions = cards.get(0).getAsJsonObject().get("suggestions").getAsJsonArray(); - assertNotNull(suggestions.get(0)); - assertNotNull(suggestions.get(0).getAsJsonObject().get("actions")); - JsonArray actions = suggestions.get(0).getAsJsonObject().get("actions").getAsJsonArray(); - assertNotNull(actions.get(0)); - assertNotNull(actions.get(0).getAsJsonObject().get("description")); - String suggestionsDescription = actions.get(0).getAsJsonObject().get("description").getAsString(); - assertEquals("The CDS Service is alive and communicating successfully!", suggestionsDescription); + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpPost request = new HttpPost(ourCdsBase + "/hello-world-patient-view"); + request.setEntity(new StringEntity(jsonRequestObject.toString())); + request.addHeader("Content-Type", "application/json"); + + CloseableHttpResponse response = httpClient.execute(request); + String result = EntityUtils.toString(response.getEntity()); + + Gson gsonResponse = new Gson(); + JsonObject jsonResponseObject = gsonResponse.fromJson(result, JsonObject.class); + + // Ensure Cards + assertNotNull(jsonResponseObject.get("cards")); + JsonArray cards = jsonResponseObject.get("cards").getAsJsonArray(); + + // Ensure Patient Detail + assertNotNull(cards.get(0).getAsJsonObject().get("detail")); + String patientName = cards.get(0).getAsJsonObject().get("detail").getAsString(); + assertEquals("The CDS Service is alive and communicating successfully!", patientName); + + // Ensure Summary + assertNotNull(cards.get(0)); + assertNotNull(cards.get(0).getAsJsonObject().get("summary")); + String summary = cards.get(0).getAsJsonObject().get("summary").getAsString(); + assertEquals("Hello World!", summary); + + // Ensure Activity Definition / Suggestions + assertNotNull(cards.get(0).getAsJsonObject().get("suggestions")); + JsonArray suggestions = cards.get(0).getAsJsonObject().get("suggestions").getAsJsonArray(); + assertNotNull(suggestions.get(0)); + assertNotNull(suggestions.get(0).getAsJsonObject().get("actions")); + JsonArray actions = suggestions.get(0).getAsJsonObject().get("actions").getAsJsonArray(); + assertNotNull(actions.get(0)); + assertNotNull(actions.get(0).getAsJsonObject().get("description")); + String suggestionsDescription = actions.get(0).getAsJsonObject().get("description").getAsString(); + assertEquals("The CDS Service is alive and communicating successfully!", suggestionsDescription); + } catch (IOException ioe) { + fail(ioe.getMessage()); + } } } diff --git a/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/r4/CdsHooksServletIT.java b/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/r4/CdsHooksServletIT.java index b977d8030..9be6cfc87 100644 --- a/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/r4/CdsHooksServletIT.java +++ b/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/r4/CdsHooksServletIT.java @@ -34,9 +34,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; @ExtendWith(SpringExtension.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = - { Application.class, CdsHooksConfig.class }, - properties = {"hapi.fhir.fhir_version=r4", "hapi.fhir.security.basic_auth.enabled=false"}) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { Application.class, CdsHooksConfig.class }, + properties = {"hapi.fhir.fhir_version=r4", "hapi.fhir.security.basic_auth.enabled=false"}) class CdsHooksServletIT extends RestIntegrationTest { @Autowired CdsServicesCache cdsServicesCache; diff --git a/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/r4/OpioidRecommendation08IT.java b/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/r4/OpioidRecommendation08IT.java index df14a3806..65a424ac3 100644 --- a/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/r4/OpioidRecommendation08IT.java +++ b/plugin/cds-hooks/src/test/java/org/opencds/cqf/ruler/plugin/cdshooks/r4/OpioidRecommendation08IT.java @@ -41,7 +41,6 @@ void beforeEach() { ourCdsBase = "http://localhost:" + getPort() + "/cds-services"; } - /* @Test void testOpioidRecommendation08OrderSignWithoutPrefetch() { loadTransaction("opioidcds-08-order-sign-bundle.json"); @@ -71,7 +70,6 @@ void testOpioidRecommendation08OrderSignWithoutPrefetch() { } @Test - void testOpioidRecommendation08OrderSignWithPrefetch() { loadTransaction("opioidcds-08-order-sign-bundle.json"); loadResource("opioidcds-08-medication.json"); @@ -126,5 +124,4 @@ void validate(String cardsString) { assertTrue(card.get("links").isJsonArray()); assertEquals(2, card.get("links").getAsJsonArray().size()); } - */ } diff --git a/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionProvider.java b/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionProvider.java index 2e5c3c2a8..110fe8a9c 100644 --- a/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionProvider.java +++ b/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionProvider.java @@ -1,7 +1,7 @@ package org.opencds.cqf.ruler.cpg.dstu3.provider; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.part; import java.util.Collections; import java.util.List; @@ -36,7 +36,9 @@ import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; +import org.springframework.beans.factory.annotation.Configurable; +@Configurable public class CqlExecutionProvider extends DaoRegistryOperationProvider { @Autowired @@ -214,18 +216,18 @@ public Parameters evaluate( "subject", "expression", "parameters", "library", "useServerData", "data", "prefetchData", "dataEndpoint", "contentEndpoint", "terminologyEndpoint", "content"); if (outcome != null) { - return newParameters(newPart("error", (OperationOutcome) outcome)); + return parameters(part("error", (OperationOutcome) outcome)); } } if (prefetchData != null) { - return newParameters(newPart("invalid parameters", + return parameters(part("invalid parameters", (OperationOutcome) evaluationHelper.createIssue( "error", "prefetchData is not yet supported"))); } if (expression == null && content == null) { - return newParameters(newPart("invalid parameters", + return parameters(part("invalid parameters", (OperationOutcome) evaluationHelper.createIssue("error", "The $cql operation requires the expression parameter and/or content parameter to exist"))); } @@ -253,7 +255,7 @@ public Parameters evaluate( expression == null ? null : Collections.singleton(expression)); } catch (Exception e) { e.printStackTrace(); - return newParameters(newPart("evaluation error", + return parameters(part("evaluation error", (OperationOutcome) evaluationHelper.createIssue("error", e.getMessage()))); } } diff --git a/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/dstu3/provider/LibraryEvaluationProvider.java b/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/dstu3/provider/LibraryEvaluationProvider.java index d86bb2216..831700a60 100644 --- a/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/dstu3/provider/LibraryEvaluationProvider.java +++ b/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/dstu3/provider/LibraryEvaluationProvider.java @@ -1,7 +1,7 @@ package org.opencds.cqf.ruler.cpg.dstu3.provider; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.part; import java.util.HashSet; import java.util.List; @@ -35,7 +35,9 @@ import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; +import org.springframework.beans.factory.annotation.Configurable; +@Configurable public class LibraryEvaluationProvider extends DaoRegistryOperationProvider { @Autowired @@ -164,11 +166,11 @@ public Parameters evaluate( "prefetchData", "dataEndpoint", "contentEndpoint", "terminologyEndpoint"); if (outcome != null) - return newParameters(newPart("error", (OperationOutcome) outcome)); + return parameters(part("error", (OperationOutcome) outcome)); } if (prefetchData != null) - return newParameters(newPart("invalid parameters", + return parameters(part("invalid parameters", (OperationOutcome) evaluationHelper.createIssue("error", "prefetchData is not yet supported"))); @@ -181,7 +183,7 @@ public Parameters evaluate( expression == null ? null : new HashSet<>(expression)); } catch (Exception e) { e.printStackTrace(); - return newParameters(newPart("evaluation error", + return parameters(part("evaluation error", (OperationOutcome) evaluationHelper.createIssue("error", e.getMessage()))); } } diff --git a/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionProvider.java b/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionProvider.java index 19cfe84d4..f0f5060a8 100644 --- a/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionProvider.java +++ b/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionProvider.java @@ -1,7 +1,7 @@ package org.opencds.cqf.ruler.cpg.r4.provider; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; import java.util.Collections; import java.util.List; @@ -223,18 +223,18 @@ public Parameters evaluate( "data", "prefetchData", "dataEndpoint", "contentEndpoint", "terminologyEndpoint", "content"); if (outcome != null) { - return newParameters(newPart("invalid parameters", (OperationOutcome) outcome)); + return parameters(part("invalid parameters", (OperationOutcome) outcome)); } } if (prefetchData != null) { - return newParameters(newPart("invalid parameters", + return parameters(part("invalid parameters", (OperationOutcome) evaluationHelper.createIssue( "warning", "prefetchData is not yet supported"))); } if (expression == null && content == null) { - return newParameters(newPart("invalid parameters", + return parameters(part("invalid parameters", (OperationOutcome) evaluationHelper.createIssue("error", "The $cql operation requires the expression parameter and/or content parameter to exist"))); } @@ -262,7 +262,7 @@ public Parameters evaluate( expression == null ? null : Collections.singleton(expression)); } catch (Exception e) { e.printStackTrace(); - return newParameters(newPart("evaluation error", + return parameters(part("evaluation error", (OperationOutcome) evaluationHelper.createIssue("error", e.getMessage()))); } } diff --git a/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/r4/provider/LibraryEvaluationProvider.java b/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/r4/provider/LibraryEvaluationProvider.java index 7b081c813..8d5dbd7b1 100644 --- a/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/r4/provider/LibraryEvaluationProvider.java +++ b/plugin/cpg/src/main/java/org/opencds/cqf/ruler/cpg/r4/provider/LibraryEvaluationProvider.java @@ -1,7 +1,7 @@ package org.opencds.cqf.ruler.cpg.r4.provider; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; import java.util.HashSet; import java.util.List; @@ -35,7 +35,9 @@ import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; +import org.springframework.beans.factory.annotation.Configurable; +@Configurable public class LibraryEvaluationProvider extends DaoRegistryOperationProvider { @Autowired @@ -164,12 +166,12 @@ public Parameters evaluate( "prefetchData", "dataEndpoint", "contentEndpoint", "terminologyEndpoint"); if (outcome != null) { - return newParameters(newPart("error", (OperationOutcome) outcome)); + return parameters(part("error", (OperationOutcome) outcome)); } } if (prefetchData != null) { - return newParameters(newPart("invalid parameters", + return parameters(part("invalid parameters", (OperationOutcome) evaluationHelper.createIssue("error", "prefetchData is not yet supported"))); } @@ -183,7 +185,7 @@ public Parameters evaluate( expression == null ? null : new HashSet<>(expression)); } catch (Exception e) { e.printStackTrace(); - return newParameters(newPart("evaluation error", + return parameters(part("evaluation error", (OperationOutcome) evaluationHelper.createIssue("error", e.getMessage()))); } } diff --git a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionProviderIT.java b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionProviderIT.java index a8f35d501..9666ce809 100644 --- a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionProviderIT.java +++ b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionProviderIT.java @@ -2,12 +2,10 @@ import org.hl7.fhir.dstu3.model.BooleanType; import org.hl7.fhir.dstu3.model.Bundle; -import org.hl7.fhir.dstu3.model.DateType; import org.hl7.fhir.dstu3.model.IntegerType; import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.Patient; -import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.OperationOutcome; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -18,8 +16,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.booleanPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.datePart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.part; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.stringPart; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CqlExecutionProviderIT.class, CpgConfig.class }, @@ -37,7 +38,7 @@ void setup() { @Test void testSimpleArithmeticCqlExecutionProvider() { - Parameters params = newParameters(newPart("expression", new StringType("5 * 5"))); + Parameters params = parameters(stringPart("expression", "5 * 5")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.getParameter().get(0).getValue() instanceof IntegerType); @@ -46,9 +47,9 @@ void testSimpleArithmeticCqlExecutionProvider() { @Test void testSimpleRetrieveCqlExecutionProvider() { - Parameters params = newParameters( - newPart("subject", new StringType("SimplePatient")), - newPart("expression", new StringType("[Observation]"))); + Parameters params = parameters( + stringPart("subject", "SimplePatient"), + stringPart("expression", "[Observation]")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); // TODO: result is always null... @@ -57,15 +58,13 @@ void testSimpleRetrieveCqlExecutionProvider() { @Test void testReferencedLibraryCqlExecutionProvider() { - Parameters libraryParameter = newParameters( - newPart("url", new StringType( - this.getClient().getServerBase() + "Library/SimpleDstu3Library")), - newPart("name", new StringType("SimpleDstu3Library"))); - Parameters params = newParameters( - newPart("subject", new StringType("SimplePatient")), - newPart("library", libraryParameter), - newPart("expression", new StringType( - "SimpleDstu3Library.\"simpleBooleanExpression\""))); + Parameters libraryParameter = parameters( + stringPart("url", this.getClient().getServerBase() + "Library/SimpleDstu3Library"), + stringPart("name", "SimpleDstu3Library")); + Parameters params = parameters( + stringPart("subject", "SimplePatient"), + part("library", libraryParameter), + stringPart("expression", "SimpleDstu3Library.\"simpleBooleanExpression\"")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.getParameter().get(0).getValue() instanceof BooleanType); @@ -74,16 +73,15 @@ void testReferencedLibraryCqlExecutionProvider() { @Test void testDataBundleCqlExecutionProvider() { - Parameters libraryParameter = newParameters( - newPart("url", new StringType( - this.getClient().getServerBase() + "Library/SimpleDstu3Library")), - newPart("name", new StringType("SimpleDstu3Library"))); + Parameters libraryParameter = parameters( + stringPart("url", this.getClient().getServerBase() + "Library/SimpleDstu3Library"), + stringPart("name", "SimpleDstu3Library")); Bundle data = (Bundle) loadResource(packagePrefix + "SimpleDataBundle.json"); - Parameters params = newParameters( - newPart("library", libraryParameter), - newPart("expression", new StringType("SimpleDstu3Library.\"observationRetrieve\"")), - newPart("data", data), - newPart("useServerData", new BooleanType(false))); + Parameters params = parameters( + part("library", libraryParameter), + stringPart("expression", "SimpleDstu3Library.\"observationRetrieve\""), + part("data", data), + booleanPart("useServerData", false)); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.getParameter().get(0).getResource() instanceof Observation); @@ -91,17 +89,16 @@ void testDataBundleCqlExecutionProvider() { @Test void testDataBundleCqlExecutionProviderWithSubject() { - Parameters libraryParameter = newParameters( - newPart("url", new StringType( - this.getClient().getServerBase() + "Library/SimpleDstu3Library")), - newPart("name", new StringType("SimpleDstu3Library"))); + Parameters libraryParameter = parameters( + stringPart("url", this.getClient().getServerBase() + "Library/SimpleDstu3Library"), + stringPart("name", "SimpleDstu3Library")); Bundle data = (Bundle) loadResource(packagePrefix + "SimpleDataBundle.json"); - Parameters params = newParameters( - newPart("subject", new StringType("SimplePatient")), - newPart("library", libraryParameter), - newPart("expression", new StringType("SimpleDstu3Library.\"observationRetrieve\"")), - newPart("data", data), - newPart("useServerData", new BooleanType(false))); + Parameters params = parameters( + stringPart("subject", "SimplePatient"), + part("library", libraryParameter), + stringPart("expression", "SimpleDstu3Library.\"observationRetrieve\""), + part("data", data), + booleanPart("useServerData", false)); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.getParameter().get(0).getResource() instanceof Observation); @@ -109,11 +106,11 @@ void testDataBundleCqlExecutionProviderWithSubject() { @Test void testSimpleParametersCqlExecutionProvider() { - Parameters evaluationParams = newParameters( - newPart("%inputDate", new DateType("2019-11-01"))); - Parameters params = newParameters( - newPart("expression", new StringType("year from %inputDate before 2020")), - newPart("parameters", evaluationParams)); + Parameters evaluationParams = parameters( + datePart("%inputDate", "2019-11-01")); + Parameters params = parameters( + stringPart("expression", "year from %inputDate before 2020"), + part("parameters", evaluationParams)); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.getParameter().get(0).getValue() instanceof BooleanType); @@ -122,9 +119,9 @@ void testSimpleParametersCqlExecutionProvider() { @Test void testCqlExecutionProviderWithContent() { - Parameters params = newParameters( - newPart("subject", new StringType("Patient/SimplePatient")), - newPart("content", new StringType("library SimpleSTU3Library\n" + + Parameters params = parameters( + stringPart("subject", "Patient/SimplePatient"), + stringPart("content", "library SimpleSTU3Library\n" + "\n" + "using FHIR version '3.0.1'\n" + "\n" + @@ -142,7 +139,7 @@ void testCqlExecutionProviderWithContent() { "\n" + "define \"Denominator\": \"Initial Population\"\n" + "\n" + - "define \"Numerator\": \"Denominator\""))); + "define \"Numerator\": \"Denominator\"")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); @@ -167,10 +164,10 @@ void testCqlExecutionProviderWithContent() { @Test void testCqlExecutionProviderWithContentAndExpression() { - Parameters params = newParameters( - newPart("subject", new StringType("Patient/SimplePatient")), - newPart("expression", new StringType("Numerator")), - newPart("content", new StringType("library SimpleSTU3Library\n" + + Parameters params = parameters( + stringPart("subject", "Patient/SimplePatient"), + stringPart("expression", "Numerator"), + stringPart("content", "library SimpleSTU3Library\n" + "\n" + "using FHIR version '3.0.1'\n" + "\n" + @@ -188,7 +185,7 @@ void testCqlExecutionProviderWithContentAndExpression() { "\n" + "define \"Denominator\": \"Initial Population\"\n" + "\n" + - "define \"Numerator\": \"Denominator\""))); + "define \"Numerator\": \"Denominator\"")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); @@ -202,7 +199,7 @@ void testCqlExecutionProviderWithContentAndExpression() { @Test void testErrorExpression() { - Parameters params = newParameters(newPart("expression", new StringType("Interval[1,5]"))); + Parameters params = parameters(stringPart("expression", "Interval[1,5]")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.hasParameter()); diff --git a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/LibraryEvaluationProviderIT.java b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/LibraryEvaluationProviderIT.java index bfea9d696..cd2141a35 100644 --- a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/LibraryEvaluationProviderIT.java +++ b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/LibraryEvaluationProviderIT.java @@ -2,7 +2,6 @@ import org.hl7.fhir.dstu3.model.BooleanType; import org.hl7.fhir.dstu3.model.IdType; -import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.OperationOutcome; import org.junit.jupiter.api.Test; @@ -17,8 +16,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.stringPart; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { LibraryEvaluationProviderIT.class, CpgConfig.class }, @@ -32,8 +31,8 @@ void testSimpleAsthmaInlineCode() { loadResource(packagePrefix + "SimplePatient.json"); loadResource(packagePrefix + "SimpleCondition.json"); loadResource(packagePrefix + "AsthmaTest.json"); - Parameters params = newParameters( - newPart("subject", new StringType("Patient/SimplePatient"))); + Parameters params = parameters( + stringPart("subject", "Patient/SimplePatient")); Parameters result = getClient().operation() .onInstance(new IdType("Library", "AsthmaTest")) @@ -56,8 +55,8 @@ void testSimpleLibrary() { loadResource(packagePrefix + "SimplePatient.json"); loadResource(packagePrefix + "SimpleObservation.json"); loadResource(packagePrefix + "SimpleDstu3Library.json"); - Parameters params = newParameters( - newPart("subject", new StringType("Patient/SimplePatient"))); + Parameters params = parameters( + stringPart("subject", "Patient/SimplePatient")); Parameters result = getClient().operation() .onInstance(new IdType("Library", "SimpleDstu3Library")) @@ -88,7 +87,7 @@ void testErrorLibrary() { Parameters results = getClient().operation() .onInstance(new IdType("Library", "ErrorLibrary")) .named("$evaluate") - .withParameters(newParameters()) + .withParameters(parameters()) .returnResourceType(Parameters.class) .execute(); diff --git a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionProviderIT.java b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionProviderIT.java index 346d05a54..cc5ccde98 100644 --- a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionProviderIT.java +++ b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionProviderIT.java @@ -2,14 +2,11 @@ import org.hl7.fhir.r4.model.BooleanType; import org.hl7.fhir.r4.model.Bundle; -import org.hl7.fhir.r4.model.CanonicalType; import org.hl7.fhir.r4.model.Condition; -import org.hl7.fhir.r4.model.DateType; import org.hl7.fhir.r4.model.IntegerType; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Patient; -import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.OperationOutcome; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -20,10 +17,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.booleanPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.canonicalPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.datePart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; +import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CqlExecutionProviderIT.class, CpgConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { CqlExecutionProviderIT.class, CpgConfig.class }, + properties = { "hapi.fhir.fhir_version=r4" }) class CqlExecutionProviderIT extends RestIntegrationTest { private final String packagePrefix = "org/opencds/cqf/ruler/cpg/r4/provider/"; @@ -37,7 +40,7 @@ void setup() { @Test void testSimpleArithmeticCqlExecutionProvider() { - Parameters params = newParameters(newPart("expression", new StringType("5 * 5"))); + Parameters params = parameters(stringPart("expression", "5 * 5")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.getParameter("return") instanceof IntegerType); @@ -46,9 +49,9 @@ void testSimpleArithmeticCqlExecutionProvider() { @Test void testSimpleRetrieveCqlExecutionProvider() { - Parameters params = newParameters( - newPart("subject", new StringType("SimplePatient"), - newPart("expression", new StringType("[Observation]")))); + Parameters params = parameters( + stringPart("subject", "SimplePatient", + stringPart("expression", "[Observation]"))); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); // TODO: result is always null... @@ -57,14 +60,13 @@ void testSimpleRetrieveCqlExecutionProvider() { @Test void testReferencedLibraryCqlExecutionProvider() { - Parameters libraryParameter = newParameters( - newPart("url", new CanonicalType( - this.getClient().getServerBase() + "Library/SimpleR4Library")), - newPart("name", new StringType("SimpleR4Library"))); - Parameters params = newParameters( - newPart("subject", new StringType("SimplePatient")), - newPart("library", libraryParameter), - newPart("expression", new StringType("SimpleR4Library.\"simpleBooleanExpression\""))); + Parameters libraryParameter = parameters( + canonicalPart("url", this.getClient().getServerBase() + "Library/SimpleR4Library"), + stringPart("name", "SimpleR4Library")); + Parameters params = parameters( + stringPart("subject", "SimplePatient"), + part("library", libraryParameter), + stringPart("expression", "SimpleR4Library.\"simpleBooleanExpression\"")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.getParameter("return") instanceof BooleanType); @@ -73,16 +75,15 @@ void testReferencedLibraryCqlExecutionProvider() { @Test void testDataBundleCqlExecutionProvider() { - Parameters libraryParameter = newParameters( - newPart("url", new CanonicalType( - this.getClient().getServerBase() + "Library/SimpleR4Library")), - newPart("name", new StringType("SimpleR4Library"))); + Parameters libraryParameter = parameters( + canonicalPart("url", this.getClient().getServerBase() + "Library/SimpleR4Library"), + stringPart("name", "SimpleR4Library")); Bundle data = (Bundle) loadResource(packagePrefix + "SimpleDataBundle.json"); - Parameters params = newParameters( - newPart("library", libraryParameter), - newPart("expression", new StringType("SimpleR4Library.\"observationRetrieve\"")), - newPart("data", data), - newPart("useServerData", new BooleanType(false))); + Parameters params = parameters( + part("library", libraryParameter), + stringPart("expression","SimpleR4Library.\"observationRetrieve\""), + part("data", data), + booleanPart("useServerData", false)); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.getParameter().get(0).getResource() instanceof Observation); @@ -90,17 +91,16 @@ void testDataBundleCqlExecutionProvider() { @Test void testDataBundleCqlExecutionProviderWithSubject() { - Parameters libraryParameter = newParameters( - newPart("url", new CanonicalType( - this.getClient().getServerBase() + "Library/SimpleR4Library")), - newPart("name", new StringType("SimpleR4Library"))); + Parameters libraryParameter = parameters( + canonicalPart("url", this.getClient().getServerBase() + "Library/SimpleR4Library"), + stringPart("name", "SimpleR4Library")); Bundle data = (Bundle) loadResource(packagePrefix + "SimpleDataBundle.json"); - Parameters params = newParameters( - newPart("subject", new StringType("SimplePatient")), - newPart("library", libraryParameter), - newPart("expression", new StringType("SimpleR4Library.\"observationRetrieve\"")), - newPart("data", data), - newPart("useServerData", new BooleanType(false))); + Parameters params = parameters( + stringPart("subject", "SimplePatient"), + part("library", libraryParameter), + stringPart("expression", "SimpleR4Library.\"observationRetrieve\""), + part("data", data), + booleanPart("useServerData", false)); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.getParameter().get(0).getResource() instanceof Observation); @@ -108,11 +108,11 @@ void testDataBundleCqlExecutionProviderWithSubject() { @Test void testSimpleParametersCqlExecutionProvider() { - Parameters evaluationParams = newParameters( - newPart("%inputDate", new DateType("2019-11-01"))); - Parameters params = newParameters( - newPart("expression", new StringType("year from %inputDate before 2020")), - newPart("parameters", evaluationParams)); + Parameters evaluationParams = parameters( + datePart("%inputDate", "2019-11-01")); + Parameters params = parameters( + stringPart("expression", "year from %inputDate before 2020"), + part("parameters", evaluationParams)); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.getParameter("return") instanceof BooleanType); @@ -121,9 +121,9 @@ void testSimpleParametersCqlExecutionProvider() { @Test void testCqlExecutionProviderWithContent() { - Parameters params = newParameters( - newPart("subject", new StringType("SimplePatient")), - newPart("content", new StringType("library SimpleR4Library\n" + + Parameters params = parameters( + stringPart("subject", "SimplePatient"), + stringPart("content", "library SimpleR4Library\n" + "\n" + "using FHIR version '4.0.1'\n" + "\n" + @@ -141,7 +141,7 @@ void testCqlExecutionProviderWithContent() { "\n" + "define \"Denominator\": \"Initial Population\"\n" + "\n" + - "define \"Numerator\": \"Denominator\""))); + "define \"Numerator\": \"Denominator\"")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); @@ -173,10 +173,10 @@ void testCqlExecutionProviderWithContent() { @Test void testCqlExecutionProviderWithContentAndExpression() { - Parameters params = newParameters( - newPart("subject", new StringType("SimplePatient")), - newPart("expression", new StringType("Numerator")), - newPart("content", new StringType("library SimpleR4Library\n" + + Parameters params = parameters( + stringPart("subject", "SimplePatient"), + stringPart("expression", "Numerator"), + stringPart("content","library SimpleR4Library\n" + "\n" + "using FHIR version '4.0.1'\n" + "\n" + @@ -194,7 +194,7 @@ void testCqlExecutionProviderWithContentAndExpression() { "\n" + "define \"Denominator\": \"Initial Population\"\n" + "\n" + - "define \"Numerator\": \"Denominator\""))); + "define \"Numerator\": \"Denominator\"")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); @@ -207,9 +207,9 @@ void testCqlExecutionProviderWithContentAndExpression() { @Test void testContentRetrieveWithInlineCode() { - Parameters params = newParameters( - newPart("subject", new StringType("SimplePatient")), - newPart("content", new StringType("library AsthmaTest version '1.0.0'\n" + + Parameters params = parameters( + stringPart("subject", "SimplePatient"), + stringPart("content", "library AsthmaTest version '1.0.0'\n" + "\n" + "using FHIR version '4.0.1'\n" + "\n" + @@ -225,7 +225,7 @@ void testContentRetrieveWithInlineCode() { " [Condition: \"Asthma\"]\n" + "\n" + "define \"Has Asthma Diagnosis\":\n" + - " exists(\"Asthma Diagnosis\")\n"))); + " exists(\"Asthma Diagnosis\")\n")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); @@ -242,7 +242,7 @@ void testContentRetrieveWithInlineCode() { @Test void testErrorExpression() { - Parameters params = newParameters(newPart("expression", new StringType("Interval[1,5]"))); + Parameters params = parameters(stringPart("expression", "Interval[1,5]")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); assertTrue(results.hasParameter()); diff --git a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/LibraryEvaluationProviderIT.java b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/LibraryEvaluationProviderIT.java index 015b942a1..8976d2c46 100644 --- a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/LibraryEvaluationProviderIT.java +++ b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/LibraryEvaluationProviderIT.java @@ -19,8 +19,10 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.booleanPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; +import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { LibraryEvaluationProviderIT.class, CpgConfig.class }, @@ -34,8 +36,7 @@ void testSimpleAsthmaInlineCode() { loadResource(packagePrefix + "SimplePatient.json"); loadResource(packagePrefix + "SimpleCondition.json"); loadResource(packagePrefix + "AsthmaTest.json"); - Parameters params = newParameters( - newPart("subject", new StringType("Patient/SimplePatient"))); + Parameters params = parameters(stringPart("subject", "Patient/SimplePatient")); Parameters result = getClient().operation() .onInstance(new IdType("Library", "AsthmaTest")) @@ -54,8 +55,7 @@ void testSimpleLibrary() { loadResource(packagePrefix + "SimplePatient.json"); loadResource(packagePrefix + "SimpleObservation.json"); loadResource(packagePrefix + "SimpleR4Library.json"); - Parameters params = newParameters( - newPart("subject", new StringType("Patient/SimplePatient"))); + Parameters params = parameters(stringPart("subject", "Patient/SimplePatient")); Parameters result = getClient().operation() .onInstance(new IdType("Library", "SimpleR4Library")) @@ -77,10 +77,10 @@ void testSimpleLibrary() { void testSimpleLibraryWithBundle() { loadResource(packagePrefix + "SimpleR4Library.json"); Bundle data = (Bundle) loadResource(packagePrefix + "SimpleDataBundle.json"); - Parameters params = newParameters( - newPart("subject", "SimplePatient"), - newPart("data", data), - newPart("useServerData", new BooleanType(false))); + Parameters params = parameters( + stringPart("subject", "SimplePatient"), + part("data", data), + booleanPart("useServerData", false)); Parameters result = getClient().operation() .onInstance(new IdType("Library", "SimpleR4Library")) @@ -103,9 +103,7 @@ void testOpioidRec10Library() { loadTransaction(packagePrefix + "OpioidCDSREC10-artifact-bundle.json"); loadTransaction(packagePrefix + "OpioidCDSREC10-patient-data-bundle.json"); - Parameters params = newParameters( - newPart("subject", new StringType("Patient/example-rec-10-no-screenings")) - ); + Parameters params = parameters(stringPart("subject", "Patient/example-rec-10-no-screenings")); Parameters result = getClient().operation() .onInstance(new IdType("Library", "OpioidCDSREC10PatientView")) @@ -155,7 +153,7 @@ void testErrorLibrary() { Parameters results = getClient().operation() .onInstance(new IdType("Library", "ErrorLibrary")) .named("$evaluate") - .withParameters(newParameters()) + .withParameters(parameters()) .returnResourceType(Parameters.class) .execute(); diff --git a/plugin/cpg/src/test/resources/org/opencds/cqf/ruler/cpg/dstu3/provider/SimpleObservation.json b/plugin/cpg/src/test/resources/org/opencds/cqf/ruler/cpg/dstu3/provider/SimpleObservation.json index 4b8c1d3df..edb47ec88 100644 --- a/plugin/cpg/src/test/resources/org/opencds/cqf/ruler/cpg/dstu3/provider/SimpleObservation.json +++ b/plugin/cpg/src/test/resources/org/opencds/cqf/ruler/cpg/dstu3/provider/SimpleObservation.json @@ -4,25 +4,24 @@ "status": "final", "code": { "coding": [ - { - "system": "http://loinc.org", - "code": "10524-7", - "display": "Microscopic observation [Identifier] in Cervix by Cyto stain" - } + { + "system": "http://loinc.org", + "code": "10524-7", + "display": "Microscopic observation [Identifier] in Cervix by Cyto stain" + } ] - }, - "value": { - "coding": [ - { - "system": "http://loinc.org", - "code": "10524-7", - "display": "Microscopic observation [Identifier] in Cervix by Cyto stain" - } - ] - }, - "subject": { - "reference": "Patient/SimplePatient", - "type": "Patient" - }, - "effectiveDateTime": "2019-11-01T00:00:00" + }, + "valueCodeableConcept": { + "coding": [ + { + "system": "http://loinc.org", + "code": "10524-7", + "display": "Microscopic observation [Identifier] in Cervix by Cyto stain" + } + ] + }, + "subject": { + "reference": "Patient/SimplePatient" + }, + "effectiveDateTime": "2019-11-01T00:00:00" } diff --git a/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/CqlPropertiesTest.java b/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/CqlPropertiesTest.java index 40d439991..b14c081e5 100644 --- a/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/CqlPropertiesTest.java +++ b/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/CqlPropertiesTest.java @@ -16,7 +16,7 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration(initializers = ConfigDataApplicationContextInitializer.class) @EnableConfigurationProperties(CqlProperties.class) -public class CqlPropertiesTest { +class CqlPropertiesTest { @Autowired CqlProperties cqlProperties; @@ -24,7 +24,7 @@ public class CqlPropertiesTest { // This tests that all the various cql-related properties are being bound // correctly to the configuration @Test - public void cqlPropertiesAreSet() { + void cqlPropertiesAreSet() { assertTrue(cqlProperties.isEnabled()); assertFalse(cqlProperties.useEmbeddedLibraries()); diff --git a/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirRetrieveProviderIT.java b/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirRetrieveProviderIT.java index bfffb1faf..25fe8a78d 100644 --- a/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirRetrieveProviderIT.java +++ b/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/JpaFhirRetrieveProviderIT.java @@ -25,7 +25,7 @@ import ca.uhn.fhir.jpa.provider.ValueSetOperationProvider; @SpringBootTest(classes = { JpaFhirRetrieveProviderIT.class }, properties = { "hapi.fhir.fhir_version=r4" }) -public class JpaFhirRetrieveProviderIT extends DaoIntegrationTest { +class JpaFhirRetrieveProviderIT extends DaoIntegrationTest { @Autowired SearchParameterResolver searchParameterResolver; @@ -45,7 +45,7 @@ private JpaFhirRetrieveProvider createProvider() { } @Test - public void testReadPatient() { + void testReadPatient() { this.update(patient()); JpaFhirRetrieveProvider jfrp = this.createProvider(); @@ -60,7 +60,7 @@ public void testReadPatient() { } @Test - public void testReadObservation() { + void testReadObservation() { this.update(patient()); this.update(observation()); @@ -77,7 +77,7 @@ public void testReadObservation() { } @Test - public void testReadObservationByValueSet() { + void testReadObservationByValueSet() { this.update(patient()); this.update(observation()); this.update(valueSet()); diff --git a/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/r4/PreExpandedTermReadSvcR4IT.java b/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/r4/PreExpandedTermReadSvcR4IT.java index 1254ae9fa..c3780c719 100644 --- a/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/r4/PreExpandedTermReadSvcR4IT.java +++ b/plugin/cql/src/test/java/org/opencds/cqf/ruler/cql/r4/PreExpandedTermReadSvcR4IT.java @@ -23,10 +23,10 @@ import ca.uhn.fhir.rest.param.TokenParamModifier; @SpringBootTest(classes = { PreExpandedTermReadSvcR4IT.class }, properties = { "hapi.fhir.fhir_version=r4" }) -public class PreExpandedTermReadSvcR4IT extends DaoIntegrationTest { +class PreExpandedTermReadSvcR4IT extends DaoIntegrationTest { @Test - public void testSearchObservationByComposedValueSet() { + void testSearchObservationByComposedValueSet() { this.update(composedValueSet()); this.update(patient()); this.update(observation()); @@ -38,7 +38,7 @@ public void testSearchObservationByComposedValueSet() { } @Test - public void testSearchObservationByExpandedValueSet() { + void testSearchObservationByExpandedValueSet() { this.update(expandedValueSet()); this.update(patient()); this.update(observation()); diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/provider/CollectDataProvider.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/provider/CollectDataProvider.java index a13260875..aefee0bfb 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/provider/CollectDataProvider.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/provider/CollectDataProvider.java @@ -1,7 +1,7 @@ package org.opencds.cqf.ruler.cr.dstu3.provider; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.part; import java.util.ArrayList; import java.util.List; @@ -68,7 +68,7 @@ public Parameters collectData(RequestDetails theRequestDetails, @IdParam IdType report.setType(MeasureReportType.SUMMARY); report.setGroup(null); - Parameters parameters = newParameters(newPart("measureReport", report)); + Parameters parameters = parameters(part("measureReport", report)); addEvaluatedResourcesToParameters(report, parameters); @@ -88,7 +88,7 @@ private List readEvaluatedResources(MeasureReport report) { String listId = listReference.getReference().substring(1); Optional list = report.getContained().stream().filter(x -> x.getId().equals(listId)).findFirst(); - if (!list.isPresent()) { + if (list.isEmpty()) { return resources; } @@ -108,6 +108,6 @@ private List readEvaluatedResources(MeasureReport report) { private void addEvaluatedResourcesToParameters(MeasureReport report, Parameters parameters) { readEvaluatedResources(report) - .forEach(resource -> parameters.addParameter(newPart("resource", resource))); + .forEach(resource -> parameters.addParameter(part("resource", resource))); } } diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/CollectDataProvider.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/CollectDataProvider.java index ca768a53e..844eaea44 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/CollectDataProvider.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/CollectDataProvider.java @@ -1,7 +1,7 @@ package org.opencds.cqf.ruler.cr.r4.provider; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; import java.util.ArrayList; import java.util.List; @@ -63,7 +63,7 @@ public Parameters collectData(RequestDetails theRequestDetails, @IdParam IdType report.setType(MeasureReport.MeasureReportType.DATACOLLECTION); report.setGroup(null); - Parameters parameters = newParameters(newPart("measureReport", report)); + Parameters parameters = parameters(part("measureReport", report)); addEvaluatedResourcesToParameters(report, parameters); @@ -88,6 +88,6 @@ private List readEvaluatedResources(MeasureReport report) { private void addEvaluatedResourcesToParameters(MeasureReport report, Parameters parameters) { readEvaluatedResources(report) - .forEach(resource -> parameters.addParameter(newPart("resource", resource))); + .forEach(resource -> parameters.addParameter(part("resource", resource))); } } diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/ExpressionEvaluationIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/ExpressionEvaluationIT.java index cd5c1b540..f135d45df 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/ExpressionEvaluationIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/ExpressionEvaluationIT.java @@ -16,11 +16,10 @@ import ca.uhn.fhir.jpa.partition.SystemRequestDetails; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { ExpressionEvaluationIT.class, - CrConfig.class, CqlConfig.class }, properties = { - "hapi.fhir.fhir_version=dstu3", - }) -public class ExpressionEvaluationIT extends RestIntegrationTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { ExpressionEvaluationIT.class, CrConfig.class, CqlConfig.class }, + properties = { "hapi.fhir.fhir_version=dstu3" }) +class ExpressionEvaluationIT extends RestIntegrationTest { @Autowired private ExpressionEvaluation expressionEvaluation; @@ -35,7 +34,7 @@ public void setup() throws Exception { } @Test - public void testOpioidCdsPlanDefinitionDomain() throws Exception { + void testOpioidCdsPlanDefinitionDomain() throws Exception { DomainResource plandefinition = (DomainResource) planDefinitions.get("opioidcds-10"); // Patient First uploadTests("test/plandefinition/Rec10/Patient"); @@ -45,6 +44,6 @@ public void testOpioidCdsPlanDefinitionDomain() throws Exception { "true", false, patient.getIdElement().getIdPart(), new SystemRequestDetails()); assertTrue(isFormerSmoker instanceof Boolean); - assertTrue(((Boolean) isFormerSmoker).booleanValue()); + assertTrue((Boolean) isFormerSmoker); } } diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/ActivityDefinitionApplyProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/ActivityDefinitionApplyProviderIT.java index 4403c9eb9..9c6e8c3a5 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/ActivityDefinitionApplyProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/ActivityDefinitionApplyProviderIT.java @@ -19,12 +19,11 @@ import ca.uhn.fhir.jpa.partition.SystemRequestDetails; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { - ActivityDefinitionApplyProviderIT.class, - CrConfig.class, CqlConfig.class }, properties = { - "hapi.fhir.fhir_version=dstu3", - }) -public class ActivityDefinitionApplyProviderIT extends RestIntegrationTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { ActivityDefinitionApplyProviderIT.class, + CrConfig.class, CqlConfig.class }, + properties = { "hapi.fhir.fhir_version=dstu3" }) +class ActivityDefinitionApplyProviderIT extends RestIntegrationTest { @Autowired private ActivityDefinitionApplyProvider activityDefinitionApplyProvider; @@ -37,7 +36,7 @@ public void setup() throws Exception { } @Test - public void testActivityDefinitionApply() throws Exception { + void testActivityDefinitionApply() throws Exception { DomainResource activityDefinition = (DomainResource) activityDefinitions.get("opioidcds-risk-assessment-request"); // Patient First Map resources = uploadTests("test/activitydefinition/Patient"); diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/CollectDataProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/CollectDataProviderIT.java index 542cf50c6..1f1ba1d14 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/CollectDataProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/CollectDataProviderIT.java @@ -1,5 +1,6 @@ package org.opencds.cqf.ruler.cr.dstu3.provider; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.getPartsByName; import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.List; @@ -25,13 +26,13 @@ import ca.uhn.fhir.jpa.partition.SystemRequestDetails; @SpringBootTest(classes = { CollectDataProviderIT.class }, properties = { "hapi.fhir.fhir_version=dstu3", }) -public class CollectDataProviderIT extends DaoIntegrationTest { +class CollectDataProviderIT extends DaoIntegrationTest { @Autowired CollectDataProvider collectDataProvider; @Test - public void testCollectData() { + void testCollectData() { // Create test Measure String cql = CqlBuilder.newCqlLibrary("3.0.0") .addExpression( @@ -64,11 +65,11 @@ public void testCollectData() { Parameters results = collectDataProvider.collectData(new SystemRequestDetails(), m.getIdElement(), "2019-01-01", "2019-12-31", Ids.simple(john), null, null); - List resources = org.opencds.cqf.ruler.utility.dstu3.Parameters.getPartsByName(results, "resource"); + List resources = getPartsByName(results, "resource"); assertEquals(1, resources.size()); assertEquals("Observation", resources.get(0).getResource().fhirType()); - List reports = org.opencds.cqf.ruler.utility.dstu3.Parameters.getPartsByName(results, "measureReport"); + List reports = getPartsByName(results, "measureReport"); assertEquals(1, reports.size()); assertEquals("MeasureReport", reports.get(0).getResource().fhirType()); } diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/DataOperationProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/DataOperationProviderIT.java index 0e31b386a..35dfeea17 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/DataOperationProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/DataOperationProviderIT.java @@ -1,31 +1,27 @@ package org.opencds.cqf.ruler.cr.dstu3.provider; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.stringPart; import static org.junit.jupiter.api.Assertions.assertNotNull; -import java.io.IOException; - -import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Library; import org.hl7.fhir.dstu3.model.Parameters; -import org.hl7.fhir.dstu3.model.StringType; import org.junit.jupiter.api.Test; import org.opencds.cqf.ruler.cr.CrConfig; import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { DataOperationProviderIT.class, - CrConfig.class }, properties = { "hapi.fhir.fhir_version=dstu3" }) -public class DataOperationProviderIT extends RestIntegrationTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { DataOperationProviderIT.class, CrConfig.class }, + properties = { "hapi.fhir.fhir_version=dstu3" }) +class DataOperationProviderIT extends RestIntegrationTest { @Test - public void testDstu3DataRequirementsOperation() throws IOException { - String bundleAsText = stringFromResource("DataReqLibraryTransactionBundleDstu3.json"); - Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); + void testDstu3DataRequirementsOperation() { + loadTransaction("DataReqLibraryTransactionBundleDstu3.json"); - Parameters params = new Parameters(); - params.addParameter().setName("target").setValue(new StringType("dummy")); + Parameters params = parameters(stringPart("target", "dummy")); Library returnLibrary = getClient().operation() .onInstance(new IdType("Library", "LibraryEvaluationTest")) @@ -38,16 +34,15 @@ public void testDstu3DataRequirementsOperation() throws IOException { } @Test - public void testDstu3MeasureDataRequirementsOperation() throws IOException { - String bundleAsText = stringFromResource("Exm105Dstu3MeasureBundle.json"); - Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); + void testDstu3MeasureDataRequirementsOperation() { + loadTransaction("Exm105Dstu3MeasureBundle.json"); - Parameters params = new Parameters(); - params.addParameter().setName("startPeriod").setValue(new StringType("2019-01-01")); - params.addParameter().setName("endPeriod").setValue(new StringType("2020-01-01")); + Parameters params = parameters( + stringPart("startPeriod", "2019-01-01"), + stringPart("endPeriod", "2020-01-01")); - Library returnLibrary = getClient().operation().onInstance(new IdType("Measure", "measure-EXM105-FHIR3-8.0.000")) + Library returnLibrary = getClient().operation() + .onInstance(new IdType("Measure", "measure-EXM105-FHIR3-8.0.000")) .named("$data-requirements") .withParameters(params) .returnResourceType(Library.class) diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/MeasureEvaluateProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/MeasureEvaluateProviderIT.java index 289dc4ccf..62805acd5 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/MeasureEvaluateProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/MeasureEvaluateProviderIT.java @@ -1,5 +1,8 @@ package org.opencds.cqf.ruler.cr.dstu3.provider; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.part; +import static org.opencds.cqf.ruler.utility.dstu3.Parameters.stringPart; import static org.junit.jupiter.api.Assertions.assertNotNull; import org.hl7.fhir.dstu3.model.Bundle; @@ -7,31 +10,28 @@ import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.MeasureReport; import org.hl7.fhir.dstu3.model.Parameters; -import org.hl7.fhir.dstu3.model.StringType; import org.junit.jupiter.api.Test; import org.opencds.cqf.ruler.cql.CqlConfig; import org.opencds.cqf.ruler.cr.CrConfig; import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { MeasureEvaluateProviderIT.class, - CrConfig.class, CqlConfig.class }, properties = { - "hapi.fhir.fhir_version=dstu3" - }) -public class MeasureEvaluateProviderIT extends RestIntegrationTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { MeasureEvaluateProviderIT.class, CrConfig.class, CqlConfig.class }, + properties = { "hapi.fhir.fhir_version=dstu3" }) +class MeasureEvaluateProviderIT extends RestIntegrationTest { @Test - public void testMeasureEvaluate() throws Exception { - String bundleAsText = stringFromResource("Exm105Fhir3Measure.json"); - Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); - - Parameters params = new Parameters(); - params.addParameter().setName("periodStart").setValue(new StringType("2019-01-01")); - params.addParameter().setName("periodEnd").setValue(new StringType("2020-01-01")); - params.addParameter().setName("reportType").setValue(new StringType("individual")); - params.addParameter().setName("subject").setValue(new StringType("Patient/denom-EXM105-FHIR3")); - params.addParameter().setName("lastReceivedOn").setValue(new StringType("2019-12-12")); + void testMeasureEvaluate() { + loadTransaction("Exm105Fhir3Measure.json"); + + Parameters params = parameters( + stringPart("periodStart", "2019-01-01"), + stringPart("periodEnd", "2020-01-01"), + stringPart("reportType", "individual"), + stringPart("subject", "Patient/denom-EXM105-FHIR3"), + stringPart("lastReceivedOn", "2019-12-12") + ); MeasureReport returnMeasureReport = getClient().operation() .onInstance(new IdType("Measure", "measure-EXM105-FHIR3-8.0.000")) @@ -44,22 +44,20 @@ public void testMeasureEvaluate() throws Exception { } @Test - public void testMeasureEvaluateWithTerminology() throws Exception { - String bundleAsText = stringFromResource("Exm105Fhir3Measure.json"); - Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); + void testMeasureEvaluateWithTerminology() { + loadTransaction("Exm105Fhir3Measure.json"); - String terminologyAsText = stringFromResource("Endpoint.json"); - Endpoint terminologyEndpoint = (Endpoint) getFhirContext().newJsonParser().parseResource(terminologyAsText); + Endpoint terminologyEndpoint = (Endpoint) loadResource("Endpoint.json"); terminologyEndpoint.setAddress(String.format("http://localhost:%s/fhir/", getPort())); - Parameters params = new Parameters(); - params.addParameter().setName("periodStart").setValue(new StringType("2019-01-01")); - params.addParameter().setName("periodEnd").setValue(new StringType("2020-01-01")); - params.addParameter().setName("reportType").setValue(new StringType("individual")); - params.addParameter().setName("subject").setValue(new StringType("Patient/denom-EXM105-FHIR3")); - params.addParameter().setName("lastReceivedOn").setValue(new StringType("2019-12-12")); - params.addParameter().setName("terminologyEndpoint").setResource(terminologyEndpoint); + Parameters params = parameters( + stringPart("periodStart", "2019-01-01"), + stringPart("periodEnd", "2020-01-01"), + stringPart("reportType", "individual"), + stringPart("subject", "Patient/denom-EXM105-FHIR3"), + stringPart("lastReceivedOn", "2019-12-12"), + part("terminologyEndpoint", terminologyEndpoint) + ); MeasureReport returnMeasureReport = getClient().operation() .onInstance(new IdType("Measure", "measure-EXM105-FHIR3-8.0.000")) @@ -72,21 +70,18 @@ public void testMeasureEvaluateWithTerminology() throws Exception { } @Test - public void testMeasureEvaluateWithAdditionalData() throws Exception { - String mainBundleAsText = stringFromResource("Exm105FhirR3MeasurePartBundle.json"); - Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(mainBundleAsText); - getClient().transaction().withBundle(bundle).execute(); - - String additionalBundleAsText = stringFromResource("Exm105FhirR3MeasureAdditionalData.json"); - Bundle additionalData = (Bundle) getFhirContext().newJsonParser().parseResource(additionalBundleAsText); - - Parameters params = new Parameters(); - params.addParameter().setName("periodStart").setValue(new StringType("2019-01-01")); - params.addParameter().setName("periodEnd").setValue(new StringType("2020-01-01")); - params.addParameter().setName("reportType").setValue(new StringType("individual")); - params.addParameter().setName("subject").setValue(new StringType("Patient/denom-EXM105-FHIR3")); - params.addParameter().setName("lastReceivedOn").setValue(new StringType("2019-12-12")); - params.addParameter().setName("additionalData").setResource(additionalData); + void testMeasureEvaluateWithAdditionalData() { + loadTransaction("Exm105FhirR3MeasurePartBundle.json"); + Bundle additionalData = (Bundle) loadResource("Exm105FhirR3MeasureAdditionalData.json"); + + Parameters params = parameters( + stringPart("periodStart", "2019-01-01"), + stringPart("periodEnd", "2020-01-01"), + stringPart("reportType", "individual"), + stringPart("subject", "Patient/denom-EXM105-FHIR3"), + stringPart("lastReceivedOn", "2019-12-12"), + part("additionalData", additionalData) + ); MeasureReport returnMeasureReport = getClient().operation() .onInstance(new IdType("Measure", "measure-EXM105-FHIR3-8.0.000")) diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/PlanDefinitionApplyProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/PlanDefinitionApplyProviderIT.java index 95ac686c1..4ddb784e5 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/PlanDefinitionApplyProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/PlanDefinitionApplyProviderIT.java @@ -1,10 +1,9 @@ package org.opencds.cqf.ruler.cr.dstu3.provider; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.Map; -import org.hl7.fhir.dstu3.model.CarePlan; import org.hl7.fhir.dstu3.model.DomainResource; import org.hl7.fhir.instance.model.api.IBaseResource; import org.junit.jupiter.api.BeforeEach; @@ -17,12 +16,11 @@ import ca.uhn.fhir.jpa.partition.SystemRequestDetails; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { - PlanDefinitionApplyProviderIT.class, - CrConfig.class, CqlConfig.class }, properties = { - "hapi.fhir.fhir_version=dstu3", - }) -public class PlanDefinitionApplyProviderIT extends RestIntegrationTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { PlanDefinitionApplyProviderIT.class, + CrConfig.class, CqlConfig.class }, + properties = { "hapi.fhir.fhir_version=dstu3" }) +class PlanDefinitionApplyProviderIT extends RestIntegrationTest { @Autowired private PlanDefinitionApplyProvider planDefinitionApplyProvider; @@ -37,7 +35,7 @@ public void setup() throws Exception { } @Test - public void testPlanDefinitionApplyRec10NoScreenings() throws Exception { + void testPlanDefinitionApplyRec10NoScreenings() throws Exception { DomainResource plandefinition = (DomainResource) planDefinitions.get("opioidcds-10"); // Patient First uploadTests("test/plandefinition/Rec10/Patient"); @@ -46,6 +44,6 @@ public void testPlanDefinitionApplyRec10NoScreenings() throws Exception { Object recommendation = planDefinitionApplyProvider.applyPlanDefinition(new SystemRequestDetails(), plandefinition.getIdElement(), patient.getIdElement().getIdPart(), null, null, null, null, null, null, null, null); - assertTrue(recommendation instanceof CarePlan); + assertNotNull(recommendation); } } diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/SubmitDataProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/SubmitDataProviderIT.java index e8b9009f7..22e250887 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/SubmitDataProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/SubmitDataProviderIT.java @@ -19,13 +19,13 @@ import ca.uhn.fhir.jpa.partition.SystemRequestDetails; @SpringBootTest(classes = { SubmitDataProviderIT.class }, properties = { "hapi.fhir.fhir_version=dstu3", }) -public class SubmitDataProviderIT extends DaoIntegrationTest { +class SubmitDataProviderIT extends DaoIntegrationTest { @Autowired SubmitDataProvider mySubmitDataProvider; @Test - public void testSubmitData() { + void testSubmitData() { // Create a MR and a resource MeasureReport mr = newResource(MeasureReport.class, "test-mr"); Observation obs = newResource(Observation.class, "test-obs"); @@ -43,7 +43,7 @@ public void testSubmitData() { } @Test - public void testSubmitDataNoId() { + void testSubmitDataNoId() { // Create a MR and a resource MeasureReport mr = newResource(MeasureReport.class).setMeasure(new Reference("Measure/123")); Observation obs = newResource(Observation.class).setValue(new StringType("ABC")); diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluationIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluationIT.java index 21cfa176e..d2762bbe9 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluationIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluationIT.java @@ -1,5 +1,6 @@ package org.opencds.cqf.ruler.cr.r4; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Map; @@ -20,7 +21,7 @@ CrConfig.class, CqlConfig.class }, properties = { "hapi.fhir.fhir_version=r4", }) -public class ExpressionEvaluationIT extends RestIntegrationTest { +class ExpressionEvaluationIT extends RestIntegrationTest { @Autowired private ExpressionEvaluation expressionEvaluation; @@ -37,7 +38,7 @@ public void setup() throws Exception { } @Test - public void testExpressionEvaluationANCIND01MeasureDomain() throws Exception { + void testExpressionEvaluationANCIND01MeasureDomain() throws Exception { DomainResource measure = (DomainResource) measures.get("ANCIND01"); // Patient First uploadTests("test/measure/ANCIND01/charity-otala-1/Patient"); @@ -46,19 +47,19 @@ public void testExpressionEvaluationANCIND01MeasureDomain() throws Exception { Object ipResult = expressionEvaluation.evaluateInContext(measure, "ANCIND01.\"Initial Population\"", patient.getIdElement().getIdPart(), new SystemRequestDetails()); assertTrue(ipResult instanceof Boolean); - assertTrue(((Boolean) ipResult).booleanValue()); + assertTrue((Boolean) ipResult); Object denomResult = expressionEvaluation.evaluateInContext(measure, "ANCIND01.Denominator", patient.getIdElement().getIdPart(), new SystemRequestDetails()); assertTrue(denomResult instanceof Boolean); - assertTrue(((Boolean) denomResult).booleanValue()); + assertTrue((Boolean) denomResult); Object numerResult = expressionEvaluation.evaluateInContext(measure, "ANCIND01.Numerator", patient.getIdElement().getIdPart(), new SystemRequestDetails()); assertTrue(numerResult instanceof Boolean); - assertTrue(((Boolean) numerResult).booleanValue()); + assertTrue((Boolean) numerResult); } @Test - public void testExpressionEvaluationANCDT01PlanDefinitionDomain() throws Exception { + void testExpressionEvaluationANCDT01PlanDefinitionDomain() throws Exception { DomainResource planDefinition = (DomainResource) planDefinitions.get("lcs-cds-patient-view"); // Patient First uploadTests("test/plandefinition/LungCancerScreening/Former-Smoker/Patient"); @@ -68,11 +69,11 @@ public void testExpressionEvaluationANCDT01PlanDefinitionDomain() throws Excepti "Is former smoker who quit within past 15 years", patient.getIdElement().getIdPart(), true, new SystemRequestDetails()); assertTrue(isFormerSmoker instanceof Boolean); - assertTrue(((Boolean) isFormerSmoker).booleanValue()); + assertTrue((Boolean) isFormerSmoker); Object isCurrentSmoker = expressionEvaluation.evaluateInContext(planDefinition, "Is current smoker", patient.getIdElement().getIdPart(), true, new SystemRequestDetails()); assertTrue(isCurrentSmoker instanceof Boolean); - assertTrue((!(Boolean) isCurrentSmoker)); + assertFalse((Boolean) isCurrentSmoker); } } diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/ActivityDefinitionApplyProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/ActivityDefinitionApplyProviderIT.java index 5d13664b4..24c9d9cb9 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/ActivityDefinitionApplyProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/ActivityDefinitionApplyProviderIT.java @@ -24,7 +24,7 @@ CrConfig.class, CqlConfig.class }, properties = { "hapi.fhir.fhir_version=r4", }) -public class ActivityDefinitionApplyProviderIT extends RestIntegrationTest { +class ActivityDefinitionApplyProviderIT extends RestIntegrationTest { @Autowired private ActivityDefinitionApplyProvider activityDefinitionApplyProvider; @@ -37,7 +37,7 @@ public void setup() throws Exception { } @Test - public void testActivityDefinitionApply() throws Exception { + void testActivityDefinitionApply() throws Exception { DomainResource activityDefinition = (DomainResource) activityDefinitions.get("opioidcds-risk-assessment-request"); // Patient First Map resources = uploadTests("test/activitydefinition/Patient"); diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/CareGapsProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/CareGapsProviderIT.java index 9c27a0166..8788e0f2a 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/CareGapsProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/CareGapsProviderIT.java @@ -22,7 +22,7 @@ "hapi.fhir.cr.measure_report.care_gaps_reporter=Organization/alphora", "hapi.fhir.cr.measure_report.care_gaps_composition_section_author=Organization/alphora-author" }) -public class CareGapsProviderIT extends RestIntegrationTest { +class CareGapsProviderIT extends RestIntegrationTest { private static final String periodStartValid = "2019-01-01"; private static final String periodEndValid = "2019-12-31"; @@ -44,7 +44,7 @@ public class CareGapsProviderIT extends RestIntegrationTest { private static final String subjectReferenceInvalid = "Measure/gic-sub-1"; @BeforeEach - public void beforeEach() { + void beforeEach() { loadResource("Alphora-organization.json"); loadResource("AlphoraAuthor-organization.json"); loadResource("numer-EXM125-patient.json"); @@ -65,7 +65,7 @@ private void beforeEachMultipleMeasures() { } @Test - public void testMinimalParametersValid() { + void testMinimalParametersValid() { beforeEachMeasure(); Parameters params = new Parameters(); @@ -86,25 +86,24 @@ public void testMinimalParametersValid() { @SuppressWarnings("java:S5778") @Test - public void testPeriodStartNull() throws Exception { + void testPeriodStartNull() { Parameters params = new Parameters(); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); params.addParameter().setName("subject").setValue(new StringType(subjectPatientValid)); params.addParameter().setName("status").setValue(new StringType(statusValid)); params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); - assertThrows(InternalErrorException.class, () -> { - getClient().operation().onType(Measure.class).named("$care-gaps") - .withParameters(params) - .useHttpGet() - .returnResourceType(Parameters.class) - .execute(); - }); + assertThrows(InternalErrorException.class, () -> + getClient().operation().onType(Measure.class).named("$care-gaps") + .withParameters(params) + .useHttpGet() + .returnResourceType(Parameters.class) + .execute()); } @SuppressWarnings("java:S5778") @Test - public void testPeriodStartInvalid() throws Exception { + void testPeriodStartInvalid() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(dateInvalid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); @@ -112,36 +111,34 @@ public void testPeriodStartInvalid() throws Exception { params.addParameter().setName("status").setValue(new StringType(statusValid)); params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); - assertThrows(InternalErrorException.class, () -> { - getClient().operation().onType(Measure.class).named("$care-gaps") - .withParameters(params) - .useHttpGet() - .returnResourceType(Parameters.class) - .execute(); - }); + assertThrows(InternalErrorException.class, () -> + getClient().operation().onType(Measure.class).named("$care-gaps") + .withParameters(params) + .useHttpGet() + .returnResourceType(Parameters.class) + .execute()); } @SuppressWarnings("java:S5778") @Test - public void testPeriodEndNull() throws Exception { + void testPeriodEndNull() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("subject").setValue(new StringType(subjectPatientValid)); params.addParameter().setName("status").setValue(new StringType(statusValid)); params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); - assertThrows(InternalErrorException.class, () -> { - getClient().operation().onType(Measure.class).named("$care-gaps") - .withParameters(params) - .useHttpGet() - .returnResourceType(Parameters.class) - .execute(); - }); + assertThrows(InternalErrorException.class, () -> + getClient().operation().onType(Measure.class).named("$care-gaps") + .withParameters(params) + .useHttpGet() + .returnResourceType(Parameters.class) + .execute()); } @SuppressWarnings("java:S5778") @Test - public void testPeriodEndInvalid() throws Exception { + void testPeriodEndInvalid() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(dateInvalid)); @@ -149,18 +146,17 @@ public void testPeriodEndInvalid() throws Exception { params.addParameter().setName("status").setValue(new StringType(statusValid)); params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); - assertThrows(InternalErrorException.class, () -> { - getClient().operation().onType(Measure.class).named("$care-gaps") - .withParameters(params) - .useHttpGet() - .returnResourceType(Parameters.class) - .execute(); - }); + assertThrows(InternalErrorException.class, () -> + getClient().operation().onType(Measure.class).named("$care-gaps") + .withParameters(params) + .useHttpGet() + .returnResourceType(Parameters.class) + .execute()); } @SuppressWarnings("java:S5778") @Test - public void testPeriodInvalid() throws Exception { + void testPeriodInvalid() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodEndValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodStartValid)); @@ -168,17 +164,16 @@ public void testPeriodInvalid() throws Exception { params.addParameter().setName("status").setValue(new StringType(statusValid)); params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); } @Test - public void testSubjectGroupValid() throws Exception { + void testSubjectGroupValid() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); @@ -199,7 +194,7 @@ public void testSubjectGroupValid() throws Exception { @SuppressWarnings("java:S5778") @Test - public void testSubjectInvalid() throws Exception { + void testSubjectInvalid() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); @@ -207,18 +202,17 @@ public void testSubjectInvalid() throws Exception { params.addParameter().setName("status").setValue(new StringType(statusValid)); params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); } @SuppressWarnings("java:S5778") @Test - public void testSubjectReferenceInvalid() throws Exception { + void testSubjectReferenceInvalid() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); @@ -226,18 +220,17 @@ public void testSubjectReferenceInvalid() throws Exception { params.addParameter().setName("status").setValue(new StringType(statusValid)); params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); } @SuppressWarnings("java:S5778") @Test - public void testSubjectAndPractitioner() throws Exception { + void testSubjectAndPractitioner() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); @@ -246,18 +239,17 @@ public void testSubjectAndPractitioner() throws Exception { params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); params.addParameter().setName("practitioner").setValue(new StringType(practitionerValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); } @SuppressWarnings("java:S5778") @Test - public void testSubjectAndOrganization() throws Exception { + void testSubjectAndOrganization() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); @@ -266,17 +258,16 @@ public void testSubjectAndOrganization() throws Exception { params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); params.addParameter().setName("organization").setValue(new StringType(organizationValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); } @Test - public void testPractitionerAndOrganization() throws Exception { + void testPractitionerAndOrganization() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); @@ -285,13 +276,12 @@ public void testPractitionerAndOrganization() throws Exception { params.addParameter().setName("organization").setValue(new StringType(organizationValid)); params.addParameter().setName("practitioner").setValue(new StringType(practitionerValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); // TODO: implement practitioner and organization // assertDoesNotThrow(() -> { // getClient().operation().onType(Measure.class).named("$care-gaps") @@ -303,7 +293,7 @@ public void testPractitionerAndOrganization() throws Exception { } @Test - public void testOrganizationOnly() throws Exception { + void testOrganizationOnly() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); @@ -311,13 +301,12 @@ public void testOrganizationOnly() throws Exception { params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); params.addParameter().setName("organization").setValue(new StringType(organizationValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); // TODO: implement organization // assertDoesNotThrow(() -> { // getClient().operation().onType(Measure.class).named("$care-gaps") @@ -330,7 +319,7 @@ public void testOrganizationOnly() throws Exception { @SuppressWarnings("java:S5778") @Test - public void testPractitionerOnly() throws Exception { + void testPractitionerOnly() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); @@ -338,18 +327,17 @@ public void testPractitionerOnly() throws Exception { params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); params.addParameter().setName("practitioner").setValue(new StringType(practitionerValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); } @SuppressWarnings("java:S5778") @Test - public void testSubjectMultiple() throws Exception { + void testSubjectMultiple() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); @@ -358,36 +346,34 @@ public void testSubjectMultiple() throws Exception { params.addParameter().setName("status").setValue(new StringType(statusValid)); params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); } @SuppressWarnings("java:S5778") @Test - public void testNoMeasure() throws Exception { + void testNoMeasure() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); params.addParameter().setName("subject").setValue(new StringType(subjectPatientValid)); params.addParameter().setName("status").setValue(new StringType(statusValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); } @SuppressWarnings("java:S5778") @Test - public void testStatusInvalid() throws Exception { + void testStatusInvalid() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); @@ -395,35 +381,33 @@ public void testStatusInvalid() throws Exception { params.addParameter().setName("status").setValue(new StringType(statusInvalid)); params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); } @SuppressWarnings("java:S5778") @Test - public void testStatusNull() throws Exception { + void testStatusNull() { Parameters params = new Parameters(); params.addParameter().setName("periodStart").setValue(new StringType(periodStartValid)); params.addParameter().setName("periodEnd").setValue(new StringType(periodEndValid)); params.addParameter().setName("subject").setValue(new StringType(subjectPatientValid)); params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); - assertThrows(InternalErrorException.class, () -> { + assertThrows(InternalErrorException.class, () -> getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) - .execute(); - }); + .execute()); } @Test - public void testMultipleStatusValid() throws Exception { + void testMultipleStatusValid() { beforeEachMeasure(); Parameters params = new Parameters(); @@ -444,7 +428,7 @@ public void testMultipleStatusValid() throws Exception { } @Test - public void testMeasures() throws Exception { + void testMeasures() { beforeEachMultipleMeasures(); Parameters params = new Parameters(); @@ -470,7 +454,7 @@ public void testMeasures() throws Exception { @SuppressWarnings("java:S5778") @Test - public void testParallelMultiSubject() throws Exception { + void testParallelMultiSubject() { beforeEachParallelMeasure(); Parameters params = new Parameters(); @@ -480,10 +464,12 @@ public void testParallelMultiSubject() throws Exception { params.addParameter().setName("status").setValue(new StringType(statusValid)); params.addParameter().setName("measureId").setValue(new StringType(measureIdValid)); - getClient().operation().onType(Measure.class).named("$care-gaps") + Parameters result = getClient().operation().onType(Measure.class).named("$care-gaps") .withParameters(params) .useHttpGet() .returnResourceType(Parameters.class) .execute(); + + assertNotNull(result); } } diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/CollectDataProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/CollectDataProviderIT.java index 54ba7ca2f..25bb46758 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/CollectDataProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/CollectDataProviderIT.java @@ -25,13 +25,13 @@ import ca.uhn.fhir.jpa.partition.SystemRequestDetails; @SpringBootTest(classes = { CollectDataProviderIT.class }, properties = { "hapi.fhir.fhir_version=r4", }) -public class CollectDataProviderIT extends DaoIntegrationTest { +class CollectDataProviderIT extends DaoIntegrationTest { @Autowired CollectDataProvider collectDataProvider; @Test - public void testCollectData() { + void testCollectData() { // Create test Measure String cql = CqlBuilder.newCqlLibrary("4.0.1") .addExpression( diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/DataOperationProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/DataOperationProviderIT.java index 2efd3c08f..b897723b6 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/DataOperationProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/DataOperationProviderIT.java @@ -1,7 +1,5 @@ package org.opencds.cqf.ruler.cr.r4.provider; -import java.io.IOException; - import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.DataRequirement; import org.hl7.fhir.r4.model.IdType; @@ -13,21 +11,20 @@ import org.springframework.boot.test.context.SpringBootTest; import static org.junit.jupiter.api.Assertions.*; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { DataOperationProviderIT.class, - CrConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) -public class DataOperationProviderIT extends RestIntegrationTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { DataOperationProviderIT.class, CrConfig.class }, + properties = { "hapi.fhir.fhir_version=r4" }) +class DataOperationProviderIT extends RestIntegrationTest { @Test - public void testR4LibraryDataRequirementsOperation() throws IOException { - String bundleAsText = stringFromResource( "DataReqLibraryTransactionBundleR4.json"); - Bundle bundle = (Bundle)getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); + void testR4LibraryDataRequirementsOperation() { + loadTransaction("DataReqLibraryTransactionBundleR4.json"); - Parameters params = newParameters(newPart("target", "dummy")); + Parameters params = parameters(stringPart("target", "dummy")); Library returnLibrary = getClient().operation() .onInstance(new IdType("Library", "LibraryEvaluationTest")) @@ -46,14 +43,13 @@ public void testR4LibraryDataRequirementsOperation() throws IOException { .execute(); assertNotNull(returnLibrary2); - assertNotNull(returnLibrary2.getDataRequirement().get(1).getExtensionByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-pertinence")); + assertNotNull(returnLibrary2.getDataRequirement().get(1).getExtensionByUrl( + "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-pertinence")); } @Test - public void testR4LibraryDataRequirementsNonManifestMultiVersionOperation() throws IOException { - String bundleAsText = stringFromResource( "DataReqLibraryTransactionBundleMultiVersionR4.json"); - Bundle bundle = (Bundle)getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); + void testR4LibraryDataRequirementsNonManifestMultiVersionOperation() { + loadTransaction("DataReqLibraryTransactionBundleMultiVersionR4.json"); Library library = getClient().read().resource(Library.class).withId("LibraryEvaluationTest").execute(); assertNotNull(library); @@ -67,8 +63,7 @@ public void testR4LibraryDataRequirementsNonManifestMultiVersionOperation() thro assertEquals(library.getUrl(), library2.getUrl()); - Parameters params = newParameters( - newPart("target", "dummy")); + Parameters params = parameters(stringPart("target", "dummy")); Library returnLibrary1 = getClient().operation() .onInstance(new IdType("Library", "LibraryEvaluationTest")) @@ -99,43 +94,48 @@ public void testR4LibraryDataRequirementsNonManifestMultiVersionOperation() thro } @Test - public void testR4LibraryFhirQueryPattern() throws IOException { - String bundleAsText = stringFromResource("ExmLogicTransactionBundle.json"); - Bundle bundle = (Bundle)getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); + void testR4LibraryFhirQueryPattern() { + loadTransaction("ExmLogicTransactionBundle.json"); - Parameters params = newParameters(newPart("target", "dummy")); + Parameters params = parameters(stringPart("target", "dummy")); - Library returnLibrary = getClient().operation().onInstance(new IdType("Library", "EXMLogic")) - .named("$data-requirements") - .withParameters(params) - .returnResourceType(Library.class) - .execute(); + Library returnLibrary = getClient().operation() + .onInstance(new IdType("Library", "EXMLogic")) + .named("$data-requirements") + .withParameters(params) + .returnResourceType(Library.class) + .execute(); assertNotNull(returnLibrary); for (DataRequirement dr : returnLibrary.getDataRequirement()) { switch (dr.getType()) { case "Patient": { - String query = dr.getExtensionByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern").getValueAsPrimitive().getValueAsString(); - assertTrue("Patient?_id={{context.patientId}}".equals(query)); + String query = dr.getExtensionByUrl( + "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern") + .getValueAsPrimitive().getValueAsString(); + assertEquals("Patient?_id={{context.patientId}}", query); } break; case "Encounter": { - String query = dr.getExtensionByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern").getValueAsPrimitive().getValueAsString(); + String query = dr.getExtensionByUrl( + "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern") + .getValueAsPrimitive().getValueAsString(); if (dr.hasCodeFilter()) { - assertTrue("Encounter?subject=Patient/{{context.patientId}}&type:in=http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292".equals(query)); + assertEquals("Encounter?subject=Patient/{{context.patientId}}&type:in=http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292", query); } else { - assertTrue("Encounter?subject=Patient/{{context.patientId}}".equals(query)); + assertEquals("Encounter?subject=Patient/{{context.patientId}}", query); } } break; case "Coverage": { - String query = dr.getExtensionByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern").getValueAsPrimitive().getValueAsString(); - assertTrue("Coverage?policy-holder=Patient/{{context.patientId}}&type:in=http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.3591".equals(query)); + String query = dr.getExtensionByUrl( + "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern") + .getValueAsPrimitive().getValueAsString(); + assertEquals("Coverage?policy-holder=Patient/{{context.patientId}}&type:in=http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.3591", query); } break; } @@ -143,64 +143,68 @@ public void testR4LibraryFhirQueryPattern() throws IOException { } @Test - public void testR4MeasureDataRequirementsOperation() throws IOException { - String bundleAsText = stringFromResource( "Exm104FhirR4MeasureBundle.json"); - Bundle bundle = (Bundle)getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); + void testR4MeasureDataRequirementsOperation() { + loadTransaction("Exm104FhirR4MeasureBundle.json"); - Parameters params = newParameters( - newPart("startPeriod", "2019-01-01"), - newPart("endPeriod", "2020-01-01")); + Parameters params = parameters( + stringPart("startPeriod", "2019-01-01"), + stringPart("endPeriod", "2020-01-01")); - Library returnLibrary = getClient().operation().onInstance(new IdType("Measure", "measure-EXM104-8.2.000")) - .named("$data-requirements") - .withParameters(params) - .returnResourceType(Library.class) - .execute(); + Library returnLibrary = getClient().operation() + .onInstance(new IdType("Measure", "measure-EXM104-8.2.000")) + .named("$data-requirements") + .withParameters(params) + .returnResourceType(Library.class) + .execute(); assertNotNull(returnLibrary); } @Test - public void testR4MeasureFhirQueryPattern() throws IOException { - String bundleAsText = stringFromResource("ExmLogicMeasureTransactionBundle.json"); - Bundle bundle = (Bundle)getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); + void testR4MeasureFhirQueryPattern() { + loadTransaction("ExmLogicMeasureTransactionBundle.json"); - Parameters params = newParameters( - newPart("startPeriod", "2019-01-01"), - newPart("endPeriod", "2020-01-01")); + Parameters params = parameters( + stringPart("startPeriod", "2019-01-01"), + stringPart("endPeriod", "2020-01-01")); - Library returnLibrary = getClient().operation().onInstance(new IdType("Measure", "measure-exm")) - .named("$data-requirements") - .withParameters(params) - .returnResourceType(Library.class) - .execute(); + Library returnLibrary = getClient().operation() + .onInstance(new IdType("Measure", "measure-exm")) + .named("$data-requirements") + .withParameters(params) + .returnResourceType(Library.class) + .execute(); assertNotNull(returnLibrary); for (DataRequirement dr : returnLibrary.getDataRequirement()) { switch (dr.getType()) { case "Patient": { - String query = dr.getExtensionByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern").getValueAsPrimitive().getValueAsString(); - assertTrue("Patient?_id={{context.patientId}}".equals(query)); + String query = dr.getExtensionByUrl( + "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern") + .getValueAsPrimitive().getValueAsString(); + assertEquals("Patient?_id={{context.patientId}}", query); } break; case "Encounter": { - String query = dr.getExtensionByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern").getValueAsPrimitive().getValueAsString(); + String query = dr.getExtensionByUrl( + "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern") + .getValueAsPrimitive().getValueAsString(); if (dr.hasCodeFilter()) { - assertTrue("Encounter?status=finished&subject=Patient/{{context.patientId}}&type:in=http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292".equals(query)); + assertEquals("Encounter?status=finished&subject=Patient/{{context.patientId}}&type:in=http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.117.1.7.1.292", query); } else { - assertTrue("Encounter?subject=Patient/{{context.patientId}}".equals(query)); + assertEquals("Encounter?subject=Patient/{{context.patientId}}", query); } } break; case "Coverage": { - String query = dr.getExtensionByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern").getValueAsPrimitive().getValueAsString(); - assertTrue("Coverage?policy-holder=Patient/{{context.patientId}}&type:in=http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.3591".equals(query)); + String query = dr.getExtensionByUrl( + "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern") + .getValueAsPrimitive().getValueAsString(); + assertEquals("Coverage?policy-holder=Patient/{{context.patientId}}&type:in=http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.114222.4.11.3591", query); } break; } @@ -208,47 +212,50 @@ public void testR4MeasureFhirQueryPattern() throws IOException { } @Test - public void testR4LibraryEvaluationTest() throws IOException { + void testR4LibraryEvaluationTest() { String bundleAsText = stringFromResource("bundlegen-bundle.json"); Bundle bundle = (Bundle)getFhirContext().newJsonParser().parseResource(bundleAsText); getClient().transaction().withBundle(bundle).execute(); + loadTransaction("bundlegen-bundle.json"); - Parameters params = newParameters(newPart("target", "dummy")); + Parameters params = parameters(stringPart("target", "dummy")); - Library returnLibrary = getClient().operation().onInstance(new IdType("Library", "LibraryEvaluationTest")) - .named("$data-requirements") - .withParameters(params) - .returnResourceType(Library.class) - .execute(); + Library returnLibrary = getClient().operation() + .onInstance(new IdType("Library", "LibraryEvaluationTest")) + .named("$data-requirements") + .withParameters(params) + .returnResourceType(Library.class) + .execute(); assertNotNull(returnLibrary); - System.out.println("Resource:"+this.getFhirContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(returnLibrary)); for (DataRequirement dr : returnLibrary.getDataRequirement()) { - String query = dr.getExtensionByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern").getValueAsPrimitive().getValueAsString(); + String query = dr.getExtensionByUrl( + "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern") + .getValueAsPrimitive().getValueAsString(); switch (dr.getType()) { case "Patient": { - assertTrue("Patient?_id={{context.patientId}}".equals(query)); + assertEquals("Patient?_id={{context.patientId}}", query); } break; case "Condition": { if (dr.hasCodeFilter() && dr.getCodeFilter().size() > 0) { - assertTrue("Condition?category:in=http://mcg.com/fhir/ValueSet/condition-problem-list-category&subject=Patient/{{context.patientId}}".equals(query)); + assertEquals("Condition?category:in=http://mcg.com/fhir/ValueSet/condition-problem-list-category&subject=Patient/{{context.patientId}}", query); } else { - assertTrue("Condition?subject=Patient/{{context.patientId}}".equals(query)); + assertEquals("Condition?subject=Patient/{{context.patientId}}", query); } } break; case "Encounter": { - assertTrue("Encounter?subject=Patient/{{context.patientId}}".equals(query)); + assertEquals("Encounter?subject=Patient/{{context.patientId}}", query); } break; case "Procedure": { - assertTrue("Procedure?subject=Patient/{{context.patientId}}".equals(query)); + assertEquals("Procedure?subject=Patient/{{context.patientId}}", query); } break; } diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/MeasureEvaluateAdditionalDataTest.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/MeasureEvaluateAdditionalDataTest.java index ca406c439..1b41b1ad0 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/MeasureEvaluateAdditionalDataTest.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/MeasureEvaluateAdditionalDataTest.java @@ -1,12 +1,14 @@ package org.opencds.cqf.ruler.cr.r4.provider; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.MeasureReport; import org.hl7.fhir.r4.model.Parameters; -import org.hl7.fhir.r4.model.StringType; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -22,7 +24,7 @@ }) @TestInstance(TestInstance.Lifecycle.PER_METHOD) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -public class MeasureEvaluateAdditionalDataTest extends RestIntegrationTest { +class MeasureEvaluateAdditionalDataTest extends RestIntegrationTest { @Override public void baseAfterAll() { @@ -36,7 +38,7 @@ public void afterEach() { } @Test - public void testMeasureEvaluateWithXmlAdditionalData() throws Exception { + void testMeasureEvaluateWithXmlAdditionalData() { String mainBundleAsText = stringFromResource("ClientNonPatientBasedMeasureBundle.json"); Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(mainBundleAsText); getClient().transaction().withBundle(bundle).execute(); @@ -57,7 +59,7 @@ public void testMeasureEvaluateWithXmlAdditionalData() throws Exception { } @Test - public void testMeasureEvaluateWithAdditionalData() throws Exception { + void testMeasureEvaluateWithAdditionalData() { String mainBundleAsText = stringFromResource("Exm104FhirR4MeasurePartBundle.json"); Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(mainBundleAsText); @@ -66,13 +68,14 @@ public void testMeasureEvaluateWithAdditionalData() throws Exception { String additionalBundleAsText = stringFromResource("Exm104FhirR4MeasureAdditionalData.json"); Bundle additionalData = (Bundle) getFhirContext().newJsonParser().parseResource(additionalBundleAsText); - Parameters params = new Parameters(); - params.addParameter().setName("periodStart").setValue(new StringType("2019-01-01")); - params.addParameter().setName("periodEnd").setValue(new StringType("2020-01-01")); - params.addParameter().setName("reportType").setValue(new StringType("subject")); - params.addParameter().setName("subject").setValue(new StringType("Patient/numer-EXM104")); - params.addParameter().setName("lastReceivedOn").setValue(new StringType("2019-12-12")); - params.addParameter().setName("additionalData").setResource(additionalData); + Parameters params = parameters( + stringPart("periodStart", "2019-01-01"), + stringPart("periodEnd", "2020-01-01"), + stringPart("reportType", "subject"), + stringPart("subject", "Patient/numer-EXM104"), + stringPart("lastReceivedOn", "2019-12-12"), + part("additionalData", additionalData) + ); MeasureReport returnMeasureReport = getClient().operation() .onInstance(new IdType("Measure", "measure-EXM104-8.2.000")) diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/MeasureEvaluateProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/MeasureEvaluateProviderIT.java index 0258790b5..b0e28bdd5 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/MeasureEvaluateProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/MeasureEvaluateProviderIT.java @@ -4,12 +4,12 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; +import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; import java.util.Optional; -import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Endpoint; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Measure; @@ -17,7 +17,6 @@ import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Resource; -import org.hl7.fhir.r4.model.StringType; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.opencds.cqf.ruler.cql.CqlConfig; @@ -25,25 +24,21 @@ import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = { - MeasureEvaluateProviderIT.class, - CrConfig.class, CqlConfig.class }, properties = { - "hapi.fhir.fhir_version=r4", "hapi.fhir.security.enabled=true" }) - -public class MeasureEvaluateProviderIT extends RestIntegrationTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, + classes = { MeasureEvaluateProviderIT.class, CrConfig.class, CqlConfig.class }, + properties = { "hapi.fhir.fhir_version=r4", "hapi.fhir.security.enabled=true" }) +class MeasureEvaluateProviderIT extends RestIntegrationTest { @Test - public void testMeasureEvaluate() throws Exception { - String bundleAsText = stringFromResource("Exm104FhirR4MeasureBundle.json"); - Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); - - Parameters params = newParameters( - newPart("periodStart", "2019-01-01"), - newPart("periodEnd", "2020-01-01"), - newPart("reportType", "individual"), - newPart("subject", "Patient/numer-EXM104"), - newPart("lastReceivedOn", "2019-12-12")); + void testMeasureEvaluate() { + loadTransaction("Exm104FhirR4MeasureBundle.json"); + + Parameters params = parameters( + stringPart("periodStart", "2019-01-01"), + stringPart("periodEnd", "2020-01-01"), + stringPart("reportType", "individual"), + stringPart("subject", "Patient/numer-EXM104"), + stringPart("lastReceivedOn", "2019-12-12")); MeasureReport returnMeasureReport = getClient().operation() .onInstance(new IdType("Measure", "measure-EXM104-8.2.000")) @@ -56,31 +51,26 @@ public void testMeasureEvaluate() throws Exception { } @Test - public void testMeasureEvaluateWithTerminologyEndpoint() throws Exception { - String bundleAsText = stringFromResource("Exm104FhirR4MeasureBundle.json"); - Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); + void testMeasureEvaluateWithTerminologyEndpoint() { + loadTransaction("Exm104FhirR4MeasureBundle.json"); getClient().operation().onInstance(new IdType("ValueSet", "2.16.840.1.114222.4.11.3591")).named("expand") .withNoParameters(Parameters.class).execute(); - String terminologyAsText = stringFromResource("Endpoint.json"); - - Endpoint terminologyEndpointValid = (Endpoint) getFhirContext().newJsonParser().parseResource(terminologyAsText); + Endpoint terminologyEndpointValid = (Endpoint) loadResource("Endpoint.json"); terminologyEndpointValid.setAddress(this.getServerBase()); - Endpoint terminologyEndpointInvalid = (Endpoint) getFhirContext().newJsonParser() - .parseResource(terminologyAsText); + Endpoint terminologyEndpointInvalid = (Endpoint) loadResource("Endpoint.json"); terminologyEndpointInvalid.setAddress("https://tx.nhsnlink.org/fhir234"); - Parameters params = newParameters( - newPart("periodStart", "2019-01-01"), - newPart("periodEnd", "2020-01-01"), - newPart("reportType", "individual"), - newPart("subject", "Patient/numer-EXM104"), - newPart("lastReceivedOn", "2019-12-12"), - newPart("terminologyEndpoint", terminologyEndpointValid)); + Parameters params = parameters( + stringPart("periodStart", "2019-01-01"), + stringPart("periodEnd", "2020-01-01"), + stringPart("reportType", "individual"), + stringPart("subject", "Patient/numer-EXM104"), + stringPart("lastReceivedOn", "2019-12-12"), + part("terminologyEndpoint", terminologyEndpointValid)); MeasureReport returnMeasureReport = getClient().operation() .onInstance(new IdType("Measure", "measure-EXM104-8.2.000")) @@ -91,22 +81,20 @@ public void testMeasureEvaluateWithTerminologyEndpoint() throws Exception { assertNotNull(returnMeasureReport); - Parameters paramsWithInvalidTerminology = newParameters( - newPart("periodStart", "2019-01-01"), - newPart("periodEnd", "2020-01-01"), - newPart("reportType", "individual"), - newPart("subject", "Patient/numer-EXM104"), - newPart("lastReceivedOn", "2019-12-12"), - newPart("terminologyEndpoint", terminologyEndpointInvalid)); - - Exception ex = assertThrows(Exception.class, () -> { - getClient().operation() - .onInstance(new IdType("Measure", "measure-EXM104-8.2.000")) - .named("$evaluate-measure") - .withParameters(paramsWithInvalidTerminology) - .returnResourceType(MeasureReport.class) - .execute(); - }); + Parameters paramsWithInvalidTerminology = parameters( + stringPart("periodStart", "2019-01-01"), + stringPart("periodEnd", "2020-01-01"), + stringPart("reportType", "individual"), + stringPart("subject", "Patient/numer-EXM104"), + stringPart("lastReceivedOn", "2019-12-12"), + part("terminologyEndpoint", terminologyEndpointInvalid)); + + Exception ex = assertThrows(Exception.class, () -> getClient().operation() + .onInstance(new IdType("Measure", "measure-EXM104-8.2.000")) + .named("$evaluate-measure") + .withParameters(paramsWithInvalidTerminology) + .returnResourceType(MeasureReport.class) + .execute()); assertTrue(ex.getMessage().contains("Error performing expansion")); } @@ -114,13 +102,14 @@ public void testMeasureEvaluateWithTerminologyEndpoint() throws Exception { private void runWithPatient(String measureId, String patientId, int initialPopulationCount, int denominatorCount, int denominatorExclusionCount, int numeratorCount, boolean enrolledDuringParticipationPeriod, String participationPeriod) { - Parameters params = new Parameters(); - params.addParameter().setName("periodStart").setValue(new StringType("2022-01-01")); - params.addParameter().setName("periodEnd").setValue(new StringType("2022-12-31")); - params.addParameter().setName("reportType").setValue(new StringType("individual")); - params.addParameter().setName("subject").setValue(new StringType(patientId)); + Parameters params = parameters( + stringPart("periodStart", "2022-01-01"), + stringPart("periodEnd", "2022-12-31"), + stringPart("reportType", "individual"), + stringPart("subject", patientId)); - MeasureReport returnMeasureReport = getClient().operation().onInstance(new IdType("Measure", measureId)) + MeasureReport returnMeasureReport = getClient().operation() + .onInstance(new IdType("Measure", measureId)) .named("$evaluate-measure") .withParameters(params) .returnResourceType(MeasureReport.class) @@ -153,10 +142,8 @@ private void runWithPatient(String measureId, String patientId, int initialPopul Observation o = (Observation) r; if (o.getCode().getText().equals("Enrolled During Participation Period")) { enrolledDuringParticipationPeriodObs = o; - continue; } else if (o.getCode().getText().equals("Participation Period")) { participationPeriodObs = o; - continue; } } } @@ -170,10 +157,8 @@ private void runWithPatient(String measureId, String patientId, int initialPopul } @Test - public void testBCSEHEDISMY2022() throws Exception { - String bundleAsText = stringFromResource("BCSEHEDISMY2022-bundle.json"); - Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); + void testBCSEHEDISMY2022() { + loadTransaction("BCSEHEDISMY2022-bundle.json"); runWithPatient("BCSEHEDISMY2022", "Patient/Patient-5", 0, 0, 0, 0, false, "Interval[2020-10-01T00:00:00.000, 2022-12-31T23:59:59.999]"); @@ -190,19 +175,17 @@ public void testBCSEHEDISMY2022() throws Exception { } @Test - public void testClientNonPatientBasedMeasureEvaluate() throws Exception { - String bundleAsText = stringFromResource("ClientNonPatientBasedMeasureBundle.json"); - Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText); - getClient().transaction().withBundle(bundle).execute(); + void testClientNonPatientBasedMeasureEvaluate() { + loadTransaction("ClientNonPatientBasedMeasureBundle.json"); Measure measure = getClient().read().resource(Measure.class).withId("InitialInpatientPopulation").execute(); assertNotNull(measure); - Parameters params = new Parameters(); - params.addParameter().setName("periodStart").setValue(new StringType("2019-01-01")); - params.addParameter().setName("periodEnd").setValue(new StringType("2020-01-01")); - params.addParameter().setName("reportType").setValue(new StringType("subject")); - params.addParameter().setName("subject").setValue(new StringType("Patient/97f27374-8a5c-4aa1-a26f-5a1ab03caa47")); + Parameters params = parameters( + stringPart("periodStart", "2019-01-01"), + stringPart("periodEnd", "2020-01-01"), + stringPart("reportType", "subject"), + stringPart("subject", "Patient/97f27374-8a5c-4aa1-a26f-5a1ab03caa47")); MeasureReport returnMeasureReport = getClient().operation() .onInstance(new IdType("Measure", "InitialInpatientPopulation")) @@ -228,17 +211,13 @@ public void testClientNonPatientBasedMeasureEvaluate() throws Exception { @Disabled("The cql/elm in the Bundles is incorrect. It references ValueSets by localhost url, which is not valid") @Test - public void testMeasureEvaluateMultiVersion() throws Exception { - String bundleAsTextVersion7 = stringFromResource("multiversion/EXM124-7.0.000-bundle.json"); - String bundleAsTextVersion9 = stringFromResource("multiversion/EXM124-9.0.000-bundle.json"); - Bundle bundleVersion7 = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsTextVersion7); - Bundle bundleVersion9 = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsTextVersion9); - getClient().transaction().withBundle(bundleVersion7).execute(); - getClient().transaction().withBundle(bundleVersion9).execute(); - Parameters params = new Parameters(); - params.addParameter().setName("reportType").setValue(new StringType("individual")); - params.addParameter().setName("subject").setValue(new StringType("Patient/numer-EXM124")); - params.addParameter().setName("lastReceivedOn").setValue(new StringType("2019-12-12")); + void testMeasureEvaluateMultiVersion() { + loadTransaction("multiversion/EXM124-7.0.000-bundle.json"); + loadTransaction("multiversion/EXM124-9.0.000-bundle.json"); + Parameters params = parameters( + stringPart("reportType", "individual"), + stringPart("subject", "Patient/numer-EXM124"), + stringPart("lastReceivedOn", "2019-12-12")); MeasureReport returnMeasureReportVersion7 = getClient().operation() .onInstance(new IdType("Measure", "measure-EXM124-7.0.000")) @@ -257,7 +236,6 @@ public void testMeasureEvaluateMultiVersion() throws Exception { .execute(); assertNotNull(returnMeasureReportVersion9); - } } diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/PlanDefinitionApplyProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/PlanDefinitionApplyProviderIT.java index f0fe7a508..e8324d6de 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/PlanDefinitionApplyProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/PlanDefinitionApplyProviderIT.java @@ -1,11 +1,10 @@ package org.opencds.cqf.ruler.cr.r4.provider; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.Map; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r4.model.CarePlan; import org.hl7.fhir.r4.model.DomainResource; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,7 +21,7 @@ CrConfig.class, CqlConfig.class }, properties = { "hapi.fhir.fhir_version=r4", }) -public class PlanDefinitionApplyProviderIT extends RestIntegrationTest { +class PlanDefinitionApplyProviderIT extends RestIntegrationTest { @Autowired private PlanDefinitionApplyProvider planDefinitionApplyProvider; @@ -37,15 +36,15 @@ public void setup() throws Exception { } @Test - public void testPlanDefinitionApplyFormerSmoker() throws Exception { + void testPlanDefinitionApplyFormerSmoker() throws Exception { DomainResource plandefinition = (DomainResource) planDefinitions.get("lcs-cds-patient-view"); // Patient First uploadTests("test/plandefinition/LungCancerScreening/Former-Smoker/Patient"); Map resources = uploadTests("test/plandefinition/LungCancerScreening/Former-Smoker"); IBaseResource patient = resources.get("Former-Smoker"); Object isFormerSmoker = planDefinitionApplyProvider.applyPlanDefinition(new SystemRequestDetails(), - plandefinition.getIdElement(), patient.getIdElement().getIdPart(), null, null, null, null, null, null, null, - null); - assertTrue(isFormerSmoker instanceof CarePlan); + plandefinition.getIdElement(), patient.getIdElement().getIdPart(), null, null, + null, null, null, null, null, null); + assertNotNull(isFormerSmoker); } } diff --git a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/SubmitDataProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/SubmitDataProviderIT.java index 8e93ed24a..9ce48a006 100644 --- a/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/SubmitDataProviderIT.java +++ b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/SubmitDataProviderIT.java @@ -18,13 +18,13 @@ import ca.uhn.fhir.jpa.partition.SystemRequestDetails; @SpringBootTest(classes = { SubmitDataProviderIT.class }, properties = { "hapi.fhir.fhir_version=r4", }) -public class SubmitDataProviderIT extends DaoIntegrationTest { +class SubmitDataProviderIT extends DaoIntegrationTest { @Autowired SubmitDataProvider mySubmitDataProvider; @Test - public void testSubmitData() { + void testSubmitData() { // Create a MR and a resource MeasureReport mr = newResource(MeasureReport.class, "test-mr"); Observation obs = newResource(Observation.class, "test-obs"); @@ -42,7 +42,7 @@ public void testSubmitData() { } @Test - public void testSubmitDataNoId() { + void testSubmitDataNoId() { // Create a MR and a resource MeasureReport mr = newResource(MeasureReport.class).setMeasure("Measure/A123"); Observation obs = newResource(Observation.class).setValue(new StringType("ABC")); diff --git a/plugin/cr/src/test/resources/Exm105FhirR3MeasureAdditionalData.json b/plugin/cr/src/test/resources/Exm105FhirR3MeasureAdditionalData.json index c4c47a520..ee830b93c 100644 --- a/plugin/cr/src/test/resources/Exm105FhirR3MeasureAdditionalData.json +++ b/plugin/cr/src/test/resources/Exm105FhirR3MeasureAdditionalData.json @@ -1,7 +1,7 @@ { "resourceType": "Bundle", "id": "Exm105FhirR3MeasureAdditionalData", - "type": "transaction", + "type": "collection", "entry": [ { "resource": { diff --git a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/DevToolsConfig.java b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/DevToolsConfig.java index 0b987c576..a1820ccc2 100644 --- a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/DevToolsConfig.java +++ b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/DevToolsConfig.java @@ -1,6 +1,5 @@ package org.opencds.cqf.ruler.devtools; -import org.opencds.cqf.ruler.api.OperationProvider; import org.opencds.cqf.ruler.external.annotations.OnDSTU3Condition; import org.opencds.cqf.ruler.external.annotations.OnR4Condition; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -35,25 +34,25 @@ public DevToolsProperties devToolsProperties() { @Bean @Conditional(OnR4Condition.class) - public OperationProvider r4CodeSystemUpdateProvider() { + public org.opencds.cqf.ruler.devtools.r4.CodeSystemUpdateProvider r4CodeSystemUpdateProvider() { return new org.opencds.cqf.ruler.devtools.r4.CodeSystemUpdateProvider(); } @Bean @Conditional(OnDSTU3Condition.class) - public OperationProvider dstu3CodeSystemUpdateProvider() { + public org.opencds.cqf.ruler.devtools.dstu3.CodeSystemUpdateProvider dstu3CodeSystemUpdateProvider() { return new org.opencds.cqf.ruler.devtools.dstu3.CodeSystemUpdateProvider(); } @Bean @Conditional(OnR4Condition.class) - public OperationProvider r4CacheValueSetsProvider() { + public org.opencds.cqf.ruler.devtools.r4.CacheValueSetsProvider r4CacheValueSetsProvider() { return new org.opencds.cqf.ruler.devtools.r4.CacheValueSetsProvider(); } @Bean @Conditional(OnDSTU3Condition.class) - public OperationProvider dstu3CacheValueSetsProvider() { + public org.opencds.cqf.ruler.devtools.dstu3.CacheValueSetsProvider dstu3CacheValueSetsProvider() { return new org.opencds.cqf.ruler.devtools.dstu3.CacheValueSetsProvider(); } } diff --git a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProviderIT.java b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProviderIT.java index bdf0a87ad..b02a60a5d 100644 --- a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProviderIT.java +++ b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProviderIT.java @@ -6,7 +6,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.util.Arrays; +import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import org.hl7.fhir.dstu3.model.Bundle; @@ -28,14 +29,15 @@ import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.StringAndListParam; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CacheValueSetsProviderIT.class, - DevToolsConfig.class },properties = "hapi.fhir.fhir_version=dstu3") -public class CacheValueSetsProviderIT extends RestIntegrationTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { CacheValueSetsProviderIT.class, DevToolsConfig.class }, + properties = { "hapi.fhir.fhir_version=dstu3" }) +class CacheValueSetsProviderIT extends RestIntegrationTest { @Autowired private CacheValueSetsProvider cacheValueSetsProvider; @Test - public void testCacheValueSetsEndpointDNE() throws Exception { + void testCacheValueSetsEndpointDNE() throws Exception { Endpoint endpoint = new Endpoint(); endpoint.setId(new IdType("localhost")); StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json"); @@ -47,7 +49,7 @@ public void testCacheValueSetsEndpointDNE() throws Exception { } @Test - public void testCacheValueSetsEndpointNull() throws Exception { + void testCacheValueSetsEndpointNull() throws Exception { StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json"); RequestDetails details = Mockito.mock(RequestDetails.class); Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, new Endpoint().getIdElement(), @@ -56,7 +58,7 @@ public void testCacheValueSetsEndpointNull() throws Exception { } @Test - public void testCacheValueSetsAuthenticationErrorUsername() throws Exception { + void testCacheValueSetsAuthenticationErrorUsername() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json"); RequestDetails details = Mockito.mock(RequestDetails.class); @@ -67,7 +69,7 @@ public void testCacheValueSetsAuthenticationErrorUsername() throws Exception { } @Test - public void testCacheValueSetsAuthenticationErrorPassword() throws Exception { + void testCacheValueSetsAuthenticationErrorPassword() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json"); RequestDetails details = Mockito.mock(RequestDetails.class); @@ -78,11 +80,11 @@ public void testCacheValueSetsAuthenticationErrorPassword() throws Exception { } @Test - public void testCacheValueSetsValueSetDNE() throws Exception { + void testCacheValueSetsValueSetDNE() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); StringAndListParam stringAndListParam = new StringAndListParam(); stringAndListParam.setValuesAsQueryTokens(getFhirContext(), "valueset", - Arrays.asList(QualifiedParamList.singleton("dne"))); + List.of(QualifiedParamList.singleton("dne"))); RequestDetails details = Mockito.mock(RequestDetails.class); Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, endpoint.getIdElement(), stringAndListParam, null, null); @@ -90,11 +92,11 @@ public void testCacheValueSetsValueSetDNE() throws Exception { } @Test - public void testCacheValueSetsValueSetNull() throws Exception { + void testCacheValueSetsValueSetNull() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); StringAndListParam stringAndListParam = new StringAndListParam(); stringAndListParam.setValuesAsQueryTokens(getFhirContext(), "valueset", - Arrays.asList(QualifiedParamList.singleton(new ValueSet().getId()))); + List.of(QualifiedParamList.singleton(new ValueSet().getId()))); RequestDetails details = Mockito.mock(RequestDetails.class); Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, endpoint.getIdElement(), stringAndListParam, null, null); @@ -103,7 +105,7 @@ public void testCacheValueSetsValueSetNull() throws Exception { } @Test - public void testCacheValueSetsNoCompose() throws Exception { + void testCacheValueSetsNoCompose() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); RequestDetails details = Mockito.mock(RequestDetails.class); ValueSet vs = uploadValueSet("valueset/valueset-benzodiazepine-medications.json"); @@ -123,40 +125,39 @@ public void testCacheValueSetsNoCompose() throws Exception { // assertTrue(resultingValueSet.getVersion().endsWith("-cached")); } - // Get help with this.... - // @Test - // public void testCacheValueSetsExpandAndAddConcepts() throws Exception { - // Endpoint endpoint = uploadLocalServerEndpoint(); - // RequestDetails details = Mockito.mock(RequestDetails.class); - // ValueSet vs = - // uploadValueSet("valueset/valueset-buprenorphine-and-methadone-medications.json"); - // vs.getCompose().getInclude().forEach(include -> { - // assertTrue(!include.hasConcept()); - // }); - // StringAndListParam stringAndListParam = - // getStringAndListParamFromValueSet(vs); - - // IGenericClient localClient = createClient(ourCtx, endpoint); - // // - // localClient.operation().onServer().named("updateCodeSystems").withNoParameters(Parameters.class).execute(); - // Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, - // endpoint.getIdElement(), stringAndListParam, null, null); - // assertTrue(outcomeResource instanceof Bundle); - // Bundle resultBundle = (Bundle) outcomeResource; - // assertTrue(resultBundle.getEntry().size() == 1); - // BundleEntryComponent entry = resultBundle.getEntry().get(0); - // assertTrue(entry.getResponse().getLocation().startsWith("ValueSet/" + - // vs.getIdElement().getIdPart())); - // assertTrue(entry.getResponse().getStatus().equals("200 OK")); - // ValueSet resultingValueSet = - // localClient.read().resource(ValueSet.class).withId(vs.getIdElement()).execute(); - // resultingValueSet.getCompose().getInclude().forEach(include -> { - // assertTrue(include.hasConcept()); - // }); - // } +// TODO Get help with this.... +// @Test +// void testCacheValueSetsExpandAndAddConcepts() throws Exception { +// Endpoint endpoint = uploadLocalServerEndpoint(); +// RequestDetails details = Mockito.mock(RequestDetails.class); +// ValueSet vs = +// uploadValueSet("valueset/valueset-buprenorphine-and-methadone-medications.json"); +// vs.getCompose().getInclude().forEach(include -> { +// assertFalse(include.hasConcept()); +// }); +// StringAndListParam stringAndListParam = +// getStringAndListParamFromValueSet(vs); +// +// IGenericClient localClient = getClient(); +// localClient.operation().onServer().named("updateCodeSystems").withNoParameters(Parameters.class).execute(); +// Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, +// endpoint.getIdElement(), stringAndListParam, null, null); +// assertTrue(outcomeResource instanceof Bundle); +// Bundle resultBundle = (Bundle) outcomeResource; +// assertEquals(1, resultBundle.getEntry().size()); +// BundleEntryComponent entry = resultBundle.getEntry().get(0); +// assertTrue(entry.getResponse().getLocation().startsWith("ValueSet/" + +// vs.getIdElement().getIdPart())); +// assertEquals("200 OK", entry.getResponse().getStatus()); +// ValueSet resultingValueSet = +// localClient.read().resource(ValueSet.class).withId(vs.getIdElement()).execute(); +// resultingValueSet.getCompose().getInclude().forEach(include -> { +// assertTrue(include.hasConcept()); +// }); +// } @Test - public void testCacheValueSetsAlreadyExpanded() throws Exception { + void testCacheValueSetsAlreadyExpanded() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); RequestDetails details = Mockito.mock(RequestDetails.class); ValueSet vs = uploadValueSet("valueset/valueset-benzodiazepine-medications.json"); @@ -176,10 +177,10 @@ private StringAndListParam getStringAndListParamFromValueSet(String location) th return getStringAndListParamFromValueSet(vs); } - private StringAndListParam getStringAndListParamFromValueSet(ValueSet vs) throws IOException { + private StringAndListParam getStringAndListParamFromValueSet(ValueSet vs) { StringAndListParam stringAndListParam = new StringAndListParam(); stringAndListParam.setValuesAsQueryTokens(getFhirContext(), "valueset", - Arrays.asList(QualifiedParamList.singleton(vs.getIdElement().getIdPart()))); + List.of(QualifiedParamList.singleton(vs.getIdElement().getIdPart()))); return stringAndListParam; } @@ -193,8 +194,8 @@ private void validateOutcome(Resource outcomeResource, String detailMessage) { } private ValueSet uploadValueSet(String location) throws IOException { - BufferedReader reader = new BufferedReader( - new InputStreamReader(CacheValueSetsProvider.class.getResourceAsStream(location))); + BufferedReader reader = new BufferedReader(new InputStreamReader( + Objects.requireNonNull(CacheValueSetsProvider.class.getResourceAsStream(location)))); String resourceString = reader.lines().collect(Collectors.joining(System.lineSeparator())); reader.close(); return (ValueSet) loadResource("json", resourceString); @@ -202,7 +203,7 @@ private ValueSet uploadValueSet(String location) throws IOException { private Endpoint uploadLocalServerEndpoint() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader( - CacheValueSetsProvider.class.getResourceAsStream("endpoint/LocalServerEndpoint.json"))); + Objects.requireNonNull(CacheValueSetsProvider.class.getResourceAsStream("endpoint/LocalServerEndpoint.json")))); String resourceString = reader.lines().collect(Collectors.joining(System.lineSeparator())); reader.close(); // Don't want to update during loading because need to setAddress first diff --git a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemProviderIT.java b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemProviderIT.java index e63f3a02b..86681d5c4 100644 --- a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemProviderIT.java +++ b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemProviderIT.java @@ -1,6 +1,7 @@ package org.opencds.cqf.ruler.devtools.dstu3; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.BufferedReader; @@ -8,7 +9,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; import java.util.stream.Collectors; import org.apache.commons.io.FilenameUtils; @@ -32,19 +34,18 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CodeSystemProviderIT.class, - DevToolsConfig.class }, properties = "hapi.fhir.fhir_version=dstu3") +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { CodeSystemProviderIT.class, DevToolsConfig.class }, + properties = { "hapi.fhir.fhir_version=dstu3" }) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class CodeSystemProviderIT extends RestIntegrationTest { - private Logger log = LoggerFactory.getLogger(CodeSystemProviderIT.class); +class CodeSystemProviderIT extends RestIntegrationTest { + private final Logger log = LoggerFactory.getLogger(CodeSystemProviderIT.class); @Autowired CodeSystemUpdateProvider codeSystemUpdateProvider; - private String icd10 = "http://hl7.org/fhir/sid/icd-10"; - private String rxNormUrl = "http://www.nlm.nih.gov/research/umls/rxnorm"; - private String snomedSctUrl = "http://snomed.info/sct"; - private String cptUrl = "http://www.ama-assn.org/go/cpt"; + private final String icd10 = "http://hl7.org/fhir/sid/icd-10"; + private final String rxNormUrl = "http://www.nlm.nih.gov/research/umls/rxnorm"; @AfterEach void tearDown() { @@ -55,7 +56,7 @@ void tearDown() { @Test @Order(1) - public void testCodeSystemUpdateValueSetDNE() throws IOException { + void testCodeSystemUpdateValueSetDNE() { ValueSet vs = (ValueSet) readResource("org/opencds/cqf/ruler/devtools/dstu3/valueset/AntithromboticTherapy.json"); OperationOutcome outcome = codeSystemUpdateProvider.updateCodeSystems(vs.getIdElement()); assertEquals(1, outcome.getIssue().size()); @@ -66,7 +67,7 @@ public void testCodeSystemUpdateValueSetDNE() throws IOException { @Test @Order(2) - public void testCodeSystemUpdateValueSetIdNull() { + void testCodeSystemUpdateValueSetIdNull() { OperationOutcome outcome = codeSystemUpdateProvider.updateCodeSystems(new ValueSet().getIdElement()); assertEquals(1, outcome.getIssue().size()); OperationOutcomeIssueComponent issue = outcome.getIssue().get(0); @@ -76,7 +77,7 @@ public void testCodeSystemUpdateValueSetIdNull() { @Test @Order(3) - public void testDSTU3RxNormCodeSystemUpdateById() throws IOException { + void testDSTU3RxNormCodeSystemUpdateById() { log.info("Beginning Test DSTU3 RxNorm CodeSystemUpdate"); ValueSet vs = (ValueSet) loadResource("org/opencds/cqf/ruler/devtools/dstu3/valueset/AntithromboticTherapy.json"); @@ -94,17 +95,18 @@ public void testDSTU3RxNormCodeSystemUpdateById() throws IOException { @Test @Order(4) - public void testDSTU3ICD10PerformCodeSystemUpdateByList() throws IOException { + void testDSTU3ICD10PerformCodeSystemUpdateByList() throws IOException { log.info("Beginning Test DSTU3 ICD10 CodeSystemUpdate"); BufferedReader reader = new BufferedReader(new InputStreamReader( - CodeSystemProviderIT.class.getResourceAsStream("valueset" + "/" + "AllPrimaryandSecondaryCancer.json"))); + Objects.requireNonNull(CodeSystemProviderIT.class.getResourceAsStream( + "valueset" + "/" + "AllPrimaryandSecondaryCancer.json")))); String resourceString = reader.lines().collect(Collectors.joining(System.lineSeparator())); reader.close(); ValueSet vs = (ValueSet) loadResource("json", resourceString); assertEquals(0, performCodeSystemSearchByUrl(icd10).size()); - codeSystemUpdateProvider.performCodeSystemUpdate(Arrays.asList(vs)); + codeSystemUpdateProvider.performCodeSystemUpdate(Collections.singletonList(vs)); OperationOutcome outcome = codeSystemUpdateProvider.updateCodeSystems(vs.getIdElement()); for (OperationOutcomeIssueComponent issue : outcome.getIssue()) { assertEquals(OperationOutcome.IssueSeverity.INFORMATION, issue.getSeverity()); @@ -118,12 +120,15 @@ public void testDSTU3ICD10PerformCodeSystemUpdateByList() throws IOException { @Test @Order(5) - public void testDSTU3UpdateCodeSystems() throws IOException { + void testDSTU3UpdateCodeSystems() throws IOException { log.info("Beginning Test DSTU3 Update Code Systems"); + String cptUrl = "http://www.ama-assn.org/go/cpt"; assertEquals(0, performCodeSystemSearchByUrl(cptUrl).size()); - File[] valuesets = new File(CodeSystemProviderIT.class.getResource("valueset").getPath()).listFiles(); + File[] valuesets = new File(Objects.requireNonNull( + CodeSystemProviderIT.class.getResource("valueset")).getPath()).listFiles(); + assertNotNull(valuesets); for (File file : valuesets) { if (file.isFile() && FilenameUtils.getExtension(file.getPath()).equals("json")) { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); @@ -148,6 +153,7 @@ public void testDSTU3UpdateCodeSystems() throws IOException { } assertEquals(1, performCodeSystemSearchByUrl(icd10).size()); assertEquals(1, performCodeSystemSearchByUrl(rxNormUrl).size()); + String snomedSctUrl = "http://snomed.info/sct"; assertEquals(1, performCodeSystemSearchByUrl(snomedSctUrl).size()); assertEquals(1, performCodeSystemSearchByUrl(cptUrl).size()); diff --git a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProviderIT.java b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProviderIT.java index 6794a9e80..3091dd3d5 100644 --- a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProviderIT.java +++ b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProviderIT.java @@ -6,7 +6,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.util.Arrays; +import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import org.hl7.fhir.r4.model.Bundle; @@ -30,12 +31,12 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CacheValueSetsProviderIT.class, DevToolsConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) -public class CacheValueSetsProviderIT extends RestIntegrationTest { +class CacheValueSetsProviderIT extends RestIntegrationTest { @Autowired private CacheValueSetsProvider cacheValueSetsProvider; @Test - public void testCacheValueSetsEndpointDNE() throws Exception { + void testCacheValueSetsEndpointDNE() throws Exception { Endpoint endpoint = new Endpoint(); endpoint.setId(new IdType("localhost")); StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json"); @@ -47,7 +48,7 @@ public void testCacheValueSetsEndpointDNE() throws Exception { } @Test - public void testCacheValueSetsEndpointNull() throws Exception { + void testCacheValueSetsEndpointNull() throws Exception { StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json"); RequestDetails details = Mockito.mock(RequestDetails.class); Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, new Endpoint().getIdElement(), @@ -56,7 +57,7 @@ public void testCacheValueSetsEndpointNull() throws Exception { } @Test - public void testCacheValueSetsAuthenticationErrorUsername() throws Exception { + void testCacheValueSetsAuthenticationErrorUsername() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json"); RequestDetails details = Mockito.mock(RequestDetails.class); @@ -67,7 +68,7 @@ public void testCacheValueSetsAuthenticationErrorUsername() throws Exception { } @Test - public void testCacheValueSetsAuthenticationErrorPassword() throws Exception { + void testCacheValueSetsAuthenticationErrorPassword() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); StringAndListParam stringAndListParam = getStringAndListParamFromValueSet("valueset/AcuteInpatient.json"); RequestDetails details = Mockito.mock(RequestDetails.class); @@ -78,11 +79,11 @@ public void testCacheValueSetsAuthenticationErrorPassword() throws Exception { } @Test - public void testCacheValueSetsValueSetDNE() throws Exception { + void testCacheValueSetsValueSetDNE() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); StringAndListParam stringAndListParam = new StringAndListParam(); stringAndListParam.setValuesAsQueryTokens(getFhirContext(), "valueset", - Arrays.asList(QualifiedParamList.singleton("dne"))); + List.of(QualifiedParamList.singleton("dne"))); RequestDetails details = Mockito.mock(RequestDetails.class); Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, endpoint.getIdElement(), stringAndListParam, null, null); @@ -90,11 +91,11 @@ public void testCacheValueSetsValueSetDNE() throws Exception { } @Test - public void testCacheValueSetsValueSetNull() throws Exception { + void testCacheValueSetsValueSetNull() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); StringAndListParam stringAndListParam = new StringAndListParam(); stringAndListParam.setValuesAsQueryTokens(getFhirContext(), "valueset", - Arrays.asList(QualifiedParamList.singleton(new ValueSet().getId()))); + List.of(QualifiedParamList.singleton(new ValueSet().getId()))); RequestDetails details = Mockito.mock(RequestDetails.class); Resource outcomeResource = cacheValueSetsProvider.cacheValuesets(details, endpoint.getIdElement(), stringAndListParam, null, null); @@ -103,7 +104,7 @@ public void testCacheValueSetsValueSetNull() throws Exception { } @Test - public void testCacheValueSetsNoCompose() throws Exception { + void testCacheValueSetsNoCompose() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); RequestDetails details = Mockito.mock(RequestDetails.class); ValueSet vs = uploadValueSet("valueset/valueset-benzodiazepine-medications.json"); @@ -125,7 +126,7 @@ public void testCacheValueSetsNoCompose() throws Exception { // Get help with this.... // @Test - // public void testCacheValueSetsExpandAndAddConcepts() throws Exception { + // void testCacheValueSetsExpandAndAddConcepts() throws Exception { // Endpoint endpoint = uploadLocalServerEndpoint(); // RequestDetails details = Mockito.mock(RequestDetails.class); // ValueSet vs = @@ -156,7 +157,7 @@ public void testCacheValueSetsNoCompose() throws Exception { // } @Test - public void testCacheValueSetsAlreadyExpanded() throws Exception { + void testCacheValueSetsAlreadyExpanded() throws Exception { Endpoint endpoint = uploadLocalServerEndpoint(); RequestDetails details = Mockito.mock(RequestDetails.class); ValueSet vs = uploadValueSet("valueset/valueset-benzodiazepine-medications.json"); @@ -176,10 +177,10 @@ private StringAndListParam getStringAndListParamFromValueSet(String location) th return getStringAndListParamFromValueSet(vs); } - private StringAndListParam getStringAndListParamFromValueSet(ValueSet vs) throws IOException { + private StringAndListParam getStringAndListParamFromValueSet(ValueSet vs) { StringAndListParam stringAndListParam = new StringAndListParam(); stringAndListParam.setValuesAsQueryTokens(getFhirContext(), "valueset", - Arrays.asList(QualifiedParamList.singleton(vs.getIdElement().getIdPart()))); + List.of(QualifiedParamList.singleton(vs.getIdElement().getIdPart()))); return stringAndListParam; } @@ -194,7 +195,7 @@ private void validateOutcome(Resource outcomeResource, String detailMessage) { private ValueSet uploadValueSet(String location) throws IOException { BufferedReader reader = new BufferedReader( - new InputStreamReader(CacheValueSetsProvider.class.getResourceAsStream(location))); + new InputStreamReader(Objects.requireNonNull(CacheValueSetsProvider.class.getResourceAsStream(location)))); String resourceString = reader.lines().collect(Collectors.joining(System.lineSeparator())); reader.close(); return (ValueSet) loadResource("json", resourceString); @@ -202,7 +203,7 @@ private ValueSet uploadValueSet(String location) throws IOException { private Endpoint uploadLocalServerEndpoint() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader( - CacheValueSetsProvider.class.getResourceAsStream("endpoint/LocalServerEndpoint.json"))); + Objects.requireNonNull(CacheValueSetsProvider.class.getResourceAsStream("endpoint/LocalServerEndpoint.json")))); String resourceString = reader.lines().collect(Collectors.joining(System.lineSeparator())); reader.close(); // Don't want to update during loading because need to setAddress first diff --git a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemProviderIT.java b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemProviderIT.java index 18e7ea61d..2405a1738 100644 --- a/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemProviderIT.java +++ b/plugin/dev-tools/src/test/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemProviderIT.java @@ -1,6 +1,7 @@ package org.opencds.cqf.ruler.devtools.r4; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.BufferedReader; @@ -8,7 +9,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; import java.util.stream.Collectors; import org.apache.commons.io.FilenameUtils; @@ -34,15 +36,14 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CodeSystemProviderIT.class, DevToolsConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) -public class CodeSystemProviderIT extends RestIntegrationTest { - private Logger log = LoggerFactory.getLogger(CodeSystemProviderIT.class); +class CodeSystemProviderIT extends RestIntegrationTest { + private final Logger log = LoggerFactory.getLogger(CodeSystemProviderIT.class); @Autowired CodeSystemUpdateProvider codeSystemUpdateProvider; - private String loincUrl = "http://loinc.org"; - private String snomedSctUrl = "http://snomed.info/sct"; - private String cptUrl = "http://www.ama-assn.org/go/cpt"; + private final String loincUrl = "http://loinc.org"; + private final String snomedSctUrl = "http://snomed.info/sct"; @AfterEach void tearDown() { @@ -53,7 +54,7 @@ void tearDown() { @Test @Order(1) - public void testCodeSystemUpdateValueSetDNE() throws IOException { + void testCodeSystemUpdateValueSetDNE() { ValueSet vs = (ValueSet) readResource( "org/opencds/cqf/ruler/devtools/r4/valueset/valueset-pain-treatment-plan.json"); OperationOutcome outcome = codeSystemUpdateProvider.updateCodeSystems(vs.getIdElement()); @@ -65,7 +66,7 @@ public void testCodeSystemUpdateValueSetDNE() throws IOException { @Test @Order(2) - public void testCodeSystemUpdateValueSetIdNull() { + void testCodeSystemUpdateValueSetIdNull() { OperationOutcome outcome = codeSystemUpdateProvider.updateCodeSystems(new ValueSet().getIdElement()); assertEquals(1, outcome.getIssue().size()); OperationOutcomeIssueComponent issue = outcome.getIssue().get(0); @@ -75,7 +76,7 @@ public void testCodeSystemUpdateValueSetIdNull() { @Test @Order(3) - public void testR4RxNormCodeSystemUpdateById() throws IOException { + void testR4RxNormCodeSystemUpdateById() { log.info("Beginning Test R4 LOINC CodeSystemUpdate"); ValueSet vs = (ValueSet) loadResource( "org/opencds/cqf/ruler/devtools/r4/valueset/valueset-pain-treatment-plan.json"); @@ -94,17 +95,17 @@ public void testR4RxNormCodeSystemUpdateById() throws IOException { @Test @Order(4) - public void testR4ICD10PerformCodeSystemUpdateByList() throws IOException { + void testR4ICD10PerformCodeSystemUpdateByList() throws IOException { log.info("Beginning Test R4 SNOMED CodeSystemUpdate"); BufferedReader reader = new BufferedReader(new InputStreamReader( - CodeSystemProviderIT.class.getResourceAsStream("valueset" + "/" + "valueset-pdmp-review-procedure.json"))); + Objects.requireNonNull(CodeSystemProviderIT.class.getResourceAsStream("valueset" + "/" + "valueset-pdmp-review-procedure.json")))); String resourceString = reader.lines().collect(Collectors.joining(System.lineSeparator())); reader.close(); ValueSet vs = (ValueSet) loadResource("json", resourceString); assertEquals(0, performCodeSystemSearchByUrl(snomedSctUrl).size()); - codeSystemUpdateProvider.performCodeSystemUpdate(Arrays.asList(vs)); + codeSystemUpdateProvider.performCodeSystemUpdate(Collections.singletonList(vs)); OperationOutcome outcome = codeSystemUpdateProvider.updateCodeSystems(vs.getIdElement()); for (OperationOutcomeIssueComponent issue : outcome.getIssue()) { assertEquals(OperationOutcome.IssueSeverity.INFORMATION, issue.getSeverity()); @@ -118,12 +119,15 @@ public void testR4ICD10PerformCodeSystemUpdateByList() throws IOException { @Test @Order(5) - public void testR4UpdateCodeSystems() throws IOException { + void testR4UpdateCodeSystems() throws IOException { log.info("Beginning Test R4 Update Code Systems"); + String cptUrl = "http://www.ama-assn.org/go/cpt"; assertEquals(0, performCodeSystemSearchByUrl(cptUrl).size()); - File[] valuesets = new File(CodeSystemProviderIT.class.getResource("valueset").getPath()).listFiles(); + File[] valuesets = new File(Objects.requireNonNull( + CodeSystemProviderIT.class.getResource("valueset")).getPath()).listFiles(); + assertNotNull(valuesets); for (File file : valuesets) { if (file.isFile() && FilenameUtils.getExtension(file.getPath()).equals("json")) { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); diff --git a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/ReportProvider.java b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/ReportProvider.java index 692e7bb42..55938184c 100644 --- a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/ReportProvider.java +++ b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/ReportProvider.java @@ -31,8 +31,8 @@ import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.ReferenceParam; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; public class ReportProvider extends DaoRegistryOperationProvider implements ParameterUser, ResourceCreator, MeasureReportUser { @@ -53,7 +53,6 @@ public class ReportProvider extends DaoRegistryOperationProvider * Resources */ @Description(shortDefinition = "$report", value = "Implements the $report operation found in the Da Vinci Risk Adjustment IG.") - @Operation(name = "$report", idempotent = true, type = MeasureReport.class) public Parameters report( RequestDetails requestDetails, @@ -70,7 +69,7 @@ public Parameters report( Operations.validatePattern("subject", subject, Operations.PATIENT_OR_GROUP_REFERENCE); Operations.validatePeriod(requestDetails, "periodStart", "periodEnd"); } catch (Exception e) { - return newParameters(newPart("Invalid parameters", + return parameters(part("Invalid parameters", generateIssue("error", e.getMessage()))); } } @@ -132,13 +131,13 @@ private Parameters.ParametersParameterComponent patientReport(Patient thePatient patientReportBundle.setTimestamp(new Date()); patientReportBundle.setId(patientId + "-report"); patientReportBundle.setIdentifier( - new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + UUID.randomUUID().toString())); + new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + UUID.randomUUID())); - bundleEntries.entrySet().forEach(resource -> patientReportBundle.addEntry( + bundleEntries.forEach((key, value) -> patientReportBundle.addEntry( new Bundle.BundleEntryComponent() - .setResource((Resource) resource.getValue()) - .setFullUrl(Operations.getFullUrl(serverBase, resource.getValue().fhirType(), - resource.getValue().getIdElement().getIdPart())))); + .setResource((Resource) value) + .setFullUrl(Operations.getFullUrl(serverBase, value.fhirType(), + value.getIdElement().getIdPart())))); Parameters.ParametersParameterComponent patientParameter = new Parameters.ParametersParameterComponent(); patientParameter.setResource(patientReportBundle); diff --git a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/ResolveProvider.java b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/ResolveProvider.java index cdfa0c5ef..01ea35b83 100644 --- a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/ResolveProvider.java +++ b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/ResolveProvider.java @@ -33,8 +33,8 @@ import java.util.Map; import java.util.stream.Collectors; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; public class ResolveProvider extends DaoRegistryOperationProvider implements MeasureReportUser { @@ -61,8 +61,7 @@ public Parameters resolve( Operations.validatePattern("subject", subject, Operations.PATIENT_OR_GROUP_REFERENCE); Operations.validateAtLeastOne(requestDetails, "measureId", "measureIdentifier", "measureUrl"); } catch (Exception e) { - return newParameters(newPart("Invalid parameters", - generateIssue("error", e.getMessage()))); + return parameters(part("Invalid parameters", generateIssue("error", e.getMessage()))); } } @@ -85,7 +84,7 @@ public Parameters resolve( Parameters result = new Parameters(); for (Bundle raBundle : raBundles) { - result.addParameter(newPart("return", raBundle)); + result.addParameter(part("return", raBundle)); } return result; diff --git a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentProvider.java b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentProvider.java index 2c810a09d..b98555c98 100644 --- a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentProvider.java +++ b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentProvider.java @@ -1,8 +1,5 @@ package org.opencds.cqf.ruler.ra.r4; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; - import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -33,6 +30,9 @@ import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; + @Configurable public class RiskAdjustmentProvider extends DaoRegistryOperationProvider implements MeasureReportUser { @@ -63,8 +63,7 @@ public Parameters evaluateRiskConditionCategory( Operations.validateCardinality(requestDetails, "periodEnd", 1); Operations.validateCardinality(requestDetails, "subject", 1); } catch (Exception e) { - return newParameters(newPart("Invalid parameters", - generateIssue(ERROR, e.getMessage()))); + return parameters(part("Invalid parameters", generateIssue(ERROR, e.getMessage()))); } } diff --git a/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/ReportProviderIT.java b/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/ReportProviderIT.java index c4311b1da..e4c03235a 100644 --- a/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/ReportProviderIT.java +++ b/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/ReportProviderIT.java @@ -4,7 +4,6 @@ import org.hl7.fhir.r4.model.Group; import org.hl7.fhir.r4.model.MeasureReport; import org.hl7.fhir.r4.model.Parameters; -import org.hl7.fhir.r4.model.StringType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.opencds.cqf.ruler.ra.RAConfig; @@ -21,8 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { ReportProviderIT.class, RAConfig.class }, @@ -39,10 +38,10 @@ public void beforeEach() { @Test void testMissingPeriodStartParam() { - Parameters params = newParameters( - newPart("periodEnd", new StringType("2021-12-31")), - newPart("subject", new StringType("Patient/testReport01")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "Patient/testReport01"), + stringPart("measureId", "Measure-RAModelExample01")); Parameters result = getClient().operation().onType(MeasureReport.class).named("$report") .withParameters(params).useHttpGet().returnResourceType(Parameters.class).execute(); @@ -52,10 +51,10 @@ void testMissingPeriodStartParam() { @Test void testMissingPeriodEndParam() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("subject", new StringType("Patient/testReport01")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("subject", "Patient/testReport01"), + stringPart("measureId", "Measure-RAModelExample01")); Parameters result = getClient().operation().onType(MeasureReport.class).named("$report") .withParameters(params).useHttpGet().returnResourceType(Parameters.class).execute(); @@ -65,10 +64,10 @@ void testMissingPeriodEndParam() { @Test void testMissingSubjectParam() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("periodEnd", new StringType("2021-12-31")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("measureId", "Measure-RAModelExample01")); Parameters result = getClient().operation().onType(MeasureReport.class).named("$report") .withParameters(params).useHttpGet().returnResourceType(Parameters.class).execute(); @@ -78,11 +77,11 @@ void testMissingSubjectParam() { @Test void testStartPeriodBeforeEndPeriod() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("periodEnd", new StringType("2020-12-31")), - newPart("subject", new StringType("Patient/testReport01")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2020-12-31"), + stringPart("subject", "Patient/testReport01"), + stringPart("measureId", "Measure-RAModelExample01")); Parameters result = getClient().operation().onType(MeasureReport.class).named("$report") .withParameters(params).useHttpGet().returnResourceType(Parameters.class).execute(); @@ -93,11 +92,11 @@ void testStartPeriodBeforeEndPeriod() { // TODO: add the count of patients returned @Test void testSubjectPatient() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("periodEnd", new StringType("2021-12-31")), - newPart("subject", new StringType("Patient/ra-patient01")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "Patient/ra-patient01"), + stringPart("measureId", "Measure-RAModelExample01")); loadResource("Patient-ra-patient01.json"); @@ -110,11 +109,11 @@ void testSubjectPatient() { // TODO: add the count of patients returned @Test void testSubjectGroup() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("periodEnd", new StringType("2021-12-31")), - newPart("subject", new StringType("Group/ra-group01")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "Group/ra-group01"), + stringPart("measureId", "Measure-RAModelExample01")); loadResource("Patient-ra-patient01.json"); loadResource("Group-ra-group01.json"); @@ -127,11 +126,11 @@ void testSubjectGroup() { @Test void testSubjectIsNotPatientOrGroup() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("periodEnd", new StringType("2021-12-31")), - newPart("subject", new StringType("ra-patient01")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "ra-patient01"), + stringPart("measureId", "Measure-RAModelExample01")); Parameters result = getClient().operation().onType(MeasureReport.class).named("$report") .withParameters(params).useHttpGet().returnResourceType(Parameters.class).execute(); @@ -141,11 +140,11 @@ void testSubjectIsNotPatientOrGroup() { @Test void testPatientSubjectNotFound() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("periodEnd", new StringType("2021-12-31")), - newPart("subject", new StringType("Patient/bad-patient")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "Patient/bad-patient"), + stringPart("measureId", "Measure-RAModelExample01")); assertThrows(ResourceNotFoundException.class, () -> getClient().operation() .onType(MeasureReport.class).named("$report").withParameters(params) @@ -154,11 +153,11 @@ void testPatientSubjectNotFound() { @Test void testGroupSubjectNotFound() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("periodEnd", new StringType("2021-12-31")), - newPart("subject", new StringType("Group/bad-group")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "Group/bad-group"), + stringPart("measureId", "Measure-RAModelExample01")); assertThrows(ResourceNotFoundException.class, () -> getClient().operation() .onType(MeasureReport.class).named("$report").withParameters(params) @@ -169,11 +168,11 @@ void testGroupSubjectNotFound() { // enforce_referential_integrity_on_write: false @Test void testSubjectPatientNotFoundInGroup() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("periodEnd", new StringType("2021-12-31")), - newPart("subject", new StringType("Group/ra-group00")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "Group/ra-group00"), + stringPart("measureId", "Measure-RAModelExample01")); loadResource("Group-ra-group00.json"); Group group = getClient().read().resource(Group.class).withId("ra-group00").execute(); @@ -188,11 +187,11 @@ void testSubjectPatientNotFoundInGroup() { // TODO: add the count of patients returned @Test void testSubjectMultiplePatientGroup() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("periodEnd", new StringType("2021-12-31")), - newPart("subject", new StringType("Group/ra-group02")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "Group/ra-group02"), + stringPart("measureId", "Measure-RAModelExample01")); loadResource("Patient-ra-patient02.json"); loadResource("Patient-ra-patient03.json"); @@ -206,11 +205,11 @@ void testSubjectMultiplePatientGroup() { @Test void testSingleSubjectSingleReport() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("periodEnd", new StringType("2021-12-31")), - newPart("subject", new StringType("Patient/ra-patient01")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "Patient/ra-patient01"), + stringPart("measureId", "Measure-RAModelExample01")); loadResource("Patient-ra-patient01.json"); loadResource("Condition-ra-condition02pat01.json"); @@ -248,11 +247,11 @@ void testSingleSubjectSingleReport() { @Test void testReportDoesNotIncludeNonEvaluatedResources() { - Parameters params = newParameters( - newPart("periodStart", new StringType("2021-01-01")), - newPart("periodEnd", new StringType("2021-12-31")), - newPart("subject", new StringType("Patient/ra-patient01")), - newPart("measureId", new StringType("Measure-RAModelExample01"))); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "Patient/ra-patient01"), + stringPart("measureId", "Measure-RAModelExample01")); loadResource("Patient-ra-patient01.json"); loadResource("Condition-ra-condition02pat01.json"); diff --git a/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/ResolveProviderIT.java b/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/ResolveProviderIT.java index 2c1576bb3..328f6e4a2 100644 --- a/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/ResolveProviderIT.java +++ b/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/ResolveProviderIT.java @@ -17,8 +17,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { ResolveProviderIT.class, RAConfig.class }, @@ -36,11 +36,11 @@ public void beforeEach() { @Test void testResolveProvider() { - Parameters params = newParameters( - newPart("periodStart", "2021-01-01"), - newPart("periodEnd", "2021-12-31"), - newPart("subject", "Patient/ra-patient02"), - newPart("measureId", "Measure-RAModelExample01")); + Parameters params = parameters( + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "Patient/ra-patient02"), + stringPart("measureId", "Measure-RAModelExample01")); loadTransaction("resolve-test-bundle.json"); diff --git a/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentProviderIT.java b/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentProviderIT.java index 15cb44e58..1755ae77b 100644 --- a/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentProviderIT.java +++ b/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentProviderIT.java @@ -3,8 +3,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newParameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.newPart; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; import java.util.HashSet; import java.util.List; @@ -83,11 +83,11 @@ void riskAssessmentHistoricNetNew() { } private Parameters getRequestParameters(String subject) { - return newParameters( - newPart("periodStart", "2022-01-01"), - newPart("periodEnd", "2022-12-31"), - newPart("subject", subject), - newPart("type", "report")); + return parameters( + stringPart("periodStart", "2022-01-01"), + stringPart("periodEnd", "2022-12-31"), + stringPart("subject", subject), + stringPart("type", "report")); } private Parameters callOperation(Parameters requestParameters) { diff --git a/plugin/sdc/src/test/java/org/opencds/cqf/ruler/sdc/r4/ExtractProviderIT.java b/plugin/sdc/src/test/java/org/opencds/cqf/ruler/sdc/r4/ExtractProviderIT.java index 8d4eb2263..259e39642 100644 --- a/plugin/sdc/src/test/java/org/opencds/cqf/ruler/sdc/r4/ExtractProviderIT.java +++ b/plugin/sdc/src/test/java/org/opencds/cqf/ruler/sdc/r4/ExtractProviderIT.java @@ -1,11 +1,10 @@ package org.opencds.cqf.ruler.sdc.r4; +import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.io.IOException; -import java.net.URISyntaxException; +import static org.opencds.cqf.ruler.utility.r4.Parameters.part; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Parameters; @@ -25,18 +24,18 @@ @ActiveProfiles("test") @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { Application.class, SDCConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) -public class ExtractProviderIT extends RestIntegrationTest { +class ExtractProviderIT extends RestIntegrationTest { @Autowired private SDCProperties mySdcProperties; @BeforeEach - public void beforeEach() { + void beforeEach() { String ourServerBase = "http://localhost:" + getPort() + "/fhir/"; mySdcProperties.getExtract().setEndpoint(ourServerBase); } @Test - public void testExtract() throws IOException, URISyntaxException { + void testExtract() { String examplePatient = "example_patient.json"; String exampleQuestionnaire = "questionnaire_1559.json"; String exampleQR = "questionnaire_response_1558.json"; @@ -45,8 +44,9 @@ public void testExtract() throws IOException, URISyntaxException { loadResource(exampleQuestionnaire); QuestionnaireResponse questionnaireResponse = (QuestionnaireResponse) loadResource(exampleQR); - Parameters params = new Parameters(); - params.addParameter().setName("questionnaireResponse").setResource(questionnaireResponse); + Parameters params = parameters( + part("questionnaireResponse", questionnaireResponse) + ); Bundle actual = getClient() .operation() @@ -68,7 +68,7 @@ public void testExtract() throws IOException, URISyntaxException { } @Test - public void testExtract_noQuestionnaireReference_throwsException() throws IOException { + void testExtract_noQuestionnaireReference_throwsException() { QuestionnaireResponse test = (QuestionnaireResponse) getFhirContext().newJsonParser() .parseResource(stringFromResource("mypain-questionnaire-response-no-url.json")); diff --git a/plugin/security/src/test/java/org/opencds/cqf/ruler/security/dstu3/OAuthProviderIT.java b/plugin/security/src/test/java/org/opencds/cqf/ruler/security/dstu3/OAuthProviderIT.java index 1da12c858..74d40ac1a 100644 --- a/plugin/security/src/test/java/org/opencds/cqf/ruler/security/dstu3/OAuthProviderIT.java +++ b/plugin/security/src/test/java/org/opencds/cqf/ruler/security/dstu3/OAuthProviderIT.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.hl7.fhir.dstu3.model.CapabilityStatement; import org.junit.jupiter.api.Test; @@ -10,18 +11,19 @@ import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { OAuthProviderIT.class, - SecurityConfig.class }, properties = { - "hapi.fhir.fhir_version=dstu3", "hapi.fhir.security.oauth.enabled=true" -}) -public class OAuthProviderIT extends RestIntegrationTest { +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = { OAuthProviderIT.class, SecurityConfig.class }, + properties = { "hapi.fhir.fhir_version=dstu3", "hapi.fhir.security.oauth.enabled=true" }) +class OAuthProviderIT extends RestIntegrationTest { @Test - public void testOAuthConfig() { + void testOAuthConfig() { CapabilityStatement cs = getClient().capabilities().ofType(CapabilityStatement.class).execute(); assertNotNull(cs); - assertEquals(true, cs.getRestFirstRep().getSecurity().getCors()); - assertEquals("http://hl7.org/fhir/restful-security-service", cs.getRestFirstRep().getSecurity().getService().stream().findAny().get().getCodingFirstRep().getSystem()); + assertTrue(cs.getRestFirstRep().getSecurity().getCors()); + assertTrue(cs.getRestFirstRep().getSecurity().getService().stream().findAny().isPresent()); + assertEquals("http://hl7.org/fhir/restful-security-service", + cs.getRestFirstRep().getSecurity().getService().stream().findAny().get().getCodingFirstRep().getSystem()); } } diff --git a/plugin/security/src/test/java/org/opencds/cqf/ruler/security/r4/OAuthProviderIT.java b/plugin/security/src/test/java/org/opencds/cqf/ruler/security/r4/OAuthProviderIT.java index 444b519c7..4a64724ee 100644 --- a/plugin/security/src/test/java/org/opencds/cqf/ruler/security/r4/OAuthProviderIT.java +++ b/plugin/security/src/test/java/org/opencds/cqf/ruler/security/r4/OAuthProviderIT.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.hl7.fhir.r4.model.CapabilityStatement; import org.junit.jupiter.api.Test; @@ -13,13 +14,14 @@ SecurityConfig.class }, properties = { "hapi.fhir.fhir_version=r4", "hapi.fhir.security.oauth.enabled=true" }) -public class OAuthProviderIT extends RestIntegrationTest { +class OAuthProviderIT extends RestIntegrationTest { @Test - public void testOAuthConfig() { + void testOAuthConfig() { CapabilityStatement cs = getClient().capabilities().ofType(CapabilityStatement.class).execute(); assertNotNull(cs); - assertEquals(true, cs.getRestFirstRep().getSecurity().getCors()); + assertTrue(cs.getRestFirstRep().getSecurity().getCors()); + assertTrue(cs.getRestFirstRep().getSecurity().getService().stream().findAny().isPresent()); assertEquals("http://hl7.org/fhir/restful-security-service", cs.getRestFirstRep().getSecurity().getService().stream().findAny().get().getCodingFirstRep().getSystem());