Search in sources :

Example 26 with DvCodedText

use of com.nedap.archie.rm.datavalues.DvCodedText 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 27 with DvCodedText

use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.

the class IsmTransitionValueInserter method insert.

@Override
public void insert(IsmTransition rmObject, DefaultValues defaultValues) {
    if (RMHelper.isEmpty(rmObject.getCurrentState()) && defaultValues.containsDefaultValue(DefaultValuePath.ACTION_ISM_TRANSITION_CURRENT_STATE)) {
        State defaultValue = defaultValues.getDefaultValue(DefaultValuePath.ACTION_ISM_TRANSITION_CURRENT_STATE);
        rmObject.setCurrentState(new DvCodedText(defaultValue.getValue(), defaultValue.toCodePhrase()));
    }
}
Also used : DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) State(org.ehrbase.client.classgenerator.shareddefinition.State)

Example 28 with DvCodedText

use of com.nedap.archie.rm.datavalues.DvCodedText 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 29 with DvCodedText

use of com.nedap.archie.rm.datavalues.DvCodedText in project openEHR_SDK by ehrbase.

the class DefaultValues method buildParticipation.

public static Participation buildParticipation(Collection<Map.Entry<String, String>> subValues) {
    Participation participation = new Participation();
    participation.setPerformer(new PartyIdentified());
    extractExact(subValues, "id", s -> {
        participation.getPerformer().setExternalRef(new PartyRef());
        participation.getPerformer().getExternalRef().setType("PARTY");
        GenericId id = new GenericId();
        id.setValue(s);
        participation.getPerformer().getExternalRef().setId(id);
    });
    extract(subValues, "name", ((PartyIdentified) participation.getPerformer())::setName);
    if (participation.getPerformer().getExternalRef() != null) {
        extract(subValues, "id_namespace", n -> participation.getPerformer().getExternalRef().setNamespace(n));
        extract(subValues, "id_scheme", ((GenericId) participation.getPerformer().getExternalRef().getId())::setScheme);
    }
    extract(subValues, "function", s -> participation.setFunction(new DvText(s)));
    extract(subValues, "mode", s -> {
        ParticipationMode participationMode = findEnumValueOrThrow(s, ParticipationMode.class);
        participation.setMode(new DvCodedText());
        participation.getMode().setValue(participationMode.getValue());
        participation.getMode().setDefiningCode(participationMode.toCodePhrase());
    });
    ((PartyIdentified) participation.getPerformer()).setIdentifiers(splitByIndex(filter(subValues.stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), DefaultValuePath.PARTICIPATION.getPath() + "_" + "identifiers")).values().stream().map(DefaultValues::toDvIdentifier).collect(Collectors.toList()));
    return participation;
}
Also used : PartyRef(com.nedap.archie.rm.support.identification.PartyRef) Participation(com.nedap.archie.rm.generic.Participation) GenericId(com.nedap.archie.rm.support.identification.GenericId) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) ParticipationMode(org.ehrbase.client.classgenerator.shareddefinition.ParticipationMode) DvText(com.nedap.archie.rm.datavalues.DvText)

Example 30 with DvCodedText

use of com.nedap.archie.rm.datavalues.DvCodedText 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

DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)74 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)56 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)50 Test (org.junit.jupiter.api.Test)25 DvText (com.nedap.archie.rm.datavalues.DvText)17 Test (org.junit.Test)15 Composition (com.nedap.archie.rm.composition.Composition)9 ArrayList (java.util.ArrayList)9 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)8 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)8 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)7 HierObjectId (com.nedap.archie.rm.support.identification.HierObjectId)7 List (java.util.List)7 AbstractRMObjectValidatorTest (org.ehrbase.validation.webtemplate.AbstractRMObjectValidatorTest)7 IOException (java.io.IOException)6 PersistedPartyProxy (org.ehrbase.dao.access.jooq.party.PersistedPartyProxy)6 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)6 FlatPathDto (org.ehrbase.webtemplate.path.flat.FlatPathDto)6 EventContext (com.nedap.archie.rm.composition.EventContext)4 DvIdentifier (com.nedap.archie.rm.datavalues.DvIdentifier)4