Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.nedap.archie.creation;
import com.nedap.archie.aom.*;
import com.nedap.archie.aom.primitives.*;
import com.nedap.archie.aom.profile.AomProfile;
import com.nedap.archie.aom.profile.AomPropertyMapping;
import com.nedap.archie.aom.profile.AomTypeMapping;
import com.nedap.archie.aom.terminology.ArchetypeTerm;
import com.nedap.archie.aom.terminology.ArchetypeTerminology;
import com.nedap.archie.aom.terminology.ValueSet;
import com.nedap.archie.base.Interval;
import com.nedap.archie.base.MultiplicityInterval;
import com.nedap.archie.rminfo.MetaModels;
import org.openehr.bmm.core.*;
import org.openehr.bmm.persistence.validation.BmmDefinitions;
import org.threeten.extra.PeriodDuration;
import java.time.Duration;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
/**
* generates an example structure for any model based on an operational template + a BMM model + the AOP profile
*
* Output is a Map<String, Object>, where object is again a Map<String, Object>, or a simple type directly serializable
* using the jackson object mapper. This can be simply serialized to JSON if desired.
*
*
* This contains a tiny bit of OpenEHR RM specific code, that is to be converted to subclasses for the different RMs
* BMM + AOP simply does nto contain enough information for this to be truly RM independent
*/
public class ExampleJsonInstanceGenerator {
public static final String MISSING_TERM_IN_ARCHETYPE_FOR_LANGUAGE = "missing term in archetype for language ";
private final String language;
private final MetaModels models;
private OperationalTemplate archetype;
private BmmModel bmm;
private AomProfile aomProfile;
private boolean useTypeNameWhenTermMissing = false;
private boolean addUniqueNamesForSiblingNodes = false;
private String typePropertyName = "_type";
OpenEhrRmInstanceGenerator openEhrRmInstanceGenerator;
public ExampleJsonInstanceGenerator(MetaModels models, String language) {
this.language = language;
this.models = models;
openEhrRmInstanceGenerator = new OpenEhrRmInstanceGenerator(this, typePropertyName);
}
public Map generate(OperationalTemplate archetype) {
this.archetype = archetype;
String rmRelease = archetype.getRmRelease();
//rm release 1.0.4 and 1.1.0 supported. if other versions, switch to 1.1.0 automatically to support other archetypes
if(rmRelease == null ||
!(rmRelease.equalsIgnoreCase("1.0.4") || rmRelease.equalsIgnoreCase("1.1.0"))) {
rmRelease = "1.1.0";
}
models.selectModel(archetype, rmRelease);
aomProfile = models.getSelectedAomProfile();
bmm = models.getSelectedBmmModel();
return generate(archetype.getDefinition());
}
public boolean isUseTypeNameWhenTermMissing() {
return useTypeNameWhenTermMissing;
}
/**
* Set whether to add a human readable 'name is missing' message in english for a missing type name, or
* to use the RM type name as name
* @param useTypeNameWhenTermMissing
*/
public void setUseTypeNameWhenTermMissing(boolean useTypeNameWhenTermMissing) {
this.useTypeNameWhenTermMissing = useTypeNameWhenTermMissing;
}
/**
* The the property name for the type identifier. Defaults to "@type", can be set to "_type" for standard behaviour
* @param typePropertyName the name of the type property
*/
public void setTypePropertyName(String typePropertyName) {
this.typePropertyName = typePropertyName;
this.openEhrRmInstanceGenerator.setTypePropertyName(typePropertyName);
}
public boolean isAddUniqueNamesForSiblingNodes() {
return addUniqueNamesForSiblingNodes;
}
/**
* Set to false to just include the terms from the archetype as names
* Set to true to append a numeric suffix to these terms in case two sibling nodes will have the same name with a different archetype node id
*
* @param addUniqueNamesForSiblingNodes whether to ensure name uniqueness or not
*/
public void setAddUniqueNamesForSiblingNodes(boolean addUniqueNamesForSiblingNodes) {
this.addUniqueNamesForSiblingNodes = addUniqueNamesForSiblingNodes;
}
private Map generate(CComplexObject cObject) {
String type = getConcreteTypeName(cObject.getRmTypeName());
Map result = openEhrRmInstanceGenerator.generateCustomExampleType(type);
if(result == null) {
result = new LinkedHashMap<>();
result.put(typePropertyName, type);
}
BmmClass classDefinition = bmm.getClassDefinition(cObject.getRmTypeName());
openEhrRmInstanceGenerator.addAdditionalPropertiesAtBegin(classDefinition, result, cObject);
for (CAttribute attribute : cObject.getAttributes()) {
BmmProperty> property = bmm.propertyAtPath (cObject.getRmTypeName(), attribute.getRmAttributeName());
if(property == null || property.getComputed()) {
continue;//do not serialize non-bmm properties such as functions and computed properties
}
List