From 235def48b4a9bf21be5818b398cfe15d4fad9608 Mon Sep 17 00:00:00 2001 From: stefanspiska Date: Tue, 1 Mar 2022 07:46:47 +0100 Subject: [PATCH] fix history origin in flat (#329) * fix history origin in flat see CDR-273 * fix IsmTransition in flat see CDR-273 * fix test see CDR-273 * add CHANGELOG.md --- CHANGELOG.md | 1 + .../postprocessor/HistoryPostprocessor.java | 16 ++--- .../IsmTransitionPostprocessor.java | 63 +++++++++++++++++++ .../IsmTransitionPostprocessor.java | 32 ++++++++++ .../ehrbase_conformance_action.json | 7 +++ .../ehrbase_conformance_observation.json | 1 + 6 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/marshal/postprocessor/IsmTransitionPostprocessor.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 7de8ecf15..7059e627b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Note: version releases in the 0.x.y range may introduce breaking changes. ### Fixed - Flat : corrected handling of PARTY_PROXY ( see https://github.com/ehrbase/openEHR_SDK/pull/320) +- Flat : corrected handling of history origin and ISM_TRANSITION (see https://github.com/ehrbase/openEHR_SDK/pull/329) - Walker, Flat, DTO, Validation : enhance performance of path handling ( see https://github.com/ehrbase/openEHR_SDK/pull/325 ) diff --git a/serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/marshal/postprocessor/HistoryPostprocessor.java b/serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/marshal/postprocessor/HistoryPostprocessor.java index 7d08f820d..f6977aaa8 100644 --- a/serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/marshal/postprocessor/HistoryPostprocessor.java +++ b/serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/marshal/postprocessor/HistoryPostprocessor.java @@ -25,7 +25,6 @@ import com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime; import org.ehrbase.serialisation.walker.Context; -import java.time.temporal.TemporalAccessor; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -44,18 +43,21 @@ public void process( Context> context) { if (rmObject.getOrigin() != null && rmObject.getOrigin().getValue() != null) { - Optional first = + + // Add history origin only if different from time of first event. + Optional first = ((History) rmObject) .getEvents().stream() .map(Event::getTime) .filter(Objects::nonNull) - .map(DvDateTime::getValue) - .filter(Objects::nonNull) + .filter(t -> t.getValue() != null) .sorted() .findFirst(); - first - .filter(t -> t.equals(((History) rmObject).getOrigin().getValue())) - .ifPresent(t -> values.remove(term + "/" + "origin")); + if (first + .filter(t -> Objects.equals(t.getMagnitude(), rmObject.getOrigin().getMagnitude())) + .isEmpty()) { + addValue(values, term + "/history_origin", null, rmObject.getOrigin().getValue()); + } } } diff --git a/serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/marshal/postprocessor/IsmTransitionPostprocessor.java b/serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/marshal/postprocessor/IsmTransitionPostprocessor.java new file mode 100644 index 000000000..89ff479a5 --- /dev/null +++ b/serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/marshal/postprocessor/IsmTransitionPostprocessor.java @@ -0,0 +1,63 @@ +/* + * + * * Copyright (c) 2020 Stefan Spiska (Vitasystems GmbH) and Hannover Medical School + * * This file is part of Project EHRbase + * * + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package org.ehrbase.serialisation.flatencoding.std.marshal.postprocessor; + +import com.nedap.archie.rm.composition.IsmTransition; +import org.ehrbase.serialisation.walker.Context; + +import java.util.Map; +import java.util.stream.IntStream; + +public class IsmTransitionPostprocessor extends AbstractMarshalPostprocessor { + + /** {@inheritDoc} Adds the encoding information */ + @Override + public void process( + String term, + IsmTransition rmObject, + Map values, + Context> context) { + + IntStream.range(0, rmObject.getReason().size()) + .forEach( + i -> { + callMarshal( + term, + "_reason:" + i, + rmObject.getReason().get(i), + values, + context, + context.getNodeDeque().peek().findChildById("mapping").orElse(null)); + callPostprocess( + term, + "_reason:" + i, + rmObject.getReason().get(i), + values, + context, + context.getNodeDeque().peek().findChildById("mapping").orElse(null)); + }); + } + + /** {@inheritDoc} */ + @Override + public Class getAssociatedClass() { + return IsmTransition.class; + } +} diff --git a/serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/umarshal/postprocessor/IsmTransitionPostprocessor.java b/serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/umarshal/postprocessor/IsmTransitionPostprocessor.java index 99492ed64..d1e5a39dd 100644 --- a/serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/umarshal/postprocessor/IsmTransitionPostprocessor.java +++ b/serialisation/src/main/java/org/ehrbase/serialisation/flatencoding/std/umarshal/postprocessor/IsmTransitionPostprocessor.java @@ -20,6 +20,8 @@ package org.ehrbase.serialisation.flatencoding.std.umarshal.postprocessor; import com.nedap.archie.rm.composition.IsmTransition; +import com.nedap.archie.rm.datavalues.DvCodedText; +import com.nedap.archie.rm.datavalues.DvText; import org.apache.commons.collections4.CollectionUtils; import org.ehrbase.client.classgenerator.EnumValueSet; import org.ehrbase.client.classgenerator.shareddefinition.State; @@ -68,6 +70,36 @@ public void process( .map(EnumValueSet::toCodedText) .ifPresent(rmObject::setCurrentState); } + + Map> reasonValues = + FlatHelper.extractMultiValued(term, "_reason", values); + + reasonValues.forEach( + (key, value) -> { + final DvText reasonText; + if (FlatHelper.isExactlyDvCodedText(value, term + "/_reason:0")) { + reasonText = new DvCodedText(); + } else { + reasonText = new DvText(); + } + rmObject.addReason(reasonText); + callUnmarshal( + term, + "_reason:" + key, + reasonText, + value, + consumedPaths, + context, + FlatHelper.findOrBuildSubNode(context, "reason")); + callPostProcess( + term, + "_reason:" + key, + reasonText, + value, + consumedPaths, + context, + FlatHelper.findOrBuildSubNode(context, "reason")); + }); } /** {@inheritDoc} */ diff --git a/test-data/src/main/resources/composition/flat/simSDT/conformance/ehrbase_conformance_action.json b/test-data/src/main/resources/composition/flat/simSDT/conformance/ehrbase_conformance_action.json index ca5e4ea0d..e335f27f2 100644 --- a/test-data/src/main/resources/composition/flat/simSDT/conformance/ehrbase_conformance_action.json +++ b/test-data/src/main/resources/composition/flat/simSDT/conformance/ehrbase_conformance_action.json @@ -20,6 +20,13 @@ "conformance-ehrbase.de.v0/conformance_section/conformance_action/ism_transition/current_state|code": "532", "conformance-ehrbase.de.v0/conformance_section/conformance_action/ism_transition/current_state|value": "completed", "conformance-ehrbase.de.v0/conformance_section/conformance_action/ism_transition/current_state|terminology": "openehr", + "conformance-ehrbase.de.v0/conformance_section/conformance_action/ism_transition/transition|code": "548", + "conformance-ehrbase.de.v0/conformance_section/conformance_action/ism_transition/transition|value": "finish", + "conformance-ehrbase.de.v0/conformance_section/conformance_action/ism_transition/transition|terminology": "openehr", + "conformance-ehrbase.de.v0/conformance_section/conformance_action/ism_transition/careflow_step|code": "at0006", + "conformance-ehrbase.de.v0/conformance_section/conformance_action/ism_transition/careflow_step|value": "transition", + "conformance-ehrbase.de.v0/conformance_section/conformance_action/ism_transition/careflow_step|terminology": "local", + "conformance-ehrbase.de.v0/conformance_section/conformance_action/ism_transition/_reason:0": "reason 1", "conformance-ehrbase.de.v0/conformance_section/conformance_action/_instruction_details|path": "/content[openEHR-EHR-SECTION.conformance_section.v0]/items[openEHR-EHR-INSTRUCTION.conformance_instruction.v0]", "conformance-ehrbase.de.v0/conformance_section/conformance_action/_instruction_details|composition_uid": "4cdc3017-d8c5-4cd3-9900-f3bb7171d006", "conformance-ehrbase.de.v0/conformance_section/conformance_action/_instruction_details|activity_id": "activities[at0001]", diff --git a/test-data/src/main/resources/composition/flat/simSDT/conformance/ehrbase_conformance_observation.json b/test-data/src/main/resources/composition/flat/simSDT/conformance/ehrbase_conformance_observation.json index 499ded5fa..1e133dd56 100644 --- a/test-data/src/main/resources/composition/flat/simSDT/conformance/ehrbase_conformance_observation.json +++ b/test-data/src/main/resources/composition/flat/simSDT/conformance/ehrbase_conformance_observation.json @@ -20,6 +20,7 @@ "conformance-ehrbase.de.v0/conformance_section/conformance_observation/any_event:0/dv_text_state": "DV_TEXT in State", "conformance-ehrbase.de.v0/conformance_section/conformance_observation/dv_text": "dv_text in protocol", "conformance-ehrbase.de.v0/conformance_section/conformance_observation/any_event:0/time": "2021-12-21T16:02:58.0094262+01:00", + "conformance-ehrbase.de.v0/conformance_section/conformance_observation/history_origin": "2021-12-20T15:02:58.0094262+01:00", "conformance-ehrbase.de.v0/conformance_section/conformance_observation/language|code": "en", "conformance-ehrbase.de.v0/conformance_section/conformance_observation/language|terminology": "ISO_639-1", "conformance-ehrbase.de.v0/conformance_section/conformance_observation/encoding|code": "UTF-8",