Search in sources :

Example 1 with CompositionValidator

use of org.ehrbase.validation.CompositionValidator in project openEHR_SDK by ehrbase.

the class FlatConformanceTest method testRoundTrip.

@ParameterizedTest
@MethodSource("testRoundTripArguments")
void testRoundTrip(CompositionTestDataConformanceSDTJson testData, String[] expectedMissing, String[] expectedExtra, String[] expectedValidationErrorPath) throws IOException {
    String templateId = testData.getTemplate().getTemplateId();
    RMDataFormat cut = new FlatJasonProvider(TEMPLATE_PROVIDER).buildFlatJson(FlatFormat.SIM_SDT, templateId);
    String flat = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
    Composition unmarshal = cut.unmarshal(flat);
    SoftAssertions softAssertions = new SoftAssertions();
    softAssertions.assertThat(unmarshal).isNotNull();
    CompositionValidator rmObjectValidator = new CompositionValidator();
    softAssertions.assertThat(rmObjectValidator.validate(unmarshal, TEMPLATE_PROVIDER.buildIntrospect(templateId).orElseThrow())).filteredOn(d -> !ArrayUtils.contains(expectedValidationErrorPath, d.getAqlPath())).isEmpty();
    String actual = cut.marshal(unmarshal);
    String expected = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
    List<String> errors = compere(actual, expected);
    softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder(expectedMissing);
    softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder(expectedExtra);
    softAssertions.assertAll();
}
Also used : Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) Composition(com.nedap.archie.rm.composition.Composition) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ArrayUtils(org.apache.commons.lang3.ArrayUtils) IOException(java.io.IOException) Arguments(org.junit.jupiter.params.provider.Arguments) JacksonUtil(org.ehrbase.serialisation.jsonencoding.JacksonUtil) CompositionValidator(org.ehrbase.validation.CompositionValidator) StandardCharsets(java.nio.charset.StandardCharsets) ArrayList(java.util.ArrayList) IOUtils(org.apache.commons.io.IOUtils) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) CompositionTestDataConformanceSDTJson(org.ehrbase.test_data.composition.CompositionTestDataConformanceSDTJson) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) TestDataTemplateProvider(org.ehrbase.conformance_test.templateprovider.TestDataTemplateProvider) Map(java.util.Map) FlatFormat(org.ehrbase.serialisation.flatencoding.FlatFormat) MethodSource(org.junit.jupiter.params.provider.MethodSource) Composition(com.nedap.archie.rm.composition.Composition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) SoftAssertions(org.assertj.core.api.SoftAssertions) CompositionValidator(org.ehrbase.validation.CompositionValidator) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with CompositionValidator

use of org.ehrbase.validation.CompositionValidator in project openEHR_SDK by ehrbase.

the class DbConformanceTest method testRoundTrip.

@ParameterizedTest
@MethodSource("testRoundTripArguments")
void testRoundTrip(CompositionTestDataConformanceSDTJson testData, String[] expectedMissing, String[] expectedExtra, String[] expectedValidationErrorPath) throws IOException {
    String templateId = testData.getTemplate().getTemplateId();
    RMDataFormat cut = new FlatJasonProvider(TEMPLATE_PROVIDER).buildFlatJson(FlatFormat.SIM_SDT, templateId);
    String flat = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
    Composition composition = cut.unmarshal(flat);
    CompositionSerializer compositionSerializerRawJson = new CompositionSerializer();
    String db_encoded = compositionSerializerRawJson.dbEncode(composition);
    assertNotNull(db_encoded);
    String converted = new LightRawJsonEncoder(db_encoded).encodeCompositionAsString();
    assertNotNull(converted);
    Composition actual = new CanonicalJson().unmarshal(converted, Composition.class);
    SoftAssertions softAssertions = new SoftAssertions();
    softAssertions.assertThat(actual).isNotNull();
    CompositionValidator rmObjectValidator = new CompositionValidator();
    softAssertions.assertThat(rmObjectValidator.validate(actual, TEMPLATE_PROVIDER.buildIntrospect(templateId).orElseThrow())).filteredOn(d -> !List.of("/composer", "/language", "/category", "/territory").contains(d.getAqlPath())).filteredOn(d -> !(Objects.equals("/", d.getAqlPath()) && d.getMessage().equals("Invariant Is_archetype_root failed on type COMPOSITION"))).filteredOn(d -> !ArrayUtils.contains(expectedValidationErrorPath, d.getAqlPath())).isEmpty();
    String actualString = cut.marshal(actual);
    String expected = IOUtils.toString(testData.getStream(), StandardCharsets.UTF_8);
    List<String> errors = compere(actualString, expected);
    softAssertions.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).containsExactlyInAnyOrder(expectedMissing);
    softAssertions.assertThat(errors).filteredOn(s -> !List.of("Extra path: conformance-ehrbase.de.v0/_uid, value: 6e3a9506-b81c-4d74-a37f-1464fb7106b2::piri.ehrscape.com::1", "Extra path: conformance-ehrbase.de.v0/language|code, value: en", "Extra path: conformance-ehrbase.de.v0/language|terminology, value: ISO_639-1", "Extra path: conformance-ehrbase.de.v0/territory|code, value: US", "Extra path: conformance-ehrbase.de.v0/territory|terminology, value: ISO_3166-1", "Extra path: conformance-ehrbase.de.v0/category|code, value: 433", "Extra path: conformance-ehrbase.de.v0/category|value, value: event", "Extra path: conformance-ehrbase.de.v0/category|terminology, value: openehr", "Extra path: conformance-ehrbase.de.v0/context/_health_care_facility|id, value: 9091", "Extra path: conformance-ehrbase.de.v0/context/_health_care_facility|id_scheme, value: HOSPITAL-NS", "Extra path: conformance-ehrbase.de.v0/context/_health_care_facility|id_namespace, value: HOSPITAL-NS", "Extra path: conformance-ehrbase.de.v0/context/_health_care_facility|name, value: Hospital", "Extra path: conformance-ehrbase.de.v0/context/start_time, value: 2021-12-21T14:19:31.649613+01:00", "Extra path: conformance-ehrbase.de.v0/context/_end_time, value: 2021-12-21T15:19:31.649613+01:00", "Extra path: conformance-ehrbase.de.v0/context/_location, value: 2021-12-21T15:19:31.649613+01:00", "Extra path: conformance-ehrbase.de.v0/context/setting|code, value: 238", "Extra path: conformance-ehrbase.de.v0/context/setting|value, value: other care", "Extra path: conformance-ehrbase.de.v0/context/setting|terminology, value: openehr", "Extra path: conformance-ehrbase.de.v0/composer|name, value: Silvia Blake", "Extra path: conformance-ehrbase.de.v0/composer|id, value: 1234-5678", "Extra path: conformance-ehrbase.de.v0/composer|id_scheme, value: UUID", "Extra path: conformance-ehrbase.de.v0/composer|id_namespace, value: EHR.NETWORK", "Extra path: conformance-ehrbase.de.v0/context/_participation:0|function, value: requester", "Extra path: conformance-ehrbase.de.v0/context/_participation:0|mode, value: face-to-face communication", "Extra path: conformance-ehrbase.de.v0/context/_participation:0|name, value: Dr. Marcus Johnson", "Extra path: conformance-ehrbase.de.v0/context/_participation:0|id, value: 199", "Extra path: conformance-ehrbase.de.v0/context/_participation:0|id_scheme, value: HOSPITAL-NS", "Extra path: conformance-ehrbase.de.v0/context/_participation:0|id_namespace, value: HOSPITAL-NS", "Extra path: conformance-ehrbase.de.v0/_link:0|type, value: problem", "Extra path: conformance-ehrbase.de.v0/_link:0|meaning, value: problem related note", "Extra path: conformance-ehrbase.de.v0/_link:0|target, value: ehr://ehr.network/347a5490-55ee-4da9-b91a-9bba710f730e").contains(s)).filteredOn(s -> s.startsWith("Extra")).containsExactlyInAnyOrder(expectedExtra);
    softAssertions.assertAll();
}
Also used : java.util(java.util) SoftAssertions(org.assertj.core.api.SoftAssertions) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) Composition(com.nedap.archie.rm.composition.Composition) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ArrayUtils(org.apache.commons.lang3.ArrayUtils) IOException(java.io.IOException) Arguments(org.junit.jupiter.params.provider.Arguments) CompositionSerializer(org.ehrbase.serialisation.dbencoding.CompositionSerializer) JacksonUtil(org.ehrbase.serialisation.jsonencoding.JacksonUtil) CompositionValidator(org.ehrbase.validation.CompositionValidator) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) CompositionTestDataConformanceSDTJson(org.ehrbase.test_data.composition.CompositionTestDataConformanceSDTJson) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) TestDataTemplateProvider(org.ehrbase.conformance_test.templateprovider.TestDataTemplateProvider) LightRawJsonEncoder(org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder) FlatFormat(org.ehrbase.serialisation.flatencoding.FlatFormat) MethodSource(org.junit.jupiter.params.provider.MethodSource) Composition(com.nedap.archie.rm.composition.Composition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) LightRawJsonEncoder(org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) SoftAssertions(org.assertj.core.api.SoftAssertions) CompositionSerializer(org.ehrbase.serialisation.dbencoding.CompositionSerializer) CompositionValidator(org.ehrbase.validation.CompositionValidator) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Composition (com.nedap.archie.rm.composition.Composition)2 IOException (java.io.IOException)2 StandardCharsets (java.nio.charset.StandardCharsets)2 IOUtils (org.apache.commons.io.IOUtils)2 ArrayUtils (org.apache.commons.lang3.ArrayUtils)2 SoftAssertions (org.assertj.core.api.SoftAssertions)2 TestDataTemplateProvider (org.ehrbase.conformance_test.templateprovider.TestDataTemplateProvider)2 RMDataFormat (org.ehrbase.serialisation.RMDataFormat)2 FlatFormat (org.ehrbase.serialisation.flatencoding.FlatFormat)2 FlatJasonProvider (org.ehrbase.serialisation.flatencoding.FlatJasonProvider)2 JacksonUtil (org.ehrbase.serialisation.jsonencoding.JacksonUtil)2 CompositionTestDataConformanceSDTJson (org.ehrbase.test_data.composition.CompositionTestDataConformanceSDTJson)2 CompositionValidator (org.ehrbase.validation.CompositionValidator)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Arguments (org.junit.jupiter.params.provider.Arguments)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 java.util (java.util)1 ArrayList (java.util.ArrayList)1