Search in sources :

Example 76 with Property

use of org.hl7.fhir.r4b.model.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);
            }
        }
    }
}
Also used : Property(org.hl7.fhir.r5.model.Property) Base(org.hl7.fhir.r5.model.Base)

Example 77 with Property

use of org.hl7.fhir.r4b.model.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++;
    }
}
Also used : ObjectValue(org.hl7.fhir.utilities.graphql.ObjectValue) Argument(org.hl7.fhir.utilities.graphql.Argument) StringValue(org.hl7.fhir.utilities.graphql.StringValue) Directive(org.hl7.fhir.utilities.graphql.Directive) FHIRException(org.hl7.fhir.exceptions.FHIRException) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Example 78 with Property

use of org.hl7.fhir.r4b.model.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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Extension(org.hl7.fhir.dstu3.model.Extension) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) Property(org.hl7.fhir.dstu3.model.Property)

Example 79 with Property

use of org.hl7.fhir.r4b.model.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;
}
Also used : TableModel(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)

Example 80 with Property

use of org.hl7.fhir.r4b.model.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;
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Aggregations

ArrayList (java.util.ArrayList)35 FHIRException (org.hl7.fhir.exceptions.FHIRException)35 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)30 JsonElement (com.google.gson.JsonElement)23 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)21 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)15 JsonObject (com.google.gson.JsonObject)14 List (java.util.List)14 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)14 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)11 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Collectors (java.util.stream.Collectors)8 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)8 SpecialElement (org.hl7.fhir.r4b.elementmodel.Element.SpecialElement)8 NamedElement (org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement)8 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)8