Skip to content

Commit

Permalink
fix history origin in flat (#329)
Browse files Browse the repository at this point in the history
* fix history origin in flat

see CDR-273

* fix IsmTransition in flat

see CDR-273

* fix test

see CDR-273

* add CHANGELOG.md
  • Loading branch information
stefanspiska authored Mar 1, 2022
1 parent 8940c46 commit 235def4
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,18 +43,21 @@ public void process(
Context<Map<String, Object>> context) {

if (rmObject.getOrigin() != null && rmObject.getOrigin().getValue() != null) {
Optional<TemporalAccessor> first =

// Add history origin only if different from time of first event.
Optional<DvDateTime> first =
((History<ItemStructure>) 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<ItemStructure>) 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());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<IsmTransition> {

/** {@inheritDoc} Adds the encoding information */
@Override
public void process(
String term,
IsmTransition rmObject,
Map<String, Object> values,
Context<Map<String, Object>> 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<IsmTransition> getAssociatedClass() {
return IsmTransition.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +70,36 @@ public void process(
.map(EnumValueSet::toCodedText)
.ifPresent(rmObject::setCurrentState);
}

Map<Integer, Map<FlatPathDto, String>> 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} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 235def4

Please sign in to comment.