diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java index c5efe3318..7bad1a90f 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java @@ -120,7 +120,7 @@ public abstract class ParserBase { public Element parseSingle(InputStream stream) throws IOException, FHIRFormatError, DefinitionException, FHIRException { List res = parse(stream); - if (res.size() == 1) { + if (res.size() == 0) { throw new FHIRException("Parsing FHIR content returned no elements in a context where one element is required"); } if (res.size() != 1) { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CanonicalResource.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CanonicalResource.java index ad40e273c..8f6c6ab74 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CanonicalResource.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/CanonicalResource.java @@ -35,6 +35,10 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.json.JsonUtilities; + +import com.google.gson.JsonObject; + import org.hl7.fhir.r5.model.Enumerations.*; import org.hl7.fhir.instance.model.api.IBaseBackboneElement; import org.hl7.fhir.exceptions.FHIRException; @@ -568,5 +572,14 @@ public abstract class CanonicalResource extends DomainResource { return null; } + public String getOid() { + for (Identifier id : getIdentifier()) { + if ("urn:ietf:rfc:3986".equals(id.getSystem()) && id.hasValue() && id.getValue().startsWith("urn:oid:")) { + return id.getValue().substring(8); + } + } + return null; + } + } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ConceptMapUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ConceptMapUtilities.java new file mode 100644 index 000000000..3878c0fda --- /dev/null +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/ConceptMapUtilities.java @@ -0,0 +1,34 @@ +package org.hl7.fhir.r5.terminologies; + +import org.hl7.fhir.r5.model.ConceptMap; +import org.hl7.fhir.r5.model.Identifier; +import org.hl7.fhir.r5.model.ValueSet; + +public class ConceptMapUtilities { + + public static boolean hasOID(ConceptMap cm) { + return getOID(cm) != null; + } + + public static String getOID(ConceptMap cm) { + for (Identifier id : cm.getIdentifier()) { + if ("urn:ietf:rfc:3986".equals(id.getSystem()) && id.hasValue() && id.getValue().startsWith("urn:oid:")) + return id.getValue().substring(8); + } + return null; + } + + public static void setOID(ConceptMap cm, String oid) { + if (!oid.startsWith("urn:oid:")) + oid = "urn:oid:" + oid; + for (Identifier id : cm.getIdentifier()) { + if ("urn:ietf:rfc:3986".equals(id.getSystem()) && id.hasValue() && id.getValue().startsWith("urn:oid:")) { + id.setValue(oid); + return; + } + } + cm.addIdentifier().setSystem("urn:ietf:rfc:3986").setValue(oid); + } + + +} diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLUtil.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLUtil.java index 34ba270a5..e2b6f6679 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLUtil.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xml/XMLUtil.java @@ -461,6 +461,13 @@ public class XMLUtil { return builder.parse(new FileInputStream(filename)); } + public static Document parseFileToDom(String filename, boolean ns) throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(ns); + DocumentBuilder builder = factory.newDocumentBuilder(); + return builder.parse(new FileInputStream(filename)); + } + public static Element getLastChild(Element e) { if (e == null) return null;