From fd73a593ea26a69e2de8be435dfad7cee74f5561 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 25 Oct 2019 08:50:34 -0400 Subject: [PATCH] Work on merge --- .../context/RuntimeChildChoiceDefinition.java | 2 -- .../java/ca/uhn/fhir/parser/XmlParser.java | 23 +++++++++++-------- .../extractor/BaseSearchParamExtractor.java | 16 +++++++++++++ .../extractor/SearchParamExtractorR4.java | 6 ++--- .../BaseStructureSpreadsheetParser.java | 20 ++++++++-------- 5 files changed, 43 insertions(+), 24 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java index 9acae772f0f..2c39f35ece8 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java @@ -93,8 +93,6 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini boolean nonPreferred = false; if (IBaseResource.class.isAssignableFrom(next)) { elementName = getElementName() + StringUtils.capitalize(next.getSimpleName()); - List> types = new ArrayList>(); - types.add((Class) next); nextDef = findResourceReferenceDefinition(theClassToElementDefinitions); myNameToChildDefinition.put(getElementName() + "Reference", nextDef); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java index c1b866a0489..70b31374cfe 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java @@ -43,6 +43,7 @@ import java.io.Writer; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Optional; import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; @@ -236,9 +237,9 @@ public class XmlParser extends BaseParser { switch (childDef.getChildType()) { case ID_DATATYPE: { - IIdType value = IIdType.class.cast(theElement); + IIdType value = (IIdType) theElement; String encodedValue = "id".equals(theChildName) ? value.getIdPart() : value.getValue(); - if (StringUtils.isNotBlank(encodedValue) || !super.hasNoExtensions(value)) { + if (StringUtils.isNotBlank(encodedValue) || !hasNoExtensions(value)) { theEventWriter.writeStartElement(theChildName); if (StringUtils.isNotBlank(encodedValue)) { theEventWriter.writeAttribute("value", encodedValue); @@ -249,9 +250,9 @@ public class XmlParser extends BaseParser { break; } case PRIMITIVE_DATATYPE: { - IPrimitiveType pd = IPrimitiveType.class.cast(theElement); + IPrimitiveType pd = (IPrimitiveType) theElement; String value = pd.getValueAsString(); - if (value != null || !super.hasNoExtensions(pd)) { + if (value != null || !hasNoExtensions(pd)) { theEventWriter.writeStartElement(theChildName); String elementId = getCompositeElementId(theElement); if (isNotBlank(elementId)) { @@ -308,14 +309,14 @@ public class XmlParser extends BaseParser { break; } case PRIMITIVE_XHTML: { - XhtmlDt dt = XhtmlDt.class.cast(theElement); + XhtmlDt dt = (XhtmlDt) theElement; if (dt.hasContent()) { encodeXhtml(dt, theEventWriter); } break; } case PRIMITIVE_XHTML_HL7ORG: { - IBaseXhtml dt = IBaseXhtml.class.cast(theElement); + IBaseXhtml dt = (IBaseXhtml) theElement; if (!dt.isEmpty()) { // TODO: this is probably not as efficient as it could be XhtmlDt hdt = new XhtmlDt(); @@ -354,17 +355,19 @@ public class XmlParser extends BaseParser { } if (nextChild instanceof RuntimeChildNarrativeDefinition) { - INarrative narr = (INarrative) nextChild.getAccessor().getFirstValueOrNull(theElement); + Optional narr = nextChild.getAccessor().getFirstValueOrNull(theElement); INarrativeGenerator gen = myContext.getNarrativeGenerator(); - if (gen != null && (narr == null || narr.isEmpty())) { + if (gen != null && (narr.isPresent() == false || narr.get().isEmpty())) { gen.populateResourceNarrative(myContext, theResource); + narr = nextChild.getAccessor().getFirstValueOrNull(theElement); } - if (narr != null && narr.isEmpty() == false) { + + if (narr.isPresent() && narr.get().isEmpty() == false) { RuntimeChildNarrativeDefinition child = (RuntimeChildNarrativeDefinition) nextChild; String childName = nextChild.getChildNameByDatatype(child.getDatatype()); BaseRuntimeElementDefinition type = child.getChildByName(childName); - encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, narr, childName, type, null, theContainedResource, nextChildElem, theEncodeContext); + encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, narr.get(), childName, type, null, theContainedResource, nextChildElem, theEncodeContext); continue; } } diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java index 1a8f4739d90..8f9b4cf7152 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/BaseSearchParamExtractor.java @@ -24,7 +24,11 @@ import ca.uhn.fhir.context.BaseRuntimeElementDefinition; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeSearchParam; +import ca.uhn.fhir.jpa.model.entity.BaseResourceIndexedSearchParam; import ca.uhn.fhir.jpa.model.entity.ModelConfig; +import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString; +import ca.uhn.fhir.jpa.model.entity.ResourceTable; +import ca.uhn.fhir.jpa.model.util.StringNormalizer; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import org.apache.commons.lang3.ObjectUtils; import org.hl7.fhir.instance.model.api.IBase; @@ -37,6 +41,7 @@ import java.util.*; import java.util.function.Supplier; import java.util.regex.Pattern; +import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; public abstract class BaseSearchParamExtractor implements ISearchParamExtractor { @@ -62,6 +67,17 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor mySearchParamRegistry = theSearchParamRegistry; } + protected void addSearchTerm(ResourceTable theEntity, Set retVal, String resourceName, String searchTerm) { + if (isBlank(searchTerm)) { + return; + } + retVal.add(createResourceIndexedSearchParamString(theEntity, resourceName, searchTerm)); + } + + protected void addStringParam(ResourceTable theEntity, Set retVal, RuntimeSearchParam nextSpDef, String value) { + retVal.add(createResourceIndexedSearchParamString(theEntity, nextSpDef.getName(), value)); + } + protected Set> getIgnoredForSearchDatatypes() { return myIgnoredForSearchDatatypes; } diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR4.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR4.java index 6a8ba085524..eff3ff4e251 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR4.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorR4.java @@ -690,8 +690,8 @@ public class SearchParamExtractorR4 extends BaseSearchParamExtractor implements * Override parent because we're using FHIRPath here */ @Override - protected List extractValues(String thePaths, IBaseResource theResource) { - List values = new ArrayList<>(); + protected List extractValues(String thePaths, IBaseResource theResource) { + List values = new ArrayList<>(); String[] nextPathsSplit = SPLIT_R4.split(thePaths); for (String nextPath : nextPathsSplit) { List allValues; @@ -707,7 +707,7 @@ public class SearchParamExtractorR4 extends BaseSearchParamExtractor implements } for (int i = 0; i < values.size(); i++) { - Object nextObject = values.get(i); + IBase nextObject = values.get(i); if (nextObject instanceof Extension) { Extension nextExtension = (Extension) nextObject; nextObject = nextExtension.getValue(); diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java index b73f4042a9b..8eec3e9f203 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureSpreadsheetParser.java @@ -110,7 +110,6 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser // Map blockFullNameToShortName = new // HashMap(); - Map> pathToResourceTypes = new HashMap>(); List blockCopies = new ArrayList(); for (int i = 2; i < rows.getLength(); i++) { Element nextRow = (Element) rows.item(i); @@ -161,8 +160,6 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser scanForSimpleSetters(elem); } - pathToResourceTypes.put(name, elem.getType()); - } postProcess(resource); @@ -241,12 +238,17 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser continue; } nextName = nextName.toLowerCase().trim().replace(".", ""); - if ("name".equals(nextName) || "binding name".equals(nextName)) { - colName = j; - } else if ("reference".equals(nextName)) { - colRef = j; - } else if ("conformance".equals(nextName)) { - colStrength = j; + switch (nextName) { + case "name": + case "binding name": + colName = j; + break; + case "reference": + colRef = j; + break; + case "conformance": + colStrength = j; + break; } }