001package org.hl7.fhir.r5.terminologies.validation; 002 003import java.util.ArrayList; 004import java.util.Collections; 005import java.util.List; 006 007import org.hl7.fhir.r5.model.OperationOutcome.IssueSeverity; 008import org.hl7.fhir.r5.model.OperationOutcome.OperationOutcomeIssueComponent; 009import org.hl7.fhir.r5.terminologies.utilities.TerminologyServiceErrorClass; 010import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; 011 012public class ValidationProcessInfo { 013 private TerminologyServiceErrorClass err; 014 private List<OperationOutcomeIssueComponent> issues = new ArrayList<>(); 015 016 public ValidationProcessInfo() { 017 } 018 019 public ValidationProcessInfo(List<OperationOutcomeIssueComponent> issues) { 020 this.issues = issues; 021 } 022 public TerminologyServiceErrorClass getErr() { 023 return err; 024 } 025 public void setErr(TerminologyServiceErrorClass err) { 026 this.err = err; 027 } 028 029 public List<OperationOutcomeIssueComponent> getIssues() { 030 return issues; 031 } 032 public void addIssue(List<OperationOutcomeIssueComponent> issues) { 033 this.issues.addAll(issues); 034 035 } 036 public boolean hasErrors() { 037 for (OperationOutcomeIssueComponent issue : issues) { 038 if (issue.getSeverity() == IssueSeverity.FATAL || issue.getSeverity() == IssueSeverity.ERROR) { 039 return true; 040 } 041 } 042 return false; 043 } 044 public String summary() { 045 List<String> msgs = new ArrayList<>(); 046 for (OperationOutcomeIssueComponent issue : issues) { 047 msgs.add(issue.getDetails().getText()); 048 } 049 Collections.sort(msgs); 050 return CommaSeparatedStringBuilder.join("; ", msgs); 051 } 052 public List<String> summaryList() { 053 List<String> msgs = new ArrayList<>(); 054 for (OperationOutcomeIssueComponent issue : issues) { 055 msgs.add(issue.getDetails().getText()); 056 } 057 Collections.sort(msgs); 058 return msgs; 059 } 060 061 public boolean hasMessage(String msg) { 062 for (OperationOutcomeIssueComponent iss : issues) { 063 if (msg.equals(iss.getDetails().getText())) { 064 return true; 065 } 066 } 067 return false; 068 } 069 070 public boolean hasNotFound(String system) { 071 for (OperationOutcomeIssueComponent iss : issues) { 072 if (iss.getDetails().hasCoding("http://hl7.org/fhir/tools/CodeSystem/tx-issue-type", "not-found") && 073 iss.getDetails().hasText() && iss.getDetails().getText().contains(system)) { 074 return true; 075 } 076 } 077 return false; 078 } 079}