Skip to content
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this file seem like formatting changes? Do we really need to make these changes as part of this PR?

Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public interface IAdapter<T extends IBase> {
*/
T get();

public FhirContext fhirContext();
FhirContext fhirContext();

public ModelResolver getModelResolver();
ModelResolver getModelResolver();

public default void setExtension(List<? extends IBaseExtension<?, ?>> extensions) {
default void setExtension(List<? extends IBaseExtension<?, ?>> extensions) {
try {
getModelResolver().setValue(get(), "extension", null);
getModelResolver().setValue(get(), "extension", extensions);
Expand All @@ -46,7 +46,7 @@ public default void setExtension(List<? extends IBaseExtension<?, ?>> extensions
}
}

public default <E extends IBaseExtension<?, ?>> void addExtension(E extension) {
default <E extends IBaseExtension<?, ?>> void addExtension(E extension) {
try {
getModelResolver().setValue(get(), "extension", Collections.singletonList(extension));
} catch (Exception e) {
Expand All @@ -55,63 +55,63 @@ public default void setExtension(List<? extends IBaseExtension<?, ?>> extensions
}
}

public default boolean hasExtension() {
default boolean hasExtension() {
return !getExtension().isEmpty();
}

public default boolean hasExtension(String url) {
default boolean hasExtension(String url) {
return hasExtension(get(), url);
}

public default <E extends IBaseExtension<?, ?>> List<E> getExtension() {
default <E extends IBaseExtension<?, ?>> List<E> getExtension() {
return getExtension(get());
}

public default <E extends IBaseExtension<?, ?>> E getExtensionByUrl(String url) {
default <E extends IBaseExtension<?, ?>> E getExtensionByUrl(String url) {
return getExtensionByUrl(get(), url);
}

public default <E extends IBaseExtension<?, ?>> List<E> getExtensionsByUrl(String url) {
default <E extends IBaseExtension<?, ?>> List<E> getExtensionsByUrl(String url) {
return getExtensionsByUrl(get(), url);
}

@SuppressWarnings("unchecked")
public default <E extends IBaseExtension<?, ?>> List<E> getExtension(IBase base) {
default <E extends IBaseExtension<?, ?>> List<E> getExtension(IBase base) {
return resolvePathList(base, "extension").stream().map(e -> (E) e).collect(Collectors.toList());
}

@SuppressWarnings("unchecked")
public default <E extends IBaseExtension<?, ?>> List<E> getExtensionsByUrl(IBase base, String url) {
default <E extends IBaseExtension<?, ?>> List<E> getExtensionsByUrl(IBase base, String url) {
return getExtension(base).stream()
.filter(e -> e.getUrl().equals(url))
.map(e -> (E) e)
.collect(Collectors.toList());
}

@SuppressWarnings("unchecked")
public default <E extends IBaseExtension<?, ?>> E getExtensionByUrl(IBase base, String url) {
default <E extends IBaseExtension<?, ?>> E getExtensionByUrl(IBase base, String url) {
return getExtensionsByUrl(base, url).stream()
.map(e -> (E) e)
.findFirst()
.orElse(null);
}

public default Boolean hasExtension(IBase base, String url) {
default Boolean hasExtension(IBase base, String url) {
return getExtension(base).stream().anyMatch(e -> e.getUrl().equals(url));
}

@SuppressWarnings("unchecked")
public default List<IBase> resolvePathList(IBase base, String path) {
default List<IBase> resolvePathList(IBase base, String path) {
var pathResult = getModelResolver().resolvePath(base, path);
return pathResult instanceof List ? (List<IBase>) pathResult : new ArrayList<>();
}

@SuppressWarnings("unchecked")
public default <B extends IBase> List<B> resolvePathList(IBase base, String path, Class<B> clazz) {
default <B extends IBase> List<B> resolvePathList(IBase base, String path, Class<B> clazz) {
return resolvePathList(base, path).stream().map(i -> (B) i).collect(Collectors.toList());
}

public default String resolvePathString(IBase base, String path) {
default String resolvePathString(IBase base, String path) {
var result = resolvePath(base, path);
if (result == null) {
return null;
Expand All @@ -127,96 +127,72 @@ public default String resolvePathString(IBase base, String path) {
}
}

public default IBase resolvePath(IBase base, String path) {
default IBase resolvePath(IBase base, String path) {
return (IBase) getModelResolver().resolvePath(base, path);
}

@SuppressWarnings("unchecked")
public default <B extends IBase> B resolvePath(IBase base, String path, Class<B> clazz) {
default <B extends IBase> B resolvePath(IBase base, String path, Class<B> clazz) {
return (B) resolvePath(base, path);
}

@SuppressWarnings("unchecked")
static <T extends ICompositeType> T newPeriod(FhirVersionEnum version) {
switch (version) {
case DSTU3:
return (T) new org.hl7.fhir.dstu3.model.Period();
case R4:
return (T) new org.hl7.fhir.r4.model.Period();
case R5:
return (T) new org.hl7.fhir.r5.model.Period();
default:
throw new UnprocessableEntityException(UNSUPPORTED_VERSION.formatted(version.toString()));
}
return switch (version) {
case DSTU3 -> (T) new org.hl7.fhir.dstu3.model.Period();
case R4 -> (T) new org.hl7.fhir.r4.model.Period();
case R5 -> (T) new org.hl7.fhir.r5.model.Period();
default -> throw new UnprocessableEntityException(String.format(UNSUPPORTED_VERSION, version.toString()));
};
}

@SuppressWarnings("unchecked")
static <T extends IPrimitiveType<String>> T newStringType(FhirVersionEnum version, String string) {
switch (version) {
case DSTU3:
return (T) new org.hl7.fhir.dstu3.model.StringType(string);
case R4:
return (T) new org.hl7.fhir.r4.model.StringType(string);
case R5:
return (T) new org.hl7.fhir.r5.model.StringType(string);
default:
throw new UnprocessableEntityException(UNSUPPORTED_VERSION.formatted(version.toString()));
}
return switch (version) {
case DSTU3 -> (T) new org.hl7.fhir.dstu3.model.StringType(string);
case R4 -> (T) new org.hl7.fhir.r4.model.StringType(string);
case R5 -> (T) new org.hl7.fhir.r5.model.StringType(string);
default -> throw new UnprocessableEntityException(String.format(UNSUPPORTED_VERSION, version.toString()));
};
}

@SuppressWarnings("unchecked")
static <T extends IPrimitiveType<String>> T newUriType(FhirVersionEnum version, String string) {
switch (version) {
case DSTU3:
return (T) new org.hl7.fhir.dstu3.model.UriType(string);
case R4:
return (T) new org.hl7.fhir.r4.model.UriType(string);
case R5:
return (T) new org.hl7.fhir.r5.model.UriType(string);
default:
throw new UnprocessableEntityException(UNSUPPORTED_VERSION.formatted(version.toString()));
}
return switch (version) {
case DSTU3 -> (T) new org.hl7.fhir.dstu3.model.UriType(string);
case R4 -> (T) new org.hl7.fhir.r4.model.UriType(string);
case R5 -> (T) new org.hl7.fhir.r5.model.UriType(string);
default -> throw new UnprocessableEntityException(String.format(UNSUPPORTED_VERSION, version.toString()));
};
}

@SuppressWarnings("unchecked")
static <T extends IPrimitiveType<String>> T newUrlType(FhirVersionEnum version, String string) {
switch (version) {
case DSTU3:
return (T) new org.hl7.fhir.dstu3.model.UriType(string);
case R4:
return (T) new org.hl7.fhir.r4.model.UrlType(string);
case R5:
return (T) new org.hl7.fhir.r5.model.UrlType(string);
default:
throw new UnprocessableEntityException(UNSUPPORTED_VERSION.formatted(version.toString()));
}
return switch (version) {
case DSTU3 -> (T) new org.hl7.fhir.dstu3.model.UriType(string);
case R4 -> (T) new org.hl7.fhir.r4.model.UrlType(string);
case R5 -> (T) new org.hl7.fhir.r5.model.UrlType(string);
default -> throw new UnprocessableEntityException(String.format(UNSUPPORTED_VERSION, version.toString()));
};
}

@SuppressWarnings("unchecked")
static <T extends IPrimitiveType<Date>> T newDateType(FhirVersionEnum version, Date date) {
switch (version) {
case DSTU3:
return (T) new org.hl7.fhir.dstu3.model.DateType(date);
case R4:
return (T) new org.hl7.fhir.r4.model.DateType(date);
case R5:
return (T) new org.hl7.fhir.r5.model.DateType(date);
default:
throw new UnprocessableEntityException(UNSUPPORTED_VERSION.formatted(version.toString()));
}
return switch (version) {
case DSTU3 -> (T) new org.hl7.fhir.dstu3.model.DateType(date);
case R4 -> (T) new org.hl7.fhir.r4.model.DateType(date);
case R5 -> (T) new org.hl7.fhir.r5.model.DateType(date);
default -> throw new UnprocessableEntityException(String.format(UNSUPPORTED_VERSION, version.toString()));
};
}

@SuppressWarnings("unchecked")
static <T extends IPrimitiveType<Date>> T newDateTimeType(FhirVersionEnum version, Date date) {
switch (version) {
case DSTU3:
return (T) new org.hl7.fhir.dstu3.model.DateTimeType(date);
case R4:
return (T) new org.hl7.fhir.r4.model.DateTimeType(date);
case R5:
return (T) new org.hl7.fhir.r5.model.DateTimeType(date);
default:
throw new UnprocessableEntityException(UNSUPPORTED_VERSION.formatted(version.toString()));
}
return switch (version) {
case DSTU3 -> (T) new org.hl7.fhir.dstu3.model.DateTimeType(date);
case R4 -> (T) new org.hl7.fhir.r4.model.DateTimeType(date);
case R5 -> (T) new org.hl7.fhir.r5.model.DateTimeType(date);
default -> throw new UnprocessableEntityException(String.format(UNSUPPORTED_VERSION, version.toString()));
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ static IResourceAdapter createAdapterForResource(IBaseResource resource) {
*/
ILibraryAdapter createLibrary(IBaseResource library);

/**
* Creates an adapter that exposes common Measure operations across multiple versions of FHIR
*
* @param measure a FHIR Measure Resource
* @return an adapter exposing common api calls
*/
IMeasureAdapter createMeasure(IBaseResource measure);

/**
* Creates an adapter that exposes common PlanDefinition operations across multiple versions of FHIR
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.opencds.cqf.fhir.utility.Canonicals;
import org.opencds.cqf.fhir.utility.Constants;
import org.opencds.cqf.fhir.utility.SearchHelper;
import org.opencds.cqf.fhir.utility.VersionComparator;
import org.opencds.cqf.fhir.utility.VersionUtilities;
import org.opencds.cqf.fhir.utility.Versions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -338,12 +338,11 @@ static boolean isSupportedMetadataResource(IBaseResource resource) {
}

static Optional<IDomainResource> findLatestVersion(IBaseBundle bundle) {
var versionComparator = new VersionComparator();
var sorted = BundleHelper.getEntryResources(bundle).stream()
.filter(IKnowledgeArtifactAdapter::isSupportedMetadataResource)
.map(r -> (IKnowledgeArtifactAdapter) IAdapterFactory.forFhirVersion(r.getStructureFhirVersionEnum())
.createResource(r))
.sorted((a, b) -> versionComparator.compare(a.getVersion(), b.getVersion()))
.sorted((a, b) -> Versions.compareVersions(a.getVersion(), b.getVersion()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question, is this change needed by this PR?

.toList();
if (!sorted.isEmpty()) {
return Optional.of(sorted.get(sorted.size() - 1).get());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.opencds.cqf.fhir.utility.adapter;

import java.util.List;

/**
* This interface exposes common functionality across all FHIR Questionnaire versions.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment seems wrong?

public interface IMeasureAdapter extends IKnowledgeArtifactAdapter {}
public interface IMeasureAdapter extends IKnowledgeArtifactAdapter {
List<String> getLibrary();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.opencds.cqf.fhir.utility.adapter.IEndpointAdapter;
import org.opencds.cqf.fhir.utility.adapter.IKnowledgeArtifactAdapter;
import org.opencds.cqf.fhir.utility.adapter.ILibraryAdapter;
import org.opencds.cqf.fhir.utility.adapter.IMeasureAdapter;
import org.opencds.cqf.fhir.utility.adapter.IParametersAdapter;
import org.opencds.cqf.fhir.utility.adapter.IParametersParameterComponentAdapter;
import org.opencds.cqf.fhir.utility.adapter.IPlanDefinitionAdapter;
Expand Down Expand Up @@ -82,6 +83,11 @@ public ILibraryAdapter createLibrary(IBaseResource library) {
return new LibraryAdapter((IDomainResource) library);
}

@Override
public IMeasureAdapter createMeasure(IBaseResource measure) {
return new MeasureAdapter((IDomainResource) measure);
}

@Override
public IAttachmentAdapter createAttachment(ICompositeType attachment) {
return new AttachmentAdapter(attachment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public Measure copy() {
private Library effectiveDataRequirements;
private LibraryAdapter effectiveDataRequirementsAdapter;

@Override
public List<String> getLibrary() {
return getMeasure().getLibrary().stream().map(Reference::getReference).toList();
}

private String getEdrReferenceString(Extension edrExtension) {
return edrExtension.getUrl().contains("cqfm")
? ((Reference) edrExtension.getValue()).getReference()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.opencds.cqf.fhir.utility.adapter.IEndpointAdapter;
import org.opencds.cqf.fhir.utility.adapter.IKnowledgeArtifactAdapter;
import org.opencds.cqf.fhir.utility.adapter.ILibraryAdapter;
import org.opencds.cqf.fhir.utility.adapter.IMeasureAdapter;
import org.opencds.cqf.fhir.utility.adapter.IParametersAdapter;
import org.opencds.cqf.fhir.utility.adapter.IParametersParameterComponentAdapter;
import org.opencds.cqf.fhir.utility.adapter.IPlanDefinitionAdapter;
Expand Down Expand Up @@ -82,6 +83,11 @@ public ILibraryAdapter createLibrary(IBaseResource library) {
return new LibraryAdapter((IDomainResource) library);
}

@Override
public IMeasureAdapter createMeasure(IBaseResource measure) {
return new MeasureAdapter((IDomainResource) measure);
}

@Override
public IAttachmentAdapter createAttachment(ICompositeType attachment) {
return new AttachmentAdapter(attachment);
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a PR that is just for the Measure adapter?

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Library;
import org.hl7.fhir.r4.model.Measure;
import org.hl7.fhir.r4.model.PrimitiveType;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.RelatedArtifact;
import org.hl7.fhir.r4.model.UriType;
Expand Down Expand Up @@ -50,6 +51,13 @@ public Measure copy() {
private Library effectiveDataRequirements;
private LibraryAdapter effectiveDataRequirementsAdapter;

@Override
public List<String> getLibrary() {
return getMeasure().getLibrary().stream()
.map(PrimitiveType::getValueAsString)
.toList();
}

private String getEdrReferenceString(Extension edrExtension) {
return edrExtension.getUrl().contains("cqfm")
? ((Reference) edrExtension.getValue()).getReference()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.opencds.cqf.fhir.utility.adapter.IEndpointAdapter;
import org.opencds.cqf.fhir.utility.adapter.IKnowledgeArtifactAdapter;
import org.opencds.cqf.fhir.utility.adapter.ILibraryAdapter;
import org.opencds.cqf.fhir.utility.adapter.IMeasureAdapter;
import org.opencds.cqf.fhir.utility.adapter.IParametersAdapter;
import org.opencds.cqf.fhir.utility.adapter.IParametersParameterComponentAdapter;
import org.opencds.cqf.fhir.utility.adapter.IPlanDefinitionAdapter;
Expand Down Expand Up @@ -82,6 +83,11 @@ public ILibraryAdapter createLibrary(IBaseResource library) {
return new LibraryAdapter((IDomainResource) library);
}

@Override
public IMeasureAdapter createMeasure(IBaseResource measure) {
return new MeasureAdapter((IDomainResource) measure);
}

@Override
public IAttachmentAdapter createAttachment(ICompositeType attachment) {
return new AttachmentAdapter(attachment);
Expand Down
Loading
Loading