Search in sources :

Example 21 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.

the class DvTextPostprocessor method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(String term, DvText rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
    FlatHelper.extractMultiValuedFullPath(term, "_mapping", values).entrySet().stream().map(e -> {
        TermMapping termMapping = new TermMapping();
        callUnmarshal(term, "/_mapping:" + e.getKey(), termMapping, e.getValue(), consumedPaths, context, context.getNodeDeque().peek().findChildById("mappings").orElse(buildDummyChild("mappings", context.getNodeDeque().peek())));
        callPostProcess(term, "/_mapping:" + e.getKey(), termMapping, e.getValue(), consumedPaths, context, context.getNodeDeque().peek().findChildById("mappings").orElse(buildDummyChild("mappings", context.getNodeDeque().peek())));
        return termMapping;
    }).forEach(rmObject::addMapping);
    FlatHelper.consumeAllMatching(term + "/_mapping", values, consumedPaths, false);
    Map<FlatPathDto, String> language = FlatHelper.filter(values, term + "/_language", false);
    if (!language.isEmpty()) {
        rmObject.setLanguage(new CodePhrase());
        handleRmAttribute(term, rmObject.getLanguage(), language, consumedPaths, context, "language");
    }
    Map<FlatPathDto, String> encoding = FlatHelper.filter(values, term + "/_encoding", false);
    if (!encoding.isEmpty()) {
        rmObject.setEncoding(new CodePhrase());
        handleRmAttribute(term, rmObject.getEncoding(), encoding, consumedPaths, context, "encoding");
    }
}
Also used : Context(org.ehrbase.serialisation.walker.Context) FlatHelper(org.ehrbase.serialisation.walker.FlatHelper) DvText(com.nedap.archie.rm.datavalues.DvText) Map(java.util.Map) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) FlatHelper.buildDummyChild(org.ehrbase.serialisation.walker.FlatHelper.buildDummyChild) Set(java.util.Set) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) TermMapping(com.nedap.archie.rm.datavalues.TermMapping) TermMapping(com.nedap.archie.rm.datavalues.TermMapping) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto)

Example 22 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.

the class DvCodedTextRMUnmarshaller method handle.

/**
 * {@inheritDoc}
 */
@Override
public void handle(String currentTerm, DvCodedText rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
    setValue(currentTerm, "value", currentValues, rmObject::setValue, String.class, consumedPaths);
    rmObject.setDefiningCode(new CodePhrase());
    setValue(currentTerm, "code", currentValues, c -> rmObject.getDefiningCode().setCodeString(c), String.class, consumedPaths);
    rmObject.getDefiningCode().setTerminologyId(new TerminologyId());
    setValue(currentTerm, "terminology", currentValues, t -> rmObject.getDefiningCode().getTerminologyId().setValue(t), String.class, consumedPaths);
    if (rmObject.getDefiningCode().getCodeString() == null && rmObject.getValue() == null) {
        setValue(currentTerm, null, currentValues, c -> {
            if (c != null) {
                // try to interpret as code
                setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), c));
                if (rmObject.getValue() == null) {
                    // try to interpret as value
                    setFromNode(rmObject, context, v -> Objects.equals(v.getLabel(), c));
                }
            }
        }, String.class, consumedPaths);
    } else if (rmObject.getDefiningCode().getCodeString() == null) {
        setValue(currentTerm, null, currentValues, // It is the code
        c -> rmObject.getDefiningCode().setCodeString(c), String.class, consumedPaths);
    }
    // Set terminology from Node
    Optional.of(context.getNodeDeque().peek().getInputs()).stream().flatMap(List::stream).filter(i -> "code".equals(i.getSuffix())).findAny().map(WebTemplateInput::getTerminology).ifPresent(t -> rmObject.getDefiningCode().getTerminologyId().setValue(t));
    // Set value from Node
    setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), rmObject.getDefiningCode().getCodeString()));
    // set code from value if not set
    if (rmObject.getDefiningCode().getCodeString() == null && rmObject.getValue() != null) {
        setFromNode(rmObject, context, v -> Objects.equals(v.getLabel(), rmObject.getValue()));
    }
    setFromNode(rmObject, context, v -> Objects.equals(v.getValue(), rmObject.getDefiningCode().getCodeString()));
    // consume strange legacy paths
    if (rmObject.getDefiningCode() != null && rmObject.getDefiningCode().getCodeString() != null) {
        currentValues.keySet().stream().map(FlatPathDto::format).filter(k -> StringUtils.substringAfter(k, "|").equals(rmObject.getDefiningCode().getCodeString())).forEach(consumedPaths::add);
    }
    setValue(currentTerm, "formatting", currentValues, rmObject::setFormatting, String.class, consumedPaths);
}
Also used : Context(org.ehrbase.serialisation.walker.Context) WebTemplateInputValue(org.ehrbase.webtemplate.model.WebTemplateInputValue) java.util(java.util) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) Predicate(java.util.function.Predicate) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) StringUtils(org.apache.commons.lang3.StringUtils) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto)

Example 23 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.

the class DvEncapsulatedPostprocessor method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(String term, DvEncapsulated rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
    Map<FlatPathDto, String> languageValues = filter(values, term + "/_language", false);
    if (!languageValues.isEmpty()) {
        rmObject.setLanguage(new CodePhrase());
        handleRmAttribute(term, rmObject.getLanguage(), languageValues, consumedPaths, context, "language");
    }
    Map<FlatPathDto, String> charsetValues = filter(values, term + "/_charset", false);
    if (!charsetValues.isEmpty()) {
        rmObject.setCharset(new CodePhrase());
        handleRmAttribute(term, rmObject.getCharset(), charsetValues, consumedPaths, context, "charset");
    }
}
Also used : CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto)

Example 24 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.

the class DvOrderedPostprocessor method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(String term, DvOrdered rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
    handleNormalRange(values, consumedPaths, context, term + "/_normal_range", rmObject::setNormalRange);
    FlatHelper.extractMultiValuedFullPath(term, "_other_reference_ranges", values).forEach((k, v) -> {
        ReferenceRange referenceRange = new ReferenceRange();
        rmObject.addOtherReferenceRange(referenceRange);
        Map<FlatPathDto, String> meaningValues = FlatHelper.filter(values, term + "/_other_reference_ranges:" + k + "/meaning", false);
        if (!meaningValues.isEmpty()) {
            final DvText meaning;
            String meaningAttributeName = "meaning";
            boolean isDvCodedText = isDvCodedText(meaningValues, term + "/_other_reference_ranges:" + k + "/meaning");
            if (isDvCodedText) {
                meaning = new DvCodedText();
            } else {
                meaning = new DvText();
            }
            referenceRange.setMeaning(meaning);
            callUnmarshal(term + "/_other_reference_ranges:" + k, meaningAttributeName, meaning, meaningValues, consumedPaths, context, context.getNodeDeque().peek().findChildById(meaningAttributeName).orElse(buildDummyChild(meaningAttributeName, context.getNodeDeque().peek())));
            callPostProcess(term + "/_other_reference_ranges:" + k, meaningAttributeName, meaning, meaningValues, consumedPaths, context, context.getNodeDeque().peek().findChildById(meaningAttributeName).orElse(buildDummyChild(meaningAttributeName, context.getNodeDeque().peek())));
        }
        handleNormalRange(v, consumedPaths, context, term + "/_other_reference_ranges:" + k, referenceRange::setRange);
    });
    setValue(term, "normal_status", values, s -> {
        if (s != null) {
            rmObject.setNormalStatus(new CodePhrase(new TerminologyId("openehr_normal_statuses"), s));
        }
    }, String.class, consumedPaths);
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) FlatHelper.isDvCodedText(org.ehrbase.serialisation.walker.FlatHelper.isDvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) ReferenceRange(com.nedap.archie.rm.datavalues.quantity.ReferenceRange) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) DvText(com.nedap.archie.rm.datavalues.DvText)

Example 25 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase in project openEHR_SDK by ehrbase.

the class IsmTransitionRMUnmarshaller method handle.

@Override
public void handle(String currentTerm, IsmTransition rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
    rmObject.setCurrentState(new DvCodedText());
    rmObject.getCurrentState().setDefiningCode(new CodePhrase());
    rmObject.getCurrentState().getDefiningCode().setTerminologyId(new TerminologyId());
    setValue(currentTerm + "/current_state", "code", currentValues, rmObject.getCurrentState().getDefiningCode()::setCodeString, String.class, consumedPaths);
    setValue(currentTerm + "/current_state", "value", currentValues, rmObject.getCurrentState()::setValue, String.class, consumedPaths);
    setValue(currentTerm + "/current_state", "terminology", currentValues, rmObject.getCurrentState().getDefiningCode().getTerminologyId()::setValue, String.class, consumedPaths);
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase)

Aggregations

CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)71 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)60 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)56 Test (org.junit.jupiter.api.Test)23 Test (org.junit.Test)16 Composition (com.nedap.archie.rm.composition.Composition)12 DvText (com.nedap.archie.rm.datavalues.DvText)12 ArrayList (java.util.ArrayList)8 AbstractRMObjectValidatorTest (org.ehrbase.validation.webtemplate.AbstractRMObjectValidatorTest)7 RMObject (com.nedap.archie.rm.RMObject)5 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)5 FlatPathDto (org.ehrbase.webtemplate.path.flat.FlatPathDto)5 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)4 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)4 ObjectVersionId (com.nedap.archie.rm.support.identification.ObjectVersionId)4 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 WebTemplate (org.ehrbase.webtemplate.model.WebTemplate)4 WebTemplateNode (org.ehrbase.webtemplate.model.WebTemplateNode)4 Entry (com.nedap.archie.rm.composition.Entry)3