use of org.hl7.cql_annotations.r1.Tag in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method renderResponse.
private void renderResponse(XhtmlNode root, BundleEntryResponseComponent response) {
root.para().addText("Request:");
StringBuilder b = new StringBuilder();
b.append(response.getStatus() + "\r\n");
if (response.hasLocation())
b.append("Location: " + response.getLocation() + "\r\n");
if (response.hasEtag())
b.append("E-Tag: " + response.getEtag() + "\r\n");
if (response.hasLastModified())
b.append("LastModified: " + response.getEtag() + "\r\n");
root.pre().addText(b.toString());
}
use of org.hl7.cql_annotations.r1.Tag in project org.hl7.fhir.core by hapifhir.
the class Turtle method parseComplex.
private TTLComplex parseComplex(Lexer lexer) throws FHIRFormatError {
TTLComplex result = new TTLComplex(lexer.startLine, lexer.startCol);
boolean done = lexer.peek(LexerTokenType.TOKEN, "]");
while (!done) {
String uri = null;
if (lexer.peekType() == LexerTokenType.URI)
uri = lexer.uri();
else {
String t = lexer.peekType() == LexerTokenType.WORD ? lexer.word() : null;
if (lexer.type == LexerTokenType.TOKEN && lexer.token.equals(":")) {
lexer.token(":");
if (!prefixes.containsKey(t))
throw new FHIRFormatError("unknown prefix " + t);
uri = prefixes.get(t) + lexer.word();
} else if (t.equals("a"))
uri = prefixes.get("rdfs") + "type";
else
throw lexer.error("unexpected token");
}
boolean inlist = false;
if (lexer.peek(LexerTokenType.TOKEN, "(")) {
inlist = true;
lexer.token("(");
}
boolean rpt = false;
do {
if (lexer.peek(LexerTokenType.TOKEN, "[")) {
lexer.token("[");
result.addPredicate(uri, parseComplex(lexer));
lexer.token("]");
} else if (lexer.peekType() == LexerTokenType.URI) {
TTLURL u = new TTLURL(lexer.startLine, lexer.startCol);
u.setUri(lexer.uri());
result.addPredicate(uri, u);
} else if (lexer.peekType() == LexerTokenType.LITERAL) {
TTLLiteral u = new TTLLiteral(lexer.startLine, lexer.startCol);
u.value = lexer.literal();
if (lexer.peek(LexerTokenType.TOKEN, "^")) {
lexer.token("^");
lexer.token("^");
if (lexer.peekType() == LexerTokenType.URI) {
u.type = lexer.uri();
} else {
String l = lexer.word();
lexer.token(":");
u.type = prefixes.get(l) + lexer.word();
}
}
if (lexer.peek(LexerTokenType.TOKEN, "@")) {
// lang tag - skip it
lexer.token("@");
String lang = lexer.word();
if (!lang.matches(LANG_REGEX)) {
throw new FHIRFormatError("Invalid Language tag " + lang);
}
}
result.addPredicate(uri, u);
} else if (lexer.peekType() == LexerTokenType.WORD || lexer.peek(LexerTokenType.TOKEN, ":")) {
int sl = lexer.startLine;
int sc = lexer.startCol;
String pfx = lexer.peekType() == LexerTokenType.WORD ? lexer.word() : null;
if (Utilities.isDecimal(pfx, true) && !lexer.peek(LexerTokenType.TOKEN, ":")) {
TTLLiteral u = new TTLLiteral(sl, sc);
u.value = pfx;
result.addPredicate(uri, u);
} else if (("false".equals(pfx) || "true".equals(pfx)) && !lexer.peek(LexerTokenType.TOKEN, ":")) {
TTLLiteral u = new TTLLiteral(sl, sc);
u.value = pfx;
result.addPredicate(uri, u);
} else {
if (!prefixes.containsKey(pfx))
throw new FHIRFormatError("Unknown prefix " + (pfx == null ? "''" : pfx));
TTLURL u = new TTLURL(sl, sc);
lexer.token(":");
u.setUri(prefixes.get(pfx) + lexer.word());
result.addPredicate(uri, u);
}
} else if (!lexer.peek(LexerTokenType.TOKEN, ";") && (!inlist || !lexer.peek(LexerTokenType.TOKEN, ")"))) {
throw new FHIRFormatError("unexpected token " + lexer.token);
}
if (inlist)
rpt = !lexer.peek(LexerTokenType.TOKEN, ")");
else {
rpt = lexer.peek(LexerTokenType.TOKEN, ",");
if (rpt)
lexer.readNext(false);
}
} while (rpt);
if (inlist)
lexer.token(")");
if (lexer.peek(LexerTokenType.TOKEN, ";")) {
while ((lexer.peek(LexerTokenType.TOKEN, ";"))) lexer.token(";");
done = lexer.peek(LexerTokenType.TOKEN, ".") || lexer.peek(LexerTokenType.TOKEN, "]");
} else {
done = true;
}
}
return result;
}
use of org.hl7.cql_annotations.r1.Tag in project org.hl7.fhir.core by hapifhir.
the class XhtmlParser method parse.
private XhtmlDocument parse(String entryName) throws FHIRFormatError, IOException {
XhtmlDocument result = new XhtmlDocument();
skipWhiteSpaceAndComments(result);
if (peekChar() != '<')
throw new FHIRFormatError("Unable to Parse HTML - does not start with tag. Found " + peekChar() + descLoc());
readChar();
markLocation();
QName n = new QName(readName().toLowerCase());
if ((entryName != null) && !n.getName().equals(entryName))
throw new FHIRFormatError("Unable to Parse HTML - starts with '" + n + "' not '" + entryName + "'" + descLoc());
XhtmlNode root = result.addTag(n.getName());
root.setLocation(markLocation());
parseAttributes(root);
markLocation();
NSMap nsm = checkNamespaces(n, root, null, true);
if (readChar() == '/') {
if (peekChar() != '>')
throw new FHIRFormatError("unexpected non-end of element " + n + " " + descLoc());
readChar();
} else {
unwindPoint = null;
List<XhtmlNode> p = new ArrayList<>();
parseElementInner(root, p, nsm, true);
}
return result;
}
use of org.hl7.cql_annotations.r1.Tag in project org.hl7.fhir.core by hapifhir.
the class XhtmlParser method parseFragment.
private XhtmlNode parseFragment() throws IOException, FHIRException {
skipWhiteSpace();
if (peekChar() != '<')
throw new FHIRException("Unable to Parse HTML - does not start with tag. Found " + peekChar() + descLoc());
readChar();
if (peekChar() == '?') {
readToTagEnd();
skipWhiteSpaceInternal();
if (peekChar() != '<')
throw new FHIRException("Unable to Parse HTML - does not start with tag after processing instruction. Found " + peekChar() + descLoc());
readChar();
}
String n = readName().toLowerCase();
readToTagEnd();
XhtmlNode result = new XhtmlNode(NodeType.Element);
int colonIndex = n.indexOf(':');
if (colonIndex != -1) {
n = n.substring(colonIndex + 1);
}
result.setName(n);
unwindPoint = null;
List<XhtmlNode> p = new ArrayList<>();
parseElementInner(result, p, null, true);
return result;
}
use of org.hl7.cql_annotations.r1.Tag in project org.hl7.fhir.core by hapifhir.
the class Turtle method parseComplex.
private TTLComplex parseComplex(Lexer lexer) throws FHIRFormatError {
TTLComplex result = new TTLComplex(lexer.startLine, lexer.startCol);
boolean done = lexer.peek(LexerTokenType.TOKEN, "]");
while (!done) {
String uri = null;
if (lexer.peekType() == LexerTokenType.URI)
uri = lexer.uri();
else {
String t = lexer.peekType() == LexerTokenType.WORD ? lexer.word() : null;
if (lexer.type == LexerTokenType.TOKEN && lexer.token.equals(":")) {
lexer.token(":");
if (!prefixes.containsKey(t))
throw new FHIRFormatError("unknown prefix " + t);
uri = prefixes.get(t) + lexer.word();
} else if (t.equals("a"))
uri = prefixes.get("rdfs") + "type";
else
throw lexer.error("unexpected token");
}
boolean inlist = false;
if (lexer.peek(LexerTokenType.TOKEN, "(")) {
inlist = true;
lexer.token("(");
}
boolean rpt = false;
do {
if (lexer.peek(LexerTokenType.TOKEN, "[")) {
lexer.token("[");
result.addPredicate(uri, parseComplex(lexer));
lexer.token("]");
} else if (lexer.peekType() == LexerTokenType.URI) {
TTLURL u = new TTLURL(lexer.startLine, lexer.startCol);
u.setUri(lexer.uri());
result.addPredicate(uri, u);
} else if (lexer.peekType() == LexerTokenType.LITERAL) {
TTLLiteral u = new TTLLiteral(lexer.startLine, lexer.startCol);
u.value = lexer.literal();
if (lexer.peek(LexerTokenType.TOKEN, "^")) {
lexer.token("^");
lexer.token("^");
if (lexer.peekType() == LexerTokenType.URI) {
u.type = lexer.uri();
} else {
String l = lexer.word();
lexer.token(":");
u.type = prefixes.get(l) + lexer.word();
}
}
if (lexer.peek(LexerTokenType.TOKEN, "@")) {
// lang tag - skip it
lexer.token("@");
String lang = lexer.word();
if (!lang.matches(LANG_REGEX)) {
throw new FHIRFormatError("Invalid Language tag " + lang);
}
}
result.addPredicate(uri, u);
} else if (lexer.peekType() == LexerTokenType.WORD || lexer.peek(LexerTokenType.TOKEN, ":")) {
int sl = lexer.startLine;
int sc = lexer.startCol;
String pfx = lexer.peekType() == LexerTokenType.WORD ? lexer.word() : null;
if (Utilities.isDecimal(pfx, true, true) && !lexer.peek(LexerTokenType.TOKEN, ":")) {
TTLLiteral u = new TTLLiteral(sl, sc);
u.value = pfx;
result.addPredicate(uri, u);
} else if (("false".equals(pfx) || "true".equals(pfx)) && !lexer.peek(LexerTokenType.TOKEN, ":")) {
TTLLiteral u = new TTLLiteral(sl, sc);
u.value = pfx;
result.addPredicate(uri, u);
} else {
if (!prefixes.containsKey(pfx))
throw new FHIRFormatError("Unknown prefix " + (pfx == null ? "''" : pfx));
TTLURL u = new TTLURL(sl, sc);
lexer.token(":");
u.setUri(prefixes.get(pfx) + lexer.word());
result.addPredicate(uri, u);
}
} else if (!lexer.peek(LexerTokenType.TOKEN, ";") && (!inlist || !lexer.peek(LexerTokenType.TOKEN, ")"))) {
throw new FHIRFormatError("unexpected token " + lexer.token);
}
if (inlist)
rpt = !lexer.peek(LexerTokenType.TOKEN, ")");
else {
rpt = lexer.peek(LexerTokenType.TOKEN, ",");
if (rpt)
lexer.readNext(false);
}
} while (rpt);
if (inlist)
lexer.token(")");
if (lexer.peek(LexerTokenType.TOKEN, ";")) {
while ((lexer.peek(LexerTokenType.TOKEN, ";"))) lexer.token(";");
done = lexer.peek(LexerTokenType.TOKEN, ".") || lexer.peek(LexerTokenType.TOKEN, "]");
} else {
done = true;
}
}
return result;
}
Aggregations