fix duplicate sheet name problem generating spreadsheets

This commit is contained in:
Grahame Grieve 2021-09-03 17:31:05 +10:00
parent f0738ac706
commit f8268442d1
6 changed files with 61 additions and 44 deletions

View File

@ -21,7 +21,7 @@ public class CanonicalSpreadsheetGenerator extends SpreadsheetGenerator {
}
protected Sheet renderCanonicalResource(CanonicalResource cr) {
Sheet sheet = wb.createSheet("Metadata");
Sheet sheet = makeSheet("Metadata");
Row headerRow = sheet.createRow(0);
addCell(headerRow, 0, "Property", styles.get("header"));

View File

@ -68,7 +68,7 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
}
private void addFilters(List<CodeSystemFilterComponent> filters) {
Sheet sheet = wb.createSheet("Filters");
Sheet sheet = makeSheet("Filters");
addHeaders(sheet, "Code", "Description", "Operators", "Value");
for (CodeSystemFilterComponent f : filters) {
CommaSeparatedStringBuilder cs = new CommaSeparatedStringBuilder();
@ -80,7 +80,7 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
}
private void addProperties(List<PropertyComponent> properties) {
Sheet sheet = wb.createSheet("Properties");
Sheet sheet = makeSheet("Properties");
addHeaders(sheet, "Code", "Uri", "Description", "Type");
for (PropertyComponent p : properties) {
addRow(sheet, p.getCode(), p.getUri(), p.getDescription(), p.getTypeElement().asStringValue());
@ -88,7 +88,7 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
}
private void addConcepts(List<ConceptDefinitionComponent> concepts) {
Sheet sheet = wb.createSheet("Concepts");
Sheet sheet = makeSheet("Concepts");
addHeaders(sheet, "Level", "Code", "Display", "Definition"); //todo: properties and designations
addConcepts(sheet, 1, concepts);
}
@ -103,7 +103,7 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
}
private void genExpansionParams(List<ValueSetExpansionParameterComponent> params) {
Sheet sheet = wb.createSheet("Expansion Parameters");
Sheet sheet = makeSheet("Expansion Parameters");
addHeaders(sheet, "Parameter", "Value");
for (ValueSetExpansionParameterComponent p : params) {
addRow(sheet, p.getName(), dr.display(p.getValue()));
@ -111,7 +111,7 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
}
private void genExpansion(List<ValueSetExpansionContainsComponent> list) {
Sheet sheet = wb.createSheet("Expansion");
Sheet sheet = makeSheet("Expansion");
addHeaders(sheet, "Level", "System", "version", "Code", "Display", "Abstract", "Inactive");
genExpansionEntry(1, list, sheet);
}
@ -129,12 +129,12 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
return value ? "" : "false";
}
private void genInclude(ValueSet vs, ConceptSetComponent inc, String mode) {
if (inc.hasSystem()) {
genIncludeSystem(vs, inc, mode);
} else {
genIncludeValueSets(vs, inc, mode);
}
// private void genInclude(ValueSet vs, ConceptSetComponent inc, String mode) {
// if (inc.hasSystem()) {
// genIncludeSystem(vs, inc, mode);
// } else {
// genIncludeValueSets(vs, inc, mode);
// }
// String subname = inc.hasSystem() ? : "ValueSets";
//
//
@ -152,33 +152,33 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
// processElement(sheet, sd, child);
// }
// configureSheet(sheet, sd);
}
// }
private void genIncludeValueSets(ValueSet vs, ConceptSetComponent inc, String mode) {
Sheet sheet = wb.createSheet(mode+" ValueSets");
addValueSets(sheet, inc.getValueSet());
configureSheet(sheet);
}
private void genIncludeSystem(ValueSet vs, ConceptSetComponent inc, String mode) {
Sheet sheet = wb.createSheet(mode+" from "+dr.displaySystem(inc.getSystem()));
if (inc.hasValueSet()) {
addValueSets(sheet, inc.getValueSet());
}
if (inc.hasFilter()) {
addFilters(sheet, inc.getFilter());
}
if (inc.hasConcept()) {
addConcepts(sheet, inc.getConcept());
}
if (!inc.hasConcept() && !inc.hasFilter()) {
addAllCodes(sheet);
}
addRow(sheet, "", "");
addRow(sheet, "System URI", inc.getSystem());
configureSheet(sheet);
}
// private void genIncludeValueSets(ValueSet vs, ConceptSetComponent inc, String mode) {
// Sheet sheet = makeSheet(mode+" ValueSets");
// addValueSets(sheet, inc.getValueSet());
// configureSheet(sheet);
// }
//
// private void genIncludeSystem(ValueSet vs, ConceptSetComponent inc, String mode) {
// Sheet sheet = makeSheet(mode+" from "+dr.displaySystem(inc.getSystem()));
// if (inc.hasValueSet()) {
// addValueSets(sheet, inc.getValueSet());
// }
// if (inc.hasFilter()) {
// addFilters(sheet, inc.getFilter());
// }
// if (inc.hasConcept()) {
// addConcepts(sheet, inc.getConcept());
// }
// if (!inc.hasConcept() && !inc.hasFilter()) {
// addAllCodes(sheet);
// }
// addRow(sheet, "", "");
// addRow(sheet, "System URI", inc.getSystem());
//
// configureSheet(sheet);
// }
private void addAllCodes(Sheet sheet) {
addHeaders(sheet, "Codes");

View File

@ -38,7 +38,7 @@ public class ConceptMapSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
}
private void renderGroup(ConceptMapGroupComponent grp, int i) {
Sheet sheet = wb.createSheet("Mapping Table "+Integer.toString(i));
Sheet sheet = makeSheet("Mapping Table "+Integer.toString(i));
addHeaders(sheet, "Source", "Display", "Relationship", "Target", "Display");
addRow(sheet, grp.getSource(), "", "", grp.getTarget(), "");
for (SourceElementComponent s : grp.getElement()) {

View File

@ -2,7 +2,9 @@ package org.hl7.fhir.r5.renderers.spreadsheets;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.ss.usermodel.BorderStyle;
@ -58,6 +60,7 @@ public class SpreadsheetGenerator {
protected Map<String, CellStyle> styles;
protected DataRenderer dr;
private List<String> sheetNames = new ArrayList<>();
public SpreadsheetGenerator(IWorkerContext context) {
super();
@ -72,6 +75,19 @@ public class SpreadsheetGenerator {
outStream.close();
}
protected Sheet makeSheet(String name) {
String s = name;
if (sheetNames.contains(s)) {
int i = 1;
do {
i++;
s = name+" "+Integer.toString(i);
} while (sheetNames.contains(s));
}
sheetNames.add(s);
return wb.createSheet(s);
}
private static Map<String, CellStyle> createStyles(Workbook wb){
Map<String, CellStyle> styles = new HashMap<>();

View File

@ -96,7 +96,7 @@ public class StructureDefinitionSpreadsheetGenerator extends CanonicalSpreadshee
throw new DefinitionException(context.formatMessage(I18nConstants.NEEDS_A_SNAPSHOT));
}
addStructureDefinitionMetadata(renderCanonicalResource(sd), sd);
Sheet sheet = wb.createSheet("Elements");
Sheet sheet = makeSheet("Elements");
Row headerRow = sheet.createRow(0);
for (int i = 0; i < titles.length; i++) {
@ -115,6 +115,7 @@ public class StructureDefinitionSpreadsheetGenerator extends CanonicalSpreadshee
return this;
}
private void addStructureDefinitionMetadata(Sheet sheet, StructureDefinition sd) {
for (Coding k : sd.getKeyword()) {
addMetadataRow(sheet, "Keyword", dr.display(k));

View File

@ -56,7 +56,7 @@ public class ValueSetSpreadsheetGenerator extends CanonicalSpreadsheetGenerator
}
private void genExpansionParams(List<ValueSetExpansionParameterComponent> params) {
Sheet sheet = wb.createSheet("Expansion Parameters");
Sheet sheet = makeSheet("Expansion Parameters");
addHeaders(sheet, "Parameter", "Value");
for (ValueSetExpansionParameterComponent p : params) {
addRow(sheet, p.getName(), dr.display(p.getValue()));
@ -64,7 +64,7 @@ public class ValueSetSpreadsheetGenerator extends CanonicalSpreadsheetGenerator
}
private void genExpansion(List<ValueSetExpansionContainsComponent> list) {
Sheet sheet = wb.createSheet("Expansion");
Sheet sheet = makeSheet("Expansion");
addHeaders(sheet, "Level", "System", "version", "Code", "Display", "Abstract", "Inactive");
genExpansionEntry(1, list, sheet);
}
@ -108,13 +108,13 @@ public class ValueSetSpreadsheetGenerator extends CanonicalSpreadsheetGenerator
}
private void genIncludeValueSets(ValueSet vs, ConceptSetComponent inc, String mode) {
Sheet sheet = wb.createSheet(mode+" ValueSets");
Sheet sheet = makeSheet(mode+" ValueSets");
addValueSets(sheet, inc.getValueSet());
configureSheet(sheet);
}
private void genIncludeSystem(ValueSet vs, ConceptSetComponent inc, String mode) {
Sheet sheet = wb.createSheet(mode+" from "+dr.displaySystem(inc.getSystem()));
Sheet sheet = makeSheet(mode+" from "+dr.displaySystem(inc.getSystem()));
if (inc.hasValueSet()) {
addValueSets(sheet, inc.getValueSet());
}