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:
Amir Toosi 2023-04-13 04:31:58 +10:00 committed by GitHub
parent 8ba4d75451
commit b09e536387
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 204 additions and 52 deletions

View File

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

View File

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

View File

@ -678,7 +678,9 @@ public class HumanName extends Type implements ICompositeType {
List<StringType> nameParts = new ArrayList<StringType>();
nameParts.addAll(getPrefix());
nameParts.addAll(getGiven());
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);

View File

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

View File

@ -678,7 +678,9 @@ public class HumanName extends Type implements ICompositeType {
List<StringType> nameParts = new ArrayList<StringType>();
nameParts.addAll(getPrefix());
nameParts.addAll(getGiven());
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);

View File

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

View File

@ -900,7 +900,9 @@ public class HumanName extends DataType implements ICompositeType {
List<StringType> nameParts = new ArrayList<StringType>();
nameParts.addAll(getPrefix());
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

View File

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

View File

@ -900,7 +900,9 @@ public class HumanName extends DataType implements ICompositeType {
List<StringType> nameParts = new ArrayList<StringType>();
nameParts.addAll(getPrefix());
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

View File

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