diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/MetaUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/MetaUtil.java index 1740172784f7..9a685093a6f7 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/MetaUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/MetaUtil.java @@ -39,6 +39,7 @@ import java.util.stream.Collectors; import static org.apache.commons.lang3.StringUtils.defaultString; +import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank; public class MetaUtil { @@ -101,9 +102,13 @@ private static String getSourceR4Plus(FhirContext theFhirContext, IBaseMetaType public static void populateResourceSource( FhirContext theFhirContext, String theProvenanceSourceUri, String theProvenanceRequestId, R theRetVal) { - String sourceString = cleanProvenanceSourceUriOrEmpty(theProvenanceSourceUri); - if (isNotBlank(theProvenanceRequestId)) { - sourceString = sourceString + "#" + theProvenanceRequestId; + String cleanedProvenanceSourceUri = cleanProvenanceSourceUriOrEmpty(theProvenanceSourceUri); + String sourceString = ""; + + if (isBlank(cleanedProvenanceSourceUri)) { + sourceString = theProvenanceRequestId; + } else { + sourceString = cleanedProvenanceSourceUri + "#" + theProvenanceRequestId; } if (isNotBlank(sourceString)) {