Search in sources :

Example 41 with DvCodedText

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

the class TermMappingRMUnmarshaller method handle.

/**
 * {@inheritDoc}
 */
@Override
public void handle(String currentTerm, TermMapping rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
    setValue(currentTerm, "match", currentValues, s -> Optional.ofNullable(s).map(c -> c.charAt(0)).ifPresent(rmObject::setMatch), String.class, consumedPaths);
    Map<FlatPathDto, String> targetValues = FlatHelper.filter(currentValues, currentTerm + "/target", false);
    if (!targetValues.isEmpty()) {
        rmObject.setTarget(new CodePhrase());
        context.getNodeDeque().push(buildDummyChild("target", context.getNodeDeque().peek()));
        CODE_PHRASE_RM_UNMARSHALLER.handle(currentTerm + "/target", rmObject.getTarget(), targetValues, context, consumedPaths);
        context.getNodeDeque().poll();
    }
    Map<FlatPathDto, String> purposeValues = FlatHelper.filter(currentValues, currentTerm + "/purpose", false);
    if (!purposeValues.isEmpty()) {
        rmObject.setPurpose(new DvCodedText());
        context.getNodeDeque().push(buildDummyChild("purpose", context.getNodeDeque().peek()));
        DV_CODED_TEXT_RM_UNMARSHALLER.handle(currentTerm + "/purpose", rmObject.getPurpose(), purposeValues, context, consumedPaths);
        context.getNodeDeque().poll();
    }
}
Also used : CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto)

Example 42 with DvCodedText

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

the class TermMappingTestOverwritten method testTermMappingFromMap.

@Override
@Test
public void testTermMappingFromMap() throws Exception {
    String template = this.getFileContent("/res/Demo Vitals.xml");
    String rawJson = this.getFileContent("/res/TmComposition.json");
    Composition unmarshal = new CanonicalJson().unmarshal(rawJson.replace("\"@class\"", "\"_type\""), Composition.class);
    String flatJson = getFlatJson(template, FlatFormat.SIM_SDT).marshal(unmarshal);
    Composition actualComposition = getFlatJson(template, FlatFormat.SIM_SDT).unmarshal(flatJson);
    List<TermMapping> termMappings = ((DvText) actualComposition.itemsAtPath("/content[openEHR-EHR-SECTION.ispek_dialog.v1]/items[openEHR-EHR-OBSERVATION.body_temperature-zn.v1]/data[at0002]/events/data/items[at0.63]/value").get(0)).getMappings();
    assertThat(termMappings).extracting(TermMapping::getMatch, t -> t.getTarget().getCodeString(), t -> t.getTarget().getTerminologyId().getValue(), TermMapping::getPurpose).containsExactlyInAnyOrder(new Tuple('=', "21794005", "SNOMED-CT", null), new Tuple('=', "W.11.7", "RTX", null));
    List<TermMapping> termMappings2 = ((DvText) actualComposition.itemsAtPath("/content[openEHR-EHR-SECTION.ispek_dialog.v1]/items[openEHR-EHR-OBSERVATION.body_temperature-zn.v1]/data[at0002]/events/state/items[at0041]/value").get(0)).getMappings();
    assertThat(termMappings2).extracting(TermMapping::getMatch, t -> t.getTarget().getCodeString(), t -> t.getTarget().getTerminologyId().getValue(), TermMapping::getPurpose).containsExactlyInAnyOrder(new Tuple('=', "99.1", "IAXA", new DvCodedText("Purpose 1", new CodePhrase(new TerminologyId("Purposes"), "p.0.63.1"))));
}
Also used : TermMapping(com.nedap.archie.rm.datavalues.TermMapping) Tuple(org.assertj.core.groups.Tuple) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) Composition(com.nedap.archie.rm.composition.Composition) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvText(com.nedap.archie.rm.datavalues.DvText) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.jupiter.api.Test) TermMappingTest(care.better.platform.web.template.TermMappingTest) List(java.util.List) Helper.getFlatJson(org.ehrbase.conformance_test.extern.Helper.getFlatJson) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) TermMapping(com.nedap.archie.rm.datavalues.TermMapping) FlatFormat(org.ehrbase.serialisation.flatencoding.FlatFormat) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) Composition(com.nedap.archie.rm.composition.Composition) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Tuple(org.assertj.core.groups.Tuple) DvText(com.nedap.archie.rm.datavalues.DvText) Test(org.junit.jupiter.api.Test) TermMappingTest(care.better.platform.web.template.TermMappingTest)

Example 43 with DvCodedText

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

the class SimpleValidationTest method testSimpleValidation.

@Test
public void testSimpleValidation() throws Exception {
    TerminologyInterface simpleTerminologyInterface = new SimpleTerminologyInterface("en");
    AttributeCodesetMapping codesetMapping = AttributeCodesetMapping.getInstance();
    CodePhrase codePhrase = new CodePhrase(new TerminologyId("openehr"), "433");
    DvCodedText category = new DvCodedText("event", codePhrase);
    // get the actual attribute
    String attribute = codesetMapping.actualAttributeId("openehr", "category", "en");
    ContainerType containerType = codesetMapping.containerType("openehr", "category");
    switch(containerType) {
        case // a code string defined within a group of a codeset
        GROUP:
            boolean valid = simpleTerminologyInterface.terminology("openehr").hasCodeForGroupId(attribute, codePhrase);
            // check if the supplied value matches codephrase
            String rubric = simpleTerminologyInterface.terminology("openehr").rubricForCode(codePhrase.getCodeString(), "en");
            valid = rubric.equals("event");
            break;
        case // a codestring defined in a codeset
        CODESET:
            valid = simpleTerminologyInterface.codeSet(attribute).hasCode(codePhrase);
            break;
        default:
            throw new IllegalArgumentException("undefined container type");
    }
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) TerminologyInterface(org.ehrbase.terminology.openehr.TerminologyInterface) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) Test(org.junit.Test)

Example 44 with DvCodedText

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

the class DvCodedTextAdapter method write.

@Override
public void write(JsonWriter writer, DvCodedText dvalue) throws IOException {
    if (!Optional.ofNullable(dvalue).map(DvCodedText::getDefiningCode).map(CodePhrase::getCodeString).isPresent()) {
        writer.nullValue();
        return;
    }
    TermMappingAdapter termMappingAdapter = new TermMappingAdapter();
    if (adapterType == I_DvTypeAdapter.AdapterType.PG_JSONB) {
        writer.beginObject();
        writer.name(VALUE).value(dvalue.getValue());
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(DvCodedText.class.getSimpleName()).camelToUpperSnake());
        writer.name("definingCode");
        writer.beginObject();
        writer.name("codeString").value(dvalue.getDefiningCode().getCodeString());
        writer.name("terminologyId");
        writer.beginObject();
        writer.name(VALUE).value(dvalue.getDefiningCode().getTerminologyId().getValue());
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(TerminologyId.class.getSimpleName()).camelToUpperSnake());
        writer.endObject();
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(CodePhrase.class.getSimpleName()).camelToUpperSnake());
        writer.endObject();
        termMappingAdapter.write(writer, dvalue.getMappings());
        writer.endObject();
    } else if (adapterType == I_DvTypeAdapter.AdapterType.RAW_JSON) {
        writer.beginObject();
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new ObjectSnakeCase(dvalue).camelToUpperSnake());
        writer.name(VALUE).value(dvalue.getValue());
        CodePhrase codePhrase = dvalue.getDefiningCode();
        writer.name("defining_code").value(gson.toJson(codePhrase));
        writer.name(I_DvTypeAdapter.TAG_CLASS_RAW_JSON).value(new SnakeCase(CodePhrase.class.getSimpleName()).camelToUpperSnake());
        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) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) ObjectSnakeCase(org.ehrbase.serialisation.util.ObjectSnakeCase)

Example 45 with DvCodedText

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

the class DvOrdinalConfig method buildChildValues.

/**
 * {@inheritDoc}
 */
@Override
public Map<String, Object> buildChildValues(String currentTerm, DvOrdinal rmObject, Context<Map<String, Object>> context) {
    Map<String, Object> result = new HashMap<>();
    String codeString = Optional.of(rmObject).map(DvOrdinal::getSymbol).map(DvCodedText::getDefiningCode).map(CodePhrase::getCodeString).orElse(null);
    addValue(result, currentTerm, "code", codeString);
    WebTemplateInputValue value = context.getNodeDeque().peek().getInputs().get(0).getList().stream().filter(o -> o.getValue().equals(codeString)).findAny().orElseThrow(() -> new SdkException(String.format("Unknown Ordinal with code %s", codeString)));
    addValue(result, currentTerm, "ordinal", value.getOrdinal());
    addValue(result, currentTerm, "value", value.getLabel());
    return result;
}
Also used : DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) HashMap(java.util.HashMap) SdkException(org.ehrbase.util.exception.SdkException) WebTemplateInputValue(org.ehrbase.webtemplate.model.WebTemplateInputValue)

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