001package org.hl7.fhir.r5.renderers.spreadsheets;
002
003import java.io.OutputStream;
004
005import org.apache.poi.ss.usermodel.Row;
006import org.apache.poi.ss.usermodel.Sheet;
007import org.hl7.fhir.r5.context.IWorkerContext;
008import org.hl7.fhir.r5.model.CanonicalResource;
009import org.hl7.fhir.r5.model.CodeableConcept;
010import org.hl7.fhir.r5.model.ContactDetail;
011import org.hl7.fhir.r5.model.ElementDefinition;
012import org.hl7.fhir.r5.model.Identifier;
013import org.hl7.fhir.r5.model.StructureDefinition;
014import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent;
015import org.hl7.fhir.r5.renderers.DataRenderer;
016
017public class CanonicalSpreadsheetGenerator extends SpreadsheetGenerator {
018
019  public CanonicalSpreadsheetGenerator(IWorkerContext context) {
020    super(context);
021  }
022
023  protected Sheet renderCanonicalResource(CanonicalResource cr, boolean forMultiple) {
024    Sheet sheet = forMultiple && hasSheet("Metadata") ? getSheet("Metadata") : makeSheet("Metadata");
025
026    Row headerRow = sheet.createRow(forMultiple ? sheet.getLastRowNum()+1 : 0);
027    addCell(headerRow, 0, "Property", styles.get("header"));
028    addCell(headerRow, 1, "Value", styles.get("header"));
029
030    if (forMultiple) {
031      addMetadataRow(sheet, "ID", cr.getId());      
032    }
033    addMetadataRow(sheet, "URL", cr.getUrl());
034    for (Identifier id : cr.getIdentifier()) {
035      addMetadataRow(sheet, "Identifier", dr.displayDataType(id));
036    }
037    addMetadataRow(sheet, "Version", cr.getVersion());
038    addMetadataRow(sheet, "Name", cr.getName());
039    addMetadataRow(sheet, "Title", cr.getTitle());
040    addMetadataRow(sheet, "Status", cr.getStatusElement().asStringValue());
041    addMetadataRow(sheet, "Experimental", cr.getExperimentalElement().asStringValue());
042    addMetadataRow(sheet, "Date", cr.getDateElement().asStringValue());
043    addMetadataRow(sheet, "Publisher", cr.getPublisher());
044    for (ContactDetail c : cr.getContact()) {
045      addMetadataRow(sheet, "Contact", dr.displayDataType(c));
046    }
047    for (CodeableConcept j : cr.getJurisdiction()) {
048      addMetadataRow(sheet, "Jurisdiction", dr.displayDataType(j));
049    }
050
051    addMetadataRow(sheet, "Description", cr.getDescription());
052    addMetadataRow(sheet, "Purpose", cr.getPurpose());
053    addMetadataRow(sheet, "Copyright", cr.getCopyright());
054    configureSheet(sheet);
055    return sheet;
056  }
057
058  private void configureSheet(Sheet sheet) {
059    sheet.setColumnWidth(0, columnPixels(15));
060    sheet.setColumnWidth(1, columnPixels(80));
061  }
062
063  protected void addMetadataRow(Sheet sheet, String name, String value) {
064    Row row = sheet.createRow(sheet.getLastRowNum()+1);
065    addCell(row, 0, name, styles.get("body"));
066    addCell(row, 1, value);
067  }
068
069
070  
071}