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;
}
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();
}
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();
}
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());
}
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();
}
Aggregations