Search in sources :

Example 16 with IniFile

use of org.hl7.fhir.utilities.IniFile in project kindling by HL7.

the class OldVersionRedirector method processVersion.

private void processVersion(File f, String dst, String url) throws Exception {
    String s = TextFile.fileToString(Utilities.path(f.getAbsolutePath(), "version.info"));
    IniFile ini = new IniFile(new ByteArrayInputStream(s.getBytes()));
    String ver = ini.getStringProperty("FHIR", "version");
    ver = ver.substring(0, 3);
    System.out.println("Process " + f.getAbsolutePath() + " as version " + ver);
    processVersionFiles(f, Utilities.path(dst, ver), ver, url);
}
Also used : IniFile(org.hl7.fhir.utilities.IniFile) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 17 with IniFile

use of org.hl7.fhir.utilities.IniFile in project kindling by HL7.

the class ProfileGenerator method generate.

public StructureDefinition generate(Profile pack, ResourceDefn r, String usage, boolean logical) throws Exception {
    StructureDefinition p = new StructureDefinition();
    p.setId(r.getRoot().getName());
    p.setUrl("http://hl7.org/fhir/StructureDefinition/" + r.getRoot().getName());
    if (logical)
        p.setKind(StructureDefinitionKind.LOGICAL);
    else
        p.setKind(StructureDefinitionKind.RESOURCE);
    if (r.isInterface()) {
        ToolingExtensions.addBooleanExtension(p, ToolingExtensions.EXT_RESOURCE_INTERFACE, true);
    }
    IniFile cini = new IniFile(Utilities.path(rootFolder, "temp", "categories.ini"));
    String cat = cini.getStringProperty("category", r.getName());
    if (!Utilities.noString(cat))
        ToolingExtensions.setStringExtension(p, ToolingExtensions.EXT_RESOURCE_CATEGORY, cat);
    p.setAbstract(r.isAbstract());
    assert !Utilities.noString(r.getRoot().typeCode());
    if (!Utilities.noString(r.getRoot().typeCode())) {
        p.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + r.getRoot().typeCode());
        p.setDerivation(TypeDerivationRule.SPECIALIZATION);
    // if (r.getTemplate() != null)
    // ToolingExtensions.addStringExtension(p.getBaseDefinitionElement(), ToolingExtensions.EXT_CODE_GENERATION_PARENT, r.getTemplate().getName());
    }
    p.setType(r.getRoot().getName());
    p.setUserData("filename", r.getName().toLowerCase());
    p.setUserData("path", r.getName().toLowerCase() + ".html");
    p.setTitle(pack.metadata("display"));
    p.setFhirVersion(version);
    p.setVersion(version.toCode());
    ToolingExtensions.setStandardsStatus(p, r.getStatus(), r.getNormativeVersion());
    if (r.getFmmLevel() != null)
        ToolingExtensions.addIntegerExtension(p, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(r.getFmmLevel()));
    if (r.getSecurityCategorization() != null)
        ToolingExtensions.addCodeExtension(p, ToolingExtensions.EXT_SEC_CAT, r.getSecurityCategorization().toCode());
    ToolResourceUtilities.updateUsage(p, usage);
    p.setName(r.getRoot().getName());
    p.setPublisher("Health Level Seven International" + (r.getWg() == null ? "" : " (" + r.getWg().getName() + ")"));
    p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, "http://hl7.org/fhir"));
    if (r.getWg() != null)
        p.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, r.getWg().getUrl()));
    ToolingExtensions.setCodeExtension(p, ToolingExtensions.EXT_WORKGROUP, r.getWg().getCode());
    p.setDescription(r.getDefinition());
    p.setPurpose(r.getRoot().getRequirements());
    if (!p.hasPurpose())
        p.setPurpose(r.getRoot().getRequirements());
    p.setDate(genDate.getTime());
    // DSTU
    p.setStatus(r.getStatus() == StandardsStatus.NORMATIVE ? PublicationStatus.fromCode("active") : PublicationStatus.fromCode("draft"));
    Set<String> containedSlices = new HashSet<String>();
    // first, the differential
    p.setDifferential(new StructureDefinitionDifferentialComponent());
    defineElement(null, p, p.getDifferential().getElement(), r.getRoot(), r.getRoot().getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.None, true, "BackboneElement", r.getRoot().typeCode(), false);
    reset();
    // now. the snapshot'
    p.setSnapshot(new StructureDefinitionSnapshotComponent());
    defineElement(null, p, p.getSnapshot().getElement(), r.getRoot(), r.getRoot().getName(), containedSlices, new ArrayList<ProfileGenerator.SliceHandle>(), SnapShotMode.Resource, true, "BackboneElement", r.getRoot().typeCode(), true);
    for (ElementDefinition ed : p.getSnapshot().getElement()) if (!ed.hasBase() && !logical)
        generateElementDefinition(p, ed, getParent(ed, p.getSnapshot().getElement()));
    if (!logical && !r.isInterface()) {
        List<String> names = new ArrayList<String>();
        names.addAll(r.getSearchParams().keySet());
        Collections.sort(names);
        // 1st, non composites
        for (String pn : names) {
            SearchParameterDefn sp = r.getSearchParams().get(pn);
            if (sp.getType() != SearchType.composite)
                pack.getSearchParameters().add(makeSearchParam(p, r.getName() + "-" + pn.replace("_", ""), r.getName(), sp, r));
        }
        for (String pn : names) {
            SearchParameterDefn sp = r.getSearchParams().get(pn);
            if (sp.getType() == SearchType.composite)
                pack.getSearchParameters().add(makeSearchParam(p, r.getName() + "-" + pn.replace("_", ""), r.getName(), sp, r));
        }
    }
    containedSlices.clear();
    addElementConstraintToSnapshot(p);
    p.getDifferential().getElement().get(0).getType().clear();
    p.getSnapshot().getElement().get(0).getType().clear();
    XhtmlNode div = new XhtmlNode(NodeType.Element, "div");
    div.addText("to do");
    p.setText(new Narrative());
    p.getText().setStatus(NarrativeStatus.GENERATED);
    p.getText().setDiv(div);
    checkHasTypes(p);
    return p;
}
Also used : IniFile(org.hl7.fhir.utilities.IniFile) SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) ArrayList(java.util.ArrayList) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Narrative(org.hl7.fhir.r5.model.Narrative) StructureDefinitionSnapshotComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionSnapshotComponent) StructureDefinitionDifferentialComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionDifferentialComponent) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) HashSet(java.util.HashSet)

Example 18 with IniFile

use of org.hl7.fhir.utilities.IniFile in project kindling by HL7.

the class SchemaGenerator method generate.

public void generate(Definitions definitions, IniFile ini, String tmpResDir, String xsdDir, String dstDir, String srcDir, String version, String genDate, BuildWorkerContext workerContext) throws Exception {
    this.genDate = genDate;
    this.version = version;
    this.workerContext = workerContext;
    File dir = new CSFile(xsdDir);
    File[] list = dir.listFiles();
    if (list != null) {
        for (File f : list) {
            if (!f.isDirectory() && f.getName().endsWith(".schema.json"))
                f.delete();
        }
    }
    JsonObject schema = new JsonObject();
    schema.addProperty("$schema", "http://json-schema.org/draft-06/schema#");
    schema.addProperty("id", "http://hl7.org/fhir/json-schema/" + version.substring(0, version.lastIndexOf(".")));
    // schema.addProperty("$ref", "#/definitions/ResourceList");
    schema.addProperty("description", "see http://hl7.org/fhir/json.html#schema for information about the FHIR Json Schemas");
    List<String> names = new ArrayList<String>();
    names.addAll(definitions.getResources().keySet());
    names.addAll(definitions.getBaseResources().keySet());
    addAllResourcesChoice(definitions, schema, names);
    names.clear();
    names.addAll(definitions.getPrimitives().keySet());
    Collections.sort(names);
    for (String n : names) {
        new JsonGenerator(definitions, workerContext, definitions.getKnownTypes(), version).generate(definitions.getPrimitives().get(n), version, genDate, schema);
    }
    new JsonGenerator(definitions, workerContext, definitions.getKnownTypes(), version).generate(new DefinedCode().setCode("xhtml").setDefinition("xhtml - escaped html (see specfication)"), version, genDate, schema);
    for (TypeRef tr : definitions.getKnownTypes()) {
        if (!definitions.getPrimitives().containsKey(tr.getName()) && !definitions.getConstraints().containsKey(tr.getName())) {
            TypeDefn root = definitions.getElementDefn(tr.getName());
            if (!isBackboneElement(root.getName())) {
                JsonObject s = new JsonGenerator(definitions, workerContext, definitions.getKnownTypes(), version).generate(root, version, genDate, null);
                save(s, tmpResDir + root.getName().replace(".", "_") + ".schema.json");
                new JsonGenerator(definitions, workerContext, definitions.getKnownTypes(), version).generate(root, version, genDate, schema);
            }
        }
    }
    names.clear();
    names.addAll(definitions.getResources().keySet());
    names.addAll(definitions.getBaseResources().keySet());
    Collections.sort(names);
    for (String name : names) {
        ResourceDefn root = definitions.getResourceByName(name);
        JsonObject s = new JsonGenerator(definitions, workerContext, definitions.getKnownTypes(), version).generate(root.getRoot(), version, genDate, null);
        save(s, tmpResDir + root.getName().replace(".", "_") + ".schema.json");
        if (!root.isAbstract()) {
            new JsonGenerator(definitions, workerContext, definitions.getKnownTypes(), version).generate(root.getRoot(), version, genDate, schema);
        }
    }
    // save(generateAllResourceChoice(names), xsdDir+"ResourceList.schema.json");
    save(schema, xsdDir + "fhir.schema.json");
    dir = new CSFile(xsdDir);
    list = dir.listFiles();
    for (File f : list) {
        if (!f.isDirectory() && f.getName().endsWith(".schema.json"))
            Utilities.copyFile(f, new CSFile(dstDir + f.getName()));
    }
}
Also used : TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) CSFile(org.hl7.fhir.utilities.CSFile) CSFile(org.hl7.fhir.utilities.CSFile) File(java.io.File) IniFile(org.hl7.fhir.utilities.IniFile) TextFile(org.hl7.fhir.utilities.TextFile) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 19 with IniFile

use of org.hl7.fhir.utilities.IniFile in project kindling by HL7.

the class SchemaGenerator method generate.

public void generate(Definitions definitions, IniFile ini, String tmpResDir, String xsdDir, String dstDir, String srcDir, String version, String genDate, boolean forCodeGeneration, BuildWorkerContext workerContext) throws Exception {
    this.genDate = genDate;
    this.version = version;
    this.workerContext = workerContext;
    if (!forCodeGeneration) {
        File dir = new CSFile(xsdDir);
        File[] list = dir.listFiles();
        if (list != null) {
            for (File f : list) {
                if (!f.isDirectory())
                    f.delete();
            }
        }
    }
    XSDBaseGenerator xsdb = new XSDBaseGenerator(new OutputStreamWriter(new FileOutputStream(new CSFile(xsdDir + "fhir-base.xsd")), "UTF-8"), forCodeGeneration, workerContext, new HashSet<>(), version);
    xsdb.setDefinitions(definitions);
    xsdb.generate(version, genDate, true);
    xsdb.getWriter().close();
    Set<String> allenums = new HashSet<String>();
    List<String> names = new ArrayList<String>();
    names.addAll(definitions.getResources().keySet());
    names.add("Parameters");
    Collections.sort(names);
    for (String name : names) {
        ResourceDefn root = definitions.getResourceByName(name);
        XSDGenerator sgen = new XSDGenerator(new OutputStreamWriter(new FileOutputStream(new CSFile(xsdDir + root.getName().toLowerCase() + ".xsd")), "UTF-8"), definitions, forCodeGeneration, workerContext, allenums, version);
        sgen.setDataTypes(definitions.getKnownTypes());
        sgen.generate(root.getRoot(), version, genDate, true);
        sgen.getWriter().close();
    }
    OutputStreamWriter single = new OutputStreamWriter(new FileOutputStream(new CSFile(xsdDir + "fhir-single.xsd")), "UTF-8");
    single.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
    single.write("<!-- \r\n");
    single.write(Config.FULL_LICENSE_CODE);
    single.write("\r\n");
    single.write("  Generated on " + genDate + " for FHIR v" + version + " \r\n");
    single.write("-->\r\n");
    single.write("<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://hl7.org/fhir\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\" " + "xmlns:xml=\"http://www.w3.org/XML/1998/namespace\" targetNamespace=\"http://hl7.org/fhir\" elementFormDefault=\"qualified\" version=\"" + version + "\">\r\n");
    single.write("  <!-- Note: When using this schema with some tools, it may also be necessary to declare xmlns:xml=\"http://www.w3.org/XML/1998/namespace\", however this causes performance issues with other tools and thus is not in the base schemas. -->\r\n");
    allenums = new HashSet<String>();
    xsdb = new XSDBaseGenerator(single, forCodeGeneration, workerContext, allenums, version);
    xsdb.setDefinitions(definitions);
    xsdb.generate(version, genDate, false);
    // 
    for (String name : names) {
        ResourceDefn root = definitions.getResourceByName(name);
        XSDGenerator sgen = new XSDGenerator(single, definitions, forCodeGeneration, workerContext, allenums, version);
        sgen.setDataTypes(definitions.getKnownTypes());
        sgen.generate(root.getRoot(), version, genDate, false);
    }
    single.write("</xs:schema>\r\n");
    single.flush();
    single.close();
    for (String n : ini.getPropertyNames("schema")) {
        String xsd = TextFile.fileToString(srcDir + n);
        xsd = processSchemaIncludes(definitions, n, xsd, false);
        TextFile.stringToFile(xsd, xsdDir + n);
    }
    produceCombinedSchema(definitions, xsdDir, dstDir, srcDir);
    if (!forCodeGeneration) {
        File dir = new CSFile(xsdDir);
        File[] list = dir.listFiles();
        for (File f : list) {
            if (!f.isDirectory())
                Utilities.copyFile(f, new CSFile(dstDir + f.getName()));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CSFile(org.hl7.fhir.utilities.CSFile) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) CSFile(org.hl7.fhir.utilities.CSFile) File(java.io.File) IniFile(org.hl7.fhir.utilities.IniFile) TextFile(org.hl7.fhir.utilities.TextFile) HashSet(java.util.HashSet)

Example 20 with IniFile

use of org.hl7.fhir.utilities.IniFile in project kindling by HL7.

the class SvgGenerator method generate.

public String generate(String filename, String id) throws Exception {
    this.id = id;
    ini = new IniFile(filename);
    String[] classNames = ini.getStringProperty("diagram", "classes") == null ? null : ini.getStringProperty("diagram", "classes").split("\\,");
    if ("false".equals(ini.getStringProperty("diagram", "attributes")))
        attributes = false;
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    XMLWriter xml = new XMLWriter(bytes, "UTF-8");
    minx = 0;
    miny = 0;
    Point size = determineMetrics(classNames);
    adjustAllForMin(size);
    xml.setPretty(false);
    xml.start();
    xml.setDefaultNamespace(NS_SVG);
    xml.namespace(NS_XLINK, "xlink");
    xml.attribute("id", "n" + (++nc));
    xml.attribute("version", "1.1");
    xml.attribute("width", Utilities.noString(ini.getStringProperty("size", "width")) ? Double.toString(size.x) : ini.getStringProperty("size", "width"));
    xml.attribute("height", Utilities.noString(ini.getStringProperty("size", "height")) ? Double.toString(size.y) : ini.getStringProperty("size", "height"));
    xml.enter("svg");
    shadowFilter(xml);
    drawElement(xml, classNames);
    countDuplicateLinks();
    for (Link l : links) {
        drawLink(xml, l);
    }
    xml.exit("svg");
    xml.end();
    String s = new String(bytes.toByteArray());
    return s.substring(s.indexOf(">") + 1);
}
Also used : IniFile(org.hl7.fhir.utilities.IniFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLWriter(org.hl7.fhir.utilities.xml.XMLWriter)

Aggregations

IniFile (org.hl7.fhir.utilities.IniFile)27 File (java.io.File)16 TextFile (org.hl7.fhir.utilities.TextFile)12 ArrayList (java.util.ArrayList)7 CSFile (org.hl7.fhir.utilities.CSFile)6 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 Date (java.util.Date)5 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)5 FileInputStream (java.io.FileInputStream)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)4 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)4 RandomAccessFile (java.io.RandomAccessFile)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 JsonObject (com.google.gson.JsonObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParseException (java.text.ParseException)2