Search in sources :

Example 1 with TermMapping

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

the class RecordedDvCodedTextTest method testToDB.

@Test
public void testToDB() {
    Record record = new EventContextRecord();
    DvCodedText dvCodedText = new DvCodedText("testvalue", new CodePhrase("en"), new CodePhrase("UTF-8"), new CodePhrase(new TerminologyId("terminology"), "1224"));
    TermMapping termMapping = new TermMapping(new CodePhrase(new TerminologyId("A"), "target"), Character.valueOf('>'), new DvCodedText("purpose", new CodePhrase(new TerminologyId("B"), "BBB")));
    List<TermMapping> termMappings = new ArrayList<>();
    termMappings.add(termMapping);
    dvCodedText.setMappings(termMappings);
    new RecordedDvCodedText().toDB(record, EventContext.EVENT_CONTEXT.SETTING, dvCodedText);
    DvCodedTextRecord dvCodedTextRecord = record.get(EventContext.EVENT_CONTEXT.SETTING);
    assertEquals(">", dvCodedTextRecord.getTermMapping()[0].split("|")[0]);
}
Also used : TermMapping(com.nedap.archie.rm.datavalues.TermMapping) TerminologyId(com.nedap.archie.rm.support.identification.TerminologyId) DvCodedTextRecord(org.ehrbase.jooq.pg.udt.records.DvCodedTextRecord) DvCodedText(com.nedap.archie.rm.datavalues.DvCodedText) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) ArrayList(java.util.ArrayList) Record(org.jooq.Record) CodePhraseRecord(org.ehrbase.jooq.pg.udt.records.CodePhraseRecord) DvCodedTextRecord(org.ehrbase.jooq.pg.udt.records.DvCodedTextRecord) EventContextRecord(org.ehrbase.jooq.pg.tables.records.EventContextRecord) EventContextRecord(org.ehrbase.jooq.pg.tables.records.EventContextRecord) Test(org.junit.Test)

Example 2 with TermMapping

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

the class TermMappingAdapter method write.

public void write(JsonWriter writer, List<TermMapping> termMappings) throws IOException {
    if (termMappings == null) {
        // writer.nullValue();
        return;
    }
    if (termMappings.size() > 0) {
        // used to encode DV_CODED_TEXT in mappings
        DvCodedTextAdapter dvCodedTextAdapter = new DvCodedTextAdapter();
        CodePhraseAdapter codePhraseAdapter = new CodePhraseAdapter();
        writer.name("mappings");
        // [
        writer.beginArray();
        for (TermMapping termMapping : termMappings) {
            // {
            writer.beginObject();
            writer.name("match").value("" + new Character(termMapping.getMatch()));
            writer.name("purpose");
            new DvCodedTextAdapter(AdapterType.PG_JSONB).write(writer, termMapping.getPurpose());
            writer.name("target");
            new CodePhraseAdapter(AdapterType.PG_JSONB).write(writer, termMapping.getTarget());
            // }
            writer.endObject();
        }
        // ]
        writer.endArray();
    }
}
Also used : TermMapping(com.nedap.archie.rm.datavalues.TermMapping)

Example 3 with TermMapping

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

the class TermMappingTestOverwritten method testTermMappingFromJson.

@Override
@Test
public void testTermMappingFromJson() 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 structuredJson = getFlatJson(template, FlatFormat.STRUCTURED).marshal(unmarshal);
    Composition actualComposition = getFlatJson(template, FlatFormat.STRUCTURED).unmarshal(structuredJson);
    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 4 with TermMapping

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

the class DvTextPostprocessor method process.

/**
 * {@inheritDoc}
 */
@Override
public void process(String term, DvText rmObject, Map<FlatPathDto, String> values, Set<String> consumedPaths, Context<Map<FlatPathDto, String>> context) {
    FlatHelper.extractMultiValuedFullPath(term, "_mapping", values).entrySet().stream().map(e -> {
        TermMapping termMapping = new TermMapping();
        callUnmarshal(term, "/_mapping:" + e.getKey(), termMapping, e.getValue(), consumedPaths, context, context.getNodeDeque().peek().findChildById("mappings").orElse(buildDummyChild("mappings", context.getNodeDeque().peek())));
        callPostProcess(term, "/_mapping:" + e.getKey(), termMapping, e.getValue(), consumedPaths, context, context.getNodeDeque().peek().findChildById("mappings").orElse(buildDummyChild("mappings", context.getNodeDeque().peek())));
        return termMapping;
    }).forEach(rmObject::addMapping);
    FlatHelper.consumeAllMatching(term + "/_mapping", values, consumedPaths, false);
    Map<FlatPathDto, String> language = FlatHelper.filter(values, term + "/_language", false);
    if (!language.isEmpty()) {
        rmObject.setLanguage(new CodePhrase());
        handleRmAttribute(term, rmObject.getLanguage(), language, consumedPaths, context, "language");
    }
    Map<FlatPathDto, String> encoding = FlatHelper.filter(values, term + "/_encoding", false);
    if (!encoding.isEmpty()) {
        rmObject.setEncoding(new CodePhrase());
        handleRmAttribute(term, rmObject.getEncoding(), encoding, consumedPaths, context, "encoding");
    }
}
Also used : Context(org.ehrbase.serialisation.walker.Context) FlatHelper(org.ehrbase.serialisation.walker.FlatHelper) DvText(com.nedap.archie.rm.datavalues.DvText) Map(java.util.Map) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto) FlatHelper.buildDummyChild(org.ehrbase.serialisation.walker.FlatHelper.buildDummyChild) Set(java.util.Set) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) TermMapping(com.nedap.archie.rm.datavalues.TermMapping) TermMapping(com.nedap.archie.rm.datavalues.TermMapping) CodePhrase(com.nedap.archie.rm.datatypes.CodePhrase) FlatPathDto(org.ehrbase.webtemplate.path.flat.FlatPathDto)

Example 5 with TermMapping

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

Aggregations

TermMapping (com.nedap.archie.rm.datavalues.TermMapping)6 CodePhrase (com.nedap.archie.rm.datatypes.CodePhrase)4 DvCodedText (com.nedap.archie.rm.datavalues.DvCodedText)3 DvText (com.nedap.archie.rm.datavalues.DvText)3 TerminologyId (com.nedap.archie.rm.support.identification.TerminologyId)3 TermMappingTest (care.better.platform.web.template.TermMappingTest)2 Composition (com.nedap.archie.rm.composition.Composition)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Tuple (org.assertj.core.groups.Tuple)2 Helper.getFlatJson (org.ehrbase.conformance_test.extern.Helper.getFlatJson)2 FlatFormat (org.ehrbase.serialisation.flatencoding.FlatFormat)2 CanonicalJson (org.ehrbase.serialisation.jsonencoding.CanonicalJson)2 Test (org.junit.jupiter.api.Test)2 Map (java.util.Map)1 Set (java.util.Set)1 EventContextRecord (org.ehrbase.jooq.pg.tables.records.EventContextRecord)1 CodePhraseRecord (org.ehrbase.jooq.pg.udt.records.CodePhraseRecord)1 DvCodedTextRecord (org.ehrbase.jooq.pg.udt.records.DvCodedTextRecord)1