Search in sources :

Example 31 with XmlParser

use of org.hl7.fhir.r4b.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(" ", "&nbsp;") + "<br/>");
        }
    }
    return b.toString();
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) PrimitiveType(org.hl7.fhir.r5.model.PrimitiveType) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 32 with XmlParser

use of org.hl7.fhir.r4b.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);
        }
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) FileInputStream(java.io.FileInputStream)

Example 33 with XmlParser

use of org.hl7.fhir.r4b.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);
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) FileOutputStream(java.io.FileOutputStream)

Example 34 with XmlParser

use of org.hl7.fhir.r4b.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");
}
Also used : XmlParser(org.hl7.fhir.r4.formats.XmlParser) JsonElement(com.google.gson.JsonElement) FileOutputStream(java.io.FileOutputStream) JsonObject(com.google.gson.JsonObject) HashSet(java.util.HashSet)

Example 35 with XmlParser

use of org.hl7.fhir.r4b.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;
}
Also used : ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) XmlParser(org.hl7.fhir.r4.formats.XmlParser) JsonElement(com.google.gson.JsonElement) FileOutputStream(java.io.FileOutputStream)

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