Search in sources :

Example 1 with SpreadSheetReloader

use of org.hl7.fhir.definitions.parsers.spreadsheets.SpreadSheetReloader in project kindling by HL7.

the class SourceParser method loadResource.

private ResourceDefn loadResource(String n, Map<String, ResourceDefn> map, boolean isAbstract, boolean isTemplate, String t, boolean isInterface) throws Exception {
    String folder = n;
    WorkGroup wg = definitions.getWorkgroups().get(ini.getStringProperty("workgroups", n));
    if (wg == null)
        throw new Exception("No Workgroup found for resource " + n + ": '" + ini.getStringProperty("workgroups", n) + "'");
    File f = new File(Utilities.path(srcDir, folder, n + ".svg"));
    if (isTemplate) {
        File spreadsheet = new CSFile((srcDir) + folder + File.separatorChar + n + "-spreadsheet.xml");
        OldSpreadsheetParser sparser = new OldSpreadsheetParser("core", new CSFileInputStream(spreadsheet), spreadsheet.getName(), spreadsheet.getAbsolutePath(), definitions, srcDir, logger, registry, version, context, genDate, isAbstract, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
        ResourceDefn root;
        try {
            root = sparser.parseResource(isTemplate);
        } catch (Exception e) {
            throw new Exception("Error Parsing Resource " + n + ": " + e.getMessage(), e);
        }
        root.setAbstract(isAbstract);
        root.setInterface(isInterface);
        errors.addAll(sparser.getErrors());
        setResourceProps(n, wg, root);
        String sc = ini.getStringProperty("security-categorization", root.getName().toLowerCase());
        if (sc != null) {
            root.setSecurityCategorization(SecurityCategorization.fromCode(sc));
        } else if (!Utilities.existsInList(root.getName(), "Resource", "DomainResource", "CanonicalResource", "MetadataResource", "MetadataPattern"))
            throw new Exception("Must have an entry in the security-categorization section of fhir.ini for the resource " + root.getName());
        for (EventDefn e : sparser.getEvents()) {
            processEvent(e, root.getRoot());
        }
        if (map != null) {
            map.put(root.getName(), root);
        }
        if (!isTemplate) {
            definitions.getKnownResources().put(root.getName(), new DefinedCode(root.getName(), root.getRoot().getDefinition(), n));
            context.getResourceNames().add(root.getName());
        }
        if (root.getNormativeVersion() != null || root.getNormativePackage() != null) {
            root.setStatus(StandardsStatus.NORMATIVE);
        }
        if (f.exists()) {
            parseSvgFile(f, root.getLayout(), f.getName());
        }
        if (map != null) {
            map.put(root.getName(), root);
        }
        return root;
    } else {
        try {
            new SpreadSheetReloader(context, srcDir, t, version.toCode()).process();
        } catch (Exception e) {
            System.out.println("Error loading spreadsheet for resource " + t + ": " + e.getMessage());
        }
        new SpreadSheetCreator(context, srcDir, t).generateSpreadsheet();
        ResourceDefn rootNew = new ResourceParser(srcDir, definitions, context, wg, registry, version.toCode(), page.getConceptMaps()).parse(n, t);
        if (f.exists()) {
            parseSvgFile(f, rootNew.getLayout(), f.getName());
        }
        if (!isTemplate) {
            definitions.getKnownResources().put(rootNew.getName(), new DefinedCode(rootNew.getName(), rootNew.getRoot().getDefinition(), n));
            context.getResourceNames().add(rootNew.getName());
        }
        setResourceProps(n, wg, rootNew);
        if (map != null) {
            map.put(rootNew.getName(), rootNew);
        }
        return rootNew;
    }
}
Also used : SpreadSheetCreator(org.hl7.fhir.definitions.parsers.spreadsheets.SpreadSheetCreator) EventDefn(org.hl7.fhir.definitions.model.EventDefn) CSFile(org.hl7.fhir.utilities.CSFile) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WorkGroup(org.hl7.fhir.definitions.model.WorkGroup) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) OldSpreadsheetParser(org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) SpreadSheetReloader(org.hl7.fhir.definitions.parsers.spreadsheets.SpreadSheetReloader) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 DefinedCode (org.hl7.fhir.definitions.model.DefinedCode)1 EventDefn (org.hl7.fhir.definitions.model.EventDefn)1 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)1 WorkGroup (org.hl7.fhir.definitions.model.WorkGroup)1 OldSpreadsheetParser (org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser)1 SpreadSheetCreator (org.hl7.fhir.definitions.parsers.spreadsheets.SpreadSheetCreator)1 SpreadSheetReloader (org.hl7.fhir.definitions.parsers.spreadsheets.SpreadSheetReloader)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1 CSFile (org.hl7.fhir.utilities.CSFile)1 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)1 IniFile (org.hl7.fhir.utilities.IniFile)1 TextFile (org.hl7.fhir.utilities.TextFile)1 SAXException (org.xml.sax.SAXException)1