Search in sources :

Example 1 with Coding

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

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

the class IssueTest method deserialize.

@Test
public void deserialize() 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();
    Issue readIssue = objectMapper.readValue(objectMapper.writeValueAsString(issue), Issue.class);
    assertEquals(IssueSeverity.ERROR.getCode(), readIssue.getSeverity());
    assertEquals(IssueType.REQUIRED.getCode(), readIssue.getCode());
    assertThat(readIssue.getExpressions(), hasItems("Issue expression"));
    assertThat(readIssue.getLocations(), hasItems("Issue location"));
    CodeableConcept details = readIssue.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 3 with Coding

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

the class SandBoxRestTest method buildCode.

// @Test
public void buildCode() throws IOException {
    Coding coding = Coding.builder().system("http://hl7.org/fhir/issue-severity").code("fatal").build();
    LookupRequest request = LookupRequest.builder().coding(coding).addProperty("name").build();
    Json json1 = new Parameters.Json(request);
    Fhir fhir = new Parameters.Fhir(json1.parameters());
    String fhirJson = objectMapper.writeValueAsString(fhir);
    System.out.println("This is the JSON request from the client: " + fhirJson);
    System.out.println("This is happening in the server-side...");
    Fhir parameters = objectMapper.readValue(fhirJson, Parameters.Fhir.class);
    System.out.println("Deserialized into FHIR parameters..." + parameters.getParameters());
    System.out.println("Back to Domain JSON...");
    Json json = new Parameters.Json(parameters);
    Parameters parameters2 = json.parameters();
    List<Parameter> parameters3 = parameters2.getParameters();
    for (Parameter parameter : parameters3) {
        System.out.println("P: " + parameter);
    }
    LookupRequest lookupRequest = objectMapper.convertValue(json, LookupRequest.class);
    System.out.println("... and back to the object representation we started from:" + lookupRequest);
    Json finalJson = new Parameters.Json(lookupRequest);
    Fhir finalFhir = new Parameters.Fhir(finalJson.parameters());
    String stringJson = objectMapper.writeValueAsString(finalFhir);
    System.out.println("Final final: " + stringJson);
/*
			*/
// String jsonBody = objectMapper.writeValueAsString(fhirParameters);
// System.out.println("Json: " + jsonBody);
}
Also used : Parameters(com.b2international.snowowl.fhir.core.model.dt.Parameters) 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) Json(com.b2international.snowowl.fhir.core.model.dt.Parameters.Json) LookupRequest(com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)

Example 4 with Coding

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

the class CodeableConceptUsageContextTest method setup.

@Before
public void setup() throws Exception {
    Coding coding = Coding.builder().code("1234").system("http://www.whocc.no/atc").version("20180131").build();
    CodeableConcept cc = CodeableConcept.builder().addCoding(coding).text("text").build();
    usageContext = CodeableConceptUsageContext.builder().code(Coding.builder().code("coding").display("codingDisplay").build()).value(cc).id("usageContextId").build();
}
Also used : Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) CodeableConcept(com.b2international.snowowl.fhir.core.model.dt.CodeableConcept) Before(org.junit.Before)

Example 5 with Coding

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

the class ValidateFhirCodeRestTest method validCodingTestWithPostTest.

@Test
public void validCodingTestWithPostTest() throws Exception {
    String system = "http://hl7.org/fhir/issue-severity";
    Coding coding = Coding.builder().system(system).code("fatal").build();
    ValidateCodeRequest request = ValidateCodeRequest.builder().url(system).coding(coding).build();
    Fhir fhirParameters = new Parameters.Fhir(request);
    String jsonBody = objectMapper.writeValueAsString(fhirParameters);
    givenAuthenticatedRequest(FHIR_ROOT_CONTEXT).contentType(APPLICATION_FHIR_JSON).body(jsonBody).when().post("/CodeSystem/$validate-code").then().body("resourceType", equalTo("Parameters")).body("parameter[0].name", equalTo("result")).body("parameter[0].valueBoolean", equalTo(true)).statusCode(200);
}
Also used : Coding(com.b2international.snowowl.fhir.core.model.dt.Coding) Fhir(com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir) ValidateCodeRequest(com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest) Test(org.junit.Test) FhirRestTest(com.b2international.snowowl.fhir.tests.FhirRestTest)

Aggregations

Coding (com.b2international.snowowl.fhir.core.model.dt.Coding)24 Test (org.junit.Test)16 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)13 CodeableConcept (com.b2international.snowowl.fhir.core.model.dt.CodeableConcept)11 Fhir (com.b2international.snowowl.fhir.core.model.dt.Parameters.Fhir)9 Issue (com.b2international.snowowl.fhir.core.model.Issue)6 LookupRequest (com.b2international.snowowl.fhir.core.model.codesystem.LookupRequest)6 Parameters (com.b2international.snowowl.fhir.core.model.dt.Parameters)5 Json (com.b2international.snowowl.fhir.core.model.dt.Parameters.Json)5 OperationOutcomeCode (com.b2international.snowowl.fhir.core.codesystems.OperationOutcomeCode)3 ValidateCodeRequest (com.b2international.snowowl.fhir.core.model.codesystem.ValidateCodeRequest)3 Parameter (com.b2international.snowowl.fhir.core.model.dt.Parameter)3 FhirRestTest (com.b2international.snowowl.fhir.tests.FhirRestTest)3 JsonPath (io.restassured.path.json.JsonPath)3 IssueSeverity (com.b2international.snowowl.fhir.core.codesystems.IssueSeverity)2 IssueType (com.b2international.snowowl.fhir.core.codesystems.IssueType)2 ValidationException (com.b2international.snowowl.fhir.core.exceptions.ValidationException)2 Designation (com.b2international.snowowl.fhir.core.model.Designation)2 Builder (com.b2international.snowowl.fhir.core.model.Issue.Builder)2 Uri (com.b2international.snowowl.fhir.core.model.dt.Uri)2