Search in sources :

Example 31 with BindingSpecification

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

the class BindingsParser method processLine.

private void processLine(List<BindingSpecification> results, Sheet sheet, int row) throws Exception {
    BindingSpecification cd = new BindingSpecification("core", sheet.getColumn(row, "Binding Name"), true);
    if (!cd.getName().startsWith("!")) {
        if (Character.isLowerCase(cd.getName().charAt(0)))
            throw new Exception("binding name " + cd.getName() + " is illegal - must start with a capital letter");
        cd.setDefinition(Utilities.appendPeriod(sheet.getColumn(row, "Definition")));
        cd.setBindingMethod(readBinding(sheet.getColumn(row, "Binding"), cd.getName() + " in " + filename));
        boolean utg = "y".equals(sheet.getColumn(row, "UTG"));
        String ref = sheet.getColumn(row, "Reference");
        if (!cd.getBinding().equals(BindingMethod.Unbound) && Utilities.noString(ref))
            throw new Exception("binding " + cd.getName() + " is missing a reference");
        if (cd.getBinding() == BindingMethod.CodeList) {
            cd.setValueSet(new ValueSet());
            cd.getValueSet().setId(ref.substring(1));
            cd.getValueSet().setUrl("http://hl7.org/fhir/ValueSet/" + ref.substring(1));
            cd.getValueSet().setVersion(version);
            if (!Utilities.noString(sheet.getColumn(row, "Committee"))) {
                cd.getValueSet().addExtension().setUrl(ToolingExtensions.EXT_WORKGROUP).setValue(new CodeType(sheet.getColumn(row, "Committee").toLowerCase()));
            }
            cd.getValueSet().setUserData("filename", "valueset-" + cd.getValueSet().getId());
            cd.getValueSet().setUserData("path", "valueset-" + cd.getValueSet().getId() + ".html");
            cd.getValueSet().setName(cd.getName());
            cd.getValueSet().setTitle(cd.getName());
            cd.getValueSet().setDateElement(new DateTimeType(genDate));
            cd.getValueSet().setStatus(PublicationStatus.DRAFT);
            cd.getValueSet().setDescription(sheet.getColumn(row, "Description"));
            if (!cd.getValueSet().hasDescription())
                cd.getValueSet().setDescription(cd.getDefinition());
            if (!ref.startsWith("#"))
                throw new Exception("Error parsing binding " + cd.getName() + ": code list reference '" + ref + "' must started with '#'");
            Sheet cs = xls.getSheets().get(ref.substring(1));
            if (cs == null)
                throw new Exception("Error parsing binding " + cd.getName() + ": code list reference '" + ref + "' not resolved");
            new CodeListToValueSetParser(cs, ref.substring(1), cd.getValueSet(), version, codeSystems, maps, packageInfo).execute(sheet.getColumn(row, "v2"), sheet.getColumn(row, "v3"), utg);
        } else if (cd.getBinding() == BindingMethod.ValueSet) {
            if (ref.startsWith("http:")) {
                // will sort this out later
                cd.setReference(sheet.getColumn(row, "Reference"));
            } else
                cd.setValueSet(loadValueSet(ref, sheet.getColumn(row, "Committee").toLowerCase()));
            String max = sheet.getColumn(row, "Max");
            if (!Utilities.noString(max))
                if (max.startsWith("http:")) {
                    // will sort this out later
                    cd.setMaxReference(max);
                } else
                    cd.setMaxValueSet(loadValueSet(max, sheet.getColumn(row, "Committee").toLowerCase()));
        } else if (cd.getBinding() == BindingMethod.Special) {
            cd.setValueSet(new ValueSet());
            cd.getValueSet().setId(ref.substring(1));
            cd.getValueSet().setUrl("http://hl7.org/fhir/ValueSet/" + ref.substring(1));
            cd.getValueSet().setVersion(version);
            cd.getValueSet().setName(cd.getName());
        // do nothing more: this will get filled out once all the resources are loaded
        }
        // do this anyway in the short term
        cd.setReference(sheet.getColumn(row, "Reference"));
        if (cd.getValueSet() != null) {
            touchVS(cd.getValueSet());
            ValueSetUtilities.markStatus(cd.getValueSet(), Utilities.noString(sheet.getColumn(row, "Committee")) ? "vocab" : sheet.getColumn(row, "Committee").toLowerCase(), null, null, Utilities.noString(sheet.getColumn(row, "FMM")) ? null : sheet.getColumn(row, "FMM"), null, Utilities.noString(sheet.getColumn(row, "Normative-Version")) ? null : sheet.getColumn(row, "Normative-Version"));
        }
        if (cd.getMaxValueSet() != null) {
            touchVS(cd.getMaxValueSet());
            ValueSetUtilities.markStatus(cd.getMaxValueSet(), Utilities.noString(sheet.getColumn(row, "Committee")) ? "vocab" : sheet.getColumn(row, "Committee").toLowerCase(), null, null, Utilities.noString(sheet.getColumn(row, "FMM")) ? null : sheet.getColumn(row, "FMM"), null, Utilities.noString(sheet.getColumn(row, "Max-Normative-Version")) ? null : sheet.getColumn(row, "Max-Normative-Version"));
        }
        cd.setDescription(sheet.getColumn(row, "Description"));
        cd.setSource(filename);
        cd.setUri(sheet.getColumn(row, "Uri"));
        cd.setStrength(readBindingStrength(sheet.getColumn(row, "Conformance")));
        String oid = sheet.getColumn(row, "Oid");
        if (!Utilities.noString(oid))
            // no cs oid in this case
            cd.setVsOid(oid);
        cd.setWebSite(sheet.getColumn(row, "Website"));
        cd.setStatus(PublicationStatus.fromCode(sheet.getColumn(row, "Status")));
        cd.setEmail(sheet.getColumn(row, "Email"));
        cd.setV2Map(sheet.getColumn(row, "v2"));
        cd.setV3Map(sheet.getColumn(row, "v3"));
        if (cd.getBinding() == BindingMethod.Unbound) {
            cd.setStrength(BindingStrength.EXAMPLE);
        }
        results.add(cd);
    }
}
Also used : DateTimeType(org.hl7.fhir.r5.model.DateTimeType) CodeListToValueSetParser(org.hl7.fhir.definitions.parsers.CodeListToValueSetParser) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) CodeType(org.hl7.fhir.r5.model.CodeType) ValueSet(org.hl7.fhir.r5.model.ValueSet) Sheet(org.hl7.fhir.utilities.xls.XLSXmlParser.Sheet) URISyntaxException(java.net.URISyntaxException)

Example 32 with BindingSpecification

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

the class PageProcessor method processPageIncludesForPrinting.

String processPageIncludesForPrinting(String file, String src, Resource resource, ImplementationGuideDefn ig) throws Exception {
    boolean even = false;
    List<String> tabs = new ArrayList<String>();
    while (src.contains("<%") || src.contains("[%")) {
        int i1 = src.indexOf("<%");
        int i2 = src.indexOf("%>");
        if (i1 == -1) {
            i1 = src.indexOf("[%");
            i2 = src.indexOf("%]");
        }
        String s1 = src.substring(0, i1);
        String s2 = src.substring(i1 + 2, i2).trim();
        String s3 = src.substring(i2 + 2);
        String name = file.substring(0, file.indexOf("."));
        String[] com = s2.split(" ");
        if (com.length == 3 && com[0].equals("edt")) {
            if (tabs != null)
                tabs.add("tabs-" + com[1]);
            src = s1 + orgDT(com[1], xmlForDt(com[1], com[2]), treeForDt(com[1]), umlForDt(com[1], com[2]), umlForDt(com[1], com[2] + "b"), profileRef(com[1]), tsForDt(com[1]), jsonForDt(com[1], com[2]), ttlForDt(com[1], com[2]), diffForDt(com[1], com[2])) + s3;
        } else if (com.length == 2 && com[0].equals("dt")) {
            if (tabs != null)
                tabs.add("tabs-" + com[1]);
            src = s1 + xmlForDt(com[1], null) + tsForDt(com[1]) + s3;
        } else if (com.length == 2 && com[0].equals("adt")) {
            if (tabs != null)
                tabs.add("tabs-" + com[1]);
            src = s1 + xmlForDt(com[1], null) + tsForDt(com[1]) + s3;
        } else if (com.length == 2 && com[0].equals("dt.constraints"))
            src = s1 + genConstraints(com[1], "") + s3;
        else if (com.length == 2 && com[0].equals("dt.restrictions"))
            src = s1 + genRestrictions(com[1]) + s3;
        else if (com.length == 2 && com[0].equals("dictionary"))
            src = s1 + dictForDt(com[1]) + s3;
        else if (Utilities.existsInList(com[0], "pageheader", "dtheader", "atheader", "mdtheader", "edheader", "mmheader", "drheader", "elheader", "belheader", "extheader", "resourcesheader", "formatsheader", "narrheader", "refheader", "extrasheader", "profilesheader", "txheader", "txheader0", "fmtheader", "igheader", "cmpheader", "atomheader", "dictheader", "ctheader", "adheader", "pdheader", "tdheader", "cdheader", "diheader", "statheader", "ordistheader", "ucheader", "rrheader"))
            src = s1 + s3;
        else if (com[0].equals("resheader"))
            src = s1 + resHeader(name, "Document", com.length > 1 ? com[1] : null) + s3;
        else if (com[0].equals("aresheader"))
            src = s1 + abstractResHeader(name, "Document", com.length > 1 ? com[1] : null) + s3;
        else if (com[0].equals("codelist"))
            src = s1 + codelist((CodeSystem) resource, com.length > 1 ? com[1] : null, false, true, file) + s3;
        else if (com[0].equals("codelist-nh"))
            src = s1 + codelist((CodeSystem) resource, com.length > 1 ? com[1] : null, false, false, file) + s3;
        else if (com[0].equals("linkcodelist"))
            src = s1 + codelist((CodeSystem) resource, com.length > 1 ? com[1] : null, true, false, file) + s3;
        else if (com[0].equals("sct-vs-list"))
            src = s1 + getSnomedCTVsList() + s3;
        else if (com[0].equals("sct-concept-list"))
            src = s1 + getSnomedCTConceptList() + s3;
        else if (com[0].equals("codetoc"))
            src = s1 + codetoc(com.length > 1 ? com[1] : null) + s3;
        else if (com[0].equals("res-category")) {
            src = s1 + resCategory(s2.substring(com[0].length() + 1)) + s3;
            even = false;
        } else if (com[0].equals("res-item")) {
            even = !even;
            src = s1 + resItem(com[1], even) + s3;
        } else if (com[0].equals("resdesc")) {
            src = s1 + resDesc(com[1]) + s3;
        } else if (com[0].equals("rescat")) {
            src = s1 + resCat(com.length == 1 ? null : s2.substring(7)) + s3;
        } else if (com[0].equals("w5"))
            src = s1 + genW5("true".equals(com[1])) + s3;
        else if (com[0].equals("vs-warning"))
            src = s1 + vsWarning((ValueSet) resource) + s3;
        else if (com[0].equals("res-status-special"))
            src = s1 + vsSpecialStatus((DomainResource) resource) + s3;
        else if (com[0].equals("file")) {
            if (new File(folders.templateDir + com[1] + ".html").exists()) {
                src = s1 + TextFile.fileToString(folders.templateDir + com[1] + ".html") + s3;
            } else {
                src = s1 + TextFile.fileToString(folders.srcDir + com[1] + ".html") + s3;
            }
        } else if (com[0].equals("conceptmaplistvs")) {
            throw new Error("Fix this");
        // BindingSpecification bs = definitions.getBindingByName(Utilities.fileTitle(file));
        // String ref;
        // if (bs == null) {
        // ref = "http://hl7.org/fhir/ValueSet/"+Utilities.fileTitle(file);
        // } else {
        // ref = bs.getReference();
        // if (ref.startsWith("valueset-"))
        // ref = ref.substring(9);
        // ref = "http://hl7.org/fhir/ValueSet/"+ref;
        // }
        // src = s1 + conceptmaplist(ref, com[1]) + s3;
        } else if (com[0].equals("dtmappings"))
            src = s1 + genDataTypeMappings(com[1]) + s3;
        else if (com[0].equals("dtusage"))
            src = s1 + genDataTypeUsage(com[1]) + s3;
        else if (com[0].equals("othertabs"))
            src = s1 + genOtherTabs(com[1], tabs) + s3;
        else if (com[0].equals("toc"))
            src = s1 + generateToc() + s3;
        else if (com.length != 1)
            throw new Exception("Instruction <%" + s2 + "%> not understood parsing page " + file);
        else if (com[0].equals("newheader"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newheader.html") + s3;
        else if (com[0].equals("newheader1"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newheader1.html") + s3;
        else if (com[0].equals("footer"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer.html") + s3;
        else if (com[0].equals("newfooter"))
            src = s1 + TextFile.fileToString(folders.srcDir + "newfooter.html") + s3;
        else if (com[0].equals("footer1"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer1.html") + s3;
        else if (com[0].equals("footer2"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer2.html") + s3;
        else if (com[0].equals("footer3"))
            src = s1 + TextFile.fileToString(folders.srcDir + "footer3.html") + s3;
        else if (com[0].equals("title"))
            src = s1 + Utilities.escapeXml(name.toUpperCase().substring(0, 1) + name.substring(1)) + s3;
        else if (com[0].equals("xtitle"))
            src = s1 + Utilities.escapeXml(name.toUpperCase().substring(0, 1) + name.substring(1)) + s3;
        else if (com[0].equals("name"))
            src = s1 + name + s3;
        else if (com[0].equals("version"))
            src = s1 + ini.getStringProperty("FHIR", "version") + s3;
        else if (com[0].equals("gendate"))
            src = s1 + Config.DATE_FORMAT().format(new Date()) + s3;
        else if (com[0].equals("maindiv"))
            src = s1 + s3;
        else if (com[0].equals("/maindiv"))
            src = s1 + s3;
        else if (com[0].equals("enteredInErrorTable"))
            src = s1 + enteredInErrorTable() + s3;
        else if (com[0].equals("events"))
            src = s1 + getEventsTable(file) + s3;
        else if (com[0].equals("resourcecodes"))
            src = s1 + genResCodes() + s3;
        else if (com[0].equals("datatypecodes"))
            src = s1 + genDTCodes() + s3;
        else // src = s1 + genBindingTable(false) + s3;
        if (com[0].equals("codeslist"))
            src = s1 + genCodeSystemsTable() + s3;
        else if (com[0].equals("valuesetslist"))
            src = s1 + genValueSetsTable(ig) + s3;
        else if (com[0].equals("igvaluesetslist"))
            src = s1 + genIGValueSetsTable() + s3;
        else if (com[0].equals("namespacelist"))
            src = s1 + genNSList() + s3;
        else if (com[0].equals("resimplall"))
            src = s1 + genResImplList() + s3;
        else if (com[0].equals("txurl"))
            src = s1 + "http://hl7.org/fhir/" + Utilities.fileTitle(file) + s3;
        else if (com[0].equals("vstxurl"))
            src = s1 + "http://hl7.org/fhir/ValueSet/" + Utilities.fileTitle(file) + s3;
        else if (com[0].equals("csurl")) {
            if (resource instanceof CodeSystem)
                src = s1 + ((CodeSystem) resource).getUrl() + s3;
            else
                src = s1 + ((ValueSet) resource).getUrl() + s3;
        } else if (com[0].equals("vsurl")) {
            if (resource instanceof CodeSystem)
                src = s1 + ((CodeSystem) resource).getUrl() + s3;
            else
                src = s1 + ((ValueSet) resource).getUrl() + s3;
        } else if (com[0].equals("txdef"))
            src = s1 + generateCodeDefinition(Utilities.fileTitle(file)) + s3;
        else if (com[0].equals("vsxref"))
            src = s1 + xreferencesForFhir(name) + s3;
        else if (com[0].equals("vsdef"))
            if (resource instanceof CodeSystem)
                src = s1 + Utilities.escapeXml(((CodeSystem) resource).getDescription()) + s3;
            else
                src = s1 + Utilities.escapeXml(((ValueSet) resource).getDescription()) + s3;
        else if (com[0].equals("txusage"))
            src = s1 + generateValueSetUsage((ValueSet) resource, genlevel(0), true) + s3;
        else if (com[0].equals("vsusage"))
            src = s1 + generateValueSetUsage((ValueSet) resource, genlevel(0), true) + s3;
        else if (com[0].equals("csusage"))
            src = s1 + generateCSUsage((CodeSystem) resource, genlevel(0)) + s3;
        else if (com[0].equals("vssummary"))
            src = s1 + "todo" + s3;
        else if (com[0].equals("piperesources"))
            src = s1 + pipeResources() + s3;
        else if (com[0].equals("pub-type"))
            src = s1 + publicationType + s3;
        else // src = s1 + expandValueSet(Utilities.fileTitle(file), resource == null ? null : (ValueSet) resource) + s3;
        if (com[0].equals("vsexpansionig"))
            src = s1 + expandValueSetIG((ValueSet) resource, true) + s3;
        else if (com[0].equals("pub-notice"))
            src = s1 + publicationNotice + s3;
        else if (com[0].startsWith("!"))
            src = s1 + s3;
        else if (macros.containsKey(com[0])) {
            src = s1 + macros.get(com[0]) + s3;
        } else
            throw new Exception("Instruction <%" + s2 + "%> not understood parsing page " + file);
    }
    return src;
}
Also used : DomainResource(org.hl7.fhir.r5.model.DomainResource) ArrayList(java.util.ArrayList) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Date(java.util.Date) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) CSFile(org.hl7.fhir.utilities.CSFile) TextFile(org.hl7.fhir.utilities.TextFile) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Aggregations

BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)20 ValueSet (org.hl7.fhir.r5.model.ValueSet)13 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)10 ArrayList (java.util.ArrayList)8 TypeRef (org.hl7.fhir.definitions.model.TypeRef)6 FHIRException (org.hl7.fhir.exceptions.FHIRException)6 IOException (java.io.IOException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 CodeType (org.hl7.fhir.r5.model.CodeType)4 FileNotFoundException (java.io.FileNotFoundException)3 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)3 CSFile (org.hl7.fhir.utilities.CSFile)3 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2 TransformerException (javax.xml.transform.TransformerException)2 DefinedCode (org.hl7.fhir.definitions.model.DefinedCode)2 Invariant (org.hl7.fhir.definitions.model.Invariant)2 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)2 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)2