use of org.hl7.fhir.r4.formats.XmlParser in project kindling by HL7.
the class DictHTMLGenerator method encodeValue.
private String encodeValue(DataType value) throws Exception {
if (value == null || value.isEmpty())
return null;
if (value instanceof PrimitiveType)
return Utilities.escapeXml(((PrimitiveType) value).asStringValue());
ByteArrayOutputStream bs = new ByteArrayOutputStream();
XmlParser parser = new XmlParser();
parser.setOutputStyle(OutputStyle.PRETTY);
parser.compose(bs, null, value);
String[] lines = bs.toString().split("\\r?\\n");
StringBuilder b = new StringBuilder();
for (String s : lines) {
if (!Utilities.noString(s) && !s.startsWith("<?")) {
// eliminate the xml header
b.append(Utilities.escapeXml(s).replace(" ", " ") + "<br/>");
}
}
return b.toString();
}
use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.
the class SpecDifferenceEvaluator method loadSD.
private static void loadSD(Map<String, StructureDefinition> map, String fn) throws FHIRFormatError, IOException {
Bundle bundle = (Bundle) new XmlParser().parse(new FileInputStream(fn));
for (BundleEntryComponent be : bundle.getEntry()) {
if (be.getResource() instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) be.getResource();
map.put(sd.getName(), sd);
}
}
}
use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.
the class ObservationStatsBuilder method buildStatsSeries.
/**
* @throws FHIRException
* @throws IOException
* @throws FileNotFoundException
*/
public static void buildStatsSeries() throws FHIRException, IOException, FileNotFoundException {
Bundle b = new Bundle();
b.setType(BundleType.COLLECTION);
b.setId(UUID.randomUUID().toString().toLowerCase());
addAge(b, 5, 1, "18.3");
addAge(b, 5, 2, "18.4");
addAge(b, 5, 3, "18.6");
addAge(b, 5, 4, "18.8");
addAge(b, 5, 5, "19.0");
addAge(b, 5, 6, "19.1");
addAge(b, 5, 7, "19.3");
addAge(b, 5, 8, "19.5");
addAge(b, 5, 9, "19.6");
addAge(b, 5, 10, "19.8");
addAge(b, 5, 11, "20.0");
addAge(b, 6, 0, "20.2");
addAge(b, 6, 1, "20.3");
addAge(b, 6, 2, "20.5");
addAge(b, 6, 3, "20.7");
addAge(b, 6, 4, "20.9");
addAge(b, 6, 5, "21.0");
addAge(b, 6, 6, "21.2");
addAge(b, 6, 7, "21.4");
addAge(b, 6, 8, "21.6");
addAge(b, 6, 9, "21.8");
addAge(b, 6, 10, "22.0");
addAge(b, 6, 11, "22.2");
addAge(b, 7, 0, "22.4");
addAge(b, 7, 1, "22.6");
addAge(b, 7, 2, "22.8");
addAge(b, 7, 3, "23.0");
addAge(b, 7, 4, "23.2");
addAge(b, 7, 5, "23.4");
addAge(b, 7, 6, "23.6");
addAge(b, 7, 7, "23.9");
addAge(b, 7, 8, "24.1");
addAge(b, 7, 9, "24.3");
addAge(b, 7, 10, "24.5");
addAge(b, 7, 11, "24.8");
addAge(b, 8, 0, "25.0");
addAge(b, 8, 1, "25.3");
addAge(b, 8, 2, "25.5");
addAge(b, 8, 3, "25.8");
addAge(b, 8, 4, "26.0");
addAge(b, 8, 5, "26.3");
addAge(b, 8, 6, "26.6");
addAge(b, 8, 7, "26.8");
addAge(b, 8, 8, "27.1");
addAge(b, 8, 9, "27.4");
addAge(b, 8, 10, "27.6");
addAge(b, 8, 11, "27.9");
addAge(b, 9, 0, "28.2");
addAge(b, 9, 1, "28.5");
addAge(b, 9, 2, "28.8");
addAge(b, 9, 3, "29.1");
addAge(b, 9, 4, "29.4");
addAge(b, 9, 5, "29.7");
addAge(b, 9, 6, "30.0");
addAge(b, 9, 7, "30.3");
addAge(b, 9, 8, "30.6");
addAge(b, 9, 9, "30.9");
addAge(b, 9, 10, "31.2");
addAge(b, 9, 11, "31.5");
addAge(b, 10, 0, "31.9");
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "obs.xml")), b);
}
use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.
the class ICD11Generator method execute.
private void execute(String base, String dest) throws IOException {
CodeSystem cs = makeMMSCodeSystem();
JsonObject version = fetchJson(Utilities.pathURL(base, "/icd/release/11/mms"));
String[] p = version.get("latestRelease").getAsString().split("\\/");
cs.setVersion(p[6]);
JsonObject root = fetchJson(url(base, version.get("latestRelease").getAsString()));
cs.setDateElement(new DateTimeType(root.get("releaseDate").getAsString()));
for (JsonElement child : root.getAsJsonArray("child")) {
processMMSEntity(cs, base, child.getAsString(), cs.addConcept(), dest);
System.out.println();
}
new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "icd-11-mms.xml")), cs);
makeFullVs(dest, cs);
cs = makeEntityCodeSystem();
root = fetchJson(Utilities.pathURL(base, "/icd/entity"));
cs.setVersion(root.get("releaseId").getAsString());
cs.setDateElement(new DateTimeType(root.get("releaseDate").getAsString()));
cs.setTitle(readString(root, "title"));
Set<String> ids = new HashSet<>();
for (JsonElement child : root.getAsJsonArray("child")) {
processEntity(cs, ids, base, tail(child.getAsString()), dest);
System.out.println();
}
new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "icd-11-foundation.xml")), cs);
makeFullVs2(dest, cs);
System.out.println("finished");
}
use of org.hl7.fhir.r4.formats.XmlParser in project org.hl7.fhir.core by hapifhir.
the class ICD11Generator method buildValueSet.
private String buildValueSet(CodeSystem cs, String code, String name, JsonObject o, String dest) throws IOException {
String id = code + "-" + name;
String url = "http://id.who.int/icd11/ValueSet/" + id;
ValueSet vs = new ValueSet();
vs.setId(id);
vs.setUrl(url);
vs.setName("VS" + name + "4" + code);
vs.setTitle("Value Set for " + name + " on " + code);
vs.setStatus(PublicationStatus.ACTIVE);
vs.setExperimental(false);
vs.setDate(cs.getDate());
vs.setPublisher("WHO");
vs.setCopyright("Consult WHO For terms of use");
vs.setVersion(cs.getVersion());
vs.setStatus(cs.getStatus());
ConceptSetComponent inc = vs.getCompose().addInclude();
inc.setSystem(cs.getUrl());
for (JsonElement e : o.getAsJsonArray("scaleEntity")) {
inc.addFilter().setProperty("concept").setOp(FilterOperator.ISA).setValue(tail(e.getAsString()));
}
new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "vs-" + id + ".xml")), vs);
return url;
}
Aggregations