Skip to content

Commit

Permalink
-ExtractMatBundle modified to handle whole directory of files, test c…
Browse files Browse the repository at this point in the history
…overage added (#475)

* Moved the processing of a file to its own method, incorporated a for loop into the execute method should -dir be passed in.

* Finished with directory processing, adding test.

* Fixed issue with test, now verify Bundle using instanceof

* Removed member variable references for readability.

* Validating input earlier, adjusted BundlUtils to handle logic about versioning the method call.

* 80% code coverage on ExtractMatBundleOperation class

* Added more robust tests for the supplied output directory by the user

* Removed unused test

* Added transactional bundle files for tests to POST

* Added commented out line for localhost POST testing.

* Updated ExtractMatBundle tests to cover wider range of file types and content.

* Eliminating unused resource

* Added resource ID verification so resources aren't processed repeatedly. Once extracted from a transaction bundle, the resource ID is logged, and if found in another bundle, removed from that bundle prior to processing it.

* Fixed failing tests elsewhere in the app on null outputpath

* Removing RefreshIG work accidentally included in this branch

* Restoring Main documentation for -dir

---------

Co-authored-by: Evan Chicoine <[email protected]>
  • Loading branch information
echicoine-icf and Evan Chicoine authored Oct 13, 2023
1 parent 23c5f8b commit 929c130
Show file tree
Hide file tree
Showing 31 changed files with 56,051 additions and 289 deletions.
15 changes: 8 additions & 7 deletions tooling-cli/src/main/java/org/opencds/cqf/tooling/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@
- This tooling decomposes a Bundle entry into separate resource files
- Accepts Bundles with .json or .xml extensions
- MAT Bundle extraction
- mvn exec:java -Dexec.args="[-ExtractMatBundle] [Bundle file path] (-v)
- Example: mvn exec:java -Dexec.args="-ExtractMatBundle /Users/mholck/Development/ecqm-content-r4/bundles/mat/EXM124/EXM124.json -v=r4"
- This tooling extracts out the resources and CQL from a MAT export bundle and puts them in the appropriate directories
- Accepts Bundles with .json or .xml extensions
- version = FHIR version { stu3, r4 }
Default version: r4
- MAT Bundle extraction
- mvn exec:java -Dexec.args="[-ExtractMatBundle] [Bundle file path] (-v) (-dir)
- Example: mvn exec:java -Dexec.args="-ExtractMatBundle /Users/mholck/Development/ecqm-content-r4/bundles/mat/EXM124/EXM124.json -v=r4"
- This tooling extracts out the resources and CQL from a MAT export bundle and puts them in the appropriate directories
- Accepts Bundles with .json or .xml extensions
- version = FHIR version { stu3, r4 }
Default version: r4
- dir = Directory indicator. To process the input location as a directory of files, the input should point to a valid directory and the -dir flag should be present in the arguments list.
- Generate StructureDefinitions from ModelInfo
- command: mvn exec:java -Dexec.args="[-GenerateSDs] [path to modelinfo xml] (-outputpath | -op) (-encoding | -e)"
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static Object bundleArtifacts(String id, List<IBaseResource> resources, F
case DSTU3:
return bundleStu3Artifacts(id, resources);
case R4:
if(identifiers != null && identifiers.length > 0){
if (identifiers != null && identifiers.length > 0) {
return bundleR4Artifacts(id, resources, identifiers[0], addBundleTimestamp);
}
return bundleR4Artifacts(id, resources, null, addBundleTimestamp);
Expand All @@ -42,53 +42,49 @@ public static Object bundleArtifacts(String id, List<IBaseResource> resources, F
}
}

public static org.hl7.fhir.dstu3.model.Bundle bundleStu3Artifacts(String id, List<IBaseResource> resources)
{
public static org.hl7.fhir.dstu3.model.Bundle bundleStu3Artifacts(String id, List<IBaseResource> resources) {
org.hl7.fhir.dstu3.model.Bundle bundle = new org.hl7.fhir.dstu3.model.Bundle();
ResourceUtils.setIgId(id, bundle, false);
bundle.setType(org.hl7.fhir.dstu3.model.Bundle.BundleType.TRANSACTION);
for (IBaseResource resource : resources)
{
for (IBaseResource resource : resources) {
bundle.addEntry(
new org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent()
.setResource((org.hl7.fhir.dstu3.model.Resource) resource)
.setRequest(
new org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent()
.setMethod(org.hl7.fhir.dstu3.model.Bundle.HTTPVerb.PUT)
.setUrl(((org.hl7.fhir.dstu3.model.Resource) resource).getId())
)
new org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent()
.setResource((org.hl7.fhir.dstu3.model.Resource) resource)
.setRequest(
new org.hl7.fhir.dstu3.model.Bundle.BundleEntryRequestComponent()
.setMethod(org.hl7.fhir.dstu3.model.Bundle.HTTPVerb.PUT)
.setUrl(((org.hl7.fhir.dstu3.model.Resource) resource).getId())
)
);
}
return bundle;
}

public static org.hl7.fhir.r4.model.Bundle bundleR4Artifacts(String id, List<IBaseResource> resources, List<Object> identifiers, Boolean addBundleTimestamp)
{
public static org.hl7.fhir.r4.model.Bundle bundleR4Artifacts(String id, List<IBaseResource> resources, List<Object> identifiers, Boolean addBundleTimestamp) {
org.hl7.fhir.r4.model.Bundle bundle = new org.hl7.fhir.r4.model.Bundle();
ResourceUtils.setIgId(id, bundle, false);
bundle.setType(org.hl7.fhir.r4.model.Bundle.BundleType.TRANSACTION);
if (addBundleTimestamp) {
bundle.setTimestamp((new Date()));
}
if (identifiers!= null && !identifiers.isEmpty()) {
if (identifiers != null && !identifiers.isEmpty()) {
org.hl7.fhir.r4.model.Identifier identifier = (org.hl7.fhir.r4.model.Identifier) identifiers.get(0);
if(identifier.hasValue()) {
if (identifier.hasValue()) {
identifier.setValue(identifier.getValue() + "-bundle");
}
bundle.setIdentifier(identifier);
}

for (IBaseResource resource : resources)
{
for (IBaseResource resource : resources) {
String resourceRef = (resource.getIdElement().getResourceType() == null) ? resource.fhirType() + "/" + resource.getIdElement().getIdPart() : resource.getIdElement().getValueAsString();
bundle.addEntry(
new org.hl7.fhir.r4.model.Bundle.BundleEntryComponent()
.setResource((org.hl7.fhir.r4.model.Resource) resource)
.setRequest(
new org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent()
.setMethod(org.hl7.fhir.r4.model.Bundle.HTTPVerb.PUT)
.setUrl(resourceRef)
)
new org.hl7.fhir.r4.model.Bundle.BundleEntryComponent()
.setResource((org.hl7.fhir.r4.model.Resource) resource)
.setRequest(
new org.hl7.fhir.r4.model.Bundle.BundleEntryRequestComponent()
.setMethod(org.hl7.fhir.r4.model.Bundle.HTTPVerb.PUT)
.setUrl(resourceRef)
)
);
}
return bundle;
Expand Down Expand Up @@ -140,53 +136,63 @@ public static List<Map.Entry<String, IBaseResource>> GetBundlesInDir(String dire
}

public static void stampDstu3BundleEntriesWithSoftwareSystems(org.hl7.fhir.dstu3.model.Bundle bundle, List<CqfmSoftwareSystem> softwareSystems, FhirContext fhirContext, String rootDir) {
for (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent entry: bundle.getEntry()) {
for (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent entry : bundle.getEntry()) {
org.hl7.fhir.dstu3.model.Resource resource = entry.getResource();
if ((resource.fhirType().equals("Library")) || ((resource.fhirType().equals("Measure")))) {
org.opencds.cqf.tooling.common.stu3.CqfmSoftwareSystemHelper cqfmSoftwareSystemHelper = new org.opencds.cqf.tooling.common.stu3.CqfmSoftwareSystemHelper(rootDir);
cqfmSoftwareSystemHelper.ensureSoftwareSystemExtensionAndDevice((org.hl7.fhir.dstu3.model.DomainResource)resource, softwareSystems, fhirContext);
cqfmSoftwareSystemHelper.ensureSoftwareSystemExtensionAndDevice((org.hl7.fhir.dstu3.model.DomainResource) resource, softwareSystems, fhirContext);
}
}
}

public static void stampR4BundleEntriesWithSoftwareSystems(org.hl7.fhir.r4.model.Bundle bundle, List<CqfmSoftwareSystem> softwareSystems, FhirContext fhirContext, String rootDir) {
for (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent entry: bundle.getEntry()) {
for (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent entry : bundle.getEntry()) {
org.hl7.fhir.r4.model.Resource resource = entry.getResource();
if ((resource.fhirType().equals("Library")) || ((resource.fhirType().equals("Measure")))) {
org.opencds.cqf.tooling.common.r4.CqfmSoftwareSystemHelper cqfmSoftwareSystemHelper = new org.opencds.cqf.tooling.common.r4.CqfmSoftwareSystemHelper(rootDir);
cqfmSoftwareSystemHelper.ensureSoftwareSystemExtensionAndDevice((org.hl7.fhir.r4.model.DomainResource)resource, softwareSystems, fhirContext);
cqfmSoftwareSystemHelper.ensureSoftwareSystemExtensionAndDevice((org.hl7.fhir.r4.model.DomainResource) resource, softwareSystems, fhirContext);
}
}
}

public static void extractStu3Resources(org.hl7.fhir.dstu3.model.Bundle bundle, String encoding, String outputPath, boolean suppressNarrative) {
FhirContext context = FhirContext.forDstu3Cached();
for (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent entry : bundle.getEntry()) {
FhirContext context = FhirContext.forDstu3Cached();
for (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent entry : bundle.getEntry()) {
org.hl7.fhir.dstu3.model.Resource entryResource = entry.getResource();
if (entryResource != null) {
if(entryResource.fhirType().equals("Measure") && suppressNarrative){
((org.hl7.fhir.dstu3.model.Measure)entryResource).setText(null);
if (entryResource.fhirType().equals("Measure") && suppressNarrative) {
((org.hl7.fhir.dstu3.model.Measure) entryResource).setText(null);
}
ResourceUtils.outputResource(entryResource, encoding, context, outputPath);
}
}
ResourceUtils.outputResource(entryResource, encoding, context, outputPath);
}
}
}

public static void extractR4Resources(org.hl7.fhir.r4.model.Bundle bundle, String encoding, String outputPath, boolean suppressNarrative) {
FhirContext context = FhirContext.forR4Cached();
for (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent entry : bundle.getEntry()) {
FhirContext context = FhirContext.forR4Cached();
for (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent entry : bundle.getEntry()) {
org.hl7.fhir.r4.model.Resource entryResource = entry.getResource();
if (entryResource != null) {
if(entryResource.fhirType().equals("Measure") && suppressNarrative){
((org.hl7.fhir.r4.model.Measure)entryResource).setText(null);
if (entryResource != null) {
if (entryResource.fhirType().equals("Measure") && suppressNarrative) {
((org.hl7.fhir.r4.model.Measure) entryResource).setText(null);
}
ResourceUtils.outputResource(entryResource, encoding, context, outputPath);
}
}
ResourceUtils.outputResource(entryResource, encoding, context, outputPath);
}
}
}

public static void extractResources(Object bundle, String encoding, String outputDir, boolean suppressNarrative, String version) {
if (version.equals("stu3") && bundle instanceof org.hl7.fhir.dstu3.model.Bundle) {
BundleUtils.extractStu3Resources((org.hl7.fhir.dstu3.model.Bundle) bundle, encoding, outputDir, suppressNarrative);
} else if (version.equals("r4") && bundle instanceof org.hl7.fhir.r4.model.Bundle) {
BundleUtils.extractR4Resources((org.hl7.fhir.r4.model.Bundle) bundle, encoding, outputDir, suppressNarrative);
}else{
throw new IllegalArgumentException("Invalid bundle/version: " + bundle + "/" + version);
}
}

public static ArrayList<Resource> getR4ResourcesFromBundle(Bundle bundle){
ArrayList <Resource> resourceArrayList = new ArrayList<>();
public static ArrayList<Resource> getR4ResourcesFromBundle(Bundle bundle) {
ArrayList<Resource> resourceArrayList = new ArrayList<>();
FhirContext context = FhirContext.forR4Cached();
for (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent entry : bundle.getEntry()) {
org.hl7.fhir.r4.model.Resource entryResource = entry.getResource();
Expand All @@ -197,8 +203,8 @@ public static ArrayList<Resource> getR4ResourcesFromBundle(Bundle bundle){
return resourceArrayList;
}

public static ArrayList<org.hl7.fhir.dstu3.model.Resource> getStu3ResourcesFromBundle(org.hl7.fhir.dstu3.model.Bundle bundle){
ArrayList <org.hl7.fhir.dstu3.model.Resource> resourceArrayList = new ArrayList<>();
public static ArrayList<org.hl7.fhir.dstu3.model.Resource> getStu3ResourcesFromBundle(org.hl7.fhir.dstu3.model.Bundle bundle) {
ArrayList<org.hl7.fhir.dstu3.model.Resource> resourceArrayList = new ArrayList<>();
for (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent entry : bundle.getEntry()) {
org.hl7.fhir.dstu3.model.Resource entryResource = entry.getResource();
if (entryResource != null) {
Expand Down
Loading

0 comments on commit 929c130

Please sign in to comment.