Search in sources :

Example 36 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase 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 37 with CodePhrase

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

the class DvMultimediaRMUnmarshaller method handle.

/**
 * {@inheritDoc}
 */
@Override
public void handle(String currentTerm, DvMultimedia rmObject, Map<FlatPathDto, String> currentValues, Context<Map<FlatPathDto, String>> context, Set<String> consumedPaths) {
    rmObject.setUri(new DvURI());
    setValue(currentTerm, "url", currentValues, rmObject.getUri()::setValue, URI.class, consumedPaths);
    if (rmObject.getUri().getValue() == null) {
        setValue(currentTerm, null, currentValues, rmObject.getUri()::setValue, URI.class, consumedPaths);
    }
    if (RMHelper.isEmpty(rmObject.getUri())) {
        rmObject.setUri(null);
    }
    rmObject.setMediaType(new CodePhrase());
    rmObject.getMediaType().setTerminologyId(new TerminologyId("IANA_media-types"));
    setValue(currentTerm, "mediatype", currentValues, rmObject.getMediaType()::setCodeString, String.class, consumedPaths);
    setValue(currentTerm, "compression_algorithm", currentValues, codeString -> {
        if (codeString != null) {
            rmObject.setCompressionAlgorithm(new CodePhrase());
            rmObject.getCompressionAlgorithm().setTerminologyId(new TerminologyId("openehr_compression_algorithms"));
            rmObject.getCompressionAlgorithm().setCodeString(codeString);
        }
    }, String.class, consumedPaths);
    setValue(currentTerm, "integrity_check_algorithm", currentValues, codeString -> {
        if (codeString != null) {
            rmObject.setIntegrityCheckAlgorithm(new CodePhrase());
            rmObject.getIntegrityCheckAlgorithm().setTerminologyId(new TerminologyId("openehr_integrity_check_algorithms"));
            rmObject.getIntegrityCheckAlgorithm().setCodeString(codeString);
        }
    }, String.class, consumedPaths);
    setValue(currentTerm, "integrity_check", currentValues, codeString -> {
        if (codeString != null) {
            rmObject.setIntegrityCheck(codeString.getBytes(StandardCharsets.UTF_8));
        }
    }, String.class, consumedPaths);
    setValue(currentTerm, "data", currentValues, codeString -> {
        if (codeString != null) {
            rmObject.setData(codeString.getBytes(StandardCharsets.UTF_8));
        }
    }, String.class, consumedPaths);
    setValue(currentTerm, "size", currentValues, rmObject::setSize, Integer.class, consumedPaths);
    setValue(currentTerm, "alternatetext", currentValues, rmObject::setAlternateText, String.class, consumedPaths);
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) DvURI(com.nedap.archie.rm.datavalues.DvURI)

Example 38 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase 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 39 with CodePhrase

use of com.nedap.archie.rm.datatypes.CodePhrase 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 40 with CodePhrase

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

the class TerminologyAccessTest method testTerminologyAccess.

@Test
public void testTerminologyAccess() throws Exception {
    assertEquals("openehr", terminologyAccess.id());
    Set<CodePhrase> codePhrases = terminologyAccess.allCodes();
    assertEquals(216, codePhrases.size());
    codePhrases = terminologyAccess.codesForGroupId("setting");
    assertEquals(13, codePhrases.size());
    // nursing home care
    assertTrue(terminologyAccess.hasCodeForGroupId("setting", new CodePhrase(new TerminologyId("openehr"), "237")));
    // bad code string
    assertFalse(terminologyAccess.hasCodeForGroupId("setting", new CodePhrase(new TerminologyId("openehr"), "240")));
}
Also used : TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Test(org.junit.Test)

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