Search in sources :

Example 46 with TypeRef

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

the class PageProcessor method ttlForDt.

private String ttlForDt(String dt, String pn) throws Exception {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    TurtleSpecGenerator gen = new TurtleSpecGenerator(b, pn == null ? null : pn.substring(0, pn.indexOf(".")) + "-definitions.html", null, this, "", version.toCode());
    TypeParser tp = new TypeParser(version.toCode());
    TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
    ElementDefn e = definitions.getElementDefn(t.getName());
    if (e == null) {
        gen.close();
        throw new Exception("unable to find definition for " + dt);
    } else {
        gen.generate(e, false);
        gen.close();
    }
    String val = new String(b.toByteArray()) + "\r\n";
    return val;
}
Also used : ITypeParser(org.hl7.fhir.r5.renderers.utils.RenderingContext.ITypeParser) TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) TypeRef(org.hl7.fhir.definitions.model.TypeRef) TurtleSpecGenerator(org.hl7.fhir.definitions.generators.specification.TurtleSpecGenerator) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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)

Example 47 with TypeRef

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

the class PageProcessor method jsonForDt.

private String jsonForDt(String dt, String pn) throws Exception {
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    JsonSpecGenerator gen = new JsonSpecGenerator(b, pn == null ? null : pn.substring(0, pn.indexOf(".")) + "-definitions.html", null, this, "", version.toCode());
    TypeParser tp = new TypeParser(version.toCode());
    TypeRef t = tp.parse(dt, false, null, workerContext, true).get(0);
    ElementDefn e = definitions.getElementDefn(t.getName());
    if (e == null) {
        gen.close();
        throw new Exception("unable to find definition for " + dt);
    } else {
        gen.generate(e, false, false);
        gen.close();
    }
    String val = new String(b.toByteArray()) + "\r\n";
    return val;
}
Also used : JsonSpecGenerator(org.hl7.fhir.definitions.generators.specification.JsonSpecGenerator) ITypeParser(org.hl7.fhir.r5.renderers.utils.RenderingContext.ITypeParser) TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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)

Example 48 with TypeRef

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

the class PageProcessor method buildCircularReferenceList.

private void buildCircularReferenceList(StringBuilder b, String s, ElementDefn t, ResourceDefn rd, Boolean hierarchy) {
    if (t.getHierarchy() == hierarchy)
        for (TypeRef tr : t.getTypes()) {
            if (tr.getName().equals("Reference") || tr.getName().equals("canonical"))
                for (String p : tr.getParams()) {
                    if (s.equals(p)) {
                        b.append("<li><a href=\"" + s.toLowerCase() + "-definitions.html#" + t.getPath() + "\">");
                        b.append(t.getPath());
                        b.append("</a>");
                        boolean first = true;
                        for (String spn : sorted(rd.getSearchParams().keySet())) {
                            SearchParameterDefn sp = rd.getSearchParams().get(spn);
                            if (pointsAtElement(sp, t)) {
                                if (first) {
                                    b.append(" (");
                                    first = false;
                                } else
                                    b.append(",");
                                b.append(sp.getCode());
                            }
                        }
                        if (!first)
                            b.append(")");
                        b.append("</li>");
                    }
                }
        }
    for (ElementDefn e : t.getElements()) buildCircularReferenceList(b, s, e, rd, hierarchy);
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn)

Example 49 with TypeRef

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

the class OldSpreadsheetParser method processExtension.

private int processExtension(ElementDefn extensions, Sheet sheet, int row, Definitions definitions, String uri, Profile ap, List<ValidationMessage> issues, Map<String, Invariant> invariants, WorkGroup wg) throws Exception {
    // first, we build the extension definition
    StructureDefinition ex = new StructureDefinition();
    ex.setUserData(ToolResourceUtilities.NAME_RES_IG, ig == null ? "core" : ig.getCode());
    ex.setUserData("profile", ap);
    ex.setKind(StructureDefinitionKind.COMPLEXTYPE);
    ex.setType("Extension");
    ex.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/Extension");
    ex.setDerivation(TypeDerivationRule.CONSTRAINT);
    ex.setAbstract(false);
    ex.setFhirVersion(version);
    ex.setVersion(version.toCode());
    if (wg != null)
        ToolingExtensions.setCodeExtension(ex, ToolingExtensions.EXT_WORKGROUP, wg.getCode());
    String fmm = sheet.getColumn(row, "FMM");
    if (Utilities.noString(fmm))
        // default fmm value for extensions
        fmm = "1";
    ToolingExtensions.addIntegerExtension(ex, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(fmm));
    if (ap.hasMetadata("fmm-level"))
        ToolingExtensions.addIntegerExtension(ex, ToolingExtensions.EXT_FMM_LEVEL, Integer.parseInt(ap.getFmmLevel()));
    if (ap.hasMetadata("workgroup"))
        ToolingExtensions.setCodeExtension(ex, ToolingExtensions.EXT_WORKGROUP, ap.getWg());
    ToolResourceUtilities.updateUsage(ex, ap.getCategory());
    String name = sheet.getColumn(row, "Code");
    String context = null;
    if (Utilities.noString(name))
        throw new Exception("No code found on Extension at " + getLocation(row));
    if (name.contains("."))
        throw new Exception("Extension Definition Error: Extension names cannot contain '.': " + name + "  at " + getLocation(row));
    ex.setUrl(uri + name);
    ex.setId(tail(ex.getUrl()));
    ex.setUserData("path", "extension-" + ex.getId().toLowerCase() + ".html");
    ap.getExtensions().add(ex);
    if (context == null) {
        ExtensionContextType ct = readContextType(sheet.getColumn(row, "Context Type"), row);
        if (sheet.hasColumn("Context Invariant"))
            for (String s : sheet.getColumn(row, "Context Invariant").split("~")) ex.addContextInvariant(s);
        String cc = checkContextMacro(sheet.getColumn(row, "Context"));
        if (!Utilities.noString(cc))
            for (String c : cc.split("\\;")) {
                StructureDefinitionContextComponent ec = ex.addContext();
                ec.setExpression(c.trim());
                ec.setType(ct);
                if (definitions != null) {
                    definitions.checkContextValid(ec, this.name, this.context);
                }
            }
    }
    ex.setTitle(sheet.getColumn(row, "Display"));
    ElementDefn exe = new ElementDefn();
    exe.setName(sheet.getColumn(row, "Code"));
    ElementDefn exu = new ElementDefn();
    exu.setName("url");
    exu.setXmlAttribute(true);
    exe.getElements().add(exu);
    exu.setFixed(new UriType(ex.getUrl()));
    exu.getTypes().add(new TypeRef().setName("uri"));
    if (invariants != null) {
        for (Invariant inv : invariants.values()) {
            if (inv.getContext().equals(name))
                exe.getInvariants().put(inv.getId(), inv);
        }
    }
    parseExtensionElement(sheet, row, definitions, exe, false);
    String sl = exe.getShortDefn();
    ex.setName(sheet.getColumn(row, "Name"));
    if (!ex.hasName())
        ex.setName(exe.getName());
    if (!ex.hasName())
        ex.setName(ex.getTitle());
    if (!ex.hasName() && !Utilities.noString(sl))
        ex.setName(sl);
    if (!ex.hasName())
        throw new Exception("Extension " + ex.getUrl() + " missing name at " + getLocation(row));
    ex.setDescription(preProcessMarkdown(exe.getDefinition(), "Extension Definition"));
    ex.setPublisher(ap.metadata("author.name"));
    if (ap.hasMetadata("author.reference"))
        ex.addContact().getTelecom().add(Factory.newContactPoint(ContactPointSystem.URL, ap.metadata("author.reference")));
    // <code> opt Zero+ Coding assist with indexing and finding</code>
    if (ap.hasMetadata("date"))
        ex.setDateElement(Factory.newDateTime(ap.metadata("date").substring(0, 10)));
    else
        ex.setDate(genDate.getTime());
    if (ap.hasMetadata("status"))
        ex.setStatus(PublicationStatus.fromCode(ap.metadata("status")));
    row++;
    if (ig == null || ig.isCore()) {
        if (!ex.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/") && !ex.getUrl().startsWith("http://fhir-registry.smarthealthit.org/StructureDefinition/"))
            throw new Exception("extension " + ex.getUrl() + " is not valid in the publication tooling");
    } else {
        if (!ex.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/" + ig.getCode() + "-"))
            throw new Exception("extension " + ex.getUrl() + " is not valid for the IG " + ig.getCode() + " in the publication tooling");
    }
    while (row < sheet.getRows().size() && sheet.getColumn(row, "Code").startsWith(name + ".")) {
        String n = sheet.getColumn(row, "Code");
        ElementDefn p = findContext(exe, n.substring(0, n.lastIndexOf(".")), "Extension Definition " + name);
        ElementDefn child = new ElementDefn();
        p.getElements().add(child);
        child.setName(n.substring(n.lastIndexOf(".") + 1));
        child.setProfileName(child.getName());
        parseExtensionElement(sheet, row, definitions, child, true);
        if (invariants != null) {
            for (Invariant inv : invariants.values()) {
                if (inv.getContext().equals(n))
                    child.getInvariants().put(inv.getId(), inv);
            }
        }
        row++;
    }
    ProfileGenerator gen = new ProfileGenerator(definitions, null, pkp, null, version, null, fpUsages, null, null, rc);
    ProfileUtilities utils = new ProfileUtilities(this.context, issues, pkp);
    gen.convertElements(exe, ex, null);
    ex.getDifferential().getElementFirstRep().getType().clear();
    utils.setIds(ex, false);
    StructureDefinition base = definitions != null ? definitions.getSnapShotForType("Extension") : this.context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Extension");
    List<String> errors = new ArrayList<String>();
    utils.sortDifferential(base, ex, "extension " + ex.getUrl(), errors, false);
    assert (errors.size() == 0);
    utils.generateSnapshot(base, ex, ex.getUrl(), "http://hl7.org/fhir", ex.getName());
    utils.setIds(ex, true);
    new ExtensionDefinitionValidator(context).validate(ex);
    this.context.cacheResource(ex);
    return row;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) ProfileGenerator(org.hl7.fhir.definitions.generators.specification.ProfileGenerator) StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException) UriType(org.hl7.fhir.r5.model.UriType) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ExtensionContextType(org.hl7.fhir.r5.model.StructureDefinition.ExtensionContextType) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) ExtensionDefinitionValidator(org.hl7.fhir.definitions.validation.ExtensionDefinitionValidator)

Example 50 with TypeRef

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

the class OldSpreadsheetParser method parseExtensionElement.

private void parseExtensionElement(Sheet sheet, int row, Definitions definitions, ElementDefn exe, boolean nested) throws Exception {
    // things that go on Extension
    String[] card = sheet.getColumn(row, "Card.").split("\\.\\.");
    if (card.length != 2 || !Utilities.isInteger(card[0]) || (!"*".equals(card[1]) && !Utilities.isInteger(card[1])))
        throw new Exception("Unable to parse Cardinality " + sheet.getColumn(row, "Card.") + " in " + getLocation(row));
    exe.setMinCardinality(Integer.parseInt(card[0]));
    exe.setMaxCardinality("*".equals(card[1]) ? Integer.MAX_VALUE : Integer.parseInt(card[1]));
    exe.setDefinition(Utilities.appendPeriod(processDefinition(sheet.getColumn(row, "Definition"))));
    exe.setRequirements(Utilities.appendPeriod(sheet.getColumn(row, "Requirements")));
    exe.setComments(Utilities.appendPeriod(sheet.getColumn(row, "Comments")));
    doAliases(sheet, row, exe);
    for (String n : mappings.keySet()) {
        exe.addMapping(n, sheet.getColumn(row, mappings.get(n).getColumnName()).trim());
    }
    exe.setTodo(Utilities.appendPeriod(sheet.getColumn(row, "To Do")));
    exe.setCommitteeNotes(Utilities.appendPeriod(sheet.getColumn(row, "Committee Notes")));
    exe.setShortDefn(sheet.getColumn(row, "Short Name"));
    exe.setIsModifier(parseBoolean(sheet.getColumn(row, "Is Modifier"), row, null));
    if (exe.isModifier()) {
        String reason = sheet.getColumn(row, "Modifier Reason");
        if (Utilities.noString(reason)) {
            System.out.println("Missing IsModifierReason on extension @ " + getLocation(row));
            reason = "Not known why this is labelled a modifier";
        }
        exe.setModifierReason(reason);
    }
    if (nested && exe.isModifier())
        throw new Exception("Cannot create a nested extension that is a modifier @" + getLocation(row));
    exe.getTypes().add(new TypeRef().setName("Extension"));
    // things that go on Extension.value
    if (!Utilities.noString(sheet.getColumn(row, "Type"))) {
        ElementDefn exv = new ElementDefn();
        exv.setName("value[x]");
        exv.getTypes().addAll(new TypeParser(version.toCode()).parse(sheet.getColumn(row, "Type"), true, profileExtensionBase, context, false, sheet.title));
        /*      if (!exv.getName().equals("value[x]")) {
        ElementDefn exd = new ElementDefn();
        exd.setName("value[x]");
        exd.setMaxCardinality(1);
        exd.getTypes().add(new TypeRef(exv.getTypes().get(0).getName()));
        List<String> discriminator = new ArrayList<String>();
        discriminator.add("@type");
        exd.setDiscriminator(discriminator);
        exe.getElements().add(exd);
        exv.setProfileName("value");
      }*/
        exe.getElements().add(exv);
        String bindingName = sheet.getColumn(row, "Binding");
        if (!Utilities.noString(bindingName)) {
            BindingSpecification binding = bindings.get(bindingName);
            if (binding == null && definitions != null)
                binding = definitions.getCommonBindings().get(bindingName);
            if (binding == null) {
                if (bindingName.startsWith("!"))
                    exv.setNoBindingAllowed(true);
                else
                    throw new Exception("Binding name " + bindingName + " could not be resolved in local spreadsheet");
            }
            exv.setBinding(binding);
            if (binding != null && !binding.getUseContexts().contains(name))
                binding.getUseContexts().add(name);
        }
        // exv.setBinding();
        exv.setMaxLength(sheet.getColumn(row, "Max Length"));
        exv.setExample(processValue(sheet, row, "Example", sheet.getColumn(row, "Example"), exv));
    }
}
Also used : TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

TypeRef (org.hl7.fhir.definitions.model.TypeRef)51 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)26 ArrayList (java.util.ArrayList)18 FHIRException (org.hl7.fhir.exceptions.FHIRException)13 IOException (java.io.IOException)10 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)9 URISyntaxException (java.net.URISyntaxException)8 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)8 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)7 File (java.io.File)6 FileNotFoundException (java.io.FileNotFoundException)6 Invariant (org.hl7.fhir.definitions.model.Invariant)6 CSFile (org.hl7.fhir.utilities.CSFile)6 IniFile (org.hl7.fhir.utilities.IniFile)6 TextFile (org.hl7.fhir.utilities.TextFile)6 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 TransformerException (javax.xml.transform.TransformerException)5 NotImplementedException (org.apache.commons.lang3.NotImplementedException)5 UcumException (org.fhir.ucum.UcumException)5 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5