Search in sources :

Example 31 with Property

use of org.hl7.fhir.r5.elementmodel.Property in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeValueSetConceptSetFilterComponent.

protected void composeValueSetConceptSetFilterComponent(Complex parent, String parentType, String name, ValueSet.ConceptSetFilterComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "filter", name, element, index);
    if (element.hasPropertyElement())
        composeCode(t, "ValueSet", "property", element.getPropertyElement(), -1);
    if (element.hasOpElement())
        composeEnum(t, "ValueSet", "op", element.getOpElement(), -1);
    if (element.hasValueElement())
        composeCode(t, "ValueSet", "value", element.getValueElement(), -1);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 32 with Property

use of org.hl7.fhir.r5.elementmodel.Property in project org.hl7.fhir.core by hapifhir.

the class ParserBase method getChildProperties.

protected List<Property> getChildProperties(Property property, String elementName, String statedType) throws DefinitionException {
    ElementDefinition ed = property.getDefinition();
    StructureDefinition sd = property.getStructure();
    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
                if (ed.hasRepresentation(PropertyRepresentation.TYPEATTR)) {
                    t = statedType;
                    if (t == null && ToolingExtensions.hasExtension(ed, "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaultype"))
                        t = ToolingExtensions.readStringExtension(ed, "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaultype");
                    boolean ok = false;
                    for (TypeRefComponent tr : ed.getType()) if (tr.getCode().equals(t))
                        ok = true;
                    if (!ok)
                        throw new DefinitionException("Type '" + t + "' is not an acceptable type for '" + elementName + "' on property " + property.getDefinition().getPath());
                } else {
                    t = elementName.substring(tail(ed.getPath()).length() - 3);
                    if (isPrimitive(lowFirst(t)))
                        t = lowFirst(t);
                }
            }
        }
        if (!"xhtml".equals(t)) {
            sd = context.fetchTypeDefinition(t);
            if (sd == null)
                throw new DefinitionException("Unable to find class '" + t + "' for name '" + elementName + "' on property " + property.getDefinition().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.dstu2016may.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 33 with Property

use of org.hl7.fhir.r5.elementmodel.Property in project org.hl7.fhir.core by hapifhir.

the class CodeSystem method setProperty.

@Override
public void setProperty(String name, Base value) throws FHIRException {
    if (name.equals("url"))
        // UriType
        this.url = castToUri(value);
    else if (name.equals("identifier"))
        // Identifier
        this.identifier = castToIdentifier(value);
    else if (name.equals("version"))
        // StringType
        this.version = castToString(value);
    else if (name.equals("name"))
        // StringType
        this.name = castToString(value);
    else if (name.equals("status"))
        // Enumeration<ConformanceResourceStatus>
        this.status = new ConformanceResourceStatusEnumFactory().fromType(value);
    else if (name.equals("experimental"))
        // BooleanType
        this.experimental = castToBoolean(value);
    else if (name.equals("publisher"))
        // StringType
        this.publisher = castToString(value);
    else if (name.equals("contact"))
        this.getContact().add((CodeSystemContactComponent) value);
    else if (name.equals("date"))
        // DateTimeType
        this.date = castToDateTime(value);
    else if (name.equals("description"))
        // StringType
        this.description = castToString(value);
    else if (name.equals("useContext"))
        this.getUseContext().add(castToCodeableConcept(value));
    else if (name.equals("requirements"))
        // StringType
        this.requirements = castToString(value);
    else if (name.equals("copyright"))
        // StringType
        this.copyright = castToString(value);
    else if (name.equals("caseSensitive"))
        // BooleanType
        this.caseSensitive = castToBoolean(value);
    else if (name.equals("valueSet"))
        // UriType
        this.valueSet = castToUri(value);
    else if (name.equals("compositional"))
        // BooleanType
        this.compositional = castToBoolean(value);
    else if (name.equals("versionNeeded"))
        // BooleanType
        this.versionNeeded = castToBoolean(value);
    else if (name.equals("content"))
        // Enumeration<CodeSystemContentMode>
        this.content = new CodeSystemContentModeEnumFactory().fromType(value);
    else if (name.equals("count"))
        // UnsignedIntType
        this.count = castToUnsignedInt(value);
    else if (name.equals("filter"))
        this.getFilter().add((CodeSystemFilterComponent) value);
    else if (name.equals("property"))
        this.getProperty().add((CodeSystemPropertyComponent) value);
    else if (name.equals("concept"))
        this.getConcept().add((ConceptDefinitionComponent) value);
    else
        super.setProperty(name, value);
}
Also used : ConformanceResourceStatusEnumFactory(org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatusEnumFactory)

Example 34 with Property

use of org.hl7.fhir.r5.elementmodel.Property in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parse.

public Element parse(JsonObject object) throws Exception {
    JsonElement rt = object.get("resourceType");
    if (rt == null) {
        logError(line(object), col(object), "$", IssueType.INVALID, "Unable to find resourceType property", IssueSeverity.FATAL);
        return null;
    } else {
        String name = rt.getAsString();
        String path = "/" + name;
        StructureDefinition sd = getDefinition(line(object), col(object), name);
        if (sd == null)
            return null;
        Element result = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd));
        checkObject(object, path);
        result.markLocation(line(object), col(object));
        result.setType(name);
        parseChildren(path, object, result, true);
        result.numberChildren();
        return result;
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) JsonElement(com.google.gson.JsonElement) SpecialElement(org.hl7.fhir.dstu2016may.metamodel.Element.SpecialElement) JsonElement(com.google.gson.JsonElement)

Example 35 with Property

use of org.hl7.fhir.r5.elementmodel.Property in project org.hl7.fhir.core by hapifhir.

the class XmlParser method parseResource.

private void parseResource(String string, org.w3c.dom.Element container, Element parent) throws Exception {
    org.w3c.dom.Element res = XMLUtil.getFirstChild(container);
    String name = res.getLocalName();
    StructureDefinition sd = context.fetchTypeDefinition(name);
    if (sd == null)
        throw new FHIRFormatError("Contained resource does not appear to be a FHIR resource (unknown name '" + res.getLocalName() + "')");
    parent.updateProperty(new Property(context, sd.getSnapshot().getElement().get(0), sd), parent.getProperty().getName().equals("contained") ? SpecialElement.CONTAINED : SpecialElement.BUNDLE_ENTRY);
    parent.setType(name);
    parseChildren(res.getLocalName(), res, parent);
}
Also used : StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError)

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