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