fix duplicate sheet name problem generating spreadsheets
This commit is contained in:
parent
f0738ac706
commit
f8268442d1
|
@ -21,7 +21,7 @@ public class CanonicalSpreadsheetGenerator extends SpreadsheetGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Sheet renderCanonicalResource(CanonicalResource cr) {
|
protected Sheet renderCanonicalResource(CanonicalResource cr) {
|
||||||
Sheet sheet = wb.createSheet("Metadata");
|
Sheet sheet = makeSheet("Metadata");
|
||||||
|
|
||||||
Row headerRow = sheet.createRow(0);
|
Row headerRow = sheet.createRow(0);
|
||||||
addCell(headerRow, 0, "Property", styles.get("header"));
|
addCell(headerRow, 0, "Property", styles.get("header"));
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addFilters(List<CodeSystemFilterComponent> filters) {
|
private void addFilters(List<CodeSystemFilterComponent> filters) {
|
||||||
Sheet sheet = wb.createSheet("Filters");
|
Sheet sheet = makeSheet("Filters");
|
||||||
addHeaders(sheet, "Code", "Description", "Operators", "Value");
|
addHeaders(sheet, "Code", "Description", "Operators", "Value");
|
||||||
for (CodeSystemFilterComponent f : filters) {
|
for (CodeSystemFilterComponent f : filters) {
|
||||||
CommaSeparatedStringBuilder cs = new CommaSeparatedStringBuilder();
|
CommaSeparatedStringBuilder cs = new CommaSeparatedStringBuilder();
|
||||||
|
@ -80,7 +80,7 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addProperties(List<PropertyComponent> properties) {
|
private void addProperties(List<PropertyComponent> properties) {
|
||||||
Sheet sheet = wb.createSheet("Properties");
|
Sheet sheet = makeSheet("Properties");
|
||||||
addHeaders(sheet, "Code", "Uri", "Description", "Type");
|
addHeaders(sheet, "Code", "Uri", "Description", "Type");
|
||||||
for (PropertyComponent p : properties) {
|
for (PropertyComponent p : properties) {
|
||||||
addRow(sheet, p.getCode(), p.getUri(), p.getDescription(), p.getTypeElement().asStringValue());
|
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) {
|
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
|
addHeaders(sheet, "Level", "Code", "Display", "Definition"); //todo: properties and designations
|
||||||
addConcepts(sheet, 1, concepts);
|
addConcepts(sheet, 1, concepts);
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
|
||||||
}
|
}
|
||||||
|
|
||||||
private void genExpansionParams(List<ValueSetExpansionParameterComponent> params) {
|
private void genExpansionParams(List<ValueSetExpansionParameterComponent> params) {
|
||||||
Sheet sheet = wb.createSheet("Expansion Parameters");
|
Sheet sheet = makeSheet("Expansion Parameters");
|
||||||
addHeaders(sheet, "Parameter", "Value");
|
addHeaders(sheet, "Parameter", "Value");
|
||||||
for (ValueSetExpansionParameterComponent p : params) {
|
for (ValueSetExpansionParameterComponent p : params) {
|
||||||
addRow(sheet, p.getName(), dr.display(p.getValue()));
|
addRow(sheet, p.getName(), dr.display(p.getValue()));
|
||||||
|
@ -111,7 +111,7 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
|
||||||
}
|
}
|
||||||
|
|
||||||
private void genExpansion(List<ValueSetExpansionContainsComponent> list) {
|
private void genExpansion(List<ValueSetExpansionContainsComponent> list) {
|
||||||
Sheet sheet = wb.createSheet("Expansion");
|
Sheet sheet = makeSheet("Expansion");
|
||||||
addHeaders(sheet, "Level", "System", "version", "Code", "Display", "Abstract", "Inactive");
|
addHeaders(sheet, "Level", "System", "version", "Code", "Display", "Abstract", "Inactive");
|
||||||
genExpansionEntry(1, list, sheet);
|
genExpansionEntry(1, list, sheet);
|
||||||
}
|
}
|
||||||
|
@ -129,12 +129,12 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
|
||||||
return value ? "" : "false";
|
return value ? "" : "false";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void genInclude(ValueSet vs, ConceptSetComponent inc, String mode) {
|
// private void genInclude(ValueSet vs, ConceptSetComponent inc, String mode) {
|
||||||
if (inc.hasSystem()) {
|
// if (inc.hasSystem()) {
|
||||||
genIncludeSystem(vs, inc, mode);
|
// genIncludeSystem(vs, inc, mode);
|
||||||
} else {
|
// } else {
|
||||||
genIncludeValueSets(vs, inc, mode);
|
// genIncludeValueSets(vs, inc, mode);
|
||||||
}
|
// }
|
||||||
// String subname = inc.hasSystem() ? : "ValueSets";
|
// String subname = inc.hasSystem() ? : "ValueSets";
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
@ -152,33 +152,33 @@ public class CodeSystemSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
|
||||||
// processElement(sheet, sd, child);
|
// processElement(sheet, sd, child);
|
||||||
// }
|
// }
|
||||||
// configureSheet(sheet, sd);
|
// configureSheet(sheet, sd);
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void genIncludeValueSets(ValueSet vs, ConceptSetComponent inc, String mode) {
|
// private void genIncludeValueSets(ValueSet vs, ConceptSetComponent inc, String mode) {
|
||||||
Sheet sheet = wb.createSheet(mode+" ValueSets");
|
// Sheet sheet = makeSheet(mode+" ValueSets");
|
||||||
addValueSets(sheet, inc.getValueSet());
|
// addValueSets(sheet, inc.getValueSet());
|
||||||
configureSheet(sheet);
|
// configureSheet(sheet);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private void genIncludeSystem(ValueSet vs, ConceptSetComponent inc, String mode) {
|
// 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()) {
|
// if (inc.hasValueSet()) {
|
||||||
addValueSets(sheet, inc.getValueSet());
|
// addValueSets(sheet, inc.getValueSet());
|
||||||
}
|
// }
|
||||||
if (inc.hasFilter()) {
|
// if (inc.hasFilter()) {
|
||||||
addFilters(sheet, inc.getFilter());
|
// addFilters(sheet, inc.getFilter());
|
||||||
}
|
// }
|
||||||
if (inc.hasConcept()) {
|
// if (inc.hasConcept()) {
|
||||||
addConcepts(sheet, inc.getConcept());
|
// addConcepts(sheet, inc.getConcept());
|
||||||
}
|
// }
|
||||||
if (!inc.hasConcept() && !inc.hasFilter()) {
|
// if (!inc.hasConcept() && !inc.hasFilter()) {
|
||||||
addAllCodes(sheet);
|
// addAllCodes(sheet);
|
||||||
}
|
// }
|
||||||
addRow(sheet, "", "");
|
// addRow(sheet, "", "");
|
||||||
addRow(sheet, "System URI", inc.getSystem());
|
// addRow(sheet, "System URI", inc.getSystem());
|
||||||
|
//
|
||||||
configureSheet(sheet);
|
// configureSheet(sheet);
|
||||||
}
|
// }
|
||||||
|
|
||||||
private void addAllCodes(Sheet sheet) {
|
private void addAllCodes(Sheet sheet) {
|
||||||
addHeaders(sheet, "Codes");
|
addHeaders(sheet, "Codes");
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class ConceptMapSpreadsheetGenerator extends CanonicalSpreadsheetGenerato
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderGroup(ConceptMapGroupComponent grp, int i) {
|
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");
|
addHeaders(sheet, "Source", "Display", "Relationship", "Target", "Display");
|
||||||
addRow(sheet, grp.getSource(), "", "", grp.getTarget(), "");
|
addRow(sheet, grp.getSource(), "", "", grp.getTarget(), "");
|
||||||
for (SourceElementComponent s : grp.getElement()) {
|
for (SourceElementComponent s : grp.getElement()) {
|
||||||
|
|
|
@ -2,7 +2,9 @@ package org.hl7.fhir.r5.renderers.spreadsheets;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.BorderStyle;
|
import org.apache.poi.ss.usermodel.BorderStyle;
|
||||||
|
@ -58,6 +60,7 @@ public class SpreadsheetGenerator {
|
||||||
protected Map<String, CellStyle> styles;
|
protected Map<String, CellStyle> styles;
|
||||||
|
|
||||||
protected DataRenderer dr;
|
protected DataRenderer dr;
|
||||||
|
private List<String> sheetNames = new ArrayList<>();
|
||||||
|
|
||||||
public SpreadsheetGenerator(IWorkerContext context) {
|
public SpreadsheetGenerator(IWorkerContext context) {
|
||||||
super();
|
super();
|
||||||
|
@ -72,6 +75,19 @@ public class SpreadsheetGenerator {
|
||||||
outStream.close();
|
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){
|
private static Map<String, CellStyle> createStyles(Workbook wb){
|
||||||
Map<String, CellStyle> styles = new HashMap<>();
|
Map<String, CellStyle> styles = new HashMap<>();
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class StructureDefinitionSpreadsheetGenerator extends CanonicalSpreadshee
|
||||||
throw new DefinitionException(context.formatMessage(I18nConstants.NEEDS_A_SNAPSHOT));
|
throw new DefinitionException(context.formatMessage(I18nConstants.NEEDS_A_SNAPSHOT));
|
||||||
}
|
}
|
||||||
addStructureDefinitionMetadata(renderCanonicalResource(sd), sd);
|
addStructureDefinitionMetadata(renderCanonicalResource(sd), sd);
|
||||||
Sheet sheet = wb.createSheet("Elements");
|
Sheet sheet = makeSheet("Elements");
|
||||||
|
|
||||||
Row headerRow = sheet.createRow(0);
|
Row headerRow = sheet.createRow(0);
|
||||||
for (int i = 0; i < titles.length; i++) {
|
for (int i = 0; i < titles.length; i++) {
|
||||||
|
@ -115,6 +115,7 @@ public class StructureDefinitionSpreadsheetGenerator extends CanonicalSpreadshee
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addStructureDefinitionMetadata(Sheet sheet, StructureDefinition sd) {
|
private void addStructureDefinitionMetadata(Sheet sheet, StructureDefinition sd) {
|
||||||
for (Coding k : sd.getKeyword()) {
|
for (Coding k : sd.getKeyword()) {
|
||||||
addMetadataRow(sheet, "Keyword", dr.display(k));
|
addMetadataRow(sheet, "Keyword", dr.display(k));
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class ValueSetSpreadsheetGenerator extends CanonicalSpreadsheetGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
private void genExpansionParams(List<ValueSetExpansionParameterComponent> params) {
|
private void genExpansionParams(List<ValueSetExpansionParameterComponent> params) {
|
||||||
Sheet sheet = wb.createSheet("Expansion Parameters");
|
Sheet sheet = makeSheet("Expansion Parameters");
|
||||||
addHeaders(sheet, "Parameter", "Value");
|
addHeaders(sheet, "Parameter", "Value");
|
||||||
for (ValueSetExpansionParameterComponent p : params) {
|
for (ValueSetExpansionParameterComponent p : params) {
|
||||||
addRow(sheet, p.getName(), dr.display(p.getValue()));
|
addRow(sheet, p.getName(), dr.display(p.getValue()));
|
||||||
|
@ -64,7 +64,7 @@ public class ValueSetSpreadsheetGenerator extends CanonicalSpreadsheetGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
private void genExpansion(List<ValueSetExpansionContainsComponent> list) {
|
private void genExpansion(List<ValueSetExpansionContainsComponent> list) {
|
||||||
Sheet sheet = wb.createSheet("Expansion");
|
Sheet sheet = makeSheet("Expansion");
|
||||||
addHeaders(sheet, "Level", "System", "version", "Code", "Display", "Abstract", "Inactive");
|
addHeaders(sheet, "Level", "System", "version", "Code", "Display", "Abstract", "Inactive");
|
||||||
genExpansionEntry(1, list, sheet);
|
genExpansionEntry(1, list, sheet);
|
||||||
}
|
}
|
||||||
|
@ -108,13 +108,13 @@ public class ValueSetSpreadsheetGenerator extends CanonicalSpreadsheetGenerator
|
||||||
}
|
}
|
||||||
|
|
||||||
private void genIncludeValueSets(ValueSet vs, ConceptSetComponent inc, String mode) {
|
private void genIncludeValueSets(ValueSet vs, ConceptSetComponent inc, String mode) {
|
||||||
Sheet sheet = wb.createSheet(mode+" ValueSets");
|
Sheet sheet = makeSheet(mode+" ValueSets");
|
||||||
addValueSets(sheet, inc.getValueSet());
|
addValueSets(sheet, inc.getValueSet());
|
||||||
configureSheet(sheet);
|
configureSheet(sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void genIncludeSystem(ValueSet vs, ConceptSetComponent inc, String mode) {
|
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()) {
|
if (inc.hasValueSet()) {
|
||||||
addValueSets(sheet, inc.getValueSet());
|
addValueSets(sheet, inc.getValueSet());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue