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