Search in sources :

Example 6 with CodeableConcept

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

the class IssueTest method build.

@Test
public void build() throws Exception {
    Issue issue = Issue.builder().severity(IssueSeverity.ERROR).code(IssueType.REQUIRED).addExpression("Issue expression").addLocation("Issue location").details(CodeableConcept.builder().addCoding(Coding.builder().code("A").display("A display").build()).text("Text").build()).build();
    assertEquals(IssueSeverity.ERROR.getCode(), issue.getSeverity());
    assertEquals(IssueType.REQUIRED.getCode(), issue.getCode());
    assertThat(issue.getExpressions(), hasItems("Issue expression"));
    assertThat(issue.getLocations(), hasItems("Issue location"));
    CodeableConcept details = issue.getDetails();
    assertEquals(1, details.getCodings().size());
    assertEquals("Text", details.getText());
    Coding coding = details.getCodings().iterator().next();
    assertEquals("A", coding.getCode().getCodeValue());
    assertEquals("A display", coding.getDisplay());
}
Also used : Issue(com.b2international.snowowl.fhir.core.model.Issue) Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) CodeableConcept(com.b2international.snowowl.fhir.core.model.dt.CodeableConcept) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 7 with CodeableConcept

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

the class FhirValidateCodeRequest method collectCodingsToValidate.

private Set<Coding> collectCodingsToValidate(ValidateCodeRequest request) {
    Set<Coding> codings = new HashSet<>(3);
    if (request.getCode() != null) {
        Coding coding = Coding.builder().code(request.getCode()).display(request.getDisplay()).build();
        codings.add(coding);
    }
    if (request.getCoding() != null) {
        codings.add(request.getCoding());
    }
    CodeableConcept codeableConcept = request.getCodeableConcept();
    if (codeableConcept != null) {
        if (codeableConcept.getCodings() != null) {
            codeableConcept.getCodings().forEach(c -> codings.add(c));
        }
    }
    return codings;
}
Also used : Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) HashSet(java.util.HashSet) CodeableConcept(com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)

Example 8 with CodeableConcept

use of com.b2international.snowowl.fhir.core.model.dt.CodeableConcept 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 9 with CodeableConcept

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

the class RestTest method validate.

private void validate(Rest rest) {
    assertEquals("documentation", rest.getDocumentation());
    assertEquals(RestfulCapabilityMode.CLIENT.getCode(), rest.getMode());
    assertEquals("serviceDescription", rest.getSecurity().getDescription());
    CodeableConcept serviceConcept = rest.getSecurity().getServices().iterator().next();
    assertEquals("codingTest", serviceConcept.getText());
    Resource restResource = rest.getResources().iterator().next();
    assertEquals("profile", restResource.getProfile().getUriValue());
    assertEquals("name", restResource.getOperations().iterator().next().getName());
    assertEquals("compartment", rest.getCompartments().iterator().next().getUriValue());
    assertEquals("name", rest.getSearchParams().iterator().next().getName());
}
Also used : CodeableConcept(com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)

Example 10 with CodeableConcept

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

the class CodeableConcepTest method deserialize.

@Test
public void deserialize() throws JsonProcessingException {
    Coding coding = Coding.builder().code("codingCode").display("codingDisplay").system("http://www.whocc.no/atc").version("20180131").build();
    CodeableConcept cc = CodeableConcept.builder().addCoding(coding).text("text").build();
    String serializedString = objectMapper.writeValueAsString(cc);
    CodeableConcept codeableConcept = objectMapper.readValue(serializedString, CodeableConcept.class);
    assertEquals("text", codeableConcept.getText());
    Coding builtCoding = codeableConcept.getCodings().iterator().next();
    assertEquals("codingCode", builtCoding.getCode().getCodeValue());
    assertEquals("codingDisplay", builtCoding.getDisplay());
    assertEquals("http://www.whocc.no/atc", builtCoding.getSystem().getUriValue());
    assertEquals("20180131", builtCoding.getVersion());
}
Also used : Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) CodeableConcept(com.b2international.snowowl.fhir.core.model.dt.CodeableConcept) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Aggregations

CodeableConcept (com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)11 Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)10 Test (org.junit.Test)6 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)5 Issue (com.b2international.snowowl.fhir.core.model.Issue)4 OperationOutcome (com.b2international.snowowl.fhir.core.model.OperationOutcome)1 Builder (com.b2international.snowowl.fhir.core.model.OperationOutcome.Builder)1 ValidateCodeRequest (com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest)1 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)1 FhirRestTest (com.b2international.snowowl.fhir.tests.FhirRestTest)1 JsonPath (io.restassured.path.json.JsonPath)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1