use of org.hl7.fhir.r4.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method getChildrenByName.
/**
* Given an item, return all the children that conform to the pattern described in name
*
* Possible patterns:
* - a simple name (which may be the base of a name with [] e.g. value[x])
* - a name with a type replacement e.g. valueCodeableConcept
* - * which means all children
* - ** which means all descendants
*
* @param item
* @param name
* @param result
* @throws FHIRException
*/
protected void getChildrenByName(Base item, String name, List<Base> result) throws FHIRException {
String tn = null;
if (isAllowPolymorphicNames()) {
// we'll look to see whether we hav a polymorphic name
for (Property p : item.children()) {
if (p.getName().endsWith("[x]")) {
String n = p.getName().substring(0, p.getName().length() - 3);
if (name.startsWith(n)) {
tn = name.substring(n.length());
name = n;
break;
}
}
}
}
Base[] list = item.listChildrenByName(name, false);
if (list != null) {
for (Base v : list) {
if (v != null && (tn == null || v.fhirType().equalsIgnoreCase(tn))) {
result.add(v);
}
}
}
}
use of org.hl7.fhir.r4.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngine method processValues.
private void processValues(Resource context, Selection sel, Property prop, ObjectValue target, List<Base> values, boolean extensionMode, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
boolean il = false;
Argument arg = null;
ExpressionNode expression = null;
if (sel.getField().hasDirective("slice")) {
Directive dir = sel.getField().directive("slice");
String s = ((StringValue) dir.getArguments().get(0).getValues().get(0)).getValue();
if (s.equals("$index"))
expression = magicExpression;
else
expression = fpe.parse(s);
}
if (// special: instruction to drop this node...
sel.getField().hasDirective("flatten"))
il = prop.isList() && !sel.getField().hasDirective("first");
else if (sel.getField().hasDirective("first")) {
if (expression != null)
throw new FHIRException("You cannot mix @slice and @first");
arg = target.addField(sel.getField().getAlias() + suffix, listStatus(sel.getField(), inheritedList));
} else if (expression == null)
arg = target.addField(sel.getField().getAlias() + suffix, listStatus(sel.getField(), prop.isList() || inheritedList));
int index = 0;
for (Base value : values) {
String ss = "";
if (expression != null) {
if (expression == magicExpression)
ss = suffix + '.' + Integer.toString(index);
else
ss = suffix + '.' + fpe.evaluateToString(null, null, null, value, expression);
if (!sel.getField().hasDirective("flatten"))
arg = target.addField(sel.getField().getAlias() + suffix, listStatus(sel.getField(), prop.isList() || inheritedList));
}
if (value.isPrimitive() && !extensionMode) {
if (!sel.getField().getSelectionSet().isEmpty())
throw new EGraphQLException("Encountered a selection set on a scalar field type");
processPrimitive(arg, value);
} else {
if (sel.getField().getSelectionSet().isEmpty())
throw new EGraphQLException("No Fields selected on a complex object");
if (arg == null)
processObject(context, value, target, sel.getField().getSelectionSet(), il, ss);
else {
ObjectValue n = new ObjectValue();
arg.addValue(n);
processObject(context, value, n, sel.getField().getSelectionSet(), il, ss);
}
}
if (sel.getField().hasDirective("first"))
return;
index++;
}
}
use of org.hl7.fhir.r4.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method splitExtensions.
private List<PropertyWrapper> splitExtensions(StructureDefinition profile, List<PropertyWrapper> children) throws UnsupportedEncodingException, IOException, FHIRException {
List<PropertyWrapper> results = new ArrayList<PropertyWrapper>();
Map<String, PropertyWrapper> map = new HashMap<String, PropertyWrapper>();
for (PropertyWrapper p : children) if (p.getName().equals("extension") || p.getName().equals("modifierExtension")) {
// we're going to split these up, and create a property for each url
if (p.hasValues()) {
for (BaseWrapper v : p.getValues()) {
Extension ex = (Extension) v.getBase();
String url = ex.getUrl();
StructureDefinition ed = context.fetchResource(StructureDefinition.class, url);
if (p.getName().equals("modifierExtension") && ed == null)
throw new DefinitionException("Unknown modifier extension " + url);
PropertyWrapper pe = map.get(p.getName() + "[" + url + "]");
if (pe == null) {
if (ed == null) {
if (url.startsWith("http://hl7.org/fhir"))
throw new DefinitionException("unknown extension " + url);
// System.out.println("unknown extension "+url);
pe = new PropertyWrapperDirect(new Property(p.getName() + "[" + url + "]", p.getTypeCode(), p.getDefinition(), p.getMinCardinality(), p.getMaxCardinality(), ex));
} else {
ElementDefinition def = ed.getSnapshot().getElement().get(0);
pe = new PropertyWrapperDirect(new Property(p.getName() + "[" + url + "]", "Extension", def.getDefinition(), def.getMin(), def.getMax().equals("*") ? Integer.MAX_VALUE : Integer.parseInt(def.getMax()), ex));
((PropertyWrapperDirect) pe).wrapped.setStructure(ed);
}
results.add(pe);
} else
pe.getValues().add(v);
}
}
} else
results.add(p);
return results;
}
use of org.hl7.fhir.r4.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method initSpanningTable.
public TableModel initSpanningTable(HierarchicalTableGenerator gen, String prefix, boolean isLogical, String id) {
TableModel model = gen.new TableModel(id, false);
model.setDocoImg(prefix + "help16.png");
// todo: change to graph definition
model.setDocoRef(prefix + "formats.html#table");
model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Property", "A profiled resource", null, 0));
model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Card.", "Minimum and Maximum # of times the the element can appear in the instance", null, 0));
model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Content", "What goes here", null, 0));
model.getTitles().add(gen.new Title(null, model.getDocoRef(), "Description", "Description of the profile", null, 0));
return model;
}
use of org.hl7.fhir.r4.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class Property method getChildProperties.
protected List<Property> getChildProperties(TypeDetails type) throws DefinitionException {
ElementDefinition ed = definition;
StructureDefinition sd = structure;
List<ElementDefinition> children = ProfileUtilities.getChildMap(sd, ed);
if (children.isEmpty()) {
// ok, find the right definitions
String t = null;
if (ed.getType().size() == 1)
t = ed.getType().get(0).getCode();
else if (ed.getType().size() == 0)
throw new Error("types == 0, and no children found");
else {
t = ed.getType().get(0).getCode();
boolean all = true;
for (TypeRefComponent tr : ed.getType()) {
if (!tr.getCode().equals(t)) {
all = false;
break;
}
}
if (!all) {
// ok, it's polymorphic
t = type.getType();
}
}
if (!"xhtml".equals(t)) {
sd = context.fetchResource(StructureDefinition.class, t);
if (sd == null)
throw new DefinitionException("Unable to find class '" + t + "' for name '" + ed.getPath() + "' on property " + definition.getPath());
children = ProfileUtilities.getChildMap(sd, sd.getSnapshot().getElement().get(0));
}
}
List<Property> properties = new ArrayList<Property>();
for (ElementDefinition child : children) {
properties.add(new Property(context, child, sd));
}
return properties;
}
Aggregations