Fix HumanName getNameAsSingleString never returning text element (#1207)
* Fix HumanName getNameAsSingleString never returning text element * Add test + gentle rename in joinStringsSpaceSeparated * removed unused variable from unit test. added fix for getNameAsSingleString to r5. * changed variable names in joinStringSpaceSeparated to more meaningful names * Add tests and fixes for dstu2016may, dstu3, and r4b + gentle refactor --------- Co-authored-by: dotasek <david.otasek@smilecdr.com>
This commit is contained in:
parent
8ba4d75451
commit
b09e536387
|
@ -112,7 +112,7 @@ public class HumanName extends Type implements ICompositeType {
|
|||
case ANONYMOUS: return "anonymous";
|
||||
case OLD: return "old";
|
||||
case MAIDEN: return "maiden";
|
||||
case NULL: return null;
|
||||
case NULL: return null;
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ public class HumanName extends Type implements ICompositeType {
|
|||
case ANONYMOUS: return "http://hl7.org/fhir/name-use";
|
||||
case OLD: return "http://hl7.org/fhir/name-use";
|
||||
case MAIDEN: return "http://hl7.org/fhir/name-use";
|
||||
case NULL: return null;
|
||||
case NULL: return null;
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ public class HumanName extends Type implements ICompositeType {
|
|||
case ANONYMOUS: return "Anonymous assigned name, alias, or pseudonym (used to protect a person's identity for privacy reasons)";
|
||||
case OLD: return "This name is no longer in use (or was never correct, but retained for records)";
|
||||
case MAIDEN: return "A name used prior to marriage. Marriage naming customs vary greatly around the world. This name use is for use by applications that collect and store \"maiden\" names. Though the concept of maiden name is often gender specific, the use of this term is not gender specific. The use of this term does not imply any particular history for a person's name, nor should the maiden name be determined algorithmically.";
|
||||
case NULL: return null;
|
||||
case NULL: return null;
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ public class HumanName extends Type implements ICompositeType {
|
|||
case ANONYMOUS: return "Anonymous";
|
||||
case OLD: return "Old";
|
||||
case MAIDEN: return "Maiden";
|
||||
case NULL: return null;
|
||||
case NULL: return null;
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
@ -680,17 +680,17 @@ public class HumanName extends Type implements ICompositeType {
|
|||
* TODO: replace with call to ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated when HAPI upgrades to 1.4
|
||||
*/
|
||||
private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (IPrimitiveType<String> next : theStrings) {
|
||||
if (next.isEmpty()) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (IPrimitiveType<String> string : theStrings) {
|
||||
if (string.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (b.length() > 0) {
|
||||
b.append(' ');
|
||||
if (stringBuilder.length() > 0) {
|
||||
stringBuilder.append(' ');
|
||||
}
|
||||
b.append(next.getValue());
|
||||
stringBuilder.append(string.getValue());
|
||||
}
|
||||
return b.toString();
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
protected void listChildren(List<Property> childrenList) {
|
||||
super.listChildren(childrenList);
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package org.hl7.fhir.dstu2016may.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class HumanNameTest {
|
||||
|
||||
@Test
|
||||
public void getNameAsSingleStringWithoutFamilyElement() {
|
||||
final String expected = "dummy value";
|
||||
HumanName humanName = new HumanName()
|
||||
.setTextElement(new StringType(expected));
|
||||
|
||||
String actual = humanName.getNameAsSingleString();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameAsSingleStringWithFamilyElement() {
|
||||
final String expected = "good value";
|
||||
HumanName humanName = new HumanName()
|
||||
.addFamily(expected);
|
||||
|
||||
String actual = humanName.getNameAsSingleString();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
|
@ -114,7 +114,7 @@ public class HumanName extends Type implements ICompositeType {
|
|||
case ANONYMOUS: return "anonymous";
|
||||
case OLD: return "old";
|
||||
case MAIDEN: return "maiden";
|
||||
case NULL: return null;
|
||||
case NULL: return null;
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public class HumanName extends Type implements ICompositeType {
|
|||
case ANONYMOUS: return "http://hl7.org/fhir/name-use";
|
||||
case OLD: return "http://hl7.org/fhir/name-use";
|
||||
case MAIDEN: return "http://hl7.org/fhir/name-use";
|
||||
case NULL: return null;
|
||||
case NULL: return null;
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ public class HumanName extends Type implements ICompositeType {
|
|||
case ANONYMOUS: return "Anonymous assigned name, alias, or pseudonym (used to protect a person's identity for privacy reasons)";
|
||||
case OLD: return "This name is no longer in use (or was never correct, but retained for records)";
|
||||
case MAIDEN: return "A name used prior to changing name because of marriage. This name use is for use by applications that collect and store names that were used prior to a marriage. Marriage naming customs vary greatly around the world, and are constantly changing. This term is not gender specific. The use of this term does not imply any particular history for a person's name";
|
||||
case NULL: return null;
|
||||
case NULL: return null;
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ public class HumanName extends Type implements ICompositeType {
|
|||
case ANONYMOUS: return "Anonymous";
|
||||
case OLD: return "Old";
|
||||
case MAIDEN: return "Name changed for Marriage";
|
||||
case NULL: return null;
|
||||
case NULL: return null;
|
||||
default: return "?";
|
||||
}
|
||||
}
|
||||
|
@ -678,7 +678,9 @@ public class HumanName extends Type implements ICompositeType {
|
|||
List<StringType> nameParts = new ArrayList<StringType>();
|
||||
nameParts.addAll(getPrefix());
|
||||
nameParts.addAll(getGiven());
|
||||
nameParts.add(getFamilyElement());
|
||||
if (hasFamilyElement()) {
|
||||
nameParts.add(getFamilyElement());
|
||||
}
|
||||
nameParts.addAll(getSuffix());
|
||||
if (nameParts.size() > 0) {
|
||||
return joinStringsSpaceSeparated(nameParts);
|
||||
|
@ -693,17 +695,17 @@ public class HumanName extends Type implements ICompositeType {
|
|||
* TODO: replace with call to ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated when HAPI upgrades to 1.4
|
||||
*/
|
||||
private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (IPrimitiveType<String> next : theStrings) {
|
||||
if (next.isEmpty()) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (IPrimitiveType<String> string : theStrings) {
|
||||
if (string.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (b.length() > 0) {
|
||||
b.append(' ');
|
||||
if (stringBuilder.length() > 0) {
|
||||
stringBuilder.append(' ');
|
||||
}
|
||||
b.append(next.getValue());
|
||||
stringBuilder.append(string.getValue());
|
||||
}
|
||||
return b.toString();
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
protected void listChildren(List<Property> children) {
|
||||
super.listChildren(children);
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package org.hl7.fhir.dstu3.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class HumanNameTest {
|
||||
|
||||
@Test
|
||||
public void getNameAsSingleStringWithoutFamilyElement() {
|
||||
final String expected = "dummy value";
|
||||
HumanName humanName = new HumanName()
|
||||
.setTextElement(new StringType(expected));
|
||||
|
||||
String actual = humanName.getNameAsSingleString();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameAsSingleStringWithFamilyElement() {
|
||||
final String expected = "good value";
|
||||
HumanName humanName = new HumanName()
|
||||
.setFamily(expected);
|
||||
|
||||
String actual = humanName.getNameAsSingleString();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
|
@ -678,7 +678,9 @@ public class HumanName extends Type implements ICompositeType {
|
|||
List<StringType> nameParts = new ArrayList<StringType>();
|
||||
nameParts.addAll(getPrefix());
|
||||
nameParts.addAll(getGiven());
|
||||
nameParts.add(getFamilyElement());
|
||||
if (hasFamilyElement()) {
|
||||
nameParts.add(getFamilyElement());
|
||||
}
|
||||
nameParts.addAll(getSuffix());
|
||||
if (nameParts.size() > 0) {
|
||||
return joinStringsSpaceSeparated(nameParts);
|
||||
|
@ -693,17 +695,17 @@ public class HumanName extends Type implements ICompositeType {
|
|||
* TODO: replace with call to ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated when HAPI upgrades to 1.4
|
||||
*/
|
||||
private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (IPrimitiveType<String> next : theStrings) {
|
||||
if (next.isEmpty()) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (IPrimitiveType<String> string : theStrings) {
|
||||
if (string.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (b.length() > 0) {
|
||||
b.append(' ');
|
||||
if (stringBuilder.length() > 0) {
|
||||
stringBuilder.append(' ');
|
||||
}
|
||||
b.append(next.getValue());
|
||||
stringBuilder.append(string.getValue());
|
||||
}
|
||||
return b.toString();
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
protected void listChildren(List<Property> children) {
|
||||
super.listChildren(children);
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package org.hl7.fhir.r4.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class HumanNameTest {
|
||||
|
||||
@Test
|
||||
public void getNameAsSingleStringWithoutFamilyElement() {
|
||||
final String expected = "dummy value";
|
||||
HumanName humanName = new HumanName()
|
||||
.setTextElement(new StringType(expected));
|
||||
|
||||
String actual = humanName.getNameAsSingleString();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameAsSingleStringWithFamilyElement() {
|
||||
final String expected = "good value";
|
||||
HumanName humanName = new HumanName()
|
||||
.setFamily(expected);
|
||||
|
||||
String actual = humanName.getNameAsSingleString();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
|
@ -899,8 +899,10 @@ public class HumanName extends DataType implements ICompositeType {
|
|||
public String getNameAsSingleString() {
|
||||
List<StringType> nameParts = new ArrayList<StringType>();
|
||||
nameParts.addAll(getPrefix());
|
||||
nameParts.addAll(getGiven());
|
||||
nameParts.add(getFamilyElement());
|
||||
nameParts.addAll(getGiven());
|
||||
if (hasFamilyElement()) {
|
||||
nameParts.add(getFamilyElement());
|
||||
}
|
||||
nameParts.addAll(getSuffix());
|
||||
if (nameParts.size() > 0) {
|
||||
return joinStringsSpaceSeparated(nameParts);
|
||||
|
@ -915,17 +917,17 @@ public class HumanName extends DataType implements ICompositeType {
|
|||
* TODO: replace with call to ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated when HAPI upgrades to 1.4
|
||||
*/
|
||||
private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (IPrimitiveType<String> next : theStrings) {
|
||||
if (next.isEmpty()) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (IPrimitiveType<String> string : theStrings) {
|
||||
if (string.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (b.length() > 0) {
|
||||
b.append(' ');
|
||||
if (stringBuilder.length() > 0) {
|
||||
stringBuilder.append(' ');
|
||||
}
|
||||
b.append(next.getValue());
|
||||
stringBuilder.append(string.getValue());
|
||||
}
|
||||
return b.toString();
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
// end addition
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package org.hl7.fhir.r4b.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class HumanNameTest {
|
||||
|
||||
@Test
|
||||
public void getNameAsSingleStringWithoutFamilyElement() {
|
||||
final String expected = "dummy value";
|
||||
HumanName humanName = new HumanName()
|
||||
.setTextElement(new StringType(expected));
|
||||
|
||||
String actual = humanName.getNameAsSingleString();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameAsSingleStringWithFamilyElement() {
|
||||
final String expected = "good value";
|
||||
HumanName humanName = new HumanName()
|
||||
.setFamily(expected);
|
||||
|
||||
String actual = humanName.getNameAsSingleString();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
|
@ -900,7 +900,9 @@ public class HumanName extends DataType implements ICompositeType {
|
|||
List<StringType> nameParts = new ArrayList<StringType>();
|
||||
nameParts.addAll(getPrefix());
|
||||
nameParts.addAll(getGiven());
|
||||
nameParts.add(getFamilyElement());
|
||||
if (hasFamilyElement()) {
|
||||
nameParts.add(getFamilyElement());
|
||||
}
|
||||
nameParts.addAll(getSuffix());
|
||||
if (nameParts.size() > 0) {
|
||||
return joinStringsSpaceSeparated(nameParts);
|
||||
|
@ -915,17 +917,17 @@ public class HumanName extends DataType implements ICompositeType {
|
|||
* TODO: replace with call to ca.uhn.fhir.util.DatatypeUtil.joinStringsSpaceSeparated when HAPI upgrades to 1.4
|
||||
*/
|
||||
private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (IPrimitiveType<String> next : theStrings) {
|
||||
if (next.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (b.length() > 0) {
|
||||
b.append(' ');
|
||||
}
|
||||
b.append(next.getValue());
|
||||
}
|
||||
return b.toString();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (IPrimitiveType<String> string : theStrings) {
|
||||
if (string.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (stringBuilder.length() > 0) {
|
||||
stringBuilder.append(' ');
|
||||
}
|
||||
stringBuilder.append(string.getValue());
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
// end addition
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package org.hl7.fhir.r5.model;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class HumanNameTest {
|
||||
|
||||
@Test
|
||||
public void getNameAsSingleStringWithoutFamilyElement() {
|
||||
final String expected = "dummy value";
|
||||
HumanName humanName = new HumanName()
|
||||
.setTextElement(new StringType(expected));
|
||||
|
||||
String actual = humanName.getNameAsSingleString();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNameAsSingleStringWithFamilyElement() {
|
||||
final String expected = "good value";
|
||||
HumanName humanName = new HumanName()
|
||||
.setFamily(expected);
|
||||
|
||||
String actual = humanName.getNameAsSingleString();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue