Search in sources :

Example 31 with Issue

use of com.b2international.snowowl.fhir.core.model.Issue in project snow-owl by b2ihealthcare.

the class ExceptionTest method testException2.

@Test
public void testException2() throws Exception {
    Issue expectedIssue = Issue.builder().code(IssueType.INVALID).severity(IssueSeverity.ERROR).diagnostics("No system specified [null]").addLocation("LookupRequest.system").detailsWithDisplay(OperationOutcomeCode.MSG_PARAM_INVALID, "Parameter 'LookupRequest.system' content is invalid").build();
    BadRequestException bre = new BadRequestException("No system specified [null]", "LookupRequest.system");
    exception.expect(FhirException.class);
    exception.expectMessage("No system specified [null]");
    exception.expect(FhirExceptionIssueMatcher.issue(expectedIssue));
    throw bre;
}
Also used : Issue(com.b2international.snowowl.fhir.core.model.Issue) BadRequestException(com.b2international.snowowl.fhir.core.exceptions.BadRequestException) Test(org.junit.Test)

Example 32 with Issue

use of com.b2international.snowowl.fhir.core.model.Issue in project snow-owl by b2ihealthcare.

the class ValidationException method toOperationOutcome.

/**
 * Creates an OperationOutcome representation from this exception. Useful when
 * the exception must be propagated through protocols where Java serialization
 * cannot be used (eg. HTTP), or the possible receiver cannot understand
 * serialized Java class and object byte sequences.
 *
 * @return {@link OperationOutcome} representation of this
 *         {@link FhirException}, never <code>null</code>.
 */
@Override
public OperationOutcome toOperationOutcome() {
    if (violations.isEmpty()) {
        throw new IllegalArgumentException("There are no violations to report.");
    }
    Builder outcomeBuilder = OperationOutcome.builder();
    for (ConstraintViolation<?> violation : violations) {
        String issueDetails = String.format(getOperationOutcomeCode().getDisplayName(), violation.getPropertyPath());
        StringBuilder builder = new StringBuilder(issueDetails);
        builder.append(" [");
        builder.append(violation.getInvalidValue());
        builder.append("]. Violation: ");
        builder.append(violation.getMessage());
        builder.append(".");
        Coding coding = Coding.builder().code(getOperationOutcomeCode().getCodeValue()).system(OperationOutcomeCode.CODE_SYSTEM_URI).display(builder.toString()).build();
        CodeableConcept codeableConcept = CodeableConcept.builder().addCoding(coding).text(builder.toString()).build();
        String location = violation.getRootBean().getClass().getSimpleName() + "." + violation.getPropertyPath().toString();
        Issue issue = Issue.builder().severity(IssueSeverity.ERROR).code(IssueType.INVALID).details(codeableConcept).diagnostics(getMessage()).addLocation(location).build();
        outcomeBuilder.addIssue(issue);
    }
    return outcomeBuilder.build();
}
Also used : Issue(com.b2international.snowowl.fhir.core.model.Issue) Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) Builder(com.b2international.snowowl.fhir.core.model.OperationOutcome.Builder) CodeableConcept(com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)

Example 33 with Issue

use of com.b2international.snowowl.fhir.core.model.Issue in project snow-owl by b2ihealthcare.

the class SimpleQuantityTest method invalidSimpleQuantity.

@Test
public void invalidSimpleQuantity() throws Exception {
    Issue expectedIssue = validationErrorIssueBuilder.addLocation("SimpleQuantity.comparator").detailsWithDisplay(OperationOutcomeCode.MSG_PARAM_INVALID, "Parameter 'comparator' content is invalid [Code [codeValue=>=]]. Violation: must be null.").build();
    exception.expect(ValidationException.class);
    exception.expectMessage("1 validation error");
    exception.expect(FhirExceptionIssueMatcher.issue(expectedIssue));
    SimpleQuantity.builder().value(12.3).unit("mg").system("uri:LOINC").code("code").comparator(QuantityComparator.GREATER_OR_EQUAL_TO).build();
}
Also used : Issue(com.b2international.snowowl.fhir.core.model.Issue) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 34 with Issue

use of com.b2international.snowowl.fhir.core.model.Issue in project snow-owl by b2ihealthcare.

the class ExpandValueSetRequestDeserializationTest method testDeserialization.

// @Test
public void testDeserialization() {
    Coding coding = Coding.builder().system("http://hl7.org/fhir/issue-severity").code("fatal").build();
    LookupRequest request = LookupRequest.builder().coding(coding).build();
    Fhir fhirParameters = new Parameters.Fhir(request);
    fhirParameters.getParameters().forEach(p -> System.out.println(p));
    Optional<Parameter> findFirst = fhirParameters.getParameters().stream().filter(p -> {
        Coding pCoding = (Coding) p.getValue();
        return pCoding.getSystemValue().equals("http://hl7.org/fhir/issue-severity");
    }).findFirst();
    assertTrue(findFirst.isPresent());
}
Also used : OperationOutcomeCode(com.b2international.snowowl.fhir.core.codesystems.OperationOutcomeCode) ValidationException(com.b2international.snowowl.fhir.core.exceptions.ValidationException) IssueSeverity(com.b2international.snowowl.fhir.core.codesystems.IssueSeverity) Parameter(com.b2international.snowowl.fhir.core.model.dt.Parameter) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Assert.assertTrue(org.junit.Assert.assertTrue) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) Test(org.junit.Test) Uri(com.b2international.snowowl.fhir.core.model.dt.Uri) LookupRequest(com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest) IssueType(com.b2international.snowowl.fhir.core.codesystems.IssueType) Json(com.b2international.snowowl.fhir.core.model.dt.Parameters.Json) ExpandValueSetRequest(com.b2international.snowowl.fhir.core.model.valueset.ExpandValueSetRequest) Issue(com.b2international.snowowl.fhir.core.model.Issue) Optional(java.util.Optional) Builder(com.b2international.snowowl.fhir.core.model.Issue.Builder) Parameters(com.b2international.snowowl.fhir.core.model.dt.Parameters) Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) FhirExceptionIssueMatcher(com.b2international.snowowl.fhir.tests.FhirExceptionIssueMatcher) Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) Parameter(com.b2international.snowowl.fhir.core.model.dt.Parameter) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) LookupRequest(com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)

Example 35 with Issue

use of com.b2international.snowowl.fhir.core.model.Issue in project snow-owl by b2ihealthcare.

the class FilterTest method filterMissingCodeTest.

@Test
public void filterMissingCodeTest() throws Exception {
    Issue expectedIssue = Issue.builder().code(IssueType.INVALID).severity(IssueSeverity.ERROR).diagnostics("1 validation error").addLocation("Filter.code").detailsWithDisplay(OperationOutcomeCode.MSG_PARAM_INVALID, "Parameter 'code' content is invalid [null]. Violation: may not be null.").build();
    exception.expect(ValidationException.class);
    exception.expectMessage("1 validation error");
    exception.expect(FhirExceptionIssueMatcher.issue(expectedIssue));
    Filter.builder().value("A SNOMED CT code").addOperator(FilterOperator.EQUALS).build();
}
Also used : Issue(com.b2international.snowowl.fhir.core.model.Issue) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Aggregations

Issue (com.b2international.snowowl.fhir.core.model.Issue)47 Test (org.junit.Test)44 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)42 Builder (com.b2international.snowowl.fhir.core.model.Issue.Builder)18 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)6 ValidationException (com.b2international.snowowl.fhir.core.exceptions.ValidationException)5 OperationOutcomeCode (com.b2international.snowowl.fhir.core.codesystems.OperationOutcomeCode)4 OperationOutcome (com.b2international.snowowl.fhir.core.model.OperationOutcome)4 CodeableConcept (com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)4 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)4 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)4 IssueSeverity (com.b2international.snowowl.fhir.core.codesystems.IssueSeverity)3 IssueType (com.b2international.snowowl.fhir.core.codesystems.IssueType)3 Parameters (com.b2international.snowowl.fhir.core.model.dt.Parameters)3 FhirExceptionIssueMatcher (com.b2international.snowowl.fhir.tests.FhirExceptionIssueMatcher)3 Optional (java.util.Optional)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 BadRequestException (com.b2international.snowowl.fhir.core.exceptions.BadRequestException)2 LookupRequest (com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)2 Parameter (com.b2international.snowowl.fhir.core.model.dt.Parameter)2