-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
APHL-1023-withdraw_draft_programs (#511)
* initial withdraw implementation * add test for non-draft library + only depends-on cascade delete * first check request resource id to work with * use specific withdraw resource file * return bundle and delete on ecr * fix in memory fhir repo * run code formatting * add InMemoryRepository tests * reformat code * add getEntryRequestId & isEntryRequestDelete tests * run code check * throw error if delete request entry is not present * artifacts that is owned and has composed-of relationship * run code check * update Exception thrown in in memory repo * run code check * add unsupported fhir version tests to bundle helper * rename getComponents method name --------- Co-authored-by: Ivan Baisi <[email protected]>
- Loading branch information
1 parent
8dd94d5
commit 068cc68
Showing
9 changed files
with
12,785 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
cqf-fhir-utility/src/main/java/org/opencds/cqf/fhir/utility/visitor/WithdrawVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.opencds.cqf.fhir.utility.visitor; | ||
|
||
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import org.hl7.fhir.instance.model.api.IBase; | ||
import org.hl7.fhir.instance.model.api.IBaseParameters; | ||
import org.hl7.fhir.instance.model.api.IDomainResource; | ||
import org.opencds.cqf.fhir.api.Repository; | ||
import org.opencds.cqf.fhir.utility.BundleHelper; | ||
import org.opencds.cqf.fhir.utility.PackageHelper; | ||
import org.opencds.cqf.fhir.utility.adapter.KnowledgeArtifactAdapter; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class WithdrawVisitor implements KnowledgeArtifactVisitor { | ||
private Logger log = LoggerFactory.getLogger(WithdrawVisitor.class); | ||
String isOwnedUrl = "http://hl7.org/fhir/StructureDefinition/crmi-isOwned"; | ||
|
||
@Override | ||
public IBase visit( | ||
KnowledgeArtifactAdapter rootAdapter, Repository repository, IBaseParameters operationParameters) { | ||
if (!rootAdapter.getStatus().equals("draft")) { | ||
throw new PreconditionFailedException("Cannot withdraw an artifact that is not in draft status"); | ||
} | ||
var resToUpdate = new ArrayList<IDomainResource>(); | ||
resToUpdate.add(rootAdapter.get()); | ||
|
||
var resourcesToUpdate = getComponents(rootAdapter, repository, resToUpdate); | ||
|
||
var fhirVersion = rootAdapter.get().getStructureFhirVersionEnum(); | ||
|
||
var transactionBundle = BundleHelper.newBundle(fhirVersion, null, "transaction"); | ||
for (var artifact : resourcesToUpdate) { | ||
var entry = PackageHelper.deleteEntry(artifact); | ||
BundleHelper.addEntry(transactionBundle, entry); | ||
} | ||
|
||
return repository.transaction(transactionBundle); | ||
} | ||
|
||
private List<IDomainResource> getComponents( | ||
KnowledgeArtifactAdapter adapter, Repository repository, ArrayList<IDomainResource> resourcesToUpdate) { | ||
adapter.getRelatedArtifactsOfType("composed-of").stream().forEach(c -> { | ||
final var preReleaseReference = KnowledgeArtifactAdapter.getRelatedArtifactReference(c); | ||
Optional<KnowledgeArtifactAdapter> maybeArtifact = | ||
VisitorHelper.tryGetLatestVersion(preReleaseReference, repository); | ||
if (maybeArtifact.isPresent()) { | ||
if (resourcesToUpdate.stream() | ||
.filter(rtu -> | ||
rtu.getId().equals(maybeArtifact.get().getId().toString()) | ||
&& (rtu.getExtension().stream() | ||
.anyMatch(ext -> ext.getUrl().equals(isOwnedUrl)))) | ||
.collect(Collectors.toList()) | ||
.isEmpty()) { | ||
resourcesToUpdate.add(maybeArtifact.get().get()); | ||
getComponents(maybeArtifact.get(), repository, resourcesToUpdate); | ||
} | ||
} | ||
}); | ||
|
||
return resourcesToUpdate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.