From fa1e0c5a7127b64f25a0577c766e1821067aad53 Mon Sep 17 00:00:00 2001 From: Sean McIlvenna Date: Sun, 7 May 2023 10:03:12 -0500 Subject: [PATCH] Changes based on performance profiling validation of a large Bundle of 32 patients Reduced execution time from >2 minutes to 36 seconds --- .../org/hl7/fhir/r5/elementmodel/Element.java | 12 +++------- .../java/org/hl7/fhir/r5/model/Element.java | 24 +++++++++++++++---- .../org/hl7/fhir/r5/model/PrimitiveType.java | 11 +++++---- .../org/hl7/fhir/r5/utils/TypesUtilities.java | 6 +++-- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java index 3937253a3..24b680eb7 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Element.java @@ -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 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; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Element.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Element.java index 07c81b5d1..b93f37abb 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Element.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/Element.java @@ -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 getExtensionsByUrl(String theUrl) { - org.apache.commons.lang3.Validate.notBlank(theUrl, "theUrl must not be blank or null"); - ArrayList retVal = new ArrayList(); + 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 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; } /** diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/PrimitiveType.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/PrimitiveType.java index 49ac41018..fac70c899 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/PrimitiveType.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/PrimitiveType.java @@ -127,11 +127,12 @@ public abstract class PrimitiveType 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; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/TypesUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/TypesUtilities.java index 928e74f41..9a98a5f75 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/TypesUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/TypesUtilities.java @@ -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 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); } } \ No newline at end of file