Search in sources :

Example 6 with ObjectConverter

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

the class ProfileUtilities method createExampleElement.

private org.hl7.fhir.r5.elementmodel.Element createExampleElement(StructureDefinition profile, ElementDefinition ed, ExampleValueAccessor accessor) throws FHIRException {
    DataType v = accessor.getExampleValue(ed);
    if (v != null) {
        return new ObjectConverter(context).convert(new Property(context, ed, profile), v);
    } else {
        org.hl7.fhir.r5.elementmodel.Element res = new org.hl7.fhir.r5.elementmodel.Element(tail(ed.getPath()), new Property(context, ed, profile));
        boolean hasValue = false;
        List<ElementDefinition> children = getChildMap(profile, ed);
        for (ElementDefinition child : children) {
            if (!child.hasContentReference()) {
                org.hl7.fhir.r5.elementmodel.Element e = createExampleElement(profile, child, accessor);
                if (e != null) {
                    hasValue = true;
                    res.getChildren().add(e);
                }
            }
        }
        if (hasValue)
            return res;
        else
            return null;
    }
}
Also used : ObjectConverter(org.hl7.fhir.r5.elementmodel.ObjectConverter) Element(org.hl7.fhir.r5.model.Element) DataType(org.hl7.fhir.r5.model.DataType) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) Property(org.hl7.fhir.r5.elementmodel.Property)

Aggregations

ObjectConverter (org.hl7.fhir.r5.elementmodel.ObjectConverter)3 IOException (java.io.IOException)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 Element (org.hl7.fhir.r5.elementmodel.Element)2 SchematronType (org.hl7.fhir.utilities.xml.SchematronWriter.SchematronType)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 FileNotFoundException (java.io.FileNotFoundException)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 ValidationException (org.everit.json.schema.ValidationException)1 Example (org.hl7.fhir.definitions.model.Example)1 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)1 ObjectConverter (org.hl7.fhir.dstu3.elementmodel.ObjectConverter)1 Property (org.hl7.fhir.dstu3.elementmodel.Property)1 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)1 CodeType (org.hl7.fhir.dstu3.model.CodeType)1 Element (org.hl7.fhir.dstu3.model.Element)1 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)1