cqframework / cqf-tooling

Tooling for CQL and IG Authors
Apache License 2.0
19 stars 23 forks source link

Add tooling operation StripGeneratedContent #434

Closed NataliaSmileDigital closed 1 year ago

NataliaSmileDigital commented 1 year ago

For Knowledge Artifacts (Measures, Libraries, PlanDefinition, Questionnaires) test data we can strip anything that can be generated or inferred at runtime. Specifically: text data-requirements parameters related-artifacts (of type "depends-on") content of type application/elm+json or application/elm+xml

Basically, the opposite of RefreshIG and RefreshLibrary.

The goal here is to make the test resources as easy to work with as possible. Removing any data that's not related to the functional behavior.

The less data we have, the less there is to parse at runtime, or index in the IDE, or download when you clone the repo. Tidy, small, fast.

The CQL debundling is already a huge win, we're just taking the next steps.

A rough guess is that this will half the size of the test data based on how much is narrative and so on. Also, any auto-generated extensions on those resources: http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-parameter http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-dataRequirement http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-directReferenceCode

for (var file : recursiveDirectorySearch(input)) {
   parseAsResource(file)
     .flatMap(r -> stripAndWriteIfNeeded(r, file));
}

parseAsResource(input) {
  var version = getVersionFromPath(input)
  var context = FhirContent.forCached(version);
  var content = readFile(input);
  try {

  }
  if (input.endsWith(".json") {
     return context.newJsonParser().parse(content);
  }
  else {
     return context.newXmlParser().parse(content);
  }
  catch {
     return Optional.empty();
  }
}

stripAndWriteIfNeeded(resource, file) {
  if (!isKnowledgeArtifact(resource)) {
      return;
  }

  resource.text().clear()
  resource.dataRequirements.clear()
  ... etc

  var version = getVersionFromPath(input)
  var context = FhirContent.forCached(version);

  String output;
  if (input.endsWith(".json") {
     context.newJsonParser().string(resource)
  }
  else {
     context.newXmlParser().string(resource);
  }

  files.write(content, file);
}
Chris0296 commented 1 year ago

Completed as per chat with @mdnazmulkarim. Closing this issue.