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

Aphl 656 propogate new version to artifact assessment #742

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.r4.model.Basic;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
Expand Down Expand Up @@ -45,6 +46,7 @@

import ca.uhn.fhir.model.api.IQueryParameterType;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
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.rest.server.exceptions.InternalErrorException;
Expand Down Expand Up @@ -170,6 +172,14 @@ private Bundle searchResourceByUrl(String url, FhirDal fhirDal) {
Bundle searchResultsBundle = (Bundle)fhirDal.search(Canonicals.getResourceType(url), searchParams);
return searchResultsBundle;
}
private Bundle searchArtifactAssessmentForArtifact(IdType reference, FhirDal fhirDal) {
Map<String, List<List<IQueryParameterType>>> searchParams = new HashMap<>();
List<IQueryParameterType> urlList = new ArrayList<>();
urlList.add(new ReferenceParam(reference));
searchParams.put("artifact", List.of(urlList));
Bundle searchResultsBundle = (Bundle)fhirDal.search("Basic", searchParams);
return searchResultsBundle;
}

private Bundle searchResourceByUrlAndStatus(String url, String status, FhirDal fhirDal) {
Map<String, List<List<IQueryParameterType>>> searchParams = new HashMap<>();
Expand Down Expand Up @@ -543,6 +553,30 @@ public Bundle createReleaseBundle(IdType idType, String version, CodeType versio
}
}
rootArtifactAdapter.setRelatedArtifact(distinctResolvedRelatedArtifacts);
// find any artifact assessments and update those as part of the bundle
this.searchArtifactAssessmentForArtifact(rootArtifact.getIdElement(), fhirDal)
.getEntry()
.stream()
// The search is on Basic resources only unless we can register the ArtifactAssessment class
.map(entry -> {
try {
return (Basic) entry.getResource();
} catch (Exception e) {
return null;
}
})
.filter(entry -> entry != null)
// convert Basic to ArtifactAssessment by transferring the extensions
.map(basic -> {
ArtifactAssessment extensionsTransferred = new ArtifactAssessment();
extensionsTransferred.setExtension(basic.getExtension());
extensionsTransferred.setId(basic.getClass().getSimpleName() + "/" + basic.getIdPart());
return extensionsTransferred;
})
.forEach(artifactComment -> {
artifactComment.setDerivedFromContentRelatedArtifact(new CanonicalType(String.format("%s|%s", rootArtifact.getUrl(), releaseVersion)));
transactionBundle.addEntry(createEntry(artifactComment));
});
return transactionBundle;
}
private void checkReleaseVersion(String version,CodeType versionBehavior) throws UnprocessableEntityException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class RepositoryService extends DaoRegistryOperationProvider {
* used to represent the proper structure.
* @return An IBaseResource that is the targeted resource, updated with the approval
*/
@Operation(name = "$approve", idempotent = true, global = true, type = MetadataResource.class)
@Operation(name = "$crmi.approve", idempotent = true, global = true, type = MetadataResource.class)
@Description(shortDefinition = "$approve", value = "Apply an approval to an existing artifact, regardless of status.")
public Bundle approveOperation(
RequestDetails requestDetails,
Expand Down Expand Up @@ -125,7 +125,7 @@ public Bundle approveOperation(
* @param version new version in the form MAJOR.MINOR.PATCH
* @return A transaction bundle result of the newly created resources
*/
@Operation(name = "$draft", idempotent = true, global = true, type = MetadataResource.class)
@Operation(name = "$crmi.draft", idempotent = true, global = true, type = MetadataResource.class)
@Description(shortDefinition = "$draft", value = "Create a new draft version of the reference artifact")
public Bundle draftOperation(RequestDetails requestDetails, @IdParam IdType theId, @OperationParam(name = "version") String version)
throws FHIRException {
Expand All @@ -142,7 +142,7 @@ public Bundle draftOperation(RequestDetails requestDetails, @IdParam IdType theI
* @param latestFromTxServer whether or not to query the TxServer if version information is missing from references
* @return A transaction bundle result of the updated resources
*/
@Operation(name = "$release", idempotent = true, global = true, type = MetadataResource.class)
@Operation(name = "$crmi.release", idempotent = true, global = true, type = MetadataResource.class)
@Description(shortDefinition = "$release", value = "Release an existing draft artifact")
public Bundle releaseOperation(
RequestDetails requestDetails,
Expand All @@ -156,7 +156,7 @@ public Bundle releaseOperation(
return transaction(this.artifactProcessor.createReleaseBundle(theId, version, versionBehavior, latestFromTxServer != null && latestFromTxServer.getValue(), fhirDal));
}

@Operation(name = "$package", idempotent = true, global = true, type = MetadataResource.class)
@Operation(name = "$crmi.package", idempotent = true, global = true, type = MetadataResource.class)
@Description(shortDefinition = "$package", value = "Package an artifact and components / dependencies")
public Bundle packageOperation(
RequestDetails requestDetails,
Expand Down Expand Up @@ -194,7 +194,7 @@ public Bundle packageOperation(
}


@Operation(name = "$revise", idempotent = true, global = true, type = MetadataResource.class)
@Operation(name = "$crmi.revise", idempotent = true, global = true, type = MetadataResource.class)
@Description(shortDefinition = "$revise", value = "Update an existing artifact in 'draft' status")
public IBaseResource reviseOperation(RequestDetails requestDetails, @OperationParam(name = "resource") IBaseResource resource)
throws FHIRException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,41 @@ public ArtifactAssessment createArtifactComment(ArtifactAssessmentContentInforma
}
return this;
}
public Optional<RelatedArtifact> getDerivedFromContentRelatedArtifact() {
Optional<RelatedArtifact> returnedRelatedArtifact = Optional.empty();
Optional<Extension> content = Optional.ofNullable(this.getExtensionByUrl(CONTENT));
if (content.isPresent()) {
Optional<Extension> maybeRelatedArtifact = content.get().getExtension().stream()
.filter(extension -> extension.getUrl().equals(ArtifactAssessmentContentExtension.RELATEDARTIFACT) && ((RelatedArtifact)extension.getValue()).getType().equals(RelatedArtifactType.DERIVEDFROM))
.findFirst();
if (maybeRelatedArtifact.isPresent()) {
RelatedArtifact derivedFromArtifact = (RelatedArtifact) maybeRelatedArtifact.get().getValue();
returnedRelatedArtifact = Optional.of(derivedFromArtifact);
}
}
return returnedRelatedArtifact;
}
public ArtifactAssessment setDerivedFromContentRelatedArtifact(CanonicalType targetUri){
Optional<RelatedArtifact> existingRelatedArtifact = this.getDerivedFromContentRelatedArtifact();
if (existingRelatedArtifact.isPresent()) {
RelatedArtifact derivedFromArtifact = existingRelatedArtifact.get();
derivedFromArtifact.setResourceElement(targetUri);
} else {
Extension content = this.getExtensionByUrl(CONTENT);
if (content == null) {
content = new Extension(CONTENT);
this.addExtension(content);
}
// this is duplicated from the addRelatedArtifact method
// since otherwise we get ClassCastExceptions when trying
// to Cast from Basic to ArtifactAssessment or its Extension subclasses
RelatedArtifact newRelatedArtifact = new RelatedArtifact();
newRelatedArtifact.setType(RelatedArtifactType.DERIVEDFROM);
newRelatedArtifact.setResourceElement(targetUri);
content.addExtension(ArtifactAssessmentContentExtension.RELATEDARTIFACT,newRelatedArtifact);
}
return this;
}
public boolean checkArtifactCommentParams(String infoType, String summary, String artifactReference, String citationRelatedArtifactUrl, String derivedFromRelatedArtifactUrl, String authorReference){
boolean infoTypeCorrect = false;
boolean summaryCorrect = false;
Expand Down
Loading