Header fixes
This commit is contained in:
parent
d009e836bb
commit
8e800a10b7
|
@ -20,45 +20,45 @@ package org.hl7.fhir.utilities;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class TranslatingUtilities {
|
||||
|
||||
public interface TranslationServices {
|
||||
String translate(String context, String value);
|
||||
String translate(String context, String value, Object... args);
|
||||
String toStr(int value);
|
||||
String toStr(Date value);
|
||||
}
|
||||
|
||||
private TranslationServices translator;
|
||||
|
||||
public TranslationServices getTranslator() {
|
||||
return translator;
|
||||
}
|
||||
|
||||
public void setTranslator(TranslationServices translator) {
|
||||
this.translator = translator;
|
||||
}
|
||||
|
||||
protected String translate(String context, String value) {
|
||||
return hasTranslator() ? translator.translate(context, value) : value;
|
||||
}
|
||||
|
||||
protected String translate(String context, String value, Object... args) {
|
||||
return hasTranslator() ? translator.translate(context, value, args) : String.format(value, args);
|
||||
}
|
||||
|
||||
protected boolean hasTranslator() {
|
||||
return translator != null;
|
||||
}
|
||||
|
||||
public String toStr(int value) {
|
||||
return hasTranslator() ? translator.toStr(value) : Integer.toString(value);
|
||||
}
|
||||
|
||||
public String toStr(Date value) {
|
||||
return hasTranslator() ? translator.toStr(value) : value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class TranslatingUtilities {
|
||||
|
||||
public interface TranslationServices {
|
||||
String translate(String context, String value);
|
||||
String translate(String context, String value, Object... args);
|
||||
String toStr(int value);
|
||||
String toStr(Date value);
|
||||
}
|
||||
|
||||
private TranslationServices translator;
|
||||
|
||||
public TranslationServices getTranslator() {
|
||||
return translator;
|
||||
}
|
||||
|
||||
public void setTranslator(TranslationServices translator) {
|
||||
this.translator = translator;
|
||||
}
|
||||
|
||||
protected String translate(String context, String value) {
|
||||
return hasTranslator() ? translator.translate(context, value) : value;
|
||||
}
|
||||
|
||||
protected String translate(String context, String value, Object... args) {
|
||||
return hasTranslator() ? translator.translate(context, value, args) : String.format(value, args);
|
||||
}
|
||||
|
||||
protected boolean hasTranslator() {
|
||||
return translator != null;
|
||||
}
|
||||
|
||||
public String toStr(int value) {
|
||||
return hasTranslator() ? translator.toStr(value) : Integer.toString(value);
|
||||
}
|
||||
|
||||
public String toStr(Date value) {
|
||||
return hasTranslator() ? translator.toStr(value) : value.toString();
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,31 +1,31 @@
|
|||
/*
|
||||
Copyright (c) 2011+, HL7, Inc
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
package org.hl7.fhir.utilities.xhtml;
|
||||
|
||||
/*
|
||||
|
@ -48,322 +48,322 @@ package org.hl7.fhir.utilities.xhtml;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.xml.IXMLWriter;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class XhtmlComposer {
|
||||
|
||||
public static final String XHTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
private boolean pretty;
|
||||
private boolean xmlOnly;
|
||||
|
||||
|
||||
public boolean isPretty() {
|
||||
return pretty;
|
||||
}
|
||||
|
||||
public XhtmlComposer setPretty(boolean pretty) {
|
||||
this.pretty = pretty;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isXmlOnly() {
|
||||
return xmlOnly;
|
||||
}
|
||||
|
||||
public XhtmlComposer setXmlOnly(boolean xmlOnly) {
|
||||
this.xmlOnly = xmlOnly;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
private Writer dst;
|
||||
|
||||
public String compose(XhtmlDocument doc) throws IOException {
|
||||
StringWriter sdst = new StringWriter();
|
||||
dst = sdst;
|
||||
composeDoc(doc);
|
||||
return sdst.toString();
|
||||
}
|
||||
|
||||
public String compose(XhtmlNode node) throws IOException {
|
||||
StringWriter sdst = new StringWriter();
|
||||
dst = sdst;
|
||||
writeNode("", node);
|
||||
return sdst.toString();
|
||||
}
|
||||
|
||||
public void compose(OutputStream stream, XhtmlDocument doc) throws IOException {
|
||||
byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };
|
||||
stream.write(bom);
|
||||
dst = new OutputStreamWriter(stream, "UTF-8");
|
||||
composeDoc(doc);
|
||||
dst.flush();
|
||||
}
|
||||
|
||||
private void composeDoc(XhtmlDocument doc) throws IOException {
|
||||
// headers....
|
||||
// dst.append("<html>" + (isPretty() ? "\r\n" : ""));
|
||||
for (XhtmlNode c : doc.getChildNodes())
|
||||
writeNode(" ", c);
|
||||
// dst.append("</html>" + (isPretty() ? "\r\n" : ""));
|
||||
}
|
||||
|
||||
private void writeNode(String indent, XhtmlNode node) throws IOException {
|
||||
if (node.getNodeType() == NodeType.Comment)
|
||||
writeComment(indent, node);
|
||||
else if (node.getNodeType() == NodeType.DocType)
|
||||
writeDocType(node);
|
||||
else if (node.getNodeType() == NodeType.Instruction)
|
||||
writeInstruction(node);
|
||||
else if (node.getNodeType() == NodeType.Element)
|
||||
writeElement(indent, node);
|
||||
else if (node.getNodeType() == NodeType.Document)
|
||||
writeDocument(indent, node);
|
||||
else if (node.getNodeType() == NodeType.Text)
|
||||
writeText(node);
|
||||
else if (node.getNodeType() == null)
|
||||
throw new IOException("Null node type");
|
||||
else
|
||||
throw new IOException("Unknown node type: "+node.getNodeType().toString());
|
||||
}
|
||||
|
||||
private void writeText(XhtmlNode node) throws IOException {
|
||||
for (char c : node.getContent().toCharArray())
|
||||
{
|
||||
if (c == '&')
|
||||
dst.append("&");
|
||||
else if (c == '<')
|
||||
dst.append("<");
|
||||
else if (c == '>')
|
||||
dst.append(">");
|
||||
else if (c == '"')
|
||||
dst.append(""");
|
||||
else if (xmlOnly) {
|
||||
dst.append(c);
|
||||
} else {
|
||||
if (c == XhtmlNode.NBSP.charAt(0))
|
||||
dst.append(" ");
|
||||
else if (c == (char) 0xA7)
|
||||
dst.append("§");
|
||||
else if (c == (char) 169)
|
||||
dst.append("©");
|
||||
else if (c == (char) 8482)
|
||||
dst.append("™");
|
||||
else if (c == (char) 956)
|
||||
dst.append("μ");
|
||||
else if (c == (char) 174)
|
||||
dst.append("®");
|
||||
else
|
||||
dst.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeComment(String indent, XhtmlNode node) throws IOException {
|
||||
dst.append(indent + "<!-- " + node.getContent().trim() + " -->" + (isPretty() ? "\r\n" : ""));
|
||||
}
|
||||
|
||||
private void writeDocType(XhtmlNode node) throws IOException {
|
||||
dst.append("<!" + node.getContent() + ">\r\n");
|
||||
}
|
||||
|
||||
private void writeInstruction(XhtmlNode node) throws IOException {
|
||||
dst.append("<?" + node.getContent() + "?>\r\n");
|
||||
}
|
||||
|
||||
private String escapeHtml(String s) {
|
||||
if (s == null || s.equals(""))
|
||||
return null;
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (char c : s.toCharArray())
|
||||
if (c == '<')
|
||||
b.append("<");
|
||||
else if (c == '>')
|
||||
b.append(">");
|
||||
else if (c == '"')
|
||||
b.append(""");
|
||||
else if (c == '&')
|
||||
b.append("&");
|
||||
else
|
||||
b.append(c);
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
private String attributes(XhtmlNode node) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (String n : node.getAttributes().keySet())
|
||||
s.append(" " + n + "=\"" + escapeHtml(node.getAttributes().get(n)) + "\"");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
private void writeElement(String indent, XhtmlNode node) throws IOException {
|
||||
if (!pretty)
|
||||
indent = "";
|
||||
|
||||
if (node.getChildNodes().size() == 0)
|
||||
dst.append(indent + "<" + node.getName() + attributes(node) + "/>" + (isPretty() ? "\r\n" : ""));
|
||||
else {
|
||||
boolean act = node.allChildrenAreText();
|
||||
if (act || !pretty)
|
||||
dst.append(indent + "<" + node.getName() + attributes(node)+">");
|
||||
else
|
||||
dst.append(indent + "<" + node.getName() + attributes(node) + ">\r\n");
|
||||
if (node.getName() == "head" && node.getElement("meta") == null)
|
||||
dst.append(indent + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>" + (isPretty() ? "\r\n" : ""));
|
||||
|
||||
|
||||
for (XhtmlNode c : node.getChildNodes())
|
||||
writeNode(indent + " ", c);
|
||||
if (act)
|
||||
dst.append("</" + node.getName() + ">" + (isPretty() ? "\r\n" : ""));
|
||||
else if (node.getChildNodes().get(node.getChildNodes().size() - 1).getNodeType() == NodeType.Text)
|
||||
dst.append((isPretty() ? "\r\n"+ indent : "") + "</" + node.getName() + ">" + (isPretty() ? "\r\n" : ""));
|
||||
else
|
||||
dst.append(indent + "</" + node.getName() + ">" + (isPretty() ? "\r\n" : ""));
|
||||
}
|
||||
}
|
||||
|
||||
private void writeDocument(String indent, XhtmlNode node) throws IOException {
|
||||
indent = "";
|
||||
for (XhtmlNode c : node.getChildNodes())
|
||||
writeNode(indent, c);
|
||||
}
|
||||
|
||||
|
||||
public void compose(IXMLWriter xml, XhtmlNode node) throws IOException {
|
||||
if (node.getNodeType() == NodeType.Comment)
|
||||
xml.comment(node.getContent(), isPretty());
|
||||
else if (node.getNodeType() == NodeType.Element)
|
||||
composeElement(xml, node);
|
||||
else if (node.getNodeType() == NodeType.Text)
|
||||
xml.text(node.getContent());
|
||||
else
|
||||
throw new Error("Unhandled node type: "+node.getNodeType().toString());
|
||||
}
|
||||
|
||||
private void composeElement(IXMLWriter xml, XhtmlNode node) throws IOException {
|
||||
for (String n : node.getAttributes().keySet()) {
|
||||
if (n.equals("xmlns"))
|
||||
xml.setDefaultNamespace(node.getAttributes().get(n));
|
||||
else if (n.startsWith("xmlns:"))
|
||||
xml.namespace(n.substring(6), node.getAttributes().get(n));
|
||||
else
|
||||
xml.attribute(n, node.getAttributes().get(n));
|
||||
}
|
||||
xml.enter(XHTML_NS, node.getName());
|
||||
for (XhtmlNode n : node.getChildNodes())
|
||||
compose(xml, n);
|
||||
xml.exit(XHTML_NS, node.getName());
|
||||
}
|
||||
|
||||
public String composePlainText(XhtmlNode x) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
composePlainText(x, b, false);
|
||||
return b.toString().trim();
|
||||
}
|
||||
|
||||
private boolean composePlainText(XhtmlNode x, StringBuilder b, boolean lastWS) {
|
||||
if (x.getNodeType() == NodeType.Text) {
|
||||
String s = x.getContent();
|
||||
if (!lastWS & (s.startsWith(" ") || s.startsWith("\r") || s.startsWith("\n") || s.endsWith("\t"))) {
|
||||
b.append(" ");
|
||||
lastWS = true;
|
||||
}
|
||||
String st = s.trim().replace("\r", " ").replace("\n", " ").replace("\t", " ");
|
||||
while (st.contains(" "))
|
||||
st = st.replace(" ", " ");
|
||||
if (!Utilities.noString(st)) {
|
||||
b.append(st);
|
||||
lastWS = false;
|
||||
if (!lastWS & (s.endsWith(" ") || s.endsWith("\r") || s.endsWith("\n") || s.endsWith("\t"))) {
|
||||
b.append(" ");
|
||||
lastWS = true;
|
||||
}
|
||||
}
|
||||
return lastWS;
|
||||
} else if (x.getNodeType() == NodeType.Element) {
|
||||
if (x.getName().equals("li")) {
|
||||
b.append("* ");
|
||||
lastWS = true;
|
||||
}
|
||||
|
||||
for (XhtmlNode n : x.getChildNodes()) {
|
||||
lastWS = composePlainText(n, b, lastWS);
|
||||
}
|
||||
if (x.getName().equals("p")) {
|
||||
b.append("\r\n\r\n");
|
||||
lastWS = true;
|
||||
}
|
||||
if (x.getName().equals("br") || x.getName().equals("li")) {
|
||||
b.append("\r\n");
|
||||
lastWS = true;
|
||||
}
|
||||
return lastWS;
|
||||
} else
|
||||
return lastWS;
|
||||
}
|
||||
|
||||
public void compose(Element div, XhtmlNode x) {
|
||||
for (XhtmlNode child : x.getChildNodes()) {
|
||||
appendChild(div, child);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendChild(Element e, XhtmlNode node) {
|
||||
if (node.getNodeType() == NodeType.Comment)
|
||||
e.appendChild(e.getOwnerDocument().createComment(node.getContent()));
|
||||
else if (node.getNodeType() == NodeType.DocType)
|
||||
throw new Error("not done yet");
|
||||
else if (node.getNodeType() == NodeType.Instruction)
|
||||
e.appendChild(e.getOwnerDocument().createProcessingInstruction("", node.getContent()));
|
||||
else if (node.getNodeType() == NodeType.Text)
|
||||
e.appendChild(e.getOwnerDocument().createTextNode(node.getContent()));
|
||||
else if (node.getNodeType() == NodeType.Element) {
|
||||
Element child = e.getOwnerDocument().createElementNS(XHTML_NS, node.getName());
|
||||
e.appendChild(child);
|
||||
for (XhtmlNode c : node.getChildNodes()) {
|
||||
appendChild(child, c);
|
||||
}
|
||||
} else
|
||||
throw new Error("Unknown node type: "+node.getNodeType().toString());
|
||||
}
|
||||
|
||||
public void compose(OutputStream stream, XhtmlNode x) throws IOException {
|
||||
byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };
|
||||
stream.write(bom);
|
||||
dst = new OutputStreamWriter(stream, "UTF-8");
|
||||
dst.append("<html><head><link rel=\"stylesheet\" href=\"fhir.css\"/></head><body>\r\n");
|
||||
writeNode("", x);
|
||||
dst.append("</body></html>\r\n");
|
||||
dst.flush();
|
||||
}
|
||||
|
||||
public void composeDocument(FileOutputStream f, XhtmlNode xhtml) throws IOException {
|
||||
byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };
|
||||
f.write(bom);
|
||||
dst = new OutputStreamWriter(f, "UTF-8");
|
||||
writeNode("", xhtml);
|
||||
dst.flush();
|
||||
dst.close();
|
||||
}
|
||||
|
||||
public String composeEx(XhtmlNode node) {
|
||||
try {
|
||||
return compose(node);
|
||||
} catch (IOException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
import org.hl7.fhir.utilities.xml.IXMLWriter;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class XhtmlComposer {
|
||||
|
||||
public static final String XHTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
private boolean pretty;
|
||||
private boolean xmlOnly;
|
||||
|
||||
|
||||
public boolean isPretty() {
|
||||
return pretty;
|
||||
}
|
||||
|
||||
public XhtmlComposer setPretty(boolean pretty) {
|
||||
this.pretty = pretty;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isXmlOnly() {
|
||||
return xmlOnly;
|
||||
}
|
||||
|
||||
public XhtmlComposer setXmlOnly(boolean xmlOnly) {
|
||||
this.xmlOnly = xmlOnly;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
private Writer dst;
|
||||
|
||||
public String compose(XhtmlDocument doc) throws IOException {
|
||||
StringWriter sdst = new StringWriter();
|
||||
dst = sdst;
|
||||
composeDoc(doc);
|
||||
return sdst.toString();
|
||||
}
|
||||
|
||||
public String compose(XhtmlNode node) throws IOException {
|
||||
StringWriter sdst = new StringWriter();
|
||||
dst = sdst;
|
||||
writeNode("", node);
|
||||
return sdst.toString();
|
||||
}
|
||||
|
||||
public void compose(OutputStream stream, XhtmlDocument doc) throws IOException {
|
||||
byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };
|
||||
stream.write(bom);
|
||||
dst = new OutputStreamWriter(stream, "UTF-8");
|
||||
composeDoc(doc);
|
||||
dst.flush();
|
||||
}
|
||||
|
||||
private void composeDoc(XhtmlDocument doc) throws IOException {
|
||||
// headers....
|
||||
// dst.append("<html>" + (isPretty() ? "\r\n" : ""));
|
||||
for (XhtmlNode c : doc.getChildNodes())
|
||||
writeNode(" ", c);
|
||||
// dst.append("</html>" + (isPretty() ? "\r\n" : ""));
|
||||
}
|
||||
|
||||
private void writeNode(String indent, XhtmlNode node) throws IOException {
|
||||
if (node.getNodeType() == NodeType.Comment)
|
||||
writeComment(indent, node);
|
||||
else if (node.getNodeType() == NodeType.DocType)
|
||||
writeDocType(node);
|
||||
else if (node.getNodeType() == NodeType.Instruction)
|
||||
writeInstruction(node);
|
||||
else if (node.getNodeType() == NodeType.Element)
|
||||
writeElement(indent, node);
|
||||
else if (node.getNodeType() == NodeType.Document)
|
||||
writeDocument(indent, node);
|
||||
else if (node.getNodeType() == NodeType.Text)
|
||||
writeText(node);
|
||||
else if (node.getNodeType() == null)
|
||||
throw new IOException("Null node type");
|
||||
else
|
||||
throw new IOException("Unknown node type: "+node.getNodeType().toString());
|
||||
}
|
||||
|
||||
private void writeText(XhtmlNode node) throws IOException {
|
||||
for (char c : node.getContent().toCharArray())
|
||||
{
|
||||
if (c == '&')
|
||||
dst.append("&");
|
||||
else if (c == '<')
|
||||
dst.append("<");
|
||||
else if (c == '>')
|
||||
dst.append(">");
|
||||
else if (c == '"')
|
||||
dst.append(""");
|
||||
else if (xmlOnly) {
|
||||
dst.append(c);
|
||||
} else {
|
||||
if (c == XhtmlNode.NBSP.charAt(0))
|
||||
dst.append(" ");
|
||||
else if (c == (char) 0xA7)
|
||||
dst.append("§");
|
||||
else if (c == (char) 169)
|
||||
dst.append("©");
|
||||
else if (c == (char) 8482)
|
||||
dst.append("™");
|
||||
else if (c == (char) 956)
|
||||
dst.append("μ");
|
||||
else if (c == (char) 174)
|
||||
dst.append("®");
|
||||
else
|
||||
dst.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeComment(String indent, XhtmlNode node) throws IOException {
|
||||
dst.append(indent + "<!-- " + node.getContent().trim() + " -->" + (isPretty() ? "\r\n" : ""));
|
||||
}
|
||||
|
||||
private void writeDocType(XhtmlNode node) throws IOException {
|
||||
dst.append("<!" + node.getContent() + ">\r\n");
|
||||
}
|
||||
|
||||
private void writeInstruction(XhtmlNode node) throws IOException {
|
||||
dst.append("<?" + node.getContent() + "?>\r\n");
|
||||
}
|
||||
|
||||
private String escapeHtml(String s) {
|
||||
if (s == null || s.equals(""))
|
||||
return null;
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (char c : s.toCharArray())
|
||||
if (c == '<')
|
||||
b.append("<");
|
||||
else if (c == '>')
|
||||
b.append(">");
|
||||
else if (c == '"')
|
||||
b.append(""");
|
||||
else if (c == '&')
|
||||
b.append("&");
|
||||
else
|
||||
b.append(c);
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
private String attributes(XhtmlNode node) {
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (String n : node.getAttributes().keySet())
|
||||
s.append(" " + n + "=\"" + escapeHtml(node.getAttributes().get(n)) + "\"");
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
private void writeElement(String indent, XhtmlNode node) throws IOException {
|
||||
if (!pretty)
|
||||
indent = "";
|
||||
|
||||
if (node.getChildNodes().size() == 0)
|
||||
dst.append(indent + "<" + node.getName() + attributes(node) + "/>" + (isPretty() ? "\r\n" : ""));
|
||||
else {
|
||||
boolean act = node.allChildrenAreText();
|
||||
if (act || !pretty)
|
||||
dst.append(indent + "<" + node.getName() + attributes(node)+">");
|
||||
else
|
||||
dst.append(indent + "<" + node.getName() + attributes(node) + ">\r\n");
|
||||
if (node.getName() == "head" && node.getElement("meta") == null)
|
||||
dst.append(indent + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>" + (isPretty() ? "\r\n" : ""));
|
||||
|
||||
|
||||
for (XhtmlNode c : node.getChildNodes())
|
||||
writeNode(indent + " ", c);
|
||||
if (act)
|
||||
dst.append("</" + node.getName() + ">" + (isPretty() ? "\r\n" : ""));
|
||||
else if (node.getChildNodes().get(node.getChildNodes().size() - 1).getNodeType() == NodeType.Text)
|
||||
dst.append((isPretty() ? "\r\n"+ indent : "") + "</" + node.getName() + ">" + (isPretty() ? "\r\n" : ""));
|
||||
else
|
||||
dst.append(indent + "</" + node.getName() + ">" + (isPretty() ? "\r\n" : ""));
|
||||
}
|
||||
}
|
||||
|
||||
private void writeDocument(String indent, XhtmlNode node) throws IOException {
|
||||
indent = "";
|
||||
for (XhtmlNode c : node.getChildNodes())
|
||||
writeNode(indent, c);
|
||||
}
|
||||
|
||||
|
||||
public void compose(IXMLWriter xml, XhtmlNode node) throws IOException {
|
||||
if (node.getNodeType() == NodeType.Comment)
|
||||
xml.comment(node.getContent(), isPretty());
|
||||
else if (node.getNodeType() == NodeType.Element)
|
||||
composeElement(xml, node);
|
||||
else if (node.getNodeType() == NodeType.Text)
|
||||
xml.text(node.getContent());
|
||||
else
|
||||
throw new Error("Unhandled node type: "+node.getNodeType().toString());
|
||||
}
|
||||
|
||||
private void composeElement(IXMLWriter xml, XhtmlNode node) throws IOException {
|
||||
for (String n : node.getAttributes().keySet()) {
|
||||
if (n.equals("xmlns"))
|
||||
xml.setDefaultNamespace(node.getAttributes().get(n));
|
||||
else if (n.startsWith("xmlns:"))
|
||||
xml.namespace(n.substring(6), node.getAttributes().get(n));
|
||||
else
|
||||
xml.attribute(n, node.getAttributes().get(n));
|
||||
}
|
||||
xml.enter(XHTML_NS, node.getName());
|
||||
for (XhtmlNode n : node.getChildNodes())
|
||||
compose(xml, n);
|
||||
xml.exit(XHTML_NS, node.getName());
|
||||
}
|
||||
|
||||
public String composePlainText(XhtmlNode x) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
composePlainText(x, b, false);
|
||||
return b.toString().trim();
|
||||
}
|
||||
|
||||
private boolean composePlainText(XhtmlNode x, StringBuilder b, boolean lastWS) {
|
||||
if (x.getNodeType() == NodeType.Text) {
|
||||
String s = x.getContent();
|
||||
if (!lastWS & (s.startsWith(" ") || s.startsWith("\r") || s.startsWith("\n") || s.endsWith("\t"))) {
|
||||
b.append(" ");
|
||||
lastWS = true;
|
||||
}
|
||||
String st = s.trim().replace("\r", " ").replace("\n", " ").replace("\t", " ");
|
||||
while (st.contains(" "))
|
||||
st = st.replace(" ", " ");
|
||||
if (!Utilities.noString(st)) {
|
||||
b.append(st);
|
||||
lastWS = false;
|
||||
if (!lastWS & (s.endsWith(" ") || s.endsWith("\r") || s.endsWith("\n") || s.endsWith("\t"))) {
|
||||
b.append(" ");
|
||||
lastWS = true;
|
||||
}
|
||||
}
|
||||
return lastWS;
|
||||
} else if (x.getNodeType() == NodeType.Element) {
|
||||
if (x.getName().equals("li")) {
|
||||
b.append("* ");
|
||||
lastWS = true;
|
||||
}
|
||||
|
||||
for (XhtmlNode n : x.getChildNodes()) {
|
||||
lastWS = composePlainText(n, b, lastWS);
|
||||
}
|
||||
if (x.getName().equals("p")) {
|
||||
b.append("\r\n\r\n");
|
||||
lastWS = true;
|
||||
}
|
||||
if (x.getName().equals("br") || x.getName().equals("li")) {
|
||||
b.append("\r\n");
|
||||
lastWS = true;
|
||||
}
|
||||
return lastWS;
|
||||
} else
|
||||
return lastWS;
|
||||
}
|
||||
|
||||
public void compose(Element div, XhtmlNode x) {
|
||||
for (XhtmlNode child : x.getChildNodes()) {
|
||||
appendChild(div, child);
|
||||
}
|
||||
}
|
||||
|
||||
private void appendChild(Element e, XhtmlNode node) {
|
||||
if (node.getNodeType() == NodeType.Comment)
|
||||
e.appendChild(e.getOwnerDocument().createComment(node.getContent()));
|
||||
else if (node.getNodeType() == NodeType.DocType)
|
||||
throw new Error("not done yet");
|
||||
else if (node.getNodeType() == NodeType.Instruction)
|
||||
e.appendChild(e.getOwnerDocument().createProcessingInstruction("", node.getContent()));
|
||||
else if (node.getNodeType() == NodeType.Text)
|
||||
e.appendChild(e.getOwnerDocument().createTextNode(node.getContent()));
|
||||
else if (node.getNodeType() == NodeType.Element) {
|
||||
Element child = e.getOwnerDocument().createElementNS(XHTML_NS, node.getName());
|
||||
e.appendChild(child);
|
||||
for (XhtmlNode c : node.getChildNodes()) {
|
||||
appendChild(child, c);
|
||||
}
|
||||
} else
|
||||
throw new Error("Unknown node type: "+node.getNodeType().toString());
|
||||
}
|
||||
|
||||
public void compose(OutputStream stream, XhtmlNode x) throws IOException {
|
||||
byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };
|
||||
stream.write(bom);
|
||||
dst = new OutputStreamWriter(stream, "UTF-8");
|
||||
dst.append("<html><head><link rel=\"stylesheet\" href=\"fhir.css\"/></head><body>\r\n");
|
||||
writeNode("", x);
|
||||
dst.append("</body></html>\r\n");
|
||||
dst.flush();
|
||||
}
|
||||
|
||||
public void composeDocument(FileOutputStream f, XhtmlNode xhtml) throws IOException {
|
||||
byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF };
|
||||
f.write(bom);
|
||||
dst = new OutputStreamWriter(f, "UTF-8");
|
||||
writeNode("", xhtml);
|
||||
dst.flush();
|
||||
dst.close();
|
||||
}
|
||||
|
||||
public String composeEx(XhtmlNode node) {
|
||||
try {
|
||||
return compose(node);
|
||||
} catch (IOException e) {
|
||||
throw new Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,263 +20,263 @@ package org.hl7.fhir.convertors;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
|
||||
import org.hl7.fhir.utilities.xml.XMLUtil;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class CDAUtilities {
|
||||
|
||||
private Document doc;
|
||||
|
||||
public CDAUtilities(InputStream stream) throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
|
||||
doc = builder.parse(stream);
|
||||
basicChecks();
|
||||
}
|
||||
|
||||
private void basicChecks() throws Exception {
|
||||
Element e = doc.getDocumentElement();
|
||||
rule(e.getNamespaceURI().equals("urn:hl7-org:v3"), "CDA namespace must be ");
|
||||
rule(e.getNodeName().equals("ClinicalDocument"), "CDA root name must be ClinicalDocument");
|
||||
|
||||
}
|
||||
|
||||
private void rule(boolean test, String message) throws Exception {
|
||||
if (!test)
|
||||
throw new Exception(message);
|
||||
|
||||
}
|
||||
|
||||
public Element getElement() {
|
||||
return doc.getDocumentElement();
|
||||
}
|
||||
|
||||
public void checkTemplateId(Element e, String templateId) throws Exception {
|
||||
rule(hasTemplateId(e, templateId), "Template Id '"+templateId+"' not found");
|
||||
|
||||
}
|
||||
|
||||
public Element getChild(Element e, String[] names) throws Exception {
|
||||
for (String n : names) {
|
||||
if (e == null)
|
||||
return null;
|
||||
e = getChild(e, n);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
public Element getChild(Element element, String name) throws Exception {
|
||||
if (element == null)
|
||||
return null;
|
||||
|
||||
Element e = null;
|
||||
Node n = element.getFirstChild();
|
||||
while (n != null) {
|
||||
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) {
|
||||
if (e == null) {
|
||||
e = (Element) n;
|
||||
} else {
|
||||
throw new Exception("multiple matches found for "+name);
|
||||
}
|
||||
}
|
||||
n = n.getNextSibling();
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
public Element getChildByAttribute(Element element, String name, String attrname, String value) throws Exception {
|
||||
if (element == null)
|
||||
return null;
|
||||
|
||||
Element e = null;
|
||||
Node n = element.getFirstChild();
|
||||
while (n != null) {
|
||||
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name) && value.equals(((Element) n).getAttribute(attrname))) {
|
||||
if (e == null) {
|
||||
e = (Element) n;
|
||||
} else {
|
||||
throw new Exception("multiple matches found for "+name);
|
||||
}
|
||||
}
|
||||
n = n.getNextSibling();
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
public List<Element> getChildren(Element element, String name) {
|
||||
List<Element> l = new ArrayList<Element>();
|
||||
if (element != null) {
|
||||
Node n = element.getFirstChild();
|
||||
while (n != null) {
|
||||
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) {
|
||||
l.add((Element) n);
|
||||
}
|
||||
n = n.getNextSibling();
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public Element getDescendent(Element element, String path) throws Exception {
|
||||
String[] p = path.split("\\/");
|
||||
return getDescendent(element, p);
|
||||
}
|
||||
|
||||
public Element getDescendent(Element e, String[] path) throws Exception {
|
||||
for (String n : path) {
|
||||
if (e == null)
|
||||
return e;
|
||||
e = getChild(e, n);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
public boolean hasTemplateId(Element e, String tid) {
|
||||
if (e == null)
|
||||
return false;
|
||||
boolean found = false;
|
||||
Node n = e.getFirstChild();
|
||||
while (n != null && !found) {
|
||||
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals("templateId") && tid.equals(((Element) n).getAttribute("root")))
|
||||
found = true;
|
||||
n = n.getNextSibling();
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
public String getStatus(Element act) throws Exception {
|
||||
if (act == null)
|
||||
return null;
|
||||
Element sc = getChild(act, "statusCode");
|
||||
if (sc == null)
|
||||
return null;
|
||||
else
|
||||
return sc.getAttribute("code");
|
||||
}
|
||||
|
||||
public String getSeverity(Element observation) throws Exception {
|
||||
for (Element e : getChildren(observation, "entryRelationship")) {
|
||||
Element child = getChild(e, "observation");
|
||||
if (hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.8"))
|
||||
return getChild(child, "value").getAttribute("code");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String showTemplateIds(Element element) {
|
||||
List<Element> list = getChildren(element, "templateId");
|
||||
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
|
||||
for (Element e : list) {
|
||||
if (e.hasAttribute("extension"))
|
||||
b.append(e.getAttribute("root")+"::"+e.getAttribute("extension"));
|
||||
else
|
||||
b.append(e.getAttribute("root"));
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public Element getlastChild(Element e) {
|
||||
Node n = e.getLastChild();
|
||||
while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
|
||||
n = n.getPreviousSibling();
|
||||
return n == null ? null : (Element) n;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method looks up an object by it's id, and only returns it if has a child by the given name
|
||||
* (resolving identifier based cross references)
|
||||
*
|
||||
* @param id
|
||||
* @param childName
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Element getById(Element id, String childName) throws Exception {
|
||||
return getById(doc.getDocumentElement(), id, childName);
|
||||
}
|
||||
|
||||
private Element getById(Element e, Element id, String childName) throws Exception {
|
||||
Element c = XMLUtil.getFirstChild(e);
|
||||
while (c != null) {
|
||||
Element i = getChild(c, "id");
|
||||
if (i != null && matchesAsId(i, id) && getChild(c, childName) != null)
|
||||
return c;
|
||||
Element m = getById(c, id, childName);
|
||||
if (m != null)
|
||||
return m;
|
||||
c = XMLUtil.getNextSibling(c);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean matchesAsId(Element i1, Element i2) {
|
||||
String r1 = i1.getAttribute("root");
|
||||
String r2 = i2.getAttribute("root");
|
||||
String e1 = i1.getAttribute("extension");
|
||||
String e2 = i2.getAttribute("extension");
|
||||
return (r1 != null && r1.equals(r2)) && ((e1 == null && e2 == null) || (e1 != null && e1.equals(e2)));
|
||||
}
|
||||
|
||||
public Element getByXmlId(String id) {
|
||||
return getByXmlId(doc.getDocumentElement(), id);
|
||||
}
|
||||
|
||||
private Element getByXmlId(Element e, String value) {
|
||||
Element c = XMLUtil.getFirstChild(e);
|
||||
while (c != null) {
|
||||
String id = c.getAttribute("ID");
|
||||
if (id != null && id.equals(value))
|
||||
return c;
|
||||
Element m = getByXmlId(c, value);
|
||||
if (m != null)
|
||||
return m;
|
||||
c = XMLUtil.getNextSibling(c);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.hl7.fhir.utilities.CommaSeparatedStringBuilder;
|
||||
import org.hl7.fhir.utilities.xml.XMLUtil;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
public class CDAUtilities {
|
||||
|
||||
private Document doc;
|
||||
|
||||
public CDAUtilities(InputStream stream) throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
|
||||
doc = builder.parse(stream);
|
||||
basicChecks();
|
||||
}
|
||||
|
||||
private void basicChecks() throws Exception {
|
||||
Element e = doc.getDocumentElement();
|
||||
rule(e.getNamespaceURI().equals("urn:hl7-org:v3"), "CDA namespace must be ");
|
||||
rule(e.getNodeName().equals("ClinicalDocument"), "CDA root name must be ClinicalDocument");
|
||||
|
||||
}
|
||||
|
||||
private void rule(boolean test, String message) throws Exception {
|
||||
if (!test)
|
||||
throw new Exception(message);
|
||||
|
||||
}
|
||||
|
||||
public Element getElement() {
|
||||
return doc.getDocumentElement();
|
||||
}
|
||||
|
||||
public void checkTemplateId(Element e, String templateId) throws Exception {
|
||||
rule(hasTemplateId(e, templateId), "Template Id '"+templateId+"' not found");
|
||||
|
||||
}
|
||||
|
||||
public Element getChild(Element e, String[] names) throws Exception {
|
||||
for (String n : names) {
|
||||
if (e == null)
|
||||
return null;
|
||||
e = getChild(e, n);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
public Element getChild(Element element, String name) throws Exception {
|
||||
if (element == null)
|
||||
return null;
|
||||
|
||||
Element e = null;
|
||||
Node n = element.getFirstChild();
|
||||
while (n != null) {
|
||||
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) {
|
||||
if (e == null) {
|
||||
e = (Element) n;
|
||||
} else {
|
||||
throw new Exception("multiple matches found for "+name);
|
||||
}
|
||||
}
|
||||
n = n.getNextSibling();
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
public Element getChildByAttribute(Element element, String name, String attrname, String value) throws Exception {
|
||||
if (element == null)
|
||||
return null;
|
||||
|
||||
Element e = null;
|
||||
Node n = element.getFirstChild();
|
||||
while (n != null) {
|
||||
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name) && value.equals(((Element) n).getAttribute(attrname))) {
|
||||
if (e == null) {
|
||||
e = (Element) n;
|
||||
} else {
|
||||
throw new Exception("multiple matches found for "+name);
|
||||
}
|
||||
}
|
||||
n = n.getNextSibling();
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
public List<Element> getChildren(Element element, String name) {
|
||||
List<Element> l = new ArrayList<Element>();
|
||||
if (element != null) {
|
||||
Node n = element.getFirstChild();
|
||||
while (n != null) {
|
||||
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(name)) {
|
||||
l.add((Element) n);
|
||||
}
|
||||
n = n.getNextSibling();
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public Element getDescendent(Element element, String path) throws Exception {
|
||||
String[] p = path.split("\\/");
|
||||
return getDescendent(element, p);
|
||||
}
|
||||
|
||||
public Element getDescendent(Element e, String[] path) throws Exception {
|
||||
for (String n : path) {
|
||||
if (e == null)
|
||||
return e;
|
||||
e = getChild(e, n);
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
public boolean hasTemplateId(Element e, String tid) {
|
||||
if (e == null)
|
||||
return false;
|
||||
boolean found = false;
|
||||
Node n = e.getFirstChild();
|
||||
while (n != null && !found) {
|
||||
if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals("templateId") && tid.equals(((Element) n).getAttribute("root")))
|
||||
found = true;
|
||||
n = n.getNextSibling();
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
public String getStatus(Element act) throws Exception {
|
||||
if (act == null)
|
||||
return null;
|
||||
Element sc = getChild(act, "statusCode");
|
||||
if (sc == null)
|
||||
return null;
|
||||
else
|
||||
return sc.getAttribute("code");
|
||||
}
|
||||
|
||||
public String getSeverity(Element observation) throws Exception {
|
||||
for (Element e : getChildren(observation, "entryRelationship")) {
|
||||
Element child = getChild(e, "observation");
|
||||
if (hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.8"))
|
||||
return getChild(child, "value").getAttribute("code");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String showTemplateIds(Element element) {
|
||||
List<Element> list = getChildren(element, "templateId");
|
||||
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
|
||||
for (Element e : list) {
|
||||
if (e.hasAttribute("extension"))
|
||||
b.append(e.getAttribute("root")+"::"+e.getAttribute("extension"));
|
||||
else
|
||||
b.append(e.getAttribute("root"));
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public Element getlastChild(Element e) {
|
||||
Node n = e.getLastChild();
|
||||
while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
|
||||
n = n.getPreviousSibling();
|
||||
return n == null ? null : (Element) n;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method looks up an object by it's id, and only returns it if has a child by the given name
|
||||
* (resolving identifier based cross references)
|
||||
*
|
||||
* @param id
|
||||
* @param childName
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Element getById(Element id, String childName) throws Exception {
|
||||
return getById(doc.getDocumentElement(), id, childName);
|
||||
}
|
||||
|
||||
private Element getById(Element e, Element id, String childName) throws Exception {
|
||||
Element c = XMLUtil.getFirstChild(e);
|
||||
while (c != null) {
|
||||
Element i = getChild(c, "id");
|
||||
if (i != null && matchesAsId(i, id) && getChild(c, childName) != null)
|
||||
return c;
|
||||
Element m = getById(c, id, childName);
|
||||
if (m != null)
|
||||
return m;
|
||||
c = XMLUtil.getNextSibling(c);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean matchesAsId(Element i1, Element i2) {
|
||||
String r1 = i1.getAttribute("root");
|
||||
String r2 = i2.getAttribute("root");
|
||||
String e1 = i1.getAttribute("extension");
|
||||
String e2 = i2.getAttribute("extension");
|
||||
return (r1 != null && r1.equals(r2)) && ((e1 == null && e2 == null) || (e1 != null && e1.equals(e2)));
|
||||
}
|
||||
|
||||
public Element getByXmlId(String id) {
|
||||
return getByXmlId(doc.getDocumentElement(), id);
|
||||
}
|
||||
|
||||
private Element getByXmlId(Element e, String value) {
|
||||
Element c = XMLUtil.getFirstChild(e);
|
||||
while (c != null) {
|
||||
String id = c.getAttribute("ID");
|
||||
if (id != null && id.equals(value))
|
||||
return c;
|
||||
Element m = getByXmlId(c, value);
|
||||
if (m != null)
|
||||
return m;
|
||||
c = XMLUtil.getNextSibling(c);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,15 +20,15 @@ package org.hl7.fhir.convertors;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
|
||||
public class CcdaExtensions {
|
||||
public final static String DAF_NAME_RACE = "http://hl7.org/fhir/StructureDefinition/us-core-race";
|
||||
public final static String DAF_NAME_ETHNICITY = "http://hl7.org/fhir/StructureDefinition/us-core-ethnicity";
|
||||
|
||||
public final static String BASE = "http://hl7.org/ccda";
|
||||
public final static String NAME_RELIGION = BASE+"/religious-affiliation";
|
||||
public final static String NAME_BIRTHPLACE = BASE+"birthplace";
|
||||
public final static String NAME_LANG_PROF = BASE+"proficiency-level";
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class CcdaExtensions {
|
||||
public final static String DAF_NAME_RACE = "http://hl7.org/fhir/StructureDefinition/us-core-race";
|
||||
public final static String DAF_NAME_ETHNICITY = "http://hl7.org/fhir/StructureDefinition/us-core-ethnicity";
|
||||
|
||||
public final static String BASE = "http://hl7.org/ccda";
|
||||
public final static String NAME_RELIGION = BASE+"/religious-affiliation";
|
||||
public final static String NAME_BIRTHPLACE = BASE+"birthplace";
|
||||
public final static String NAME_LANG_PROF = BASE+"proficiency-level";
|
||||
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,7 +20,7 @@ package org.hl7.fhir.convertors;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
|
||||
public class ConverterBase {
|
||||
|
||||
}
|
||||
|
||||
public class ConverterBase {
|
||||
|
||||
}
|
||||
|
|
|
@ -20,19 +20,19 @@ package org.hl7.fhir.convertors;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
|
||||
import org.hl7.fhir.dstu3.model.CodeSystem;
|
||||
import org.hl7.fhir.dstu3.model.ValueSet;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
|
||||
public interface VersionConvertorAdvisor {
|
||||
boolean ignoreEntry(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent src);
|
||||
|
||||
// called ?
|
||||
org.hl7.fhir.instance.model.Resource convert(org.hl7.fhir.dstu3.model.Resource resource) throws FHIRException;
|
||||
|
||||
// called when an r2 value set has a codeSystem in it
|
||||
void handleCodeSystem(CodeSystem tgtcs, ValueSet source);
|
||||
|
||||
CodeSystem getCodeSystem(ValueSet src);
|
||||
}
|
||||
|
||||
import org.hl7.fhir.dstu3.model.CodeSystem;
|
||||
import org.hl7.fhir.dstu3.model.ValueSet;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
|
||||
public interface VersionConvertorAdvisor {
|
||||
boolean ignoreEntry(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent src);
|
||||
|
||||
// called ?
|
||||
org.hl7.fhir.instance.model.Resource convert(org.hl7.fhir.dstu3.model.Resource resource) throws FHIRException;
|
||||
|
||||
// called when an r2 value set has a codeSystem in it
|
||||
void handleCodeSystem(CodeSystem tgtcs, ValueSet source);
|
||||
|
||||
CodeSystem getCodeSystem(ValueSet src);
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -20,468 +20,468 @@ package org.hl7.fhir.dstu2.utils;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.instance.model.BooleanType;
|
||||
import org.hl7.fhir.instance.model.CodeType;
|
||||
import org.hl7.fhir.instance.model.CodeableConcept;
|
||||
import org.hl7.fhir.instance.model.Coding;
|
||||
import org.hl7.fhir.instance.model.DataElement;
|
||||
import org.hl7.fhir.instance.model.DomainResource;
|
||||
import org.hl7.fhir.instance.model.Element;
|
||||
import org.hl7.fhir.instance.model.ElementDefinition;
|
||||
import org.hl7.fhir.instance.model.Extension;
|
||||
import org.hl7.fhir.instance.model.ExtensionHelper;
|
||||
import org.hl7.fhir.instance.model.Factory;
|
||||
import org.hl7.fhir.instance.model.Identifier;
|
||||
import org.hl7.fhir.instance.model.IntegerType;
|
||||
import org.hl7.fhir.instance.model.MarkdownType;
|
||||
import org.hl7.fhir.instance.model.PrimitiveType;
|
||||
import org.hl7.fhir.instance.model.Questionnaire.GroupComponent;
|
||||
import org.hl7.fhir.instance.model.Questionnaire.QuestionComponent;
|
||||
import org.hl7.fhir.instance.model.Reference;
|
||||
import org.hl7.fhir.instance.model.StringType;
|
||||
import org.hl7.fhir.instance.model.Type;
|
||||
import org.hl7.fhir.instance.model.UriType;
|
||||
import org.hl7.fhir.instance.model.ValueSet;
|
||||
import org.hl7.fhir.instance.model.ValueSet.ConceptDefinitionComponent;
|
||||
import org.hl7.fhir.instance.model.ValueSet.ValueSetCodeSystemComponent;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage.Source;
|
||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
|
||||
|
||||
public class ToolingExtensions {
|
||||
|
||||
// validated
|
||||
public static final String EXT_SUBSUMES = "http://hl7.org/fhir/StructureDefinition/valueset-subsumes";
|
||||
private static final String EXT_OID = "http://hl7.org/fhir/StructureDefinition/valueset-oid";
|
||||
public static final String EXT_DEPRECATED = "http://hl7.org/fhir/StructureDefinition/valueset-deprecated";
|
||||
public static final String EXT_DEFINITION = "http://hl7.org/fhir/StructureDefinition/valueset-definition";
|
||||
public static final String EXT_COMMENT = "http://hl7.org/fhir/StructureDefinition/valueset-comments";
|
||||
private static final String EXT_IDENTIFIER = "http://hl7.org/fhir/StructureDefinition/identifier";
|
||||
private static final String EXT_TRANSLATION = "http://hl7.org/fhir/StructureDefinition/translation";
|
||||
public static final String EXT_ISSUE_SOURCE = "http://hl7.org/fhir/StructureDefinition/operationoutcome-issue-source";
|
||||
public static final String EXT_DISPLAY_HINT = "http://hl7.org/fhir/StructureDefinition/structuredefinition-display-hint";
|
||||
public static final String EXT_REPLACED_BY = "http://hl7.org/fhir/StructureDefinition/valueset-replacedby";
|
||||
public static final String EXT_JSON_TYPE = "http://hl7.org/fhir/StructureDefinition/structuredefinition-json-type";
|
||||
public static final String EXT_XML_TYPE = "http://hl7.org/fhir/StructureDefinition/structuredefinition-xml-type";
|
||||
public static final String EXT_REGEX = "http://hl7.org/fhir/StructureDefinition/structuredefinition-regex";
|
||||
public static final String EXT_EXPRESSION = "http://hl7.org/fhir/StructureDefinition/structuredefinition-expression";
|
||||
public static final String EXT_SEARCH_EXPRESSION = "http://hl7.org/fhir/StructureDefinition/searchparameter-expression";
|
||||
|
||||
// unregistered?
|
||||
|
||||
public static final String EXT_FLYOVER = "http://hl7.org/fhir/Profile/questionnaire-extensions#flyover";
|
||||
private static final String EXT_QTYPE = "http://www.healthintersections.com.au/fhir/Profile/metadata#type";
|
||||
private static final String EXT_QREF = "http://www.healthintersections.com.au/fhir/Profile/metadata#reference";
|
||||
private static final String EXTENSION_FILTER_ONLY = "http://www.healthintersections.com.au/fhir/Profile/metadata#expandNeedsFilter";
|
||||
private static final String EXT_TYPE = "http://www.healthintersections.com.au/fhir/Profile/metadata#type";
|
||||
private static final String EXT_REFERENCE = "http://www.healthintersections.com.au/fhir/Profile/metadata#reference";
|
||||
private static final String EXT_ALLOWABLE_UNITS = "http://hl7.org/fhir/StructureDefinition/elementdefinition-allowedUnits";
|
||||
public static final String EXT_CIMI_REFERENCE = "http://hl7.org/fhir/StructureDefinition/cimi-reference";
|
||||
public static final String EXT_UNCLOSED = "http://hl7.org/fhir/StructureDefinition/valueset-unclosed";
|
||||
public static final String EXT_FMM_LEVEL = "http://hl7.org/fhir/StructureDefinition/structuredefinition-fmm";
|
||||
|
||||
|
||||
// specific extension helpers
|
||||
|
||||
public static Extension makeIssueSource(Source source) {
|
||||
Extension ex = new Extension();
|
||||
// todo: write this up and get it published with the pack (and handle the redirect?)
|
||||
ex.setUrl(ToolingExtensions.EXT_ISSUE_SOURCE);
|
||||
CodeType c = new CodeType();
|
||||
c.setValue(source.toString());
|
||||
ex.setValue(c);
|
||||
return ex;
|
||||
}
|
||||
|
||||
public static boolean hasExtension(DomainResource de, String url) {
|
||||
return getExtension(de, url) != null;
|
||||
}
|
||||
|
||||
public static boolean hasExtension(Element e, String url) {
|
||||
return getExtension(e, url) != null;
|
||||
}
|
||||
|
||||
public static void addStringExtension(DomainResource dr, String url, String content) {
|
||||
if (!Utilities.noString(content)) {
|
||||
Extension ex = getExtension(dr, url);
|
||||
if (ex != null)
|
||||
ex.setValue(new StringType(content));
|
||||
else
|
||||
dr.getExtension().add(Factory.newExtension(url, new StringType(content), true));
|
||||
}
|
||||
}
|
||||
|
||||
public static void addStringExtension(Element e, String url, String content) {
|
||||
if (!Utilities.noString(content)) {
|
||||
Extension ex = getExtension(e, url);
|
||||
if (ex != null)
|
||||
ex.setValue(new StringType(content));
|
||||
else
|
||||
e.getExtension().add(Factory.newExtension(url, new StringType(content), true));
|
||||
}
|
||||
}
|
||||
|
||||
public static void addIntegerExtension(DomainResource dr, String url, int value) {
|
||||
Extension ex = getExtension(dr, url);
|
||||
if (ex != null)
|
||||
ex.setValue(new IntegerType(value));
|
||||
else
|
||||
dr.getExtension().add(Factory.newExtension(url, new IntegerType(value), true));
|
||||
}
|
||||
|
||||
public static void addComment(Element nc, String comment) {
|
||||
if (!Utilities.noString(comment))
|
||||
nc.getExtension().add(Factory.newExtension(EXT_COMMENT, Factory.newString_(comment), true));
|
||||
}
|
||||
|
||||
public static void markDeprecated(Element nc) {
|
||||
setDeprecated(nc);
|
||||
}
|
||||
|
||||
public static void addSubsumes(ConceptDefinitionComponent nc, String code) {
|
||||
nc.getModifierExtension().add(Factory.newExtension(EXT_SUBSUMES, Factory.newCode(code), true));
|
||||
}
|
||||
|
||||
public static void addDefinition(Element nc, String definition) {
|
||||
if (!Utilities.noString(definition))
|
||||
nc.getExtension().add(Factory.newExtension(EXT_DEFINITION, Factory.newString_(definition), true));
|
||||
}
|
||||
|
||||
public static void addDisplayHint(Element def, String hint) {
|
||||
if (!Utilities.noString(hint))
|
||||
def.getExtension().add(Factory.newExtension(EXT_DISPLAY_HINT, Factory.newString_(hint), true));
|
||||
}
|
||||
|
||||
public static String getDisplayHint(Element def) {
|
||||
return readStringExtension(def, EXT_DISPLAY_HINT);
|
||||
}
|
||||
|
||||
public static String readStringExtension(Element c, String uri) {
|
||||
Extension ex = ExtensionHelper.getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return null;
|
||||
if (ex.getValue() instanceof UriType)
|
||||
return ((UriType) ex.getValue()).getValue();
|
||||
if (!(ex.getValue() instanceof StringType))
|
||||
return null;
|
||||
return ((StringType) ex.getValue()).getValue();
|
||||
}
|
||||
|
||||
public static String readStringExtension(DomainResource c, String uri) {
|
||||
Extension ex = getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return null;
|
||||
if ((ex.getValue() instanceof StringType))
|
||||
return ((StringType) ex.getValue()).getValue();
|
||||
if ((ex.getValue() instanceof UriType))
|
||||
return ((UriType) ex.getValue()).getValue();
|
||||
if ((ex.getValue() instanceof MarkdownType))
|
||||
return ((MarkdownType) ex.getValue()).getValue();
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static PrimitiveType<Type> readPrimitiveExtension(DomainResource c, String uri) {
|
||||
Extension ex = getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return null;
|
||||
return (PrimitiveType<Type>) ex.getValue();
|
||||
}
|
||||
|
||||
public static boolean findStringExtension(Element c, String uri) {
|
||||
Extension ex = ExtensionHelper.getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return false;
|
||||
if (!(ex.getValue() instanceof StringType))
|
||||
return false;
|
||||
return !Utilities.noString(((StringType) ex.getValue()).getValue());
|
||||
}
|
||||
|
||||
public static Boolean readBooleanExtension(Element c, String uri) {
|
||||
Extension ex = ExtensionHelper.getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return null;
|
||||
if (!(ex.getValue() instanceof BooleanType))
|
||||
return null;
|
||||
return ((BooleanType) ex.getValue()).getValue();
|
||||
}
|
||||
|
||||
public static boolean findBooleanExtension(Element c, String uri) {
|
||||
Extension ex = ExtensionHelper.getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return false;
|
||||
if (!(ex.getValue() instanceof BooleanType))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getComment(ConceptDefinitionComponent c) {
|
||||
return readStringExtension(c, EXT_COMMENT);
|
||||
}
|
||||
|
||||
public static Boolean getDeprecated(Element c) {
|
||||
return readBooleanExtension(c, EXT_DEPRECATED);
|
||||
}
|
||||
|
||||
public static boolean hasComment(ConceptDefinitionComponent c) {
|
||||
return findStringExtension(c, EXT_COMMENT);
|
||||
}
|
||||
|
||||
public static boolean hasDeprecated(Element c) {
|
||||
return findBooleanExtension(c, EXT_DEPRECATED);
|
||||
}
|
||||
|
||||
public static List<CodeType> getSubsumes(ConceptDefinitionComponent c) {
|
||||
List<CodeType> res = new ArrayList<CodeType>();
|
||||
|
||||
for (Extension e : c.getExtension()) {
|
||||
if (EXT_SUBSUMES.equals(e.getUrl()))
|
||||
res.add((CodeType) e.getValue());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void addFlyOver(GroupComponent group, String text) {
|
||||
if (!Utilities.noString(text))
|
||||
group.getExtension().add(Factory.newExtension(EXT_FLYOVER, Factory.newString_(text), true));
|
||||
|
||||
}
|
||||
|
||||
public static void setQuestionType(GroupComponent group, String text) {
|
||||
if (!Utilities.noString(text))
|
||||
group.getExtension().add(Factory.newExtension(EXT_QTYPE, Factory.newString_(text), true));
|
||||
}
|
||||
|
||||
public static void setQuestionReference(GroupComponent group, String text) {
|
||||
if (!Utilities.noString(text))
|
||||
group.getExtension().add(Factory.newExtension(EXT_QREF, Factory.newString_(text), true));
|
||||
}
|
||||
|
||||
public static void addFlyOver(Element element, String text) {
|
||||
element.getExtension().add(Factory.newExtension(EXT_FLYOVER, Factory.newString_(text), true));
|
||||
}
|
||||
|
||||
public static void addFilterOnly(Reference element, boolean value) {
|
||||
element.getExtension().add(Factory.newExtension(EXTENSION_FILTER_ONLY, Factory.newBoolean(value), true));
|
||||
}
|
||||
|
||||
public static void addType(GroupComponent group, String value) {
|
||||
group.getExtension().add(Factory.newExtension(EXT_TYPE, Factory.newString_(value), true));
|
||||
}
|
||||
|
||||
public static void addReference(QuestionComponent group, String value) {
|
||||
group.getExtension().add(Factory.newExtension(EXT_REFERENCE, Factory.newString_(value), true));
|
||||
}
|
||||
|
||||
public static void addIdentifier(Element element, Identifier value) {
|
||||
element.getExtension().add(Factory.newExtension(EXT_IDENTIFIER, value, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the identity of the extension of interest
|
||||
* @return The extension, if on this element, else null
|
||||
*/
|
||||
public static Extension getExtension(DomainResource resource, String name) {
|
||||
if (name == null)
|
||||
return null;
|
||||
if (!resource.hasExtension())
|
||||
return null;
|
||||
for (Extension e : resource.getExtension()) {
|
||||
if (name.equals(e.getUrl()))
|
||||
return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Extension getExtension(Element el, String name) {
|
||||
if (name == null)
|
||||
return null;
|
||||
if (!el.hasExtension())
|
||||
return null;
|
||||
for (Extension e : el.getExtension()) {
|
||||
if (name.equals(e.getUrl()))
|
||||
return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setStringExtension(DomainResource resource, String uri, String value) {
|
||||
Extension ext = getExtension(resource, uri);
|
||||
if (ext != null)
|
||||
ext.setValue(new StringType(value));
|
||||
else
|
||||
resource.getExtension().add(new Extension(new UriType(uri)).setValue(new StringType(value)));
|
||||
}
|
||||
|
||||
public static String getOID(ValueSetCodeSystemComponent define) {
|
||||
return readStringExtension(define, EXT_OID);
|
||||
}
|
||||
|
||||
public static String getOID(ValueSet vs) {
|
||||
return readStringExtension(vs, EXT_OID);
|
||||
}
|
||||
|
||||
public static void setOID(ValueSetCodeSystemComponent define, String oid) throws FHIRFormatError, URISyntaxException {
|
||||
if (!oid.startsWith("urn:oid:"))
|
||||
throw new FHIRFormatError("Error in OID format");
|
||||
if (oid.startsWith("urn:oid:urn:oid:"))
|
||||
throw new FHIRFormatError("Error in OID format");
|
||||
define.getExtension().add(Factory.newExtension(EXT_OID, Factory.newUri(oid), false));
|
||||
}
|
||||
public static void setOID(ValueSet vs, String oid) throws FHIRFormatError, URISyntaxException {
|
||||
if (!oid.startsWith("urn:oid:"))
|
||||
throw new FHIRFormatError("Error in OID format");
|
||||
if (oid.startsWith("urn:oid:urn:oid:"))
|
||||
throw new FHIRFormatError("Error in OID format");
|
||||
vs.getExtension().add(Factory.newExtension(EXT_OID, Factory.newUri(oid), false));
|
||||
}
|
||||
|
||||
public static boolean hasLanguageTranslation(Element element, String lang) {
|
||||
for (Extension e : element.getExtension()) {
|
||||
if (e.getUrl().equals(EXT_TRANSLATION)) {
|
||||
Extension e1 = ExtensionHelper.getExtension(e, "lang");
|
||||
|
||||
if (e1 != null && e1.getValue() instanceof CodeType && ((CodeType) e.getValue()).getValue().equals(lang))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getLanguageTranslation(Element element, String lang) {
|
||||
for (Extension e : element.getExtension()) {
|
||||
if (e.getUrl().equals(EXT_TRANSLATION)) {
|
||||
Extension e1 = ExtensionHelper.getExtension(e, "lang");
|
||||
|
||||
if (e1 != null && e1.getValue() instanceof CodeType && ((CodeType) e.getValue()).getValue().equals(lang)) {
|
||||
e1 = ExtensionHelper.getExtension(e, "content");
|
||||
return ((StringType) e.getValue()).getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addLanguageTranslation(Element element, String lang, String value) {
|
||||
Extension extension = new Extension().setUrl(EXT_TRANSLATION);
|
||||
extension.addExtension().setUrl("lang").setValue(new StringType(lang));
|
||||
extension.addExtension().setUrl("content").setValue(new StringType(value));
|
||||
element.getExtension().add(extension);
|
||||
}
|
||||
|
||||
public static Type getAllowedUnits(ElementDefinition eld) {
|
||||
for (Extension e : eld.getExtension())
|
||||
if (e.getUrl().equals(EXT_ALLOWABLE_UNITS))
|
||||
return e.getValue();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setAllowableUnits(ElementDefinition eld, CodeableConcept cc) {
|
||||
for (Extension e : eld.getExtension())
|
||||
if (e.getUrl().equals(EXT_ALLOWABLE_UNITS)) {
|
||||
e.setValue(cc);
|
||||
return;
|
||||
}
|
||||
eld.getExtension().add(new Extension().setUrl(EXT_ALLOWABLE_UNITS).setValue(cc));
|
||||
}
|
||||
|
||||
public static List<Extension> getExtensions(Element element, String url) {
|
||||
List<Extension> results = new ArrayList<Extension>();
|
||||
for (Extension ex : element.getExtension())
|
||||
if (ex.getUrl().equals(url))
|
||||
results.add(ex);
|
||||
return results;
|
||||
}
|
||||
|
||||
public static List<Extension> getExtensions(DomainResource resource, String url) {
|
||||
List<Extension> results = new ArrayList<Extension>();
|
||||
for (Extension ex : resource.getExtension())
|
||||
if (ex.getUrl().equals(url))
|
||||
results.add(ex);
|
||||
return results;
|
||||
}
|
||||
|
||||
public static void addDEReference(DataElement de, String value) {
|
||||
for (Extension e : de.getExtension())
|
||||
if (e.getUrl().equals(EXT_CIMI_REFERENCE)) {
|
||||
e.setValue(new UriType(value));
|
||||
return;
|
||||
}
|
||||
de.getExtension().add(new Extension().setUrl(EXT_CIMI_REFERENCE).setValue(new UriType(value)));
|
||||
}
|
||||
|
||||
public static void setDeprecated(Element nc) {
|
||||
for (Extension e : nc.getExtension())
|
||||
if (e.getUrl().equals(EXT_DEPRECATED)) {
|
||||
e.setValue(new BooleanType(true));
|
||||
return;
|
||||
}
|
||||
nc.getExtension().add(new Extension().setUrl(EXT_DEPRECATED).setValue(new BooleanType(true)));
|
||||
}
|
||||
|
||||
public static void setExtension(Element focus, String url, Coding c) {
|
||||
for (Extension e : focus.getExtension())
|
||||
if (e.getUrl().equals(url)) {
|
||||
e.setValue(c);
|
||||
return;
|
||||
}
|
||||
focus.getExtension().add(new Extension().setUrl(url).setValue(c));
|
||||
}
|
||||
|
||||
public static void removeExtension(DomainResource focus, String url) {
|
||||
Iterator<Extension> i = focus.getExtension().iterator();
|
||||
while (i.hasNext()) {
|
||||
Extension e = i.next(); // must be called before you can call i.remove()
|
||||
if (e.getUrl().equals(url)) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeExtension(Element focus, String url) {
|
||||
Iterator<Extension> i = focus.getExtension().iterator();
|
||||
while (i.hasNext()) {
|
||||
Extension e = i.next(); // must be called before you can call i.remove()
|
||||
if (e.getUrl().equals(url)) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/*
|
||||
Copyright (c) 2011+, HL7, Inc
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||
endorse or promote products derived from this software without specific
|
||||
prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.instance.model.BooleanType;
|
||||
import org.hl7.fhir.instance.model.CodeType;
|
||||
import org.hl7.fhir.instance.model.CodeableConcept;
|
||||
import org.hl7.fhir.instance.model.Coding;
|
||||
import org.hl7.fhir.instance.model.DataElement;
|
||||
import org.hl7.fhir.instance.model.DomainResource;
|
||||
import org.hl7.fhir.instance.model.Element;
|
||||
import org.hl7.fhir.instance.model.ElementDefinition;
|
||||
import org.hl7.fhir.instance.model.Extension;
|
||||
import org.hl7.fhir.instance.model.ExtensionHelper;
|
||||
import org.hl7.fhir.instance.model.Factory;
|
||||
import org.hl7.fhir.instance.model.Identifier;
|
||||
import org.hl7.fhir.instance.model.IntegerType;
|
||||
import org.hl7.fhir.instance.model.MarkdownType;
|
||||
import org.hl7.fhir.instance.model.PrimitiveType;
|
||||
import org.hl7.fhir.instance.model.Questionnaire.GroupComponent;
|
||||
import org.hl7.fhir.instance.model.Questionnaire.QuestionComponent;
|
||||
import org.hl7.fhir.instance.model.Reference;
|
||||
import org.hl7.fhir.instance.model.StringType;
|
||||
import org.hl7.fhir.instance.model.Type;
|
||||
import org.hl7.fhir.instance.model.UriType;
|
||||
import org.hl7.fhir.instance.model.ValueSet;
|
||||
import org.hl7.fhir.instance.model.ValueSet.ConceptDefinitionComponent;
|
||||
import org.hl7.fhir.instance.model.ValueSet.ValueSetCodeSystemComponent;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage.Source;
|
||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||
import org.hl7.fhir.utilities.Utilities;
|
||||
|
||||
|
||||
public class ToolingExtensions {
|
||||
|
||||
// validated
|
||||
public static final String EXT_SUBSUMES = "http://hl7.org/fhir/StructureDefinition/valueset-subsumes";
|
||||
private static final String EXT_OID = "http://hl7.org/fhir/StructureDefinition/valueset-oid";
|
||||
public static final String EXT_DEPRECATED = "http://hl7.org/fhir/StructureDefinition/valueset-deprecated";
|
||||
public static final String EXT_DEFINITION = "http://hl7.org/fhir/StructureDefinition/valueset-definition";
|
||||
public static final String EXT_COMMENT = "http://hl7.org/fhir/StructureDefinition/valueset-comments";
|
||||
private static final String EXT_IDENTIFIER = "http://hl7.org/fhir/StructureDefinition/identifier";
|
||||
private static final String EXT_TRANSLATION = "http://hl7.org/fhir/StructureDefinition/translation";
|
||||
public static final String EXT_ISSUE_SOURCE = "http://hl7.org/fhir/StructureDefinition/operationoutcome-issue-source";
|
||||
public static final String EXT_DISPLAY_HINT = "http://hl7.org/fhir/StructureDefinition/structuredefinition-display-hint";
|
||||
public static final String EXT_REPLACED_BY = "http://hl7.org/fhir/StructureDefinition/valueset-replacedby";
|
||||
public static final String EXT_JSON_TYPE = "http://hl7.org/fhir/StructureDefinition/structuredefinition-json-type";
|
||||
public static final String EXT_XML_TYPE = "http://hl7.org/fhir/StructureDefinition/structuredefinition-xml-type";
|
||||
public static final String EXT_REGEX = "http://hl7.org/fhir/StructureDefinition/structuredefinition-regex";
|
||||
public static final String EXT_EXPRESSION = "http://hl7.org/fhir/StructureDefinition/structuredefinition-expression";
|
||||
public static final String EXT_SEARCH_EXPRESSION = "http://hl7.org/fhir/StructureDefinition/searchparameter-expression";
|
||||
|
||||
// unregistered?
|
||||
|
||||
public static final String EXT_FLYOVER = "http://hl7.org/fhir/Profile/questionnaire-extensions#flyover";
|
||||
private static final String EXT_QTYPE = "http://www.healthintersections.com.au/fhir/Profile/metadata#type";
|
||||
private static final String EXT_QREF = "http://www.healthintersections.com.au/fhir/Profile/metadata#reference";
|
||||
private static final String EXTENSION_FILTER_ONLY = "http://www.healthintersections.com.au/fhir/Profile/metadata#expandNeedsFilter";
|
||||
private static final String EXT_TYPE = "http://www.healthintersections.com.au/fhir/Profile/metadata#type";
|
||||
private static final String EXT_REFERENCE = "http://www.healthintersections.com.au/fhir/Profile/metadata#reference";
|
||||
private static final String EXT_ALLOWABLE_UNITS = "http://hl7.org/fhir/StructureDefinition/elementdefinition-allowedUnits";
|
||||
public static final String EXT_CIMI_REFERENCE = "http://hl7.org/fhir/StructureDefinition/cimi-reference";
|
||||
public static final String EXT_UNCLOSED = "http://hl7.org/fhir/StructureDefinition/valueset-unclosed";
|
||||
public static final String EXT_FMM_LEVEL = "http://hl7.org/fhir/StructureDefinition/structuredefinition-fmm";
|
||||
|
||||
|
||||
// specific extension helpers
|
||||
|
||||
public static Extension makeIssueSource(Source source) {
|
||||
Extension ex = new Extension();
|
||||
// todo: write this up and get it published with the pack (and handle the redirect?)
|
||||
ex.setUrl(ToolingExtensions.EXT_ISSUE_SOURCE);
|
||||
CodeType c = new CodeType();
|
||||
c.setValue(source.toString());
|
||||
ex.setValue(c);
|
||||
return ex;
|
||||
}
|
||||
|
||||
public static boolean hasExtension(DomainResource de, String url) {
|
||||
return getExtension(de, url) != null;
|
||||
}
|
||||
|
||||
public static boolean hasExtension(Element e, String url) {
|
||||
return getExtension(e, url) != null;
|
||||
}
|
||||
|
||||
public static void addStringExtension(DomainResource dr, String url, String content) {
|
||||
if (!Utilities.noString(content)) {
|
||||
Extension ex = getExtension(dr, url);
|
||||
if (ex != null)
|
||||
ex.setValue(new StringType(content));
|
||||
else
|
||||
dr.getExtension().add(Factory.newExtension(url, new StringType(content), true));
|
||||
}
|
||||
}
|
||||
|
||||
public static void addStringExtension(Element e, String url, String content) {
|
||||
if (!Utilities.noString(content)) {
|
||||
Extension ex = getExtension(e, url);
|
||||
if (ex != null)
|
||||
ex.setValue(new StringType(content));
|
||||
else
|
||||
e.getExtension().add(Factory.newExtension(url, new StringType(content), true));
|
||||
}
|
||||
}
|
||||
|
||||
public static void addIntegerExtension(DomainResource dr, String url, int value) {
|
||||
Extension ex = getExtension(dr, url);
|
||||
if (ex != null)
|
||||
ex.setValue(new IntegerType(value));
|
||||
else
|
||||
dr.getExtension().add(Factory.newExtension(url, new IntegerType(value), true));
|
||||
}
|
||||
|
||||
public static void addComment(Element nc, String comment) {
|
||||
if (!Utilities.noString(comment))
|
||||
nc.getExtension().add(Factory.newExtension(EXT_COMMENT, Factory.newString_(comment), true));
|
||||
}
|
||||
|
||||
public static void markDeprecated(Element nc) {
|
||||
setDeprecated(nc);
|
||||
}
|
||||
|
||||
public static void addSubsumes(ConceptDefinitionComponent nc, String code) {
|
||||
nc.getModifierExtension().add(Factory.newExtension(EXT_SUBSUMES, Factory.newCode(code), true));
|
||||
}
|
||||
|
||||
public static void addDefinition(Element nc, String definition) {
|
||||
if (!Utilities.noString(definition))
|
||||
nc.getExtension().add(Factory.newExtension(EXT_DEFINITION, Factory.newString_(definition), true));
|
||||
}
|
||||
|
||||
public static void addDisplayHint(Element def, String hint) {
|
||||
if (!Utilities.noString(hint))
|
||||
def.getExtension().add(Factory.newExtension(EXT_DISPLAY_HINT, Factory.newString_(hint), true));
|
||||
}
|
||||
|
||||
public static String getDisplayHint(Element def) {
|
||||
return readStringExtension(def, EXT_DISPLAY_HINT);
|
||||
}
|
||||
|
||||
public static String readStringExtension(Element c, String uri) {
|
||||
Extension ex = ExtensionHelper.getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return null;
|
||||
if (ex.getValue() instanceof UriType)
|
||||
return ((UriType) ex.getValue()).getValue();
|
||||
if (!(ex.getValue() instanceof StringType))
|
||||
return null;
|
||||
return ((StringType) ex.getValue()).getValue();
|
||||
}
|
||||
|
||||
public static String readStringExtension(DomainResource c, String uri) {
|
||||
Extension ex = getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return null;
|
||||
if ((ex.getValue() instanceof StringType))
|
||||
return ((StringType) ex.getValue()).getValue();
|
||||
if ((ex.getValue() instanceof UriType))
|
||||
return ((UriType) ex.getValue()).getValue();
|
||||
if ((ex.getValue() instanceof MarkdownType))
|
||||
return ((MarkdownType) ex.getValue()).getValue();
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static PrimitiveType<Type> readPrimitiveExtension(DomainResource c, String uri) {
|
||||
Extension ex = getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return null;
|
||||
return (PrimitiveType<Type>) ex.getValue();
|
||||
}
|
||||
|
||||
public static boolean findStringExtension(Element c, String uri) {
|
||||
Extension ex = ExtensionHelper.getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return false;
|
||||
if (!(ex.getValue() instanceof StringType))
|
||||
return false;
|
||||
return !Utilities.noString(((StringType) ex.getValue()).getValue());
|
||||
}
|
||||
|
||||
public static Boolean readBooleanExtension(Element c, String uri) {
|
||||
Extension ex = ExtensionHelper.getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return null;
|
||||
if (!(ex.getValue() instanceof BooleanType))
|
||||
return null;
|
||||
return ((BooleanType) ex.getValue()).getValue();
|
||||
}
|
||||
|
||||
public static boolean findBooleanExtension(Element c, String uri) {
|
||||
Extension ex = ExtensionHelper.getExtension(c, uri);
|
||||
if (ex == null)
|
||||
return false;
|
||||
if (!(ex.getValue() instanceof BooleanType))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static String getComment(ConceptDefinitionComponent c) {
|
||||
return readStringExtension(c, EXT_COMMENT);
|
||||
}
|
||||
|
||||
public static Boolean getDeprecated(Element c) {
|
||||
return readBooleanExtension(c, EXT_DEPRECATED);
|
||||
}
|
||||
|
||||
public static boolean hasComment(ConceptDefinitionComponent c) {
|
||||
return findStringExtension(c, EXT_COMMENT);
|
||||
}
|
||||
|
||||
public static boolean hasDeprecated(Element c) {
|
||||
return findBooleanExtension(c, EXT_DEPRECATED);
|
||||
}
|
||||
|
||||
public static List<CodeType> getSubsumes(ConceptDefinitionComponent c) {
|
||||
List<CodeType> res = new ArrayList<CodeType>();
|
||||
|
||||
for (Extension e : c.getExtension()) {
|
||||
if (EXT_SUBSUMES.equals(e.getUrl()))
|
||||
res.add((CodeType) e.getValue());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void addFlyOver(GroupComponent group, String text) {
|
||||
if (!Utilities.noString(text))
|
||||
group.getExtension().add(Factory.newExtension(EXT_FLYOVER, Factory.newString_(text), true));
|
||||
|
||||
}
|
||||
|
||||
public static void setQuestionType(GroupComponent group, String text) {
|
||||
if (!Utilities.noString(text))
|
||||
group.getExtension().add(Factory.newExtension(EXT_QTYPE, Factory.newString_(text), true));
|
||||
}
|
||||
|
||||
public static void setQuestionReference(GroupComponent group, String text) {
|
||||
if (!Utilities.noString(text))
|
||||
group.getExtension().add(Factory.newExtension(EXT_QREF, Factory.newString_(text), true));
|
||||
}
|
||||
|
||||
public static void addFlyOver(Element element, String text) {
|
||||
element.getExtension().add(Factory.newExtension(EXT_FLYOVER, Factory.newString_(text), true));
|
||||
}
|
||||
|
||||
public static void addFilterOnly(Reference element, boolean value) {
|
||||
element.getExtension().add(Factory.newExtension(EXTENSION_FILTER_ONLY, Factory.newBoolean(value), true));
|
||||
}
|
||||
|
||||
public static void addType(GroupComponent group, String value) {
|
||||
group.getExtension().add(Factory.newExtension(EXT_TYPE, Factory.newString_(value), true));
|
||||
}
|
||||
|
||||
public static void addReference(QuestionComponent group, String value) {
|
||||
group.getExtension().add(Factory.newExtension(EXT_REFERENCE, Factory.newString_(value), true));
|
||||
}
|
||||
|
||||
public static void addIdentifier(Element element, Identifier value) {
|
||||
element.getExtension().add(Factory.newExtension(EXT_IDENTIFIER, value, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the identity of the extension of interest
|
||||
* @return The extension, if on this element, else null
|
||||
*/
|
||||
public static Extension getExtension(DomainResource resource, String name) {
|
||||
if (name == null)
|
||||
return null;
|
||||
if (!resource.hasExtension())
|
||||
return null;
|
||||
for (Extension e : resource.getExtension()) {
|
||||
if (name.equals(e.getUrl()))
|
||||
return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Extension getExtension(Element el, String name) {
|
||||
if (name == null)
|
||||
return null;
|
||||
if (!el.hasExtension())
|
||||
return null;
|
||||
for (Extension e : el.getExtension()) {
|
||||
if (name.equals(e.getUrl()))
|
||||
return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setStringExtension(DomainResource resource, String uri, String value) {
|
||||
Extension ext = getExtension(resource, uri);
|
||||
if (ext != null)
|
||||
ext.setValue(new StringType(value));
|
||||
else
|
||||
resource.getExtension().add(new Extension(new UriType(uri)).setValue(new StringType(value)));
|
||||
}
|
||||
|
||||
public static String getOID(ValueSetCodeSystemComponent define) {
|
||||
return readStringExtension(define, EXT_OID);
|
||||
}
|
||||
|
||||
public static String getOID(ValueSet vs) {
|
||||
return readStringExtension(vs, EXT_OID);
|
||||
}
|
||||
|
||||
public static void setOID(ValueSetCodeSystemComponent define, String oid) throws FHIRFormatError, URISyntaxException {
|
||||
if (!oid.startsWith("urn:oid:"))
|
||||
throw new FHIRFormatError("Error in OID format");
|
||||
if (oid.startsWith("urn:oid:urn:oid:"))
|
||||
throw new FHIRFormatError("Error in OID format");
|
||||
define.getExtension().add(Factory.newExtension(EXT_OID, Factory.newUri(oid), false));
|
||||
}
|
||||
public static void setOID(ValueSet vs, String oid) throws FHIRFormatError, URISyntaxException {
|
||||
if (!oid.startsWith("urn:oid:"))
|
||||
throw new FHIRFormatError("Error in OID format");
|
||||
if (oid.startsWith("urn:oid:urn:oid:"))
|
||||
throw new FHIRFormatError("Error in OID format");
|
||||
vs.getExtension().add(Factory.newExtension(EXT_OID, Factory.newUri(oid), false));
|
||||
}
|
||||
|
||||
public static boolean hasLanguageTranslation(Element element, String lang) {
|
||||
for (Extension e : element.getExtension()) {
|
||||
if (e.getUrl().equals(EXT_TRANSLATION)) {
|
||||
Extension e1 = ExtensionHelper.getExtension(e, "lang");
|
||||
|
||||
if (e1 != null && e1.getValue() instanceof CodeType && ((CodeType) e.getValue()).getValue().equals(lang))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getLanguageTranslation(Element element, String lang) {
|
||||
for (Extension e : element.getExtension()) {
|
||||
if (e.getUrl().equals(EXT_TRANSLATION)) {
|
||||
Extension e1 = ExtensionHelper.getExtension(e, "lang");
|
||||
|
||||
if (e1 != null && e1.getValue() instanceof CodeType && ((CodeType) e.getValue()).getValue().equals(lang)) {
|
||||
e1 = ExtensionHelper.getExtension(e, "content");
|
||||
return ((StringType) e.getValue()).getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addLanguageTranslation(Element element, String lang, String value) {
|
||||
Extension extension = new Extension().setUrl(EXT_TRANSLATION);
|
||||
extension.addExtension().setUrl("lang").setValue(new StringType(lang));
|
||||
extension.addExtension().setUrl("content").setValue(new StringType(value));
|
||||
element.getExtension().add(extension);
|
||||
}
|
||||
|
||||
public static Type getAllowedUnits(ElementDefinition eld) {
|
||||
for (Extension e : eld.getExtension())
|
||||
if (e.getUrl().equals(EXT_ALLOWABLE_UNITS))
|
||||
return e.getValue();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setAllowableUnits(ElementDefinition eld, CodeableConcept cc) {
|
||||
for (Extension e : eld.getExtension())
|
||||
if (e.getUrl().equals(EXT_ALLOWABLE_UNITS)) {
|
||||
e.setValue(cc);
|
||||
return;
|
||||
}
|
||||
eld.getExtension().add(new Extension().setUrl(EXT_ALLOWABLE_UNITS).setValue(cc));
|
||||
}
|
||||
|
||||
public static List<Extension> getExtensions(Element element, String url) {
|
||||
List<Extension> results = new ArrayList<Extension>();
|
||||
for (Extension ex : element.getExtension())
|
||||
if (ex.getUrl().equals(url))
|
||||
results.add(ex);
|
||||
return results;
|
||||
}
|
||||
|
||||
public static List<Extension> getExtensions(DomainResource resource, String url) {
|
||||
List<Extension> results = new ArrayList<Extension>();
|
||||
for (Extension ex : resource.getExtension())
|
||||
if (ex.getUrl().equals(url))
|
||||
results.add(ex);
|
||||
return results;
|
||||
}
|
||||
|
||||
public static void addDEReference(DataElement de, String value) {
|
||||
for (Extension e : de.getExtension())
|
||||
if (e.getUrl().equals(EXT_CIMI_REFERENCE)) {
|
||||
e.setValue(new UriType(value));
|
||||
return;
|
||||
}
|
||||
de.getExtension().add(new Extension().setUrl(EXT_CIMI_REFERENCE).setValue(new UriType(value)));
|
||||
}
|
||||
|
||||
public static void setDeprecated(Element nc) {
|
||||
for (Extension e : nc.getExtension())
|
||||
if (e.getUrl().equals(EXT_DEPRECATED)) {
|
||||
e.setValue(new BooleanType(true));
|
||||
return;
|
||||
}
|
||||
nc.getExtension().add(new Extension().setUrl(EXT_DEPRECATED).setValue(new BooleanType(true)));
|
||||
}
|
||||
|
||||
public static void setExtension(Element focus, String url, Coding c) {
|
||||
for (Extension e : focus.getExtension())
|
||||
if (e.getUrl().equals(url)) {
|
||||
e.setValue(c);
|
||||
return;
|
||||
}
|
||||
focus.getExtension().add(new Extension().setUrl(url).setValue(c));
|
||||
}
|
||||
|
||||
public static void removeExtension(DomainResource focus, String url) {
|
||||
Iterator<Extension> i = focus.getExtension().iterator();
|
||||
while (i.hasNext()) {
|
||||
Extension e = i.next(); // must be called before you can call i.remove()
|
||||
if (e.getUrl().equals(url)) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeExtension(Element focus, String url) {
|
||||
Iterator<Extension> i = focus.getExtension().iterator();
|
||||
while (i.hasNext()) {
|
||||
Extension e = i.next(); // must be called before you can call i.remove()
|
||||
if (e.getUrl().equals(url)) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,64 +20,64 @@ package org.hl7.fhir.utilities;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
|
||||
public class OIDUtils {
|
||||
|
||||
/*
|
||||
2.16.840.1.113883.3.72.5.2 - NIST owns this
|
||||
2.16.840.1.113883.4.6 - National Provider Identifier
|
||||
2.16.840.1.113883.6.21 - UB92
|
||||
2.16.840.1.113883.6.69 - NDC
|
||||
*/
|
||||
|
||||
public static String getUriForOid(String r) {
|
||||
if (r.equals("2.16.840.1.113883.6.96"))
|
||||
return "http://snomed.info/sct";
|
||||
if (r.equals("2.16.840.1.113883.6.1"))
|
||||
return "http://loinc.org";
|
||||
if (r.equals("2.16.840.1.113883.6.8"))
|
||||
return "http://unitsofmeasure.org";
|
||||
if (r.equals("2.16.840.1.113883.6.3"))
|
||||
return "http://hl7.org/fhir/sid/icd-10";
|
||||
if (r.equals("2.16.840.1.113883.6.42"))
|
||||
return "http://hl7.org/fhir/sid/icd-9";
|
||||
if (r.equals("2.16.840.1.113883.6.104"))
|
||||
return "http://hl7.org/fhir/sid/icd-9";
|
||||
if (r.equals("2.16.840.1.113883.6.103"))
|
||||
return "http://hl7.org/fhir/sid/icd-9"; //todo: confirm this
|
||||
if (r.equals("2.16.840.1.113883.6.73"))
|
||||
return "http://hl7.org/fhir/sid/atc";
|
||||
if (r.equals("2.16.840.1.113883.3.26.1.1"))
|
||||
return "http://ncimeta.nci.nih.gov";
|
||||
if (r.equals("2.16.840.1.113883.3.26.1.1.1"))
|
||||
return "http://ncimeta.nci.nih.gov";
|
||||
if (r.equals("2.16.840.1.113883.6.88"))
|
||||
return "http://www.nlm.nih.gov/research/umls/rxnorm"; // todo: confirm this
|
||||
|
||||
if (r.equals("2.16.840.1.113883.5.1008"))
|
||||
return "http://hl7.org/fhir/v3/NullFlavor";
|
||||
if (r.equals("2.16.840.1.113883.5.111"))
|
||||
return "http://hl7.org/fhir/v3/RoleCode";
|
||||
if (r.equals("2.16.840.1.113883.5.4"))
|
||||
return "http://hl7.org/fhir/v3/ActCode";
|
||||
if (r.equals("2.16.840.1.113883.5.8"))
|
||||
return "http://hl7.org/fhir/v3/ActReason";
|
||||
if (r.equals("2.16.840.1.113883.5.83"))
|
||||
return "http://hl7.org/fhir/v3/ObservationInterpretation";
|
||||
if (r.equals("2.16.840.1.113883.6.238"))
|
||||
return "http://hl7.org/fhir/v3/Race";
|
||||
|
||||
if (r.equals("2.16.840.1.113883.6.59"))
|
||||
return "http://hl7.org/fhir/sid/cvx";
|
||||
if (r.equals("2.16.840.1.113883.12.292"))
|
||||
return "http://hl7.org/fhir/sid/cvx";
|
||||
|
||||
if (r.equals("2.16.840.1.113883.6.12"))
|
||||
return "http://www.ama-assn.org/go/cpt";
|
||||
|
||||
if (r.startsWith("2.16.840.1.113883.12."))
|
||||
return "http://hl7.org/fhir/sid/v2-"+r.substring(21);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class OIDUtils {
|
||||
|
||||
/*
|
||||
2.16.840.1.113883.3.72.5.2 - NIST owns this
|
||||
2.16.840.1.113883.4.6 - National Provider Identifier
|
||||
2.16.840.1.113883.6.21 - UB92
|
||||
2.16.840.1.113883.6.69 - NDC
|
||||
*/
|
||||
|
||||
public static String getUriForOid(String r) {
|
||||
if (r.equals("2.16.840.1.113883.6.96"))
|
||||
return "http://snomed.info/sct";
|
||||
if (r.equals("2.16.840.1.113883.6.1"))
|
||||
return "http://loinc.org";
|
||||
if (r.equals("2.16.840.1.113883.6.8"))
|
||||
return "http://unitsofmeasure.org";
|
||||
if (r.equals("2.16.840.1.113883.6.3"))
|
||||
return "http://hl7.org/fhir/sid/icd-10";
|
||||
if (r.equals("2.16.840.1.113883.6.42"))
|
||||
return "http://hl7.org/fhir/sid/icd-9";
|
||||
if (r.equals("2.16.840.1.113883.6.104"))
|
||||
return "http://hl7.org/fhir/sid/icd-9";
|
||||
if (r.equals("2.16.840.1.113883.6.103"))
|
||||
return "http://hl7.org/fhir/sid/icd-9"; //todo: confirm this
|
||||
if (r.equals("2.16.840.1.113883.6.73"))
|
||||
return "http://hl7.org/fhir/sid/atc";
|
||||
if (r.equals("2.16.840.1.113883.3.26.1.1"))
|
||||
return "http://ncimeta.nci.nih.gov";
|
||||
if (r.equals("2.16.840.1.113883.3.26.1.1.1"))
|
||||
return "http://ncimeta.nci.nih.gov";
|
||||
if (r.equals("2.16.840.1.113883.6.88"))
|
||||
return "http://www.nlm.nih.gov/research/umls/rxnorm"; // todo: confirm this
|
||||
|
||||
if (r.equals("2.16.840.1.113883.5.1008"))
|
||||
return "http://hl7.org/fhir/v3/NullFlavor";
|
||||
if (r.equals("2.16.840.1.113883.5.111"))
|
||||
return "http://hl7.org/fhir/v3/RoleCode";
|
||||
if (r.equals("2.16.840.1.113883.5.4"))
|
||||
return "http://hl7.org/fhir/v3/ActCode";
|
||||
if (r.equals("2.16.840.1.113883.5.8"))
|
||||
return "http://hl7.org/fhir/v3/ActReason";
|
||||
if (r.equals("2.16.840.1.113883.5.83"))
|
||||
return "http://hl7.org/fhir/v3/ObservationInterpretation";
|
||||
if (r.equals("2.16.840.1.113883.6.238"))
|
||||
return "http://hl7.org/fhir/v3/Race";
|
||||
|
||||
if (r.equals("2.16.840.1.113883.6.59"))
|
||||
return "http://hl7.org/fhir/sid/cvx";
|
||||
if (r.equals("2.16.840.1.113883.12.292"))
|
||||
return "http://hl7.org/fhir/sid/cvx";
|
||||
|
||||
if (r.equals("2.16.840.1.113883.6.12"))
|
||||
return "http://www.ama-assn.org/go/cpt";
|
||||
|
||||
if (r.startsWith("2.16.840.1.113883.12."))
|
||||
return "http://hl7.org/fhir/sid/v2-"+r.substring(21);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue