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
|
@ -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
|
* 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) {
|
private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
for (IPrimitiveType<String> next : theStrings) {
|
for (IPrimitiveType<String> string : theStrings) {
|
||||||
if (next.isEmpty()) {
|
if (string.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (b.length() > 0) {
|
if (stringBuilder.length() > 0) {
|
||||||
b.append(' ');
|
stringBuilder.append(' ');
|
||||||
}
|
}
|
||||||
b.append(next.getValue());
|
stringBuilder.append(string.getValue());
|
||||||
}
|
}
|
||||||
return b.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
protected void listChildren(List<Property> childrenList) {
|
protected void listChildren(List<Property> childrenList) {
|
||||||
super.listChildren(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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -678,7 +678,9 @@ public class HumanName extends Type implements ICompositeType {
|
||||||
List<StringType> nameParts = new ArrayList<StringType>();
|
List<StringType> nameParts = new ArrayList<StringType>();
|
||||||
nameParts.addAll(getPrefix());
|
nameParts.addAll(getPrefix());
|
||||||
nameParts.addAll(getGiven());
|
nameParts.addAll(getGiven());
|
||||||
|
if (hasFamilyElement()) {
|
||||||
nameParts.add(getFamilyElement());
|
nameParts.add(getFamilyElement());
|
||||||
|
}
|
||||||
nameParts.addAll(getSuffix());
|
nameParts.addAll(getSuffix());
|
||||||
if (nameParts.size() > 0) {
|
if (nameParts.size() > 0) {
|
||||||
return joinStringsSpaceSeparated(nameParts);
|
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
|
* 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) {
|
private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
for (IPrimitiveType<String> next : theStrings) {
|
for (IPrimitiveType<String> string : theStrings) {
|
||||||
if (next.isEmpty()) {
|
if (string.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (b.length() > 0) {
|
if (stringBuilder.length() > 0) {
|
||||||
b.append(' ');
|
stringBuilder.append(' ');
|
||||||
}
|
}
|
||||||
b.append(next.getValue());
|
stringBuilder.append(string.getValue());
|
||||||
}
|
}
|
||||||
return b.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
protected void listChildren(List<Property> children) {
|
protected void listChildren(List<Property> children) {
|
||||||
super.listChildren(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>();
|
List<StringType> nameParts = new ArrayList<StringType>();
|
||||||
nameParts.addAll(getPrefix());
|
nameParts.addAll(getPrefix());
|
||||||
nameParts.addAll(getGiven());
|
nameParts.addAll(getGiven());
|
||||||
|
if (hasFamilyElement()) {
|
||||||
nameParts.add(getFamilyElement());
|
nameParts.add(getFamilyElement());
|
||||||
|
}
|
||||||
nameParts.addAll(getSuffix());
|
nameParts.addAll(getSuffix());
|
||||||
if (nameParts.size() > 0) {
|
if (nameParts.size() > 0) {
|
||||||
return joinStringsSpaceSeparated(nameParts);
|
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
|
* 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) {
|
private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
for (IPrimitiveType<String> next : theStrings) {
|
for (IPrimitiveType<String> string : theStrings) {
|
||||||
if (next.isEmpty()) {
|
if (string.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (b.length() > 0) {
|
if (stringBuilder.length() > 0) {
|
||||||
b.append(' ');
|
stringBuilder.append(' ');
|
||||||
}
|
}
|
||||||
b.append(next.getValue());
|
stringBuilder.append(string.getValue());
|
||||||
}
|
}
|
||||||
return b.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
protected void listChildren(List<Property> children) {
|
protected void listChildren(List<Property> children) {
|
||||||
super.listChildren(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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -900,7 +900,9 @@ public class HumanName extends DataType implements ICompositeType {
|
||||||
List<StringType> nameParts = new ArrayList<StringType>();
|
List<StringType> nameParts = new ArrayList<StringType>();
|
||||||
nameParts.addAll(getPrefix());
|
nameParts.addAll(getPrefix());
|
||||||
nameParts.addAll(getGiven());
|
nameParts.addAll(getGiven());
|
||||||
|
if (hasFamilyElement()) {
|
||||||
nameParts.add(getFamilyElement());
|
nameParts.add(getFamilyElement());
|
||||||
|
}
|
||||||
nameParts.addAll(getSuffix());
|
nameParts.addAll(getSuffix());
|
||||||
if (nameParts.size() > 0) {
|
if (nameParts.size() > 0) {
|
||||||
return joinStringsSpaceSeparated(nameParts);
|
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
|
* 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) {
|
private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
for (IPrimitiveType<String> next : theStrings) {
|
for (IPrimitiveType<String> string : theStrings) {
|
||||||
if (next.isEmpty()) {
|
if (string.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (b.length() > 0) {
|
if (stringBuilder.length() > 0) {
|
||||||
b.append(' ');
|
stringBuilder.append(' ');
|
||||||
}
|
}
|
||||||
b.append(next.getValue());
|
stringBuilder.append(string.getValue());
|
||||||
}
|
}
|
||||||
return b.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
// end addition
|
// 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>();
|
List<StringType> nameParts = new ArrayList<StringType>();
|
||||||
nameParts.addAll(getPrefix());
|
nameParts.addAll(getPrefix());
|
||||||
nameParts.addAll(getGiven());
|
nameParts.addAll(getGiven());
|
||||||
|
if (hasFamilyElement()) {
|
||||||
nameParts.add(getFamilyElement());
|
nameParts.add(getFamilyElement());
|
||||||
|
}
|
||||||
nameParts.addAll(getSuffix());
|
nameParts.addAll(getSuffix());
|
||||||
if (nameParts.size() > 0) {
|
if (nameParts.size() > 0) {
|
||||||
return joinStringsSpaceSeparated(nameParts);
|
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
|
* 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) {
|
private static String joinStringsSpaceSeparated(List<? extends IPrimitiveType<String>> theStrings) {
|
||||||
StringBuilder b = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
for (IPrimitiveType<String> next : theStrings) {
|
for (IPrimitiveType<String> string : theStrings) {
|
||||||
if (next.isEmpty()) {
|
if (string.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (b.length() > 0) {
|
if (stringBuilder.length() > 0) {
|
||||||
b.append(' ');
|
stringBuilder.append(' ');
|
||||||
}
|
}
|
||||||
b.append(next.getValue());
|
stringBuilder.append(string.getValue());
|
||||||
}
|
}
|
||||||
return b.toString();
|
return stringBuilder.toString();
|
||||||
}
|
}
|
||||||
// end addition
|
// 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