Spreadsheet generation by validator

This commit is contained in:
Grahame Grieve 2021-09-01 09:53:18 +10:00
parent 2250b01fdd
commit 2845078c9e
5 changed files with 43 additions and 0 deletions

View File

@ -473,6 +473,15 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst
return sd;
}
public CanonicalResource loadCanonicalResource(String source, String version) throws FHIRException, IOException {
Content cnt = igLoader.loadContent(source, "validate", false);
Resource res = igLoader.loadResourceByVersion(version, cnt.focus, Utilities.getFileNameForName(source));
if (!(res instanceof CanonicalResource))
throw new FHIRException("Require a CanonicalResource");
return (CanonicalResource) res;
}
public void seeResource(Resource r) throws FHIRException {
context.cacheResource(r);
}

View File

@ -212,6 +212,9 @@ public class ValidatorCli {
case SNAPSHOT:
validationService.generateSnapshot(cliContext, validator);
break;
case SPREADSHEET:
validationService.generateSpreadsheet(cliContext, validator);
break;
case CONVERT:
validationService.convertSources(cliContext, validator);
break;

View File

@ -1,5 +1,6 @@
package org.hl7.fhir.validation.cli.services;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.context.TerminologyCache;
import org.hl7.fhir.r5.elementmodel.Manager;
@ -8,6 +9,10 @@ import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.*;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.renderers.spreadsheets.CodeSystemSpreadsheetGenerator;
import org.hl7.fhir.r5.renderers.spreadsheets.ConceptMapSpreadsheetGenerator;
import org.hl7.fhir.r5.renderers.spreadsheets.StructureDefinitionSpreadsheetGenerator;
import org.hl7.fhir.r5.renderers.spreadsheets.ValueSetSpreadsheetGenerator;
import org.hl7.fhir.r5.utils.ToolingExtensions;
import org.hl7.fhir.utilities.TextFile;
import org.hl7.fhir.utilities.TimeTracker;
@ -24,6 +29,7 @@ import org.hl7.fhir.validation.cli.utils.EngineMode;
import org.hl7.fhir.validation.cli.utils.VersionSourceInformation;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.util.ArrayList;
@ -349,4 +355,25 @@ public class ValidationService {
}
throw new Exception("-> Multiple versions found. Specify a particular version using the -version parameter");
}
public void generateSpreadsheet(CliContext cliContext, ValidationEngine validator) throws Exception {
CanonicalResource cr = validator.loadCanonicalResource(cliContext.getSources().get(0), cliContext.getSv());
boolean ok = true;
if (cr instanceof StructureDefinition) {
new StructureDefinitionSpreadsheetGenerator(validator.getContext(), false, false).renderStructureDefinition((StructureDefinition) cr).finish(new FileOutputStream(cliContext.getOutput()));
} else if (cr instanceof CodeSystem) {
new CodeSystemSpreadsheetGenerator(validator.getContext()).renderCodeSystem((CodeSystem) cr).finish(new FileOutputStream(cliContext.getOutput()));
} else if (cr instanceof ValueSet) {
new ValueSetSpreadsheetGenerator(validator.getContext()).renderValueSet((ValueSet) cr).finish(new FileOutputStream(cliContext.getOutput()));
} else if (cr instanceof ConceptMap) {
new ConceptMapSpreadsheetGenerator(validator.getContext()).renderConceptMap((ConceptMap) cr).finish(new FileOutputStream(cliContext.getOutput()));
} else {
ok = false;
System.out.println(" ...Unable to generate spreadsheet for "+cliContext.getSources().get(0)+": no way to generate a spreadsheet for a "+cr.fhirType());
}
if (ok) {
System.out.println(" ...generated spreadsheet successfully");
}
}
}

View File

@ -7,6 +7,7 @@ public enum EngineMode {
SNAPSHOT,
SCAN,
CONVERT,
SPREADSHEET,
FHIRPATH,
VERSION
}

View File

@ -48,6 +48,7 @@ public class Params {
public static final String TEST = "-tests";
public static final String HELP = "help";
public static final String COMPARE = "-compare";
public static final String SPREADSHEET = "-spreadsheet";
public static final String DESTINATION = "-dest";
public static final String LEFT = "-left";
public static final String RIGHT = "-right";
@ -181,6 +182,8 @@ public class Params {
cliContext.setMode(EngineMode.TRANSFORM);
} else if (args[i].equals(NARRATIVE)) {
cliContext.setMode(EngineMode.NARRATIVE);
} else if (args[i].equals(SPREADSHEET)) {
cliContext.setMode(EngineMode.SPREADSHEET);
} else if (args[i].equals(SNAPSHOT)) {
cliContext.setMode(EngineMode.SNAPSHOT);
} else if (args[i].equals(SECURITY_CHECKS)) {