Search in sources :

Example 11 with WorkGroup

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

the class OldSpreadsheetParser method parseConformancePackage.

public void parseConformancePackage(Profile ap, Definitions definitions, String folder, String usage, List<ValidationMessage> issues, WorkGroup wg) throws Exception {
    try {
        isProfile = true;
        this.folder = folder;
        checkMappings(ap);
        Sheet sheet = loadSheet("Bindings");
        if (sheet != null)
            readBindings(sheet);
        sheet = loadSheet("Metadata");
        for (int row = 0; row < sheet.rows.size(); row++) {
            String n = sheet.getColumn(row, "Name");
            String v = sheet.getColumn(row, "Value");
            if (n != null && v != null) {
                if (ap.getMetadata().containsKey(n))
                    ap.getMetadata().get(n).add(v);
                else {
                    ArrayList<String> vl = new ArrayList<String>();
                    vl.add(v);
                    ap.getMetadata().put(n, vl);
                }
            }
        }
        if (!Utilities.noString(ap.metadata("category")))
            usage = ap.metadata("category");
        if (ap.hasMetadata("name"))
            ap.setTitle(ap.metadata("name"));
        if (ap.hasMetadata("introduction"))
            ap.setIntroduction(Utilities.path(folder, ap.metadata("introduction")));
        if (ap.hasMetadata("notes"))
            ap.setNotes(Utilities.path(folder, ap.metadata("notes")));
        if (!ap.hasMetadata("id"))
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " no 'id' found in metadata");
        if (!ap.metadata("id").matches(FormatUtilities.ID_REGEX))
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " 'id' is not a valid id");
        if (wg == null)
            wg = workgroups.get(ap.metadata("workgroup"));
        if (wg == null)
            wg = committee;
        if (wg == null)
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " : no workgroup value in the metadata");
        if (!ap.metadata("id").equals(ap.metadata("id").toLowerCase()))
            throw new Exception("Error parsing " + ap.getId() + "/" + ap.getTitle() + " 'id' must be all lowercase");
        this.profileExtensionBase = ap.metadata("extension.uri");
        if (ig == null || ig.isCore()) {
            if (!profileExtensionBase.startsWith("http://hl7.org/fhir/StructureDefinition/") && !profileExtensionBase.startsWith("http://fhir-registry.smarthealthit.org/StructureDefinition/"))
                throw new Exception("Core extensions must have a url starting with http://hl7.org/fhir/StructureDefinition/ for " + ap.getId());
        } else {
            if (!profileExtensionBase.startsWith("http://hl7.org/fhir/StructureDefinition/" + ig.getCode() + "-"))
                throw new Exception("Core extensions must have a url starting with http://hl7.org/fhir/StructureDefinition/" + ig.getCode() + "- for " + ap.getId());
        }
        Map<String, Invariant> invariants = null;
        sheet = loadSheet("Extensions-Inv");
        if (sheet != null) {
            invariants = readInvariants(sheet, "", "Extensions-Inv");
        }
        sheet = loadSheet("Extensions");
        if (sheet != null) {
            int row = 0;
            while (row < sheet.rows.size()) {
                if (sheet.getColumn(row, "Code").startsWith("!"))
                    row++;
                else
                    row = processExtension(null, sheet, row, definitions, ap.metadata("extension.uri"), ap, issues, invariants, wg);
            }
        }
        List<String> namedSheets = new ArrayList<String>();
        if (ap.getMetadata().containsKey("published.structure")) {
            for (String n : ap.getMetadata().get("published.structure")) {
                if (!Utilities.noString(n)) {
                    if (ig != null && !ig.isCore() && !n.toLowerCase().startsWith(ig.getCode() + "-"))
                        throw new Exception("Error: published structure names must start with the implementation guide code (" + ig.getCode() + "-)");
                    String fmm = ap.metadata("fmm-" + n);
                    if (Utilities.noString(fmm))
                        fmm = ap.metadata("fmm");
                    if (Utilities.noString(fmm))
                        // default fmm value
                        fmm = "1";
                    ap.getProfiles().add(parseProfileSheet(definitions, ap, n, namedSheets, true, usage, issues, wg, fmm));
                }
            }
        }
        int i = 0;
        while (i < namedSheets.size()) {
            String fmm = ap.metadata("fmm-" + namedSheets.get(i));
            if (Utilities.noString(fmm))
                fmm = ap.metadata("fmm");
            if (Utilities.noString(fmm))
                // default fmm value
                fmm = "1";
            ap.getProfiles().add(parseProfileSheet(definitions, ap, namedSheets.get(i), namedSheets, false, usage, issues, wg, fmm));
            i++;
        }
        if (namedSheets.isEmpty() && xls.getSheets().containsKey("Search"))
            readSearchParams(ap, xls.getSheets().get("Search"), this.profileExtensionBase);
        if (xls.getSheets().containsKey("Operations"))
            readOperations(ap.getOperations(), loadSheet("Operations"));
    } catch (Exception e) {
        throw new Exception("exception parsing pack " + ap.getSource() + ": " + e.getMessage(), e);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ArrayList(java.util.ArrayList) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 12 with WorkGroup

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

the class SourceParser method loadWorkGroups.

private void loadWorkGroups() {
    String[] wgs = ini.getPropertyNames("wg-info");
    for (String wg : wgs) {
        String s = ini.getStringProperty("wg-info", wg);
        int i = s.indexOf(" ");
        String url = s.substring(0, i);
        String name = s.substring(i + 1).trim();
        definitions.getWorkgroups().put(wg, new WorkGroup(wg, name, url));
    }
}
Also used : WorkGroup(org.hl7.fhir.definitions.model.WorkGroup)

Example 13 with WorkGroup

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

the class SourceParser method loadConformancePackage.

private void loadConformancePackage(Profile ap, List<ValidationMessage> issues, WorkGroup wg) throws FileNotFoundException, IOException, Exception {
    if (ap.getSourceType() == ConformancePackageSourceType.Spreadsheet) {
        OldSpreadsheetParser sparser = new OldSpreadsheetParser(ap.getCategory(), new CSFileInputStream(ap.getSource()), Utilities.noString(ap.getId()) ? ap.getSource() : ap.getId(), ap.getSource(), definitions, srcDir, logger, registry, version, context, genDate, false, page, false, ini, wg, definitions.getProfileIds(), fpUsages, page.getConceptMaps(), exceptionIfExcelNotNormalised, page.packageInfo(), page.getRc());
        sparser.setFolder(Utilities.getDirectoryForFile(ap.getSource()));
        sparser.parseConformancePackage(ap, definitions, Utilities.getDirectoryForFile(ap.getSource()), ap.getCategory(), issues, wg);
        errors.addAll(sparser.getErrors());
    } else if (ap.getSourceType() == ConformancePackageSourceType.StructureDefinition) {
        Resource rf;
        try {
            rf = new XmlParser().parse(new CSFileInputStream(ap.getSource()));
        } catch (Exception e) {
            throw new Exception("Error parsing " + ap.getSource() + ": " + e.getMessage(), e);
        }
        if (!(rf instanceof StructureDefinition))
            throw new Exception("Error parsing Profile: not a structure definition");
        StructureDefinition sd = (StructureDefinition) rf;
        sd.setVersion(version.toCode());
        ap.putMetadata("id", sd.getId() + "-pack");
        ap.putMetadata("date", sd.getDateElement().asStringValue());
        ap.putMetadata("title", sd.getTitle());
        ap.putMetadata("status", sd.getStatus().toCode());
        ap.putMetadata("description", new XhtmlComposer(XhtmlComposer.HTML).compose(sd.getText().getDiv()));
        if (ToolingExtensions.hasExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg")) {
            wg = definitions.getWorkgroups().get(ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/structuredefinition-wg"));
            ap.putMetadata("workgroup", wg.getCode());
        }
        ap.setTitle(sd.getTitle());
        new ProfileUtilities(page.getWorkerContext(), null, null).setIds(sd, false);
        ap.getProfiles().add(new ConstraintStructure(sd, definitions.getUsageIG(ap.getCategory(), "Parsing " + ap.getSource()), wg == null ? wg(sd) : wg, fmm(sd), sd.getExperimental()));
    } else if (ap.getSource() != null) {
        parseConformanceDocument(ap, ap.getId(), new CSFile(ap.getSource()), ap.getCategory(), wg);
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) Resource(org.hl7.fhir.r5.model.Resource) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) OldSpreadsheetParser(org.hl7.fhir.definitions.parsers.spreadsheets.OldSpreadsheetParser) CSFile(org.hl7.fhir.utilities.CSFile) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 14 with WorkGroup

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

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

the class ResourceParser method processProfile.

private ConstraintStructure processProfile(String rid, String igId, ImplementationGuideDefinitionResourceComponent res, WorkGroup wg) throws FHIRFormatError, FileNotFoundException, IOException {
    StructureDefinition sd = (StructureDefinition) parseXml("structuredefinition-profile-" + rid + ".xml");
    ImplementationGuideDefn ig = definitions.getIgs().get(BuildExtensions.readStringExtension(res, igId));
    if (ig == null) {
        ig = definitions.getIgs().get("core");
    }
    ConstraintStructure cs = new ConstraintStructure(sd, ig, wg == null ? wg(sd) : wg, null, false);
    return cs;
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ImplementationGuideDefn(org.hl7.fhir.definitions.model.ImplementationGuideDefn) ConstraintStructure(org.hl7.fhir.definitions.model.ConstraintStructure)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)13 FileNotFoundException (java.io.FileNotFoundException)9 IOException (java.io.IOException)9 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)9 CSFile (org.hl7.fhir.utilities.CSFile)9 ConstraintStructure (org.hl7.fhir.definitions.model.ConstraintStructure)8 WorkGroup (org.hl7.fhir.definitions.model.WorkGroup)8 File (java.io.File)7 ArrayList (java.util.ArrayList)6 TransformerException (javax.xml.transform.TransformerException)6 TextFile (org.hl7.fhir.utilities.TextFile)6 URISyntaxException (java.net.URISyntaxException)5 CSFileInputStream (org.hl7.fhir.utilities.CSFileInputStream)5 IniFile (org.hl7.fhir.utilities.IniFile)5 Date (java.util.Date)4 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 UcumException (org.fhir.ucum.UcumException)4 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)4 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)4