diff --git a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java index e7f127b80..fa7f79cb2 100644 --- a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java +++ b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/ProfileUtilities.java @@ -891,7 +891,7 @@ public class ProfileUtilities { if (derived.hasDefinitionElement()) { if (derived.getDefinition().startsWith("...")) - base.setDefinition(base.getDefinition()+"\r\n"+derived.getDefinition().substring(3)); + base.setDefinition(Utilities.appendDerivedTextToBase(base.getDefinition(), derived.getDefinition())); else if (!Base.compareDeep(derived.getDefinitionElement(), base.getDefinitionElement(), false)) base.setDefinitionElement(derived.getDefinitionElement().copy()); else if (trimDifferential) @@ -902,7 +902,7 @@ public class ProfileUtilities { if (derived.hasCommentsElement()) { if (derived.getComments().startsWith("...")) - base.setComments(base.getComments()+"\r\n"+derived.getComments().substring(3)); + base.setComments(Utilities.appendDerivedTextToBase(base.getComments(), derived.getComments())); else if (!Base.compareDeep(derived.getCommentsElement(), base.getCommentsElement(), false)) base.setCommentsElement(derived.getCommentsElement().copy()); else if (trimDifferential) @@ -913,7 +913,7 @@ public class ProfileUtilities { if (derived.hasLabelElement()) { if (derived.getLabel().startsWith("...")) - base.setLabel(base.getLabel()+"\r\n"+derived.getLabel().substring(3)); + base.setLabel(Utilities.appendDerivedTextToBase(base.getLabel(), derived.getLabel())); else if (!Base.compareDeep(derived.getLabelElement(), base.getLabelElement(), false)) base.setLabelElement(derived.getLabelElement().copy()); else if (trimDifferential) @@ -924,7 +924,7 @@ public class ProfileUtilities { if (derived.hasRequirementsElement()) { if (derived.getRequirements().startsWith("...")) - base.setRequirements(base.getRequirements()+"\r\n"+derived.getRequirements().substring(3)); + base.setRequirements(Utilities.appendDerivedTextToBase(base.getRequirements(), derived.getRequirements())); else if (!Base.compareDeep(derived.getRequirementsElement(), base.getRequirementsElement(), false)) base.setRequirementsElement(derived.getRequirementsElement().copy()); else if (trimDifferential) diff --git a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java index 5f671340f..29a087deb 100644 --- a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java +++ b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/ProfileUtilities.java @@ -892,7 +892,7 @@ public class ProfileUtilities { if (derived.hasDefinitionElement()) { if (derived.getDefinition().startsWith("...")) - base.setDefinition(base.getDefinition()+"\r\n"+derived.getDefinition().substring(3)); + base.setDefinition(Utilities.appendDerivedTextToBase(base.getDefinition(), derived.getDefinition())); else if (!Base.compareDeep(derived.getDefinitionElement(), base.getDefinitionElement(), false)) base.setDefinitionElement(derived.getDefinitionElement().copy()); else if (trimDifferential) @@ -903,7 +903,7 @@ public class ProfileUtilities { if (derived.hasCommentsElement()) { if (derived.getComments().startsWith("...")) - base.setComments(base.getComments()+"\r\n"+derived.getComments().substring(3)); + base.setComments(Utilities.appendDerivedTextToBase(base.getComments(), derived.getComments())); else if (!Base.compareDeep(derived.getCommentsElement(), base.getCommentsElement(), false)) base.setCommentsElement(derived.getCommentsElement().copy()); else if (trimDifferential) @@ -914,7 +914,7 @@ public class ProfileUtilities { if (derived.hasLabelElement()) { if (derived.getLabel().startsWith("...")) - base.setLabel(base.getLabel()+"\r\n"+derived.getLabel().substring(3)); + base.setLabel(Utilities.appendDerivedTextToBase(base.getLabel(), derived.getLabel())); else if (!Base.compareDeep(derived.getLabelElement(), base.getLabelElement(), false)) base.setLabelElement(derived.getLabelElement().copy()); else if (trimDifferential) @@ -925,7 +925,7 @@ public class ProfileUtilities { if (derived.hasRequirementsElement()) { if (derived.getRequirements().startsWith("...")) - base.setRequirements(base.getRequirements()+"\r\n"+derived.getRequirements().substring(3)); + base.setRequirements(Utilities.appendDerivedTextToBase(base.getRequirements(), derived.getRequirements())); else if (!Base.compareDeep(derived.getRequirementsElement(), base.getRequirementsElement(), false)) base.setRequirementsElement(derived.getRequirementsElement().copy()); else if (trimDifferential) diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java index 4d2b6fced..eb7ad438f 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/conformance/ProfileUtilities.java @@ -1214,7 +1214,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasDefinitionElement()) { if (derived.getDefinition().startsWith("...")) - base.setDefinition(base.getDefinition()+"\r\n"+derived.getDefinition().substring(3)); + base.setDefinition(Utilities.appendDerivedTextToBase(base.getDefinition(), derived.getDefinition())); else if (!Base.compareDeep(derived.getDefinitionElement(), base.getDefinitionElement(), false)) base.setDefinitionElement(derived.getDefinitionElement().copy()); else if (trimDifferential) @@ -1225,7 +1225,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasCommentElement()) { if (derived.getComment().startsWith("...")) - base.setComment(base.getComment()+"\r\n"+derived.getComment().substring(3)); + base.setComment(Utilities.appendDerivedTextToBase(base.getComment(), derived.getComment())); else if (derived.hasCommentElement()!= base.hasCommentElement() || !Base.compareDeep(derived.getCommentElement(), base.getCommentElement(), false)) base.setCommentElement(derived.getCommentElement().copy()); else if (trimDifferential) @@ -1236,7 +1236,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasLabelElement()) { if (derived.getLabel().startsWith("...")) - base.setLabel(base.getLabel()+"\r\n"+derived.getLabel().substring(3)); + base.setLabel(Utilities.appendDerivedTextToBase(base.getLabel(), derived.getLabel())); else if (!base.hasLabelElement() || !Base.compareDeep(derived.getLabelElement(), base.getLabelElement(), false)) base.setLabelElement(derived.getLabelElement().copy()); else if (trimDifferential) @@ -1247,7 +1247,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasRequirementsElement()) { if (derived.getRequirements().startsWith("...")) - base.setRequirements(base.getRequirements()+"\r\n"+derived.getRequirements().substring(3)); + base.setRequirements(Utilities.appendDerivedTextToBase(base.getRequirements(), derived.getRequirements())); else if (!base.hasRequirementsElement() || !Base.compareDeep(derived.getRequirementsElement(), base.getRequirementsElement(), false)) base.setRequirementsElement(derived.getRequirementsElement().copy()); else if (trimDifferential) diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java index 80aebef51..8f4ed5a52 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java @@ -1719,7 +1719,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasDefinitionElement()) { if (derived.getDefinition().startsWith("...")) - base.setDefinition(base.getDefinition()+"\r\n"+derived.getDefinition().substring(3)); + base.setDefinition(Utilities.appendDerivedTextToBase(base.getDefinition(), derived.getDefinition())); else if (!Base.compareDeep(derived.getDefinitionElement(), base.getDefinitionElement(), false)) base.setDefinitionElement(derived.getDefinitionElement().copy()); else if (trimDifferential) @@ -1730,7 +1730,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasCommentElement()) { if (derived.getComment().startsWith("...")) - base.setComment(base.getComment()+"\r\n"+derived.getComment().substring(3)); + base.setComment(Utilities.appendDerivedTextToBase(base.getComment(), derived.getComment())); else if (derived.hasCommentElement()!= base.hasCommentElement() || !Base.compareDeep(derived.getCommentElement(), base.getCommentElement(), false)) base.setCommentElement(derived.getCommentElement().copy()); else if (trimDifferential) @@ -1741,7 +1741,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasLabelElement()) { if (derived.getLabel().startsWith("...")) - base.setLabel(base.getLabel()+"\r\n"+derived.getLabel().substring(3)); + base.setLabel(Utilities.appendDerivedTextToBase(base.getLabel(), derived.getLabel())); else if (!base.hasLabelElement() || !Base.compareDeep(derived.getLabelElement(), base.getLabelElement(), false)) base.setLabelElement(derived.getLabelElement().copy()); else if (trimDifferential) @@ -1752,7 +1752,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasRequirementsElement()) { if (derived.getRequirements().startsWith("...")) - base.setRequirements(base.getRequirements()+"\r\n"+derived.getRequirements().substring(3)); + base.setRequirements(Utilities.appendDerivedTextToBase(base.getRequirements(), derived.getRequirements())); else if (!base.hasRequirementsElement() || !Base.compareDeep(derived.getRequirementsElement(), base.getRequirementsElement(), false)) base.setRequirementsElement(derived.getRequirementsElement().copy()); else if (trimDifferential) diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/conformance/ProfileUtilities.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/conformance/ProfileUtilities.java index cb77745ea..3a54442ad 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/conformance/ProfileUtilities.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/conformance/ProfileUtilities.java @@ -2918,7 +2918,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasDefinitionElement()) { if (derived.getDefinition().startsWith("...")) - base.setDefinition(base.getDefinition()+"\r\n"+derived.getDefinition().substring(3)); + base.setDefinition(Utilities.appendDerivedTextToBase(base.getDefinition(), derived.getDefinition())); else if (!Base.compareDeep(derived.getDefinitionElement(), base.getDefinitionElement(), false)) base.setDefinitionElement(derived.getDefinitionElement().copy()); else if (trimDifferential) @@ -2929,7 +2929,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasCommentElement()) { if (derived.getComment().startsWith("...")) - base.setComment(base.getComment()+"\r\n"+derived.getComment().substring(3)); + base.setComment(Utilities.appendDerivedTextToBase(base.getComment(), derived.getComment())); else if (derived.hasCommentElement()!= base.hasCommentElement() || !Base.compareDeep(derived.getCommentElement(), base.getCommentElement(), false)) base.setCommentElement(derived.getCommentElement().copy()); else if (trimDifferential) @@ -2940,7 +2940,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasLabelElement()) { if (derived.getLabel().startsWith("...")) - base.setLabel(base.getLabel()+"\r\n"+derived.getLabel().substring(3)); + base.setLabel(Utilities.appendDerivedTextToBase(base.getLabel(), derived.getLabel())); else if (!base.hasLabelElement() || !Base.compareDeep(derived.getLabelElement(), base.getLabelElement(), false)) base.setLabelElement(derived.getLabelElement().copy()); else if (trimDifferential) @@ -2951,7 +2951,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasRequirementsElement()) { if (derived.getRequirements().startsWith("...")) - base.setRequirements(base.getRequirements()+"\r\n"+derived.getRequirements().substring(3)); + base.setRequirements(Utilities.appendDerivedTextToBase(base.getRequirements(), derived.getRequirements())); else if (!base.hasRequirementsElement() || !Base.compareDeep(derived.getRequirementsElement(), base.getRequirementsElement(), false)) base.setRequirementsElement(derived.getRequirementsElement().copy()); else if (trimDifferential) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java index 94975627e..6b19cde28 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/conformance/profile/ProfileUtilities.java @@ -2064,7 +2064,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasDefinitionElement()) { if (derived.getDefinition().startsWith("...")) - base.setDefinition(base.getDefinition()+"\r\n"+derived.getDefinition().substring(3)); + base.setDefinition(Utilities.appendDerivedTextToBase(base.getDefinition(), derived.getDefinition())); else if (!Base.compareDeep(derived.getDefinitionElement(), base.getDefinitionElement(), false)) base.setDefinitionElement(derived.getDefinitionElement().copy()); else if (trimDifferential) @@ -2075,7 +2075,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasCommentElement()) { if (derived.getComment().startsWith("...")) - base.setComment(base.getComment()+"\r\n"+derived.getComment().substring(3)); + base.setComment(Utilities.appendDerivedTextToBase(base.getComment(), derived.getComment())); else if (derived.hasCommentElement()!= base.hasCommentElement() || !Base.compareDeep(derived.getCommentElement(), base.getCommentElement(), false)) base.setCommentElement(derived.getCommentElement().copy()); else if (trimDifferential) @@ -2086,7 +2086,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasLabelElement()) { if (derived.getLabel().startsWith("...")) - base.setLabel(base.getLabel()+"\r\n"+derived.getLabel().substring(3)); + base.setLabel(Utilities.appendDerivedTextToBase(base.getLabel(), derived.getLabel())); else if (!base.hasLabelElement() || !Base.compareDeep(derived.getLabelElement(), base.getLabelElement(), false)) base.setLabelElement(derived.getLabelElement().copy()); else if (trimDifferential) @@ -2097,7 +2097,7 @@ public class ProfileUtilities extends TranslatingUtilities { if (derived.hasRequirementsElement()) { if (derived.getRequirements().startsWith("...")) - base.setRequirements(base.getRequirements()+"\r\n"+derived.getRequirements().substring(3)); + base.setRequirements(Utilities.appendDerivedTextToBase(base.getRequirements(), derived.getRequirements())); else if (!base.hasRequirementsElement() || !Base.compareDeep(derived.getRequirementsElement(), base.getRequirementsElement(), false)) base.setRequirementsElement(derived.getRequirementsElement().copy()); else if (trimDifferential) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java index f27c4ff54..d081fac18 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java @@ -65,6 +65,8 @@ import org.apache.commons.io.FileUtils; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.utilities.FileNotifier.FileNotifier2; +import javax.annotation.Nullable; + public class Utilities { private static final String UUID_REGEX = "[0-9a-f]{8}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{4}\\-[0-9a-f]{12}"; @@ -1799,4 +1801,18 @@ public class Utilities { } } -} \ No newline at end of file + /** + * Appends a text from a derived element to its base element. + * + * @param baseText The text set in the base element, or {@code null}. + * @param derivedText The text set in the derived element, starting with "...". + * @return The resulting text. + */ + public static String appendDerivedTextToBase(@Nullable final String baseText, + final String derivedText) { + if (baseText == null) { + return derivedText.substring(3); + } + return baseText + "\r\n" + derivedText.substring(3); + } +}