Merge pull request #911 from hapifhir/gg-202209-oids

Gg 202209 oids
This commit is contained in:
Grahame Grieve 2022-09-04 08:13:06 +10:00 committed by GitHub
commit be293a31d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 13 deletions

View File

@ -120,6 +120,9 @@ public abstract class ParserBase {
public Element parseSingle(InputStream stream) throws IOException, FHIRFormatError, DefinitionException, FHIRException {
List<NamedElement> res = parse(stream);
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) {
throw new FHIRException("Parsing FHIR content returned multiple elements in a context where only one element is allowed");
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -38,8 +38,6 @@ public class BuildExtensions extends ToolingExtensions {
public static final String EXT_WEBSITE = "http://hl7.org/fhir/build/StructureDefinition/website";
public static final String EXT_EMAIL = "http://hl7.org/fhir/build/StructureDefinition/email";
public static final String EXT_COPYRIGHT = "http://hl7.org/fhir/build/StructureDefinition/copyright";
public static final String EXT_CS_OID = "http://hl7.org/fhir/build/StructureDefinition/cs-oid";
public static final String EXT_VS_OID = "http://hl7.org/fhir/build/StructureDefinition/vs-oid";
public static final String EXT_STATUS = "http://hl7.org/fhir/build/StructureDefinition/status";
public static final String EXT_INTRODUCTION = "http://hl7.org/fhir/build/StructureDefinition/introduction";
public static final String EXT_NOTES = "http://hl7.org/fhir/build/StructureDefinition/notes";

View File

@ -153,7 +153,6 @@ public class TypesUtilities {
// metadata types
res.add(new WildcardInformation("ContactDetail", TypeClassification.METADATATYPE));
res.add(new WildcardInformation("Contributor", TypeClassification.METADATATYPE));
res.add(new WildcardInformation("DataRequirement", TypeClassification.METADATATYPE));
res.add(new WildcardInformation("Expression", TypeClassification.METADATATYPE));
res.add(new WildcardInformation("ParameterDefinition", TypeClassification.METADATATYPE));

View File

@ -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;

View File

@ -720,5 +720,5 @@ TX_SERVER_NO_BATCH_RESPONSE = The server return null from a batch validation req
BUNDLE_POSSSIBLE_MATCHES = The bundle contains no match for {1} by the rules of Bundle reference resolution, but it has multiple resources that match {0} by resource type and id
BUNDLE_BUNDLE_POSSIBLE_MATCH_NO_FU = Entry {0} matches the reference {1} by type and id but it does not match the full target URL {2} by Bundle resolution rules
BUNDLE_BUNDLE_POSSIBLE_MATCH_WRONG_FU = Entry {0} matches the reference {1} by type and id but it''s fullUrl {2} does not match the full target URL {3} by Bundle resolution rules
SD_ILLEGAL_CHARACTERISTICS = This element has a {0} but the types to do not make this kind of constraint relevant
SD_ILLEGAL_CHARACTERISTICS = This element has a {0} but the types {1} to do not make this kind of constraint relevant
SD_VALUE_COMPLEX_FIXED = For the complex type {0}, consider using a pattern rather than a fixed value to avoid over-constraining the instance

View File

@ -149,7 +149,7 @@ public class StructureDefinitionValidator extends BaseValidator {
addCharacteristics(tcharacteristics, tc);
characteristics.addAll(tcharacteristics);
if (type.hasChildren("targetProfile")) {
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), tcharacteristics.contains("has-target") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "targetProfile");
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), tcharacteristics.contains("has-target") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "targetProfile", tc);
}
// check the stated profile - must be a constraint on the type
if (snapshot || sd != null) {
@ -165,7 +165,7 @@ public class StructureDefinitionValidator extends BaseValidator {
}
if (element.hasChild("binding")) {
if (!typeCodes.isEmpty()) {
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("can-bind") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "Binding");
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("can-bind") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "Binding", typeCodes);
}
Element binding = element.getNamedChild("binding");
validateBinding(errors, binding, stack.push(binding, -1, null, null), typeCodes, snapshot, element.getNamedChildValue("path"));
@ -176,22 +176,22 @@ public class StructureDefinitionValidator extends BaseValidator {
}
if (!typeCodes.isEmpty()) {
if (element.hasChild("maxLength")) {
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("has-length") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "MaxLength");
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("has-length") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "MaxLength", typeCodes);
}
if (element.hasExtension(ToolingExtensions.EXT_MIN_LENGTH)) {
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("has-length") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "MinLength Extension");
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("has-length") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "MinLength Extension", typeCodes);
}
if (element.hasChild("minValue")) {
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("has-range") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "MinValue");
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("has-range") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "MinValue", typeCodes);
}
if (element.hasChild("maxValue")) {
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("has-range") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "MaxValue");
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("has-range") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "MaxValue", typeCodes);
}
if (element.hasExtension(ToolingExtensions.EXT_MAX_DECIMALS)) {
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("is-continuous") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "Max Decimal Places Extension");
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("is-continuous") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "Max Decimal Places Extension", typeCodes);
}
if (element.hasExtension(ToolingExtensions.EXT_MAX_SIZE)) {
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("has-size") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "Max Size");
rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), characteristics.contains("has-size") , I18nConstants.SD_ILLEGAL_CHARACTERISTICS, "Max Size", typeCodes);
}
}
// in a snapshot, we validate that fixedValue, pattern, and defaultValue, if present, are all of the right type
@ -285,7 +285,7 @@ public class StructureDefinitionValidator extends BaseValidator {
case "Dosage" : return addCharacteristicsForType(set);
case "Meta" :return addCharacteristicsForType(set);
case "Resource" :return addCharacteristicsForType(set);
case "Extension" :return addCharacteristicsForType(set);
case "Extension" :return addCharacteristicsForType(set, "can-bind");
case "Narrative" :return addCharacteristicsForType(set);
case "Element" :return addCharacteristicsForType(set);
case "BackboneElement" :return addCharacteristicsForType(set);