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

-ExtractMatBundle modified to handle whole directory of files, test coverage added #460

Closed
wants to merge 12 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,14 @@
- Accepts Bundles with .json or .xml extensions

- MAT Bundle extraction
- mvn exec:java -Dexec.args="[-ExtractMatBundle] [Bundle file path] (-v)
- 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)"
- TODO
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
Loading