ehrbase / openEHR_SDK

A SDK to facilitate the development of openEHR applications
Other
48 stars 27 forks source link

Issues with Flattener/Unflattener #85

Closed chevalleyc closed 4 years ago

chevalleyc commented 4 years ago

Steps to reproduce

Flatten and unflatten composition using the attached template failed as follows (also attached the corresponding canonical json for use with Postman). Corresponding snippet is as follows:

        Composition composition = new CanonicalJson().unmarshal(IOUtils.toString(CompositionTestDataCanonicalJson.VIROLOGY_FINDING_WITH_SPECIMEN.getStream(), StandardCharsets.UTF_8), Composition.class);

        assertThat(composition.itemsAtPath("/content[openEHR-EHR-OBSERVATION.laboratory_test_result.v1]/data[at0001]/events[at0002]/data[at0003]")).isNotNull();

        Flattener flattener = new Flattener();

        VirologischerBefundComposition virologischerBefundComposition = flattener.flatten(composition, VirologischerBefundComposition.class);
        assertThat(virologischerBefundComposition.getBefund()).isNotNull();

        //with the test data
        virologischerBefundComposition = TestData.buildTestVirologischerBefundComposition();
        assertThat(virologischerBefundComposition.getBefund()).isNotNull();

        UUID ehr = openEhrClient.ehrEndpoint().createEhr();
        openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(virologischerBefundComposition);
  1. Statement assertThat(virologischerBefundComposition.getBefund()).isNotNull(); fails

  2. Statement openEhrClient.compositionEndpoint(ehr).mergeCompositionEntity(virologischerBefundComposition); raises a ClassCastException in Unflattener.java line 97:

           List valueList = (List) value;
            if (CollectionUtils.isNotEmpty((List) child)) {
                List childList = new ArrayList();

    The test data snippet to construct the composition is attached below (the .txt should be removed...)

TestData.buildTestVirologischerBefundComposition() scratch_5.java.txt

Canonical JSON

virology_finding_with_specimen.json.txt

Template Virologischer Befund.opt.txt

Expected result

  1. should be not null
  2. no exception raised

Success criteria

stefanspiska commented 4 years ago

In the template the name of openEHR-EHR-OBSERVATION.laboratory_test_result is renamed from "Laborergebnis" to "Befund" however virology_finding_with_specimen.json.txt the name of openEHR-EHR-OBSERVATION.laboratory_test is "Laborergebnis". If I change it to "Befund" the first assert works.

The second assert was a bug in handling of paths with names.

see

fixed in https://github.com/ehrbase/openEHR_SDK/pull/87