diff --git a/core/pom.xml b/core/pom.xml index a5a168f2c..deda26882 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.opencds.cqf.ruler @@ -16,6 +17,11 @@ 0.9.0-SNAPSHOT + + org.opencds.cqf.cql + evaluator.fhir + + javax javaee-api diff --git a/core/src/main/java/org/opencds/cqf/ruler/behavior/DaoRegistryUser.java b/core/src/main/java/org/opencds/cqf/ruler/behavior/DaoRegistryUser.java index f45418632..171cd1fb2 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/behavior/DaoRegistryUser.java +++ b/core/src/main/java/org/opencds/cqf/ruler/behavior/DaoRegistryUser.java @@ -37,7 +37,7 @@ public default FhirContext getFhirContext() { * Get the class of the given Resource. FHIR version aware. For example, if the * server is running in DSTU3 mode * this will return the DSTU3 Library class when invoked with "Library". - * + * * @param the type of resource to return * @param theResourceName the name of the Resource to get the class for * @return the class of the resource @@ -52,7 +52,7 @@ public default Class getClass(String theResourceNam * the Resource is not present *

* NOTE: Use {@code search} if a null result is preferred over an error. - * + * * @param the Resource type to read * @param theId the id to read * @return the FHIR Resource @@ -69,7 +69,7 @@ default T read(IIdType theId) { * the Resource is not present *

* NOTE: Use {@code search} if a null result is preferred over an error. - * + * * @param the Resource type to read * @param theId the id to read * @param requestDetails multi-tenancy information @@ -85,7 +85,7 @@ default T read(IIdType theId, RequestDetails requestDe /** * Creates the given Resource on the local server - * + * * @param The Resource type * @param theResource the resource to create * @return the outcome of the creation @@ -98,7 +98,7 @@ default DaoMethodOutcome create(T theResource) { /** * Creates the given Resource on the local server - * + * * @param The Resource type * @param theResource the resource to create * @param requestDetails multi-tenancy information @@ -114,7 +114,7 @@ default DaoMethodOutcome create(T theResource, Request /** * Updates the given Resource on the local server - * + * * @param The Resource type * @param theResource the resource to update * @return the outcome of the creation @@ -127,7 +127,7 @@ default DaoMethodOutcome update(T theResource) { /** * Updates the given Resource on the local server - * + * * @param The Resource type * @param theResource the resource to update * @param requestDetails multi-tenancy information @@ -143,7 +143,7 @@ default DaoMethodOutcome update(T theResource, Request /** * Deletes the Resource with the given Id from the local server - * + * * @param theIdType the Id of the Resource to delete. * @return the outcome of the deletion */ @@ -155,7 +155,7 @@ default DaoMethodOutcome delete(IIdType theIdType) { /** * Deletes the Resource with the given Id from the local server - * + * * @param theIdType the Id of the Resource to delete. * @param requestDetails multi-tenancy information * @return the outcome of the deletion @@ -170,7 +170,7 @@ default DaoMethodOutcome delete(IIdType theIdType, RequestDetails requestDetails * NOTE: This is untested as of the time I'm writing this so it may need to be * reworked. * Executes a given transaction Bundle on the local server - * + * * @param the type of Bundle * @param theTransaction the transaction to process * @return the transaction outcome @@ -185,7 +185,7 @@ default T transaction(T theTransaction) { * NOTE: This is untested as of the time I'm writing this so it may need to be * reworked. * Executes a given transaction Bundle on the local server - * + * * @param the type of Bundle * @param theTransaction the transaction to process * @param theRequestDetails multi-tenancy information @@ -201,7 +201,7 @@ default T transaction(T theTransaction, RequestDetails t /** * Searches for a Resource on the local server using the Search Parameters * specified - * + * * @param the type of Resource to return * @param theResourceClass the class of the Resource * @param theSearchMap the Search Parameters @@ -218,7 +218,7 @@ default TypedBundleProvider search(Class theReso /** * Searches for a Resource on the local server using the Search Parameters * specified - * + * * @param the type of Resource to return * @param theResourceClass the class of the Resource * @param theSearchMap the Search Parameters diff --git a/core/src/main/java/org/opencds/cqf/ruler/behavior/IdCreator.java b/core/src/main/java/org/opencds/cqf/ruler/behavior/IdCreator.java index 47547e6f3..dd4f424cb 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/behavior/IdCreator.java +++ b/core/src/main/java/org/opencds/cqf/ruler/behavior/IdCreator.java @@ -3,8 +3,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import org.hl7.fhir.instance.model.api.IIdType; -import org.opencds.cqf.ruler.utility.Ids; - +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; public interface IdCreator extends FhirContextUser { @@ -17,7 +16,7 @@ default T newId(String theResourceName, String theResourceId default T newId(String theResourceId) { checkNotNull(theResourceId); - + return Ids.newId(getFhirContext(), theResourceId); } } diff --git a/core/src/main/java/org/opencds/cqf/ruler/behavior/ResourceCreator.java b/core/src/main/java/org/opencds/cqf/ruler/behavior/ResourceCreator.java index fa681469c..c9e2a40a5 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/behavior/ResourceCreator.java +++ b/core/src/main/java/org/opencds/cqf/ruler/behavior/ResourceCreator.java @@ -5,7 +5,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.opencds.cqf.ruler.utility.Ids; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; public interface ResourceCreator extends FhirContextUser { @SuppressWarnings("unchecked") @@ -23,7 +23,7 @@ default T newResource(Class theResourceClass, Strin checkNotNull(theIdPart); T newResource = newResource(theResourceClass); - newResource.setId((IIdType)Ids.newId(getFhirContext(), newResource.fhirType(), theIdPart)); + newResource.setId((IIdType) Ids.newId(getFhirContext(), newResource.fhirType(), theIdPart)); return newResource; } @@ -32,13 +32,13 @@ default T newResource(Class theResourceClass, Strin default T newResource(Class theResourceClass) { checkNotNull(theResourceClass); - return (T)this.getFhirContext().getResourceDefinition(theResourceClass).newInstance(); + return (T) this.getFhirContext().getResourceDefinition(theResourceClass).newInstance(); } @SuppressWarnings("unchecked") default T newResource(String theResourceType) { checkNotNull(theResourceType); - return (T)this.getFhirContext().getResourceDefinition(theResourceType).newInstance(); + return (T) this.getFhirContext().getResourceDefinition(theResourceType).newInstance(); } } diff --git a/core/src/main/java/org/opencds/cqf/ruler/behavior/r4/MeasureReportUser.java b/core/src/main/java/org/opencds/cqf/ruler/behavior/r4/MeasureReportUser.java index 308f1db66..17028e051 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/behavior/r4/MeasureReportUser.java +++ b/core/src/main/java/org/opencds/cqf/ruler/behavior/r4/MeasureReportUser.java @@ -23,9 +23,9 @@ import org.hl7.fhir.r4.model.Resource; import org.hl7.fhir.r4.model.SearchParameter; import org.hl7.fhir.r4.model.SearchParameter.XPathUsageType; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; import org.opencds.cqf.ruler.behavior.DaoRegistryUser; import org.opencds.cqf.ruler.behavior.IdCreator; -import org.opencds.cqf.ruler.utility.Ids; import org.opencds.cqf.ruler.utility.Searches; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core/src/main/java/org/opencds/cqf/ruler/behavior/r4/ParameterUser.java b/core/src/main/java/org/opencds/cqf/ruler/behavior/r4/ParameterUser.java index 075fc1ea5..2ecb172cf 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/behavior/r4/ParameterUser.java +++ b/core/src/main/java/org/opencds/cqf/ruler/behavior/r4/ParameterUser.java @@ -40,7 +40,8 @@ default List getMeasures(List measureIds, List measureI if (hasMeasureIds) { measureList - .addAll(search(Measure.class, Searches.byIds(measureIds), theRequestDetails).getAllResourcesTyped()); + .addAll(search(Measure.class, Searches.byIds(measureIds), theRequestDetails) + .getAllResourcesTyped()); } // TODO: implement searching by measure identifiers diff --git a/core/src/main/java/org/opencds/cqf/ruler/builder/BackboneElementBuilder.java b/core/src/main/java/org/opencds/cqf/ruler/builder/BackboneElementBuilder.java index 0f4bf977c..60b3c17f1 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/builder/BackboneElementBuilder.java +++ b/core/src/main/java/org/opencds/cqf/ruler/builder/BackboneElementBuilder.java @@ -10,10 +10,10 @@ import org.apache.commons.lang3.tuple.Pair; import org.hl7.fhir.instance.model.api.IBaseBackboneElement; import org.hl7.fhir.instance.model.api.IBaseExtension; -import org.opencds.cqf.ruler.utility.FhirVersions; -import org.opencds.cqf.ruler.utility.Resources; +import org.opencds.cqf.cql.evaluator.fhir.util.FhirVersions; +import org.opencds.cqf.cql.evaluator.fhir.util.Resources; -public abstract class BackboneElementBuilder { +public abstract class BackboneElementBuilder, T extends IBaseBackboneElement> { private final Class myResourceClass; diff --git a/core/src/main/java/org/opencds/cqf/ruler/builder/ResourceBuilder.java b/core/src/main/java/org/opencds/cqf/ruler/builder/ResourceBuilder.java index 37fbc0fb5..fe3cf0382 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/builder/ResourceBuilder.java +++ b/core/src/main/java/org/opencds/cqf/ruler/builder/ResourceBuilder.java @@ -11,7 +11,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.elasticsearch.common.Strings; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.opencds.cqf.ruler.utility.Resources; +import org.opencds.cqf.cql.evaluator.fhir.util.Resources; public abstract class ResourceBuilder { diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/CanonicalParts.java b/core/src/main/java/org/opencds/cqf/ruler/utility/CanonicalParts.java deleted file mode 100644 index 48932c93b..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/CanonicalParts.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -public final class CanonicalParts { - private final String url; - private final String idPart; - private final String resourceType; - private final String version; - private final String fragment; - - CanonicalParts(String url, String idPart, String resourceType, String version, String fragment) { - this.url = url; - this.idPart = idPart; - this.resourceType = resourceType; - this.version = version; - this.fragment = fragment; - } - - public String url() { - return this.url; - } - - public String idPart() { - return this.idPart; - } - - public String resourceType() { - return this.resourceType; - } - - public String version() { - return this.version; - } - - public String fragment() { - return this.fragment; - } -} diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/Canonicals.java b/core/src/main/java/org/opencds/cqf/ruler/utility/Canonicals.java deleted file mode 100644 index 2f8331134..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/Canonicals.java +++ /dev/null @@ -1,230 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.ArrayList; -import java.util.List; - -import org.hl7.fhir.instance.model.api.IPrimitiveType; - -public class Canonicals { - - private Canonicals() { - } - - /** - * Gets the Resource type component of a canonical url - * - * @param A CanonicalType - * @param theCanonicalType the canonical url to parse - * @return the Resource type, or null if one can not be parsed - */ - public static > String getResourceType(CanonicalType theCanonicalType) { - checkNotNull(theCanonicalType); - checkArgument(theCanonicalType.hasValue()); - - return getResourceType(theCanonicalType.getValue()); - } - - /** - * Gets the ResourceType component of a canonical url - * - * @param theCanonical the canonical url to parse - * @return the ResourceType, or null if one can not be parsed - */ - - public static String getResourceType(String theCanonical) { - checkNotNull(theCanonical); - - if (!theCanonical.contains("/")) { - return null; - } - - theCanonical = theCanonical.replace(theCanonical.substring(theCanonical.lastIndexOf("/")), ""); - return theCanonical.contains("/") ? theCanonical.substring(theCanonical.lastIndexOf("/") + 1) : theCanonical; - } - - /** - * Gets the ID component of a canonical url. Does not include resource name if - * present in the url. - * - * @param A CanonicalType - * @param theCanonicalType the canonical url to parse - * @return the Id, or null if one can not be parsed - */ - public static > String getIdPart(CanonicalType theCanonicalType) { - checkNotNull(theCanonicalType); - checkArgument(theCanonicalType.hasValue()); - - return getIdPart(theCanonicalType.getValue()); - } - - /** - * Gets the ID component of a canonical url. Does not include resource name if - * present in the url. - * - * @param theCanonical the canonical url to parse - * @return the Id, or null if one can not be parsed - */ - public static String getIdPart(String theCanonical) { - checkNotNull(theCanonical); - - if (!theCanonical.contains("/")) { - return null; - } - - int lastIndex = calculateLastIndex(theCanonical); - - return theCanonical.substring(theCanonical.lastIndexOf("/") + 1, lastIndex); - } - - /** - * Gets the Version component of a canonical url - * - * @param A CanonicalType - * @param theCanonicalType the canonical url to parse - * @return the Version, or null if one can not be parsed - */ - public static > String getVersion(CanonicalType theCanonicalType) { - checkNotNull(theCanonicalType); - checkArgument(theCanonicalType.hasValue()); - - return getVersion(theCanonicalType.getValue()); - } - - /** - * Gets the Version component of a canonical url - * - * @param theCanonical the canonical url to parse - * @return the Version, or null if one can not be parsed - */ - public static String getVersion(String theCanonical) { - checkNotNull(theCanonical); - - if (!theCanonical.contains("|")) { - return null; - } - - int lastIndex = theCanonical.lastIndexOf("#"); - if (lastIndex == -1) { - lastIndex = theCanonical.length(); - } - - return theCanonical.substring(theCanonical.lastIndexOf("|") + 1, lastIndex); - } - - /** - * Gets the Url component of a canonical url. Includes the base url, the - * resource type, and the id if present. - * - * @param A CanonicalType - * @param theCanonicalType the canonical url to parse - * @return the Url, or null if one can not be parsed - */ - public static > String getUrl(CanonicalType theCanonicalType) { - checkNotNull(theCanonicalType); - checkArgument(theCanonicalType.hasValue()); - - return getUrl(theCanonicalType.getValue()); - } - - /** - * Get the Url component of a canonical url. Includes the base url, the resource - * type, and the id if present. - * - * @param theCanonical the canonical url to parse - * @return the Url, or null if one can not be parsed - */ - public static String getUrl(String theCanonical) { - checkNotNull(theCanonical); - - if (!theCanonical.contains("/")) { - return null; - } - - int lastIndex = calculateLastIndex(theCanonical); - - return theCanonical.substring(0, lastIndex); - } - - /** - * Get the Url component for a set of canonical urls. Includes the base url, the - * resource type, and the id if present. - * - * @param theCanonicals the set of canonical urls to parse - * @return the set of Url and null (if one can not be parsed) values - */ - public static List getUrls(List theCanonicals) { - checkNotNull(theCanonicals); - - List result = new ArrayList<>(); - theCanonicals.forEach(canonical -> result.add(getUrl(canonical))); - - return result; - } - - /** - * Gets the Fragment component of a canonical url. - * - * @param A CanonicalType - * @param theCanonicalType the canonical url to parse - * @return the Fragment, or null if one can not be parsed - */ - public static > String getFragment(CanonicalType theCanonicalType) { - checkNotNull(theCanonicalType); - checkArgument(theCanonicalType.hasValue()); - - return getFragment(theCanonicalType.getValue()); - } - - /** - * Gets the Fragment component of a canonical url. - * - * @param theCanonical the canonical url to parse - * @return the Fragment, or null if one can not be parsed - */ - public static String getFragment(String theCanonical) { - checkNotNull(theCanonical); - - if (!theCanonical.contains("#")) { - return null; - } - - return theCanonical.substring(theCanonical.lastIndexOf("#") + 1); - } - - public static > CanonicalParts getParts( - CanonicalType theCanonicalType) { - checkNotNull(theCanonicalType); - checkArgument(theCanonicalType.hasValue()); - - return getParts(theCanonicalType.getValue()); - } - - public static CanonicalParts getParts(String theCanonical) { - checkNotNull(theCanonical); - - String url = getUrl(theCanonical); - String id = getIdPart(theCanonical); - String resourceType = getResourceType(theCanonical); - String version = getVersion(theCanonical); - String fragment = getFragment(theCanonical); - return new CanonicalParts(url, id, resourceType, version, fragment); - } - - private static int calculateLastIndex(String theCanonical) { - int lastIndexOfBar = theCanonical.lastIndexOf("|"); - int lastIndexOfHash = theCanonical.lastIndexOf("#"); - - int lastIndex = theCanonical.length(); - int mul = lastIndexOfBar * lastIndexOfHash; - if (mul > 1) { - lastIndex = Math.min(lastIndexOfBar, lastIndexOfHash); - } else if (mul < 0) { - lastIndex = Math.max(lastIndexOfBar, lastIndexOfHash); - } - return lastIndex; - } - -} diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/Clients.java b/core/src/main/java/org/opencds/cqf/ruler/utility/Clients.java deleted file mode 100644 index cdfec2a67..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/Clients.java +++ /dev/null @@ -1,290 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.context.FhirVersionEnum; -import ca.uhn.fhir.rest.client.api.IClientInterceptor; -import ca.uhn.fhir.rest.client.api.IGenericClient; -import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; -import ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor; -import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor; - -/** - * This class provides utility functions for creating IGenericClients and - * setting up authentication - */ -public abstract class Clients { - - private Clients() { - } - - /** - * Creates an IGenericClient for the given url. Defaults to NEVER - * ServerValidationMode - * - * @param theFhirVersionEnum the FHIR version to create a client for - * @param theUrl the server base url to connect to - * @return IGenericClient for the given url - */ - public static IGenericClient forUrl(FhirVersionEnum theFhirVersionEnum, String theUrl) { - checkNotNull(theFhirVersionEnum); - checkNotNull(theUrl); - - return forUrl(FhirContext.forCached(theFhirVersionEnum), theUrl); - } - - /** - * Creates an IGenericClient for the given url. Defaults to NEVER - * ServerValidationMode - * - * @param theFhirContext the FhirContext to use to create the client - * @param theUrl the server base url to connect to - * @return IGenericClient for the given url - */ - public static IGenericClient forUrl(FhirContext theFhirContext, String theUrl) { - checkNotNull(theFhirContext); - checkNotNull(theUrl); - - return forUrl(theFhirContext, theUrl, ServerValidationModeEnum.NEVER); - } - - /** - * Creates an IGenericClient for the given url. - * - * @param theFhirVersionEnum the FHIR version to create a client for - * @param theUrl the server base url to connect to - * @param theServerValidationModeEnum the ServerValidationMode to use - * @return IGenericClient for the given url, with the server validation mode set - */ - public static IGenericClient forUrl(FhirVersionEnum theFhirVersionEnum, String theUrl, - ServerValidationModeEnum theServerValidationModeEnum) { - checkNotNull(theFhirVersionEnum, "theFhirVersionEnum is required"); - checkNotNull(theUrl, "theUrl is required"); - checkNotNull(theServerValidationModeEnum, "theServerValidationModeEnum is required"); - - return forUrl(FhirContext.forCached(theFhirVersionEnum), theUrl, theServerValidationModeEnum); - } - - /** - * Creates an IGenericClient for the given url. - * - * @param theFhirContext the FhirContext to use to create the - * client - * @param theUrl the server base url to connect to - * @param theServerValidationModeEnum the ServerValidationMode to use - * @return IGenericClient for the given url, with the server validation mode set - */ - public static IGenericClient forUrl(FhirContext theFhirContext, String theUrl, - ServerValidationModeEnum theServerValidationModeEnum) { - checkNotNull(theFhirContext); - checkNotNull(theUrl); - checkNotNull(theServerValidationModeEnum, "theServerValidationModeEnum is required"); - - theFhirContext.getRestfulClientFactory().setServerValidationMode(theServerValidationModeEnum); - return theFhirContext.newRestfulGenericClient(theUrl); - } - - /** - * Creates an IGenericClient for the given Endpoint. - * - * @param theEndpoint the Endpoint to connect to - * @return IGenericClient for the given Endpoint, with appropriate header - * interceptors set up - */ - public static IGenericClient forEndpoint(org.hl7.fhir.dstu3.model.Endpoint theEndpoint) { - checkNotNull(theEndpoint); - - return forEndpoint(FhirContext.forDstu3Cached(), theEndpoint); - } - - /** - * Creates an IGenericClient for the given Endpoint. - * - * @param theFhirContext the FhirContext to use to create the client - * @param theEndpoint the Endpoint to connect to - * @return IGenericClient for the given Endpoint, with appropriate header - * interceptors set up - */ - public static IGenericClient forEndpoint(FhirContext theFhirContext, - org.hl7.fhir.dstu3.model.Endpoint theEndpoint) { - checkNotNull(theFhirContext); - checkNotNull(theEndpoint); - - IGenericClient client = forUrl(theFhirContext, theEndpoint.getAddress()); - if (theEndpoint.hasHeader()) { - List headerList = theEndpoint.getHeader().stream().map(headerString -> headerString.asStringValue()) - .collect(Collectors.toList()); - registerHeaders(client, headerList); - } - return client; - } - - /** - * Creates an IGenericClient for the given Endpoint. - * - * @param theEndpoint the Endpoint to connect to - * @return IGenericClient for the given Endpoint, with appropriate header - * interceptors set up - */ - public static IGenericClient forEndpoint(org.hl7.fhir.r4.model.Endpoint theEndpoint) { - checkNotNull(theEndpoint); - - return forEndpoint(FhirContext.forR4Cached(), theEndpoint); - } - - /** - * Creates an IGenericClient for the given Endpoint. - * - * @param theFhirContext the FhirContext to use to create the client - * @param theEndpoint the Endpoint to connect to - * @return IGenericClient for the given Endpoint, with appropriate header - * interceptors set up - */ - public static IGenericClient forEndpoint(FhirContext theFhirContext, org.hl7.fhir.r4.model.Endpoint theEndpoint) { - checkNotNull(theFhirContext); - checkNotNull(theEndpoint); - - IGenericClient client = forUrl(theFhirContext, theEndpoint.getAddress()); - if (theEndpoint.hasHeader()) { - List headerList = theEndpoint.getHeader().stream().map(headerString -> headerString.asStringValue()) - .collect(Collectors.toList()); - registerHeaders(client, headerList); - } - return client; - } - - /** - * Creates an IGenericClient for the given Endpoint. - * - * @param theEndpoint the Endpoint to connect to - * @return IGenericClient for the given Endpoint, with appropriate header - * interceptors set up - */ - public static IGenericClient forEndpoint(org.hl7.fhir.r5.model.Endpoint theEndpoint) { - checkNotNull(theEndpoint, "theEndpoint is required"); - - return forEndpoint(FhirContext.forR4Cached(), theEndpoint); - } - - /** - * Creates an IGenericClient for the given Endpoint. - * - * @param theFhirContext the FhirContext to use to create the client - * @param theEndpoint the Endpoint to connect to - * @return IGenericClient for the given Endpoint, with appropriate header - * interceptors set up - */ - public static IGenericClient forEndpoint(FhirContext theFhirContext, org.hl7.fhir.r5.model.Endpoint theEndpoint) { - checkNotNull(theFhirContext); - checkNotNull(theEndpoint); - - IGenericClient client = forUrl(theFhirContext, theEndpoint.getAddress()); - if (theEndpoint.hasHeader()) { - List headerList = theEndpoint.getHeader().stream().map(headerString -> headerString.asStringValue()) - .collect(Collectors.toList()); - registerHeaders(client, headerList); - } - return client; - } - - /** - * Registers HeaderInjectionInterceptors on a client. - * - * @param theClient the client to add headers to - * @param theHeaders an Array of Strings representing headers to add - */ - public static void registerHeaders(IGenericClient theClient, String... theHeaders) { - checkNotNull(theClient); - - registerHeaders(theClient, Arrays.asList(theHeaders)); - } - - /** - * Registers HeaderInjectionInterceptors on a client - * - * @param theClient the client to add headers to - * @param theHeaderList a List of Strings representing headers to add - */ - public static void registerHeaders(IGenericClient theClient, List theHeaderList) { - checkNotNull(theClient); - checkNotNull(theHeaderList); - - Map headerMap = setupHeaderMap(theHeaderList); - for (Map.Entry entry : headerMap.entrySet()) { - IClientInterceptor headInterceptor = new HeaderInjectionInterceptor(entry.getKey(), entry.getValue()); - theClient.registerInterceptor(headInterceptor); - } - } - - /** - * Registers BasicAuthInterceptors on a client. This is useful when you have a - * username and password. - * - * @param theClient the client to register basic auth on - * @param theUsername the username - * @param thePassword the password - */ - public static void registerBasicAuth(IGenericClient theClient, String theUsername, String thePassword) { - checkNotNull(theClient, "theClient is required"); - - if (theUsername != null) { - BasicAuthInterceptor authInterceptor = new BasicAuthInterceptor(theUsername, thePassword); - theClient.registerInterceptor(authInterceptor); - } - } - - /** - * Registers BearerAuthInterceptors on a client. This is useful when you have a - * bearer token. - * - * @param theClient the client to register BearerToken authentication on - * @param theToken the bearer token to register - */ - public static void registerBearerTokenAuth(IGenericClient theClient, String theToken) { - checkNotNull(theClient, "theClient is required"); - - if (theToken != null) { - BearerTokenAuthInterceptor authInterceptor = new BearerTokenAuthInterceptor(theToken); - theClient.registerInterceptor(authInterceptor); - } - } - - /** - * Parses a list of headers into their constituent parts. Used to prep the - * headers for registration with HeaderInjectionInterceptors - * - * @param theHeaderList a List of Strings representing headers to create - * @return key-value pairs of headers - */ - static Map setupHeaderMap(List theHeaderList) { - checkNotNull(theHeaderList, "theHeaderList is required"); - - Map headerMap = new HashMap(); - String leftAuth = null; - String rightAuth = null; - if (theHeaderList.size() < 1 || theHeaderList.isEmpty()) { - leftAuth = null; - rightAuth = null; - headerMap.put(leftAuth, rightAuth); - } else { - for (String header : theHeaderList) { - if (!header.contains(":")) { - throw new IllegalArgumentException("Endpoint header must contain \":\" ."); - } - String[] authSplit = header.split(":"); - leftAuth = authSplit[0]; - rightAuth = authSplit[1]; - headerMap.put(leftAuth, rightAuth); - } - - } - return headerMap; - } -} diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/FhirVersions.java b/core/src/main/java/org/opencds/cqf/ruler/utility/FhirVersions.java deleted file mode 100644 index 058cf6073..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/FhirVersions.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static com.google.common.base.Preconditions.checkNotNull; - -import org.hl7.fhir.instance.model.api.IBase; - -import ca.uhn.fhir.context.FhirVersionEnum; - - -public class FhirVersions { - - private FhirVersions() { - } - - /** - * Returns a FhirVersionEnum for a given BaseType - * - * @param an IBase type - * @param theBaseTypeClass the class of the resource to get the version for - * @return the FhirVersionEnum corresponding to the theBaseTypeClass - */ - public static FhirVersionEnum forClass( - final Class theBaseTypeClass) { - checkNotNull(theBaseTypeClass); - - String packageName = theBaseTypeClass.getPackage().getName(); - if (packageName.contains("r5")) { - return FhirVersionEnum.R5; - } else if (packageName.contains("r4")) { - return FhirVersionEnum.R4; - } else if (packageName.contains("dstu3")) { - return FhirVersionEnum.DSTU3; - } else if (packageName.contains("dstu2016may")) { - return FhirVersionEnum.DSTU2_1; - } else if (packageName.contains("org.hl7.fhir.dstu2")) { - return FhirVersionEnum.DSTU2_HL7ORG; - } else if (packageName.contains("ca.uhn.fhir.model.dstu2")) { - return FhirVersionEnum.DSTU2; - } else { - throw new IllegalArgumentException(String.format( - "Unable to determine FHIR version for IBaseResource type: %s", theBaseTypeClass.getName())); - } - } - -} diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/HeaderInjectionInterceptor.java b/core/src/main/java/org/opencds/cqf/ruler/utility/HeaderInjectionInterceptor.java deleted file mode 100644 index ecd55b515..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/HeaderInjectionInterceptor.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import ca.uhn.fhir.rest.client.api.IClientInterceptor; -import ca.uhn.fhir.rest.client.api.IHttpRequest; -import ca.uhn.fhir.rest.client.api.IHttpResponse; - -public class HeaderInjectionInterceptor implements IClientInterceptor { - - private Map myHeaders; - - /** - * Instantiates a new header injection interception. - * - * @param headerKey the header key - * @param headerValue the header value - */ - public HeaderInjectionInterceptor(String headerKey, String headerValue) { - super(); - this.myHeaders = new HashMap<>(); - this.myHeaders.put(headerKey, headerValue); - } - - /** - * Instantiates a new header injection interception. - * - * @param headers the headers - */ - public HeaderInjectionInterceptor(Map headers) { - super(); - this.myHeaders = headers; - } - - @Override - public void interceptRequest(IHttpRequest theRequest) { - - for (Map.Entry entry : this.myHeaders.entrySet()) { - theRequest.addHeader(entry.getKey(), entry.getValue()); - } - } - - @Override - public void interceptResponse(IHttpResponse theResponse) throws IOException { - // nothing - } -} diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/Ids.java b/core/src/main/java/org/opencds/cqf/ruler/utility/Ids.java deleted file mode 100644 index cea561adc..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/Ids.java +++ /dev/null @@ -1,207 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import org.hl7.fhir.instance.model.api.IBase; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.instance.model.api.IIdType; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.context.FhirVersionEnum; - -public class Ids { - - private Ids() { - } - - /** - * Creates the appropriate IIdType for a given ResourceTypeClass - * - * @param an IBase type - * @param an IIdType type - * @param theResourceTypeClass the type of the Resource to create an Id for - * @param theId the String representation of the Id to generate - * @return the id - */ - public static IdType newId( - Class theResourceTypeClass, String theId) { - checkNotNull(theResourceTypeClass); - checkNotNull(theId); - - FhirVersionEnum versionEnum = FhirVersions.forClass(theResourceTypeClass); - return newId(versionEnum, theResourceTypeClass.getSimpleName(), theId); - } - - /** - * Creates the appropriate IIdType for a given BaseTypeClass - * - * @param an IBase type - * @param an IIdType type - * @param theBaseTypeClass the BaseTypeClass to use for for determining the FHIR - * Version - * @param theResourceName the type of the Resource to create an Id for - * @param theId the String representation of the Id to generate - * @return the id - */ - public static IdType newId( - Class theBaseTypeClass, String theResourceName, String theId) { - checkNotNull(theBaseTypeClass); - checkNotNull(theResourceName); - checkNotNull(theId); - - FhirVersionEnum versionEnum = FhirVersions.forClass(theBaseTypeClass); - return newId(versionEnum, theResourceName, theId); - } - - /** - * Creates the appropriate IIdType for a given FhirContext - * - * @param an IIdType type - * @param theFhirContext the FhirContext to use for Id generation - * @param theResourceType the type of the Resource to create an Id for - * @param theId the String representation of the Id to generate - * @return the id - */ - public static IdType newId(FhirContext theFhirContext, String theResourceType, - String theId) { - checkNotNull(theFhirContext); - checkNotNull(theResourceType); - checkNotNull(theId); - - return newId(theFhirContext.getVersion().getVersion(), theResourceType, theId); - } - - /** - * Creates the appropriate IIdType for a given FhirVersionEnum - * - * @param an IIdType type - * @param theFhirVersionEnum the FHIR version to generate an Id for - * @param theResourceType the type of the Resource to create an Id for - * @param theIdPart the String representation of the Id to generate - * @return the id - */ - public static IdType newId(FhirVersionEnum theFhirVersionEnum, String theResourceType, - String theIdPart) { - checkNotNull(theFhirVersionEnum); - checkNotNull(theResourceType); - checkNotNull(theIdPart); - - return newId(theFhirVersionEnum, theResourceType + "/" + theIdPart); - } - - /** - * Creates the appropriate IIdType for a given FhirContext - * - * @param an IIdType type - * @param theFhirContext the FhirContext to use for Id generation - * @param theId the String representation of the Id to generate - * @return the id - */ - public static IdType newId(FhirContext theFhirContext, String theId) { - checkNotNull(theFhirContext); - checkNotNull(theId); - - return newId(theFhirContext.getVersion().getVersion(), theId); - } - - /** - * The gets the "simple" Id for the Resource, without qualifiers or versions. - * For example, "Patient/123". - *

- * This is shorthand for - * resource.getIdElement().toUnqualifiedVersionless().getValue() - * - * @param resource the Resource to get the Id for - * @return the simple Id - */ - public static String simple(IBaseResource resource) { - checkNotNull(resource); - checkArgument(resource.getIdElement() != null); - - return simple(resource.getIdElement()); - } - - /** - * The gets the "simple" Id for the Id, without qualifiers or versions. For - * example, "Patient/123". - *

- * This is shorthand for id.toUnqualifiedVersionless().getValue() - * - * @param id the IIdType to get the Id for - * @return the simple Id - */ - public static String simple(IIdType id) { - checkNotNull(id); - checkArgument(id.hasResourceType()); - checkArgument(id.hasIdPart()); - - return id.toUnqualifiedVersionless().getValue(); - } - - /** - * The gets the "simple" Id part for the Id, without qualifiers or versions or - * the resource Prefix. For example, "123". - *

- * This is shorthand for - * resource.getIdElement().toUnqualifiedVersionless().getIdPart() - * - * @param resource the Resource to get the Id for - * @return the simple Id part - */ - public static String simplePart(IBaseResource resource) { - checkNotNull(resource); - checkArgument(resource.getIdElement() != null); - - return simplePart(resource.getIdElement()); - } - - /** - * The gets the "simple" Id part for the Id, without qualifiers or versions or - * the resource Prefix. For example, "123". - *

- * This is shorthand for id.toUnqualifiedVersionless().getIdPart() - * - * @param id the IIdType to get the Id for - * @return the simple Id part - */ - public static String simplePart(IIdType id) { - checkNotNull(id); - checkArgument(id.hasResourceType()); - checkArgument(id.hasIdPart()); - - return id.toUnqualifiedVersionless().getIdPart(); - } - - /** - * Creates the appropriate IIdType for a given FhirVersionEnum - * - * @param an IIdType type - * @param theFhirVersionEnum the FHIR version to generate an Id for - * @param theId the String representation of the Id to generate - * @return the id - */ - @SuppressWarnings("unchecked") - public static IdType newId(FhirVersionEnum theFhirVersionEnum, String theId) { - checkNotNull(theFhirVersionEnum); - checkNotNull(theId); - - switch (theFhirVersionEnum) { - case DSTU2: - return (IdType) new ca.uhn.fhir.model.primitive.IdDt(theId); - case DSTU2_1: - return (IdType) new org.hl7.fhir.dstu2016may.model.IdType(theId); - case DSTU2_HL7ORG: - return (IdType) new org.hl7.fhir.dstu2.model.IdType(theId); - case DSTU3: - return (IdType) new org.hl7.fhir.dstu3.model.IdType(theId); - case R4: - return (IdType) new org.hl7.fhir.r4.model.IdType(theId); - case R5: - return (IdType) new org.hl7.fhir.r5.model.IdType(theId); - default: - throw new IllegalArgumentException(String.format("newId does not support FHIR version %s", - theFhirVersionEnum.getFhirVersionString())); - } - } -} diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/Libraries.java b/core/src/main/java/org/opencds/cqf/ruler/utility/Libraries.java deleted file mode 100644 index ea59179e2..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/Libraries.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; - -import org.hl7.fhir.instance.model.api.IBase; -import org.hl7.fhir.instance.model.api.IBaseResource; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.context.FhirVersionEnum; - -public class Libraries { - - private static final Map cachedFunctions = new ConcurrentHashMap<>(); - private static final String LIBRARY_RESOURCE_TYPE = "Library"; - - private Libraries() { - } - - static byte[] getContent(IBaseResource library, LibraryFunctions libraryFunctions, String contentType) { - for (IBase attachment : libraryFunctions.getAttachments().apply(library)) { - String libraryContentType = libraryFunctions.getContentType().apply(attachment); - if (libraryContentType != null && libraryContentType.equals(contentType)) { - byte[] content = libraryFunctions.getContent().apply(attachment); - if (content != null) { - return content; - } - } - } - - return null; - } - - public static byte[] getContent(IBaseResource library, String contentType) { - checkNotNull(library); - checkArgument(library.fhirType().equals(LIBRARY_RESOURCE_TYPE)); - checkNotNull(contentType); - - LibraryFunctions libraryFunctions = getFunctions(library); - return getContent(library, libraryFunctions, contentType); - } - - static LibraryFunctions getFunctions(IBaseResource library) { - FhirVersionEnum fhirVersion = library.getStructureFhirVersionEnum(); - return cachedFunctions.computeIfAbsent(fhirVersion, Libraries::getFunctions); - } - - static LibraryFunctions getFunctions(FhirVersionEnum fhirVersionEnum) { - FhirContext fhirContext = FhirContext.forCached(fhirVersionEnum); - - Class libraryClass = fhirContext.getResourceDefinition(LIBRARY_RESOURCE_TYPE) - .getImplementingClass(); - Function> attachments = Reflections - .getFunction(libraryClass, "content"); - Function contentType = Reflections.getPrimitiveFunction( - fhirContext.getElementDefinition("Attachment").getImplementingClass(), "contentType"); - Function content = Reflections - .getPrimitiveFunction(fhirContext.getElementDefinition("Attachment").getImplementingClass(), "data"); - Function version = Reflections.getVersionFunction(libraryClass); - return new LibraryFunctions(attachments, contentType, content, version); - } - - public static String getVersion(IBaseResource library) { - checkNotNull(library); - checkArgument(library.fhirType().equals(LIBRARY_RESOURCE_TYPE)); - - LibraryFunctions libraryFunctions = getFunctions(library); - return libraryFunctions.getVersion().apply(library); - } -} diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/LibraryFunctions.java b/core/src/main/java/org/opencds/cqf/ruler/utility/LibraryFunctions.java deleted file mode 100644 index f5e1b729b..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/LibraryFunctions.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import java.util.List; -import java.util.function.Function; - -import org.hl7.fhir.instance.model.api.IBase; - -final class LibraryFunctions { - - private final Function> getAttachments; - private final Function getContentType; - private final Function getContent; - private final Function getVersion; - - LibraryFunctions(Function> getAttachments, Function getContentType, Function getContent, Function getVersion) { - this.getAttachments = getAttachments; - this.getContentType = getContentType; - this.getContent = getContent; - this.getVersion = getVersion; - } - - public Function> getAttachments() { - return this.getAttachments; - } - - public Function getContentType() { - return this.getContentType; - } - - public Function getContent() { - return this.getContent; - } - - public Function getVersion() { - return this.getVersion; - } -} diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/Operations.java b/core/src/main/java/org/opencds/cqf/ruler/utility/Operations.java index 161bf29db..f42529ada 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/Operations.java +++ b/core/src/main/java/org/opencds/cqf/ruler/utility/Operations.java @@ -6,12 +6,14 @@ import java.util.Optional; import java.util.regex.Pattern; -import ca.uhn.fhir.rest.api.RequestTypeEnum; -import ca.uhn.fhir.rest.param.DateRangeParam; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; +import org.opencds.cqf.cql.evaluator.fhir.util.Parameters; +import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.param.DateRangeParam; /** * This class provides utilities for implementing FHIR operations @@ -35,7 +37,7 @@ private Operations() { /** * This function returns a fullUrl for a resource. - * + * * @param serverAddress the address of the server * @param fhirType the type of the resource * @param elementId the id of the resource @@ -48,7 +50,7 @@ public static String getFullUrl(String serverAddress, String fhirType, String el /** * This function returns a fullUrl for a resource. - * + * * @param serverAddress the address of the server * @param resource the resource * @return the full url as a String @@ -59,7 +61,7 @@ public static String getFullUrl(String serverAddress, IBaseResource resource) { /** * This function validates a string as a representation of a FHIR date. - * + * * @param theParameter the name of the parameter * @param theValue the value of the parameter */ @@ -72,7 +74,7 @@ public static void validateDate(String theParameter, String theValue) { * This function validates a parameter as a string representation of a FHIR * date. * Precondition: the parameter has one and only one value. - * + * * @param theRequestDetails metadata about the current request being processed. * Generally auto-populated by the HAPI FHIR server * framework. @@ -82,10 +84,9 @@ public static void validateSingularDate(RequestDetails theRequestDetails, String validateCardinality(theRequestDetails, theParameter, 1, 1); if (theRequestDetails.getRequestType() == RequestTypeEnum.GET) { validateDate(theParameter, theRequestDetails.getParameters().get(theParameter)[0]); - } - else { + } else { Optional theValue = Parameters.getSingularStringPart( - theRequestDetails.getFhirContext(), theRequestDetails.getResource(), theParameter); + theRequestDetails.getFhirContext(), theRequestDetails.getResource(), theParameter); theValue.ifPresent(s -> validateDate(theParameter, s)); } } @@ -96,18 +97,18 @@ public static void validateSingularDate(RequestDetails theRequestDetails, String * @param requestDetails metadata about the current request being processed. * Generally auto-populated by the HAPI FHIR server * framework. - * @param parameter the name of the parameter - * @return the number of input parameters as an integer + * @param parameter the name of the parameter + * @return the number of input parameters as an integer */ public static int getNumberOfParametersFromRequest(RequestDetails requestDetails, String parameter) { if (requestDetails.getRequestType() == RequestTypeEnum.POST) { - List parameterList = Parameters.getPartsByName(requestDetails.getFhirContext(), requestDetails.getResource(), parameter); + List parameterList = Parameters.getPartsByName(requestDetails.getFhirContext(), + requestDetails.getResource(), parameter); if (parameterList == null) { return 0; } return parameterList.size(); - } - else { + } else { String[] parameterArr = requestDetails.getParameters().get(parameter); if (parameterArr == null) { return 0; @@ -119,7 +120,7 @@ public static int getNumberOfParametersFromRequest(RequestDetails requestDetails /** * This function validates the minimal and maximum number (inclusive) of values * (cardinality) of a parameter. - * + * * @param theRequestDetails metadata about the current request being processed. * Generally auto-populated by the HAPI FHIR server * framework. @@ -139,7 +140,7 @@ public static void validateCardinality(RequestDetails theRequestDetails, String /** * This function validates the minimal number (inclusive) of values * (cardinality) of a parameter. - * + * * @param theRequestDetails metadata about the current request being processed. * Generally auto-populated by the HAPI FHIR server * framework. @@ -161,7 +162,7 @@ public static void validateCardinality(RequestDetails theRequestDetails, String * FHIR dates and that they are a valid interval. * This includes that the start value is before the end value. * Precondition: the start and end parameters have one and only one value. - * + * * @param theRequestDetails metadata about the current request being processed. * Generally auto-populated by the HAPI FHIR server * framework. @@ -175,13 +176,12 @@ public static void validatePeriod(RequestDetails theRequestDetails, String theSt validateCardinality(theRequestDetails, theEndParameter, 1, 1); if (theRequestDetails.getRequestType() == RequestTypeEnum.GET) { new DateRangeParam(theRequestDetails.getParameters().get(theStartParameter)[0], - theRequestDetails.getParameters().get(theEndParameter)[0]); - } - else { + theRequestDetails.getParameters().get(theEndParameter)[0]); + } else { Optional start = Parameters.getSingularStringPart( - theRequestDetails.getFhirContext(), theRequestDetails.getResource(), theStartParameter); + theRequestDetails.getFhirContext(), theRequestDetails.getResource(), theStartParameter); Optional end = Parameters.getSingularStringPart( - theRequestDetails.getFhirContext(), theRequestDetails.getResource(), theEndParameter); + theRequestDetails.getFhirContext(), theRequestDetails.getResource(), theEndParameter); if (start.isPresent() && end.isPresent()) { new DateRangeParam(start.get(), end.get()); } @@ -191,7 +191,7 @@ public static void validatePeriod(RequestDetails theRequestDetails, String theSt /** * This function validates the value provided for a parameter matches a * specified regex pattern. - * + * * @param theParameter the name of the parameter * @param theValue the value of the parameter * @param thePattern the regex pattern to match @@ -207,7 +207,7 @@ public static void validatePattern(String theParameter, String theValue, Pattern * Pattern matching is only enforced if the parameter has a non null/empty * value. * Precondition: the parameter has one and only one value. - * + * * @param theRequestDetails metadata about the current request being processed. * Generally auto-populated by the HAPI FHIR server * framework. @@ -221,9 +221,9 @@ public static void validateSingularPattern(RequestDetails theRequestDetails, Str } if (theRequestDetails.getRequestType() == RequestTypeEnum.GET) { validatePattern(theParameter, theRequestDetails.getParameters().get(theParameter)[0], thePattern); - } - else { - Optional theValue = Parameters.getSingularStringPart(theRequestDetails.getFhirContext(), theRequestDetails.getResource(), theParameter); + } else { + Optional theValue = Parameters.getSingularStringPart(theRequestDetails.getFhirContext(), + theRequestDetails.getResource(), theParameter); theValue.ifPresent(s -> validatePattern(theParameter, s, thePattern)); } } @@ -233,7 +233,7 @@ public static void validateSingularPattern(RequestDetails theRequestDetails, Str * parameters. * Exclusivity is only enforced if the exclusive parameter has at least one * value. - * + * * @param theRequestDetails metadata about the current request being * processed. * Generally auto-populated by the HAPI FHIR server @@ -249,7 +249,7 @@ public static void validateExclusive(RequestDetails theRequestDetails, String th } for (String excludedParameter : theExcludedParameters) { checkArgument(getNumberOfParametersFromRequest(theRequestDetails, excludedParameter) <= 0, - "Parameter '%s' cannot be included with parameter '%s'.", excludedParameter, theParameter); + "Parameter '%s' cannot be included with parameter '%s'.", excludedParameter, theParameter); } } @@ -258,7 +258,7 @@ public static void validateExclusive(RequestDetails theRequestDetails, String th * parameter. * Inclusivity is only enforced if the inclusive parameter has at least one * value. - * + * * @param theRequestDetails metadata about the current request being * processed. * Generally auto-populated by the HAPI FHIR server @@ -274,7 +274,7 @@ public static void validateInclusive(RequestDetails theRequestDetails, String th } for (String includedParameter : theIncludedParameters) { checkArgument(getNumberOfParametersFromRequest(theRequestDetails, includedParameter) > 0, - "Parameter '%s' must be included with parameter '%s'.", includedParameter, theParameter); + "Parameter '%s' must be included with parameter '%s'.", includedParameter, theParameter); } } @@ -283,7 +283,7 @@ public static void validateInclusive(RequestDetails theRequestDetails, String th * value. * It is an exception that neither of the parameters has a value. * It is also an exception that both of the parameters has a value. - * + * * @param theRequestDetails metadata about the current request being * processed. * Generally auto-populated by the HAPI FHIR server @@ -304,7 +304,7 @@ public static void validateExclusiveOr(RequestDetails theRequestDetails, String * This function validates that at least one of a set of parameters has a value. * It is an exception that none of the parameters has a value. * It is not an exception that some or all of the parameters have a value. - * + * * @param theRequestDetails metadata about the current request being * processed. * Generally auto-populated by the HAPI FHIR server 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 deleted file mode 100644 index f237db150..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/Parameters.java +++ /dev/null @@ -1,200 +0,0 @@ -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 java.util.Optional; - -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 Optional getSingularStringPart(FhirContext fhirContext, IBaseResource parameters, String name) { - checkNotNull(parameters); - checkNotNull(name); - return ParametersUtil.getNamedParameterValueAsString(fhirContext, (IBaseParameters) parameters, name); - } - - 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/Reflections.java b/core/src/main/java/org/opencds/cqf/ruler/utility/Reflections.java deleted file mode 100644 index afd9f6bc5..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/Reflections.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.List; -import java.util.Optional; -import java.util.function.Function; - -import org.hl7.fhir.instance.model.api.IBase; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.instance.model.api.IPrimitiveType; - -import ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor; -import ca.uhn.fhir.context.BaseRuntimeElementDefinition; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.context.RuntimeResourceDefinition; - -/** - * This class provides utility methods for doing reflection on FHIR - * resources. It's specifically focused on knowledge artifact resources since - * there's not a common interface for those across different Resources (and FHIR - * versions) - */ -public class Reflections { - - private Reflections() { - } - - /** - * Gets the IAccessor for the given BaseType and child - * - * @param an IBase type - * @param theBaseTypeClass the class of a the IBase type - * @param theChildName the name of the child property of the - * BaseType to generate an accessor for - * @return an IAccessor for the given child and the BaseType - */ - public static IAccessor getAccessor( - final Class theBaseTypeClass, String theChildName) { - checkNotNull(theBaseTypeClass); - checkNotNull(theChildName); - - FhirContext fhirContext = FhirContext.forCached(FhirVersions.forClass(theBaseTypeClass)); - if (theBaseTypeClass.isInstance(IBaseResource.class)) { - Class theIBaseResourceClass = theBaseTypeClass.asSubclass(IBaseResource.class); - RuntimeResourceDefinition resourceDefinition = fhirContext - .getResourceDefinition(theIBaseResourceClass); - return resourceDefinition.getChildByName(theChildName).getAccessor(); - } else { - BaseRuntimeElementDefinition elementDefinition = fhirContext.getElementDefinition(theBaseTypeClass); - return elementDefinition.getChildByName(theChildName).getAccessor(); - } - } - - /** - * Generates a function to access a primitive property of the given - * BaseType. - * - * @param an IBase type - * @param a return type for the Functions - * @param theBaseTypeClass the class of a the IBase type - * @param theChildName to create a function for - * @return a function for accessing the "theChildName" property of the - * BaseType - */ - public static Function getPrimitiveFunction( - final Class theBaseTypeClass, String theChildName) { - checkNotNull(theBaseTypeClass); - checkNotNull(theChildName); - - IAccessor accessor = getAccessor(theBaseTypeClass, theChildName); - return r -> { - Optional value = accessor.getFirstValueOrNull(r); - if (!value.isPresent()) { - return null; - } else { - @SuppressWarnings("unchecked") - ReturnType x = ((IPrimitiveType) value.get()).getValue(); - return x; - } - }; - } - - /** - * Generates a function to access a primitive property of the given - * BaseType. - * - * @param an IBase type - * @param a return type for the Functions - * @param theBaseTypeClass the class of a the IBase type - * @param theChildName to create a function for - * @return a function for accessing the "theChildName" property of the - * BaseType - */ - public static > Function getFunction( - final Class theBaseTypeClass, String theChildName) { - checkNotNull(theBaseTypeClass); - checkNotNull(theChildName); - - IAccessor accessor = getAccessor(theBaseTypeClass, theChildName); - return r -> { - @SuppressWarnings("unchecked") - ReturnType x = (ReturnType) accessor.getValues(r); - return x; - }; - } - - /** - * Generates a function to access the "version" property of the given - * BaseType. - * - * @param an IBase type - * @param theBaseTypeClass the class of a the IBase type - * @return a function for accessing the "version" property of the BaseType - */ - public static Function getVersionFunction( - final Class theBaseTypeClass) { - checkNotNull(theBaseTypeClass); - - return getPrimitiveFunction(theBaseTypeClass, "version"); - } - - /** - * Generates a function to access the "url" property of the given BaseType. - * - * @param an IBase type - * @param theBaseTypeClass the class of a the IBase type - * @return a function for accessing the "url" property of the BaseType - */ - public static Function getUrlFunction( - final Class theBaseTypeClass) { - checkNotNull(theBaseTypeClass); - - return getPrimitiveFunction(theBaseTypeClass, "url"); - } - - /** - * Generates a function to access the "name" property of the given BaseType. - * - * @param an IBase type - * @param theBaseTypeClass the class of a the IBase type - * @return a function for accessing the "name" property of the BaseType - */ - public static Function getNameFunction( - final Class theBaseTypeClass) { - checkNotNull(theBaseTypeClass); - - return getPrimitiveFunction(theBaseTypeClass, "name"); - } -} diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/Resources.java b/core/src/main/java/org/opencds/cqf/ruler/utility/Resources.java deleted file mode 100644 index 12fb1bfe8..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/Resources.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import org.hl7.fhir.instance.model.api.IBaseBackboneElement; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.instance.model.api.IIdType; - -public class Resources { - - private Resources() { - } - - public static T newResource(Class theResourceClass, - String theIdPart) { - checkNotNull(theResourceClass); - checkNotNull(theIdPart); - checkArgument(!theIdPart.contains("/"), "theIdPart must be a simple id. Do not include resourceType or history"); - T resource = newResource(theResourceClass); - - @SuppressWarnings("unchecked") - I id = (I) Ids.newId(theResourceClass, theIdPart); - resource.setId(id); - return resource; - } - - public static T newResource(Class theResourceClass) { - checkNotNull(theResourceClass); - T resource = null; - try { - resource = theResourceClass.getConstructor().newInstance(); - } catch (Exception e) { - throw new IllegalArgumentException( - "theResourceClass must be a type with an empty default constructor to use this function"); - } - - return resource; - } - - public static T newBackboneElement(Class theBackboneElementClass) { - checkNotNull(theBackboneElementClass); - T backboneElement = null; - try { - backboneElement = theBackboneElementClass.getConstructor().newInstance(); - } catch (Exception e) { - throw new IllegalArgumentException( - "theBackboneElementClass must be a type with an empty default constructor to use this function"); - } - - return backboneElement; - } -} diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/Searches.java b/core/src/main/java/org/opencds/cqf/ruler/utility/Searches.java index 1908c92f1..9ff47a29d 100644 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/Searches.java +++ b/core/src/main/java/org/opencds/cqf/ruler/utility/Searches.java @@ -8,6 +8,7 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; +import org.opencds.cqf.cql.evaluator.fhir.util.Canonicals; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.model.api.IQueryParameterType; diff --git a/core/src/main/java/org/opencds/cqf/ruler/utility/Versions.java b/core/src/main/java/org/opencds/cqf/ruler/utility/Versions.java deleted file mode 100644 index 494a37bd7..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/Versions.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.List; -import java.util.function.Function; - -import org.hl7.fhir.instance.model.api.IBaseResource; - -/** - * This class provides utilities for handling multiple business versions of FHIR - * Resources. - */ -public class Versions { - private Versions() { - } - - /** - * This function compares two versions using semantic versioning. - * - * @param version1 the first version to compare - * @param version2 the second version to compare - * @return 0 if versions are equal, 1 if version1 is greater than version2, and - * -1 otherwise - */ - public static int compareVersions(String version1, String version2) { - // Treat null as MAX VERSION - if (version1 == null && version2 == null) { - return 0; - } - - if (version1 != null && version2 == null) { - return -1; - } - - if (version1 == null) { - return 1; - } - - String[] string1Vals = version1.split("\\."); - String[] string2Vals = version2.split("\\."); - - int length = Math.max(string1Vals.length, string2Vals.length); - - for (int i = 0; i < length; i++) { - Integer v1 = i < string1Vals.length ? Integer.parseInt(string1Vals[i]) : 0; - Integer v2 = i < string2Vals.length ? Integer.parseInt(string2Vals[i]) : 0; - - // Making sure Version1 bigger than version2 - if (v1 > v2) { - return 1; - } - // Making sure Version1 smaller than version2 - else if (v1 < v2) { - return -1; - } - } - - // Both are equal - return 0; - } - - /*** - * Given a list of FHIR Resources that have the same name, choose the one with - * the matching version. - * - * @param an IBaseResource type - * @param theResources a list of Resources to select from - * @param theVersion the version of the Resource to select - * @param theGetVersion a function to access version information for the - * ResourceType - * @return the Resource with a matching version, or the highest version - * otherwise. - */ - public static ResourceType selectByVersion(List theResources, - String theVersion, - Function theGetVersion) { - checkNotNull(theResources); - checkNotNull(theGetVersion); - - ResourceType library = null; - ResourceType maxVersion = null; - for (ResourceType l : theResources) { - String currentVersion = theGetVersion.apply(l); - if (theVersion == null && currentVersion == null || theVersion != null && theVersion.equals(currentVersion)) { - library = l; - } - - if (maxVersion == null || compareVersions(currentVersion, theGetVersion.apply(maxVersion)) >= 0) { - maxVersion = l; - } - } - - // If we were not given a version, return the highest found - if ((theVersion == null || library == null) && maxVersion != null) { - return maxVersion; - } - - return library; - } -} 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 deleted file mode 100644 index 88149c3ad..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/dstu3/Parameters.java +++ /dev/null @@ -1,174 +0,0 @@ -package org.opencds.cqf.ruler.utility.dstu3; - -import static com.google.common.base.Preconditions.checkNotNull; - -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 { - - private Parameters() { - } - - 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 = parameters(parts); - p.setId(theId); - return p; - } - - public static org.hl7.fhir.dstu3.model.Parameters parameters( - String theIdPart, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) { - checkNotNull(theIdPart); - return parameters((IdType) Ids.newId(org.hl7.fhir.dstu3.model.Parameters.class, theIdPart), parts); - } - - 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 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 = part(name, parts); - c.setValue(new StringType(value)); - return c; - } - - 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 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 = part(name, parts); - c.setValue(value); - return c; - } - - 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 = part(name, parts); - c.setResource(resource); - return c; - } - - public static List getPartsByName( - org.hl7.fhir.dstu3.model.Parameters parameters, String name) { - checkNotNull(parameters); - checkNotNull(name); - return parameters.getParameter().stream().filter(x -> 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 deleted file mode 100644 index 525cf4f75..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/r4/Parameters.java +++ /dev/null @@ -1,197 +0,0 @@ -package org.opencds.cqf.ruler.utility.r4; - -import static com.google.common.base.Preconditions.checkNotNull; - -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 { - - private Parameters() { - } - - 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 = parameters(parts); - p.setId(theId); - return p; - } - - public static org.hl7.fhir.r4.model.Parameters parameters( - String theIdPart, org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent... parts) { - checkNotNull(theIdPart); - return parameters((IdType) Ids.newId(org.hl7.fhir.r4.model.Parameters.class, theIdPart), parts); - } - - 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 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 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 = part(name, parts); - c.setValue(new StringType(value)); - return c; - } - - 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 = part(name, parts); - c.setValue(value); - return c; - } - - 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 = part(name, parts); - c.setResource(resource); - return c; - } - - public static List getPartsByName( - org.hl7.fhir.r4.model.Parameters parameters, String name) { - checkNotNull(parameters); - checkNotNull(name); - return parameters.getParameter().stream().filter(x -> 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 deleted file mode 100644 index 4d5cdc967..000000000 --- a/core/src/main/java/org/opencds/cqf/ruler/utility/r5/Parameters.java +++ /dev/null @@ -1,203 +0,0 @@ -package org.opencds.cqf.ruler.utility.r5; - -import static com.google.common.base.Preconditions.checkNotNull; - -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 { - - private Parameters() { - } - - 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 = parameters(parts); - p.setId(theId); - return p; - } - - public static org.hl7.fhir.r5.model.Parameters parameters( - String theIdPart, org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent... parts) { - checkNotNull(theIdPart); - return parameters((IdType) Ids.newId(org.hl7.fhir.r5.model.Parameters.class, theIdPart), parts); - } - - 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 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 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 = part(name, parts); - c.setValue(new StringType(value)); - return c; - } - - 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 = part(name, parts); - c.setValue(value); - return c; - } - - 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 = part(name, parts); - c.setResource(resource); - return c; - } - - public static List getPartsByName( - org.hl7.fhir.r5.model.Parameters parameters, String name) { - checkNotNull(parameters); - checkNotNull(name); - return parameters.getParameter().stream().filter(x -> 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/ExampleServerR5IT.java b/core/src/test/java/org/opencds/cqf/ruler/ExampleServerR5IT.java index 47cb4d109..eaf5586ea 100644 --- a/core/src/test/java/org/opencds/cqf/ruler/ExampleServerR5IT.java +++ b/core/src/test/java/org/opencds/cqf/ruler/ExampleServerR5IT.java @@ -9,7 +9,6 @@ import org.hl7.fhir.r5.model.Patient; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; @@ -36,7 +35,7 @@ public class ExampleServerR5IT { @LocalServerPort private int port; - @Test + // @Test public void testCreateAndRead() { String methodName = "testCreateResourceConditional"; diff --git a/core/src/test/java/org/opencds/cqf/ruler/utility/CanonicalsTest.java b/core/src/test/java/org/opencds/cqf/ruler/utility/CanonicalsTest.java deleted file mode 100644 index 1af177687..000000000 --- a/core/src/test/java/org/opencds/cqf/ruler/utility/CanonicalsTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import org.hl7.fhir.r4.model.CanonicalType; -import org.junit.jupiter.api.Test; - -public class CanonicalsTest { - @Test - public void fullCanonicalUrl() { - String testUrl = "http://fhir.acme.com/Questionnaire/example|1.0#vs1"; - - assertEquals("http://fhir.acme.com/Questionnaire/example", Canonicals.getUrl(testUrl)); - assertEquals("example", Canonicals.getIdPart(testUrl)); - assertEquals("1.0", Canonicals.getVersion(testUrl)); - assertEquals("vs1", Canonicals.getFragment(testUrl)); - } - - @Test - public void fullCanonicalUrlWithoutHash() { - String testUrl = "http://fhir.acme.com/Questionnaire/example|1.0"; - - assertEquals("http://fhir.acme.com/Questionnaire/example", Canonicals.getUrl(testUrl)); - assertEquals("example", Canonicals.getIdPart(testUrl)); - assertEquals("1.0", Canonicals.getVersion(testUrl)); - } - - @Test - public void partialCanonicalUrl() { - String testUrl = "http://fhir.acme.com/Questionnaire/example"; - - assertEquals("http://fhir.acme.com/Questionnaire/example", Canonicals.getUrl(testUrl)); - assertEquals("example", Canonicals.getIdPart(testUrl)); - assertNull(Canonicals.getVersion(testUrl)); - assertNull(Canonicals.getFragment(testUrl)); - } - - @Test - public void fullCanonicalType() { - CanonicalType testUrl = new CanonicalType("http://fhir.acme.com/Questionnaire/example|1.0#vs1"); - - assertEquals("http://fhir.acme.com/Questionnaire/example", Canonicals.getUrl(testUrl)); - assertEquals("example", Canonicals.getIdPart(testUrl)); - assertEquals("1.0", Canonicals.getVersion(testUrl)); - assertEquals("vs1", Canonicals.getFragment(testUrl)); - } - - @Test - public void partialCanonicalType() { - CanonicalType testUrl = new CanonicalType("http://fhir.acme.com/Questionnaire/example"); - - assertEquals("http://fhir.acme.com/Questionnaire/example", Canonicals.getUrl(testUrl)); - assertEquals("Questionnaire", Canonicals.getResourceType(testUrl)); - assertEquals("example", Canonicals.getIdPart(testUrl)); - assertNull(Canonicals.getVersion(testUrl)); - assertNull(Canonicals.getFragment(testUrl)); - } - - @Test - public void canonicalParts() { - CanonicalType testUrl = new CanonicalType("http://fhir.acme.com/Questionnaire/example|1.0#vs1"); - - CanonicalParts parts = Canonicals.getParts(testUrl); - - assertEquals("http://fhir.acme.com/Questionnaire/example", parts.url()); - assertEquals("Questionnaire", parts.resourceType()); - assertEquals("example", parts.idPart()); - assertEquals("1.0", parts.version()); - assertEquals("vs1", parts.fragment()); - } -} diff --git a/core/src/test/java/org/opencds/cqf/ruler/utility/ClientsTest.java b/core/src/test/java/org/opencds/cqf/ruler/utility/ClientsTest.java deleted file mode 100644 index ece2c72b9..000000000 --- a/core/src/test/java/org/opencds/cqf/ruler/utility/ClientsTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -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 static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.Collections; -import java.util.List; - -import org.hl7.fhir.dstu3.model.Endpoint; -import org.hl7.fhir.dstu3.model.StringType; -import org.junit.jupiter.api.Test; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.client.api.IGenericClient; -import ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor; - -public class ClientsTest { - @Test - public void testCreateClient() { - IGenericClient client = Clients.forUrl(FhirContext.forR4Cached(), "http://test.com"); - - assertNotNull(client); - assertEquals("http://test.com", client.getServerBase()); - } - - @Test - public void testRegisterAuth() { - IGenericClient client = Clients.forUrl(FhirContext.forR4Cached(), "http://test.com"); - Clients.registerBasicAuth(client, "user", "password"); - - List interceptors = client.getInterceptorService().getAllRegisteredInterceptors(); - - Object authInterceptor = interceptors.get(0); - assertTrue(authInterceptor instanceof BasicAuthInterceptor); - } - - @Test - public void testRegisterHeaders() { - IGenericClient client = Clients.forUrl(FhirContext.forR4Cached(), "http://test.com"); - Clients.registerHeaders(client, "Basic: XYZ123"); - - List interceptors = client.getInterceptorService().getAllRegisteredInterceptors(); - - Object interceptor = interceptors.get(0); - assertTrue(interceptor instanceof HeaderInjectionInterceptor); - } - - @Test - public void testRejectInvalidHeaders() { - IGenericClient client = Clients.forUrl(FhirContext.forR4Cached(), "http://test.com"); - assertThrows(IllegalArgumentException.class, () -> { - Clients.registerHeaders(client, "BasicXYZ123"); - }); - } - - @Test - public void testClientForEndpoint() { - Endpoint endpoint = new Endpoint(); - endpoint.setAddress("http://test.com"); - - endpoint.setHeader(Collections.singletonList(new StringType("Basic: XYZ123"))); - IGenericClient client = Clients.forEndpoint(endpoint); - - assertEquals("http://test.com", client.getServerBase()); - List interceptors = client.getInterceptorService().getAllRegisteredInterceptors(); - - Object interceptor = interceptors.get(0); - assertTrue(interceptor instanceof HeaderInjectionInterceptor); - } -} diff --git a/core/src/test/java/org/opencds/cqf/ruler/utility/FhirVersionsTest.java b/core/src/test/java/org/opencds/cqf/ruler/utility/FhirVersionsTest.java deleted file mode 100644 index c78e18782..000000000 --- a/core/src/test/java/org/opencds/cqf/ruler/utility/FhirVersionsTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.hl7.fhir.dstu3.model.Library; -import org.junit.jupiter.api.Test; - -import ca.uhn.fhir.context.FhirVersionEnum; - -public class FhirVersionsTest { - - @Test - public void testGetFhirVersion() { - FhirVersionEnum fhirVersion = FhirVersions.forClass(Library.class); - - assertEquals(FhirVersionEnum.DSTU3, fhirVersion); - } - - @Test - public void testGetFhirVersionUnknownClass() { - Library library = new Library(); - FhirVersionEnum fhirVersion = FhirVersions.forClass(library.getClass()); - - assertEquals(FhirVersionEnum.DSTU3, fhirVersion); - } - -} diff --git a/core/src/test/java/org/opencds/cqf/ruler/utility/IdsTest.java b/core/src/test/java/org/opencds/cqf/ruler/utility/IdsTest.java deleted file mode 100644 index ab8c2a06c..000000000 --- a/core/src/test/java/org/opencds/cqf/ruler/utility/IdsTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.jupiter.api.Test; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.context.FhirVersionEnum; - -public class IdsTest { - @Test - public void testAllVersionsSupported() { - for (FhirVersionEnum fhirVersionEnum : FhirVersionEnum.values()) { - Ids.newId(fhirVersionEnum, "Patient/123"); - } - } - - @Test - public void testContextSupported() { - IIdType id = Ids.newId(FhirContext.forDstu3Cached(), "Patient/123"); - assertTrue(id instanceof org.hl7.fhir.dstu3.model.IdType); - } - - @Test - public void testPartsSupported() { - IIdType id = Ids.newId(FhirVersionEnum.DSTU3, "Patient", "123"); - assertTrue(id instanceof org.hl7.fhir.dstu3.model.IdType); - - assertEquals("Patient", id.getResourceType()); - assertEquals("123", id.getIdPart()); - } - - @Test - public void testClassSupported() { - IIdType id = Ids.newId(org.hl7.fhir.dstu3.model.Library.class, "123"); - assertTrue(id instanceof org.hl7.fhir.dstu3.model.IdType); - assertEquals("Library", id.getResourceType()); - assertEquals("123", id.getIdPart()); - } -} diff --git a/core/src/test/java/org/opencds/cqf/ruler/utility/LibrariesTest.java b/core/src/test/java/org/opencds/cqf/ruler/utility/LibrariesTest.java deleted file mode 100644 index 680cb96b4..000000000 --- a/core/src/test/java/org/opencds/cqf/ruler/utility/LibrariesTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import org.hl7.fhir.r4.model.Library; -import org.hl7.fhir.r4.model.Measure; -import org.junit.jupiter.api.Test; - -public class LibrariesTest { - - @Test - public void libraryNoContentReturnsNull() { - Library library = new Library(); - - byte[] content = Libraries.getContent(library, "text/cql"); - - assertNull(content); - } - - @Test - public void libraryWithContentReturnsContent() { - Library library = new Library(); - library.addContent().setContentType("text/cql").setData("test-data".getBytes()); - - - byte[] content = Libraries.getContent(library, "text/cql"); - - assertEquals("test-data", new String(content)); - } - - @Test - public void libraryMismatchedContentReturnsNull() { - Library library = new Library(); - library.addContent().setContentType("text/cql").setData("test-data".getBytes()); - - - byte[] content = Libraries.getContent(library, "text/elm"); - - assertNull(content); - } - - @Test - public void libraryDstu3WithContentReturnsContent() { - org.hl7.fhir.dstu3.model.Library library = new org.hl7.fhir.dstu3.model.Library(); - library.addContent().setContentType("text/cql").setData("test-data".getBytes()); - - - byte[] content = Libraries.getContent(library, "text/cql"); - - assertEquals("test-data", new String(content)); - } - - @Test - public void notALibraryThrowsException() { - Measure m = new Measure(); - assertThrows(IllegalArgumentException.class, () -> { - Libraries.getContent(m, "text/cql"); - }); - } - - @Test - public void libraryWithVersionReturnsVersion() { - Library library = new Library().setVersion("1.0.0"); - - String version = Libraries.getVersion(library); - - assertEquals("1.0.0", version); - } - - @Test - public void libraryNoVersionReturnsNull() { - Library library = new Library(); - - String version = Libraries.getVersion(library); - - assertNull(version); - } -} 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 deleted file mode 100644 index 8552ece1a..000000000 --- a/core/src/test/java/org/opencds/cqf/ruler/utility/ParametersTest.java +++ /dev/null @@ -1,91 +0,0 @@ -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/ReflectionsTest.java b/core/src/test/java/org/opencds/cqf/ruler/utility/ReflectionsTest.java deleted file mode 100644 index 6289345b6..000000000 --- a/core/src/test/java/org/opencds/cqf/ruler/utility/ReflectionsTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.util.Optional; -import java.util.function.Function; - -import org.hl7.fhir.dstu3.model.Library; -import org.hl7.fhir.dstu3.model.Observation; -import org.hl7.fhir.instance.model.api.IBase; -import org.hl7.fhir.instance.model.api.IPrimitiveType; -import org.junit.jupiter.api.Test; - -import ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor; - -public class ReflectionsTest { - - @Test - public void testAccessor() { - Library library = new Library().setName("test"); - - IAccessor accessor = Reflections.getAccessor(library.getClass(), "name"); - - Optional opt = accessor.getFirstValueOrNull(library); - - @SuppressWarnings("unchecked") - IPrimitiveType value = (IPrimitiveType) opt.get(); - assertEquals("test", value.getValue()); - } - - @Test - public void testGetName() { - Library library = new Library().setName("test"); - - Function getName = Reflections.getNameFunction(library.getClass()); - - String name = getName.apply(library); - - assertEquals("test", name); - } - - @Test - public void testGetNameLiteral() { - Library library = new Library().setName("test"); - - Function getName = Reflections.getNameFunction(Library.class); - - String name = getName.apply(library); - - assertEquals("test", name); - } - - @Test - public void testGetNameNotExists() { - assertThrows(RuntimeException.class, () -> { - Reflections.getNameFunction(Observation.class); - }); - } - - @Test - public void testGetVersion() { - Library library = new Library().setVersion("test"); - - Function getVersion = Reflections.getVersionFunction(library.getClass()); - - String version = getVersion.apply(library); - - assertEquals("test", version); - } - - @Test - public void testGetUrl() { - Library library = new Library().setUrl("http://test.com"); - - Function getVersion = Reflections.getUrlFunction(library.getClass()); - - String version = getVersion.apply(library); - - assertEquals("http://test.com", version); - } -} diff --git a/core/src/test/java/org/opencds/cqf/ruler/utility/VersionsTest.java b/core/src/test/java/org/opencds/cqf/ruler/utility/VersionsTest.java deleted file mode 100644 index 22e2f259e..000000000 --- a/core/src/test/java/org/opencds/cqf/ruler/utility/VersionsTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.opencds.cqf.ruler.utility; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNull; - -import java.util.Arrays; -import java.util.List; -import java.util.function.Function; - -import org.hl7.fhir.dstu3.model.Library; -import org.junit.jupiter.api.Test; - -public class VersionsTest { - - @Test - public void testVersionCompare() { - int result = Versions.compareVersions("1.0.0", "0.9.9"); - assertEquals(1, result); - - result = Versions.compareVersions("0.9.9", "1.0.0"); - assertEquals(-1, result); - - result = Versions.compareVersions("1.0.0", "1.0.0"); - assertEquals(0, result); - - result = Versions.compareVersions(null, null); - assertEquals(0, result); - - result = Versions.compareVersions(null, "1.0.0"); - assertEquals(1, result); - - result = Versions.compareVersions("1.0.0", null); - assertEquals(-1, result); - - result = Versions.compareVersions("1.0", "0.0.9"); - assertEquals(1, result); - - result = Versions.compareVersions("0", "1.1.2"); - assertEquals(-1, result); - } - - @Test - public void testSelectFromList() { - List libraries = Arrays.asList(new Library().setVersion("1.0.0"), new Library().setVersion("0.0.1"), new Library()); - - Function getVersion = l -> l.getVersion(); - - // Gets matching version - Library lib = Versions.selectByVersion(libraries, "1.0.0", getVersion); - assertEquals("1.0.0", lib.getVersion()); - - // Gets max version (null version on library is considered max version) - lib = Versions.selectByVersion(libraries, "2.0.0", getVersion); - assertNull(lib.getVersion()); - - // Null version max version (null input gets max version) - lib = Versions.selectByVersion(libraries, null, getVersion); - assertNull(lib.getVersion()); - } -} 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 deleted file mode 100644 index 4bd3c7571..000000000 --- a/core/src/test/java/org/opencds/cqf/ruler/utility/dstu3/ParametersTest.java +++ /dev/null @@ -1,145 +0,0 @@ -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 deleted file mode 100644 index 040407d7a..000000000 --- a/core/src/test/java/org/opencds/cqf/ruler/utility/r4/ParametersTest.java +++ /dev/null @@ -1,171 +0,0 @@ -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 deleted file mode 100644 index ff307a510..000000000 --- a/core/src/test/java/org/opencds/cqf/ruler/utility/r5/ParametersTest.java +++ /dev/null @@ -1,157 +0,0 @@ -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/plugin/case-reporting/src/main/java/org/opencds/cqf/ruler/casereporting/r4/MeasureDataProcessProvider.java b/plugin/case-reporting/src/main/java/org/opencds/cqf/ruler/casereporting/r4/MeasureDataProcessProvider.java index f87a75d2b..d9eef9bcf 100644 --- a/plugin/case-reporting/src/main/java/org/opencds/cqf/ruler/casereporting/r4/MeasureDataProcessProvider.java +++ b/plugin/case-reporting/src/main/java/org/opencds/cqf/ruler/casereporting/r4/MeasureDataProcessProvider.java @@ -97,8 +97,7 @@ private void gatherSubjectList(MeasureReport report, List subjectList, } if (report != null) { gatherPatientsFromReport(report, populationSubjectListReferenceMap); - } - else { + } else { for (String subject : subjectList) { populationSubjectListReferenceMap.putIfAbsent(subject, new Reference(subject)); } @@ -117,9 +116,9 @@ private void gatherPatientsFromReport(MeasureReport report, populationSubjectListReferenceMap.putIfAbsent(subject.getReference(), subject); } if (subject.fhirType().equals("Group")) { - getPatientListFromGroup(subject.getReference()).forEach(patient -> - populationSubjectListReferenceMap.putIfAbsent(patient.getReference(), patient) - ); + getPatientListFromGroup(subject.getReference()) + .forEach(patient -> populationSubjectListReferenceMap + .putIfAbsent(patient.getReference(), patient)); } } } @@ -136,7 +135,7 @@ private List getPatientListFromGroup(String subjectGroupRef) { } else if (reference.getReferenceElement().getResourceType().equals("Group")) { patientList.addAll(getPatientListFromGroup(reference.getReference())); } else { - logger.info("Group member was not a Patient or a Group, so skipping. \n{}",reference.getReference()); + logger.info("Group member was not a Patient or a Group, so skipping. \n{}", reference.getReference()); } }); return patientList; @@ -158,7 +157,8 @@ private List getSubjectResultsFromList(Reference subjectResults) { ListResource list = (ListResource) baseList; list.getEntry().forEach(entry -> { - if (entry.getItemTarget().getResourceType() == ResourceType.Patient || entry.getItemTarget().getResourceType() == ResourceType.Group) { + if (entry.getItemTarget().getResourceType() == ResourceType.Patient + || entry.getItemTarget().getResourceType() == ResourceType.Group) { results.add(entry.getItem()); } }); 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 d212dc9eb..0d783f3d4 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 static org.opencds.cqf.ruler.utility.r4.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.MeasureReport; @@ -12,9 +12,8 @@ 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" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { + MeasureDataProcessProviderIT.class, CaseReportingConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) class MeasureDataProcessProviderIT extends RestIntegrationTest { @Test void testMeasureReportExtractLineListData() { diff --git a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/discovery/DiscoveryResolutionR4.java b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/discovery/DiscoveryResolutionR4.java index 55f4fe1df..989ef6552 100644 --- a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/discovery/DiscoveryResolutionR4.java +++ b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/discovery/DiscoveryResolutionR4.java @@ -3,7 +3,6 @@ import java.util.ArrayList; import java.util.List; -import com.google.gson.JsonObject; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.DataRequirement; @@ -13,6 +12,8 @@ import org.opencds.cqf.ruler.behavior.DaoRegistryUser; import org.opencds.cqf.ruler.utility.Searches; +import com.google.gson.JsonObject; + import ca.uhn.fhir.jpa.api.dao.DaoRegistry; public class DiscoveryResolutionR4 implements DaoRegistryUser { @@ -135,7 +136,8 @@ private StringBuilder getCodesStringBuilder(List ret, StringBuilder code public List createRequestUrl(DataRequirement dataRequirement) { if (!isPatientCompartment(dataRequirement.getType())) return null; - String patientRelatedResource = dataRequirement.getType() + "?" + getPatientSearchParam(dataRequirement.getType()) + String patientRelatedResource = dataRequirement.getType() + "?" + + getPatientSearchParam(dataRequirement.getType()) + "=Patient/" + PATIENT_ID_CONTEXT; List ret = new ArrayList<>(); if (dataRequirement.hasCodeFilter()) { diff --git a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/discovery/DiscoveryResolutionStu3.java b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/discovery/DiscoveryResolutionStu3.java index 8b20825c7..eae91ce45 100644 --- a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/discovery/DiscoveryResolutionStu3.java +++ b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/discovery/DiscoveryResolutionStu3.java @@ -3,7 +3,6 @@ import java.util.ArrayList; import java.util.List; -import com.google.gson.JsonObject; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.DataRequirement; @@ -13,9 +12,11 @@ import org.opencds.cqf.ruler.behavior.DaoRegistryUser; import org.opencds.cqf.ruler.utility.Searches; +import com.google.gson.JsonObject; + import ca.uhn.fhir.jpa.api.dao.DaoRegistry; -public class DiscoveryResolutionStu3 implements DaoRegistryUser { +public class DiscoveryResolutionStu3 implements DaoRegistryUser { private final String PATIENT_ID_CONTEXT = "{{context.patientId}}"; private final int DEFAULT_MAX_URI_LENGTH = 8000; @@ -135,7 +136,8 @@ private StringBuilder getCodesStringBuilder(List ret, StringBuilder code public List createRequestUrl(DataRequirement dataRequirement) { if (!isPatientCompartment(dataRequirement.getType())) return null; - String patientRelatedResource = dataRequirement.getType() + "?" + getPatientSearchParam(dataRequirement.getType()) + String patientRelatedResource = dataRequirement.getType() + "?" + + getPatientSearchParam(dataRequirement.getType()) + "=Patient/" + PATIENT_ID_CONTEXT; List ret = new ArrayList<>(); if (dataRequirement.hasCodeFilter()) { diff --git a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/dstu3/CdsHooksServlet.java b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/dstu3/CdsHooksServlet.java index 0396f40e1..932388327 100644 --- a/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/dstu3/CdsHooksServlet.java +++ b/plugin/cds-hooks/src/main/java/org/opencds/cqf/ruler/cdshooks/dstu3/CdsHooksServlet.java @@ -25,6 +25,7 @@ import org.opencds.cqf.cql.engine.exception.CqlException; import org.opencds.cqf.cql.engine.exception.DataProviderException; import org.opencds.cqf.cql.engine.fhir.model.Dstu3FhirModelResolver; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; import org.opencds.cqf.external.AppProperties; import org.opencds.cqf.ruler.behavior.DaoRegistryUser; import org.opencds.cqf.ruler.cdshooks.CdsServicesCache; @@ -37,7 +38,6 @@ import org.opencds.cqf.ruler.cpg.dstu3.provider.LibraryEvaluationProvider; import org.opencds.cqf.ruler.cql.CqlProperties; import org.opencds.cqf.ruler.cr.dstu3.provider.ActivityDefinitionApplyProvider; -import org.opencds.cqf.ruler.utility.Ids; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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 d27e812eb..c9496db18 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 @@ -1,34 +1,37 @@ package org.opencds.cqf.ruler.cdshooks.dstu3; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.parser.JsonParser; -import ca.uhn.fhir.parser.LenientErrorHandler; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import org.hl7.fhir.dstu3.model.Parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.part; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Extension; import org.hl7.fhir.dstu3.model.ParameterDefinition; -import org.hl7.fhir.dstu3.model.Resource; +import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.PlanDefinition; +import org.hl7.fhir.dstu3.model.Resource; import org.opencds.cqf.ruler.cdshooks.request.CdsHooksRequest; -import java.util.Map; -import java.util.HashMap; -import java.util.List; -import java.util.Set; -import java.util.HashSet; -import java.util.ArrayList; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.part; +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.parser.JsonParser; +import ca.uhn.fhir.parser.LenientErrorHandler; public class CdsHooksUtil { private CdsHooksUtil() { } - // NOTE: Making an assumption here that the parameter in the CQL will be named "ContextPrescriptions" + // NOTE: Making an assumption here that the parameter in the CQL will be named + // "ContextPrescriptions" public static Parameters getParameters(JsonObject contextResources) { Parameters parameters = parameters(); Bundle contextBundle = new JsonParser(FhirContext.forDstu3Cached(), new LenientErrorHandler()) @@ -69,8 +72,8 @@ public static Bundle getPrefetchResources(CdsHooksRequest request) { } } } - } - else return null; + } else + return null; resourceMap.forEach((key, value) -> prefetchResources.addEntry().setResource(value)); return prefetchResources; } @@ -79,7 +82,8 @@ public static List getExpressions(PlanDefinition planDefinition) { return getExpressionsFromActions(planDefinition.getAction()); } - // Assumption that expressions are using CQL and will be references (text/cql.identifier introduced in FHIR R4) + // Assumption that expressions are using CQL and will be references + // (text/cql.identifier introduced in FHIR R4) private static List getExpressionsFromActions(List actions) { Set expressions = new HashSet<>(); if (actions != null) { @@ -90,8 +94,7 @@ private static List getExpressionsFromActions(List getExpressionsFromActions(List prefetchResources.addEntry().setResource(value)); return prefetchResources; } @@ -90,8 +93,7 @@ private static List getExpressionsFromActions(List getExpressionsFromActions(List headerList = Stream.of(new StringType("Content-Type: application/json"), new StringType("Authorization: " + requestDetails.getHeader("Authorization"))) - .collect(Collectors.toList()); - Endpoint defaultEndpoint = new Endpoint().setAddress(requestDetails.getFhirServerBase()).setHeader(headerList); + .collect(Collectors.toList()); + Endpoint defaultEndpoint = new Endpoint().setAddress(requestDetails.getFhirServerBase()) + .setHeader(headerList); return (Parameters) evaluationHelper.getExpressionEvaluator().evaluate(expression, parameters == null ? new Parameters() : parameters, subject, evaluationHelper.resolveIncludedLibraries(library), 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 831700a60..c11e2f639 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.parameters; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.part; import java.util.HashSet; import java.util.List; @@ -29,13 +29,13 @@ import org.opencds.cqf.ruler.cql.LibraryLoaderFactory; import org.opencds.cqf.ruler.provider.DaoRegistryOperationProvider; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Configurable; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Operation; 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 { 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 0efa8cfcf..34f61a73c 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.parameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; import java.util.Collections; import java.util.List; @@ -32,13 +32,13 @@ import org.opencds.cqf.ruler.cql.LibraryLoaderFactory; import org.opencds.cqf.ruler.provider.DaoRegistryOperationProvider; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Configurable; import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.rest.annotation.Operation; 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; /** * This class is used to provide an {@link DaoRegistryOperationProvider @@ -250,15 +250,16 @@ public Parameters evaluate( if (StringUtils.isBlank(content)) { List headerList = Stream.of(new StringType("Content-Type: application/json"), new StringType("Authorization: " + requestDetails.getHeader("Authorization"))) - .collect(Collectors.toList()); - Endpoint defaultEndpoint = new Endpoint().setAddress(requestDetails.getFhirServerBase()).setHeader(headerList); + .collect(Collectors.toList()); + Endpoint defaultEndpoint = new Endpoint().setAddress(requestDetails.getFhirServerBase()) + .setHeader(headerList); return (Parameters) evaluationHelper.getExpressionEvaluator().evaluate(expression, - parameters == null ? new Parameters() : parameters, subject, - evaluationHelper.resolveIncludedLibraries(library), - useServerData == null || useServerData.booleanValue(), data, null, - dataEndpoint == null ? defaultEndpoint : dataEndpoint, - contentEndpoint == null ? defaultEndpoint : contentEndpoint, - terminologyEndpoint == null ? defaultEndpoint : terminologyEndpoint); + parameters == null ? new Parameters() : parameters, subject, + evaluationHelper.resolveIncludedLibraries(library), + useServerData == null || useServerData.booleanValue(), data, null, + dataEndpoint == null ? defaultEndpoint : dataEndpoint, + contentEndpoint == null ? defaultEndpoint : contentEndpoint, + terminologyEndpoint == null ? defaultEndpoint : terminologyEndpoint); } return (Parameters) evaluationHelper.getLibraryEvaluator().evaluate(libraryIdentifier, 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 8d5dbd7b1..79e3b9737 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.parameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; import java.util.HashSet; import java.util.List; @@ -29,13 +29,13 @@ import org.opencds.cqf.ruler.cql.LibraryLoaderFactory; import org.opencds.cqf.ruler.provider.DaoRegistryOperationProvider; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Configurable; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Operation; 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 { diff --git a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionAuthenticationIT.java b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionAuthenticationIT.java index c5f9dfd15..cb7f23ca0 100644 --- a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionAuthenticationIT.java +++ b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/dstu3/provider/CqlExecutionAuthenticationIT.java @@ -1,6 +1,11 @@ package org.opencds.cqf.ruler.cpg.dstu3.provider; -import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.stringPart; + import org.hl7.fhir.dstu3.model.IntegerType; import org.hl7.fhir.dstu3.model.Parameters; import org.junit.jupiter.api.BeforeEach; @@ -10,15 +15,13 @@ import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -import static org.junit.jupiter.api.Assertions.*; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.stringPart; +import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - classes = { CqlExecutionProviderIT.class, CpgConfig.class, SecurityConfig.class}, - properties = { "hapi.fhir.fhir_version=dstu3", "hapi.fhir.security.basic_auth.enabled=true", - "hapi.fhir.security.basic_auth.username=admin", - "hapi.fhir.security.basic_auth.password=admin" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CqlExecutionProviderIT.class, + CpgConfig.class, SecurityConfig.class }, properties = { "hapi.fhir.fhir_version=dstu3", + "hapi.fhir.security.basic_auth.enabled=true", + "hapi.fhir.security.basic_auth.username=admin", + "hapi.fhir.security.basic_auth.password=admin" }) class CqlExecutionAuthenticationIT extends RestIntegrationTest { private final String packagePrefix = "org/opencds/cqf/ruler/cpg/dstu3/provider/"; @@ -28,11 +31,11 @@ class CqlExecutionAuthenticationIT extends RestIntegrationTest { void testSimpleArithmeticCqlExecutionProvider() { Parameters params = parameters(stringPart("expression", "5 * 5")); Parameters results = getClient().operation() - .onServer() - .named("$cql") - .withParameters(params) - .withAdditionalHeader("Authorization", "Basic YWRtaW46YWRtaW4=") - .execute(); + .onServer() + .named("$cql") + .withParameters(params) + .withAdditionalHeader("Authorization", "Basic YWRtaW46YWRtaW4=") + .execute(); assertTrue(results.getParameter().get(0).getValue() instanceof IntegerType); assertEquals("25", ((IntegerType) results.getParameter().get(0).getValue()).asStringValue()); @@ -43,10 +46,10 @@ void testSimpleArithmeticCqlExecutionProviderWithoutAuth() { Parameters params = parameters(stringPart("expression", "5 * 5")); assertThrows(AuthenticationException.class, () -> { getClient().operation() - .onServer() - .named("$cql") - .withParameters(params) - .execute(); + .onServer() + .named("$cql") + .withParameters(params) + .execute(); }); } } 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 9666ce809..53d8cbbdb 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 @@ -1,30 +1,29 @@ package org.opencds.cqf.ruler.cpg.dstu3.provider; +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.cql.evaluator.fhir.util.dstu3.Parameters.booleanPart; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.datePart; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.stringPart; + import org.hl7.fhir.dstu3.model.BooleanType; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.IntegerType; import org.hl7.fhir.dstu3.model.Observation; +import org.hl7.fhir.dstu3.model.OperationOutcome; import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.Patient; -import org.hl7.fhir.dstu3.model.OperationOutcome; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.opencds.cqf.ruler.cpg.CpgConfig; import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -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.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 }, - properties = { "hapi.fhir.fhir_version=dstu3" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CqlExecutionProviderIT.class, + CpgConfig.class }, properties = { "hapi.fhir.fhir_version=dstu3" }) class CqlExecutionProviderIT extends RestIntegrationTest { private final String packagePrefix = "org/opencds/cqf/ruler/cpg/dstu3/provider/"; @@ -122,24 +121,24 @@ void testCqlExecutionProviderWithContent() { Parameters params = parameters( stringPart("subject", "Patient/SimplePatient"), stringPart("content", "library SimpleSTU3Library\n" + - "\n" + - "using FHIR version '3.0.1'\n" + - "\n" + - "include FHIRHelpers version '3.0.1' called FHIRHelpers\n" + - "\n" + - "context Patient\n" + - "\n" + - "define simpleBooleanExpression: true\n" + - "\n" + - "define observationRetrieve: [Observation]\n" + - "\n" + - "define observationHasCode: not IsNull(([Observation]).code)\n" + - "\n" + - "define \"Initial Population\": observationHasCode\n" + - "\n" + - "define \"Denominator\": \"Initial Population\"\n" + - "\n" + - "define \"Numerator\": \"Denominator\"")); + "\n" + + "using FHIR version '3.0.1'\n" + + "\n" + + "include FHIRHelpers version '3.0.1' called FHIRHelpers\n" + + "\n" + + "context Patient\n" + + "\n" + + "define simpleBooleanExpression: true\n" + + "\n" + + "define observationRetrieve: [Observation]\n" + + "\n" + + "define observationHasCode: not IsNull(([Observation]).code)\n" + + "\n" + + "define \"Initial Population\": observationHasCode\n" + + "\n" + + "define \"Denominator\": \"Initial Population\"\n" + + "\n" + + "define \"Numerator\": \"Denominator\"")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); @@ -168,24 +167,24 @@ void testCqlExecutionProviderWithContentAndExpression() { stringPart("subject", "Patient/SimplePatient"), stringPart("expression", "Numerator"), stringPart("content", "library SimpleSTU3Library\n" + - "\n" + - "using FHIR version '3.0.1'\n" + - "\n" + - "include FHIRHelpers version '3.0.1' called FHIRHelpers\n" + - "\n" + - "context Patient\n" + - "\n" + - "define simpleBooleanExpression: true\n" + - "\n" + - "define observationRetrieve: [Observation]\n" + - "\n" + - "define observationHasCode: not IsNull(([Observation]).code)\n" + - "\n" + - "define \"Initial Population\": observationHasCode\n" + - "\n" + - "define \"Denominator\": \"Initial Population\"\n" + - "\n" + - "define \"Numerator\": \"Denominator\"")); + "\n" + + "using FHIR version '3.0.1'\n" + + "\n" + + "include FHIRHelpers version '3.0.1' called FHIRHelpers\n" + + "\n" + + "context Patient\n" + + "\n" + + "define simpleBooleanExpression: true\n" + + "\n" + + "define observationRetrieve: [Observation]\n" + + "\n" + + "define observationHasCode: not IsNull(([Observation]).code)\n" + + "\n" + + "define \"Initial Population\": observationHasCode\n" + + "\n" + + "define \"Denominator\": \"Initial Population\"\n" + + "\n" + + "define \"Numerator\": \"Denominator\"")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); @@ -208,6 +207,7 @@ void testErrorExpression() { assertTrue(results.getParameterFirstRep().hasResource()); assertTrue(results.getParameterFirstRep().getResource() instanceof OperationOutcome); assertEquals("Unsupported interval point type for FHIR conversion java.lang.Integer", - ((OperationOutcome) results.getParameterFirstRep().getResource()).getIssueFirstRep().getDetails().getText()); + ((OperationOutcome) results.getParameterFirstRep().getResource()).getIssueFirstRep().getDetails() + .getText()); } } 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 cd2141a35..3e7dfc290 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 @@ -1,27 +1,26 @@ package org.opencds.cqf.ruler.cpg.dstu3.provider; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.stringPart; + +import java.util.List; +import java.util.stream.Collectors; + import org.hl7.fhir.dstu3.model.BooleanType; import org.hl7.fhir.dstu3.model.IdType; -import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.OperationOutcome; +import org.hl7.fhir.dstu3.model.Parameters; import org.junit.jupiter.api.Test; import org.opencds.cqf.ruler.cpg.CpgConfig; import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -import java.util.List; -import java.util.stream.Collectors; - -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.assertFalse; -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 }, - properties = { "hapi.fhir.fhir_version=dstu3" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { + LibraryEvaluationProviderIT.class, CpgConfig.class }, properties = { "hapi.fhir.fhir_version=dstu3" }) class LibraryEvaluationProviderIT extends RestIntegrationTest { private final String packagePrefix = "org/opencds/cqf/ruler/cpg/dstu3/provider/"; @@ -35,17 +34,16 @@ void testSimpleAsthmaInlineCode() { stringPart("subject", "Patient/SimplePatient")); Parameters result = getClient().operation() - .onInstance(new IdType("Library", "AsthmaTest")) - .named("$evaluate") - .withParameters(params) - .returnResourceType(Parameters.class) - .execute(); + .onInstance(new IdType("Library", "AsthmaTest")) + .named("$evaluate") + .withParameters(params) + .returnResourceType(Parameters.class) + .execute(); assertNotNull(result); assertTrue(result.hasParameter()); - List asthmaDiagnosis = - result.getParameter().stream().filter( - param -> param.getName().equals("Has Asthma Diagnosis")).collect(Collectors.toList()); + List asthmaDiagnosis = result.getParameter().stream().filter( + param -> param.getName().equals("Has Asthma Diagnosis")).collect(Collectors.toList()); assertFalse(asthmaDiagnosis.isEmpty()); assertTrue(((BooleanType) asthmaDiagnosis.get(0).getValue()).booleanValue()); } @@ -59,11 +57,11 @@ void testSimpleLibrary() { stringPart("subject", "Patient/SimplePatient")); Parameters result = getClient().operation() - .onInstance(new IdType("Library", "SimpleDstu3Library")) - .named("$evaluate") - .withParameters(params) - .returnResourceType(Parameters.class) - .execute(); + .onInstance(new IdType("Library", "SimpleDstu3Library")) + .named("$evaluate") + .withParameters(params) + .returnResourceType(Parameters.class) + .execute(); assertNotNull(result); assertTrue(result.hasParameter()); @@ -97,6 +95,7 @@ void testErrorLibrary() { assertTrue(results.getParameterFirstRep().hasResource()); assertTrue(results.getParameterFirstRep().getResource() instanceof OperationOutcome); assertEquals("Unsupported interval point type for FHIR conversion java.lang.Integer", - ((OperationOutcome) results.getParameterFirstRep().getResource()).getIssueFirstRep().getDetails().getText()); + ((OperationOutcome) results.getParameterFirstRep().getResource()).getIssueFirstRep().getDetails() + .getText()); } } diff --git a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionAuthenticationIT.java b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionAuthenticationIT.java index b036d2dbc..30d471687 100644 --- a/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionAuthenticationIT.java +++ b/plugin/cpg/src/test/java/org/opencds/cqf/ruler/cpg/r4/provider/CqlExecutionAuthenticationIT.java @@ -1,6 +1,11 @@ package org.opencds.cqf.ruler.cpg.r4.provider; -import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.stringPart; + import org.hl7.fhir.r4.model.IntegerType; import org.hl7.fhir.r4.model.Parameters; import org.junit.jupiter.api.BeforeEach; @@ -10,17 +15,13 @@ import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -import static org.junit.jupiter.api.Assertions.assertEquals; -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.parameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - classes = { CqlExecutionProviderIT.class, CpgConfig.class, SecurityConfig.class}, - properties = { "hapi.fhir.fhir_version=r4", "hapi.fhir.security.basic_auth.enabled=true", - "hapi.fhir.security.basic_auth.username=admin", - "hapi.fhir.security.basic_auth.password=admin" }) +import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CqlExecutionProviderIT.class, + CpgConfig.class, SecurityConfig.class }, properties = { "hapi.fhir.fhir_version=r4", + "hapi.fhir.security.basic_auth.enabled=true", + "hapi.fhir.security.basic_auth.username=admin", + "hapi.fhir.security.basic_auth.password=admin" }) class CqlExecutionAuthenticationIT extends RestIntegrationTest { private final String packagePrefix = "org/opencds/cqf/ruler/cpg/r4/provider/"; @@ -30,11 +31,11 @@ class CqlExecutionAuthenticationIT extends RestIntegrationTest { void testSimpleArithmeticCqlExecutionProvider() { Parameters params = parameters(stringPart("expression", "5 * 5")); Parameters results = getClient().operation() - .onServer() - .named("$cql") - .withParameters(params) - .withAdditionalHeader("Authorization", "Basic YWRtaW46YWRtaW4=") - .execute(); + .onServer() + .named("$cql") + .withParameters(params) + .withAdditionalHeader("Authorization", "Basic YWRtaW46YWRtaW4=") + .execute(); assertTrue(results.getParameter("return") instanceof IntegerType); assertEquals("25", ((IntegerType) results.getParameter("return")).asStringValue()); @@ -45,10 +46,10 @@ void testSimpleArithmeticCqlExecutionProviderWithoutAuth() { Parameters params = parameters(stringPart("expression", "5 * 5")); assertThrows(AuthenticationException.class, () -> { getClient().operation() - .onServer() - .named("$cql") - .withParameters(params) - .execute(); + .onServer() + .named("$cql") + .withParameters(params) + .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 cc5ccde98..5ed17818f 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 @@ -1,32 +1,31 @@ package org.opencds.cqf.ruler.cpg.r4.provider; +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.cql.evaluator.fhir.util.r4.Parameters.booleanPart; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.canonicalPart; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.datePart; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.stringPart; + import org.hl7.fhir.r4.model.BooleanType; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Condition; import org.hl7.fhir.r4.model.IntegerType; import org.hl7.fhir.r4.model.Observation; +import org.hl7.fhir.r4.model.OperationOutcome; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Patient; -import org.hl7.fhir.r4.model.OperationOutcome; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.opencds.cqf.ruler.cpg.CpgConfig; import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -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.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/"; @@ -81,7 +80,7 @@ void testDataBundleCqlExecutionProvider() { Bundle data = (Bundle) loadResource(packagePrefix + "SimpleDataBundle.json"); Parameters params = parameters( part("library", libraryParameter), - stringPart("expression","SimpleR4Library.\"observationRetrieve\""), + stringPart("expression", "SimpleR4Library.\"observationRetrieve\""), part("data", data), booleanPart("useServerData", false)); Parameters results = getClient().operation().onServer().named("$cql") @@ -124,24 +123,24 @@ void testCqlExecutionProviderWithContent() { Parameters params = parameters( stringPart("subject", "SimplePatient"), stringPart("content", "library SimpleR4Library\n" + - "\n" + - "using FHIR version '4.0.1'\n" + - "\n" + - "include FHIRHelpers version '4.0.1' called FHIRHelpers\n" + - "\n" + - "context Patient\n" + - "\n" + - "define simpleBooleanExpression: true\n" + - "\n" + - "define observationRetrieve: [Observation]\n" + - "\n" + - "define observationHasCode: not IsNull(([Observation]).code)\n" + - "\n" + - "define \"Initial Population\": observationHasCode\n" + - "\n" + - "define \"Denominator\": \"Initial Population\"\n" + - "\n" + - "define \"Numerator\": \"Denominator\"")); + "\n" + + "using FHIR version '4.0.1'\n" + + "\n" + + "include FHIRHelpers version '4.0.1' called FHIRHelpers\n" + + "\n" + + "context Patient\n" + + "\n" + + "define simpleBooleanExpression: true\n" + + "\n" + + "define observationRetrieve: [Observation]\n" + + "\n" + + "define observationHasCode: not IsNull(([Observation]).code)\n" + + "\n" + + "define \"Initial Population\": observationHasCode\n" + + "\n" + + "define \"Denominator\": \"Initial Population\"\n" + + "\n" + + "define \"Numerator\": \"Denominator\"")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); @@ -176,25 +175,25 @@ void testCqlExecutionProviderWithContentAndExpression() { Parameters params = parameters( stringPart("subject", "SimplePatient"), stringPart("expression", "Numerator"), - stringPart("content","library SimpleR4Library\n" + - "\n" + - "using FHIR version '4.0.1'\n" + - "\n" + - "include FHIRHelpers version '4.0.1' called FHIRHelpers\n" + - "\n" + - "context Patient\n" + - "\n" + - "define simpleBooleanExpression: true\n" + - "\n" + - "define observationRetrieve: [Observation]\n" + - "\n" + - "define observationHasCode: not IsNull(([Observation]).code)\n" + - "\n" + - "define \"Initial Population\": observationHasCode\n" + - "\n" + - "define \"Denominator\": \"Initial Population\"\n" + - "\n" + - "define \"Numerator\": \"Denominator\"")); + stringPart("content", "library SimpleR4Library\n" + + "\n" + + "using FHIR version '4.0.1'\n" + + "\n" + + "include FHIRHelpers version '4.0.1' called FHIRHelpers\n" + + "\n" + + "context Patient\n" + + "\n" + + "define simpleBooleanExpression: true\n" + + "\n" + + "define observationRetrieve: [Observation]\n" + + "\n" + + "define observationHasCode: not IsNull(([Observation]).code)\n" + + "\n" + + "define \"Initial Population\": observationHasCode\n" + + "\n" + + "define \"Denominator\": \"Initial Population\"\n" + + "\n" + + "define \"Numerator\": \"Denominator\"")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); @@ -210,22 +209,22 @@ void testContentRetrieveWithInlineCode() { Parameters params = parameters( stringPart("subject", "SimplePatient"), stringPart("content", "library AsthmaTest version '1.0.0'\n" + - "\n" + - "using FHIR version '4.0.1'\n" + - "\n" + - "include FHIRHelpers version '4.0.1'\n" + - "\n" + - "codesystem \"SNOMED\": 'http://snomed.info/sct'\n" + - "\n" + - "code \"Asthma\": '195967001' from \"SNOMED\"\n" + - "\n" + - "context Patient\n" + - "\n" + - "define \"Asthma Diagnosis\":\n" + - " [Condition: \"Asthma\"]\n" + - "\n" + - "define \"Has Asthma Diagnosis\":\n" + - " exists(\"Asthma Diagnosis\")\n")); + "\n" + + "using FHIR version '4.0.1'\n" + + "\n" + + "include FHIRHelpers version '4.0.1'\n" + + "\n" + + "codesystem \"SNOMED\": 'http://snomed.info/sct'\n" + + "\n" + + "code \"Asthma\": '195967001' from \"SNOMED\"\n" + + "\n" + + "context Patient\n" + + "\n" + + "define \"Asthma Diagnosis\":\n" + + " [Condition: \"Asthma\"]\n" + + "\n" + + "define \"Has Asthma Diagnosis\":\n" + + " exists(\"Asthma Diagnosis\")\n")); Parameters results = getClient().operation().onServer().named("$cql") .withParameters(params).execute(); @@ -251,6 +250,7 @@ void testErrorExpression() { assertTrue(results.getParameterFirstRep().hasResource()); assertTrue(results.getParameterFirstRep().getResource() instanceof OperationOutcome); assertEquals("Unsupported interval point type for FHIR conversion java.lang.Integer", - ((OperationOutcome) results.getParameterFirstRep().getResource()).getIssueFirstRep().getDetails().getText()); + ((OperationOutcome) results.getParameterFirstRep().getResource()).getIssueFirstRep().getDetails() + .getText()); } } 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 8976d2c46..e035aab5b 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 @@ -1,32 +1,31 @@ package org.opencds.cqf.ruler.cpg.r4.provider; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.booleanPart; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.stringPart; + import org.hl7.fhir.r4.model.BooleanType; +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.MedicationRequest; +import org.hl7.fhir.r4.model.OperationOutcome; import org.hl7.fhir.r4.model.Parameters; -import org.hl7.fhir.r4.model.StringType; -import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Patient; -import org.hl7.fhir.r4.model.MedicationRequest; -import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.ServiceRequest; -import org.hl7.fhir.r4.model.OperationOutcome; +import org.hl7.fhir.r4.model.StringType; import org.junit.jupiter.api.Test; import org.opencds.cqf.ruler.cpg.CpgConfig; import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -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.assertFalse; -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 }, - properties = { "hapi.fhir.fhir_version=r4" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { + LibraryEvaluationProviderIT.class, CpgConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) class LibraryEvaluationProviderIT extends RestIntegrationTest { private final String packagePrefix = "org/opencds/cqf/ruler/cpg/r4/provider/"; @@ -39,11 +38,11 @@ void testSimpleAsthmaInlineCode() { Parameters params = parameters(stringPart("subject", "Patient/SimplePatient")); Parameters result = getClient().operation() - .onInstance(new IdType("Library", "AsthmaTest")) - .named("$evaluate") - .withParameters(params) - .returnResourceType(Parameters.class) - .execute(); + .onInstance(new IdType("Library", "AsthmaTest")) + .named("$evaluate") + .withParameters(params) + .returnResourceType(Parameters.class) + .execute(); assertNotNull(result); assertTrue(result.hasParameter("Has Asthma Diagnosis")); @@ -58,11 +57,11 @@ void testSimpleLibrary() { Parameters params = parameters(stringPart("subject", "Patient/SimplePatient")); Parameters result = getClient().operation() - .onInstance(new IdType("Library", "SimpleR4Library")) - .named("$evaluate") - .withParameters(params) - .returnResourceType(Parameters.class) - .execute(); + .onInstance(new IdType("Library", "SimpleR4Library")) + .named("$evaluate") + .withParameters(params) + .returnResourceType(Parameters.class) + .execute(); assertNotNull(result); assertTrue(result.hasParameter("Initial Population")); @@ -83,11 +82,11 @@ void testSimpleLibraryWithBundle() { booleanPart("useServerData", false)); Parameters result = getClient().operation() - .onInstance(new IdType("Library", "SimpleR4Library")) - .named("$evaluate") - .withParameters(params) - .returnResourceType(Parameters.class) - .execute(); + .onInstance(new IdType("Library", "SimpleR4Library")) + .named("$evaluate") + .withParameters(params) + .returnResourceType(Parameters.class) + .execute(); assertNotNull(result); assertTrue(result.hasParameter("Initial Population")); @@ -106,11 +105,11 @@ void testOpioidRec10Library() { Parameters params = parameters(stringPart("subject", "Patient/example-rec-10-no-screenings")); Parameters result = getClient().operation() - .onInstance(new IdType("Library", "OpioidCDSREC10PatientView")) - .named("$evaluate") - .withParameters(params) - .returnResourceType(Parameters.class) - .execute(); + .onInstance(new IdType("Library", "OpioidCDSREC10PatientView")) + .named("$evaluate") + .withParameters(params) + .returnResourceType(Parameters.class) + .execute(); assertNotNull(result); assertEquals(10, result.getParameter().size()); @@ -163,6 +162,7 @@ void testErrorLibrary() { assertTrue(results.getParameterFirstRep().hasResource()); assertTrue(results.getParameterFirstRep().getResource() instanceof OperationOutcome); assertEquals("Unsupported interval point type for FHIR conversion java.lang.Integer", - ((OperationOutcome) results.getParameterFirstRep().getResource()).getIssueFirstRep().getDetails().getText()); + ((OperationOutcome) results.getParameterFirstRep().getResource()).getIssueFirstRep().getDetails() + .getText()); } } diff --git a/plugin/cql/pom.xml b/plugin/cql/pom.xml index 52964b466..d9cd175ec 100644 --- a/plugin/cql/pom.xml +++ b/plugin/cql/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.opencds.cqf.ruler @@ -17,6 +18,10 @@ org.opencds.cqf.cql evaluator.spring + + org.opencds.cqf.cql + evaluator.fhir + org.opencds.cqf.cql evaluator.jackson-deps diff --git a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/CodeCacheResourceChangeListener.java b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/CodeCacheResourceChangeListener.java index f012d2a3f..02cfcaa13 100644 --- a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/CodeCacheResourceChangeListener.java +++ b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/CodeCacheResourceChangeListener.java @@ -9,7 +9,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.opencds.cqf.cql.engine.runtime.Code; -import org.opencds.cqf.ruler.utility.Reflections; +import org.opencds.cqf.cql.evaluator.fhir.util.Reflections; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; diff --git a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/ElmCacheResourceChangeListener.java b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/ElmCacheResourceChangeListener.java index 159a64e9e..30e7b70d6 100644 --- a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/ElmCacheResourceChangeListener.java +++ b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/ElmCacheResourceChangeListener.java @@ -9,7 +9,7 @@ import org.cqframework.cql.elm.execution.VersionedIdentifier; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.opencds.cqf.ruler.utility.Reflections; +import org.opencds.cqf.cql.evaluator.fhir.util.Reflections; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; diff --git a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaLibrarySourceProvider.java b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaLibrarySourceProvider.java index e74f77d65..ee86f6921 100644 --- a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaLibrarySourceProvider.java +++ b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaLibrarySourceProvider.java @@ -8,10 +8,10 @@ import org.cqframework.cql.cql2elm.LibrarySourceProvider; import org.hl7.elm.r1.VersionedIdentifier; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.opencds.cqf.cql.evaluator.fhir.util.Libraries; +import org.opencds.cqf.cql.evaluator.fhir.util.Versions; import org.opencds.cqf.ruler.behavior.DaoRegistryUser; -import org.opencds.cqf.ruler.utility.Libraries; import org.opencds.cqf.ruler.utility.Searches; -import org.opencds.cqf.ruler.utility.Versions; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.rest.api.server.RequestDetails; diff --git a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaTerminologyProvider.java b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaTerminologyProvider.java index 568286c0d..30deb2848 100644 --- a/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaTerminologyProvider.java +++ b/plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/JpaTerminologyProvider.java @@ -11,6 +11,7 @@ import org.opencds.cqf.cql.engine.terminology.CodeSystemInfo; import org.opencds.cqf.cql.engine.terminology.TerminologyProvider; import org.opencds.cqf.cql.engine.terminology.ValueSetInfo; +import org.opencds.cqf.cql.evaluator.fhir.util.Canonicals; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.IValidationSupport.LookupCodeResult; @@ -19,7 +20,6 @@ import ca.uhn.fhir.jpa.term.api.ITermReadSvc; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -import org.opencds.cqf.ruler.utility.Canonicals; /** * This class provides an implementation of the cql-engine's TerminologyProvider @@ -61,7 +61,8 @@ public Iterable expand(ValueSetInfo valueSet) throws ResourceNotFoundExcep // This could possibly be refactored into a single call to the underlying HAPI // Terminology service. Need to think through that.., - VersionedIdentifier vsId = new VersionedIdentifier().withId(valueSet.getId()).withVersion(valueSet.getVersion()); + VersionedIdentifier vsId = new VersionedIdentifier().withId(valueSet.getId()) + .withVersion(valueSet.getVersion()); if (this.myGlobalCodeCache.containsKey(vsId)) { return this.myGlobalCodeCache.get(vsId); @@ -72,12 +73,11 @@ public Iterable expand(ValueSetInfo valueSet) throws ResourceNotFoundExcep valueSetExpansionOptions.setCount(Integer.MAX_VALUE); if (valueSet.getVersion() != null && Canonicals.getUrl(valueSet.getId()) != null - && Canonicals.getVersion(valueSet.getId()) == null) { + && Canonicals.getVersion(valueSet.getId()) == null) { valueSet.setId(valueSet.getId() + "|" + valueSet.getVersion()); } - org.hl7.fhir.r4.model.ValueSet vs = - myTerminologySvc.expandValueSet(valueSetExpansionOptions, valueSet.getId()); + org.hl7.fhir.r4.model.ValueSet vs = myTerminologySvc.expandValueSet(valueSetExpansionOptions, valueSet.getId()); List codes = getCodes(vs); this.myGlobalCodeCache.put(vsId, codes); @@ -87,7 +87,7 @@ public Iterable expand(ValueSetInfo valueSet) throws ResourceNotFoundExcep @Override public Code lookup(Code code, CodeSystemInfo codeSystem) throws ResourceNotFoundException { LookupCodeResult cs = myTerminologySvc.lookupCode( - new ValidationSupportContext(myValidationSupport), codeSystem.getId(), code.getCode()); + new ValidationSupportContext(myValidationSupport), codeSystem.getId(), code.getCode()); if (cs != null) { code.setDisplay(cs.getCodeDisplay()); @@ -99,7 +99,8 @@ public Code lookup(Code code, CodeSystemInfo codeSystem) throws ResourceNotFound protected List getCodes(org.hl7.fhir.r4.model.ValueSet theValueSet) { checkState(theValueSet.hasExpansion(), - "ValueSet {} did not have an expansion. Unable to get codes unexpanded ValueSet.", theValueSet.getUrl()); + "ValueSet {} did not have an expansion. Unable to get codes unexpanded ValueSet.", + theValueSet.getUrl()); List codes = new ArrayList<>(); for (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent vse : theValueSet.getExpansion() diff --git a/plugin/cr/pom.xml b/plugin/cr/pom.xml index d263bcb6a..4eeb2515b 100644 --- a/plugin/cr/pom.xml +++ b/plugin/cr/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.opencds.cqf.ruler @@ -16,6 +17,10 @@ org.opencds.cqf.cql evaluator.measure + + org.opencds.cqf.cql + evaluator.fhir + org.opencds.cqf.cql evaluator.measure-hapi 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 aefee0bfb..dca3d78ca 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.parameters; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.part; import java.util.ArrayList; import java.util.List; @@ -36,11 +36,11 @@ public class CollectDataProvider extends DaoRegistryOperationProvider { * operation found in the * FHIR * Clinical Reasoning Module. - * + * *

* Returns a set of parameters with the generated MeasureReport and the * resources that were used during the Measure evaluation - * + * * @param theRequestDetails generally auto-populated by the HAPI server * framework. * @param theId the Id of the Measure to sub data for diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/provider/DataOperationsProvider.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/provider/DataOperationsProvider.java index 44b625b2c..5a77c69f2 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/provider/DataOperationsProvider.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/provider/DataOperationsProvider.java @@ -22,14 +22,14 @@ import org.opencds.cqf.cql.evaluator.cql2elm.content.fhir.BundleFhirLibrarySourceProvider; import org.opencds.cqf.cql.evaluator.cql2elm.util.LibraryVersionSelector; import org.opencds.cqf.cql.evaluator.fhir.adapter.AdapterFactory; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; +import org.opencds.cqf.cql.evaluator.fhir.util.Libraries; import org.opencds.cqf.ruler.cql.JpaLibrarySourceProvider; import org.opencds.cqf.ruler.cql.JpaLibrarySourceProviderFactory; import org.opencds.cqf.ruler.cql.LibraryManagerFactory; import org.opencds.cqf.ruler.cql.utility.Translators; import org.opencds.cqf.ruler.cr.utility.DataRequirements; import org.opencds.cqf.ruler.provider.DaoRegistryOperationProvider; -import org.opencds.cqf.ruler.utility.Ids; -import org.opencds.cqf.ruler.utility.Libraries; import org.opencds.cqf.ruler.utility.Searches; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -109,7 +109,8 @@ public Library getLibraryFromMeasure(Measure measure, RequestDetails theRequestD } if (library == null) { - library = search(Library.class, Searches.byCanonical(libraryIdOrCanonical), theRequestDetails).firstOrNull(); + library = search(Library.class, Searches.byCanonical(libraryIdOrCanonical), theRequestDetails) + .firstOrNull(); } return library; } diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/service/MeasureService.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/service/MeasureService.java index 37c5c25ae..12326d310 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/service/MeasureService.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/dstu3/service/MeasureService.java @@ -16,13 +16,13 @@ import org.opencds.cqf.cql.evaluator.CqlOptions; import org.opencds.cqf.cql.evaluator.builder.DataProviderFactory; import org.opencds.cqf.cql.evaluator.fhir.dal.FhirDal; +import org.opencds.cqf.cql.evaluator.fhir.util.Clients; import org.opencds.cqf.cql.evaluator.measure.MeasureEvaluationOptions; import org.opencds.cqf.ruler.behavior.DaoRegistryUser; import org.opencds.cqf.ruler.cql.JpaDataProviderFactory; import org.opencds.cqf.ruler.cql.JpaFhirDalFactory; import org.opencds.cqf.ruler.cql.JpaLibrarySourceProviderFactory; import org.opencds.cqf.ruler.cql.JpaTerminologyProviderFactory; -import org.opencds.cqf.ruler.utility.Clients; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluation.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluation.java index 475eb31b8..f2b8111c1 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluation.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/ExpressionEvaluation.java @@ -23,6 +23,7 @@ import org.opencds.cqf.cql.engine.execution.LibraryLoader; import org.opencds.cqf.cql.engine.terminology.TerminologyProvider; import org.opencds.cqf.cql.evaluator.cql2elm.content.InMemoryLibrarySourceProvider; +import org.opencds.cqf.cql.evaluator.fhir.util.Canonicals; import org.opencds.cqf.ruler.cql.CqlProperties; import org.opencds.cqf.ruler.cql.JpaDataProviderFactory; import org.opencds.cqf.ruler.cql.JpaFhirDal; @@ -30,7 +31,6 @@ import org.opencds.cqf.ruler.cql.JpaLibrarySourceProviderFactory; import org.opencds.cqf.ruler.cql.JpaTerminologyProviderFactory; import org.opencds.cqf.ruler.cql.LibraryLoaderFactory; -import org.opencds.cqf.ruler.utility.Canonicals; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.context.FhirContext; @@ -105,7 +105,8 @@ private Context setupContext(DomainResource instance, String cql, String patient // log error } if (executionLibrary == null) { - Library library = (Library) jpaFhirDal.read(new IdType("Library", Canonicals.getIdPart(libraries.get(0)))); + Library library = (Library) jpaFhirDal + .read(new IdType("Library", Canonicals.getIdPart(libraries.get(0)))); vi.setId(library.getName()); if (library.getVersion() != null) { vi.setVersion(library.getVersion()); diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/CareGapsProvider.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/CareGapsProvider.java index 86486d2cb..78e3e6cf9 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/CareGapsProvider.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/CareGapsProvider.java @@ -1,10 +1,10 @@ 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 com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Map.ofEntries; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; import java.util.AbstractMap; import java.util.ArrayList; @@ -36,6 +36,8 @@ import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.Resource; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; +import org.opencds.cqf.cql.evaluator.fhir.util.Resources; import org.opencds.cqf.ruler.behavior.ConfigurationUser; import org.opencds.cqf.ruler.behavior.ResourceCreator; import org.opencds.cqf.ruler.behavior.r4.MeasureReportUser; @@ -48,9 +50,7 @@ import org.opencds.cqf.ruler.builder.NarrativeSettings; import org.opencds.cqf.ruler.cr.CrProperties; import org.opencds.cqf.ruler.provider.DaoRegistryOperationProvider; -import org.opencds.cqf.ruler.utility.Ids; import org.opencds.cqf.ruler.utility.Operations; -import org.opencds.cqf.ruler.utility.Resources; import org.opencds.cqf.ruler.utility.Searches; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,7 +64,7 @@ import ca.uhn.fhir.rest.api.server.RequestDetails; public class CareGapsProvider extends DaoRegistryOperationProvider - implements ParameterUser, ConfigurationUser, ResourceCreator, MeasureReportUser { + implements ParameterUser, ConfigurationUser, ResourceCreator, MeasureReportUser { private static final Logger ourLog = LoggerFactory.getLogger(CareGapsProvider.class); @Autowired @@ -75,27 +75,20 @@ public class CareGapsProvider extends DaoRegistryOperationProvider private Executor cqlExecutor; private final Map configuredResources = new HashMap<>(); private static final Pattern CARE_GAPS_STATUS = Pattern.compile("(open-gap|closed-gap|not-applicable)"); - private static final String CARE_GAPS_REPORT_PROFILE = - "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/indv-measurereport-deqm"; - private static final String CARE_GAPS_BUNDLE_PROFILE = - "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/gaps-bundle-deqm"; - private static final String CARE_GAPS_COMPOSITION_PROFILE = - "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/gaps-composition-deqm"; - private static final String CARE_GAPS_DETECTEDISSUE_PROFILE = - "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/gaps-detectedissue-deqm"; - private static final String CARE_GAPS_GAP_STATUS_EXTENSION = - "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/extension-gapStatus"; - private static final String CARE_GAPS_GAP_STATUS_SYSTEM = - "http://hl7.org/fhir/us/davinci-deqm/CodeSystem/gaps-status"; - public static final String CARE_GAPS_MEASUREREPORT_REPORTER_EXTENSION = - "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/extension-reporterGroup"; + private static final String CARE_GAPS_REPORT_PROFILE = "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/indv-measurereport-deqm"; + private static final String CARE_GAPS_BUNDLE_PROFILE = "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/gaps-bundle-deqm"; + private static final String CARE_GAPS_COMPOSITION_PROFILE = "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/gaps-composition-deqm"; + private static final String CARE_GAPS_DETECTEDISSUE_PROFILE = "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/gaps-detectedissue-deqm"; + private static final String CARE_GAPS_GAP_STATUS_EXTENSION = "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/extension-gapStatus"; + private static final String CARE_GAPS_GAP_STATUS_SYSTEM = "http://hl7.org/fhir/us/davinci-deqm/CodeSystem/gaps-status"; + public static final String CARE_GAPS_MEASUREREPORT_REPORTER_EXTENSION = "http://hl7.org/fhir/us/davinci-deqm/StructureDefinition/extension-reporterGroup"; private static final Map CARE_GAPS_CODES = ofEntries( - new AbstractMap.SimpleEntry<>("http://loinc.org/96315-7", - new CodeableConceptSettings().add( - "http://loinc.org", "96315-7", "Gaps in care report")), - new AbstractMap.SimpleEntry<>("http://terminology.hl7.org/CodeSystem/v3-ActCode/CAREGAP", - new CodeableConceptSettings().add( - "http://terminology.hl7.org/CodeSystem/v3-ActCode", "CAREGAP", "Care Gaps"))); + new AbstractMap.SimpleEntry<>("http://loinc.org/96315-7", + new CodeableConceptSettings().add( + "http://loinc.org", "96315-7", "Gaps in care report")), + new AbstractMap.SimpleEntry<>("http://terminology.hl7.org/CodeSystem/v3-ActCode/CAREGAP", + new CodeableConceptSettings().add( + "http://terminology.hl7.org/CodeSystem/v3-ActCode", "CAREGAP", "Care Gaps"))); public enum CareGapsStatusCode { OPEN_GAP("open-gap"), CLOSED_GAP("closed-gap"), NOT_APPLICABLE("not-applicable"); @@ -177,22 +170,21 @@ public String toDisplayString() { * @return Parameters of bundles of Care Gap Measure Reports */ @SuppressWarnings("squid:S00107") // warning for greater than 7 parameters - @Description(shortDefinition = "$care-gaps operation", - value = "Implements the $care-gaps operation found in the Da Vinci DEQM FHIR Implementation Guide which is an extension of the $care-gaps operation found in the FHIR Clinical Reasoning Module.") + @Description(shortDefinition = "$care-gaps operation", value = "Implements the $care-gaps operation found in the Da Vinci DEQM FHIR Implementation Guide which is an extension of the $care-gaps operation found in the FHIR Clinical Reasoning Module.") @Operation(name = "$care-gaps", idempotent = true, type = Measure.class) public Parameters careGapsReport( - RequestDetails theRequestDetails, - @OperationParam(name = "periodStart", typeName = "date") IPrimitiveType periodStart, - @OperationParam(name = "periodEnd", typeName = "date") IPrimitiveType periodEnd, - @OperationParam(name = "topic") List topic, - @OperationParam(name = "subject") String subject, - @OperationParam(name = "practitioner") String practitioner, - @OperationParam(name = "organization") String organization, - @OperationParam(name = "status") List status, - @OperationParam(name = "measureId") List measureId, - @OperationParam(name = "measureIdentifier") List measureIdentifier, - @OperationParam(name = "measureUrl") List measureUrl, - @OperationParam(name = "program") List program) { + RequestDetails theRequestDetails, + @OperationParam(name = "periodStart", typeName = "date") IPrimitiveType periodStart, + @OperationParam(name = "periodEnd", typeName = "date") IPrimitiveType periodEnd, + @OperationParam(name = "topic") List topic, + @OperationParam(name = "subject") String subject, + @OperationParam(name = "practitioner") String practitioner, + @OperationParam(name = "organization") String organization, + @OperationParam(name = "status") List status, + @OperationParam(name = "measureId") List measureId, + @OperationParam(name = "measureIdentifier") List measureIdentifier, + @OperationParam(name = "measureUrl") List measureUrl, + @OperationParam(name = "program") List program) { try { validateConfiguration(theRequestDetails); @@ -215,7 +207,7 @@ public Parameters careGapsReport( } else { // TODO: implement non subject parameters (practitioner and organization) return parameters(part("Unsupported configuration", - generateIssue("error", "Non subject parameters have not been implemented."))); + generateIssue("error", "Non subject parameters have not been implemented."))); } ensureSupplementalDataElementSearchParameter(theRequestDetails); @@ -223,28 +215,28 @@ public Parameters careGapsReport( Parameters result = initializeResult(); if (crProperties.getThreadedCareGapsEnabled()) { (patients) - .forEach( - patient -> futures.add(CompletableFuture.supplyAsync(() -> patientReports(theRequestDetails, - periodStart.getValueAsString(), periodEnd.getValueAsString(), patient, status, measures, - organization), cqlExecutor))); + .forEach( + patient -> futures.add(CompletableFuture.supplyAsync(() -> patientReports(theRequestDetails, + periodStart.getValueAsString(), periodEnd.getValueAsString(), patient, status, measures, + organization), cqlExecutor))); futures.forEach(x -> result.addParameter(x.join())); } else { (patients).forEach( - patient -> { - Parameters.ParametersParameterComponent patientParameter = patientReports(theRequestDetails, - periodStart.getValueAsString(), periodEnd.getValueAsString(), patient, status, measures, - organization); - if (patientParameter != null) { - result.addParameter(patientParameter); - } - }); + patient -> { + Parameters.ParametersParameterComponent patientParameter = patientReports(theRequestDetails, + periodStart.getValueAsString(), periodEnd.getValueAsString(), patient, status, measures, + organization); + if (patientParameter != null) { + result.addParameter(patientParameter); + } + }); } return result; } private T putConfiguredResource(Class theResourceClass, String theId, String theKey, - RequestDetails theRequestDetails) { + RequestDetails theRequestDetails) { T resource = search(theResourceClass, Searches.byId(theId), theRequestDetails).firstOrNull(); if (resource != null) { configuredResources.put(theKey, resource); @@ -255,24 +247,24 @@ private T putConfiguredResource(Class theResourceClass, @Override public void validateConfiguration(RequestDetails theRequestDetails) { checkNotNull(crProperties.getMeasureReport(), - "The measure_report setting is required for the $care-gaps operation."); + "The measure_report setting is required for the $care-gaps operation."); checkArgument(!Strings.isNullOrEmpty(crProperties.getMeasureReport().getReporter()), - "The measure_report.care_gaps_reporter setting is required for the $care-gaps operation."); + "The measure_report.care_gaps_reporter setting is required for the $care-gaps operation."); checkArgument(!Strings.isNullOrEmpty(crProperties.getMeasureReport().getCompositionAuthor()), - "The measure_report.care_gaps_composition_section_author setting is required for the $care-gaps operation."); + "The measure_report.care_gaps_composition_section_author setting is required for the $care-gaps operation."); Resource configuredReporter = putConfiguredResource(Organization.class, - crProperties.getMeasureReport().getReporter(), "care_gaps_reporter", theRequestDetails); + crProperties.getMeasureReport().getReporter(), "care_gaps_reporter", theRequestDetails); Resource configuredAuthor = putConfiguredResource(Organization.class, - crProperties.getMeasureReport().getCompositionAuthor(), "care_gaps_composition_section_author", - theRequestDetails); + crProperties.getMeasureReport().getCompositionAuthor(), "care_gaps_composition_section_author", + theRequestDetails); checkNotNull(configuredReporter, String.format( - "The %s Resource is configured as the measure_report.care_gaps_reporter but the Resource could not be read.", - crProperties.getMeasureReport().getReporter())); + "The %s Resource is configured as the measure_report.care_gaps_reporter but the Resource could not be read.", + crProperties.getMeasureReport().getReporter())); checkNotNull(configuredAuthor, String.format( - "The %s Resource is configured as the measure_report.care_gaps_composition_section_author but the Resource could not be read.", - crProperties.getMeasureReport().getCompositionAuthor())); + "The %s Resource is configured as the measure_report.care_gaps_composition_section_author but the Resource could not be read.", + crProperties.getMeasureReport().getCompositionAuthor())); } @SuppressWarnings("squid:S1192") // warning for using the same string value more than 5 times @@ -309,35 +301,35 @@ private Parameters initializeResult() { @SuppressWarnings("squid:S00107") // warning for greater than 7 parameters private Parameters.ParametersParameterComponent patientReports(RequestDetails requestDetails, String periodStart, - String periodEnd, Patient patient, List status, List measures, String organization) { + String periodEnd, Patient patient, List status, List measures, String organization) { // TODO: add organization to report, if it exists. Composition composition = getComposition(patient); List detectedIssues = new ArrayList<>(); Map evalPlusSDE = new HashMap<>(); List reports = getReports(requestDetails, periodStart, periodEnd, patient, status, measures, - composition, detectedIssues, evalPlusSDE); + composition, detectedIssues, evalPlusSDE); if (reports.isEmpty()) { return null; } return initializePatientParameter(patient).setResource( - addBundleEntries(requestDetails.getFhirServerBase(), composition, detectedIssues, reports, evalPlusSDE)); + addBundleEntries(requestDetails.getFhirServerBase(), composition, detectedIssues, reports, evalPlusSDE)); } @SuppressWarnings("squid:S00107") // warning for greater than 7 parameters private List getReports(RequestDetails requestDetails, String periodStart, String periodEnd, - Patient patient, List status, List measures, Composition composition, - List detectedIssues, Map evalPlusSDE) { + Patient patient, List status, List measures, Composition composition, + List detectedIssues, Map evalPlusSDE) { List reports = new ArrayList<>(); MeasureReport report; for (Measure measure : measures) { report = measureEvaluateProvider.evaluateMeasure(requestDetails, measure.getIdElement(), periodStart, - periodEnd, "patient", Ids.simple(patient), null, null, null, null, null); + periodEnd, "patient", Ids.simple(patient), null, null, null, null, null); if (!report.hasGroup()) { ourLog.info("Report does not include a group so skipping.\nSubject: {}\nMeasure: {}", - Ids.simple(patient), - Ids.simplePart(measure)); + Ids.simple(patient), + Ids.simplePart(measure)); continue; } @@ -377,14 +369,14 @@ private void initializeReport(MeasureReport report) { private Parameters.ParametersParameterComponent initializePatientParameter(Patient patient) { Parameters.ParametersParameterComponent patientParameter = Resources - .newBackboneElement(Parameters.ParametersParameterComponent.class) - .setName("return"); + .newBackboneElement(Parameters.ParametersParameterComponent.class) + .setName("return"); patientParameter.setId("subject-" + Ids.simplePart(patient)); return patientParameter; } private Bundle addBundleEntries(String serverBase, Composition composition, List detectedIssues, - List reports, Map evalPlusSDE) { + List reports, Map evalPlusSDE) { Bundle reportBundle = getBundle(); reportBundle.addEntry(getBundleEntry(serverBase, composition)); reports.forEach(report -> reportBundle.addEntry(getBundleEntry(serverBase, report))); @@ -398,14 +390,14 @@ private CareGapsStatusCode getGapStatus(Measure measure, MeasureReport report) { Pair inNumerator = new MutablePair<>("numerator", false); report.getGroup().forEach(group -> group.getPopulation().forEach(population -> { if (population.hasCode() - && population.getCode().hasCoding(MEASUREREPORT_MEASURE_POPULATION_SYSTEM, inNumerator.getKey()) - && population.getCount() == 1) { + && population.getCode().hasCoding(MEASUREREPORT_MEASURE_POPULATION_SYSTEM, inNumerator.getKey()) + && population.getCount() == 1) { inNumerator.setValue(true); } })); boolean isPositive = measure.getImprovementNotation().hasCoding(MEASUREREPORT_IMPROVEMENT_NOTATION_SYSTEM, - "increase"); + "increase"); if ((isPositive && !inNumerator.getValue()) || (!isPositive && inNumerator.getValue())) { return CareGapsStatusCode.OPEN_GAP; @@ -416,54 +408,54 @@ private CareGapsStatusCode getGapStatus(Measure measure, MeasureReport report) { private BundleEntryComponent getBundleEntry(String serverBase, Resource resource) { return new BundleEntryComponent().setResource(resource) - .setFullUrl(Operations.getFullUrl(serverBase, resource)); + .setFullUrl(Operations.getFullUrl(serverBase, resource)); } private Composition.SectionComponent getSection(Measure measure, MeasureReport report, DetectedIssue detectedIssue, - CareGapsStatusCode gapStatus) { + CareGapsStatusCode gapStatus) { String narrative = String.format(HTML_DIV_PARAGRAPH_CONTENT, - gapStatus == CareGapsStatusCode.CLOSED_GAP ? "No detected issues." - : String.format("Issues detected. See %s for details.", Ids.simple(detectedIssue))); + gapStatus == CareGapsStatusCode.CLOSED_GAP ? "No detected issues." + : String.format("Issues detected. See %s for details.", Ids.simple(detectedIssue))); return new CompositionSectionComponentBuilder<>(Composition.SectionComponent.class) - .withTitle(measure.hasTitle() ? measure.getTitle() : measure.getUrl()) - .withFocus(Ids.simple(report)) - .withText(new NarrativeSettings(narrative)) - .withEntry(Ids.simple(detectedIssue)) - .build(); + .withTitle(measure.hasTitle() ? measure.getTitle() : measure.getUrl()) + .withFocus(Ids.simple(report)) + .withText(new NarrativeSettings(narrative)) + .withEntry(Ids.simple(detectedIssue)) + .build(); } private Bundle getBundle() { return new BundleBuilder<>(Bundle.class) - .withProfile(CARE_GAPS_BUNDLE_PROFILE) - .withType(BundleType.DOCUMENT.toString()) - .build(); + .withProfile(CARE_GAPS_BUNDLE_PROFILE) + .withType(BundleType.DOCUMENT.toString()) + .build(); } private Composition getComposition(Patient patient) { return new CompositionBuilder<>(Composition.class) - .withProfile(CARE_GAPS_COMPOSITION_PROFILE) - .withType(CARE_GAPS_CODES.get("http://loinc.org/96315-7")) - .withStatus(Composition.CompositionStatus.FINAL.toString()) - .withTitle("Care Gap Report for " + Ids.simplePart(patient)) - .withSubject(Ids.simple(patient)) - .withAuthor(Ids.simple(configuredResources.get("care_gaps_composition_section_author"))) - // .withCustodian(organization) // TODO: Optional: identifies the organization - // who is responsible for ongoing maintenance of and accessing to this gaps in - // care report. Add as a setting and optionally read if it's there. - .build(); + .withProfile(CARE_GAPS_COMPOSITION_PROFILE) + .withType(CARE_GAPS_CODES.get("http://loinc.org/96315-7")) + .withStatus(Composition.CompositionStatus.FINAL.toString()) + .withTitle("Care Gap Report for " + Ids.simplePart(patient)) + .withSubject(Ids.simple(patient)) + .withAuthor(Ids.simple(configuredResources.get("care_gaps_composition_section_author"))) + // .withCustodian(organization) // TODO: Optional: identifies the organization + // who is responsible for ongoing maintenance of and accessing to this gaps in + // care report. Add as a setting and optionally read if it's there. + .build(); } private DetectedIssue getDetectedIssue(Patient patient, MeasureReport report, CareGapsStatusCode gapStatus) { return new DetectedIssueBuilder<>(DetectedIssue.class) - .withProfile(CARE_GAPS_DETECTEDISSUE_PROFILE) - .withStatus(DetectedIssue.DetectedIssueStatus.FINAL.toString()) - .withCode(CARE_GAPS_CODES.get("http://terminology.hl7.org/CodeSystem/v3-ActCode/CAREGAP")) - .withPatient(Ids.simple(patient)) - .withEvidenceDetail(Ids.simple(report)) - .withModifierExtension(new ImmutablePair<>( - CARE_GAPS_GAP_STATUS_EXTENSION, - new CodeableConceptSettings().add(CARE_GAPS_GAP_STATUS_SYSTEM, gapStatus.toString(), - gapStatus.toDisplayString()))) - .build(); + .withProfile(CARE_GAPS_DETECTEDISSUE_PROFILE) + .withStatus(DetectedIssue.DetectedIssueStatus.FINAL.toString()) + .withCode(CARE_GAPS_CODES.get("http://terminology.hl7.org/CodeSystem/v3-ActCode/CAREGAP")) + .withPatient(Ids.simple(patient)) + .withEvidenceDetail(Ids.simple(report)) + .withModifierExtension(new ImmutablePair<>( + CARE_GAPS_GAP_STATUS_EXTENSION, + new CodeableConceptSettings().add(CARE_GAPS_GAP_STATUS_SYSTEM, gapStatus.toString(), + gapStatus.toDisplayString()))) + .build(); } } 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 844eaea44..0eb04600f 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.parameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; import java.util.ArrayList; import java.util.List; @@ -33,11 +33,11 @@ public class CollectDataProvider extends DaoRegistryOperationProvider { * operation found in the * FHIR Clinical * Reasoning Module. - * + * *

* Returns a set of parameters with the generated MeasureReport and the * resources that were used during the Measure evaluation - * + * * @param theRequestDetails generally auto-populated by the HAPI server * framework. * @param theId the Id of the Measure to sub data for diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/DataOperationsProvider.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/DataOperationsProvider.java index 0f0751b08..39ba60219 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/DataOperationsProvider.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/DataOperationsProvider.java @@ -29,6 +29,9 @@ import org.opencds.cqf.cql.evaluator.cql2elm.util.LibraryVersionSelector; import org.opencds.cqf.cql.evaluator.fhir.adapter.AdapterFactory; import org.opencds.cqf.cql.evaluator.fhir.adapter.LibraryAdapter; +import org.opencds.cqf.cql.evaluator.fhir.util.Canonicals; +import org.opencds.cqf.cql.evaluator.fhir.util.Canonicals.CanonicalParts; +import org.opencds.cqf.cql.evaluator.fhir.util.Libraries; import org.opencds.cqf.ruler.cql.JpaLibrarySourceProvider; import org.opencds.cqf.ruler.cql.JpaLibrarySourceProviderFactory; import org.opencds.cqf.ruler.cql.JpaTerminologyProviderFactory; @@ -36,9 +39,6 @@ import org.opencds.cqf.ruler.cql.utility.Translators; import org.opencds.cqf.ruler.cr.utility.DataRequirements; import org.opencds.cqf.ruler.provider.DaoRegistryOperationProvider; -import org.opencds.cqf.ruler.utility.CanonicalParts; -import org.opencds.cqf.ruler.utility.Canonicals; -import org.opencds.cqf.ruler.utility.Libraries; import org.opencds.cqf.ruler.utility.Searches; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/PlanDefinitionApplyProvider.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/PlanDefinitionApplyProvider.java index fd885b3b4..5e6887c0a 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/PlanDefinitionApplyProvider.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/provider/PlanDefinitionApplyProvider.java @@ -25,6 +25,7 @@ import org.hl7.fhir.r4.model.StringType; import org.opencds.cqf.cql.engine.execution.Context; import org.opencds.cqf.cql.engine.runtime.DateTime; +import org.opencds.cqf.cql.evaluator.fhir.util.Canonicals; import org.opencds.cqf.ruler.api.OperationProvider; import org.opencds.cqf.ruler.cr.r4.ExpressionEvaluation; import org.opencds.cqf.ruler.cr.r4.builder.AttachmentBuilder; @@ -36,7 +37,6 @@ import org.opencds.cqf.ruler.cr.r4.builder.RequestGroupActionBuilder; import org.opencds.cqf.ruler.cr.r4.builder.RequestGroupBuilder; import org.opencds.cqf.ruler.cr.r4.helper.ContainedHelper; -import org.opencds.cqf.ruler.utility.Canonicals; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -187,7 +187,8 @@ private Resource resolveDefinition(Session session, PlanDefinition.PlanDefinitio result = this.activityDefinitionApplyProvider.resolveActivityDefinition( (ActivityDefinition) resolveContained(session.getPlanDefinition(), action.getDefinitionCanonicalType().getValue()), - session.getPatientId(), session.getPractitionerId(), session.getOrganizationId(), theRequest); + session.getPatientId(), session.getPractitionerId(), session.getOrganizationId(), + theRequest); } else { result = this.activityDefinitionApplyProvider.apply( theRequest, new IdType(Canonicals.getIdPart(action.getDefinitionCanonicalType())), @@ -252,7 +253,8 @@ else if (result instanceof String) { (Base) result); } catch (Exception e) { throw new RuntimeException( - String.format("Could not set path %s to value: %s", dynamicValue.getPath(), result)); + String.format("Could not set path %s to value: %s", dynamicValue.getPath(), + result)); } } } @@ -297,10 +299,12 @@ private Boolean meetsConditions(Session session, PlanDefinition.PlanDefinitionAc Object result; if (language.equals("text/cql.identifier") || language.equals("text/cql-identifier") || language.equals("text/cql.name") || language.equals("text/cql-name")) { - result = expressionEvaluation.evaluateInContext(session.getPlanDefinition(), cql, session.getPatientId(), + result = expressionEvaluation.evaluateInContext(session.getPlanDefinition(), cql, + session.getPatientId(), true, theRequest); } else { - result = expressionEvaluation.evaluateInContext(session.getPlanDefinition(), cql, session.getPatientId(), + result = expressionEvaluation.evaluateInContext(session.getPlanDefinition(), cql, + session.getPatientId(), theRequest); } @@ -433,7 +437,8 @@ private void resolveActions(List a } try { this.activityDefinitionApplyProvider - .apply(theRequest, new IdType(action.getDefinitionCanonicalType().getId()), patientId, + .apply(theRequest, new IdType(action.getDefinitionCanonicalType().getId()), + patientId, null, null, null, null, null, null, null, null) .setId(UUID.randomUUID().toString()); diff --git a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/service/MeasureService.java b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/service/MeasureService.java index 092ebd779..7a1b84b1f 100644 --- a/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/service/MeasureService.java +++ b/plugin/cr/src/main/java/org/opencds/cqf/ruler/cr/r4/service/MeasureService.java @@ -16,13 +16,13 @@ import org.opencds.cqf.cql.evaluator.CqlOptions; import org.opencds.cqf.cql.evaluator.builder.DataProviderFactory; import org.opencds.cqf.cql.evaluator.fhir.dal.FhirDal; +import org.opencds.cqf.cql.evaluator.fhir.util.Clients; import org.opencds.cqf.cql.evaluator.measure.MeasureEvaluationOptions; import org.opencds.cqf.ruler.behavior.r4.MeasureReportUser; import org.opencds.cqf.ruler.cql.JpaDataProviderFactory; import org.opencds.cqf.ruler.cql.JpaFhirDalFactory; import org.opencds.cqf.ruler.cql.JpaLibrarySourceProviderFactory; import org.opencds.cqf.ruler.cql.JpaTerminologyProviderFactory; -import org.opencds.cqf.ruler.utility.Clients; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; @@ -97,7 +97,8 @@ public MeasureReport evaluateMeasure(IdType theId, FhirDal fhirDal = this.fhirDalFactory.create(requestDetails); org.opencds.cqf.cql.evaluator.measure.r4.R4MeasureProcessor measureProcessor = new org.opencds.cqf.cql.evaluator.measure.r4.R4MeasureProcessor( - null, this.dataProviderFactory, null, null, null, terminologyProvider, libraryContentProvider, dataProvider, + null, this.dataProviderFactory, null, null, null, terminologyProvider, libraryContentProvider, + dataProvider, fhirDal, measureEvaluationOptions, cqlOptions, this.globalLibraryCache); 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 1f1ba1d14..b14f82247 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,7 +1,7 @@ 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 static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.getPartsByName; import java.util.List; @@ -14,12 +14,12 @@ import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Reference; import org.junit.jupiter.api.Test; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; import org.opencds.cqf.ruler.cr.CqlBuilder; import org.opencds.cqf.ruler.cr.dstu3.Libraries; import org.opencds.cqf.ruler.cr.dstu3.MeasureBuilder; import org.opencds.cqf.ruler.cr.dstu3.Patients; import org.opencds.cqf.ruler.test.DaoIntegrationTest; -import org.opencds.cqf.ruler.utility.Ids; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -54,11 +54,11 @@ void testCollectData() { this.create(john); Observation obs = newResource(Observation.class) - .setSubject(new Reference(john)); + .setSubject(new Reference(john)); this.create(obs); Encounter enc = newResource(Encounter.class) - .setSubject(new Reference(john)); + .setSubject(new Reference(john)); this.create(enc); // Submit it 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 bfae1eaa9..c1d9f7cf8 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,8 +1,8 @@ package org.opencds.cqf.ruler.cr.dstu3.provider; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.parameters; -import static org.opencds.cqf.ruler.utility.dstu3.Parameters.stringPart; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.stringPart; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Library; 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 62805acd5..27fa8c292 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,9 +1,9 @@ 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 static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.dstu3.Parameters.stringPart; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Endpoint; @@ -16,9 +16,8 @@ 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" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { MeasureEvaluateProviderIT.class, + CrConfig.class, CqlConfig.class }, properties = { "hapi.fhir.fhir_version=dstu3" }) class MeasureEvaluateProviderIT extends RestIntegrationTest { @Test @@ -30,8 +29,7 @@ void testMeasureEvaluate() { stringPart("periodEnd", "2020-01-01"), stringPart("reportType", "individual"), stringPart("subject", "Patient/denom-EXM105-FHIR3"), - stringPart("lastReceivedOn", "2019-12-12") - ); + stringPart("lastReceivedOn", "2019-12-12")); MeasureReport returnMeasureReport = getClient().operation() .onInstance(new IdType("Measure", "measure-EXM105-FHIR3-8.0.000")) @@ -56,8 +54,7 @@ void testMeasureEvaluateWithTerminology() { stringPart("reportType", "individual"), stringPart("subject", "Patient/denom-EXM105-FHIR3"), stringPart("lastReceivedOn", "2019-12-12"), - part("terminologyEndpoint", terminologyEndpoint) - ); + part("terminologyEndpoint", terminologyEndpoint)); MeasureReport returnMeasureReport = getClient().operation() .onInstance(new IdType("Measure", "measure-EXM105-FHIR3-8.0.000")) @@ -80,8 +77,7 @@ void testMeasureEvaluateWithAdditionalData() { stringPart("reportType", "individual"), stringPart("subject", "Patient/denom-EXM105-FHIR3"), stringPart("lastReceivedOn", "2019-12-12"), - part("additionalData", additionalData) - ); + 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/SubmitDataProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/dstu3/provider/SubmitDataProviderIT.java index 22e250887..a2f6c5a01 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 @@ -3,8 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import com.google.common.collect.Lists; - import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.MeasureReport; import org.hl7.fhir.dstu3.model.Observation; @@ -16,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import com.google.common.collect.Lists; + import ca.uhn.fhir.jpa.partition.SystemRequestDetails; @SpringBootTest(classes = { SubmitDataProviderIT.class }, properties = { "hapi.fhir.fhir_version=dstu3", }) 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 4f47c8ef6..a2c17ab1f 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 @@ -4,9 +4,9 @@ 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.datePart; -import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.datePart; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.stringPart; import org.hl7.fhir.r4.model.Measure; import org.hl7.fhir.r4.model.Parameters; 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 346a8203a..e3ea4ea12 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 @@ -13,13 +13,13 @@ import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Reference; import org.junit.jupiter.api.Test; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; import org.opencds.cqf.ruler.cr.CqlBuilder; import org.opencds.cqf.ruler.cr.CrConfig; import org.opencds.cqf.ruler.cr.r4.Libraries; import org.opencds.cqf.ruler.cr.r4.MeasureBuilder; import org.opencds.cqf.ruler.cr.r4.Patients; import org.opencds.cqf.ruler.test.DaoIntegrationTest; -import org.opencds.cqf.ruler.utility.Ids; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -66,13 +66,15 @@ 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.r4.Parameters.getPartsByName(results, - "resource"); + List resources = org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters + .getPartsByName(results, + "resource"); assertEquals(1, resources.size()); assertEquals("Observation", resources.get(0).getResource().fhirType()); - List reports = org.opencds.cqf.ruler.utility.r4.Parameters.getPartsByName(results, - "measureReport"); + List reports = org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters + .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/r4/provider/DataOperationProviderIT.java b/plugin/cr/src/test/java/org/opencds/cqf/ruler/cr/r4/provider/DataOperationProviderIT.java index b897723b6..f9e3c3a3d 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,5 +1,11 @@ package org.opencds.cqf.ruler.cr.r4.provider; +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.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.stringPart; + import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.DataRequirement; import org.hl7.fhir.r4.model.IdType; @@ -10,14 +16,8 @@ import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.springframework.boot.test.context.SpringBootTest; -import static org.junit.jupiter.api.Assertions.*; -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" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { DataOperationProviderIT.class, + CrConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) class DataOperationProviderIT extends RestIntegrationTest { @Test @@ -27,20 +27,20 @@ void testR4LibraryDataRequirementsOperation() { Parameters params = parameters(stringPart("target", "dummy")); Library returnLibrary = getClient().operation() - .onInstance(new IdType("Library", "LibraryEvaluationTest")) - .named("$data-requirements") - .withParameters(params) - .returnResourceType(Library.class) - .execute(); + .onInstance(new IdType("Library", "LibraryEvaluationTest")) + .named("$data-requirements") + .withParameters(params) + .returnResourceType(Library.class) + .execute(); assertNotNull(returnLibrary); Library returnLibrary2 = getClient().operation() - .onInstance(new IdType("Library", "pertinencetag")) - .named("$data-requirements") - .withParameters(params) - .returnResourceType(Library.class) - .execute(); + .onInstance(new IdType("Library", "pertinencetag")) + .named("$data-requirements") + .withParameters(params) + .returnResourceType(Library.class) + .execute(); assertNotNull(returnLibrary2); assertNotNull(returnLibrary2.getDataRequirement().get(1).getExtensionByUrl( @@ -54,43 +54,42 @@ void testR4LibraryDataRequirementsNonManifestMultiVersionOperation() { Library library = getClient().read().resource(Library.class).withId("LibraryEvaluationTest").execute(); assertNotNull(library); assertEquals("http://fhir.org/guides/cqf/common/Library/LibraryEvaluationTestDependency|1.0.000", - library.getRelatedArtifact().get(0).getResource()); + library.getRelatedArtifact().get(0).getResource()); Library library2 = getClient().read().resource(Library.class).withId("LibraryEvaluationTest2").execute(); assertNotNull(library2); assertEquals("http://fhir.org/guides/cqf/common/Library/LibraryEvaluationTestDependency", - library2.getRelatedArtifact().get(0).getResource()); + library2.getRelatedArtifact().get(0).getResource()); assertEquals(library.getUrl(), library2.getUrl()); Parameters params = parameters(stringPart("target", "dummy")); Library returnLibrary1 = getClient().operation() - .onInstance(new IdType("Library", "LibraryEvaluationTest")) - .named("$data-requirements") - .withParameters(params) - .returnResourceType(Library.class) - .execute(); + .onInstance(new IdType("Library", "LibraryEvaluationTest")) + .named("$data-requirements") + .withParameters(params) + .returnResourceType(Library.class) + .execute(); assertNotNull(returnLibrary1); assertTrue(returnLibrary1.getRelatedArtifact().stream().anyMatch( - x -> (x.getType().toString().equals("DEPENDSON") && - x.getResource().equals("Library/LibraryEvaluationTestDependency|1.0.000")))); - + x -> (x.getType().toString().equals("DEPENDSON") && + x.getResource().equals("Library/LibraryEvaluationTestDependency|1.0.000")))); Library returnLibrary2 = getClient().operation() - .onInstance(new IdType("Library", "LibraryEvaluationTest2")) - .named("$data-requirements") - .withParameters(params) - .returnResourceType(Library.class) - .execute(); + .onInstance(new IdType("Library", "LibraryEvaluationTest2")) + .named("$data-requirements") + .withParameters(params) + .returnResourceType(Library.class) + .execute(); assertNotNull(returnLibrary2); assertTrue(returnLibrary2.getRelatedArtifact().stream().anyMatch( - x -> (x.getType().toString().equals("DEPENDSON") && - x.getResource().equals("Library/LibraryEvaluationTestDependency|2.0.000")))); + x -> (x.getType().toString().equals("DEPENDSON") && + x.getResource().equals("Library/LibraryEvaluationTestDependency|2.0.000")))); } @Test @@ -116,28 +115,31 @@ void testR4LibraryFhirQueryPattern() { .getValueAsPrimitive().getValueAsString(); assertEquals("Patient?_id={{context.patientId}}", query); } - break; + break; case "Encounter": { String query = dr.getExtensionByUrl( "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern") .getValueAsPrimitive().getValueAsString(); if (dr.hasCodeFilter()) { - 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 { + 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 { assertEquals("Encounter?subject=Patient/{{context.patientId}}", query); } } - break; + break; case "Coverage": { 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); + 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; + break; } } } @@ -147,8 +149,8 @@ void testR4MeasureDataRequirementsOperation() { loadTransaction("Exm104FhirR4MeasureBundle.json"); Parameters params = parameters( - stringPart("startPeriod", "2019-01-01"), - stringPart("endPeriod", "2020-01-01")); + stringPart("startPeriod", "2019-01-01"), + stringPart("endPeriod", "2020-01-01")); Library returnLibrary = getClient().operation() .onInstance(new IdType("Measure", "measure-EXM104-8.2.000")) @@ -165,8 +167,8 @@ void testR4MeasureFhirQueryPattern() { loadTransaction("ExmLogicMeasureTransactionBundle.json"); Parameters params = parameters( - stringPart("startPeriod", "2019-01-01"), - stringPart("endPeriod", "2020-01-01")); + stringPart("startPeriod", "2019-01-01"), + stringPart("endPeriod", "2020-01-01")); Library returnLibrary = getClient().operation() .onInstance(new IdType("Measure", "measure-exm")) @@ -185,28 +187,31 @@ void testR4MeasureFhirQueryPattern() { .getValueAsPrimitive().getValueAsString(); assertEquals("Patient?_id={{context.patientId}}", query); } - break; + break; case "Encounter": { String query = dr.getExtensionByUrl( "http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-fhirQueryPattern") .getValueAsPrimitive().getValueAsString(); if (dr.hasCodeFilter()) { - 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 { + 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 { assertEquals("Encounter?subject=Patient/{{context.patientId}}", query); } } - break; + break; case "Coverage": { 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); + 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; + break; } } } @@ -214,7 +219,7 @@ void testR4MeasureFhirQueryPattern() { @Test void testR4LibraryEvaluationTest() { String bundleAsText = stringFromResource("bundlegen-bundle.json"); - Bundle bundle = (Bundle)getFhirContext().newJsonParser().parseResource(bundleAsText); + Bundle bundle = (Bundle) getFhirContext().newJsonParser().parseResource(bundleAsText); getClient().transaction().withBundle(bundle).execute(); loadTransaction("bundlegen-bundle.json"); @@ -237,27 +242,28 @@ void testR4LibraryEvaluationTest() { case "Patient": { assertEquals("Patient?_id={{context.patientId}}", query); } - break; + break; case "Condition": { if (dr.hasCodeFilter() && dr.getCodeFilter().size() > 0) { - assertEquals("Condition?category:in=http://mcg.com/fhir/ValueSet/condition-problem-list-category&subject=Patient/{{context.patientId}}", query); - } - else { + assertEquals( + "Condition?category:in=http://mcg.com/fhir/ValueSet/condition-problem-list-category&subject=Patient/{{context.patientId}}", + query); + } else { assertEquals("Condition?subject=Patient/{{context.patientId}}", query); } } - break; + break; case "Encounter": { assertEquals("Encounter?subject=Patient/{{context.patientId}}", query); } - break; + break; case "Procedure": { assertEquals("Procedure?subject=Patient/{{context.patientId}}", query); } - break; + 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 1b41b1ad0..e46ba7128 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,9 +1,9 @@ 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 static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.stringPart; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.IdType; @@ -74,8 +74,7 @@ void testMeasureEvaluateWithAdditionalData() { stringPart("reportType", "subject"), stringPart("subject", "Patient/numer-EXM104"), stringPart("lastReceivedOn", "2019-12-12"), - part("additionalData", additionalData) - ); + 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 36ccdbcd9..e459f8a56 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,9 +4,9 @@ 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.parameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.part; -import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.stringPart; import java.util.Optional; @@ -153,7 +153,8 @@ private void runWithPatient(String measureId, String patientId, int initialPopul enrolledDuringParticipationPeriodObs.getValueCodeableConcept().getCodingFirstRep().getCode()); assertNotNull(participationPeriodObs); - assertEquals(participationPeriod, participationPeriodObs.getValueCodeableConcept().getCodingFirstRep().getCode()); + assertEquals(participationPeriod, + participationPeriodObs.getValueCodeableConcept().getCodingFirstRep().getCode()); } @Test @@ -204,7 +205,8 @@ void testClientNonPatientBasedMeasureEvaluate() { && x.getCode().getCoding().get(0).getCode().equals(populationName)) .findFirst(); - assertTrue(population.isPresent(), String.format("Unable to locate a population with id \"%s\"", populationName)); + assertTrue(population.isPresent(), + String.format("Unable to locate a population with id \"%s\"", populationName)); assertEquals(population.get().getCount(), expectedCount, String.format("expected count for population \"%s\" did not match", populationName)); } 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 9ce48a006..2fbfad915 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 @@ -3,8 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import com.google.common.collect.Lists; - import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.MeasureReport; import org.hl7.fhir.r4.model.Observation; @@ -15,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import com.google.common.collect.Lists; + import ca.uhn.fhir.jpa.partition.SystemRequestDetails; @SpringBootTest(classes = { SubmitDataProviderIT.class }, properties = { "hapi.fhir.fhir_version=r4", }) diff --git a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProvider.java b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProvider.java index 2a917a567..e4568b65f 100644 --- a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProvider.java +++ b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/dstu3/CacheValueSetsProvider.java @@ -13,8 +13,8 @@ import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.Resource; import org.hl7.fhir.dstu3.model.ValueSet; +import org.opencds.cqf.cql.evaluator.fhir.util.Clients; import org.opencds.cqf.ruler.api.OperationProvider; -import org.opencds.cqf.ruler.utility.Clients; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.context.FhirContext; @@ -51,7 +51,7 @@ public class CacheValueSetsProvider implements OperationProvider { * any {@link ValueSet Valueset} listed given the {@link Endpoint Endpoint} * provided. * Any Valuesets that require expansion will be expanded. - * + * * @param details the {@link RequestDetails RequestDetails} * @param endpointId the {@link Endpoint Endpoint} id * @param valuesets the {@link StringAndListParam list} of {@link ValueSet diff --git a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemUpdateProvider.java b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemUpdateProvider.java index 1b1d784c5..ff2697bea 100644 --- a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemUpdateProvider.java +++ b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/dstu3/CodeSystemUpdateProvider.java @@ -18,8 +18,8 @@ import org.hl7.fhir.dstu3.model.OperationOutcome; import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IIdType; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; import org.opencds.cqf.ruler.api.OperationProvider; -import org.opencds.cqf.ruler.utility.Ids; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem; @@ -95,7 +95,8 @@ public OperationOutcome updateCodeSystems(@IdParam IdType theId) { return buildIssue(response, "error", "not-found", "Unable to find Resource: " + theId.getIdPart()); } } catch (Exception e) { - return buildIssue(response, "error", "not-found", "Unable to find Resource: " + theId.getIdPart() + "\n" + e); + return buildIssue(response, "error", "not-found", + "Unable to find Resource: " + theId.getIdPart() + "\n" + e); } return performCodeSystemUpdate(Collections.singletonList(vs)); diff --git a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProvider.java b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProvider.java index 177dcb44a..e302b9201 100644 --- a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProvider.java +++ b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/r4/CacheValueSetsProvider.java @@ -13,8 +13,8 @@ import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Resource; import org.hl7.fhir.r4.model.ValueSet; +import org.opencds.cqf.cql.evaluator.fhir.util.Clients; import org.opencds.cqf.ruler.api.OperationProvider; -import org.opencds.cqf.ruler.utility.Clients; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.context.FhirContext; @@ -51,7 +51,7 @@ public class CacheValueSetsProvider implements OperationProvider { * any {@link ValueSet Valueset} listed given the {@link Endpoint Endpoint} * provided. * Any Valuesets that require expansion will be expanded. - * + * * @param details the {@link RequestDetails RequestDetails} * @param endpointId the {@link Endpoint Endpoint} id * @param valuesets the {@link StringAndListParam list} of {@link ValueSet diff --git a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemUpdateProvider.java b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemUpdateProvider.java index 6e5c903dd..4d2394344 100644 --- a/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemUpdateProvider.java +++ b/plugin/dev-tools/src/main/java/org/opencds/cqf/ruler/devtools/r4/CodeSystemUpdateProvider.java @@ -18,8 +18,8 @@ import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.OperationOutcome; import org.hl7.fhir.r4.model.ValueSet; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; import org.opencds.cqf.ruler.api.OperationProvider; -import org.opencds.cqf.ruler.utility.Ids; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDaoCodeSystem; @@ -95,7 +95,8 @@ public OperationOutcome updateCodeSystems(@IdParam IdType theId) { return buildIssue(response, "error", "not-found", "Unable to find Resource: " + theId.getIdPart()); } } catch (Exception e) { - return buildIssue(response, "error", "not-found", "Unable to find Resource: " + theId.getIdPart() + "\n" + e); + return buildIssue(response, "error", "not-found", + "Unable to find Resource: " + theId.getIdPart() + "\n" + e); } return performCodeSystemUpdate(Collections.singletonList(vs)); 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 86681d5c4..3b9b3ae65 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 @@ -33,10 +33,8 @@ 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) class CodeSystemProviderIT extends RestIntegrationTest { private final Logger log = LoggerFactory.getLogger(CodeSystemProviderIT.class); @@ -57,12 +55,14 @@ void tearDown() { @Test @Order(1) void testCodeSystemUpdateValueSetDNE() { - ValueSet vs = (ValueSet) readResource("org/opencds/cqf/ruler/devtools/dstu3/valueset/AntithromboticTherapy.json"); + ValueSet vs = (ValueSet) readResource( + "org/opencds/cqf/ruler/devtools/dstu3/valueset/AntithromboticTherapy.json"); OperationOutcome outcome = codeSystemUpdateProvider.updateCodeSystems(vs.getIdElement()); assertEquals(1, outcome.getIssue().size()); OperationOutcomeIssueComponent issue = outcome.getIssue().get(0); assertEquals(OperationOutcome.IssueSeverity.ERROR, issue.getSeverity()); - assertTrue(issue.getDetails().getText().startsWith("Unable to find Resource: " + vs.getIdElement().getIdPart())); + assertTrue( + issue.getDetails().getText().startsWith("Unable to find Resource: " + vs.getIdElement().getIdPart())); } @Test @@ -79,7 +79,8 @@ void testCodeSystemUpdateValueSetIdNull() { @Order(3) void testDSTU3RxNormCodeSystemUpdateById() { log.info("Beginning Test DSTU3 RxNorm CodeSystemUpdate"); - ValueSet vs = (ValueSet) loadResource("org/opencds/cqf/ruler/devtools/dstu3/valueset/AntithromboticTherapy.json"); + ValueSet vs = (ValueSet) loadResource( + "org/opencds/cqf/ruler/devtools/dstu3/valueset/AntithromboticTherapy.json"); assertEquals(0, performCodeSystemSearchByUrl(rxNormUrl).size()); OperationOutcome outcome = codeSystemUpdateProvider.updateCodeSystems(vs.getIdElement()); 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 2405a1738..f6caa442b 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 @@ -61,7 +61,8 @@ void testCodeSystemUpdateValueSetDNE() { assertEquals(1, outcome.getIssue().size()); OperationOutcomeIssueComponent issue = outcome.getIssue().get(0); assertEquals(OperationOutcome.IssueSeverity.ERROR, issue.getSeverity()); - assertTrue(issue.getDetails().getText().startsWith("Unable to find Resource: " + vs.getIdElement().getIdPart())); + assertTrue( + issue.getDetails().getText().startsWith("Unable to find Resource: " + vs.getIdElement().getIdPart())); } @Test @@ -99,7 +100,8 @@ void testR4ICD10PerformCodeSystemUpdateByList() throws IOException { log.info("Beginning Test R4 SNOMED CodeSystemUpdate"); BufferedReader reader = new BufferedReader(new InputStreamReader( - Objects.requireNonNull(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); diff --git a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RACodingGapsProvider.java b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RACodingGapsProvider.java index f46bdebac..48541eade 100644 --- a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RACodingGapsProvider.java +++ b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RACodingGapsProvider.java @@ -1,14 +1,13 @@ package org.opencds.cqf.ruler.ra.r4; import static com.google.common.base.Preconditions.checkArgument; -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.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; import java.util.Date; import java.util.List; import java.util.UUID; -import com.google.common.base.Strings; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.r4.model.Bundle; @@ -19,23 +18,24 @@ import org.hl7.fhir.r4.model.Parameters; import org.opencds.cqf.ruler.behavior.ConfigurationUser; import org.opencds.cqf.ruler.behavior.ResourceCreator; -import org.opencds.cqf.ruler.behavior.r4.MeasureReportUser; import org.opencds.cqf.ruler.behavior.r4.ParameterUser; import org.opencds.cqf.ruler.provider.DaoRegistryOperationProvider; import org.opencds.cqf.ruler.ra.RAConstants; import org.opencds.cqf.ruler.ra.RAProperties; import org.opencds.cqf.ruler.utility.Operations; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Configurable; + +import com.google.common.base.Strings; import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.api.server.RequestDetails; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Configurable; @Configurable public class RACodingGapsProvider extends DaoRegistryOperationProvider - implements ParameterUser, ConfigurationUser, ResourceCreator, MeasureReportUser, RiskAdjustmentUser { + implements ParameterUser, ConfigurationUser, ResourceCreator, RiskAdjustmentUser { @Autowired private RAProperties raProperties; @@ -86,14 +86,17 @@ public Parameters raCodingGaps( getPatientListFromSubject(subject).forEach( patient -> { List reports = getMeasureReports( - patient.getIdElement().getIdPart(), periodStart.getValueAsString(), periodEnd.getValueAsString()); + patient.getIdElement().getIdPart(), periodStart.getValueAsString(), + periodEnd.getValueAsString()); if (reports.isEmpty()) { result.addParameter(part( - RAConstants.RETURN_PARAM_NAME, buildMissingMeasureReportCodingGapReportBundle(patient))); + RAConstants.RETURN_PARAM_NAME, + buildMissingMeasureReportCodingGapReportBundle(patient))); } else { reports.forEach(report -> { List issues = buildOriginalIssues(report); - Composition composition = buildComposition(subject, report, issues, compositionSectionAuthor); + Composition composition = buildComposition(subject, report, issues, + compositionSectionAuthor); Bundle bundle = buildCodingGapReportBundle(composition, issues, report); result.addParameter(part(RAConstants.RETURN_PARAM_NAME, bundle.setId(UUID.randomUUID().toString()))); @@ -116,9 +119,10 @@ public void validateParameters(RequestDetails requestDetails) { @Override public void validateConfiguration(RequestDetails theRequestDetails) { checkArgument(!Strings.isNullOrEmpty(raProperties.getComposition().getCompositionSectionAuthor()), - "The composition.ra_composition_section_author setting is required for the $ra.coding-gaps operation."); + "The composition.ra_composition_section_author setting is required for the $ra.coding-gaps operation."); compositionSectionAuthor = new IdType(raProperties.getComposition().getCompositionSectionAuthor()); - // This will throw a ResourceNotFound exception if the Organization resource is not loaded in the server + // This will throw a ResourceNotFound exception if the Organization resource is + // not loaded in the server read(compositionSectionAuthor); } } diff --git a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RemediateProvider.java b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RemediateProvider.java index a529e9bae..71b300d4f 100644 --- a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RemediateProvider.java +++ b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RemediateProvider.java @@ -1,8 +1,13 @@ package org.opencds.cqf.ruler.ra.r4; -import ca.uhn.fhir.rest.annotation.Operation; -import ca.uhn.fhir.rest.annotation.OperationParam; -import ca.uhn.fhir.rest.api.server.RequestDetails; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.UUID; + import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Composition; @@ -14,42 +19,38 @@ import org.opencds.cqf.ruler.ra.RAConstants; import org.opencds.cqf.ruler.utility.Operations; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.UUID; - -import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.part; +import ca.uhn.fhir.rest.annotation.Operation; +import ca.uhn.fhir.rest.annotation.OperationParam; +import ca.uhn.fhir.rest.api.server.RequestDetails; public class RemediateProvider extends DaoRegistryOperationProvider implements RiskAdjustmentUser, ParameterUser { @Operation(name = "$ra.remediate-coding-gaps", idempotent = true, type = MeasureReport.class) public Parameters remediate( - RequestDetails requestDetails, - @OperationParam(name = RAConstants.PERIOD_START, typeName = "date") IPrimitiveType periodStart, - @OperationParam(name = RAConstants.PERIOD_END, typeName = "date") IPrimitiveType periodEnd, - @OperationParam(name = RAConstants.SUBJECT) String subject) { + RequestDetails requestDetails, + @OperationParam(name = RAConstants.PERIOD_START, typeName = "date") IPrimitiveType periodStart, + @OperationParam(name = RAConstants.PERIOD_END, typeName = "date") IPrimitiveType periodEnd, + @OperationParam(name = RAConstants.SUBJECT) String subject) { try { validateParameters(requestDetails); } catch (Exception e) { return parameters(part(RAConstants.INVALID_PARAMETERS_NAME, - generateIssue(RAConstants.INVALID_PARAMETERS_SEVERITY, e.getMessage()))); + generateIssue(RAConstants.INVALID_PARAMETERS_SEVERITY, e.getMessage()))); } List codingGapReportBundles = new ArrayList<>(); getPatientListFromSubject(subject).forEach( - patient -> { - Bundle b = getMostRecentCodingGapReportBundle(subject, periodStart.getValue(), periodEnd.getValue()); - MeasureReport mr = getReportFromBundle(b); - Composition composition = getCompositionFromBundle(b); - List issues = getIssuesFromBundle(b); - issues.addAll(getAssociatedIssues(mr.getIdElement().getValue())); - updateComposition(composition, mr, issues); - codingGapReportBundles.add(buildCodingGapReportBundle(composition, issues, mr)); - } - ); + patient -> { + Bundle b = getMostRecentCodingGapReportBundle(subject, periodStart.getValue(), + periodEnd.getValue()); + MeasureReport mr = getReportFromBundle(b); + Composition composition = getCompositionFromBundle(b); + List issues = getIssuesFromBundle(b); + issues.addAll(getAssociatedIssues(mr.getIdElement().getValue())); + updateComposition(composition, mr, issues); + codingGapReportBundles.add(buildCodingGapReportBundle(composition, issues, mr)); + }); Parameters result = new Parameters(); result.setId(RAConstants.REMEDIATE_ID_PREFIX + UUID.randomUUID()); @@ -67,6 +68,6 @@ public void validateParameters(RequestDetails requestDetails) { Operations.validateCardinality(requestDetails, RAConstants.SUBJECT, 1); Operations.validatePeriod(requestDetails, RAConstants.PERIOD_START, RAConstants.PERIOD_END); Operations.validateSingularPattern(requestDetails, RAConstants.SUBJECT, - Operations.PATIENT_OR_GROUP_REFERENCE); + Operations.PATIENT_OR_GROUP_REFERENCE); } } 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 aedd673c1..ab643fe0e 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,5 +1,8 @@ package org.opencds.cqf.ruler.ra.r4; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; + import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -32,9 +35,6 @@ import ca.uhn.fhir.rest.annotation.OperationParam; 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 { @@ -52,11 +52,11 @@ public class RiskAdjustmentProvider extends DaoRegistryOperationProvider impleme @Operation(name = "$davinci-ra.evaluate-measure", idempotent = true, type = Measure.class) public Parameters evaluateRiskConditionCategory( - RequestDetails requestDetails, - @IdParam IdType theId, - @OperationParam(name = RAConstants.PERIOD_START, typeName = "date") IPrimitiveType periodStart, - @OperationParam(name = RAConstants.PERIOD_END, typeName = "date") IPrimitiveType periodEnd, - @OperationParam(name = RAConstants.SUBJECT) String subject) { + RequestDetails requestDetails, + @IdParam IdType theId, + @OperationParam(name = RAConstants.PERIOD_START, typeName = "date") IPrimitiveType periodStart, + @OperationParam(name = RAConstants.PERIOD_END, typeName = "date") IPrimitiveType periodEnd, + @OperationParam(name = RAConstants.SUBJECT) String subject) { try { Operations.validateCardinality(requestDetails, RAConstants.PERIOD_START, 1); @@ -64,29 +64,30 @@ public Parameters evaluateRiskConditionCategory( Operations.validateCardinality(requestDetails, RAConstants.SUBJECT, 1); } catch (Exception e) { return parameters(part(RAConstants.INVALID_PARAMETERS_NAME, - generateIssue(RAConstants.INVALID_PARAMETERS_SEVERITY, e.getMessage()))); + generateIssue(RAConstants.INVALID_PARAMETERS_SEVERITY, e.getMessage()))); } ensureSupplementalDataElementSearchParameter(requestDetails); MeasureReport unprocessedReport = measureEvaluateProvider.evaluateMeasure(requestDetails, - theId, periodStart.getValueAsString(), periodEnd.getValueAsString(), null, subject, - null, null, null, null, null); + theId, periodStart.getValueAsString(), periodEnd.getValueAsString(), null, subject, + null, null, null, null, null); Parameters riskAdjustmentParameters = new Parameters(); RiskAdjustmentReturnElement riskAdjustmentReturnElement = new RiskAdjustmentReturnElement( - unprocessedReport.getSubject().getReference(), unprocessedReport); + unprocessedReport.getSubject().getReference(), unprocessedReport); resolveRiskAdjustmentReport(riskAdjustmentReturnElement); riskAdjustmentParameters.addParameter() - .setName(riskAdjustmentReturnElement.reference) - .setResource(riskAdjustmentReturnElement.getRiskAdjustmentOutcome()); + .setName(riskAdjustmentReturnElement.reference) + .setResource(riskAdjustmentReturnElement.getRiskAdjustmentOutcome()); return riskAdjustmentParameters; } private void resolveRiskAdjustmentReport(RiskAdjustmentReturnElement riskAdjustmentReturnElement) { - for (MeasureReport.MeasureReportGroupComponent group : riskAdjustmentReturnElement.unprocessedReport.getGroup()) { + for (MeasureReport.MeasureReportGroupComponent group : riskAdjustmentReturnElement.unprocessedReport + .getGroup()) { CodeableConcept hccCode = group.getCode(); visited = null; for (MeasureReport.MeasureReportGroupStratifierComponent stratifier : group.getStratifier()) { @@ -95,17 +96,20 @@ private void resolveRiskAdjustmentReport(RiskAdjustmentReturnElement riskAdjustm CodeableConcept value = stratum.getValue(); Quantity score = stratum.getMeasureScore(); if (stratifierPopCode.hasCoding() - && stratifierPopCode.getCodingFirstRep().getCode().equals(HISTORIC)) { + && stratifierPopCode.getCodingFirstRep().getCode().equals(HISTORIC)) { resolveGroup(riskAdjustmentReturnElement, - new Historic(hccCode, value, score, resolveEvidenceStatusDate(riskAdjustmentReturnElement))); + new Historic(hccCode, value, score, + resolveEvidenceStatusDate(riskAdjustmentReturnElement))); } else if (stratifierPopCode.hasCoding() - && stratifierPopCode.getCodingFirstRep().getCode().equals(SUSPECTED)) { + && stratifierPopCode.getCodingFirstRep().getCode().equals(SUSPECTED)) { resolveGroup(riskAdjustmentReturnElement, - new Suspected(hccCode, value, score, resolveEvidenceStatusDate(riskAdjustmentReturnElement))); + new Suspected(hccCode, value, score, + resolveEvidenceStatusDate(riskAdjustmentReturnElement))); } else if (stratifierPopCode.hasCoding() - && stratifierPopCode.getCodingFirstRep().getCode().equals(NET_NEW)) { + && stratifierPopCode.getCodingFirstRep().getCode().equals(NET_NEW)) { resolveGroup(riskAdjustmentReturnElement, - new NetNew(hccCode, value, score, resolveEvidenceStatusDate(riskAdjustmentReturnElement))); + new NetNew(hccCode, value, score, + resolveEvidenceStatusDate(riskAdjustmentReturnElement))); } } } @@ -113,16 +117,16 @@ private void resolveRiskAdjustmentReport(RiskAdjustmentReturnElement riskAdjustm } private void resolveGroup(RiskAdjustmentReturnElement riskAdjustmentReturnElement, - RiskAdjustmentGroup riskAdjustmentGroup) { + RiskAdjustmentGroup riskAdjustmentGroup) { if (riskAdjustmentGroup.value != null && riskAdjustmentGroup.value.hasText() - && riskAdjustmentGroup.value.getText().equalsIgnoreCase("true")) { + && riskAdjustmentGroup.value.getText().equalsIgnoreCase("true")) { if (visited != null) { riskAdjustmentReturnElement.createIssue( - String.format( - "Disjoint populations found. The %s and %s populations cannot be included in the same group", - visited, riskAdjustmentGroup.name)); + String.format( + "Disjoint populations found. The %s and %s populations cannot be included in the same group", + visited, riskAdjustmentGroup.name)); } else if (riskAdjustmentGroup instanceof NetNew && riskAdjustmentGroup.score.hasValue() - && riskAdjustmentGroup.score.getValue().intValue() == 0) { + && riskAdjustmentGroup.score.getValue().intValue() == 0) { riskAdjustmentReturnElement.createIssue("Invalid open gap detected for net-new population"); } else { riskAdjustmentReturnElement.processedReport.addGroup(riskAdjustmentGroup.resolveGroup()); @@ -137,18 +141,19 @@ private Extension resolveEvidenceStatusDate(RiskAdjustmentReturnElement riskAdju continue; Observation containedObservation = (Observation) contained; if (containedObservation.hasCode() && containedObservation.getCode().hasCoding() - && containedObservation.getCode().getCodingFirstRep().hasSystem() - && containedObservation.getCode().getCodingFirstRep().getSystem().equals( - "http://terminology.hl7.org/CodeSystem/measure-data-usage") - && ((Observation) contained).hasValueCodeableConcept() - && ((Observation) contained).getValueCodeableConcept().hasCoding() - && ((Observation) contained).getValueCodeableConcept().getCodingFirstRep().hasCode()) { + && containedObservation.getCode().getCodingFirstRep().hasSystem() + && containedObservation.getCode().getCodingFirstRep().getSystem().equals( + "http://terminology.hl7.org/CodeSystem/measure-data-usage") + && ((Observation) contained).hasValueCodeableConcept() + && ((Observation) contained).getValueCodeableConcept().hasCoding() + && ((Observation) contained).getValueCodeableConcept().getCodingFirstRep().hasCode()) { return new Extension().setUrl(EVIDENCE_STATUS_DATE_URL).setValue( - new CodeableConcept().setCoding( - Collections.singletonList(new Coding() - .setCode( - ((Observation) contained).getValueCodeableConcept().getCodingFirstRep().getCode()) - .setSystem(EVIDENCE_STATUS_DATE_URL)))); + new CodeableConcept().setCoding( + Collections.singletonList(new Coding() + .setCode( + ((Observation) contained).getValueCodeableConcept().getCodingFirstRep() + .getCode()) + .setSystem(EVIDENCE_STATUS_DATE_URL)))); } } return null; @@ -156,11 +161,11 @@ private Extension resolveEvidenceStatusDate(RiskAdjustmentReturnElement riskAdju private static class RiskAdjustmentGroup { private final Extension closedGapExtension = new Extension().setUrl(EVIDENCE_STATUS_URL).setValue( - new CodeableConcept().setCoding( - Collections.singletonList(new Coding().setCode("closed-gap").setSystem(EVIDENCE_STATUS_URL)))); + new CodeableConcept().setCoding( + Collections.singletonList(new Coding().setCode("closed-gap").setSystem(EVIDENCE_STATUS_URL)))); private final Extension openGapExtension = new Extension().setUrl(EVIDENCE_STATUS_URL).setValue( - new CodeableConcept().setCoding( - Collections.singletonList(new Coding().setCode("open-gap").setSystem(EVIDENCE_STATUS_URL)))); + new CodeableConcept().setCoding( + Collections.singletonList(new Coding().setCode("open-gap").setSystem(EVIDENCE_STATUS_URL)))); String name; CodeableConcept hccCode; @@ -171,7 +176,7 @@ private static class RiskAdjustmentGroup { Extension evidenceStatusDateExtension; RiskAdjustmentGroup(CodeableConcept hccCode, CodeableConcept value, Quantity score, - Extension evidenceStatusDateExtension) { + Extension evidenceStatusDateExtension) { this.hccCode = hccCode; this.value = value; this.score = score; @@ -181,33 +186,35 @@ private static class RiskAdjustmentGroup { MeasureReport.MeasureReportGroupComponent resolveGroup() { MeasureReport.MeasureReportGroupComponent group = new MeasureReport.MeasureReportGroupComponent(); evidenceStatusExtension = score.hasValue() && score.getValue().intValue() == 1 ? closedGapExtension - : openGapExtension; + : openGapExtension; group.setCode(hccCode) - .addExtension(suspectTypeExtension) - .addExtension(evidenceStatusExtension) - .addExtension(evidenceStatusDateExtension); + .addExtension(suspectTypeExtension) + .addExtension(evidenceStatusExtension) + .addExtension(evidenceStatusDateExtension); return group; } } private static class Historic extends RiskAdjustmentGroup { - Historic(CodeableConcept hccCode, CodeableConcept value, Quantity score, Extension evidenceStatusDateExtension) { + Historic(CodeableConcept hccCode, CodeableConcept value, Quantity score, + Extension evidenceStatusDateExtension) { super(hccCode, value, score, evidenceStatusDateExtension); this.suspectTypeExtension = new Extension().setUrl(SUSPECT_TYPE_URL).setValue( - new CodeableConcept().setCoding( - Collections.singletonList(new Coding().setCode(HISTORIC).setSystem(SUSPECT_TYPE_URL)))); + new CodeableConcept().setCoding( + Collections.singletonList(new Coding().setCode(HISTORIC).setSystem(SUSPECT_TYPE_URL)))); this.name = HISTORIC; } } private static class Suspected extends RiskAdjustmentGroup { - Suspected(CodeableConcept hccCode, CodeableConcept value, Quantity score, Extension evidenceStatusDateExtension) { + Suspected(CodeableConcept hccCode, CodeableConcept value, Quantity score, + Extension evidenceStatusDateExtension) { super(hccCode, value, score, evidenceStatusDateExtension); this.suspectTypeExtension = new Extension().setUrl(SUSPECT_TYPE_URL).setValue( - new CodeableConcept().setCoding( - Collections.singletonList(new Coding().setCode(SUSPECTED).setSystem(SUSPECT_TYPE_URL)))); + new CodeableConcept().setCoding( + Collections.singletonList(new Coding().setCode(SUSPECTED).setSystem(SUSPECT_TYPE_URL)))); this.name = SUSPECTED; } } @@ -217,8 +224,8 @@ private static class NetNew extends RiskAdjustmentGroup { NetNew(CodeableConcept hccCode, CodeableConcept value, Quantity score, Extension evidenceStatusDateExtension) { super(hccCode, value, score, evidenceStatusDateExtension); this.suspectTypeExtension = new Extension().setUrl(SUSPECT_TYPE_URL).setValue( - new CodeableConcept().setCoding( - Collections.singletonList(new Coding().setCode(NET_NEW).setSystem(SUSPECT_TYPE_URL)))); + new CodeableConcept().setCoding( + Collections.singletonList(new Coding().setCode(NET_NEW).setSystem(SUSPECT_TYPE_URL)))); this.name = NET_NEW; } } @@ -236,7 +243,7 @@ private class RiskAdjustmentReturnElement { this.unprocessedReport.copyValues(this.processedReport); this.processedReport.getGroup().clear(); this.processedReport.setMeta( - new Meta().addProfile("http://hl7.org/fhir/us/davinci-ra/StructureDefinition/ra-measurereport")); + new Meta().addProfile("http://hl7.org/fhir/us/davinci-ra/StructureDefinition/ra-measurereport")); } void createIssue(String issue) { diff --git a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentUser.java b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentUser.java index f7ae30449..bcbed33d5 100644 --- a/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentUser.java +++ b/plugin/ra/src/main/java/org/opencds/cqf/ruler/ra/r4/RiskAdjustmentUser.java @@ -1,13 +1,15 @@ package org.opencds.cqf.ruler.ra.r4; -import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; -import ca.uhn.fhir.rest.api.SortOrderEnum; -import ca.uhn.fhir.rest.api.SortSpec; -import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.ReferenceParam; -import ca.uhn.fhir.rest.param.TokenParam; -import ca.uhn.fhir.rest.param.UriParam; -import ca.uhn.fhir.util.BundleUtil; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; + import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.CanonicalType; import org.hl7.fhir.r4.model.Composition; @@ -20,77 +22,81 @@ import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.Resource; import org.hl7.fhir.r4.model.StringType; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; import org.opencds.cqf.ruler.behavior.r4.MeasureReportUser; import org.opencds.cqf.ruler.ra.RAConstants; -import org.opencds.cqf.ruler.utility.Ids; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; +import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.rest.api.SortOrderEnum; +import ca.uhn.fhir.rest.api.SortSpec; +import ca.uhn.fhir.rest.param.DateRangeParam; +import ca.uhn.fhir.rest.param.ReferenceParam; +import ca.uhn.fhir.rest.param.TokenParam; +import ca.uhn.fhir.rest.param.UriParam; +import ca.uhn.fhir.util.BundleUtil; public interface RiskAdjustmentUser extends MeasureReportUser { default List getMeasureReports( - String subject, String periodStart, String periodEnd) { + String subject, String periodStart, String periodEnd) { return search(MeasureReport.class, - SearchParameterMap.newSynchronous() - .add(MeasureReport.SP_SUBJECT, new ReferenceParam(subject)) - .add(MeasureReport.SP_PERIOD, new DateRangeParam(periodStart, periodEnd))) - .getAllResourcesTyped(); + SearchParameterMap.newSynchronous() + .add(MeasureReport.SP_SUBJECT, new ReferenceParam(subject)) + .add(MeasureReport.SP_PERIOD, new DateRangeParam(periodStart, periodEnd))) + .getAllResourcesTyped(); } default List getMeasureReportsWithMeasureReference( - String subject, String periodStart, String periodEnd, List measureReference) { + String subject, String periodStart, String periodEnd, List measureReference) { return getMeasureReports(subject, periodStart, periodEnd).stream().filter( - report -> { - if (report.hasMeasure()) { - for (String ref : measureReference) { - if (report.getMeasure().endsWith(ref)) - return true; + report -> { + if (report.hasMeasure()) { + for (String ref : measureReference) { + if (report.getMeasure().endsWith(ref)) + return true; + } } - } - return false; - }).collect(Collectors.toList()); + return false; + }).collect(Collectors.toList()); } default List getMostRecentCodingGapReportBundles(String subject) { - // Something like the following should work, but the composition search parameter doesn't appear to be implemented -// return search(Bundle.class, SearchParameterMap.newSynchronous() -// .add(Bundle.SP_TYPE, new TokenParam("document")) -// .add(Bundle.SP_COMPOSITION, new ReferenceParam("Composition", Composition.SP_SUBJECT, subject)) -// .setSort(new SortSpec(Bundle.SP_TIMESTAMP, SortOrderEnum.DESC))).getAllResourcesTyped(); + // Something like the following should work, but the composition search + // parameter doesn't appear to be implemented + // return search(Bundle.class, SearchParameterMap.newSynchronous() + // .add(Bundle.SP_TYPE, new TokenParam("document")) + // .add(Bundle.SP_COMPOSITION, new ReferenceParam("Composition", + // Composition.SP_SUBJECT, subject)) + // .setSort(new SortSpec(Bundle.SP_TIMESTAMP, + // SortOrderEnum.DESC))).getAllResourcesTyped(); return search(Bundle.class, SearchParameterMap.newSynchronous() - .add(Bundle.SP_TYPE, new TokenParam("document")) - .add("_profile", new UriParam(RAConstants.CODING_GAP_BUNDLE_URL)) - .setSort(new SortSpec(Bundle.SP_TIMESTAMP, SortOrderEnum.DESC))) - .getAllResourcesTyped(); + .add(Bundle.SP_TYPE, new TokenParam("document")) + .add("_profile", new UriParam(RAConstants.CODING_GAP_BUNDLE_URL)) + .setSort(new SortSpec(Bundle.SP_TIMESTAMP, SortOrderEnum.DESC))) + .getAllResourcesTyped(); } default Bundle getMostRecentCodingGapReportBundle(String subject) { return getMostRecentCodingGapReportBundles(subject).stream().filter( bundle -> bundle.hasEntry() && bundle.getEntryFirstRep().hasResource() - && bundle.getEntryFirstRep().getResource() instanceof Composition - && ((Composition) bundle.getEntryFirstRep().getResource()).getSubject().getReference().endsWith(subject)) - .collect(Collectors.toList()).stream().findFirst().orElse(null); + && bundle.getEntryFirstRep().getResource() instanceof Composition + && ((Composition) bundle.getEntryFirstRep().getResource()).getSubject().getReference() + .endsWith(subject)) + .collect(Collectors.toList()).stream().findFirst().orElse(null); } default Bundle getMostRecentCodingGapReportBundle(String subject, Date periodStart, Date periodEnd) { return getMostRecentCodingGapReportBundles(subject).stream().filter( bundle -> bundle.hasEntry() && bundle.getEntryFirstRep().hasResource() - && bundle.getEntryFirstRep().getResource() instanceof Composition - && ((Composition) bundle.getEntryFirstRep().getResource()).getSubject().getReference().endsWith(subject) - && bundle.getEntry().stream().anyMatch( - entry -> entry.hasResource() && entry.getResource() instanceof MeasureReport - && ((MeasureReport) entry.getResource()).hasDate() - && ((MeasureReport) entry.getResource()).getDate().compareTo(periodStart) >= 0 - && ((MeasureReport) entry.getResource()).getDate().compareTo(periodEnd) <= 0)) - .collect(Collectors.toList()).stream().findFirst().orElse(null); + && bundle.getEntryFirstRep().getResource() instanceof Composition + && ((Composition) bundle.getEntryFirstRep().getResource()).getSubject().getReference() + .endsWith(subject) + && bundle.getEntry().stream().anyMatch( + entry -> entry.hasResource() && entry.getResource() instanceof MeasureReport + && ((MeasureReport) entry.getResource()).hasDate() + && ((MeasureReport) entry.getResource()).getDate().compareTo(periodStart) >= 0 + && ((MeasureReport) entry.getResource()).getDate().compareTo(periodEnd) <= 0)) + .collect(Collectors.toList()).stream().findFirst().orElse(null); } default List getReportsFromBundles(List bundles) { @@ -103,12 +109,12 @@ default List getReportsFromBundles(List bundles) { default Composition getCompositionFromBundle(Bundle bundle) { return BundleUtil.toListOfResourcesOfType( - getFhirContext(), bundle, Composition.class).stream().findFirst().orElse(null); + getFhirContext(), bundle, Composition.class).stream().findFirst().orElse(null); } default MeasureReport getReportFromBundle(Bundle bundle) { return BundleUtil.toListOfResourcesOfType( - getFhirContext(), bundle, MeasureReport.class).stream().findFirst().orElse(null); + getFhirContext(), bundle, MeasureReport.class).stream().findFirst().orElse(null); } default List getIssuesFromBundle(Bundle bundle) { @@ -117,16 +123,16 @@ default List getIssuesFromBundle(Bundle bundle) { default List getOriginalIssues(String measureReportReference) { return search(DetectedIssue.class, SearchParameterMap.newSynchronous() - .add(DetectedIssue.SP_IMPLICATED, new ReferenceParam(measureReportReference)) - .add("_profile", new UriParam(RAConstants.ORIGINAL_ISSUE_PROFILE_URL))) - .getAllResourcesTyped(); + .add(DetectedIssue.SP_IMPLICATED, new ReferenceParam(measureReportReference)) + .add("_profile", new UriParam(RAConstants.ORIGINAL_ISSUE_PROFILE_URL))) + .getAllResourcesTyped(); } default List getAssociatedIssues(String measureReportReference) { return search(DetectedIssue.class, SearchParameterMap.newSynchronous() - .add(DetectedIssue.SP_IMPLICATED, new ReferenceParam(measureReportReference)) - .add("_profile", new UriParam(RAConstants.CLINICAL_EVALUATION_ISSUE_PROFILE_URL))) - .getAllResourcesTyped(); + .add(DetectedIssue.SP_IMPLICATED, new ReferenceParam(measureReportReference)) + .add("_profile", new UriParam(RAConstants.CLINICAL_EVALUATION_ISSUE_PROFILE_URL))) + .getAllResourcesTyped(); } default List getAllIssues(String measureReportReference) { @@ -140,18 +146,16 @@ default List getEvidenceById(String groupId, MeasureReport report) { List evidence = new ArrayList<>(); if (report.hasEvaluatedResource()) { report.getEvaluatedResource().forEach( - resource -> { - if (resource.hasExtension()) { - resource.getExtensionsByUrl(RAConstants.GROUP_REFERENCE_URL).forEach( - extension -> { - if (extension.getValue().primitiveValue().equals(groupId)) { - evidence.add(resource); - } - } - ); - } - } - ); + resource -> { + if (resource.hasExtension()) { + resource.getExtensionsByUrl(RAConstants.GROUP_REFERENCE_URL).forEach( + extension -> { + if (extension.getValue().primitiveValue().equals(groupId)) { + evidence.add(resource); + } + }); + } + }); } return evidence; } @@ -159,9 +163,9 @@ default List getEvidenceById(String groupId, MeasureReport report) { default DetectedIssue buildOriginalIssueStart(MeasureReport report, String groupId) { DetectedIssue originalIssue = new DetectedIssue(); originalIssue.setIdElement(new IdType( - "DetectedIssue", report.getIdElement().getIdPart() + "-" + groupId)); + "DetectedIssue", report.getIdElement().getIdPart() + "-" + groupId)); originalIssue.setMeta(new Meta().addProfile( - RAConstants.ORIGINAL_ISSUE_PROFILE_URL).setLastUpdated(new Date())); + RAConstants.ORIGINAL_ISSUE_PROFILE_URL).setLastUpdated(new Date())); originalIssue.addExtension().setUrl(RAConstants.GROUP_REFERENCE_URL).setValue(new StringType(groupId)); originalIssue.setStatus(DetectedIssue.DetectedIssueStatus.PRELIMINARY); originalIssue.setCode(RAConstants.CODING_GAP_CODE); @@ -177,23 +181,21 @@ default List buildOriginalIssues(MeasureReport report) { List issues = new ArrayList<>(); if (report.hasGroup()) { report.getGroup().forEach( - group -> issues.add(buildOriginalIssueStart(report, group.getId()).setEvidence( - getEvidenceById(group.getId(), report).stream().map( - ref -> new DetectedIssue.DetectedIssueEvidenceComponent().addDetail(ref)) - .collect(Collectors.toList()) - )) - ); + group -> issues.add(buildOriginalIssueStart(report, group.getId()).setEvidence( + getEvidenceById(group.getId(), report).stream().map( + ref -> new DetectedIssue.DetectedIssueEvidenceComponent().addDetail(ref)) + .collect(Collectors.toList())))); } return issues; } default List buildCompositionsAndBundles(String subject, Map> issues, - IdType compositionSectionAuthor) { + IdType compositionSectionAuthor) { List raBundles = new ArrayList<>(); for (Map.Entry> issuesSet : issues.entrySet()) { raBundles.add(buildCodingGapReportBundle(buildComposition( - subject, issuesSet.getKey(), issuesSet.getValue(), compositionSectionAuthor), - issuesSet.getValue(), issuesSet.getKey())); + subject, issuesSet.getKey(), issuesSet.getValue(), compositionSectionAuthor), + issuesSet.getValue(), issuesSet.getKey())); } return raBundles; @@ -207,43 +209,42 @@ default void updateComposition(Composition composition, MeasureReport report, Li default void resolveIssues(Composition composition, MeasureReport report, List issues) { issues.forEach( - issue -> { - Composition.SectionComponent section = new Composition.SectionComponent(); - if (issue.hasExtension()) { - issue.getExtension().forEach( - extension -> { - if (extension.hasUrl() && extension.getUrl().equals(RAConstants.GROUP_REFERENCE_URL)) { - report.getGroup().forEach( - group -> { - if (group.hasId() && group.getId().equals(extension.getValue().toString())) { - section.addEntry(new Reference(issue.getIdElement())); - if (group.hasCode()) { - section.setCode(group.getCode()); - } - } + issue -> { + Composition.SectionComponent section = new Composition.SectionComponent(); + if (issue.hasExtension()) { + issue.getExtension().forEach( + extension -> { + if (extension.hasUrl() + && extension.getUrl().equals(RAConstants.GROUP_REFERENCE_URL)) { + report.getGroup().forEach( + group -> { + if (group.hasId() + && group.getId().equals(extension.getValue().toString())) { + section.addEntry(new Reference(issue.getIdElement())); + if (group.hasCode()) { + section.setCode(group.getCode()); + } + } + }); + section.setFocus(new Reference(report.getIdElement().getValue())); } - ); - section.setFocus(new Reference(report.getIdElement().getValue())); - } - } - ); - composition.addSection(section); - } - } - ); + }); + composition.addSection(section); + } + }); } default Composition buildComposition(String subject, MeasureReport report, - List issues, IdType compositionSectionAuthor) { + List issues, IdType compositionSectionAuthor) { Composition composition = new Composition(); composition.setMeta(RAConstants.COMPOSITION_META); composition.setIdentifier( - new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + UUID.randomUUID())); + new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + UUID.randomUUID())); composition.setStatus(Composition.CompositionStatus.PRELIMINARY) - .setType(RAConstants.COMPOSITION_TYPE).setSubject(new Reference(subject)) - .setDate(Date.from(Instant.now())) - .setAuthor(Collections.singletonList(new Reference(compositionSectionAuthor))) - .setTitle("Risk Adjustment Coding Gaps Report for " + subject); + .setType(RAConstants.COMPOSITION_TYPE).setSubject(new Reference(subject)) + .setDate(Date.from(Instant.now())) + .setAuthor(Collections.singletonList(new Reference(compositionSectionAuthor))) + .setTitle("Risk Adjustment Coding Gaps Report for " + subject); resolveIssues(composition, report, issues); return composition; } @@ -251,16 +252,17 @@ default Composition buildComposition(String subject, MeasureReport report, default Bundle startCodingGapReportBundle() { Bundle codingGapReportBundle = new Bundle(); codingGapReportBundle.setMeta(new Meta().setProfile( - Collections.singletonList(new CanonicalType(RAConstants.CODING_GAP_BUNDLE_URL))) - .setLastUpdated(new Date())); + Collections.singletonList(new CanonicalType(RAConstants.CODING_GAP_BUNDLE_URL))) + .setLastUpdated(new Date())); codingGapReportBundle.setIdentifier( - new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + UUID.randomUUID())); + new Identifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + UUID.randomUUID())); codingGapReportBundle.setType(Bundle.BundleType.DOCUMENT); codingGapReportBundle.setTimestamp(new Date()); return codingGapReportBundle; } - default Bundle buildCodingGapReportBundle(Composition composition, List issues, MeasureReport report) { + default Bundle buildCodingGapReportBundle(Composition composition, List issues, + MeasureReport report) { Bundle codingGapReportBundle = startCodingGapReportBundle(); codingGapReportBundle.addEntry().setResource(composition); Map evaluatedResources = new HashMap<>(); @@ -289,8 +291,10 @@ default Map getEvidenceResources(DetectedIssue issue) { for (DetectedIssue.DetectedIssueEvidenceComponent evidence : issue.getEvidence()) { if (evidence.hasDetail()) { for (Reference detail : evidence.getDetail()) { - if (detail.getReference().startsWith("MeasureReport/")) continue; - evidenceResources.put(Ids.simple(new IdType(detail.getReference())), read(new IdType(detail.getReference()))); + if (detail.getReference().startsWith("MeasureReport/")) + continue; + evidenceResources.put(Ids.simple(new IdType(detail.getReference())), + read(new IdType(detail.getReference()))); } } } @@ -299,11 +303,10 @@ default Map getEvidenceResources(DetectedIssue issue) { } default List getMeasureReferences( - List measureId, List measureIdentifier, List measureUrl) { + List measureId, List measureIdentifier, List measureUrl) { if (measureUrl != null) { return measureUrl; - } - else if (measureId != null) { + } else if (measureId != null) { return measureId; } return measureIdentifier; diff --git a/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RACodingGapsProviderIT.java b/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RACodingGapsProviderIT.java index 8b362a144..6482561ce 100644 --- a/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RACodingGapsProviderIT.java +++ b/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RACodingGapsProviderIT.java @@ -5,9 +5,9 @@ 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.datePart; -import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.datePart; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.stringPart; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Composition; @@ -29,10 +29,9 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - classes = { RACodingGapsProviderIT.class, RAConfig.class }, - properties = {"hapi.fhir.fhir_version=r4", - "hapi.fhir.ra.composition.ra_composition_section_author=Organization/alphora-author" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { RACodingGapsProviderIT.class, + RAConfig.class }, properties = { "hapi.fhir.fhir_version=r4", + "hapi.fhir.ra.composition.ra_composition_section_author=Organization/alphora-author" }) class RACodingGapsProviderIT extends RestIntegrationTest { @Autowired private RAProperties myRaProperties; @@ -579,7 +578,8 @@ void testUpdatedReportOperation() { // test that Composition author is same as config properties assertTrue(((Composition) bundle.getEntryFirstRep().getResource()).hasAuthor()); - assertEquals("Organization/alphora-author", ((Composition) bundle.getEntryFirstRep().getResource()).getAuthorFirstRep().getReference()); + assertEquals("Organization/alphora-author", + ((Composition) bundle.getEntryFirstRep().getResource()).getAuthorFirstRep().getReference()); assertTrue(bundle.getEntry().get(1).getResource() instanceof DetectedIssue); assertTrue(bundle.getEntry().get(2).getResource() instanceof DetectedIssue); diff --git a/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RemediateProviderIT.java b/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RemediateProviderIT.java index 18dd49c4f..ecaf58805 100644 --- a/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RemediateProviderIT.java +++ b/plugin/ra/src/test/java/org/opencds/cqf/ruler/ra/r4/RemediateProviderIT.java @@ -1,5 +1,11 @@ package org.opencds.cqf.ruler.ra.r4; +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.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.stringPart; + import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Composition; import org.hl7.fhir.r4.model.DetectedIssue; @@ -14,15 +20,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -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.parameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; - -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - classes = { RemediateProviderIT.class, RAConfig.class }, - properties = { "hapi.fhir.fhir_version=r4" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { RemediateProviderIT.class, + RAConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) class RemediateProviderIT extends RestIntegrationTest { @Autowired @@ -53,13 +52,13 @@ void testRemediateProvider() { loadResource("DetectedIssue-ra-measurereport03-remediate.json"); Parameters params = parameters( - stringPart("periodStart", "2021-01-01"), - stringPart("periodEnd", "2021-12-31"), - stringPart("subject", "Patient/ra-patient02")); + stringPart("periodStart", "2021-01-01"), + stringPart("periodEnd", "2021-12-31"), + stringPart("subject", "Patient/ra-patient02")); Parameters result = getClient().operation().onType(MeasureReport.class) - .named("$ra.remediate-coding-gaps").withParameters(params) - .useHttpGet().returnResourceType(Parameters.class).execute(); + .named("$ra.remediate-coding-gaps").withParameters(params) + .useHttpGet().returnResourceType(Parameters.class).execute(); assertFalse(result.isEmpty()); assertTrue(result.hasParameter("return")); @@ -78,11 +77,14 @@ void testRemediateProvider() { // check that Composition identifier has not changed assertTrue(((Composition) raBundle.getEntryFirstRep().getResource()).hasIdentifier()); assertTrue(((Composition) raBundle.getEntryFirstRep().getResource()).getIdentifier().hasValue()); - assertEquals("urn:uuid:e729e44f-756b-43cd-a9a3-2913d3bce01d", ((Composition) raBundle.getEntryFirstRep().getResource()).getIdentifier().getValue()); + assertEquals("urn:uuid:e729e44f-756b-43cd-a9a3-2913d3bce01d", + ((Composition) raBundle.getEntryFirstRep().getResource()).getIdentifier().getValue()); // check that Composition date has not changed assertTrue(((Composition) raBundle.getEntryFirstRep().getResource()).hasDate()); - assertEquals("2022-11-06T15:50:24-06:00", ((Composition) raBundle.getEntryFirstRep().getResource()).getDateElement().getValueAsString()); - // check that new DetectedIssue was added to Composition (section size was 2 -> should now be 3) + assertEquals("2022-11-06T15:50:24-06:00", + ((Composition) raBundle.getEntryFirstRep().getResource()).getDateElement().getValueAsString()); + // check that new DetectedIssue was added to Composition (section size was 2 -> + // should now be 3) assertTrue(((Composition) raBundle.getEntryFirstRep().getResource()).hasSection()); assertEquals(3, ((Composition) raBundle.getEntryFirstRep().getResource()).getSection().size()); // check that next three entries are DetectedIssues 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 f8edbe25c..43260db36 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.parameters; -import static org.opencds.cqf.ruler.utility.r4.Parameters.stringPart; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.stringPart; import java.util.HashSet; import java.util.List; @@ -18,18 +18,17 @@ import org.hl7.fhir.r4.model.Reference; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.opencds.cqf.cql.evaluator.fhir.util.Ids; import org.opencds.cqf.ruler.behavior.r4.MeasureReportUser; import org.opencds.cqf.ruler.ra.RAConfig; import org.opencds.cqf.ruler.ra.RAProperties; import org.opencds.cqf.ruler.test.RestIntegrationTest; import org.opencds.cqf.ruler.test.utility.Urls; -import org.opencds.cqf.ruler.utility.Ids; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - classes = { RiskAdjustmentProviderIT.class, RAConfig.class }, - properties = { "hapi.fhir.fhir_version=r4" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { RiskAdjustmentProviderIT.class, + RAConfig.class }, properties = { "hapi.fhir.fhir_version=r4" }) class RiskAdjustmentProviderIT extends RestIntegrationTest { @Autowired private RAProperties myRaProperties; @@ -85,19 +84,19 @@ void riskAssessmentHistoricNetNew() { private Parameters getRequestParameters(String subject) { return parameters( - stringPart("periodStart", "2022-01-01"), - stringPart("periodEnd", "2022-12-31"), - stringPart("subject", subject), - stringPart("type", "report")); + stringPart("periodStart", "2022-01-01"), + stringPart("periodEnd", "2022-12-31"), + stringPart("subject", subject), + stringPart("type", "report")); } private Parameters callOperation(Parameters requestParameters) { return getClient().operation() - .onInstance(new IdType("Measure", "ConditionCategoryPOC")) - .named("$davinci-ra.evaluate-measure") - .withParameters(requestParameters).useHttpGet() - .returnResourceType(Parameters.class) - .execute(); + .onInstance(new IdType("Measure", "ConditionCategoryPOC")) + .named("$davinci-ra.evaluate-measure") + .withParameters(requestParameters).useHttpGet() + .returnResourceType(Parameters.class) + .execute(); } private void validateResultParameters(Parameters resultParams, String patientReference) { @@ -112,18 +111,18 @@ private void validateResultParameters(Parameters resultParams, String patientRef private void validateBundle(Bundle riskAssessmentBundle) { assertTrue(riskAssessmentBundle.hasEntry()); List bundleResourceReferences = riskAssessmentBundle.getEntry().stream() - .map(entry -> entry.getResource().hasIdElement() ? Ids.simple(entry.getResource().getIdElement()) - : null) - .collect(Collectors.toList()); + .map(entry -> entry.getResource().hasIdElement() ? Ids.simple(entry.getResource().getIdElement()) + : null) + .collect(Collectors.toList()); validateUniqueBundleEntry(bundleResourceReferences); assertTrue(riskAssessmentBundle.getEntryFirstRep().getResource() instanceof MeasureReport); MeasureReport raBundle = (MeasureReport) riskAssessmentBundle.getEntryFirstRep().getResource(); validateEvalResourcesInBundle(bundleResourceReferences, raBundle.getEvaluatedResource().stream() - .map(Reference::getReference).collect(Collectors.toList())); + .map(Reference::getReference).collect(Collectors.toList())); validateSdeInBundle(bundleResourceReferences, raBundle.getExtension().stream() - .filter(extension -> extension.getUrl().equals( - MeasureReportUser.MEASUREREPORT_SUPPLEMENTALDATA_SEARCHPARAMETER_URL)) - .map(extension -> extension.getValue().toString()).collect(Collectors.toList())); + .filter(extension -> extension.getUrl().equals( + MeasureReportUser.MEASUREREPORT_SUPPLEMENTALDATA_SEARCHPARAMETER_URL)) + .map(extension -> extension.getValue().toString()).collect(Collectors.toList())); } private void validateUniqueBundleEntry(List entryReferences) { @@ -139,42 +138,42 @@ private void validateSdeInBundle(List bundleResourceReferences, List - + 4.0.0 org.opencds.cqf.ruler @@ -10,5 +11,10 @@ cqf-ruler-sdc + + org.opencds.cqf.cql + evaluator.fhir + + diff --git a/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/dstu3/ExtractProvider.java b/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/dstu3/ExtractProvider.java index 0c3b122af..40a577a38 100644 --- a/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/dstu3/ExtractProvider.java +++ b/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/dstu3/ExtractProvider.java @@ -19,7 +19,7 @@ import org.hl7.fhir.dstu3.model.StringType; import org.opencds.cqf.ruler.api.OperationProvider; import org.opencds.cqf.ruler.sdc.SDCProperties; -import org.opencds.cqf.ruler.utility.Clients; +import org.opencds.cqf.cql.evaluator.fhir.util.Clients; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.context.FhirContext; @@ -36,16 +36,18 @@ public class ExtractProvider implements OperationProvider { private SDCProperties mySdcProperties; @Operation(name = "$extract", idempotent = false, type = QuestionnaireResponse.class) - public Bundle extractObservationFromQuestionnaireResponse(@OperationParam(name = "questionnaireResponse") QuestionnaireResponse questionnaireResponse) { - if(questionnaireResponse == null) { - throw new IllegalArgumentException("Unable to perform operation $extract. The QuestionnaireResponse was null"); + public Bundle extractObservationFromQuestionnaireResponse( + @OperationParam(name = "questionnaireResponse") QuestionnaireResponse questionnaireResponse) { + if (questionnaireResponse == null) { + throw new IllegalArgumentException( + "Unable to perform operation $extract. The QuestionnaireResponse was null"); } Bundle observationsFromQuestionnaireResponse = createObservationBundle(questionnaireResponse); sendObservationBundle(observationsFromQuestionnaireResponse); return observationsFromQuestionnaireResponse; } - private Bundle createObservationBundle(QuestionnaireResponse questionnaireResponse){ + private Bundle createObservationBundle(QuestionnaireResponse questionnaireResponse) { Bundle newBundle = new Bundle(); Date authored = questionnaireResponse.getAuthored(); @@ -53,40 +55,43 @@ private Bundle createObservationBundle(QuestionnaireResponse questionnaireRespon bundleId.setValue("QuestionnaireResponse/" + questionnaireResponse.getIdElement().getIdPart()); newBundle.setType(Bundle.BundleType.TRANSACTION); newBundle.setIdentifier(bundleId); - Map questionnaireCodeMap = getQuestionnaireCodeMap(questionnaireResponse.getQuestionnaire().getReference()); + Map questionnaireCodeMap = getQuestionnaireCodeMap( + questionnaireResponse.getQuestionnaire().getReference()); - questionnaireResponse.getItem().stream().forEach(item ->{ + questionnaireResponse.getItem().stream().forEach(item -> { processItems(item, authored, questionnaireResponse, newBundle, questionnaireCodeMap); }); return newBundle; } private void processItems(QuestionnaireResponse.QuestionnaireResponseItemComponent item, Date authored, - QuestionnaireResponse questionnaireResponse, Bundle newBundle, - Map questionnaireCodeMap){ - if(item.hasAnswer()){ - item.getAnswer().forEach(answer ->{ - Bundle.BundleEntryComponent newBundleEntryComponent = createObservationFromItemAnswer(answer, item.getLinkId(), authored, questionnaireResponse, questionnaireCodeMap); - if(null != newBundleEntryComponent){ + QuestionnaireResponse questionnaireResponse, Bundle newBundle, + Map questionnaireCodeMap) { + if (item.hasAnswer()) { + item.getAnswer().forEach(answer -> { + Bundle.BundleEntryComponent newBundleEntryComponent = createObservationFromItemAnswer(answer, + item.getLinkId(), authored, questionnaireResponse, questionnaireCodeMap); + if (null != newBundleEntryComponent) { newBundle.addEntry(newBundleEntryComponent); } - if(answer.hasItem()){ - answer.getItem().forEach(answerItem->{ + if (answer.hasItem()) { + answer.getItem().forEach(answerItem -> { processItems(answerItem, authored, questionnaireResponse, newBundle, questionnaireCodeMap); }); } }); } - if(item.hasItem()){ - item.getItem().forEach(itemItem ->{ + if (item.hasItem()) { + item.getItem().forEach(itemItem -> { processItems(itemItem, authored, questionnaireResponse, newBundle, questionnaireCodeMap); }); } } - private Bundle.BundleEntryComponent createObservationFromItemAnswer(QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent answer, - String linkId, Date authored, QuestionnaireResponse questionnaireResponse, - Map questionnaireCodeMap){ + private Bundle.BundleEntryComponent createObservationFromItemAnswer( + QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent answer, + String linkId, Date authored, QuestionnaireResponse questionnaireResponse, + Map questionnaireCodeMap) { Observation obs = new Observation(); obs.setEffective(new DateTimeType(authored)); obs.setStatus(Observation.ObservationStatus.FINAL); @@ -97,7 +102,7 @@ private Bundle.BundleEntryComponent createObservationFromItemAnswer(Questionnair obs.setCategory(Collections.singletonList(new CodeableConcept().addCoding(qrCategoryCoding))); obs.setCode(new CodeableConcept().addCoding(questionnaireCodeMap.get(linkId))); obs.setId("qr" + questionnaireResponse.getIdElement().getIdPart() + "." + linkId); - switch(answer.getValue().fhirType()){ + switch (answer.getValue().fhirType()) { case "string": obs.setValue(new StringType(answer.getValueStringType().getValue())); break; @@ -109,7 +114,8 @@ private Bundle.BundleEntryComponent createObservationFromItemAnswer(Questionnair break; } Reference questionnaireResponseReference = new Reference(); - questionnaireResponseReference.setReference("QuestionnaireResponse" + "/" + questionnaireResponse.getIdElement().getIdPart()); + questionnaireResponseReference + .setReference("QuestionnaireResponse" + "/" + questionnaireResponse.getIdElement().getIdPart()); Observation.ObservationRelatedComponent related = new Observation.ObservationRelatedComponent() .setType(Observation.ObservationRelationshipType.DERIVEDFROM) .setTarget(questionnaireResponseReference); @@ -131,10 +137,11 @@ private Bundle.BundleEntryComponent createObservationFromItemAnswer(Questionnair return bec; } - private Bundle sendObservationBundle(Bundle observationsBundle) throws IllegalArgumentException{ + private Bundle sendObservationBundle(Bundle observationsBundle) throws IllegalArgumentException { String url = mySdcProperties.getExtract().getEndpoint(); if (null == url || url.length() < 1) { - throw new IllegalArgumentException("Unable to transmit observation bundle. No observation.endpoint defined in sdc properties."); + throw new IllegalArgumentException( + "Unable to transmit observation bundle. No observation.endpoint defined in sdc properties."); } String user = mySdcProperties.getExtract().getUsername(); String password = mySdcProperties.getExtract().getPassword(); @@ -147,36 +154,39 @@ private Bundle sendObservationBundle(Bundle observationsBundle) throws IllegalAr return outcomeBundle; } - private Map getQuestionnaireCodeMap(String questionnaireUrl){ + private Map getQuestionnaireCodeMap(String questionnaireUrl) { String url = mySdcProperties.getExtract().getEndpoint(); if (null == url || url.length() < 1) { - throw new IllegalArgumentException("Unable to transmit observation bundle. No observation.endpoint defined in sdc properties."); + throw new IllegalArgumentException( + "Unable to transmit observation bundle. No observation.endpoint defined in sdc properties."); } String user = mySdcProperties.getExtract().getUsername(); - String password = mySdcProperties.getExtract().getPassword(); + String password = mySdcProperties.getExtract().getPassword(); IGenericClient client = Clients.forUrl(myFhirContext, url); Clients.registerBasicAuth(client, user, password); - Questionnaire questionnaire = client.read().resource(Questionnaire.class).withUrl (questionnaireUrl).execute(); + Questionnaire questionnaire = client.read().resource(Questionnaire.class).withUrl(questionnaireUrl).execute(); return createCodeMap(questionnaire); } - // this is based on "if a questionnaire.item has items then this item is a header and will not have a specific code to be used with an answer" - private Map createCodeMap(Questionnaire questionnaire){ + // this is based on "if a questionnaire.item has items then this item is a + // header and will not have a specific code to be used with an answer" + private Map createCodeMap(Questionnaire questionnaire) { Map questionnaireCodeMap = new HashMap<>(); - questionnaire.getItem().forEach((item) ->{ + questionnaire.getItem().forEach((item) -> { processQuestionnaireItems(item, questionnaireCodeMap); }); return questionnaireCodeMap; } - private void processQuestionnaireItems(Questionnaire.QuestionnaireItemComponent item, Map questionnaireCodeMap){ - if(item.hasItem()){ + private void processQuestionnaireItems(Questionnaire.QuestionnaireItemComponent item, + Map questionnaireCodeMap) { + if (item.hasItem()) { item.getItem().forEach(qItem -> { processQuestionnaireItems(qItem, questionnaireCodeMap); }); - }else{ + } else { questionnaireCodeMap.put(item.getLinkId(), item.getCodeFirstRep()); } } diff --git a/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/dstu3/TransformProvider.java b/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/dstu3/TransformProvider.java index af6c25c4a..efa5aa8ec 100644 --- a/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/dstu3/TransformProvider.java +++ b/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/dstu3/TransformProvider.java @@ -10,7 +10,7 @@ import org.hl7.fhir.dstu3.model.Observation; import org.opencds.cqf.ruler.api.OperationProvider; import org.opencds.cqf.ruler.sdc.SDCProperties; -import org.opencds.cqf.ruler.utility.Clients; +import org.opencds.cqf.cql.evaluator.fhir.util.Clients; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.context.FhirContext; @@ -41,8 +41,8 @@ public Bundle transformObservations( } String replaceCode = mySdcProperties.getTransform().getReplaceCode(); - // String username = mySdcProperties.getTransform().getUsername(); - // String password = mySdcProperties.getTransform().getPassword(); + // String username = mySdcProperties.getTransform().getUsername(); + // String password = mySdcProperties.getTransform().getPassword(); String endpoint = mySdcProperties.getTransform().getEndpoint(); IGenericClient client = Clients.forUrl(fhirContext, endpoint); diff --git a/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/r4/ExtractProvider.java b/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/r4/ExtractProvider.java index 839c6d67d..c62925401 100644 --- a/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/r4/ExtractProvider.java +++ b/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/r4/ExtractProvider.java @@ -19,7 +19,7 @@ import org.hl7.fhir.r4.model.StringType; import org.opencds.cqf.ruler.api.OperationProvider; import org.opencds.cqf.ruler.sdc.SDCProperties; -import org.opencds.cqf.ruler.utility.Clients; +import org.opencds.cqf.cql.evaluator.fhir.util.Clients; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.context.FhirContext; @@ -194,27 +194,27 @@ private Bundle sendObservationBundle(Bundle observationsBundle) return client.transaction().withBundle(observationsBundle).execute(); } - private Map getQuestionnaireCodeMap(String questionnaireUrl) { - String url = mySdcProperties.getExtract().getEndpoint(); - if (null == url || url.length() < 1) { - throw new IllegalArgumentException( - "Unable to GET Questionnaire. No observation.endpoint defined in sdc properties."); - } - String user = mySdcProperties.getExtract().getUsername(); - String password = mySdcProperties.getExtract().getPassword(); + private Map getQuestionnaireCodeMap(String questionnaireUrl) { + String url = mySdcProperties.getExtract().getEndpoint(); + if (null == url || url.length() < 1) { + throw new IllegalArgumentException( + "Unable to GET Questionnaire. No observation.endpoint defined in sdc properties."); + } + String user = mySdcProperties.getExtract().getUsername(); + String password = mySdcProperties.getExtract().getPassword(); - IGenericClient client = Clients.forUrl(myFhirContext, url); - Clients.registerBasicAuth(client, user, password); + IGenericClient client = Clients.forUrl(myFhirContext, url); + Clients.registerBasicAuth(client, user, password); - Questionnaire questionnaire = client.read().resource(Questionnaire.class).withUrl(questionnaireUrl).execute(); + Questionnaire questionnaire = client.read().resource(Questionnaire.class).withUrl(questionnaireUrl).execute(); - if (questionnaire == null) { - throw new IllegalArgumentException( - "Unable to find resource by URL " + questionnaireUrl); - } + if (questionnaire == null) { + throw new IllegalArgumentException( + "Unable to find resource by URL " + questionnaireUrl); + } - return createCodeMap(questionnaire); - } + return createCodeMap(questionnaire); + } // this is based on "if a questionnaire.item has items then this item is a // header and will not have a specific code to be used with an answer" diff --git a/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/r4/TransformProvider.java b/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/r4/TransformProvider.java index c645281da..0b4cb8289 100644 --- a/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/r4/TransformProvider.java +++ b/plugin/sdc/src/main/java/org/opencds/cqf/ruler/sdc/r4/TransformProvider.java @@ -10,7 +10,7 @@ import org.hl7.fhir.r4.model.Observation; import org.opencds.cqf.ruler.api.OperationProvider; import org.opencds.cqf.ruler.sdc.SDCProperties; -import org.opencds.cqf.ruler.utility.Clients; +import org.opencds.cqf.cql.evaluator.fhir.util.Clients; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.context.FhirContext; @@ -41,8 +41,8 @@ public Bundle transformObservations( } String replaceCode = mySdcProperties.getTransform().getReplaceCode(); - // String username = mySdcProperties.getTransform().getUsername(); - // String password = mySdcProperties.getTransform().getPassword(); + // String username = mySdcProperties.getTransform().getUsername(); + // String password = mySdcProperties.getTransform().getPassword(); String endpoint = mySdcProperties.getTransform().getEndpoint(); IGenericClient client = Clients.forUrl(fhirContext, endpoint); 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 259e39642..4621e18c8 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,10 +1,10 @@ package org.opencds.cqf.ruler.sdc.r4; -import static org.opencds.cqf.ruler.utility.r4.Parameters.parameters; +import static org.opencds.cqf.cql.evaluator.fhir.util.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 static org.opencds.cqf.ruler.utility.r4.Parameters.part; +import static org.opencds.cqf.cql.evaluator.fhir.util.r4.Parameters.part; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Parameters; @@ -45,8 +45,7 @@ void testExtract() { QuestionnaireResponse questionnaireResponse = (QuestionnaireResponse) loadResource(exampleQR); Parameters params = parameters( - part("questionnaireResponse", questionnaireResponse) - ); + part("questionnaireResponse", questionnaireResponse)); Bundle actual = getClient() .operation()