From 2f11af9bfa4e72989836109ce97ecd915d3b3f96 Mon Sep 17 00:00:00 2001 From: dotasek Date: Tue, 18 Jul 2023 12:22:53 -0400 Subject: [PATCH] Return HumanName getText() preferentially in getNameAsSingleString (#1355) * Failing tests * Return getText if it exists in HumanName --- .../hl7/fhir/dstu2016may/model/HumanName.java | 15 ++++++++---- .../fhir/dstu2016may/model/HumanNameTest.java | 10 ++++++++ .../org/hl7/fhir/dstu3/model/HumanName.java | 15 ++++++++---- .../hl7/fhir/dstu3/model/HumanNameTest.java | 10 ++++++++ .../java/org/hl7/fhir/r4/model/HumanName.java | 15 ++++++++---- .../org/hl7/fhir/r4/model/HumanNameTest.java | 10 ++++++++ .../org/hl7/fhir/r4b/model/HumanName.java | 23 +++++++++++-------- .../org/hl7/fhir/r4b/model/HumanNameTest.java | 10 ++++++++ .../java/org/hl7/fhir/r5/model/HumanName.java | 23 +++++++++++-------- .../org/hl7/fhir/r5/model/HumanNameTest.java | 10 ++++++++ 10 files changed, 108 insertions(+), 33 deletions(-) diff --git a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/HumanName.java b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/HumanName.java index 08aa8c554..fa30cdc29 100644 --- a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/HumanName.java +++ b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/model/HumanName.java @@ -655,13 +655,18 @@ public class HumanName extends Type implements ICompositeType { } /** - * Returns all of the components of the name (prefix, given, family, suffix) as a single string with a single spaced - * string separating each part. - *

- * If none of the parts are populated, returns the {@link #getTextElement() text} element value instead. - *

+ *

Returns the {@link #getTextElement() text} element value if it is not null.

+ + *

If the {@link #getTextElement() text} element value is null, returns all the components of the name (prefix, + * given, family, suffix) as a single string with a single spaced string separating each part.

+ * + * @return the human name as a single string */ public String getNameAsSingleString() { + if (hasText()) { + return getText().toString(); + } + List nameParts = new ArrayList(); nameParts.addAll(getPrefix()); nameParts.addAll(getGiven()); diff --git a/org.hl7.fhir.dstu2016may/src/test/java/org/hl7/fhir/dstu2016may/model/HumanNameTest.java b/org.hl7.fhir.dstu2016may/src/test/java/org/hl7/fhir/dstu2016may/model/HumanNameTest.java index 5e2c06f95..19a3920f4 100644 --- a/org.hl7.fhir.dstu2016may/src/test/java/org/hl7/fhir/dstu2016may/model/HumanNameTest.java +++ b/org.hl7.fhir.dstu2016may/src/test/java/org/hl7/fhir/dstu2016may/model/HumanNameTest.java @@ -25,4 +25,14 @@ public class HumanNameTest { String actual = humanName.getNameAsSingleString(); assertEquals(expected, actual); } + + @Test + public void getNameAsSingleStringPreferText() { + final String expected = "dummy value"; + HumanName humanName = new HumanName() + .setTextElement(new StringType(expected)).addFamily("wrong value"); + + String actual = humanName.getNameAsSingleString(); + assertEquals(expected, actual); + } } \ No newline at end of file diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/HumanName.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/HumanName.java index 814412456..66eed6226 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/HumanName.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/model/HumanName.java @@ -668,13 +668,18 @@ public class HumanName extends Type implements ICompositeType { } /** - * Returns all of the components of the name (prefix, given, family, suffix) as a single string with a single spaced - * string separating each part. - *

- * If none of the parts are populated, returns the {@link #getTextElement() text} element value instead. - *

+ *

Returns the {@link #getTextElement() text} element value if it is not null.

+ + *

If the {@link #getTextElement() text} element value is null, returns all the components of the name (prefix, + * given, family, suffix) as a single string with a single spaced string separating each part.

+ * + * @return the human name as a single string */ public String getNameAsSingleString() { + if (hasText()) { + return getText().toString(); + } + List nameParts = new ArrayList(); nameParts.addAll(getPrefix()); nameParts.addAll(getGiven()); diff --git a/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/model/HumanNameTest.java b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/model/HumanNameTest.java index 166fc4ed8..889866996 100644 --- a/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/model/HumanNameTest.java +++ b/org.hl7.fhir.dstu3/src/test/java/org/hl7/fhir/dstu3/model/HumanNameTest.java @@ -25,4 +25,14 @@ public class HumanNameTest { String actual = humanName.getNameAsSingleString(); assertEquals(expected, actual); } + + @Test + public void getNameAsSingleStringPreferText() { + final String expected = "dummy value"; + HumanName humanName = new HumanName() + .setTextElement(new StringType(expected)).setFamily("wrong value"); + + String actual = humanName.getNameAsSingleString(); + assertEquals(expected, actual); + } } \ No newline at end of file diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/HumanName.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/HumanName.java index 0a41b4837..704e24a04 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/HumanName.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/model/HumanName.java @@ -668,13 +668,18 @@ public class HumanName extends Type implements ICompositeType { } /** - * Returns all of the components of the name (prefix, given, family, suffix) as a single string with a single spaced - * string separating each part. - *

- * If none of the parts are populated, returns the {@link #getTextElement() text} element value instead. - *

+ *

Returns the {@link #getTextElement() text} element value if it is not null.

+ + *

If the {@link #getTextElement() text} element value is null, returns all the components of the name (prefix, + * given, family, suffix) as a single string with a single spaced string separating each part.

+ * + * @return the human name as a single string */ public String getNameAsSingleString() { + if (hasText()) { + return getText().toString(); + } + List nameParts = new ArrayList(); nameParts.addAll(getPrefix()); nameParts.addAll(getGiven()); diff --git a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/model/HumanNameTest.java b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/model/HumanNameTest.java index 40a754e27..f741e1ea3 100644 --- a/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/model/HumanNameTest.java +++ b/org.hl7.fhir.r4/src/test/java/org/hl7/fhir/r4/model/HumanNameTest.java @@ -27,4 +27,14 @@ public class HumanNameTest { String actual = humanName.getNameAsSingleString(); assertEquals(expected, actual); } + + @Test + public void getNameAsSingleStringPreferText() { + final String expected = "dummy value"; + HumanName humanName = new HumanName() + .setTextElement(new StringType(expected)).setFamily("wrong value"); + + String actual = humanName.getNameAsSingleString(); + assertEquals(expected, actual); + } } diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/HumanName.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/HumanName.java index 6f2b34733..c0f584715 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/HumanName.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/model/HumanName.java @@ -887,16 +887,21 @@ public class HumanName extends DataType implements ICompositeType { */ public String getSuffixAsSingleString() { return joinStringsSpaceSeparated(getSuffix()); - } + } + + /** + *

Returns the {@link #getTextElement() text} element value if it is not null.

+ + *

If the {@link #getTextElement() text} element value is null, returns all the components of the name (prefix, + * given, family, suffix) as a single string with a single spaced string separating each part.

+ * + * @return the human name as a single string + */ + public String getNameAsSingleString() { + if (hasText()) { + return getText().toString(); + } - /** - * Returns all of the components of the name (prefix, given, family, suffix) as a single string with a single spaced - * string separating each part. - *

- * If none of the parts are populated, returns the {@link #getTextElement() text} element value instead. - *

- */ - public String getNameAsSingleString() { List nameParts = new ArrayList(); nameParts.addAll(getPrefix()); nameParts.addAll(getGiven()); diff --git a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/model/HumanNameTest.java b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/model/HumanNameTest.java index ef5a7892a..5d7375dc0 100644 --- a/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/model/HumanNameTest.java +++ b/org.hl7.fhir.r4b/src/test/java/org/hl7/fhir/r4b/model/HumanNameTest.java @@ -25,4 +25,14 @@ public class HumanNameTest { String actual = humanName.getNameAsSingleString(); assertEquals(expected, actual); } + + @Test + public void getNameAsSingleStringPreferText() { + final String expected = "dummy value"; + HumanName humanName = new HumanName() + .setTextElement(new StringType(expected)).setFamily("wrong value"); + + String actual = humanName.getNameAsSingleString(); + assertEquals(expected, actual); + } } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/HumanName.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/HumanName.java index e68bd237e..24bcf3964 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/HumanName.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/model/HumanName.java @@ -887,17 +887,22 @@ public class HumanName extends DataType implements ICompositeType { */ public String getSuffixAsSingleString() { return joinStringsSpaceSeparated(getSuffix()); - } + } - /** - * Returns all of the components of the name (prefix, given, family, suffix) as a single string with a single spaced - * string separating each part. - *

- * If none of the parts are populated, returns the {@link #getTextElement() text} element value instead. - *

- */ + /** + *

Returns the {@link #getTextElement() text} element value if it is not null.

+ + *

If the {@link #getTextElement() text} element value is null, returns all the components of the name (prefix, + * given, family, suffix) as a single string with a single spaced string separating each part.

+ * + * @return the human name as a single string + */ public String getNameAsSingleString() { - List nameParts = new ArrayList(); + if (hasText()) { + return getText().toString(); + } + + List nameParts = new ArrayList(); nameParts.addAll(getPrefix()); nameParts.addAll(getGiven()); if (hasFamilyElement()) { diff --git a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/model/HumanNameTest.java b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/model/HumanNameTest.java index a130be4b9..24e06c690 100644 --- a/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/model/HumanNameTest.java +++ b/org.hl7.fhir.r5/src/test/java/org/hl7/fhir/r5/model/HumanNameTest.java @@ -27,4 +27,14 @@ public class HumanNameTest { String actual = humanName.getNameAsSingleString(); assertEquals(expected, actual); } + + @Test + public void getNameAsSingleStringPreferText() { + final String expected = "dummy value"; + HumanName humanName = new HumanName() + .setTextElement(new StringType(expected)).setFamily("wrong value"); + + String actual = humanName.getNameAsSingleString(); + assertEquals(expected, actual); + } }