Skip to content

Commit

Permalink
Fix warnings in adapter classes and interfaces (#562)
Browse files Browse the repository at this point in the history
* Fix warnings in adapter classes and interfaces

* cleanup
  • Loading branch information
barhodes authored Oct 16, 2024
1 parent 30c1b38 commit 057dac7
Show file tree
Hide file tree
Showing 140 changed files with 980 additions and 1,103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.opencds.cqf.fhir.cql.engine.retrieve.RetrieveSettings;
import org.opencds.cqf.fhir.cql.engine.terminology.RepositoryTerminologyProvider;
import org.opencds.cqf.fhir.utility.Constants;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory;
import org.opencds.cqf.fhir.utility.model.FhirModelResolverCache;
import org.opencds.cqf.fhir.utility.repository.InMemoryFhirRepository;
import org.slf4j.Logger;
Expand Down Expand Up @@ -92,7 +92,7 @@ public static CqlEngine forRepositoryAndSettings(
}

private static LibrarySourceProvider buildLibrarySource(Repository repository) {
var adapterFactory = AdapterFactory.forFhirContext(repository.fhirContext());
var adapterFactory = IAdapterFactory.forFhirContext(repository.fhirContext());
return new RepositoryFhirLibrarySourceProvider(
repository, adapterFactory, new LibraryVersionSelector(adapterFactory));
}
Expand Down Expand Up @@ -185,6 +185,6 @@ public static CqlFhirParametersConverter getCqlFhirParametersConverter(FhirConte
var fhirTypeConverter =
new FhirTypeConverterFactory().create(fhirContext.getVersion().getVersion());
return new CqlFhirParametersConverter(
fhirContext, AdapterFactory.forFhirContext(fhirContext), fhirTypeConverter);
fhirContext, IAdapterFactory.forFhirContext(fhirContext), fhirTypeConverter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import org.hl7.elm.r1.VersionedIdentifier;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.ICompositeType;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.AttachmentAdapter;
import org.opencds.cqf.fhir.utility.adapter.LibraryAdapter;
import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.IAttachmentAdapter;
import org.opencds.cqf.fhir.utility.adapter.ILibraryAdapter;

/**
* This class implements logic for extracting content from a FHIR Library resource and provides an
* extension point for implementing the fetch of a FHIR library matching a specific identifier.
*/
public abstract class BaseFhirLibrarySourceProvider implements LibrarySourceProvider {

protected AdapterFactory adapterFactory;
protected IAdapterFactory adapterFactory;

protected BaseFhirLibrarySourceProvider(AdapterFactory adapterFactory) {
protected BaseFhirLibrarySourceProvider(IAdapterFactory adapterFactory) {
this.adapterFactory = requireNonNull(adapterFactory, "adapterFactory can not be null");
}

Expand All @@ -40,11 +40,11 @@ public InputStream getLibraryContent(VersionedIdentifier libraryIdentifier, Libr

protected InputStream getContentStream(IBaseResource library, String contentType) {

LibraryAdapter libraryAdapter = this.adapterFactory.createLibrary(library);
ILibraryAdapter libraryAdapter = this.adapterFactory.createLibrary(library);

if (libraryAdapter.hasContent()) {
for (ICompositeType attachment : libraryAdapter.getContent()) {
AttachmentAdapter attachmentAdapter = this.adapterFactory.createAttachment(attachment);
IAttachmentAdapter attachmentAdapter = this.adapterFactory.createAttachment(attachment);
if (attachmentAdapter.getContentType().equals(contentType)) {
// get externalized extension if present and add custom load data
return new ByteArrayInputStream(attachmentAdapter.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.cql.cql2elm.util.LibraryVersionSelector;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory;
import org.opencds.cqf.fhir.utility.iterable.BundleIterable;
import org.opencds.cqf.fhir.utility.search.Searches;

Expand All @@ -20,7 +20,7 @@ public class RepositoryFhirLibrarySourceProvider extends BaseFhirLibrarySourcePr
private final LibraryVersionSelector libraryVersionSelector;

public RepositoryFhirLibrarySourceProvider(
Repository repository, AdapterFactory adapterFactory, LibraryVersionSelector libraryVersionSelector) {
Repository repository, IAdapterFactory adapterFactory, LibraryVersionSelector libraryVersionSelector) {
super(adapterFactory);
this.repository = requireNonNull(repository, "repository can not be null");
this.fhirContext = repository.fhirContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import java.util.stream.Collectors;
import org.hl7.elm.r1.VersionedIdentifier;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.LibraryAdapter;
import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.ILibraryAdapter;

public class LibraryVersionSelector {

private final AdapterFactory adapterFactory;
private final IAdapterFactory adapterFactory;

public LibraryVersionSelector(AdapterFactory adapterFactory) {
public LibraryVersionSelector(IAdapterFactory adapterFactory) {
this.adapterFactory = adapterFactory;
}

Expand All @@ -24,14 +24,14 @@ public IBaseResource select(VersionedIdentifier libraryIdentifier, Collection<IB

String targetVersion = libraryIdentifier.getVersion();

List<LibraryAdapter> adapters = libraries.stream()
List<ILibraryAdapter> adapters = libraries.stream()
.map(x -> this.adapterFactory.createLibrary(x))
.collect(Collectors.toList());

LibraryAdapter library = null;
LibraryAdapter maxLibrary = null;
ILibraryAdapter library = null;
ILibraryAdapter maxLibrary = null;

for (LibraryAdapter l : adapters) {
for (ILibraryAdapter l : adapters) {

if (!l.getName().equals(libraryIdentifier.getId())) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@
import org.opencds.cqf.cql.engine.execution.ExpressionResult;
import org.opencds.cqf.cql.engine.fhir.converter.FhirTypeConverter;
import org.opencds.cqf.cql.engine.model.ModelResolver;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.ParametersAdapter;
import org.opencds.cqf.fhir.utility.adapter.ParametersParameterComponentAdapter;
import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.IParametersAdapter;
import org.opencds.cqf.fhir.utility.adapter.IParametersParameterComponentAdapter;
import org.opencds.cqf.fhir.utility.model.FhirModelResolverCache;
import org.slf4j.LoggerFactory;

public class CqlFhirParametersConverter {

org.slf4j.Logger logger = LoggerFactory.getLogger(CqlFhirParametersConverter.class);

protected AdapterFactory adapterFactory;
protected IAdapterFactory adapterFactory;
protected FhirTypeConverter fhirTypeConverter;
protected FhirContext fhirContext;
// private IFhirPath fhirPath;
private ModelResolver modelResolver;

public CqlFhirParametersConverter(
FhirContext fhirContext, AdapterFactory adapterFactory, FhirTypeConverter fhirTypeConverter) {
FhirContext fhirContext, IAdapterFactory adapterFactory, FhirTypeConverter fhirTypeConverter) {
this.fhirContext = requireNonNull(fhirContext);
this.adapterFactory = requireNonNull(adapterFactory);
this.fhirTypeConverter = requireNonNull(fhirTypeConverter);
Expand All @@ -60,7 +60,7 @@ public IBaseParameters toFhirParameters(EvaluationResult evaluationResult) {
throw new RuntimeException(e);
}

ParametersAdapter pa = this.adapterFactory.createParameters(params);
IParametersAdapter pa = this.adapterFactory.createParameters(params);

for (Map.Entry<String, ExpressionResult> entry : evaluationResult.expressionResults.entrySet()) {
String name = entry.getKey();
Expand All @@ -84,17 +84,17 @@ public IBaseParameters toFhirParameters(EvaluationResult evaluationResult) {
return params;
}

protected ParametersParameterComponentAdapter addPart(ParametersAdapter pa, String name) {
protected IParametersParameterComponentAdapter addPart(IParametersAdapter pa, String name) {
IBaseBackboneElement ppc = pa.addParameter();
ParametersParameterComponentAdapter ppca = this.adapterFactory.createParametersParameters(ppc);
IParametersParameterComponentAdapter ppca = this.adapterFactory.createParametersParameters(ppc);
ppca.setName(name);

return ppca;
}

@SuppressWarnings("unchecked")
protected void addPart(ParametersAdapter pa, String name, Object value) {
ParametersParameterComponentAdapter ppca = this.addPart(pa, name);
protected void addPart(IParametersAdapter pa, String name, Object value) {
IParametersParameterComponentAdapter ppca = this.addPart(pa, name);

if (value == null) {
return;
Expand Down Expand Up @@ -124,18 +124,18 @@ protected void addPart(ParametersAdapter pa, String name, Object value) {
}
}

protected ParametersParameterComponentAdapter addSubPart(
ParametersParameterComponentAdapter ppcAdapter, String name) {
protected IParametersParameterComponentAdapter addSubPart(
IParametersParameterComponentAdapter ppcAdapter, String name) {
IBaseBackboneElement ppc = ppcAdapter.addPart();
ParametersParameterComponentAdapter ppca = this.adapterFactory.createParametersParameters(ppc);
IParametersParameterComponentAdapter ppca = this.adapterFactory.createParametersParameters(ppc);
ppca.setName(name);

return ppca;
}

@SuppressWarnings("unchecked")
protected void addSubPart(ParametersParameterComponentAdapter ppcAdapter, String name, Object value) {
ParametersParameterComponentAdapter ppca = this.addSubPart(ppcAdapter, name);
protected void addSubPart(IParametersParameterComponentAdapter ppcAdapter, String name, Object value) {
IParametersParameterComponentAdapter ppca = this.addSubPart(ppcAdapter, name);

if (value == null) {
return;
Expand Down Expand Up @@ -170,15 +170,15 @@ public List<CqlParameterDefinition> toCqlParameterDefinitions(IBaseParameters pa
return Collections.emptyList();
}

ParametersAdapter parametersAdapter = this.adapterFactory.createParameters(parameters);
IParametersAdapter parametersAdapter = this.adapterFactory.createParameters(parameters);

Map<String, List<ParametersParameterComponentAdapter>> children = parametersAdapter.getParameter().stream()
Map<String, List<IParametersParameterComponentAdapter>> children = parametersAdapter.getParameter().stream()
.map(x -> this.adapterFactory.createParametersParameters(x))
.filter(x -> x.getName() != null)
.collect(Collectors.groupingBy(ParametersParameterComponentAdapter::getName));
.collect(Collectors.groupingBy(IParametersParameterComponentAdapter::getName));

List<CqlParameterDefinition> cqlParameterDefinitions = new ArrayList<>();
for (Map.Entry<String, List<ParametersParameterComponentAdapter>> entry : children.entrySet()) {
for (Map.Entry<String, List<IParametersParameterComponentAdapter>> entry : children.entrySet()) {
// Meta data extension, if present
Optional<IBaseExtension<?, ?>> ext = entry.getValue().stream()
.filter(x -> x.hasExtension())
Expand Down Expand Up @@ -299,7 +299,7 @@ private Boolean isListType(IBaseExtension<?, ?> parameterDefinitionExtension) {
return false;
}

private Object convertToCql(ParametersParameterComponentAdapter ppca) {
private Object convertToCql(IParametersParameterComponentAdapter ppca) {
if (ppca.hasValue()) {
return this.fhirTypeConverter.toCqlType(ppca.getValue());
} else if (ppca.hasResource()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.opencds.cqf.cql.engine.fhir.converter.FhirTypeConverterFactory;
import org.opencds.cqf.cql.engine.runtime.Date;
import org.opencds.cqf.cql.engine.runtime.Interval;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory;

class CqlFhirParametersConverterTests {

Expand All @@ -37,7 +37,7 @@ class CqlFhirParametersConverterTests {
static void setup() {
FhirContext fhirContext = FhirContext.forCached(FhirVersionEnum.R4);

AdapterFactory adapterFactory = new org.opencds.cqf.fhir.utility.adapter.r4.AdapterFactory();
IAdapterFactory adapterFactory = new org.opencds.cqf.fhir.utility.adapter.r4.AdapterFactory();
FhirTypeConverter fhirTypeConverter =
new FhirTypeConverterFactory().create(fhirContext.getVersion().getVersion());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.opencds.cqf.fhir.cr.spring.fhir.adapter;

import ca.uhn.fhir.context.FhirContext;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AdapterConfiguration {

@Bean
AdapterFactory adapterFactory(FhirContext fhirContext) {
IAdapterFactory adapterFactory(FhirContext fhirContext) {
switch (fhirContext.getVersion().getVersion()) {
case DSTU3:
return new org.opencds.cqf.fhir.utility.adapter.dstu3.AdapterFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.opencds.cqf.fhir.cql.LibraryEngine;
import org.opencds.cqf.fhir.cr.common.ICpgRequest;
import org.opencds.cqf.fhir.cr.inputparameters.IInputParameterResolver;
import org.opencds.cqf.fhir.utility.adapter.QuestionnaireAdapter;
import org.opencds.cqf.fhir.utility.adapter.IQuestionnaireAdapter;

public class ApplyRequest implements ICpgRequest {
private final IBaseResource activityDefinition;
Expand Down Expand Up @@ -215,7 +215,7 @@ public IBaseResource getQuestionnaire() {
}

@Override
public QuestionnaireAdapter getQuestionnaireAdapter() {
public IQuestionnaireAdapter getQuestionnaireAdapter() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.cql.EvaluationSettings;
import org.opencds.cqf.fhir.cr.visitor.DataRequirementsVisitor;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory;

public class DataRequirementsProcessor implements IDataRequirementsProcessor {
protected final Repository repository;
Expand All @@ -29,7 +29,7 @@ public DataRequirementsProcessor(Repository repository, EvaluationSettings evalu
@Override
public IBaseResource getDataRequirements(IBaseResource resource, IBaseParameters parameters) {
return (IBaseResource) dataRequirementsVisitor.visit(
AdapterFactory.forFhirVersion(fhirVersion).createKnowledgeArtifactAdapter((IDomainResource) resource),
IAdapterFactory.forFhirVersion(fhirVersion).createKnowledgeArtifactAdapter((IDomainResource) resource),
repository,
parameters == null ? newParameters(repository.fhirContext()) : parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.opencds.cqf.cql.engine.model.ModelResolver;
import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory;

public interface IOperationRequest {
String getOperationName();
Expand All @@ -39,8 +39,8 @@ default FhirContext getFhirContext() {

void setOperationOutcome(IBaseOperationOutcome operationOutcome);

default AdapterFactory getAdapterFactory() {
return AdapterFactory.forFhirVersion(getFhirVersion());
default IAdapterFactory getAdapterFactory() {
return IAdapterFactory.forFhirVersion(getFhirVersion());
}

default void logException(String exceptionMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import org.hl7.fhir.instance.model.api.IDomainResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.opencds.cqf.fhir.utility.Constants;
import org.opencds.cqf.fhir.utility.adapter.QuestionnaireAdapter;
import org.opencds.cqf.fhir.utility.adapter.IQuestionnaireAdapter;

public interface IQuestionnaireRequest extends ICqlOperationRequest {
IBaseResource getQuestionnaire();

QuestionnaireAdapter getQuestionnaireAdapter();
IQuestionnaireAdapter getQuestionnaireAdapter();

default void addQuestionnaireItem(IBaseBackboneElement item) {
getModelResolver().setValue(getQuestionnaire(), "item", Collections.singletonList(item));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IDomainResource;
import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;
import org.opencds.cqf.fhir.utility.adapter.IAdapterFactory;
import org.opencds.cqf.fhir.utility.visitor.PackageVisitor;

public class PackageProcessor implements IPackageProcessor {
Expand Down Expand Up @@ -41,7 +41,7 @@ public IBaseBundle packageResource(IBaseResource resource, String method) {
@Override
public IBaseBundle packageResource(IBaseResource resource, IBaseParameters parameters) {
return (IBaseBundle) packageVisitor.visit(
AdapterFactory.forFhirVersion(fhirVersion).createKnowledgeArtifactAdapter((IDomainResource) resource),
IAdapterFactory.forFhirVersion(fhirVersion).createKnowledgeArtifactAdapter((IDomainResource) resource),
repository,
parameters);
}
Expand Down
Loading

0 comments on commit 057dac7

Please sign in to comment.