Search in sources :

Example 1 with ObjectConverter

use of org.hl7.fhir.r4b.elementmodel.ObjectConverter in project kindling by HL7.

the class ExampleInspector method fetch.

@Override
public Element fetch(IResourceValidator validator, Object appContext, String url) throws IOException, FHIRException {
    String[] parts = url.split("\\/");
    if (parts.length == 2 && definitions.hasResource(parts[0])) {
        ResourceDefn r = definitions.getResourceByName(parts[0]);
        for (Example e : r.getExamples()) {
            if (e.getElement() == null && e.hasXml()) {
                e.setElement(new org.hl7.fhir.r5.elementmodel.XmlParser(context).parse(e.getXml()));
                if (e.getElement().getProperty().getStructure().getBaseDefinition().contains("MetadataResource")) {
                    String urle = e.getElement().getChildValue("url");
                    String v = e.getElement().getChildValue("url");
                    if (urle != null && urle.startsWith("http://hl7.org/fhir") && !version.toCode().equals(v)) {
                        e.getElement().setChildValue("version", version.toCode());
                    }
                }
            }
            if (e.getElement() != null) {
                if (e.getElement().fhirType().equals("Bundle")) {
                    for (Base b : e.getElement().listChildrenByName("entry")) {
                        if (b.getChildByName("resource").hasValues()) {
                            Element res = (Element) b.getChildByName("resource").getValues().get(0);
                            if (res.fhirType().equals(parts[0]) && parts[1].equals(res.getChildValue("id"))) {
                                return res;
                            }
                        }
                    }
                } else if (e.getElement().fhirType().equals(parts[0]) && e.getId().equals(parts[1])) {
                    return e.getElement();
                }
            }
        }
        try {
            if (parts[0].equals("StructureDefinition"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(StructureDefinition.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("OperationDefinition"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(OperationDefinition.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("SearchParameter"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(SearchParameter.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("ValueSet"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(ValueSet.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
            if (parts[0].equals("CodeSystem"))
                return new ObjectConverter(context).convert(context.fetchResourceWithException(CodeSystem.class, "http://hl7.org/fhir/" + parts[0] + "/" + parts[1]));
        } catch (Exception e) {
            return null;
        }
        return null;
    } else
        return null;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) ObjectConverter(org.hl7.fhir.r5.elementmodel.ObjectConverter) Example(org.hl7.fhir.definitions.model.Example) Element(org.hl7.fhir.r5.elementmodel.Element) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) Base(org.hl7.fhir.r5.model.Base) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) ValidationException(org.everit.json.schema.ValidationException) MalformedURLException(java.net.MalformedURLException) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 2 with ObjectConverter

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

the class ProfileUtilities method createExampleElement.

private org.hl7.fhir.r4.elementmodel.Element createExampleElement(StructureDefinition profile, ElementDefinition ed, ExampleValueAccessor accessor) throws FHIRException {
    Type v = accessor.getExampleValue(ed);
    if (v != null) {
        return new ObjectConverter(context).convert(new Property(context, ed, profile), v);
    } else {
        org.hl7.fhir.r4.elementmodel.Element res = new org.hl7.fhir.r4.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.r4.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.r4.elementmodel.ObjectConverter) Element(org.hl7.fhir.r4.model.Element) PrimitiveType(org.hl7.fhir.r4.model.PrimitiveType) ExtensionContextType(org.hl7.fhir.r4.model.StructureDefinition.ExtensionContextType) StringType(org.hl7.fhir.r4.model.StringType) IntegerType(org.hl7.fhir.r4.model.IntegerType) BooleanType(org.hl7.fhir.r4.model.BooleanType) UriType(org.hl7.fhir.r4.model.UriType) SchematronType(org.hl7.fhir.utilities.xml.SchematronWriter.SchematronType) Type(org.hl7.fhir.r4.model.Type) DiscriminatorType(org.hl7.fhir.r4.model.ElementDefinition.DiscriminatorType) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) CodeType(org.hl7.fhir.r4.model.CodeType) ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition) Property(org.hl7.fhir.r4.elementmodel.Property)

Example 3 with ObjectConverter

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

the class InstanceValidator method validate.

@Override
public org.hl7.fhir.r5.elementmodel.Element validate(Object appContext, List<ValidationMessage> errors, Resource resource, List<StructureDefinition> profiles) throws FHIRException {
    long t = System.nanoTime();
    Element e;
    try {
        e = new ObjectConverter(context).convert(resource);
    } catch (IOException e1) {
        throw new FHIRException(e1);
    }
    timeTracker.load(t);
    validate(appContext, errors, null, e, profiles);
    return e;
}
Also used : ObjectConverter(org.hl7.fhir.r5.elementmodel.ObjectConverter) NamedElement(org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement) IndexedElement(org.hl7.fhir.validation.instance.utils.IndexedElement) SpecialElement(org.hl7.fhir.r5.elementmodel.Element.SpecialElement) Element(org.hl7.fhir.r5.elementmodel.Element) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 4 with ObjectConverter

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

the class ProfileUtilities method createExampleElement.

private org.hl7.fhir.r4b.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.r4b.elementmodel.Element res = new org.hl7.fhir.r4b.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.r4b.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.r4b.elementmodel.ObjectConverter) Element(org.hl7.fhir.r4b.model.Element) DataType(org.hl7.fhir.r4b.model.DataType) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) Property(org.hl7.fhir.r4b.elementmodel.Property)

Example 5 with ObjectConverter

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

the class ProfileUtilities method createExampleElement.

private org.hl7.fhir.dstu3.elementmodel.Element createExampleElement(StructureDefinition profile, ElementDefinition ed, ExampleValueAccessor accessor) throws FHIRException {
    Type v = accessor.getExampleValue(ed);
    if (v != null) {
        return new ObjectConverter(context).convert(new Property(context, ed, profile), v);
    } else {
        org.hl7.fhir.dstu3.elementmodel.Element res = new org.hl7.fhir.dstu3.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.dstu3.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.dstu3.elementmodel.ObjectConverter) Element(org.hl7.fhir.dstu3.model.Element) Type(org.hl7.fhir.dstu3.model.Type) DiscriminatorType(org.hl7.fhir.dstu3.model.ElementDefinition.DiscriminatorType) StringType(org.hl7.fhir.dstu3.model.StringType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) SchematronType(org.hl7.fhir.utilities.xml.SchematronWriter.SchematronType) CodeType(org.hl7.fhir.dstu3.model.CodeType) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) UriType(org.hl7.fhir.dstu3.model.UriType) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) Property(org.hl7.fhir.dstu3.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