001package org.hl7.fhir.validation.cli.renderers; 002 003import org.hl7.fhir.r5.model.OperationOutcome; 004import org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity; 005import org.hl7.fhir.r5.utils.ToolingExtensions; 006import org.hl7.fhir.utilities.Utilities; 007import org.hl7.fhir.utilities.validation.ValidationMessage; 008 009public class DefaultRenderer extends ValidationOutputRenderer { 010 011 @Override 012 public void render(OperationOutcome oo) { 013 int error = 0; 014 int warn = 0; 015 int info = 0; 016 String file = ToolingExtensions.readStringExtension(oo, ToolingExtensions.EXT_OO_FILE); 017 018 for (OperationOutcome.OperationOutcomeIssueComponent issue : oo.getIssue()) { 019 if (issue.getSeverity() == OperationOutcome.IssueSeverity.FATAL || issue.getSeverity() == OperationOutcome.IssueSeverity.ERROR) 020 error++; 021 else if (issue.getSeverity() == OperationOutcome.IssueSeverity.WARNING) 022 warn++; 023 else 024 info++; 025 } 026 027 if (moreThanOne) { 028 dst.print("-- "); 029 dst.print(file); 030 dst.print(" --"); 031 dst.println(Utilities.padLeft("", '-', Integer.max(38, file.length() + 6))); 032 } 033 dst.println((error == 0 ? "Success" : "*FAILURE*") + ": " + Integer.toString(error) + " errors, " + Integer.toString(warn) + " warnings, " + Integer.toString(info) + " notes"); 034 for (OperationOutcome.OperationOutcomeIssueComponent issue : oo.getIssue()) { 035 dst.println(getIssueSummary(issue)); 036 ValidationMessage vm = (ValidationMessage) issue.getUserData("source.msg"); 037 if (vm != null && vm.sliceText != null && (crumbTrails || vm.isCriticalSignpost())) { 038 for (String s : vm.sliceText) { 039 dst.println(" slice info: "+s); 040 } 041 } 042 } 043 if (moreThanOne) { 044 dst.print("---"); 045 dst.print(Utilities.padLeft("", '-', file.length())); 046 dst.print("---"); 047 dst.println(Utilities.padLeft("", '-', Integer.max(38, file.length() + 6))); 048 dst.println(); 049 } 050 } 051 052 private String getIssueSummary(OperationOutcome.OperationOutcomeIssueComponent issue) { 053 String loc; 054 if (issue.hasExpression()) { 055 int line = ToolingExtensions.readIntegerExtension(issue, ToolingExtensions.EXT_ISSUE_LINE, -1); 056 int col = ToolingExtensions.readIntegerExtension(issue, ToolingExtensions.EXT_ISSUE_COL, -1); 057 loc = " @ "+issue.getExpression().get(0).asStringValue() + (line >= 0 && col >= 0 ? " (line " + Integer.toString(line) + ", col" + Integer.toString(col) + ")" : ""); 058 } else if (issue.hasLocation()) { 059 loc = " @ "+issue.getLocation().get(0).asStringValue(); 060 } else { 061 int line = ToolingExtensions.readIntegerExtension(issue, ToolingExtensions.EXT_ISSUE_LINE, -1); 062 int col = ToolingExtensions.readIntegerExtension(issue, ToolingExtensions.EXT_ISSUE_COL, -1); 063 if (issue.getSeverity() == IssueSeverity.INFORMATION && (line == -1 || col == -1)) { 064 loc = ""; 065 } else { 066 loc = " @ "+"line " + Integer.toString(line) + ", col" + Integer.toString(col); 067 } 068 } 069 return " " + issue.getSeverity().getDisplay() + loc + ": " + issue.getDetails().getText(); 070 } 071 072}