Search in sources :

Example 1 with Unflattener

use of org.ehrbase.client.flattener.Unflattener in project openEHR_SDK by ehrbase.

the class DefaultRestCompositionEndpoint method mergeCompositionEntity.

@Override
public <T> T mergeCompositionEntity(T entity) {
    Composition composition = (Composition) new Unflattener(defaultRestClient.getTemplateProvider(), defaultRestClient.getDefaultValuesProvider()).unflatten(entity);
    Optional<VersionUid> versionUid = extractVersionUid(entity);
    final VersionUid updatedVersion = internalMerge(composition, versionUid.orElse(null));
    Flattener.addVersion(entity, updatedVersion);
    entity = (T) new Flattener(defaultRestClient.getTemplateProvider()).flatten(composition, entity.getClass());
    Flattener.addVersion(entity, updatedVersion);
    return entity;
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) VersionUid(org.ehrbase.client.openehrclient.VersionUid) Flattener(org.ehrbase.client.flattener.Flattener) Unflattener(org.ehrbase.client.flattener.Unflattener)

Example 2 with Unflattener

use of org.ehrbase.client.flattener.Unflattener in project fhir-bridge by ehrbase.

the class CompositionProducer method debugMapping.

private void debugMapping(CompositionEntity composition) {
    ResourceTemplateProvider resourceTemplateProvider = new ResourceTemplateProvider("classpath:/opt/");
    resourceTemplateProvider.afterPropertiesSet();
    Unflattener unflattener = new Unflattener(resourceTemplateProvider);
    RMObject rmObject = unflattener.unflatten(composition);
    CanonicalJson canonicalJson = new CanonicalJson();
    String compositionJson = canonicalJson.marshal(rmObject);
    writeToFile(compositionJson);
}
Also used : CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) ResourceTemplateProvider(org.ehrbase.fhirbridge.ehr.ResourceTemplateProvider) Unflattener(org.ehrbase.client.flattener.Unflattener) RMObject(com.nedap.archie.rm.RMObject)

Example 3 with Unflattener

use of org.ehrbase.client.flattener.Unflattener in project openEHR_SDK by ehrbase.

the class OldDtoModelTest method testUnflattenCorona.

@Test
public void testUnflattenCorona() throws IOException {
    Composition expected = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.CORONA.getStream(), StandardCharsets.UTF_8), Composition.class);
    Flattener flattener = new Flattener(new TestDataTemplateProvider());
    CoronaAnamneseComposition coronaAnamneseComposition = flattener.flatten(expected, CoronaAnamneseComposition.class);
    Unflattener cut = new Unflattener(new TestDataTemplateProvider());
    Composition actual = (Composition) cut.unflatten(coronaAnamneseComposition);
    assertThat(actual).isNotNull();
    assertThat(actual.getContent()).extracting(Locatable::getNameAsString, Locatable::getArchetypeNodeId).containsExactlyInAnyOrder(actual.getContent().stream().map(c -> new Tuple(c.getNameAsString(), c.getArchetypeNodeId())).toArray(Tuple[]::new));
}
Also used : CoronaAnamneseComposition(org.ehrbase.client.classgenerator.olddtoexamples.coronaanamnesecomposition.CoronaAnamneseComposition) Composition(com.nedap.archie.rm.composition.Composition) TestAllTypesEnV1Composition(org.ehrbase.client.classgenerator.olddtoexamples.testalltypesenv1composition.TestAllTypesEnV1Composition) CoronaAnamneseComposition(org.ehrbase.client.classgenerator.olddtoexamples.coronaanamnesecomposition.CoronaAnamneseComposition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) CompositionTestDataCanonicalJson(org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson) Flattener(org.ehrbase.client.flattener.Flattener) Unflattener(org.ehrbase.client.flattener.Unflattener) Tuple(org.assertj.core.groups.Tuple) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) Test(org.junit.Test)

Example 4 with Unflattener

use of org.ehrbase.client.flattener.Unflattener in project openEHR_SDK by ehrbase.

the class OldDtoModelTest method checkTestCase.

public void checkTestCase(TestCase testCase, SoftAssertions softly) throws IOException {
    String value = IOUtils.toString(testCase.simSDTJson.getStream(), UTF_8);
    RMDataFormat flatJson = new FlatJasonProvider(new TestDataTemplateProvider()).buildFlatJson(FlatFormat.SIM_SDT, testCase.templateId);
    Composition composition = flatJson.unmarshal(value);
    Flattener flattener = new Flattener(new TestDataTemplateProvider());
    Object flatten = flattener.flatten(composition, testCase.dtoClass);
    Unflattener unflattener = new Unflattener(new TestDataTemplateProvider());
    RMObject actual = unflattener.unflatten(flatten);
    String actualFlat = flatJson.marshal(actual);
    List<String> errors = compere(actualFlat, value);
    softly.assertThat(errors).filteredOn(s -> s.startsWith("Missing")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.missing);
    softly.assertThat(errors).filteredOn(s -> s.startsWith("Extra")).as("Test Case %s", testCase.id).containsExactlyInAnyOrder(testCase.extra);
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) TestAllTypesEnV1Composition(org.ehrbase.client.classgenerator.olddtoexamples.testalltypesenv1composition.TestAllTypesEnV1Composition) CoronaAnamneseComposition(org.ehrbase.client.classgenerator.olddtoexamples.coronaanamnesecomposition.CoronaAnamneseComposition) RMDataFormat(org.ehrbase.serialisation.RMDataFormat) Flattener(org.ehrbase.client.flattener.Flattener) Unflattener(org.ehrbase.client.flattener.Unflattener) RMObject(com.nedap.archie.rm.RMObject) FlatJasonProvider(org.ehrbase.serialisation.flatencoding.FlatJasonProvider) TestDataTemplateProvider(org.ehrbase.client.templateprovider.TestDataTemplateProvider) RMObject(com.nedap.archie.rm.RMObject)

Aggregations

Unflattener (org.ehrbase.client.flattener.Unflattener)4 Composition (com.nedap.archie.rm.composition.Composition)3 Flattener (org.ehrbase.client.flattener.Flattener)3 RMObject (com.nedap.archie.rm.RMObject)2 CoronaAnamneseComposition (org.ehrbase.client.classgenerator.olddtoexamples.coronaanamnesecomposition.CoronaAnamneseComposition)2 TestAllTypesEnV1Composition (org.ehrbase.client.classgenerator.olddtoexamples.testalltypesenv1composition.TestAllTypesEnV1Composition)2 TestDataTemplateProvider (org.ehrbase.client.templateprovider.TestDataTemplateProvider)2 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)2 Tuple (org.assertj.core.groups.Tuple)1 VersionUid (org.ehrbase.client.openehrclient.VersionUid)1 ResourceTemplateProvider (org.ehrbase.fhirbridge.ehr.ResourceTemplateProvider)1 RMDataFormat (org.ehrbase.serialisation.RMDataFormat)1 FlatJasonProvider (org.ehrbase.serialisation.flatencoding.FlatJasonProvider)1 CompositionTestDataCanonicalJson (org.ehrbase.test_data.composition.CompositionTestDataCanonicalJson)1 Test (org.junit.Test)1