Search in sources :

Example 1 with OperationParameter

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

the class PageProcessor method genOperationInner.

public void genOperationInner(String n, String id, boolean mixed, StandardsStatus resStatus, String prefix, String np, StringBuilder b, Operation op, boolean header) throws Exception {
    if (header)
        b.append("<h3>").append(Utilities.escapeXml(op.getTitle())).append("<a name=\"").append(op.getName()).append("\"> </a></h3>\r\n");
    if (mixed)
        b.append(opStandardsStatusNotice(n, op.getStandardsStatus(), resStatus, np, prefix) + "\r\n");
    b.append(processMarkdown(n, op.getDoco(), prefix, true) + "\r\n");
    b.append("<p>The official URL for this operation definition is</p>\r\n<pre> http://hl7.org/fhir/OperationDefinition/" + n + "-" + op.getName() + "</pre>\r\n");
    b.append("<p><a href=\"operation-" + id + "-" + op.getName().toLowerCase() + ".html\">Formal Definition</a> (as a <a href=\"" + prefix + "operationdefinition.html\">OperationDefinition</a>).</p>\r\n");
    if (op.isSystem())
        b.append("<p>URL: [base]/$").append(op.getName()).append("</p>\r\n");
    if (op.isType())
        b.append("<p>URL: [base]/").append(checkWrap(n)).append("/$").append(op.getName()).append("</p>\r\n");
    if (op.isInstance())
        b.append("<p>URL: [base]/").append(checkWrap(n)).append("/[id]/$").append(op.getName()).append("</p>\r\n");
    if (op.getIdempotent())
        b.append("<p>This is an idempotent operation</p>\r\n");
    else
        b.append("<p>This is <b>not</b> an idempotent operation</p>\r\n");
    if (!op.getParameters().isEmpty()) {
        b.append("<table class=\"grid\">\r\n");
        if (hasParameters(op.getParameters(), "In")) {
            genParameterHeader(b, "In");
            for (OperationParameter p : op.getParameters()) genOperationParameter(n, "In", "", b, op, p, prefix);
        }
        if (hasParameters(op.getParameters(), "Out")) {
            genParameterHeader(b, "Out");
            for (OperationParameter p : op.getParameters()) genOperationParameter(n, "Out", "", b, op, p, prefix);
        }
        b.append("</table>\r\n");
    }
    b.append(processMarkdown(n, op.getFooter(), prefix)).append("\r\n");
    if (op.getExamples().size() > 0) {
        b.append("<a name=\"examples\"> </a>\r\n<h4>Examples</h4>\r\n");
        boolean needsHr = false;
        boolean hasHr = false;
        for (OperationExample ex : op.getExamples()) if (!ex.isResponse()) {
            needsHr = true;
            renderExample(b, ex, "Request");
        }
        for (OperationExample ex : op.getExamples()) if (ex.isResponse()) {
            if (needsHr && !hasHr) {
                hasHr = true;
                b.append("<hr/>\r\n");
            }
            renderExample(b, ex, "Response");
        }
    }
    if (!Utilities.noString(op.getFooter2())) {
        b.append(processMarkdown(n, op.getFooter2(), prefix)).append("\r\n");
        boolean needsHr = false;
        boolean hasHr = false;
        if (op.getExamples2().size() > 0) {
            for (OperationExample ex : op.getExamples2()) if (!ex.isResponse()) {
                needsHr = true;
                renderExample(b, ex, "Request");
            }
            for (OperationExample ex : op.getExamples2()) if (ex.isResponse()) {
                if (needsHr && !hasHr) {
                    hasHr = true;
                    b.append("<hr/>\r\n");
                }
                renderExample(b, ex, "Response");
            }
        }
    }
    b.append("<p>&nbsp;</p>");
}
Also used : OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) OperationParameter(org.hl7.fhir.definitions.model.OperationParameter)

Example 2 with OperationParameter

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

the class PageProcessor method buildShortParameterList.

private String buildShortParameterList(String param) throws Exception {
    String[] p1 = param.split("\\:");
    String[] op = p1[0].split("\\/");
    String[] p = p1[1].split("\\,");
    ResourceDefn rd = definitions.getResourceByName(op[0]);
    Operation od = rd.getOperationByName(op[1].substring(1));
    StringBuilder b = new StringBuilder();
    b.append("<table class=\"grid\">\r\n");
    for (OperationParameter pd : od.getParameters()) {
        if (Utilities.existsInList(pd.getName(), p))
            b.append("<tr><td><code>" + pd.getName() + "</code></td><td>" + processMarkdown("short param list", pd.getDoc(), "") + "</td></tr>\r\n");
    }
    b.append("</table>\r\n");
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) OperationParameter(org.hl7.fhir.definitions.model.OperationParameter) Operation(org.hl7.fhir.definitions.model.Operation) ResourceDefn(org.hl7.fhir.definitions.model.ResourceDefn)

Example 3 with OperationParameter

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

the class OldSpreadsheetParser method readOperations.

private void readOperations(List<Operation> oplist, Sheet sheet) throws Exception {
    Map<String, Operation> ops = new HashMap<String, Operation>();
    Map<String, OperationParameter> params = new HashMap<String, OperationParameter>();
    if (sheet != null) {
        for (int row = 0; row < sheet.rows.size(); row++) {
            String name = sheet.getColumn(row, "Name");
            String use = sheet.getColumn(row, "Use");
            String doco = sheet.getColumn(row, "Documentation");
            String type = sheet.getColumn(row, "Type");
            List<OperationExample> examples = loadOperationExamples(sheet.getColumn(row, "Example.Request"), sheet.getColumn(row, "Example.Response"));
            List<OperationExample> examples2 = loadOperationExamples(sheet.getColumn(row, "Example2.Request"), sheet.getColumn(row, "Example2.Response"));
            if (name != null && !name.equals("") && !name.startsWith("!")) {
                if (!name.contains(".")) {
                    if (!type.equals("operation"))
                        throw new Exception("Invalid type on operation " + type + " at " + getLocation(row));
                    if (!name.toLowerCase().equals(name))
                        throw new Exception("Invalid name on operation " + name + " - must be all lower case (use dashes) at " + getLocation(row));
                    params.clear();
                    boolean system = false;
                    boolean istype = false;
                    boolean instance = false;
                    for (String c : use.split("\\|")) {
                        c = c.trim();
                        if ("system".equalsIgnoreCase(c))
                            system = true;
                        else if ("resource".equalsIgnoreCase(c))
                            istype = true;
                        else if ("instance".equalsIgnoreCase(c))
                            instance = true;
                        else
                            throw new Exception("unknown operation use code " + c + " at " + getLocation(row));
                    }
                    Operation op = new Operation(name, system, istype, instance, sheet.getColumn(row, "Type"), sheet.getColumn(row, "Title"), doco, sheet.getColumn(row, "Footer"), examples, parseBoolean(sheet.getColumn(row, "Idempotent"), row, false));
                    op.setStandardsStatus(StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status")));
                    op.setNormativeVersion(sheet.getColumn(row, "Normative-Version"));
                    op.setFooter2(sheet.getColumn(row, "Footer2"));
                    op.setFmm(sheet.getColumn(row, "fmm"));
                    op.getExamples2().addAll(examples2);
                    oplist.add(op);
                    ops.put(name, op);
                } else {
                    String context = name.substring(0, name.lastIndexOf('.'));
                    String pname = name.substring(name.lastIndexOf('.') + 1);
                    Operation operation;
                    List<OperationParameter> plist;
                    if (context.contains(".")) {
                        String opname = name.substring(0, name.indexOf('.'));
                        // inside of a tuple
                        if (!Utilities.noString(use))
                            throw new Exception("Tuple parameters: use must be blank at " + getLocation(row));
                        operation = ops.get(opname);
                        if (operation == null)
                            throw new Exception("Unknown Operation '" + opname + "' at " + getLocation(row));
                        OperationParameter param = params.get(context);
                        if (param == null)
                            throw new Exception("Tuple parameter '" + context + "' not found at " + getLocation(row));
                        if (!param.getFhirType().equals("Tuple"))
                            throw new Exception("Tuple parameter '" + context + "' type must be Tuple at " + getLocation(row));
                        plist = param.getParts();
                    } else {
                        if (!use.equals("in") && !use.equals("out"))
                            throw new Exception("Only allowed use is 'in' or 'out' at " + getLocation(row));
                        operation = ops.get(context);
                        if (operation == null)
                            throw new Exception("Unknown Operation '" + context + "' at " + getLocation(row));
                        plist = operation.getParameters();
                    }
                    String profile = sheet.getColumn(row, "Profile");
                    String min = sheet.getColumn(row, "Min");
                    String max = sheet.getColumn(row, "Max");
                    OperationParameter p = new OperationParameter(pname, use, doco, Integer.parseInt(min), max, type, sheet.getColumn(row, "Search Type"), profile);
                    String bs = sheet.getColumn(row, "Binding");
                    if (!Utilities.noString(bs))
                        p.setBs(bindings.get(bs));
                    plist.add(p);
                    params.put(name, p);
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) OperationParameter(org.hl7.fhir.definitions.model.OperationParameter) Operation(org.hl7.fhir.definitions.model.Operation) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 4 with OperationParameter

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

the class ResourceParser method convertOperationParameter.

public OperationParameter convertOperationParameter(OperationDefinitionParameterComponent psrc, boolean part) throws IOException {
    List<String> pl = new ArrayList<>();
    for (CanonicalType u : psrc.getTargetProfile()) {
        pl.add(u.asStringValue().replace("http://hl7.org/fhir/StructureDefinition/", ""));
    }
    String t;
    if (psrc.hasExtension(BuildExtensions.EXT_ALLOWED_TYPE)) {
        for (Extension e : psrc.getExtensionsByUrl(BuildExtensions.EXT_ALLOWED_TYPE)) {
            pl.add(e.getValue().primitiveValue());
        }
        t = String.join(" | ", pl);
    } else if (psrc.hasType()) {
        t = psrc.getType().toCode();
        if (pl.size() > 0) {
            t = t + "(" + String.join("|", pl) + ")";
        }
    } else {
        t = "Tuple";
    }
    OperationParameter p = new OperationParameter(psrc.getName(), part ? null : psrc.getUse().toCode(), psrc.getDocumentation(), psrc.getMin(), psrc.getMax(), t, psrc.hasSearchType() ? psrc.getSearchType().toCode() : null, null);
    if (psrc.hasBinding()) {
        p.setBs(parseBinding(psrc.getBinding()));
    }
    for (OperationDefinitionParameterComponent pc : psrc.getPart()) {
        p.getParts().add(convertOperationParameter(pc, true));
    }
    return p;
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) OperationParameter(org.hl7.fhir.definitions.model.OperationParameter) ArrayList(java.util.ArrayList) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) OperationDefinitionParameterComponent(org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterComponent)

Example 5 with OperationParameter

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

the class ProfileGenerator method produceOpParam.

private void produceOpParam(String path, List<OperationDefinitionParameterComponent> opd, OperationParameter p, OperationParameterUse defUse) throws Exception {
    OperationDefinitionParameterComponent pp = new OperationDefinitionParameterComponent();
    pp.setName(p.getName());
    if (path.contains("."))
        pp.setUse(defUse);
    else if (p.getUse().equals("in"))
        pp.setUse(OperationParameterUse.IN);
    else if (p.getUse().equals("out"))
        pp.setUse(OperationParameterUse.OUT);
    else
        // but this is validated elsewhere
        throw new Exception("Unable to determine parameter use: " + p.getUse() + " at " + path + "." + p.getName());
    pp.setDocumentation(preProcessMarkdown(p.getDoc(), "Operation Parameter Doco"));
    pp.setMin(p.getMin());
    pp.setMax(p.getMax());
    if (p.getBs() != null) {
        if (p.getBs().hasMax())
            throw new Error("Max binding not handled yet");
        pp.setBinding(new OperationDefinitionParameterBindingComponent().setStrength(p.getBs().getStrength()).setValueSet(buildValueSetReference(p.getBs())));
        if (!Utilities.noString(p.getBinding().getName())) {
            pp.getBinding().addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName", new StringType(p.getBinding().getName()));
        }
    }
    if (!Utilities.noString(p.getProfile())) {
        pp.addTargetProfile(p.getProfile());
    }
    opd.add(pp);
    if (p.getFhirType().equals("Tuple")) {
        for (OperationParameter part : p.getParts()) {
            produceOpParam(path + "." + p.getName(), pp.getPart(), part, pp.getUse());
        }
    } else {
        List<TypeRef> trs = new TypeParser(version.toCode()).parse(p.getFhirType(), false, null, null, false);
        if (trs.size() > 1) {
            if (p.getSearchType() != null)
                pp.setSearchType(SearchParamType.fromCode(p.getSearchType()));
            pp.setType(Enumerations.FHIRAllTypes.fromCode("Element"));
            for (TypeRef tr : trs) {
                pp.addExtension(ToolingExtensions.EXT_ALLOWED_TYPE, new UriType(tr.getName()));
                if (tr.getParams().size() > 0)
                    throw new Error("Multiple types for an operation parameter, where one is a reference, is not supported by the build tools");
            }
        } else {
            TypeRef tr = trs.get(0);
            if (definitions.getConstraints().containsKey(tr.getName())) {
                ProfiledType pt = definitions.getConstraints().get(tr.getName());
                pp.setType(Enumerations.FHIRAllTypes.fromCode(pt.getBaseType().equals("*") ? "Type" : pt.getBaseType()));
                pp.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + pt.getName());
            } else {
                if (p.getSearchType() != null)
                    pp.setSearchType(SearchParamType.fromCode(p.getSearchType()));
                pp.setType(Enumerations.FHIRAllTypes.fromCode(tr.getName().equals("*") ? "Type" : tr.getName()));
                if (tr.getParams().size() == 1 && !tr.getParams().get(0).equals("Any"))
                    pp.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + tr.getParams().get(0));
            }
        }
    }
}
Also used : TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) StringType(org.hl7.fhir.r5.model.StringType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) OperationDefinitionParameterBindingComponent(org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent) OperationParameter(org.hl7.fhir.definitions.model.OperationParameter) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) OperationDefinitionParameterComponent(org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterComponent) UriType(org.hl7.fhir.r5.model.UriType)

Aggregations

OperationParameter (org.hl7.fhir.definitions.model.OperationParameter)7 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)3 URISyntaxException (java.net.URISyntaxException)2 Operation (org.hl7.fhir.definitions.model.Operation)2 OperationExample (org.hl7.fhir.definitions.model.Operation.OperationExample)2 OperationDefinitionParameterComponent (org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterComponent)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TransformerFactoryConfigurationError (javax.xml.transform.TransformerFactoryConfigurationError)1 ProfiledType (org.hl7.fhir.definitions.model.ProfiledType)1 ResourceDefn (org.hl7.fhir.definitions.model.ResourceDefn)1 TypeRef (org.hl7.fhir.definitions.model.TypeRef)1 TypeParser (org.hl7.fhir.definitions.parsers.TypeParser)1 CanonicalType (org.hl7.fhir.r5.model.CanonicalType)1 Extension (org.hl7.fhir.r5.model.Extension)1 OperationDefinition (org.hl7.fhir.r5.model.OperationDefinition)1 OperationDefinitionParameterBindingComponent (org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterBindingComponent)1 StringType (org.hl7.fhir.r5.model.StringType)1 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)1