Search in sources :

Example 1 with ExampleType

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

the class OldSpreadsheetParser method readExamples.

private void readExamples(ResourceDefn defn, Sheet sheet) throws Exception {
    if (sheet != null) {
        for (int row = 0; row < sheet.rows.size(); row++) {
            String name = sheet.getColumn(row, "Name");
            if (name != null && !name.equals("") && !name.startsWith("!")) {
                String id = sheet.getColumn(row, "Identity");
                if (id == null || id.equals(""))
                    throw new Exception("Example " + name + " has no identity parsing " + this.name);
                String desc = sheet.getColumn(row, "Description");
                if (desc == null || desc.equals(""))
                    throw new Exception("Example " + name + " has no description parsing " + this.name);
                String filename = sheet.getColumn(row, "Filename");
                if (filename.startsWith(defn.getName().toLowerCase() + "-examples."))
                    throw new Exception("Cannot name an example file " + filename);
                File file = new CSFile(folder + filename);
                String type = sheet.getColumn(row, "Type");
                if (!file.exists() && !("tool".equals(type) || isSpecialType(type)))
                    throw new Exception("Example " + name + " file '" + file.getAbsolutePath() + "' not found parsing " + this.name);
                List<Example> list = defn.getExamples();
                String pn = sheet.getColumn(row, "Profile");
                if (!Utilities.noString(pn) && !pn.startsWith("!")) {
                    Profile ap = null;
                    for (Profile r : defn.getConformancePackages()) {
                        if (r.getTitle().equals(pn))
                            ap = r;
                    }
                    if (ap == null)
                        throw new Exception("Example " + name + " profile '" + pn + "' not found parsing " + this.name);
                    else
                        list = ap.getExamples();
                }
                ExampleType etype = parseExampleType(type, row);
                list.add(new Example(name, id, desc, file, parseBoolean(sheet.getColumn(row, "Registered"), row, true), etype, isAbstract));
            }
        }
    }
    if (defn.getExamples().size() == 0) {
        File file = new CSFile(folder + title + "-example.xml");
        if (!file.exists() && !isAbstract)
            throw new Exception("Example (file '" + file.getAbsolutePath() + "') not found parsing " + this.name);
        if (file.exists())
            defn.getExamples().add(new Example("General", "example", "Example of " + title, file, true, ExampleType.XmlFile, isAbstract));
    }
}
Also used : Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) CSFile(org.hl7.fhir.utilities.CSFile) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) FHIRException(org.hl7.fhir.exceptions.FHIRException) Profile(org.hl7.fhir.definitions.model.Profile) ExampleType(org.hl7.fhir.definitions.model.Example.ExampleType)

Example 2 with ExampleType

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

the class ResourceParser method parseExamples.

private void parseExamples(ResourceDefn r, String n, String t) throws FHIRException, Exception {
    ListResource list = (ListResource) parseXml("list-" + t + "-examples.xml");
    for (ListResourceEntryComponent le : list.getEntry()) {
        boolean reg = le.hasExtension(BuildExtensions.EXT_NOT_REGISTERED) ? !BuildExtensions.readBoolExtension(le, BuildExtensions.EXT_NOT_REGISTERED) : true;
        ExampleType type = ExampleType.XmlFile;
        if (le.getFlag().hasCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "container")) {
            type = ExampleType.Container;
        } else if (le.getFlag().hasCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "csv")) {
            type = ExampleType.CsvFile;
        } else if (le.getFlag().hasCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "tool")) {
            type = ExampleType.Tool;
        }
        String id = le.getItem().getReference().substring(le.getItem().getReference().lastIndexOf("/") + 1);
        String ig = le.getExtensionString(BuildExtensions.EXT_IG);
        CSFile path = Utilities.noString(ig) ? new CSFile(Utilities.path(folder, le.getExtensionString(BuildExtensions.EXT_TITLE) + ".xml")) : new CSFile(Utilities.path(rootFolder(), "guides", ig, le.getExtensionString(BuildExtensions.EXT_TITLE) + "." + ext(type)));
        Example ex = new Example(le.getItem().getDisplay(), id, le.getExtensionString(BuildExtensions.EXT_DESCRIPTION), path, reg, type, false);
        r.getExamples().add(ex);
    }
}
Also used : ListResourceEntryComponent(org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) CSFile(org.hl7.fhir.utilities.CSFile) ListResource(org.hl7.fhir.r5.model.ListResource) ExampleType(org.hl7.fhir.definitions.model.Example.ExampleType)

Aggregations

Example (org.hl7.fhir.definitions.model.Example)2 ExampleType (org.hl7.fhir.definitions.model.Example.ExampleType)2 OperationExample (org.hl7.fhir.definitions.model.Operation.OperationExample)2 CSFile (org.hl7.fhir.utilities.CSFile)2 File (java.io.File)1 Profile (org.hl7.fhir.definitions.model.Profile)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1 ListResource (org.hl7.fhir.r5.model.ListResource)1 ListResourceEntryComponent (org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent)1 IniFile (org.hl7.fhir.utilities.IniFile)1 TextFile (org.hl7.fhir.utilities.TextFile)1