use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.
the class DataRenderer method renderExtensionsInText.
public void renderExtensionsInText(XhtmlNode div, DataType element, String sep) throws FHIRFormatError, DefinitionException, IOException {
boolean first = true;
for (Extension ext : element.getExtension()) {
if (canRender(ext)) {
if (first) {
first = false;
} else {
div.tx(sep);
div.tx(" ");
}
String lbl = getExtensionLabel(ext);
div.tx(lbl);
div.tx(": ");
render(div, ext.getValue());
}
}
}
use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method getParam.
private TypeDetails getParam(VariablesForProfiling vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException {
DataType p = parameter.getValue();
if (!(p instanceof IdType))
return new TypeDetails(CollectionStatus.SINGLETON, ProfileUtilities.sdNs(p.fhirType(), worker.getOverrideVersionNs()));
else {
String n = ((IdType) p).asStringValue();
VariableForProfiling b = vars.get(VariableMode.INPUT, n);
if (b == null)
b = vars.get(VariableMode.OUTPUT, n);
if (b == null)
throw new DefinitionException("Variable " + n + " not found (" + vars.summary() + ")");
return b.getProperty().getTypes();
}
}
use of org.hl7.fhir.r4b.model.DataType in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method updateProfile.
private PropertyWithType updateProfile(VariableForProfiling var, String element, TypeDetails type, StructureMap map, List<StructureDefinition> profiles, String sliceName, DataType fixed, StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
if (var == null) {
assert (Utilities.noString(element));
// 1. start the new structure definition
StructureDefinition sdn = worker.fetchResource(StructureDefinition.class, type.getType());
if (sdn == null)
throw new FHIRException("Unable to find definition for " + type.getType());
ElementDefinition edn = sdn.getSnapshot().getElementFirstRep();
PropertyWithType pn = createProfile(map, profiles, new PropertyWithType(sdn.getId(), new Property(worker, edn, sdn), null, type), sliceName, tgt);
return pn;
} else {
assert (!Utilities.noString(element));
Property pvb = var.getProperty().getBaseProperty();
Property pvd = var.getProperty().getProfileProperty();
Property pc = pvb.getChild(element, var.getProperty().getTypes());
if (pc == null)
throw new DefinitionException("Unable to find a definition for " + pvb.getDefinition().getPath() + "." + element);
// the profile structure definition (derived)
StructureDefinition sd = var.getProperty().getProfileProperty().getStructure();
ElementDefinition ednew = sd.getDifferential().addElement();
ednew.setPath(var.getProperty().getProfileProperty().getDefinition().getPath() + "." + pc.getName());
ednew.setUserData("slice-name", sliceName);
ednew.setFixed(fixed);
for (ProfiledType pt : type.getProfiledTypes()) {
if (pt.hasBindings())
ednew.setBinding(pt.getBindings().get(0));
if (pt.getUri().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
String t = pt.getUri().substring(40);
t = checkType(t, pc, pt.getProfiles());
if (t != null) {
if (pt.hasProfiles()) {
for (String p : pt.getProfiles()) if (t.equals("Reference"))
ednew.getType(t).addTargetProfile(p);
else
ednew.getType(t).addProfile(p);
} else
ednew.getType(t);
}
}
}
return new PropertyWithType(var.getProperty().getPath() + "." + element, pc, new Property(worker, ednew, sd), type);
}
}
use of org.hl7.fhir.r4b.model.DataType in project bunsen by cerner.
the class DefinitionToSparkVisitor method visitChoice.
@Override
public HapiConverter<DataType> visitChoice(String elementName, Map<String, HapiConverter<DataType>> choiceTypes) {
StructField[] fields = choiceTypes.entrySet().stream().map(entry -> {
// Ensure first character of the field is lower case.
String fieldName = Character.toLowerCase(entry.getKey().charAt(0)) + entry.getKey().substring(1);
return new StructField(fieldName, entry.getValue().getDataType(), true, Metadata.empty());
}).toArray(StructField[]::new);
String fieldTypesString = choiceTypes.entrySet().stream().map(choiceEntry -> {
// References need their full record name, which includes the permissible referent types
if (choiceEntry.getKey().equals("Reference")) {
StructType structType = (StructType) choiceEntry.getValue().getDataType();
return Arrays.stream(structType.fields()).filter(field -> field.name().endsWith("Id") & !field.name().equals("id")).map(field -> field.name().substring(0, field.name().lastIndexOf("Id"))).sorted().map(StringUtils::capitalize).collect(Collectors.joining());
} else {
return choiceEntry.getKey();
}
}).sorted().map(StringUtils::capitalize).collect(Collectors.joining());
String fullName = basePackage + "." + "Choice" + fieldTypesString;
HapiConverter<DataType> converter = visitedConverters.get(fullName);
if (converter == null) {
converter = new HapiChoiceToSparkConverter(choiceTypes, new StructType(fields), fhirSupport);
visitedConverters.put(fullName, converter);
}
return converter;
}
use of org.hl7.fhir.r4b.model.DataType in project clinical_quality_language by cqframework.
the class Cql2ElmVisitor method visitContextDefinition.
@Override
public Object visitContextDefinition(cqlParser.ContextDefinitionContext ctx) {
String modelIdentifier = parseString(ctx.modelIdentifier());
String unqualifiedIdentifier = parseString(ctx.identifier());
currentContext = modelIdentifier != null ? modelIdentifier + "." + unqualifiedIdentifier : unqualifiedIdentifier;
if (!isUnfilteredContext(unqualifiedIdentifier)) {
ModelContext modelContext = libraryBuilder.resolveContextName(modelIdentifier, unqualifiedIdentifier);
// If this is the first time a context definition is encountered, construct a context definition:
// define <Context> = element of [<Context model type>]
Element modelContextDefinition = contextDefinitions.get(modelContext.getName());
if (modelContextDefinition == null) {
if (libraryBuilder.hasUsings()) {
ModelInfo modelInfo = modelIdentifier == null ? libraryBuilder.getModel(libraryInfo.getDefaultModelName()).getModelInfo() : libraryBuilder.getModel(modelIdentifier).getModelInfo();
// String contextTypeName = modelContext.getName();
// DataType contextType = libraryBuilder.resolveTypeName(modelInfo.getName(), contextTypeName);
DataType contextType = modelContext.getType();
modelContextDefinition = libraryBuilder.resolveParameterRef(modelContext.getName());
if (modelContextDefinition != null) {
contextDefinitions.put(modelContext.getName(), modelContextDefinition);
} else {
Retrieve contextRetrieve = of.createRetrieve().withDataType(libraryBuilder.dataTypeToQName(contextType));
track(contextRetrieve, ctx);
contextRetrieve.setResultType(new ListType(contextType));
String contextClassIdentifier = ((ClassType) contextType).getIdentifier();
if (contextClassIdentifier != null) {
contextRetrieve.setTemplateId(contextClassIdentifier);
}
modelContextDefinition = of.createExpressionDef().withName(unqualifiedIdentifier).withContext(currentContext).withExpression(of.createSingletonFrom().withOperand(contextRetrieve));
track(modelContextDefinition, ctx);
((ExpressionDef) modelContextDefinition).getExpression().setResultType(contextType);
modelContextDefinition.setResultType(contextType);
libraryBuilder.addExpression((ExpressionDef) modelContextDefinition);
contextDefinitions.put(modelContext.getName(), modelContextDefinition);
}
} else {
modelContextDefinition = of.createExpressionDef().withName(unqualifiedIdentifier).withContext(currentContext).withExpression(of.createNull());
track(modelContextDefinition, ctx);
((ExpressionDef) modelContextDefinition).getExpression().setResultType(libraryBuilder.resolveTypeName("System", "Any"));
modelContextDefinition.setResultType(((ExpressionDef) modelContextDefinition).getExpression().getResultType());
libraryBuilder.addExpression((ExpressionDef) modelContextDefinition);
contextDefinitions.put(modelContext.getName(), modelContextDefinition);
}
}
}
ContextDef contextDef = of.createContextDef().withName(currentContext);
track(contextDef, ctx);
if (libraryBuilder.isCompatibleWith("1.5")) {
libraryBuilder.addContext(contextDef);
}
return currentContext;
}
Aggregations