Search in sources :

Example 46 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn in project kindling by HL7.

the class OldSpreadsheetParser method readEvents.

private void readEvents(Sheet sheet, ResourceDefn root) throws Exception {
    if (sheet != null) {
        for (int row = 0; row < sheet.rows.size(); row++) {
            String code = sheet.getColumn(row, "Event Code");
            if (code != null && !code.equals("") && !code.startsWith("!")) {
                System.out.print("!!Lloyd Look at me! - event " + code + " on resource " + root.getName());
                EventDefn e = new EventDefn();
                events.add(e);
                e.setCode(code);
                e.setTitle(sheet.getColumn(row, "Title"));
                e.setDefinition(Utilities.appendPeriod(sheet.getColumn(row, "Description")));
                e.setCategory(readCategory(sheet.getColumn(row, "Category")));
                EventUsage u = new EventUsage();
                e.getUsages().add(u);
                u.setNotes(sheet.getColumn(row, "Notes"));
                for (String s : sheet.getColumn(row, "Request Resources").split(",")) {
                    s = s.trim();
                    if (!s.isEmpty())
                        u.getRequestResources().add(s);
                }
                for (String s : sheet.getColumn(row, "Request Aggregations").split("\n")) {
                    s = s.trim();
                    if (!s.isEmpty())
                        u.getRequestAggregations().add(s);
                }
                for (String s : sheet.getColumn(row, "Response Resources").split(",")) {
                    s = s.trim();
                    if (!s.isEmpty())
                        u.getResponseResources().add(s);
                }
                for (String s : sheet.getColumn(row, "Response Aggregations").split("\n")) {
                    s = s.trim();
                    if (!s.isEmpty())
                        u.getResponseAggregations().add(s);
                }
                for (String s : sheet.getColumn(row, "Follow Ups").split(",")) {
                    s = s.trim();
                    if (!s.isEmpty())
                        e.getFollowUps().add(s);
                }
            }
        }
    }
}
Also used : EventUsage(org.hl7.fhir.definitions.model.EventUsage) EventDefn(org.hl7.fhir.definitions.model.EventDefn)

Example 47 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn 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 48 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn 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 49 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn 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 50 with ResourceDefn

use of org.hl7.fhir.definitions.model.ResourceDefn 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)

Aggregations

ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)75 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)42 ArrayList (java.util.ArrayList)38 FHIRException (org.hl7.fhir.exceptions.FHIRException)36 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)31 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)28 File (java.io.File)26 FileOutputStream (java.io.FileOutputStream)25 CSFile (org.hl7.fhir.utilities.CSFile)24 XmlParser (org.hl7.fhir.r5.formats.XmlParser)22 FileNotFoundException (java.io.FileNotFoundException)20 IOException (java.io.IOException)20 Example (org.hl7.fhir.definitions.model.Example)20 Profile (org.hl7.fhir.definitions.model.Profile)20 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)18 IniFile (org.hl7.fhir.utilities.IniFile)18 ImplementationGuideDefn (org.hl7.fhir.definitions.model.ImplementationGuideDefn)16 TransformerException (javax.xml.transform.TransformerException)15 TextFile (org.hl7.fhir.utilities.TextFile)15 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)14