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.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

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);
        return issues.stream()
                .filter(issue -> IssueSeverity.ERROR.equals(issue.getSeverity()))
                .collect(Collectors.toList());
    }

    public static List getWarnings(List issues) {
        Objects.requireNonNull(issues);
        return issues.stream()
                .filter(issue -> IssueSeverity.WARNING.equals(issue.getSeverity()))
                .collect(Collectors.toList());
    }

    public static List getInformation(List issues) {
        Objects.requireNonNull(issues);
        return issues.stream()
                .filter(issue -> IssueSeverity.INFORMATION.equals(issue.getSeverity()))
                .collect(Collectors.toList());
    }

    public static boolean hasErrors(List issues) {
        return !getErrors(issues).isEmpty();
    }

    public static boolean hasWarnings(List issues) {
        return !getWarnings(issues).isEmpty();
    }

    public static boolean hasInformation(List issues) {
        return !getInformation(issues).isEmpty();
    }

    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