improve xls output

This commit is contained in:
Grahame Grieve 2019-05-21 10:39:51 +10:00
parent 50c88dc1c1
commit be84bb427c
4 changed files with 93 additions and 49 deletions

View File

@ -3424,16 +3424,17 @@ public class ProfileUtilities extends TranslatingUtilities {
} }
// generate an Excel representation of the structure definition // generate an Excel representation of the structure definition
public void generateXlsx(OutputStream dest, StructureDefinition structure, boolean asXml) throws IOException, DefinitionException, Exception { public void generateXlsx(OutputStream dest, StructureDefinition structure, boolean asXml, boolean hideMustSupportFalse) throws IOException, DefinitionException, Exception {
if (!structure.hasSnapshot()) if (!structure.hasSnapshot())
throw new DefinitionException("needs a snapshot"); throw new DefinitionException("needs a snapshot");
XLSXWriter xlsx = new XLSXWriter(dest, structure, asXml); XLSXWriter xlsx = new XLSXWriter(dest, structure, asXml, hideMustSupportFalse);
for (ElementDefinition child : structure.getSnapshot().getElement()) { for (ElementDefinition child : structure.getSnapshot().getElement()) {
xlsx.processElement(child); xlsx.processElement(child);
} }
xlsx.dump(); xlsx.dump();
xlsx.close();
} }
private class Slicer extends ElementDefinitionSlicingComponent { private class Slicer extends ElementDefinitionSlicingComponent {

View File

@ -58836,7 +58836,7 @@ public class JsonParser extends JsonParserBase {
else if (type instanceof ParameterDefinition) else if (type instanceof ParameterDefinition)
composeParameterDefinitionInner((ParameterDefinition) type); composeParameterDefinitionInner((ParameterDefinition) type);
else else
throw new Error("Unhandled type"); throw new Error("Unhandled type: "+type.fhirType());
} }
} }

View File

@ -53,8 +53,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.hl7.fhir.r5.formats.IParser.OutputStyle; import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.formats.JsonParser; import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser; import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.CanonicalType;
import org.hl7.fhir.r5.model.Coding; import org.hl7.fhir.r5.model.Coding;
import org.hl7.fhir.r5.model.ElementDefinition; import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.ElementDefinition.AggregationMode;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent; import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent; import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent;
import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent; import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent;
@ -65,6 +67,7 @@ import org.hl7.fhir.r5.model.StructureDefinition;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent; import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent;
import org.hl7.fhir.r5.model.Type; import org.hl7.fhir.r5.model.Type;
import org.hl7.fhir.r5.model.UriType; import org.hl7.fhir.r5.model.UriType;
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
import org.hl7.fhir.utilities.TextStreamWriter; import org.hl7.fhir.utilities.TextStreamWriter;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAutoFilter; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAutoFilter;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCustomFilter; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCustomFilter;
@ -84,6 +87,7 @@ public class XLSXWriter extends TextStreamWriter {
private XmlParser xml = new XmlParser(); private XmlParser xml = new XmlParser();
private JsonParser json = new JsonParser(); private JsonParser json = new JsonParser();
private boolean asXml; private boolean asXml;
private boolean hideMustSupportFalse;
private static String[] titles = { private static String[] titles = {
"Path", "Slice Name", "Alias(s)", "Label", "Min", "Max", "Must Support?", "Is Modifier?", "Is Summary?", "Type(s)", "Short", "Path", "Slice Name", "Alias(s)", "Label", "Min", "Max", "Must Support?", "Is Modifier?", "Is Summary?", "Type(s)", "Short",
@ -92,11 +96,12 @@ public class XLSXWriter extends TextStreamWriter {
"Slicing Discriminator", "Slicing Description", "Slicing Ordered", "Slicing Rules", "Base Path", "Base Min", "Base Max", "Slicing Discriminator", "Slicing Description", "Slicing Ordered", "Slicing Rules", "Base Path", "Base Min", "Base Max",
"Condition(s)", "Constraint(s)"}; "Condition(s)", "Constraint(s)"};
public XLSXWriter(OutputStream out, StructureDefinition def, boolean asXml) throws UnsupportedEncodingException { public XLSXWriter(OutputStream out, StructureDefinition def, boolean asXml, boolean hideMustSupportFalse) throws UnsupportedEncodingException {
super(out); super(out);
outStream = out; outStream = out;
this.asXml = asXml; this.asXml = asXml;
this.def = def; this.def = def;
this.hideMustSupportFalse = hideMustSupportFalse;
sheet = wb.createSheet("Elements"); sheet = wb.createSheet("Elements");
styles = createStyles(wb); styles = createStyles(wb);
Row headerRow = sheet.createRow(0); Row headerRow = sheet.createRow(0);
@ -155,7 +160,7 @@ public class XLSXWriter extends TextStreamWriter {
private static CellStyle createBorderedStyle(Workbook wb){ private static CellStyle createBorderedStyle(Workbook wb){
BorderStyle thin = BorderStyle.THIN; BorderStyle thin = BorderStyle.THIN;
short black = IndexedColors.BLACK.getIndex(); short black = IndexedColors.GREY_50_PERCENT.getIndex();
CellStyle style = wb.createCellStyle(); CellStyle style = wb.createCellStyle();
style.setBorderRight(thin); style.setBorderRight(thin);
@ -262,7 +267,17 @@ public class XLSXWriter extends TextStreamWriter {
val = o.toString(); val = o.toString();
} else if (o instanceof TypeRefComponent) { } else if (o instanceof TypeRefComponent) {
TypeRefComponent t = (TypeRefComponent)o; TypeRefComponent t = (TypeRefComponent)o;
val = t.getCode() + (t.getProfile() == null ? "" : " {" + t.getProfile() + "}") +(t.getTargetProfile() == null ? "" : " {" + t.getTargetProfile() + "}") + (t.getAggregation() == null || t.getAggregation().isEmpty() ? "" : " (" + itemList(t.getAggregation()) + ")"); val = t.getCode();
if (val == null)
val = "";
if (val.startsWith("http://hl7.org/fhir/StructureDefinition/"))
val = val.substring(40);
if (t.hasTargetProfile())
val = val+ "(" + canonicalList(t.getTargetProfile()) + ")";
if (t.hasProfile())
val = val + " {" + canonicalList(t.getProfile()) + "}";
if (t.hasAggregation())
val = val + " <<" + aggList(t.getAggregation()) + ">>";
} else if (o instanceof Coding) { } else if (o instanceof Coding) {
Coding t = (Coding)o; Coding t = (Coding)o;
val = (t.getSystem()==null ? "" : t.getSystem()) + (t.getCode()==null ? "" : "#" + t.getCode()) + (t.getDisplay()==null ? "" : " (" + t.getDisplay() + ")"); val = (t.getSystem()==null ? "" : t.getSystem()) + (t.getCode()==null ? "" : "#" + t.getCode()) + (t.getDisplay()==null ? "" : " (" + t.getDisplay() + ")");
@ -285,7 +300,30 @@ public class XLSXWriter extends TextStreamWriter {
return s.toString(); return s.toString();
} }
private String aggList(List<org.hl7.fhir.r5.model.Enumeration<AggregationMode>> list) {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
for (org.hl7.fhir.r5.model.Enumeration<AggregationMode> c : list)
b.append(c.getValue().toCode());
return b.toString();
}
private String canonicalList(List<CanonicalType> list) {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder("|");
for (CanonicalType c : list) {
String v = c.getValue();
if (v.startsWith("http://hl7.org/fhir/StructureDefinition/"))
v = v.substring(40);
b.append(v);
}
return b.toString();
}
private String renderType(Type value) throws Exception { private String renderType(Type value) throws Exception {
if (value == null)
return "";
if (value.isPrimitive())
return value.primitiveValue();
String s = null; String s = null;
ByteArrayOutputStream bs = new ByteArrayOutputStream(); ByteArrayOutputStream bs = new ByteArrayOutputStream();
if (asXml) { if (asXml) {
@ -339,6 +377,7 @@ public class XLSXWriter extends TextStreamWriter {
} }
sheet.createFreezePane(2,1); sheet.createFreezePane(2,1);
if (hideMustSupportFalse) {
SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting(); SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
String address = "A2:AI" + Math.max(Integer.valueOf(sheet.getLastRowNum()), 2); String address = "A2:AI" + Math.max(Integer.valueOf(sheet.getLastRowNum()), 2);
CellRangeAddress[] regions = { CellRangeAddress[] regions = {
@ -359,6 +398,7 @@ public class XLSXWriter extends TextStreamWriter {
sheet.setAutoFilter(new CellRangeAddress(0,sheet.getLastRowNum(), 0, titles.length+def.getMapping().size() - 1)); sheet.setAutoFilter(new CellRangeAddress(0,sheet.getLastRowNum(), 0, titles.length+def.getMapping().size() - 1));
XSSFSheet xSheet = (XSSFSheet)sheet; XSSFSheet xSheet = (XSSFSheet)sheet;
CTAutoFilter sheetFilter = xSheet.getCTWorksheet().getAutoFilter(); CTAutoFilter sheetFilter = xSheet.getCTWorksheet().getAutoFilter();
@ -380,6 +420,7 @@ public class XLSXWriter extends TextStreamWriter {
((XSSFRow) row).getCTRow().setHidden(true); ((XSSFRow) row).getCTRow().setHidden(true);
} }
} }
}
sheet.setActiveCell(new CellAddress(sheet.getRow(1).getCell(0))); sheet.setActiveCell(new CellAddress(sheet.getRow(1).getCell(0)));
wb.write(outStream); wb.write(outStream);

View File

@ -1,21 +1,23 @@
REM replace versions before running REM replace versions before running
REM make sure you are committed REM make sure you are committed
@echo off
echo echo
echo =====================================================================
echo =============================================================== echo upgrade and release fhir.core from 3.7.34-SNAPSHOT to 3.7.35-SNAPSHOT
echo upgrade and release fhir.core from 3.7.33-SNAPSHOT to 3.7.34-SNAPSHOT echo =====================================================================
echo =============================================================== echo
echo check versions and make sure committed...
pause pause
call mvn versions:set -DnewVersion=3.7.34-SNAPSHOT call mvn versions:set -DnewVersion=3.7.35-SNAPSHOT
call git commit -a -m "Release new version" call git commit -a -m "Release new version"
call git push origin master call git push origin master
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.java" --includeSubDirectories --find "3.7.33-SNAPSHOT" --replace "3.7.34-SNAPSHOT" call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.java" --includeSubDirectories --find "3.7.34-SNAPSHOT" --replace "3.7.35-SNAPSHOT"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\fhir-ig-publisher" --fileMask "*.xml" --includeSubDirectories --find "3.7.33-SNAPSHOT" --replace "3.7.34-SNAPSHOT" call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\fhir-ig-publisher" --fileMask "*.xml" --includeSubDirectories --find "3.7.34-SNAPSHOT" --replace "3.7.35-SNAPSHOT"
call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.xml" --find "3.7.33-SNAPSHOT" --replace "3.7.34-SNAPSHOT" call "C:\tools\fnr.exe" --cl --dir "C:\work\org.hl7.fhir\build" --fileMask "*.xml" --find "3.7.34-SNAPSHOT" --replace "3.7.35-SNAPSHOT"
call mvn deploy call mvn deploy
call python c:\tools\zulip-api\zulip\zulip\send.py --stream committers/notification --subject "java core" -m "New Java Core v3.7.34-SNAPSHOT released." --config-file zuliprc call python c:\tools\zulip-api\zulip\zulip\send.py --stream committers/notification --subject "java core" -m "New Java Core v3.7.35-SNAPSHOT released." --config-file zuliprc
echo =============================================================== echo ===============================================================
echo all done echo all done