Search in sources :

Example 21 with XmlParser

use of org.hl7.fhir.r4.formats.XmlParser in project kindling by HL7.

the class Regenerator method generateExtension.

private CanonicalResource generateExtension(String root, ResourceDefn r, Profile p, StructureDefinition sd) throws IOException {
    File fn = new File(Utilities.path(root, sd.fhirType().toLowerCase() + "-extension-" + sd.getId() + ".gen.xml"));
    sd.setSnapshot(null);
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sd);
    fn.setLastModified(r.getTimestamp());
    return sd;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 22 with XmlParser

use of org.hl7.fhir.r4.formats.XmlParser in project kindling by HL7.

the class Regenerator method generateCP.

private void generateCP(String root, ResourceDefn r, Profile p) throws IOException {
    ImplementationGuide ig = new ImplementationGuide();
    ig.setId(r.getName() + "-" + p.getCategory());
    ig.setTitle(p.getTitle());
    ig.setStatus(PublicationStatus.ACTIVE);
    ig.setDate(new Date(r.getTimestamp()));
    for (String s : p.getMetadata().keySet()) {
        List<String> vl = p.getMetadata().get(s);
        for (String v : vl) {
            if (!Utilities.noString(v)) {
                switch(s) {
                    // case "id": ig.setId(v); break;
                    case "name":
                        ig.setName(v);
                        break;
                    case "author.name":
                        ig.setPublisher(v);
                        break;
                    case "code":
                        ig.addExtension(BuildExtensions.EXT_CODE, new CodeType(v));
                        break;
                    case "fmm":
                        ig.addExtension(ToolingExtensions.EXT_FMM_LEVEL, new CodeType(v));
                        break;
                    case "description":
                        ig.setDescription(v);
                        break;
                    case "status":
                        ig.setStatus(PublicationStatus.fromCode(v));
                        break;
                    case "publication.status":
                        break;
                    case "version":
                        ig.setVersion(v);
                        break;
                    case "display":
                        ig.setTitle(v);
                        break;
                    case "workgroup":
                        ig.addExtension(ToolingExtensions.EXT_WORKGROUP, new CodeType(v));
                        break;
                    case "date":
                        ig.getDateElement().setValueAsString(v);
                        break;
                    case "Experimental":
                        ig.setExperimental(Utilities.existsInList(v.toLowerCase(), "y", "yes", "1", "true"));
                        break;
                    default:
                        if (s.startsWith("fmm-") || Utilities.existsInList(s, "extension.uri", "author.reference", "published.structure", "notes", "introduction") || s.startsWith("!")) {
                        // ignore these
                        } else if (s.startsWith("summary-")) {
                            String n = s.substring(8);
                            for (ConstraintStructure cs : p.getProfiles()) {
                                if (n.equals(cs.getTitle()) || n.equals(cs.getId())) {
                                    cs.setSummary(v);
                                }
                            }
                        } else {
                            System.out.println("Unknown metadata item: " + s + "=" + v);
                        }
                }
            }
        }
    }
    if (!Utilities.noString(p.getIntroduction())) {
        ig.addExtension(BuildExtensions.EXT_INTRODUCTION, new StringType(p.getIntroduction()));
    }
    if (!Utilities.noString(p.getNotes())) {
        ig.addExtension(BuildExtensions.EXT_NOTES, new StringType(p.getNotes()));
    }
    for (ConstraintStructure cs : p.getProfiles()) {
        CanonicalResource cr = generateProfile(root, r, p, cs);
        ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
        res.getReference().setReference(cr.fhirType() + "/" + cr.getId());
    }
    for (StructureDefinition cs : p.getExtensions()) {
        CanonicalResource cr = generateExtension(root, r, p, cs.copy());
        ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
        res.getReference().setReference(cr.fhirType() + "/" + cr.getId());
    }
    for (SearchParameter cs : p.getSearchParameters()) {
        CanonicalResource cr = generateSearchParameter(root, r, p, cs);
        ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
        res.getReference().setReference(cr.fhirType() + "/" + cr.getId());
    }
    for (Example cs : p.getExamples()) {
        ImplementationGuideDefinitionResourceComponent res = ig.getDefinition().addResource();
        generateExample(root, r, p, cs, res);
    }
    File fn = new File(Utilities.path(root, ig.fhirType().toLowerCase() + "-" + ig.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), ig);
    fn.setLastModified(r.getTimestamp());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) StringType(org.hl7.fhir.r5.model.StringType) Date(java.util.Date) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) FileOutputStream(java.io.FileOutputStream) CodeType(org.hl7.fhir.r5.model.CodeType) ImplementationGuideDefinitionResourceComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) File(java.io.File)

Example 23 with XmlParser

use of org.hl7.fhir.r4.formats.XmlParser in project kindling by HL7.

the class Regenerator method generateInner.

public void generateInner(ResourceDefn r) throws FileNotFoundException, IOException {
    String root = Utilities.path(srcFolder, r.getName());
    generateSearchParams(root, r);
    generateExamples(root, r);
    generateOperations(r, root);
    generatePacks(r, root);
    // private List<Profile> conformancePackages = new ArrayList<Profile>();
    // private Profile conformancePack;
    StructureDefinition sd = r.getProfile().copy();
    sd.setSnapshot(null);
    sd.setText(null);
    if (r.getEnteredInErrorStatus() != null) {
        sd.addExtension(BuildExtensions.EXT_ENTERED_IN_ERROR_STATUS, new CodeType(r.getEnteredInErrorStatus()));
    }
    if (r.getProposedOrder() != null) {
        sd.addExtension(BuildExtensions.EXT_PROPOSED_ORDER, new StringType(r.getProposedOrder()));
    }
    if (r.getTemplate() != null) {
        sd.addExtension(BuildExtensions.EXT_TEMPLATE, new StringType(r.getTemplate().getName()));
    }
    // now, walk through the elements.
    generateElement(root, r.getName(), sd.getDifferential(), r, r.getRoot());
    File fn = new File(Utilities.path(root, sd.fhirType().toLowerCase() + "-" + sd.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sd);
    fn.setLastModified(r.getTimestamp());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StringType(org.hl7.fhir.r5.model.StringType) FileOutputStream(java.io.FileOutputStream) CodeType(org.hl7.fhir.r5.model.CodeType) File(java.io.File)

Example 24 with XmlParser

use of org.hl7.fhir.r4.formats.XmlParser in project kindling by HL7.

the class Regenerator method generateExamples.

private void generateExamples(String root, ResourceDefn r) throws FileNotFoundException, IOException {
    ListResource list = new ListResource();
    list.setId(r.getName() + "-examples");
    list.setStatus(ListStatus.CURRENT);
    list.setMode(ListMode.WORKING);
    for (Example ex : r.getExamples()) {
        ListResourceEntryComponent li = list.addEntry();
        li.getItem().setReference(ex.getResourceName() + "/" + ex.getId());
        li.getItem().setDisplay(ex.getName());
        if (ex.getDescription() != null) {
            li.addExtension(BuildExtensions.EXT_DESCRIPTION, new StringType(ex.getDescription()));
        }
        if (ex.getTitle() != null) {
            li.addExtension(BuildExtensions.EXT_TITLE, new StringType(ex.getTitle()));
        }
        switch(ex.getType()) {
            case Container:
                li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "container", null);
                break;
            case CsvFile:
                li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "csv", null);
                break;
            case Tool:
                li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "tool", null);
                break;
            default:
                break;
        }
        if (!ex.isRegistered()) {
            li.addExtension(BuildExtensions.EXT_NOT_REGISTERED, new BooleanType(!ex.isRegistered()));
        }
        if (ex.getIg() != null) {
            li.addExtension(BuildExtensions.EXT_IG, new CodeType(ex.getIg()));
        }
        if (ex.getExampleFor() != null) {
            li.addExtension(BuildExtensions.EXT_EXAMPLE_FOR, new StringType(ex.getExampleFor()));
        }
    }
    File fn = new File(Utilities.path(root, list.fhirType().toLowerCase() + "-" + list.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), list);
    fn.setLastModified(r.getTimestamp());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StringType(org.hl7.fhir.r5.model.StringType) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) ListResourceEntryComponent(org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent) FileOutputStream(java.io.FileOutputStream) BooleanType(org.hl7.fhir.r5.model.BooleanType) CodeType(org.hl7.fhir.r5.model.CodeType) ListResource(org.hl7.fhir.r5.model.ListResource) File(java.io.File)

Example 25 with XmlParser

use of org.hl7.fhir.r4.formats.XmlParser in project kindling by HL7.

the class Regenerator method generateSearchParameter.

private CanonicalResource generateSearchParameter(String root, ResourceDefn r, Profile p, SearchParameter sp) throws IOException {
    File fn = new File(Utilities.path(root, sp.fhirType().toLowerCase() + "-profile-" + sp.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sp);
    fn.setLastModified(r.getTimestamp());
    return sp;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

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