Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSTU3 submit-data, R4 and DSTU3 collect-data #439

Merged
merged 11 commits into from
Feb 2, 2022
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"java.test.defaultConfig": "test-config",
"java.checkstyle.configuration": "${workspaceFolder}/config/checkstyle/checkstyle.xml",
"java.checkstyle.version": "9.21",
"java.checkstyle.version": "9.2.1",
"cSpell.enabledLanguageIds": [
"java",
"json",
Expand All @@ -38,6 +38,8 @@
"Codeable",
"contentgroup",
"DEQM",
"Eicrs",
"mgsc",
"drawio",
"FHIR",
"Gson",
Expand All @@ -56,4 +58,4 @@
"**/.settings": true,
"**/.factorypath": true
}
}
}
6 changes: 6 additions & 0 deletions core/src/main/java/org/opencds/cqf/ruler/Application.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opencds.cqf.ruler;

import org.opencds.cqf.ruler.config.BeanFinderConfig;
import org.opencds.cqf.ruler.config.ServerProperties;
import org.opencds.cqf.ruler.config.TesterUIConfig;
import org.opencds.cqf.ruler.external.FhirTesterConfig;
import org.opencds.cqf.ruler.external.annotations.OnEitherVersion;
Expand Down Expand Up @@ -67,4 +68,9 @@ public ServletRegistrationBean<Server> hapiServletRegistration() {

return servletRegistrationBean;
}

@Bean
public ServerProperties serverProperties() {
return new ServerProperties();
}
}
21 changes: 14 additions & 7 deletions core/src/main/java/org/opencds/cqf/ruler/Server.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.opencds.cqf.ruler;

import static com.google.common.base.MoreObjects.firstNonNull;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -14,6 +16,7 @@
import org.opencds.cqf.ruler.capability.ExtensibleJpaCapabilityStatementProvider;
import org.opencds.cqf.ruler.capability.ExtensibleJpaConformanceProviderDstu2;
import org.opencds.cqf.ruler.capability.ExtensibleJpaConformanceProviderDstu3;
import org.opencds.cqf.ruler.config.ServerProperties;
import org.opencds.cqf.ruler.external.AppProperties;
import org.opencds.cqf.ruler.external.BaseJpaRestfulServer;
import org.slf4j.Logger;
Expand All @@ -29,6 +32,7 @@
import ca.uhn.fhir.rest.server.util.ISearchParamRegistry;

public class Server extends BaseJpaRestfulServer {
private static final long serialVersionUID = 1L;

private static Logger log = LoggerFactory.getLogger(Server.class);

Expand All @@ -45,12 +49,13 @@ public class Server extends BaseJpaRestfulServer {
private IValidationSupport myValidationSupport;

@Autowired
AppProperties myAppProperties;
ApplicationContext myApplicationContext;

@Autowired
ApplicationContext myApplicationContext;
AppProperties myAppProperties;

private static final long serialVersionUID = 1L;
@Autowired
ServerProperties myServerProperties;

public Server() {
super();
Expand All @@ -68,35 +73,37 @@ protected void initialize() throws ServletException {
}

FhirVersionEnum fhirVersion = fhirSystemDao.getContext().getVersion().getVersion();

String implementationDescription = myServerProperties.getImplementation_description();
if (fhirVersion == FhirVersionEnum.DSTU2) {
List<MetadataExtender<Conformance>> extenderList = extenders.values().stream()
.map(x -> (MetadataExtender<Conformance>) x).collect(Collectors.toList());
ExtensibleJpaConformanceProviderDstu2 confProvider = new ExtensibleJpaConformanceProviderDstu2(this,
fhirSystemDao,
daoConfig, extenderList);
confProvider.setImplementationDescription("CQF RULER DSTU2 Server");
confProvider.setImplementationDescription(firstNonNull(implementationDescription, "CQF RULER DSTU2 Server"));
setServerConformanceProvider(confProvider);
} else {
if (fhirVersion == FhirVersionEnum.DSTU3) {
List<MetadataExtender<CapabilityStatement>> extenderList = extenders.values().stream()
.map(x -> (MetadataExtender<CapabilityStatement>) x).collect(Collectors.toList());
ExtensibleJpaConformanceProviderDstu3 confProvider = new ExtensibleJpaConformanceProviderDstu3(this,
fhirSystemDao, daoConfig, searchParamRegistry, extenderList);
confProvider.setImplementationDescription("CQF RULER DSTU3 Server");
confProvider.setImplementationDescription(firstNonNull(implementationDescription, "CQF RULER DSTU3 Server"));
setServerConformanceProvider(confProvider);
} else if (fhirVersion == FhirVersionEnum.R4) {
List<MetadataExtender<IBaseConformance>> extenderList = extenders.values().stream()
.map(x -> (MetadataExtender<IBaseConformance>) x).collect(Collectors.toList());
ExtensibleJpaCapabilityStatementProvider confProvider = new ExtensibleJpaCapabilityStatementProvider(this,
fhirSystemDao, daoConfig, searchParamRegistry, myValidationSupport, extenderList);
confProvider.setImplementationDescription("CQF RULER R4 Server");
confProvider.setImplementationDescription(firstNonNull(implementationDescription, "CQF RULER R4 Server"));
setServerConformanceProvider(confProvider);
} else if (fhirVersion == FhirVersionEnum.R5) {
List<MetadataExtender<IBaseConformance>> extenderList = extenders.values().stream()
.map(x -> (MetadataExtender<IBaseConformance>) x).collect(Collectors.toList());
ExtensibleJpaCapabilityStatementProvider confProvider = new ExtensibleJpaCapabilityStatementProvider(this,
fhirSystemDao, daoConfig, searchParamRegistry, myValidationSupport, extenderList);
confProvider.setImplementationDescription("CQF RULER R5 Server");
confProvider.setImplementationDescription(firstNonNull(implementationDescription, "CQF RULER R5 Server"));
setServerConformanceProvider(confProvider);
} else {
throw new IllegalStateException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.Resources;
import org.opencds.cqf.ruler.utility.Ids;

public interface ResourceCreator extends FhirContextUser {
@SuppressWarnings("unchecked")
Expand All @@ -19,6 +19,26 @@ default <T extends IBaseResource, I extends IIdType> T newResource(I theId) {
}

default <T extends IBaseResource> T newResource(Class<T> theResourceClass, String theIdPart) {
return Resources.newResource(theResourceClass, theIdPart);
checkNotNull(theResourceClass);
checkNotNull(theIdPart);

T newResource = newResource(theResourceClass);
newResource.setId((IIdType)Ids.newId(getFhirContext(), newResource.fhirType(), theIdPart));

return newResource;
}

@SuppressWarnings("unchecked")
default <T extends IBaseResource> T newResource(Class<T> theResourceClass) {
checkNotNull(theResourceClass);

return (T)this.getFhirContext().getResourceDefinition(theResourceClass).newInstance();
}

@SuppressWarnings("unchecked")
default <T extends IBaseResource> T newResource(String theResourceType) {
checkNotNull(theResourceType);

return (T)this.getFhirContext().getResourceDefinition(theResourceType).newInstance();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.opencds.cqf.ruler.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@ConfigurationProperties(prefix = "hapi.fhir")
@Configuration
@EnableConfigurationProperties
public class ServerProperties {
private String implementation_description = null;

public String getImplementation_description() {
return implementation_description;
}

public void setImplementation_description(String implementation_description) {
this.implementation_description = implementation_description;
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.opencds.cqf.ruler.utility;

public class CanonicalParts {
public final class CanonicalParts {
private final String url;
private final String idPart;
private final String resourceType;
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/java/org/opencds/cqf/ruler/utility/Ids.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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;
Expand Down Expand Up @@ -103,6 +104,33 @@ public static <IdType extends IIdType> IdType newId(FhirContext theFhirContext,
return newId(theFhirContext.getVersion().getVersion(), theId);
}

/**
* The gets the "simple" Id for the Resource, without qualifiers or versions. For example, "Patient/123".
* <p>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".
* <p>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();
}

/**
* Creates the appropriate IIdType for a given FhirVersionEnum
*
Expand Down
12 changes: 5 additions & 7 deletions core/src/main/java/org/opencds/cqf/ruler/utility/Libraries.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

import com.google.common.collect.ImmutableMap;

import org.apache.commons.lang3.tuple.Triple;
import org.cqframework.cql.elm.execution.Library;
import org.cqframework.cql.elm.execution.UsingDef;
Expand Down Expand Up @@ -78,12 +79,9 @@ public static String getVersion(IBaseResource library) {
return libraryFunctions.getVersion().apply(library);
}

private static Map<String, String> urlsByModelName = new HashMap<String, String>() {
{
put("FHIR", "http://hl7.org/fhir");
put("QDM", "urn:healthit-gov:qdm:v5_4");
}
};
private static Map<String, String> urlsByModelName = ImmutableMap.of(
"FHIR", "http://hl7.org/fhir",
"QDM", "urn:healthit-gov:qdm:v5_4");

// Returns a list of (Model, Version, Url) for the usings in library. The
// "System" using is excluded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import org.hl7.fhir.instance.model.api.IBase;

class LibraryFunctions {
final class LibraryFunctions {

private final Function<IBase, List<IBase>> getAttachments;
private final Function<IBase, String> getContentType;
Expand Down
13 changes: 10 additions & 3 deletions core/src/main/java/org/opencds/cqf/ruler/utility/Resources.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ public static <T extends IBaseResource, I extends IIdType> T newResource(Class<T
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 extends IBaseResource> T newResource(Class<T> theResourceClass) {
checkNotNull(theResourceClass);
T resource = null;
try {
resource = (T) theResourceClass.getConstructor().newInstance();
Expand All @@ -23,9 +33,6 @@ public static <T extends IBaseResource, I extends IIdType> T newResource(Class<T
"theResourceClass must be a type with an empty default constructor to use this function");
}

@SuppressWarnings("unchecked")
I id = (I) Ids.newId(theResourceClass, theIdPart);
resource.setId(id);
return resource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

public class Translators {

private Translators() {}

public static String errorsToString(Iterable<CqlTranslatorException> exceptions) {
ArrayList<String> errors = new ArrayList<>();
for (CqlTranslatorException error : exceptions) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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.IdType;
import org.opencds.cqf.ruler.utility.Ids;

public class Parameters {

private Parameters() {
}

public static org.hl7.fhir.dstu3.model.Parameters newParameters(IdType theId,
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
checkNotNull(theId);

org.hl7.fhir.dstu3.model.Parameters p = newParameters(parts);
p.setId(theId);
return p;
}

public static org.hl7.fhir.dstu3.model.Parameters newParameters(String theIdPart,
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
checkNotNull(theIdPart);

return newParameters((IdType) Ids.newId(org.hl7.fhir.dstu3.model.Parameters.class, theIdPart), parts);
}

public static org.hl7.fhir.dstu3.model.Parameters newParameters(
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
org.hl7.fhir.dstu3.model.Parameters p = new org.hl7.fhir.dstu3.model.Parameters();
for (org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c : parts) {
p.addParameter(c);
}

return p;
}

public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
checkNotNull(name);

org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = new org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent();
c.setName(name);
for (org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent p : parts) {
c.addPart(p);
}

return c;
}

public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.dstu3.model.Type value, org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
checkNotNull(name);
checkNotNull(value);

org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = newPart(name, parts);
c.setValue(value);
return c;
}

public static org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent newPart(String name,
org.hl7.fhir.dstu3.model.Resource resource,
org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent... parts) {
checkNotNull(name);
checkNotNull(resource);

org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent c = newPart(name, parts);
c.setResource(resource);
return c;
}

public static List<org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent> 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());
}
}
Loading