Addressing WG problems in kindling
This commit is contained in:
parent
3eb8ad3ab1
commit
c4f6fe4676
|
@ -0,0 +1,108 @@
|
|||
package org.hl7.fhir.r5.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.r5.elementmodel.Element;
|
||||
import org.hl7.fhir.r5.model.CanonicalResource;
|
||||
import org.hl7.fhir.r5.model.CompartmentDefinition;
|
||||
import org.hl7.fhir.r5.model.Constants;
|
||||
import org.hl7.fhir.r5.model.ContactPoint.ContactPointSystem;
|
||||
import org.hl7.fhir.utilities.HL7WorkGroups;
|
||||
import org.hl7.fhir.utilities.VersionUtilities;
|
||||
import org.hl7.fhir.utilities.xml.XMLUtil;
|
||||
|
||||
public class CanonicalResourceUtilities {
|
||||
|
||||
public static void setHl7WG(CanonicalResource cr, String wgc) {
|
||||
var wg = HL7WorkGroups.find(wgc);
|
||||
if (wg == null) {
|
||||
throw new Error("Unknown WG "+wgc);
|
||||
}
|
||||
ToolingExtensions.setCodeExtension(cr, ToolingExtensions.EXT_WORKGROUP, wg.getCode());
|
||||
cr.setPublisher("HL7 International / "+wg.getName());
|
||||
cr.getContact().clear();
|
||||
cr.addContact().addTelecom().setSystem(ContactPointSystem.URL).setValue(wg.getLink());
|
||||
}
|
||||
|
||||
public static void setHl7WG(CanonicalResource cr) {
|
||||
String wgc = ToolingExtensions.readStringExtension(cr, ToolingExtensions.EXT_WORKGROUP);
|
||||
if (wgc == null) {
|
||||
wgc = "fhir";
|
||||
}
|
||||
var wg = HL7WorkGroups.find(wgc);
|
||||
if (wg == null) {
|
||||
throw new Error("Unknown WG '"+wgc+"' in "+cr.fhirType()+"/"+cr.getIdBase());
|
||||
}
|
||||
ToolingExtensions.setCodeExtension(cr, ToolingExtensions.EXT_WORKGROUP, wg.getCode());
|
||||
cr.setPublisher("HL7 International / "+wg.getName());
|
||||
cr.getContact().clear();
|
||||
cr.addContact().addTelecom().setSystem(ContactPointSystem.URL).setValue(wg.getLink());
|
||||
}
|
||||
|
||||
public static void setHl7WG(Element res, String code) {
|
||||
if (VersionUtilities.getExtendedCanonicalResourceNames(res.getFHIRPublicationVersion().toCode()).contains(res.fhirType())) {
|
||||
var wg = HL7WorkGroups.find(code);
|
||||
if (wg == null) {
|
||||
throw new Error("Unknown WG "+code);
|
||||
}
|
||||
|
||||
Element ext = res.getExtension(ToolingExtensions.EXT_WORKGROUP);
|
||||
if (ext == null) {
|
||||
ext = res.addElement("extension");
|
||||
ext.setChildValue("url", ToolingExtensions.EXT_WORKGROUP);
|
||||
}
|
||||
ext.setChildValue("valueCode", code);
|
||||
res.setChildValue("publisher", "HL7 International / "+wg.getName());
|
||||
while (res.hasChild("contact")) {
|
||||
res.removeChild("contact");
|
||||
}
|
||||
Element c = res.addElement("contact");
|
||||
Element t = c.addElement("telecom");
|
||||
t.setChildValue("system", "url");
|
||||
t.setChildValue("value", wg.getLink());
|
||||
}
|
||||
}
|
||||
|
||||
public static void setHl7WG(org.w3c.dom.Element res, String code) {
|
||||
String rt = res.getNodeName();
|
||||
if (VersionUtilities.getExtendedCanonicalResourceNames("5.0.0").contains(rt)) {
|
||||
var wg = HL7WorkGroups.find(code);
|
||||
if (wg == null) {
|
||||
throw new Error("Unknown WG "+code);
|
||||
}
|
||||
|
||||
List<org.w3c.dom.Element> extensions = XMLUtil.getNamedChildren(res, "extension");
|
||||
org.w3c.dom.Element wgext = null;
|
||||
for (org.w3c.dom.Element ext : extensions) {
|
||||
String url = ext.getAttribute("url");
|
||||
if (ToolingExtensions.EXT_WORKGROUP.equals(url)) {
|
||||
wgext = ext;
|
||||
}
|
||||
}
|
||||
if (wgext == null) {
|
||||
wgext = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "extension");
|
||||
wgext.setAttribute("url", ToolingExtensions.EXT_WORKGROUP);
|
||||
org.w3c.dom.Element after = XMLUtil.getFirstChild(res, "modifierExtension", "url", "identifier", "version", "status");
|
||||
if (after == null) {
|
||||
after = XMLUtil.getLastChild(res, "id", "meta", "text", "implicitRules", "language", "text", "contained");
|
||||
if (after != null) {
|
||||
after = XMLUtil.getNextSibling(after);
|
||||
}
|
||||
}
|
||||
res.insertBefore(wgext, after);
|
||||
}
|
||||
XMLUtil.clearChildren(wgext);
|
||||
org.w3c.dom.Element valueCode = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "valueCode");
|
||||
wgext.appendChild(valueCode);
|
||||
valueCode.setAttribute("value", code);
|
||||
|
||||
org.w3c.dom.Element pub = XMLUtil.getNamedChild(res, "publisher");
|
||||
if (pub == null) {
|
||||
pub = res.getOwnerDocument().createElementNS(Constants.NS_FHIR_ROOT, "publisher");
|
||||
org.w3c.dom.Element after = XMLUtil.getFirstChild(res, "contact", "description", "useContext", "jurisdiction", "purpose", "copyright");
|
||||
res.insertBefore(pub, after);
|
||||
}
|
||||
pub.setAttribute("value", "HL7 International / "+wg.getName());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -875,7 +875,7 @@ public class ToolingExtensions {
|
|||
Iterator<Extension> i = focus.getExtension().iterator();
|
||||
while (i.hasNext()) {
|
||||
Extension e = i.next(); // must be called before you can call i.remove()
|
||||
if (e.getUrl().equals(url)) {
|
||||
if (url.equals(e.getUrl())) {
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,11 +125,11 @@ public class HL7WorkGroups {
|
|||
case "sd": return "Structured Documents";
|
||||
case "sec": return "Security";
|
||||
case "soa": return "Services Oriented Architecture";
|
||||
case "ti": return "Terminology Infrastructure";
|
||||
case "ti": return "Vocabulary";
|
||||
case "tsmg": return "Terminology Services Management Group (TSMG)";
|
||||
case "us": return "US Realm Steering Committee";
|
||||
case "v2": return "V2 Management Group";
|
||||
case "vocab": return "Vocabulary";
|
||||
case "vocab": return "Terminology Infrastructure";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ import org.w3c.dom.Attr;
|
|||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.w3c.dom.ls.DOMImplementationLS;
|
||||
import org.w3c.dom.ls.LSSerializer;
|
||||
import org.xml.sax.SAXException;
|
||||
|
@ -601,5 +602,36 @@ public class XMLUtil {
|
|||
return e == null ? null : e.getTextContent();
|
||||
}
|
||||
|
||||
|
||||
public static Element getFirstChild(Element res, String... names) {
|
||||
Element node = getFirstChild(res);
|
||||
while (node != null && !Utilities.existsInList(node.getLocalName(), names)) {
|
||||
node = getNextSibling(node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static Element getLastChild(Element res, String... names) {
|
||||
Element result = null;
|
||||
Element node = getFirstChild(res);
|
||||
while (node != null) {
|
||||
if (Utilities.existsInList(node.getLocalName(), names)) {
|
||||
result = node;
|
||||
}
|
||||
node = getNextSibling(node);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void clearChildren(Node node) {
|
||||
NodeList nodeList = node.getChildNodes();
|
||||
for (int i = nodeList.getLength() - 1; i >= 0; i--) {
|
||||
Node item = nodeList.item(i);
|
||||
if (item.hasChildNodes()) {
|
||||
clearChildren(item);
|
||||
}
|
||||
node.removeChild(item);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue