Search in sources :

Example 31 with TerminologyId

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

the class StdToCompositionWalker method postHandle.

@Override
protected void postHandle(Context<Map<FlatPathDto, String>> context) {
    super.postHandle(context);
    if (isRaw(context)) {
        handleRaw(context);
    }
    WebTemplateNode currentNode = context.getNodeDeque().peek();
    currentNode.getChildren().forEach(childNode -> {
        // Check for Raw in optional (skipped Nodes)
        if (context.getFlatHelper().skip(childNode, currentNode)) {
            context.getNodeDeque().push(childNode);
            context.getRmObjectDeque().push(new RMObject() {
            });
            String path = context.getFlatHelper().buildNamePath(context, true);
            Map<FlatPathDto, String> subValues = context.getObjectDeque().peek().entrySet().stream().filter(e -> e.getKey().startsWith(path + "/_" + childNode.getId())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
            context.getObjectDeque().push(subValues);
            if (isRaw(context)) {
                handleRaw(context);
            }
            context.getNodeDeque().poll();
            context.getRmObjectDeque().poll();
            context.getObjectDeque().poll();
        }
    });
    List<? extends UnmarshalPostprocessor<? extends RMObject>> postprocessor = findUnmarshalPostprocessors(context.getRmObjectDeque().peek().getClass());
    String namePath = buildNamePathWithElementHandling(context);
    if (Entry.class.isAssignableFrom(context.getRmObjectDeque().peek().getClass())) {
        if (((Entry) context.getRmObjectDeque().peek()).getSubject() instanceof PartyRelated) {
            Optional.ofNullable(context.getNodeDeque().peek()).flatMap(c -> c.findChildById("subject")).flatMap(c -> c.findChildById("relationship")).stream().map(WebTemplateNode::getInputs).flatMap(List::stream).filter(i -> "code".equals(i.getSuffix())).map(WebTemplateInput::getList).map(l -> l.size() == 1 ? l.get(0) : null).filter(Objects::nonNull).findAny().ifPresent(v -> ((PartyRelated) ((Entry) context.getRmObjectDeque().peek()).getSubject()).setRelationship(new DvCodedText(v.getLabel(), new CodePhrase(new TerminologyId("openehr"), v.getValue()))));
        }
    }
    postprocessor.forEach(p -> ((UnmarshalPostprocessor) p).process(namePath, context.getRmObjectDeque().peek(), context.getObjectDeque().peek(), consumedPaths, context));
}
Also used : Composition(com.nedap.archie.rm.composition.Composition) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) ToCompositionWalker(org.ehrbase.serialisation.walker.ToCompositionWalker) DefaultRMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.DefaultRMUnmarshaller) Element(com.nedap.archie.rm.datastructures.Element) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) WebTemplateSkeletonBuilder(org.ehrbase.building.webtemplateskeletnbuilder.WebTemplateSkeletonBuilder) HashSet(java.util.HashSet) Map(java.util.Map) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) Entry(com.nedap.archie.rm.composition.Entry) UnmarshalPostprocessor(org.ehrbase.serialisation.flatencoding.std.umarshal.postprocessor.UnmarshalPostprocessor) DV_TEXT(org.ehrbase.util.rmconstants.RmConstants.DV_TEXT) Context(org.ehrbase.serialisation.walker.Context) ReflectionHelper(org.ehrbase.util.reflection.ReflectionHelper) ELEMENT(org.ehrbase.util.rmconstants.RmConstants.ELEMENT) CanonicalJson(org.ehrbase.serialisation.jsonencoding.CanonicalJson) DvText(com.nedap.archie.rm.datavalues.DvText) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) Set(java.util.Set) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DefaultValues(org.ehrbase.serialisation.walker.defaultvalues.DefaultValues) DV_CODED_TEXT(org.ehrbase.util.rmconstants.RmConstants.DV_CODED_TEXT) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) UnmarshalException(org.ehrbase.serialisation.exception.UnmarshalException) JacksonUtil(org.ehrbase.serialisation.jsonencoding.JacksonUtil) Objects(java.util.Objects) WebTemplate(org.ehrbase.webtemplate.model.WebTemplate) List(java.util.List) WebTemplateUtils(org.ehrbase.webtemplate.util.WebTemplateUtils) RMObject(com.nedap.archie.rm.RMObject) Optional(java.util.Optional) RMUnmarshaller(org.ehrbase.serialisation.flatencoding.std.umarshal.rmunmarshaller.RMUnmarshaller) NodeId(org.ehrbase.serialisation.walker.NodeId) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) Collections(java.util.Collections) Filter(org.ehrbase.webtemplate.filter.Filter) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) WebTemplateNode(org.ehrbase.webtemplate.model.WebTemplateNode) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) WebTemplateInput(org.ehrbase.webtemplate.model.WebTemplateInput) PartyRelated(com.nedap.archie.rm.generic.PartyRelated) Entry(com.nedap.archie.rm.composition.Entry) Objects(java.util.Objects) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) RMObject(com.nedap.archie.rm.RMObject)

Example 32 with TerminologyId

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

the class EventContextUnmarshalPostprocessor method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(String term, EventContext rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
    setValue(term + PATH_DIVIDER + "_location", null, values, rmObject::setLocation, String.class, consumedPaths);
    setValue(term + PATH_DIVIDER + "_end_time", null, values, s -> {
        if (s != null) {
            rmObject.setEndTime(new DvDateTime(s));
        }
    }, String.class, consumedPaths);
    Map<FlatPathDto, String> health_care_facilityValues = FlatHelper.filter(values, term + "/_health_care_facility", false);
    if (!health_care_facilityValues.isEmpty()) {
        rmObject.setHealthCareFacility(new PartyIdentified());
        handleRmAttribute(term, rmObject.getHealthCareFacility(), health_care_facilityValues, consumedPaths, context, "health_care_facility");
    }
    Map<Integer, Map<String, String>> other = extractMultiValued(term, "_participation", values);
    other.values().stream().map(Map::entrySet).map(s -> s.stream().collect(Collectors.toMap(e -> "ctx/" + DefaultValuePath.PARTICIPATION.getPath() + "_" + e.getKey().replace("identifiers_", "identifiers|"), e -> StringUtils.wrap(e.getValue(), '"'))).entrySet()).map(DefaultValues::buildParticipation).forEach(rmObject::addParticipation);
    consumeAllMatching(term + PATH_DIVIDER + "_participation", values, consumedPaths, false);
    // Strange Path with value true if setting = other care (238)
    consumedPaths.add(term + "/" + "setting|238");
    // Strange Path with value true if setting != other care (238)
    consumedPaths.add(term + "/" + "setting|");
    if (rmObject.getSetting() != null && (rmObject.getSetting().getDefiningCode().getTerminologyId() == null || rmObject.getSetting().getDefiningCode().getTerminologyId().getValue() == null)) {
        rmObject.getSetting().getDefiningCode().setTerminologyId(new TerminologyId("openehr"));
    }
}
Also used : Context(org.ehrbase.serialisation.walker.Context) FlatHelper(org.ehrbase.serialisation.walker.FlatHelper) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DefaultValuePath(org.ehrbase.serialisation.walker.defaultvalues.DefaultValuePath) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) Set(java.util.Set) DefaultValues(org.ehrbase.serialisation.walker.defaultvalues.DefaultValues) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) EventContext(com.nedap.archie.rm.composition.EventContext) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime) PATH_DIVIDER(org.ehrbase.webtemplate.parser.OPTParser.PATH_DIVIDER) FlatHelper.extractMultiValued(org.ehrbase.serialisation.walker.FlatHelper.extractMultiValued) Map(java.util.Map) FlatHelper.consumeAllMatching(org.ehrbase.serialisation.walker.FlatHelper.consumeAllMatching) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) PartyIdentified(com.nedap.archie.rm.generic.PartyIdentified) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) Map(java.util.Map) DvDateTime(com.nedap.archie.rm.datavalues.quantity.datetime.DvDateTime)

Example 33 with TerminologyId

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

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

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

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