Search in sources :

Example 16 with TerminologyId

use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.

the class TerminologyCheckTest method testSimpleValidationWrongValue.

@Test
public void testSimpleValidationWrongValue() throws Exception {
    DvCodedText category = new DvCodedText("not quite sure what to put here", new CodePhrase(new TerminologyId("openehr"), "433"));
    try {
        org.ehrbase.validation.terminology.validator.DvCodedText.validate(localizedTerminologies.locale("en"), codesetMapping, "category", category, "en");
        fail("should have detected a wrong value");
    } catch (Exception e) {
    }
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Test(org.junit.Test)

Example 17 with TerminologyId

use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.

the class CodePhraseAdapter method write.

@Override
public void write(JsonWriter writer, CodePhrase codePhrase) throws IOException {
    if (codePhrase == null) {
        writer.nullValue();
        return;
    }
    if (adapterType == I_DvTypeAdapter.AdapterType.PG_JSONB) {
        writer.beginObject();
        writer.name("codeString").value(codePhrase.getCodeString());
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(CodePhrase.class.getSimpleName()).camelToUpperSnake());
        writer.name("terminologyId");
        writer.beginObject();
        writer.name("value").value(codePhrase.getTerminologyId().getValue());
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(TerminologyId.class.getSimpleName()).camelToUpperSnake());
        writer.endObject();
        writer.endObject();
    } else if (adapterType == I_DvTypeAdapter.AdapterType.RAW_JSON) {
        writer.beginObject();
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new ObjectSnakeCase(codePhrase).camelToUpperSnake());
        writer.name("code_string").value(codePhrase.getCodeString());
        writer.name("terminology_id").value(gson.toJson(codePhrase.getTerminologyId()));
        writer.endObject();
    }
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) SnakeCase(org.ehrbase.serialisation.util.SnakeCase) ObjectSnakeCase(org.ehrbase.serialisation.util.ObjectSnakeCase) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) ObjectSnakeCase(org.ehrbase.serialisation.util.ObjectSnakeCase)

Example 18 with TerminologyId

use of com.nedap.archie.rm.support.identification.TerminologyId in project openEHR_SDK by ehrbase.

the class CodePhraseRMUnmarshaller method handle.

/**
 * {@inheritDoc}
 */
@Override
public void handle(String currentTerm, CodePhrase rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
    setValue(currentTerm, "code", currentValues, rmObject::setCodeString, String.class, consumedPaths);
    rmObject.setTerminologyId(new TerminologyId());
    setValue(currentTerm, "terminology", currentValues, t -> rmObject.getTerminologyId().setValue(t), String.class, consumedPaths);
    setValue(currentTerm, "preferred_term", currentValues, rmObject::setPreferredTerm, String.class, consumedPaths);
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId)

Example 19 with TerminologyId

use of com.nedap.archie.rm.support.identification.TerminologyId 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 20 with TerminologyId

use of com.nedap.archie.rm.support.identification.TerminologyId 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)

Aggregations

TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)62 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)60 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)50 Test (org.junit.jupiter.api.Test)23 Test (org.junit.Test)13 DvText (com.nedap.archie.rm.datavalues.DvText)10 Composition (com.nedap.archie.rm.composition.Composition)8 ArrayList (java.util.ArrayList)7 AbstractRMObjectValidatorTest (org.ehrbase.validation.webtemplate.AbstractRMObjectValidatorTest)7 PartyIdentified (com.nedap.archie.rm.generic.PartyIdentified)6 DvDateTime (com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)5 RMObject (com.nedap.archie.rm.RMObject)4 EventContext (com.nedap.archie.rm.composition.EventContext)4 PartyProxy (com.nedap.archie.rm.generic.PartyProxy)4 List (java.util.List)4 Locatable (com.nedap.archie.rm.archetyped.Locatable)3 Entry (com.nedap.archie.rm.composition.Entry)3 DvURI (com.nedap.archie.rm.datavalues.DvURI)3 DvOrdinal (com.nedap.archie.rm.datavalues.quantity.DvOrdinal)3 PartyRelated (com.nedap.archie.rm.generic.PartyRelated)3