Search in sources :

Example 96 with Composition

use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.

the class CanonicalXMLTest method unmarshalWithDuplicatedSections.

@Test
public void unmarshalWithDuplicatedSections() throws IOException {
    String value = IOUtils.toString(CompositionTestDataCanonicalXML.REGISTRO_DE_ATENDIMENTO.getStream(), UTF_8);
    CanonicalXML cut = new CanonicalXML();
    Composition composition = cut.unmarshal(value, Composition.class);
    assertThat(composition).isNotNull();
// assertThat(composition.getArchetypeDetails().getTemplateId().getValue()).isEqualTo("test_all_types.en.v1");
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) CompositionTestDataCanonicalXML(org.ehrbase.test_data.composition.CompositionTestDataCanonicalXML) Test(org.junit.Test)

Example 97 with Composition

use of com.nedap.archie.rm.composition.Composition 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)

Example 98 with Composition

use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.

the class CompositionValidatorImp method validateWithParams.

@Override
public List<ValidationErrorDto> validateWithParams(String template, String rawComposition, boolean strictTextValidation, boolean relaxedNameMatching) throws Exception {
    TemplateDocument templateDocument = TemplateDocument.Factory.parse(IOUtils.toInputStream(template, StandardCharsets.UTF_8));
    Composition composition = new CanonicalJson().unmarshal(rawComposition.replace("@class", "_type"), Composition.class);
    org.ehrbase.validation.CompositionValidator validator = new org.ehrbase.validation.CompositionValidator();
    List<ValidationErrorDto> errorDtoList = validator.validate(composition, templateDocument.getTemplate()).stream().filter(e -> !List.of("/content[openEHR-EHR-SECTION.ispek_dialog.v1 and name/value='Restraint medication']/items[openEHR-EHR-INSTRUCTION.medication_order.v1]/activities[at0001]/description[at0002]/items[at0070]", "/context/other_context[at0001]/items[at0.0.81]").contains(e.getAqlPath())).peek(e -> logger.info(e.getMessage() + "|" + e.getAqlPath())).map(e -> new ValidationErrorDto(e.getMessage(), new String[0], 0)).collect(Collectors.toList());
    return errorDtoList;
}
Also used : IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) TemplateDocument(org.openehr.schemas.v1.TemplateDocument) Logger(org.slf4j.Logger) Composition(com.nedap.archie.rm.composition.Composition) LoggerFactory(org.slf4j.LoggerFactory) CompositionValidator(care.better.platform.web.template.validator.CompositionValidator) Collectors(java.util.stream.Collectors) ValidationErrorDto(care.better.platform.web.template.validator.ValidationErrorDto) StandardCharsets(java.nio.charset.StandardCharsets) TemplateDocument(org.openehr.schemas.v1.TemplateDocument) Composition(com.nedap.archie.rm.composition.Composition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionValidator(care.better.platform.web.template.validator.CompositionValidator) ValidationErrorDto(care.better.platform.web.template.validator.ValidationErrorDto)

Example 99 with Composition

use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.

the class NullFlavorTestOverwritten method nullFlavourJsonBuild.

@Override
@Test
public void nullFlavourJsonBuild() throws Exception {
    String template = this.getFileContent("/res/Demo Vitals.xml");
    String json = this.getFileContent("/res/NullFlavor3.json");
    Composition unmarshal = getFlatJson(template, FlatFormat.STRUCTURED).unmarshal(json);
    assertThat(unmarshal).isNotNull();
    Element element1 = (Element) unmarshal.itemsAtPath("/content[openEHR-EHR-SECTION.ispek_dialog.v1]/items[openEHR-EHR-OBSERVATION.lab_test-hba1c.v1,1]/data/events[at0002]/data/items[at0005]").get(0);
    assertThat(element1.getValue()).isNull();
    assertThat(element1.getNullFlavour()).isEqualTo(NullFlavour.NOT_APPLICABLE.toCodedText());
    Element element2 = (Element) unmarshal.itemsAtPath("/content[openEHR-EHR-SECTION.ispek_dialog.v1]/items[openEHR-EHR-OBSERVATION.lab_test-hba1c.v1,2]/data/events[at0003]/data/items[at0004]").get(0);
    assertThat(element2.getValue()).isNull();
    assertThat(element2.getNullFlavour()).isEqualTo(NullFlavour.MASKED.toCodedText());
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) Element(com.nedap.archie.rm.datastructures.Element) Test(org.junit.jupiter.api.Test) NullFlavorTest(care.better.platform.web.template.NullFlavorTest)

Example 100 with Composition

use of com.nedap.archie.rm.composition.Composition in project openEHR_SDK by ehrbase.

the class FeederAuditDetailsAttributesTest method toMap.

@Test
public void toMap() throws Exception {
    String value = IOUtils.toString(CompositionTestDataCanonicalJson.FEEDER_AUDIT_DETAILS.getStream(), UTF_8);
    CanonicalJson cut = new CanonicalJson();
    Composition composition = cut.unmarshal(value, Composition.class);
    assertNotNull(composition);
    assertNotNull(composition.getFeederAudit().getFeederSystemAudit().getOtherDetails());
    // with real data
    FeederAuditDetailsAttributes attributes = new FeederAuditDetailsAttributes(composition.getFeederAudit().getFeederSystemAudit());
    Map<String, Object> map = attributes.toMap();
    assertNotNull(map);
    assertNotNull(map.get("other_details[openEHR-EHR-ITEM_TREE.generic.v1]"));
    // valid fabricated data without brackets
    FeederAuditDetails details = new FeederAuditDetails();
    ItemSingle single = new ItemSingle("test", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
    details.setOtherDetails(single);
    details.setSystemId("system");
    attributes = new FeederAuditDetailsAttributes(details);
    map = attributes.toMap();
    assertNotNull(map.get("other_details[test]"));
    // valid fabricated data with brackets
    details = new FeederAuditDetails();
    single = new ItemSingle("[test]", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
    details.setOtherDetails(single);
    details.setSystemId("system");
    attributes = new FeederAuditDetailsAttributes(details);
    map = attributes.toMap();
    assertNotNull(map.get("other_details[test]"));
    // invalid data with one [
    details = new FeederAuditDetails();
    single = new ItemSingle("[test", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
    details.setOtherDetails(single);
    details.setSystemId("system");
    attributes = new FeederAuditDetailsAttributes(details);
    assertThrows(IllegalArgumentException.class, attributes::toMap);
    // invalid data with one ]
    details = new FeederAuditDetails();
    single = new ItemSingle("test]", new DvCodedText("text", new CodePhrase("string")), new Element("node", new DvText("name"), null));
    details.setOtherDetails(single);
    details.setSystemId("system");
    attributes = new FeederAuditDetailsAttributes(details);
    assertThrows(IllegalArgumentException.class, attributes::toMap);
}
Also used : CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) Composition(com.nedap.archie.rm.composition.Composition) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Element(com.nedap.archie.rm.datastructures.Element) DvText(com.nedap.archie.rm.datavalues.DvText) FeederAuditDetails(com.nedap.archie.rm.archetyped.FeederAuditDetails) ItemSingle(com.nedap.archie.rm.datastructures.ItemSingle) Test(org.junit.Test)

Aggregations

Composition (com.nedap.archie.rm.composition.Composition)138 Test (org.junit.Test)103 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)66 CompositionTestDataCanonicalJson (org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson)53 LightRawJsonEncoder (org.ehrbase.serialisation.dbencoding.rawjson.LightRawJsonEncoder)30 TestDataTemplateProvider (org.ehrbase.client.templateprovider.TestDataTemplateProvider)29 RMDataFormat (org.ehrbase.serialisation.RMDataFormat)28 IOException (java.io.IOException)21 List (java.util.List)21 CoronaAnamneseComposition (org.ehrbase.client.classgenerator.examples.coronaanamnesecomposition.CoronaAnamneseComposition)20 Tuple (org.assertj.core.groups.Tuple)19 EhrbaseBloodPressureSimpleDeV0Composition (org.ehrbase.client.classgenerator.examples.ehrbasebloodpressuresimpledev0composition.EhrbaseBloodPressureSimpleDeV0Composition)19 StandardCharsets (java.nio.charset.StandardCharsets)18 IOUtils (org.apache.commons.io.IOUtils)18 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)18 EhrbaseMultiOccurrenceDeV1Composition (org.ehrbase.client.classgenerator.examples.ehrbasemultioccurrencedev1composition.EhrbaseMultiOccurrenceDeV1Composition)18 OPERATIONALTEMPLATE (org.openehr.schemas.v1.OPERATIONALTEMPLATE)18 EpisodeOfCareComposition (org.ehrbase.client.classgenerator.examples.episodeofcarecomposition.EpisodeOfCareComposition)17 CompositionTestDataCanonicalXML (org.ehrbase.test_data.composition.CompositionTestDataCanonicalXML)17 WebTemplate (org.ehrbase.webtemplate.model.WebTemplate)16