Skip to content

Commit

Permalink
Release operation updates (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Stevenson authored Mar 23, 2023
1 parent 47b5a7a commit 9ff03b2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.hl7.fhir.r4.model.MetadataResource;
import org.hl7.fhir.r4.model.PlanDefinition;
import org.hl7.fhir.r4.model.RelatedArtifact;
import org.hl7.fhir.r4.model.ValueSet;

public class KnowledgeArtifactAdapter<T extends MetadataResource> {
protected T resource;
Expand Down Expand Up @@ -117,6 +118,8 @@ public List<RelatedArtifact> getDependencies() {
return getDependenciesOfMeasure();
case "PlanDefinition":
return getDependenciesOfPlanDefinition();
case "ValueSet":
return getDependenciesOfValueSet();
default :
return new ArrayList<>();
}
Expand Down Expand Up @@ -183,6 +186,27 @@ private List<RelatedArtifact> getDependenciesOfPlanDefinition() {
return dependencies;
}

private List<RelatedArtifact> getDependenciesOfValueSet() {
List<RelatedArtifact> dependencies = new ArrayList<>();
ValueSet valueSet = (ValueSet)resource;

if (valueSet.hasCompose() && valueSet.getCompose().hasInclude()) {
for (var conceptSet : valueSet.getCompose().getInclude()) {
if (conceptSet.hasValueSet()) {
for (var valueSetRef : conceptSet.getValueSet()) {
dependencies.add(
new RelatedArtifact()
.setType(RelatedArtifact.RelatedArtifactType.DEPENDSON)
.setResource(valueSetRef.getValue())
);
}
}
}
}

return dependencies;
}

public List<ContactDetail> getEndorser() {
switch (resource.getClass().getSimpleName()) {
case "Library":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ private void processReferencedResourceForDraft(FhirDal fhirDal, Bundle reference

/* $release */
public MetadataResource releaseVersion(IdType idType, String version, CodeType versionBehavior, boolean latestFromTxServer, FhirDal fhirDal) {
// TODO: This check is to avoid partial releases and should be removed once the argument is supported (or it is transactional).
if (latestFromTxServer) {
throw new NotImplementedException("Support for 'latestFromTxServer' is not yet implemented.");
}

if (version == null || version.isEmpty()) {
throw new InvalidOperatorArgument("version must be provided as an argument to the $release operation.");
}
Expand Down Expand Up @@ -260,6 +265,7 @@ public MetadataResource releaseVersion(IdType idType, String version, CodeType v
String.format("The artifact was approved on '%s', but was last modified on '%s'. An approval must be provided after the most-recent update.", currentApprovalDate, rootArtifact.getDate()));
}

// Determine which version should be used.
String existingVersion = rootArtifact.hasVersion() ? rootArtifact.getVersion() : null;
String releaseVersion = getReleaseVersion(version, versionBehavior, existingVersion);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ public Library draftOperation(RequestDetails requestDetails, @IdParam IdType the

@Operation(name = "$release", idempotent = true, global = true, type = MetadataResource.class)
@Description(shortDefinition = "$release", value = "Release an existing draft artifact")
public Library releaseOperation(RequestDetails requestDetails,
@IdParam IdType theId,
@OperationParam(name = "version") String version,
@OperationParam(name = "version-behavior") CodeType versionBehavior,
@OperationParam(name = "latest-from-tx-server", typeName = "Boolean") IPrimitiveType<Boolean> latestFromTxServer)
public Library releaseOperation(
RequestDetails requestDetails,
@IdParam IdType theId,
@OperationParam(name = "version") String version,
@OperationParam(name = "version-behavior") CodeType versionBehavior,
@OperationParam(name = "latest-from-tx-server", typeName = "Boolean") IPrimitiveType<Boolean> latestFromTxServer)
throws FHIRException {

FhirDal fhirDal = this.fhirDalFactory.create(requestDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void release_missing_approvalDate_validation_test() {
Parameters params1 = parameters(
stringPart("version", "1234"),
codePart("version-behavior", "default"),
booleanPart("latest-from-tx-server", true)
booleanPart("latest-from-tx-server", false)
);

try {
Expand Down

0 comments on commit 9ff03b2

Please sign in to comment.