Search in sources :

Example 51 with Property

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

the class ObjectConverter method convertElement.

private Element convertElement(Property property, Base base) throws FHIRException {
    if (base == null)
        return null;
    String tn = base.fhirType();
    StructureDefinition sd = context.fetchResource(StructureDefinition.class, ProfileUtilities.sdNs(tn, context.getOverrideVersionNs()));
    if (sd == null)
        throw new FHIRException("Unable to find definition for type " + tn);
    Element res = new Element(property.getName(), property);
    if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
        res.setValue(((PrimitiveType) base).asStringValue());
    List<ElementDefinition> children = profileUtilities.getChildMap(sd, sd.getSnapshot().getElementFirstRep());
    for (ElementDefinition child : children) {
        String n = tail(child.getPath());
        if (sd.getKind() != StructureDefinitionKind.PRIMITIVETYPE || !"value".equals(n)) {
            Base[] values = base.getProperty(n.hashCode(), n, false);
            if (values != null)
                for (Base value : values) {
                    res.getChildren().add(convertElement(new Property(context, child, sd), value));
                }
        }
    }
    return res;
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) NamedElement(org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement) PrimitiveType(org.hl7.fhir.r4b.model.PrimitiveType) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.r4b.model.Base)

Example 52 with Property

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

the class ProfileUtilities method generateExample.

private org.hl7.fhir.r4b.elementmodel.Element generateExample(StructureDefinition profile, ExampleValueAccessor accessor) throws FHIRException {
    ElementDefinition ed = profile.getSnapshot().getElementFirstRep();
    org.hl7.fhir.r4b.elementmodel.Element r = new org.hl7.fhir.r4b.elementmodel.Element(ed.getPath(), new Property(context, ed, profile));
    List<ElementDefinition> children = getChildMap(profile, ed);
    for (ElementDefinition child : children) {
        if (child.getPath().endsWith(".id")) {
            org.hl7.fhir.r4b.elementmodel.Element id = new org.hl7.fhir.r4b.elementmodel.Element("id", new Property(context, child, profile));
            id.setValue(profile.getId() + accessor.getId());
            r.getChildren().add(id);
        } else {
            org.hl7.fhir.r4b.elementmodel.Element e = createExampleElement(profile, child, accessor);
            if (e != null)
                r.getChildren().add(e);
        }
    }
    return r;
}
Also used : Element(org.hl7.fhir.r4b.model.Element) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) Property(org.hl7.fhir.r4b.elementmodel.Property)

Example 53 with Property

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

the class StructureMapUtilities method analyseSource.

private VariablesForProfiling analyseSource(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMapGroupRuleSourceComponent src, XhtmlNode td) throws FHIRException {
    VariableForProfiling var = vars.get(VariableMode.INPUT, src.getContext());
    if (var == null)
        throw new FHIRException("Rule \"" + ruleId + "\": Unknown input variable " + src.getContext());
    PropertyWithType prop = var.getProperty();
    boolean optional = false;
    boolean repeating = false;
    if (src.hasCondition()) {
        optional = true;
    }
    if (src.hasElement()) {
        Property element = prop.getBaseProperty().getChild(prop.getTypes().getType(), src.getElement());
        if (element == null)
            throw new FHIRException("Rule \"" + ruleId + "\": Unknown element name " + src.getElement());
        if (element.getDefinition().getMin() == 0)
            optional = true;
        if (element.getDefinition().getMax().equals("*"))
            repeating = true;
        VariablesForProfiling result = vars.copy(optional, repeating);
        TypeDetails type = new TypeDetails(CollectionStatus.SINGLETON);
        for (TypeRefComponent tr : element.getDefinition().getType()) {
            if (!tr.hasCode())
                throw new Error("Rule \"" + ruleId + "\": Element has no type");
            ProfiledType pt = new ProfiledType(tr.getWorkingCode());
            if (tr.hasProfile())
                pt.addProfiles(tr.getProfile());
            if (element.getDefinition().hasBinding())
                pt.addBinding(element.getDefinition().getBinding());
            type.addType(pt);
        }
        td.addText(prop.getPath() + "." + src.getElement());
        if (src.hasVariable())
            result.add(VariableMode.INPUT, src.getVariable(), new PropertyWithType(prop.getPath() + "." + src.getElement(), element, null, type));
        return result;
    } else {
        // ditto!
        td.addText(prop.getPath());
        return vars.copy(optional, repeating);
    }
}
Also used : ProfiledType(org.hl7.fhir.r4b.model.TypeDetails.ProfiledType) TypeRefComponent(org.hl7.fhir.r4b.model.ElementDefinition.TypeRefComponent) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException) Property(org.hl7.fhir.r4b.elementmodel.Property)

Example 54 with Property

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

the class ProfileUtilities method generateExample.

private org.hl7.fhir.r5.elementmodel.Element generateExample(StructureDefinition profile, ExampleValueAccessor accessor) throws FHIRException {
    ElementDefinition ed = profile.getSnapshot().getElementFirstRep();
    org.hl7.fhir.r5.elementmodel.Element r = new org.hl7.fhir.r5.elementmodel.Element(ed.getPath(), new Property(context, ed, profile));
    List<ElementDefinition> children = getChildMap(profile, ed);
    for (ElementDefinition child : children) {
        if (child.getPath().endsWith(".id")) {
            org.hl7.fhir.r5.elementmodel.Element id = new org.hl7.fhir.r5.elementmodel.Element("id", new Property(context, child, profile));
            id.setValue(profile.getId() + accessor.getId());
            r.getChildren().add(id);
        } else {
            org.hl7.fhir.r5.elementmodel.Element e = createExampleElement(profile, child, accessor);
            if (e != null)
                r.getChildren().add(e);
        }
    }
    return r;
}
Also used : Element(org.hl7.fhir.r5.model.Element) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) Property(org.hl7.fhir.r5.elementmodel.Property)

Example 55 with Property

use of org.hl7.fhir.r5.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, true);
    model.setDocoImg(prefix + "help16.png");
    // todo: change to graph definition
    model.setDocoRef(Utilities.pathURL(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)

Aggregations

ArrayList (java.util.ArrayList)36 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 List (java.util.List)15 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)15 JsonObject (com.google.gson.JsonObject)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 Test (org.junit.jupiter.api.Test)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)11 Map (java.util.Map)10 Property (com.adobe.target.delivery.v1.model.Property)9 TargetDeliveryRequest (com.adobe.target.edge.client.model.TargetDeliveryRequest)9 HashMap (java.util.HashMap)9 Collectors (java.util.stream.Collectors)9 Context (com.adobe.target.delivery.v1.model.Context)8