check for existence of issues with a given severity (#4328)
This commit is contained in:
parent
6ae1672599
commit
248e48072c
|
@ -122,6 +122,26 @@ public class OperationOutcomeUtil {
|
|||
return issueChild.getAccessor().getValues(theOutcome).size();
|
||||
}
|
||||
|
||||
public static boolean hasIssuesOfSeverity(FhirContext theCtx, IBaseOperationOutcome theOutcome, String theSeverity) {
|
||||
RuntimeResourceDefinition ooDef = theCtx.getResourceDefinition(theOutcome);
|
||||
BaseRuntimeChildDefinition issueChild = ooDef.getChildByName("issue");
|
||||
List<IBase> issues = issueChild.getAccessor().getValues(theOutcome);
|
||||
|
||||
if (issues.isEmpty()) {
|
||||
return false; // if there are no issues at all, there are no issues of the required severity
|
||||
}
|
||||
|
||||
IBase firstIssue = issues.get(0);
|
||||
BaseRuntimeElementCompositeDefinition<?> issueElement = (BaseRuntimeElementCompositeDefinition<?>) theCtx.getElementDefinition(firstIssue.getClass());
|
||||
BaseRuntimeChildDefinition severityChild = issueElement.getChildByName("severity");
|
||||
|
||||
return issues.stream()
|
||||
.flatMap(t -> severityChild.getAccessor().getValues(t).stream())
|
||||
.map(t -> (IPrimitiveType<?>) t)
|
||||
.map(IPrimitiveType::getValueAsString)
|
||||
.anyMatch(theSeverity::equals);
|
||||
}
|
||||
|
||||
public static IBaseOperationOutcome newInstance(FhirContext theCtx) {
|
||||
RuntimeResourceDefinition ooDef = theCtx.getResourceDefinition("OperationOutcome");
|
||||
try {
|
||||
|
|
|
@ -44,4 +44,24 @@ public class OperationOutcomeUtilTest {
|
|||
assertNotNull(oo.getIssueFirstRep().getDetails(), "OO.issue.details is empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasIssuesOfSeverity_noMatchingIssues() {
|
||||
OperationOutcome oo = new OperationOutcome();
|
||||
oo.addIssue().setSeverity(OperationOutcome.IssueSeverity.WARNING);
|
||||
oo.addIssue().setSeverity(OperationOutcome.IssueSeverity.ERROR);
|
||||
oo.addIssue().setSeverity(OperationOutcome.IssueSeverity.INFORMATION);
|
||||
|
||||
assertFalse(OperationOutcomeUtil.hasIssuesOfSeverity(myCtx, oo, OperationOutcome.IssueSeverity.FATAL.toCode()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasIssuesOfSeverity_withMatchingIssues() {
|
||||
OperationOutcome oo = new OperationOutcome();
|
||||
oo.addIssue().setSeverity(OperationOutcome.IssueSeverity.WARNING);
|
||||
oo.addIssue().setSeverity(OperationOutcome.IssueSeverity.ERROR);
|
||||
oo.addIssue().setSeverity(OperationOutcome.IssueSeverity.FATAL);
|
||||
oo.addIssue().setSeverity(OperationOutcome.IssueSeverity.INFORMATION);
|
||||
|
||||
assertTrue(OperationOutcomeUtil.hasIssuesOfSeverity(myCtx, oo, OperationOutcome.IssueSeverity.FATAL.toCode()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue