Skip to content

Commit

Permalink
Aphl 796 update package parameters (#759)
Browse files Browse the repository at this point in the history
* [APHL-796] match package operation to specification

* [APHL-796] update names

---------

Co-authored-by: taha.attari@smilecdr.com <taha.attari@smilecdr.com>
Co-authored-by: Adam Stevenson <stevenson_adam@yahoo.com>
  • Loading branch information
3 people authored Jan 12, 2024
1 parent c77ac3f commit 39cd3ab
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,9 @@ private void checkNonExperimental(MetadataResource resource, CRMIReleaseExperime
}

/* $package */
public Bundle createPackageBundle(IdType id, FhirDal fhirDal, List<String> capability, List<String> include, List<CanonicalType> canonicalVersion, List<CanonicalType> checkCanonicalVersion, List<CanonicalType> forceCanonicalVersion, Integer count, Integer offset, Endpoint contentEndpoint, Endpoint terminologyEndpoint, Boolean packageOnly) throws NotImplementedOperationException, UnprocessableEntityException, IllegalArgumentException {
if (contentEndpoint != null || terminologyEndpoint != null) {
throw new NotImplementedOperationException("This repository is not implementing custom Content and Terminology endpoints at this time");
public Bundle createPackageBundle(IdType id, FhirDal fhirDal, List<String> capability, List<String> include, List<CanonicalType> artifactVersion, List<CanonicalType> checkArtifactVersion, List<CanonicalType> forceArtifactVersion, Integer count, Integer offset, String artifactRoute, String endpointUri, Endpoint artifactEndpoint, Endpoint terminologyEndpoint, Boolean packageOnly) throws NotImplementedOperationException, UnprocessableEntityException, IllegalArgumentException {
if (artifactRoute != null || endpointUri != null || artifactEndpoint != null || terminologyEndpoint != null) {
throw new NotImplementedOperationException("This repository is not implementing custom Artifact and Terminology endpoints at this time");
}
if (packageOnly != null) {
throw new NotImplementedOperationException("This repository is not implementing packageOnly at this time");
Expand All @@ -833,14 +833,14 @@ public Bundle createPackageBundle(IdType id, FhirDal fhirDal, List<String> capab
&& include.size() == 1
&& include.stream().anyMatch((includedType) -> includedType.equals("artifact"))) {
findUnsupportedCapability(resource, capability);
processCanonicals(resource, canonicalVersion, checkCanonicalVersion, forceCanonicalVersion);
processCanonicals(resource, artifactVersion, checkArtifactVersion, forceArtifactVersion);
BundleEntryComponent entry = createEntry(resource);
entry.getRequest().setUrl(resource.getResourceType() + "/" + resource.getIdElement().getIdPart());
entry.getRequest().setMethod(HTTPVerb.POST);
entry.getRequest().setIfNoneExist("url="+resource.getUrl()+"&version="+resource.getVersion());
packagedBundle.addEntry(entry);
} else {
recursivePackage(resource, packagedBundle, fhirDal, capability, include, canonicalVersion, checkCanonicalVersion, forceCanonicalVersion);
recursivePackage(resource, packagedBundle, fhirDal, capability, include, artifactVersion, checkArtifactVersion, forceArtifactVersion);
List<BundleEntryComponent> included = findUnsupportedInclude(packagedBundle.getEntry(),include);
packagedBundle.setEntry(included);
}
Expand Down Expand Up @@ -1022,13 +1022,13 @@ void recursivePackage(
List<String> capability,
List<String> include,
List<CanonicalType> canonicalVersion,
List<CanonicalType> checkCanonicalVersion,
List<CanonicalType> forceCanonicalVersion
List<CanonicalType> checkArtifactVersion,
List<CanonicalType> forceArtifactVersion
) throws PreconditionFailedException{
if (resource != null) {
KnowledgeArtifactAdapter<MetadataResource> adapter = new KnowledgeArtifactAdapter<MetadataResource>(resource);
findUnsupportedCapability(resource, capability);
processCanonicals(resource, canonicalVersion, checkCanonicalVersion, forceCanonicalVersion);
processCanonicals(resource, canonicalVersion, checkArtifactVersion, forceArtifactVersion);
boolean entryExists = bundle.getEntry().stream()
.map(e -> (MetadataResource)e.getResource())
.filter(mr -> mr.getUrl() != null && mr.getVersion() != null)
Expand All @@ -1043,7 +1043,7 @@ void recursivePackage(
combineComponentsAndDependencies(adapter).stream()
.map(ra -> searchResourceByUrl(ra.getResource(), fhirDal))
.map(searchBundle -> searchBundle.getEntry().stream().findFirst().orElseGet(()-> new BundleEntryComponent()).getResource())
.forEach(component -> recursivePackage((MetadataResource)component, bundle, fhirDal, capability, include, canonicalVersion, checkCanonicalVersion, forceCanonicalVersion));
.forEach(component -> recursivePackage((MetadataResource)component, bundle, fhirDal, capability, include, canonicalVersion, checkArtifactVersion, forceArtifactVersion));
}
}
private List<RelatedArtifact> combineComponentsAndDependencies(KnowledgeArtifactAdapter<MetadataResource> adapter) {
Expand Down Expand Up @@ -1076,10 +1076,10 @@ private void findUnsupportedCapability(MetadataResource resource, List<String> c
}
}

private void processCanonicals(MetadataResource resource, List<CanonicalType> canonicalVersion, List<CanonicalType> checkCanonicalVersion, List<CanonicalType> forceCanonicalVersion) throws PreconditionFailedException {
if (checkCanonicalVersion != null) {
private void processCanonicals(MetadataResource resource, List<CanonicalType> canonicalVersion, List<CanonicalType> checkArtifactVersion, List<CanonicalType> forceArtifactVersion) throws PreconditionFailedException {
if (checkArtifactVersion != null) {
// check throws an error
findVersionInListMatchingResource(checkCanonicalVersion, resource)
findVersionInListMatchingResource(checkArtifactVersion, resource)
.ifPresent((version) -> {
if (!resource.getVersion().equals(version)) {
throw new PreconditionFailedException(String.format("Resource with url '%s' has version '%s' but checkVersion specifies '%s'",
Expand All @@ -1089,9 +1089,9 @@ private void processCanonicals(MetadataResource resource, List<CanonicalType> ca
));
}
});
} else if (forceCanonicalVersion != null) {
} else if (forceArtifactVersion != null) {
// force just does a silent override
findVersionInListMatchingResource(forceCanonicalVersion, resource)
findVersionInListMatchingResource(forceArtifactVersion, resource)
.ifPresent((version) -> resource.setVersion(version));
} else if (canonicalVersion != null && !resource.hasVersion()) {
// canonicalVersion adds a version if it's missing
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.opencds.cqf.ruler.cr;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

import org.cqframework.fhir.api.FhirDal;
import org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService;
Expand All @@ -23,8 +25,10 @@
import org.hl7.fhir.r4.model.MetadataResource;
import org.hl7.fhir.r4.model.OperationOutcome;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.UriType;
import org.hl7.fhir.r4.model.ValueSet;
import org.opencds.cqf.cql.evaluator.fhir.util.Canonicals;
import org.opencds.cqf.ruler.cr.r4.ArtifactAssessment;
Expand Down Expand Up @@ -197,30 +201,36 @@ public Bundle packageOperation(
@IdParam IdType theId,
// TODO: $package - should capability be CodeType?
@OperationParam(name = "capability") List<String> capability,
@OperationParam(name = "canonicalVersion") List<CanonicalType> canonicalVersion,
@OperationParam(name = "checkCanonicalVersion") List<CanonicalType> checkCanonicalVersion,
@OperationParam(name = "forceCanonicalVersion") List<CanonicalType> forceCanonicalVersion,
@OperationParam(name = "artifactVersion") List<CanonicalType> artifactVersion,
@OperationParam(name = "checkArtifactVersion") List<CanonicalType> checkArtifactVersion,
@OperationParam(name = "forceArtifactVersion") List<CanonicalType> forceArtifactVersion,
// TODO: $package - should include be CodeType?
@OperationParam(name = "include") List<String> include,
@OperationParam(name = "manifest") CanonicalType manifest,
@OperationParam(name = "offset", typeName = "Integer") IPrimitiveType<Integer> offset,
@OperationParam(name = "count", typeName = "Integer") IPrimitiveType<Integer> count,
@OperationParam(name = "packageOnly", typeName = "Boolean") IPrimitiveType<Boolean> packageOnly,
@OperationParam(name = "contentEndpoint") Endpoint contentEndpoint,
@OperationParam(name = "artifactEndpointConfiguration") ParametersParameterComponent artifactEndpointConfiguration,
@OperationParam(name = "terminologyEndpoint") Endpoint terminologyEndpoint
) throws FHIRException {
FhirDal fhirDal = this.fhirDalFactory.create(requestDetails);
List<ParametersParameterComponent> artifactEndpointParts = Optional.ofNullable(artifactEndpointConfiguration).map(config -> config.getPart()).orElse(new ArrayList<ParametersParameterComponent>());
String artifactRoute = artifactEndpointParts.stream().filter(part -> part.getName().equals("artifactRoute")).map(part -> ((UriType)part.getValue()).getValue()).findAny().orElse(null);
String endpointUri = artifactEndpointParts.stream().filter(part -> part.getName().equals("endpointUri")).map(part -> ((UriType)part.getValue()).getValue()).findAny().orElse(null);
Endpoint artifactEndpoint = artifactEndpointParts.stream().filter(part -> part.getName().equals("endpoint")).map(part -> (Endpoint)part.getResource()).findAny().orElse(null);
return this.artifactProcessor.createPackageBundle(
theId,
fhirDal,
capability,
include,
canonicalVersion,
checkCanonicalVersion,
forceCanonicalVersion,
artifactVersion,
checkArtifactVersion,
forceArtifactVersion,
count != null ? count.getValue() : null,
offset != null ? offset.getValue() : null,
contentEndpoint,
artifactRoute,
endpointUri,
artifactEndpoint,
terminologyEndpoint,
packageOnly != null ? packageOnly.getValue() : null
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,8 @@ void packageOperation_should_apply_check_force_canonicalVersions() {
loadTransaction("ersd-active-transaction-no-versions.json");
String versionToUpdateTo = "1.3.1.23";
Parameters params = parameters(
part("canonicalVersion", new CanonicalType("http://to-add-missing-version/PlanDefinition/us-ecr-specification|" + versionToUpdateTo)),
part("canonicalVersion", new CanonicalType("http://to-add-missing-version/ValueSet/dxtc|" + versionToUpdateTo))
part("artifactVersion", new CanonicalType("http://to-add-missing-version/PlanDefinition/us-ecr-specification|" + versionToUpdateTo)),
part("artifactVersion", new CanonicalType("http://to-add-missing-version/ValueSet/dxtc|" + versionToUpdateTo))
);
Bundle updatedCanonicalVersionPackage = getClient().operation()
.onInstance(specificationLibReference)
Expand All @@ -993,7 +993,7 @@ void packageOperation_should_apply_check_force_canonicalVersions() {
assertTrue(updatedResource.getVersion().equals(versionToUpdateTo));
}
params = parameters(
part("checkCanonicalVersion", new CanonicalType("http://to-check-version/Library/SpecificationLibrary|1.3.1"))
part("checkArtifactVersion", new CanonicalType("http://to-check-version/Library/SpecificationLibrary|1.3.1"))
);
String correctCheckVersion = "2022-10-19";
PreconditionFailedException checkCanonicalThrewError = null;
Expand All @@ -1009,7 +1009,7 @@ void packageOperation_should_apply_check_force_canonicalVersions() {
}
assertNotNull(checkCanonicalThrewError);
params = parameters(
part("checkCanonicalVersion", new CanonicalType("http://to-check-version/Library/SpecificationLibrary|" + correctCheckVersion))
part("checkArtifactVersion", new CanonicalType("http://to-check-version/Library/SpecificationLibrary|" + correctCheckVersion))
);
Bundle noErrorCheckCanonicalPackage = getClient().operation()
.onInstance(specificationLibReference)
Expand All @@ -1025,7 +1025,7 @@ void packageOperation_should_apply_check_force_canonicalVersions() {
assertTrue(checkedVersionResource.get().getVersion().equals(correctCheckVersion));
String versionToForceTo = "1.1.9.23";
params = parameters(
part("forceCanonicalVersion", new CanonicalType("http://to-force-version/Library/rctc|" + versionToForceTo))
part("forceArtifactVersion", new CanonicalType("http://to-force-version/Library/rctc|" + versionToForceTo))
);
Bundle forcedVersionPackage = getClient().operation()
.onInstance(specificationLibReference)
Expand Down

0 comments on commit 39cd3ab

Please sign in to comment.