Search in sources :

Example 1 with OperationOutcome

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

the class FhirExceptionIssueMatcher method matchesSafely.

@Override
protected boolean matchesSafely(FhirException validationException) {
    OperationOutcome operationOutcome = validationException.toOperationOutcome();
    Collection<Issue> issues = operationOutcome.getIssues();
    if (issues.isEmpty()) {
        return false;
    }
    foundIssue = issues.iterator().next();
    boolean issueMatched = foundIssue.getCode().equals(expectedIssue.getCode()) && foundIssue.getSeverity().equals(expectedIssue.getSeverity()) && foundIssue.getDiagnostics().equals(expectedIssue.getDiagnostics());
    if (!issueMatched) {
        return false;
    }
    boolean collectionsMatch = HashMultiset.create(foundIssue.getLocations()).equals(HashMultiset.create(expectedIssue.getLocations())) && HashMultiset.create(foundIssue.getExpressions()).equals(HashMultiset.create(expectedIssue.getExpressions()));
    if (!collectionsMatch) {
        System.out.println("Issue expression do not match, found: " + foundIssue.getExpressions());
        System.out.println("Issue locations do not match, found: " + foundIssue.getLocations());
        return false;
    }
    if (foundIssue.getDetails() == null && expectedIssue.getDetails() != null) {
        System.out.println("Codeable concept is null.");
        return false;
    }
    if (foundIssue.getDetails() != null && expectedIssue.getDetails() == null) {
        System.out.println("Codeable concept is not null: " + foundIssue.getDetails());
        return false;
    }
    if (foundIssue.getDetails() != null && expectedIssue.getDetails() != null) {
        CodeableConcept foundCodeableConcept = foundIssue.getDetails();
        CodeableConcept expectedCodeableConcept = expectedIssue.getDetails();
        Collection<Coding> foundCodings = foundCodeableConcept.getCodings();
        Collection<Coding> expectedCodings = expectedCodeableConcept.getCodings();
        boolean codingMatched = foundCodeableConcept.getText().equals(expectedCodeableConcept.getText()) && HashMultiset.create(foundCodings).equals(HashMultiset.create(expectedCodings));
        if (!codingMatched) {
            System.out.println("Codings do not match: " + foundCodeableConcept.getText());
            return false;
        }
    }
    return true;
}
Also used : Issue(com.b2international.snowowl.fhir.core.model.Issue) Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) OperationOutcome(com.b2international.snowowl.fhir.core.model.OperationOutcome) CodeableConcept(com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)

Example 2 with OperationOutcome

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

the class BundleTest method buildMixedBundle.

@Test
public void buildMixedBundle() throws Exception {
    LookupResult lookupResult = LookupResult.builder().name("test").display("display").addDesignation(Designation.builder().value("dValue").languageCode("uk").build()).addProperty(Property.builder().code("1234").description("propDescription").valueString("stringValue").build()).build();
    OperationOutcome operationOutcome = OperationOutcome.builder().addIssue(Issue.builder().code(IssueType.CODE_INVALID).diagnostics("Invalid code").severity(IssueSeverity.ERROR).build()).build();
    Json json1 = new Parameters.Json(lookupResult);
    ParametersResponseEntry lookupResultEntry = ParametersResponseEntry.builder().resource(new Parameters.Fhir(json1.parameters())).response(BatchResponse.createOkResponse()).build();
    OperationOutcomeEntry operationOutcomeEntry = OperationOutcomeEntry.builder().operationOutcome(operationOutcome).build();
    Bundle bundle = Bundle.builder().language("en").type(BundleType.BATCH_RESPONSE).addLink("self", "http://localhost:8080/snowowl/CodeSystem").addEntry(lookupResultEntry).addEntry(operationOutcomeEntry).build();
    assertEquals("en", bundle.getLanguage().getCodeValue());
    assertEquals(BundleType.BATCH_RESPONSE.getCode(), bundle.getType());
    Link link = bundle.getLink().iterator().next();
    assertEquals("self", link.getRelation());
    assertEquals("http://localhost:8080/snowowl/CodeSystem", link.getUrl().getUriValue());
    Iterator<Entry> iterator = bundle.getItems().iterator();
    Entry bundleEntry = iterator.next();
    assertTrue(bundleEntry instanceof ParametersResponseEntry);
    ParametersResponseEntry responseEntry = (ParametersResponseEntry) bundleEntry;
    assertEquals("200", responseEntry.getResponse().getStatus());
    Fhir requestResource = responseEntry.getResponseResource();
    // Back to Domain JSON...
    Json json = new Parameters.Json(requestResource);
    LookupResult returnedResponse = objectMapper.convertValue(json, LookupResult.class);
    assertEquals("test", returnedResponse.getName());
    assertEquals("display", returnedResponse.getDisplay());
    bundleEntry = iterator.next();
    assertTrue(bundleEntry instanceof OperationOutcomeEntry);
    OperationOutcomeEntry ooce = (OperationOutcomeEntry) bundleEntry;
    Collection<Issue> issues = ooce.getOperationOutcome().getIssues();
    assertEquals(1, issues.size());
    assertEquals(IssueSeverity.ERROR.getCode(), issues.iterator().next().getSeverity());
}
Also used : Parameters(com.b2international.snowowl.fhir.core.model.dt.Parameters) Issue(com.b2international.snowowl.fhir.core.model.Issue) Bundle(com.b2international.snowowl.fhir.core.model.Bundle) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) Json(com.b2international.snowowl.fhir.core.model.dt.Parameters.Json) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) OperationOutcomeEntry(com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry) ParametersRequestEntry(com.b2international.snowowl.fhir.core.model.ParametersRequestEntry) ParametersResponseEntry(com.b2international.snowowl.fhir.core.model.ParametersResponseEntry) ResourceRequestEntry(com.b2international.snowowl.fhir.core.model.ResourceRequestEntry) Entry(com.b2international.snowowl.fhir.core.model.Entry) ResourceResponseEntry(com.b2international.snowowl.fhir.core.model.ResourceResponseEntry) OperationOutcomeEntry(com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry) OperationOutcome(com.b2international.snowowl.fhir.core.model.OperationOutcome) ParametersResponseEntry(com.b2international.snowowl.fhir.core.model.ParametersResponseEntry) LookupResult(com.b2international.snowowl.fhir.core.model.codesystem.LookupResult) Link(com.b2international.snowowl.fhir.core.model.Link) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 3 with OperationOutcome

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

the class BundleTest method deserializeOperationOutcomeBundle.

@Test
public void deserializeOperationOutcomeBundle() throws JsonProcessingException {
    OperationOutcome operationOutcome = OperationOutcome.builder().addIssue(Issue.builder().code(IssueType.CODE_INVALID).diagnostics("Invalid code").severity(IssueSeverity.ERROR).build()).build();
    OperationOutcomeEntry operationOutcomeEntry = OperationOutcomeEntry.builder().operationOutcome(operationOutcome).response(new BatchResponse("404")).build();
    Bundle bundle = Bundle.builder().language("en").type(BundleType.BATCH_RESPONSE).addLink("self", "http://localhost:8080/snowowl/CodeSystem").addEntry(operationOutcomeEntry).build();
    String json = objectMapper.writeValueAsString(bundle);
    Bundle readBundle = objectMapper.readValue(json, Bundle.class);
    assertEquals("batch-response", readBundle.getType().getCodeValue());
}
Also used : OperationOutcomeEntry(com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry) OperationOutcome(com.b2international.snowowl.fhir.core.model.OperationOutcome) BatchResponse(com.b2international.snowowl.fhir.core.model.BatchResponse) Bundle(com.b2international.snowowl.fhir.core.model.Bundle) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 4 with OperationOutcome

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

the class OperationOutcomeTest method build.

@Test
public void build() throws Exception {
    OperationOutcome operationOutcome = OperationOutcome.builder().addIssue(Issue.builder().severity(IssueSeverity.ERROR).code(IssueType.REQUIRED).build()).build();
    assertEquals(1, operationOutcome.getIssues().size());
    Issue issue = operationOutcome.getIssues().iterator().next();
    assertEquals(IssueSeverity.ERROR.getCode(), issue.getSeverity());
    assertEquals(IssueType.REQUIRED.getCode(), issue.getCode());
}
Also used : Issue(com.b2international.snowowl.fhir.core.model.Issue) OperationOutcome(com.b2international.snowowl.fhir.core.model.OperationOutcome) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 5 with OperationOutcome

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

the class OperationOutcomeTest method deserialize.

@Test
public void deserialize() throws Exception {
    OperationOutcome operationOutcome = OperationOutcome.builder().addIssue(Issue.builder().severity(IssueSeverity.ERROR).code(IssueType.REQUIRED).build()).build();
    OperationOutcome readOperationOutcome = objectMapper.readValue(objectMapper.writeValueAsString(operationOutcome), OperationOutcome.class);
    assertEquals(1, readOperationOutcome.getIssues().size());
    Issue issue = readOperationOutcome.getIssues().iterator().next();
    assertEquals(IssueSeverity.ERROR.getCode(), issue.getSeverity());
    assertEquals(IssueType.REQUIRED.getCode(), issue.getCode());
}
Also used : Issue(com.b2international.snowowl.fhir.core.model.Issue) OperationOutcome(com.b2international.snowowl.fhir.core.model.OperationOutcome) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Aggregations

OperationOutcome (com.b2international.snowowl.fhir.core.model.OperationOutcome)7 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)5 Test (org.junit.Test)5 Issue (com.b2international.snowowl.fhir.core.model.Issue)4 Bundle (com.b2international.snowowl.fhir.core.model.Bundle)2 OperationOutcomeEntry (com.b2international.snowowl.fhir.core.model.OperationOutcomeEntry)2 FhirException (com.b2international.snowowl.fhir.core.exceptions.FhirException)1 BatchResponse (com.b2international.snowowl.fhir.core.model.BatchResponse)1 Entry (com.b2international.snowowl.fhir.core.model.Entry)1 Link (com.b2international.snowowl.fhir.core.model.Link)1 ParametersRequestEntry (com.b2international.snowowl.fhir.core.model.ParametersRequestEntry)1 ParametersResponseEntry (com.b2international.snowowl.fhir.core.model.ParametersResponseEntry)1 ResourceRequestEntry (com.b2international.snowowl.fhir.core.model.ResourceRequestEntry)1 ResourceResponseEntry (com.b2international.snowowl.fhir.core.model.ResourceResponseEntry)1 LookupResult (com.b2international.snowowl.fhir.core.model.codesystem.LookupResult)1 CodeableConcept (com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)1 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)1 Parameters (com.b2international.snowowl.fhir.core.model.dt.Parameters)1 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)1 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)1