use of org.hl7.fhir.definitions.model.Operation.OperationExample in project kindling by HL7.
the class PageProcessor method renderExample.
private void renderExample(StringBuilder b, OperationExample ex, String type) throws Exception {
if (Utilities.noString(ex.getComment()))
b.append("<p>" + type + ":</p>\r\n");
else
b.append("<p>" + processMarkdown("op-example", type + ": " + Utilities.capitalize(ex.getComment()), "") + "</p>\r\n");
b.append("<pre>\r\n");
String[] lines = ex.getContent().split("\\r\\n");
for (String l : lines) {
if (l.startsWith("$bundle ")) {
b.append(Utilities.escapeXml("<Bundle xml=\"http://hl7.org/fhir\">\r\n"));
b.append(Utilities.escapeXml(" <id value=\"" + UUID.randomUUID().toString().toLowerCase() + "\"/>\r\n"));
b.append(Utilities.escapeXml(" <type value=\"searchset\"/>\r\n"));
Example e = getExampleByRef(l.substring(8));
addExample(b, e);
for (Example x : e.getInbounds()) {
addExample(b, x);
}
b.append(Utilities.escapeXml("</Bundle>\r\n"));
} else {
b.append(l);
b.append("\r\n");
}
}
b.append("</pre>\r\n");
}
use of org.hl7.fhir.definitions.model.Operation.OperationExample 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> </p>");
}
use of org.hl7.fhir.definitions.model.Operation.OperationExample in project kindling by HL7.
the class PageProcessor method buildOpReferenceList.
private String buildOpReferenceList(String rt) {
StringBuilder b = new StringBuilder();
b.append("<ul>\r\n");
for (String rn : definitions.sortedResourceNames()) {
ResourceDefn rd = definitions.getResources().get(rn);
for (Operation op : rd.getOperations()) {
boolean ok = false;
for (OperationExample ex : op.getExamples()) {
if (ex.getContent().contains("<" + rt) || ex.getContent().contains("\"" + rt + "\""))
ok = true;
}
for (OperationExample ex : op.getExamples2()) {
if (ex.getContent().contains("<" + rt) || ex.getContent().contains("\"" + rt + "\""))
ok = true;
}
if (ok) {
b.append(" <li><a href=\"" + rn.toLowerCase() + "-operation-" + op.getName().toLowerCase() + ".html#examples\">" + rn + "/$" + op.getName() + "</a></li>\r\n");
}
}
}
b.append("</ul>\r\n");
return b.toString();
}
use of org.hl7.fhir.definitions.model.Operation.OperationExample 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);
}
}
}
}
}
use of org.hl7.fhir.definitions.model.Operation.OperationExample in project kindling by HL7.
the class Regenerator method generateOperation.
private void generateOperation(String root, ResourceDefn r, Operation op) throws IOException {
OperationDefinition opd = op.getResource().copy();
opd.setId(r.getName() + "-" + op.getName());
opd.setUrl("http://hl7.org/fhir/build/OperationDefinition/" + opd.getId());
if (!Utilities.noString(op.getFooter())) {
opd.addExtension(BuildExtensions.EXT_FOOTER, new MarkdownType(op.getFooter()));
}
if (!Utilities.noString(op.getFooter2())) {
opd.addExtension(BuildExtensions.EXT_FOOTER2, new MarkdownType(op.getFooter2()));
}
for (OperationExample opex : op.getExamples()) {
Extension ex = new Extension(BuildExtensions.EXT_OP_EXAMPLE);
if (!Utilities.noString(opex.getContent())) {
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_CONTENT, new StringType(opex.getContent()));
}
if (!Utilities.noString(opex.getComment())) {
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_COMMENT, new StringType(opex.getComment()));
}
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_RESPONSE, new BooleanType(opex.isResponse()));
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_LIST, new IntegerType(1));
opd.addExtension(ex);
}
for (OperationExample opex : op.getExamples2()) {
Extension ex = new Extension(BuildExtensions.EXT_OP_EXAMPLE);
if (!Utilities.noString(opex.getContent())) {
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_CONTENT, new StringType(opex.getContent()));
}
if (!Utilities.noString(opex.getComment())) {
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_COMMENT, new StringType(opex.getComment()));
}
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_RESPONSE, new BooleanType(opex.isResponse()));
ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_LIST, new IntegerType(2));
opd.addExtension(ex);
}
File fn = new File(Utilities.path(root, opd.fhirType().toLowerCase() + "-" + opd.getId() + ".gen.xml"));
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), opd);
fn.setLastModified(r.getTimestamp());
}
Aggregations