All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibm.fhir.validation.util.FHIRValidationUtil Maven / Gradle / Ivy

/*
 * (C) Copyright IBM Corp. 2020, 2021
 *
 * SPDX-License-Identifier: Apache-2.0
 */

package com.ibm.fhir.validation.util;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

import com.ibm.fhir.model.resource.OperationOutcome.Issue;
import com.ibm.fhir.model.type.code.IssueSeverity;

public final class FHIRValidationUtil {
    public static final Comparator ISSUE_COMPARATOR = new Comparator() {
        @Override
        public int compare(Issue first, Issue second) {
            return first.getSeverity().getValueAsEnum().compareTo(second.getSeverity().getValueAsEnum());
        }
    };

    private FHIRValidationUtil() { }

    public static List getErrors(List issues) {
        Objects.requireNonNull(issues);
        List errors = new ArrayList<>();
        for (Issue issue : issues) {
            if (IssueSeverity.ERROR.equals(issue.getSeverity())) {
                errors.add(issue);
            }
        }
        return errors;
    }

    public static List getWarnings(List issues) {
        Objects.requireNonNull(issues);
        List warnings = new ArrayList<>();
        for (Issue issue : issues) {
            if (IssueSeverity.WARNING.equals(issue.getSeverity())) {
                warnings.add(issue);
            }
        }
        return warnings;
    }

    public static List getInformation(List issues) {
        Objects.requireNonNull(issues);
        List information = new ArrayList<>();
        for (Issue issue : issues) {
            if (IssueSeverity.INFORMATION.equals(issue.getSeverity())) {
                information.add(issue);
            }
        }
        return information;
    }

    public static boolean hasErrors(List issues) {
        for (Issue issue : issues) {
            if (IssueSeverity.ERROR.equals(issue.getSeverity())) {
                return true;
            }
        }
        return false;
    }

    public static boolean hasWarnings(List issues) {
        for (Issue issue : issues) {
            if (IssueSeverity.WARNING.equals(issue.getSeverity())) {
                return true;
            }
        }
        return false;
    }

    public static boolean hasInformation(List issues) {
        for (Issue issue : issues) {
            if (IssueSeverity.INFORMATION.equals(issue.getSeverity())) {
                return true;
            }
        }
        return false;
    }

    public static int countErrors(List issues) {
        return getErrors(issues).size();
    }

    public static int countWarnings(List issues) {
        return getWarnings(issues).size();
    }

    public static int countInformation(List issues) {
        return getInformation(issues).size();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy