Search in sources :

Example 1 with ParserBase

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

the class FormatUtilities method loadFile.

public static Resource loadFile(String path) throws FileNotFoundException, IOException, FHIRException {
    byte[] src = TextFile.fileToBytes(path);
    FhirFormat fmt = determineFormat(src);
    ParserBase parser = makeParser(fmt);
    return parser.parse(src);
}
Also used : FhirFormat(org.hl7.fhir.r5.elementmodel.Manager.FhirFormat)

Example 2 with ParserBase

use of org.hl7.fhir.r5.elementmodel.ParserBase 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, InputStream stream, FhirFormat format, List<StructureDefinition> profiles) throws FHIRException {
    ParserBase parser = Manager.makeParser(context, format);
    if (parser instanceof XmlParser)
        ((XmlParser) parser).setAllowXsiLocation(allowXsiLocation);
    parser.setupValidation(ValidationPolicy.EVERYTHING, errors);
    long t = System.nanoTime();
    List<NamedElement> list = null;
    try {
        list = parser.parse(stream);
    } catch (IOException e1) {
        throw new FHIRException(e1);
    }
    timeTracker.load(t);
    if (list != null && !list.isEmpty()) {
        String url = parser.getImpliedProfile();
        if (url != null) {
            StructureDefinition sd = context.fetchResource(StructureDefinition.class, url);
            if (sd == null) {
                rule(errors, IssueType.NOTFOUND, "Payload", false, "Implied profile " + url + " not known to validator");
            } else {
                profiles.add(sd);
            }
        }
        for (NamedElement ne : list) {
            validate(appContext, errors, ne.getName(), ne.getElement(), profiles);
        }
    }
    // todo: this is broken, but fixing it really complicates things elsewhere, so we do this for now
    return (list == null || list.isEmpty()) ? null : list.get(0).getElement();
}
Also used : XmlParser(org.hl7.fhir.r5.elementmodel.XmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ParserBase(org.hl7.fhir.r5.elementmodel.ParserBase) IOException(java.io.IOException) NamedElement(org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 3 with ParserBase

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

the class FormatUtilities method loadFile.

public static Resource loadFile(String path) throws FileNotFoundException, IOException, FHIRException {
    byte[] src = TextFile.fileToBytes(path);
    FhirFormat fmt = determineFormat(src);
    ParserBase parser = makeParser(fmt);
    return parser.parse(src);
}
Also used : FhirFormat(org.hl7.fhir.r4b.elementmodel.Manager.FhirFormat)

Example 4 with ParserBase

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

the class FormatUtilities method loadFile.

public static Resource loadFile(InputStream source) throws FileNotFoundException, IOException, FHIRException {
    byte[] src = TextFile.streamToBytes(source);
    FhirFormat fmt = determineFormat(src);
    ParserBase parser = makeParser(fmt);
    return parser.parse(src);
}
Also used : FhirFormat(org.hl7.fhir.r4.elementmodel.Manager.FhirFormat)

Example 5 with ParserBase

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

the class FormatUtilities method loadFile.

public static Resource loadFile(String path) throws FileNotFoundException, IOException, FHIRException {
    byte[] src = TextFile.fileToBytes(path);
    FhirFormat fmt = determineFormat(src);
    ParserBase parser = makeParser(fmt);
    return parser.parse(src);
}
Also used : FhirFormat(org.hl7.fhir.r4.elementmodel.Manager.FhirFormat)

Aggregations

FhirFormat (org.hl7.fhir.r4.elementmodel.Manager.FhirFormat)2 IOException (java.io.IOException)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1 FhirFormat (org.hl7.fhir.r4b.elementmodel.Manager.FhirFormat)1 FhirFormat (org.hl7.fhir.r5.elementmodel.Manager.FhirFormat)1 ParserBase (org.hl7.fhir.r5.elementmodel.ParserBase)1 NamedElement (org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement)1 XmlParser (org.hl7.fhir.r5.elementmodel.XmlParser)1 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)1