use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method loadFromFile.
private void loadFromFile(InputStream stream, String name) throws IOException, FHIRException {
XmlParser xml = new XmlParser();
Bundle f;
try {
f = (Bundle) xml.parse(stream);
} catch (FHIRFormatError e1) {
throw new org.hl7.fhir.exceptions.FHIRFormatError(e1.getMessage(), e1);
}
for (BundleEntryComponent e : f.getEntry()) {
if (e.getFullUrl() == null) {
System.out.println("unidentified resource in " + name + " (no fullUrl)");
}
seeResource(e.getFullUrl(), e.getResource());
}
}
use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.
the class NarrativeGeneratorTests method process.
private void process(String path) throws FileNotFoundException, IOException, XmlPullParserException, EOperationOutcome, FHIRException {
XmlParser p = new XmlParser();
DomainResource r = (DomainResource) p.parse(new FileInputStream(path));
gen.generate(r);
FileOutputStream s = new FileOutputStream(Utilities.path("[tmp]", "gen.xml"));
new XmlParser().compose(s, r, true);
s.close();
}
use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.
the class ClientUtils method getFeedAsByteArray.
public byte[] getFeedAsByteArray(Bundle feed, boolean pretty, boolean isJson) {
ByteArrayOutputStream baos = null;
byte[] byteArray = null;
try {
baos = new ByteArrayOutputStream();
IParser parser = null;
if (isJson) {
parser = new JsonParser();
} else {
parser = new XmlParser();
}
parser.setOutputStyle(pretty ? OutputStyle.PRETTY : OutputStyle.NORMAL);
parser.compose(baos, feed);
baos.close();
byteArray = baos.toByteArray();
baos.close();
} catch (Exception e) {
try {
baos.close();
} catch (Exception ex) {
throw new EFhirClientException("Error closing output stream", ex);
}
throw new EFhirClientException("Error converting output stream to byte array", e);
}
return byteArray;
}
use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method execute.
public void execute(String[] args) throws FileNotFoundException, IOException, FHIRException {
System.out.println("loading context");
context = SimpleWorkerContext.fromPack(Utilities.path(root, "validation.zip"));
comp = new ProfileComparer(context);
compare("patient-daf-dafpatient.profile.xml", "patient-qicore-qicore-patient.profile.xml");
compare("encounter-daf-dafencounter.profile.xml", "encounter-qicore-qicore-encounter.profile.xml");
compare("substance-daf-dafsubstance.profile.xml", "substance-qicore-qicore-substance.profile.xml");
compare("medication-daf-dafmedication.profile.xml", "medication-qicore-qicore-medication.profile.xml");
compare("procedure-daf-dafprocedure.profile.xml", "procedure-qicore-qicore-procedure.profile.xml");
compare("familymemberhistory-daf-daffamilymemberhistory.profile.xml", "familymemberhistory-qicore-qicore-familymemberhistory.profile.xml");
compare("immunization-daf-dafimmunization.profile.xml", "immunization-qicore-qicore-immunization.profile.xml");
compare("condition-daf-dafcondition.profile.xml", "condition-qicore-qicore-condition.profile.xml");
compare("allergyintolerance-daf-dafallergyintolerance.profile.xml", "allergyintolerance-qicore-qicore-allergyintolerance.profile.xml");
compare("medicationadministration-daf-dafmedicationadministration.profile.xml", "medicationadministration-qicore-qicore-medicationadministration.profile.xml");
compare("medicationdispense-daf-dafmedicationdispense.profile.xml", "medicationdispense-qicore-qicore-medicationdispense.profile.xml");
compare("medicationprescription-daf-dafmedicationprescription.profile.xml", "medicationprescription-qicore-qicore-medicationprescription.profile.xml");
compare("medicationstatement-daf-dafmedicationstatement.profile.xml", "medicationstatement-qicore-qicore-medicationstatement.profile.xml");
compare("observation-daf-smokingstatus-dafsmokingstatus.profile.xml", "observation-qicore-qicore-observation.profile.xml");
compare("observation-daf-vitalsigns-dafvitalsigns.profile.xml", "observation-qicore-qicore-observation.profile.xml");
// compare("observation-daf-results-dafresultobs.profile.xml", "observation-qicore-qicore-observation.profile.xml");
// compare("diagnosticorder-daf-dafdiagnosticorder.profile.xml", "diagnosticorder-qicore-qicore-diagnosticorder.profile.xml");
// compare("diagnosticreport-daf-dafdiagnosticreport.profile.xml", "diagnosticreport-qicore-qicore-diagnosticreport.profile.xml");
System.out.println("processing output");
for (ProfileComparison outcome : comp.getComparisons()) {
if (outcome.getSubset() != null)
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "intersection-" + outcome.getId() + ".xml")), outcome.getSubset());
if (outcome.getSuperset() != null)
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "union-" + outcome.getId() + ".xml")), outcome.getSuperset());
System.out.println("\r\n" + outcome.getId() + ": Comparison of " + outcome.getLeft().getUrl() + " and " + outcome.getRight().getUrl());
for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.INFORMATION)
System.out.println(vm.summary());
for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.WARNING)
System.out.println(vm.summary());
for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.ERROR)
System.out.println(vm.summary());
for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.FATAL)
System.out.println(vm.summary());
System.out.println("done. " + Integer.toString(outcome.getMessages().size()) + " messages");
System.out.println("=================================================================");
}
}
use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.
the class ToolsHelper method executeRoundTrip.
public void executeRoundTrip(String[] args) throws IOException, FHIRException {
FileInputStream in;
File source = new CSFile(args[1]);
File dest = new CSFile(args[2]);
if (args.length >= 4) {
Utilities.copyFile(args[1], args[3]);
}
if (!source.exists())
throw new FHIRException("Source File \"" + source.getAbsolutePath() + "\" not found");
in = new CSFileInputStream(source);
XmlParser p = new XmlParser();
JsonParser parser = new JsonParser();
JsonParser pj = parser;
Resource rf = p.parse(in);
ByteArrayOutputStream json = new ByteArrayOutputStream();
parser.setOutputStyle(OutputStyle.PRETTY);
parser.compose(json, rf);
json.close();
TextFile.stringToFile(new String(json.toByteArray()), Utilities.changeFileExt(dest.getAbsolutePath(), ".json"));
rf = pj.parse(new ByteArrayInputStream(json.toByteArray()));
FileOutputStream s = new FileOutputStream(dest);
new XmlParser().compose(s, rf, true);
s.close();
}
Aggregations