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();
}
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;
}
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;
}
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;
}
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;
}
Aggregations