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]);
}
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();
}
}
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"))));
}
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");
}
}
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"))));
}
Aggregations