Search in sources :

Example 46 with XmlParser

use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.

the class LoincToDEConvertor method saveBundle.

private void saveBundle() throws FHIRFormatError, IOException, XmlPullParserException {
    XmlParser xml = new XmlParser();
    FileOutputStream s = new FileOutputStream(dest);
    xml.compose(s, bundle, true);
    s.close();
}
Also used : XmlParser(org.hl7.fhir.dstu2016may.formats.XmlParser) FileOutputStream(java.io.FileOutputStream)

Example 47 with XmlParser

use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.

the class R2016MayToR5Loader method loadResource.

@Override
public org.hl7.fhir.r5.model.Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2016may = null;
    if (isJson)
        r2016may = new JsonParser().parse(stream);
    else
        r2016may = new XmlParser().parse(stream);
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_14_50.convertResource(r2016may);
    setPath(r5);
    if (!advisor.getCslist().isEmpty()) {
        throw new FHIRException("Error: Cannot have included code systems");
    }
    if (killPrimitives) {
        throw new FHIRException("Cannot kill primitives when using deferred loading");
    }
    if (patchUrls) {
        if (r5 instanceof StructureDefinition) {
            StructureDefinition sd = (StructureDefinition) r5;
            sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
            sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
            for (ElementDefinition ed : sd.getSnapshot().getElement()) patchUrl(ed);
            for (ElementDefinition ed : sd.getDifferential().getElement()) patchUrl(ed);
        }
    }
    return r5;
}
Also used : XmlParser(org.hl7.fhir.dstu2016may.formats.XmlParser) Resource(org.hl7.fhir.dstu2016may.model.Resource) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException) JsonParser(org.hl7.fhir.dstu2016may.formats.JsonParser)

Example 48 with XmlParser

use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.

the class R2ToR5Loader method loadResource.

@Override
public org.hl7.fhir.r5.model.Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2 = null;
    if (isJson)
        r2 = new JsonParser().parse(stream);
    else
        r2 = new XmlParser().parse(stream);
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_10_50.convertResource(r2, advisor);
    setPath(r5);
    if (!advisor.getCslist().isEmpty()) {
        throw new FHIRException("Error: Cannot have included code systems");
    }
    if (killPrimitives) {
        throw new FHIRException("Cannot kill primitives when using deferred loading");
    }
    if (patchUrls) {
        if (r5 instanceof StructureDefinition) {
            StructureDefinition sd = (StructureDefinition) r5;
            sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
            sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
            for (ElementDefinition ed : sd.getSnapshot().getElement()) patchUrl(ed);
            for (ElementDefinition ed : sd.getDifferential().getElement()) patchUrl(ed);
        }
    }
    return r5;
}
Also used : XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) Resource(org.hl7.fhir.dstu2.model.Resource) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Example 49 with XmlParser

use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.

the class R2ToR5Loader method loadBundle.

@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2 = null;
    if (isJson)
        r2 = new JsonParser().parse(stream);
    else
        r2 = new XmlParser().parse(stream);
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_10_50.convertResource(r2, advisor);
    Bundle b;
    if (r5 instanceof Bundle) {
        b = (Bundle) r5;
    } else {
        b = new Bundle();
        b.setId(UUID.randomUUID().toString().toLowerCase());
        b.setType(BundleType.COLLECTION);
        b.addEntry().setResource(r5).setFullUrl(r5 instanceof CanonicalResource ? ((CanonicalResource) r5).getUrl() : null);
    }
    // Add any code systems defined as part of processing value sets to the end of the converted Bundle
    for (CodeSystem cs : advisor.getCslist()) {
        BundleEntryComponent be = b.addEntry();
        be.setFullUrl(cs.getUrl());
        be.setResource(cs);
    }
    advisor.getCslist().clear();
    if (killPrimitives) {
        List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
                    remove.add(be);
            }
        }
        b.getEntry().removeAll(remove);
    }
    if (patchUrls) {
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU2));
                sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
            }
        }
    }
    return b;
}
Also used : XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) Resource(org.hl7.fhir.dstu2.model.Resource) ArrayList(java.util.ArrayList) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Example 50 with XmlParser

use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.

the class R3ToR5Loader method loadResource.

@Override
public org.hl7.fhir.r5.model.Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r3 = null;
    if (isJson)
        r3 = new JsonParser().parse(stream);
    else
        r3 = new XmlParser().parse(stream);
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_30_50.convertResource(r3);
    setPath(r5);
    if (!advisor.getCslist().isEmpty()) {
        throw new FHIRException("Error: Cannot have included code systems");
    }
    if (killPrimitives) {
        throw new FHIRException("Cannot kill primitives when using deferred loading");
    }
    if (patchUrls) {
        if (r5 instanceof StructureDefinition) {
            StructureDefinition sd = (StructureDefinition) r5;
            sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
            sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
            for (ElementDefinition ed : sd.getSnapshot().getElement()) patchUrl(ed);
            for (ElementDefinition ed : sd.getDifferential().getElement()) patchUrl(ed);
        }
    }
    return r5;
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) Resource(org.hl7.fhir.dstu3.model.Resource) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException) JsonParser(org.hl7.fhir.dstu3.formats.JsonParser)

Aggregations

FileOutputStream (java.io.FileOutputStream)130 XmlParser (org.hl7.fhir.r5.formats.XmlParser)97 FHIRException (org.hl7.fhir.exceptions.FHIRException)84 FileInputStream (java.io.FileInputStream)77 File (java.io.File)64 IOException (java.io.IOException)59 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)51 CSFile (org.hl7.fhir.utilities.CSFile)48 JsonParser (org.hl7.fhir.r5.formats.JsonParser)45 ArrayList (java.util.ArrayList)35 XmlParser (org.hl7.fhir.dstu3.formats.XmlParser)35 TextFile (org.hl7.fhir.utilities.TextFile)33 XmlParser (org.hl7.fhir.r4.formats.XmlParser)31 FileNotFoundException (java.io.FileNotFoundException)27 ByteArrayOutputStream (java.io.ByteArrayOutputStream)24 Resource (org.hl7.fhir.r5.model.Resource)24 XmlParser (org.hl7.fhir.r4b.formats.XmlParser)23 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)19 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19