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

Extract mat bundle dir processing #1

Merged
merged 5 commits into from
Sep 13, 2023
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

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
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ private void checkExpectedResourcesPresent(List<DataRequirement> drs, List<Strin
}
}

@Test
public void TestExtractMatBundleWithDirectory(){
ExtractMatBundleOperation o = new ExtractMatBundleOperation();
o.execute(new String[] { "-ExtractMATBundle", this.getClass().getResource("ecqm-content-r4-2021/bundles_small/").getFile(), "-dir" });
}

@Test
public void TestCMS816HIR() {
List<DataRequirement> drs = StartMatOutputTest("HH-01FHIR-v0-0-010-FHIR-4-0-1.json", "HospitalHarmSevereHypoglycemiaFHIR");
Expand Down
Loading