Merge remote-tracking branch 'origin/master'

This commit is contained in:
Grahame Grieve 2023-05-07 11:04:07 -05:00
commit bcb0656ff5
4 changed files with 33 additions and 20 deletions

View File

@ -32,14 +32,7 @@ import java.io.PrintStream;
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.exceptions.FHIRException;
@ -77,6 +70,7 @@ import org.hl7.fhir.utilities.xhtml.XhtmlNode;
*
*/
public class Element extends Base {
private static final HashSet<String> extensionList = new HashSet<>(Arrays.asList("extension", "modifierExtension"));
public enum SpecialElement {
CONTAINED, BUNDLE_ENTRY, BUNDLE_OUTCOME, BUNDLE_ISSUES, PARAMETER, LOGICAL;
@ -1070,7 +1064,7 @@ public class Element extends Base {
public Element getExtension(String url) {
if (children != null) {
for (Element child : children) {
if (Utilities.existsInList(child.getName(), "extension", "modifierExtension")) {
if (extensionList.contains(child.getName())) {
String u = child.getChildValue("url");
if (url.equals(u)) {
return child;

View File

@ -301,7 +301,9 @@ public abstract class Element extends Base implements IBaseHasExtensions, IBaseE
}
public boolean isEmpty() {
return super.isEmpty() && ca.uhn.fhir.util.ElementUtil.isEmpty(id, extension);
boolean idIsEmpty = id == null || id.isEmpty();
boolean extensionIsEmpty = extension == null || extension.size() == 0;
return super.isEmpty() && idIsEmpty && extensionIsEmpty;
}
// Manual code (from Configuration.txt):
@ -393,8 +395,12 @@ public abstract class Element extends Base implements IBaseHasExtensions, IBaseE
* @return an unmodifiable list containing all extensions on this element which match the given URL
*/
public List<Extension> getExtensionsByUrl(String theUrl) {
org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null");
ArrayList<Extension> retVal = new ArrayList<Extension>();
if (theUrl == null) {
throw new NullPointerException("theUrl must not be null");
} else if (theUrl.length() == 0) {
throw new IllegalArgumentException("theUrl must not be empty");
}
ArrayList<Extension> retVal = new ArrayList<>();
for (Extension next : getExtension()) {
if (theUrl.equals(next.getUrl())) {
retVal.add(next);
@ -411,7 +417,17 @@ public abstract class Element extends Base implements IBaseHasExtensions, IBaseE
* @param theUrl The URL. Must not be blank or null.
*/
public boolean hasExtension(String theUrl) {
return !getExtensionsByUrl(theUrl).isEmpty();
if (extension == null || extension.size() == 0) {
return false;
}
for (Extension ext : extension) {
if (theUrl.equals(ext.getUrl())) {
return true;
}
}
return false;
}
/**

View File

@ -127,11 +127,12 @@ public abstract class PrimitiveType<T> extends DataType implements IPrimitiveTyp
public boolean hasValue() {
return !StringUtils.isBlank(getValueAsString());
}
@Override
public boolean isEmpty() {
return super.isEmpty() && StringUtils.isBlank(getValueAsString());
}
@Override
public boolean isEmpty() {
String value = getValueAsString();
return !super.isEmpty() || (value != null && value.length() > 0);
}
public boolean isPrimitive() {
return true;

View File

@ -32,13 +32,15 @@ package org.hl7.fhir.r5.utils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
public class TypesUtilities {
private static final HashSet<String> primitiveTypes = new HashSet<>(Arrays.asList("boolean", "integer", "integer64", "string", "decimal", "uri", "url", "canonical", "base64Binary", "instant", "date", "dateTime", "time", "code", "oid", "id", "uuid", "markdown", "unsignedInt", "positiveInt", "xhtml"));
public enum TypeClassification {
PRIMITIVE, DATATYPE, METADATATYPE, SPECIAL;
@ -170,6 +172,6 @@ public class TypesUtilities {
}
public static boolean isPrimitive(String code) {
return Utilities.existsInList(code, "boolean", "integer", "integer64", "string", "decimal", "uri", "url", "canonical", "base64Binary", "instant", "date", "dateTime", "time", "code", "oid", "id", "uuid", "markdown", "unsignedInt", "positiveInt", "xhtml");
return primitiveTypes.contains(code);
}
}