Merge pull request #1048 from qligier/pr-fix-text-appending

Fix appending text in ProfileUtilities
This commit is contained in:
Grahame Grieve 2022-12-31 09:10:24 +11:00 committed by GitHub
commit b894cc6da7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 25 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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 {
}
}
}
/**
* 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);
}
}