Skip to content

Commit

Permalink
Use \n instead of ~ for multiline reports
Browse files Browse the repository at this point in the history
  • Loading branch information
LisaWellman committed Jul 20, 2021
1 parent 2fd11be commit f0afee8
Show file tree
Hide file tree
Showing 4 changed files with 391 additions and 387 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import java.util.Collection;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ca.uhn.hl7v2.model.Composite;
import ca.uhn.hl7v2.model.DataTypeException;
import ca.uhn.hl7v2.model.Primitive;
Expand All @@ -18,113 +20,113 @@
import ca.uhn.hl7v2.model.primitive.ID;
import ca.uhn.hl7v2.model.primitive.IS;


public class Hl7DataHandlerUtil {

private static final Logger LOGGER = LoggerFactory.getLogger(Hl7DataHandlerUtil.class);

private Hl7DataHandlerUtil() {}

public static String getStringValue(Object obj) {
return getStringValue(obj, false);
}
private static final Logger LOGGER = LoggerFactory.getLogger(Hl7DataHandlerUtil.class);

public static String getStringValue(Object obj, boolean allComponents) {
return getStringValue(obj,allComponents,". ");
}

public static String getStringValue(Object obj, boolean allComponents, String separatorString) {
if (obj == null) {
return null;
private Hl7DataHandlerUtil() {
}
LOGGER.debug("Extracting string value for {} type {}", obj, obj.getClass());

Object local = obj;
String returnValue;
if (local instanceof Collection) {
List<Object> list = ((List) local);
if (list.size() == 1) {
returnValue = toStringValue(list.get(0), allComponents);
} else if (!list.isEmpty()) {
StringBuilder sb = new StringBuilder();
list.forEach(e -> sb.append(toStringValue(e, allComponents)).append(separatorString));
returnValue = StringUtils.strip(sb.toString());
} else {
returnValue = null;
}

} else {
returnValue = toStringValue(local, allComponents);

public static String getStringValue(Object obj) {
return getStringValue(obj, false);
}

return returnValue;
}
public static String getStringValue(Object obj, boolean allComponents) {
return getStringValue(obj, allComponents, ". ", true);
}

public static String getTableNumber(Object obj) {
public static String getStringValue(Object obj, boolean allComponents, String separatorString, boolean trim) {
if (obj == null) {
return null;
}
LOGGER.debug("Extracting string value for {} type {}", obj, obj.getClass());

Object local = obj;
String returnValue;
if (local instanceof Collection) {
List<Object> list = ((List) local);
if (list.size() == 1) {
returnValue = toStringValue(list.get(0), allComponents);
} else if (!list.isEmpty()) {
StringBuilder sb = new StringBuilder();
list.forEach(e -> sb.append(toStringValue(e, allComponents)).append(separatorString));
returnValue = sb.toString();
if (trim) {
returnValue = StringUtils.strip(returnValue);
}
} else {
returnValue = null;
}

} else {
returnValue = toStringValue(local, allComponents);
}

if (obj instanceof ID) {
ID id = (ID) obj;
return "v2-" + StringUtils.leftPad(String.valueOf(id.getTable()), 4, '0');
} else if (obj instanceof IS) {
IS id = (IS) obj;
return "v2-" + StringUtils.leftPad(String.valueOf(id.getTable()), 4, '0');
return returnValue;
}
return null;
}

public static String getTableNumber(Object obj) {

private static String toStringValue(Object local, boolean allComponents) {

if (local == null) {
return null;
}
String returnvalue;
if (local instanceof Variable) {
returnvalue = convertVariesDataTypeToString(local, allComponents);
} else if (local instanceof Composite) {
Composite com = (Composite) local;
if (allComponents) {
returnvalue = getValueFromComposite(com);
} else {
try {
returnvalue = com.getComponent(0).toString();
} catch (DataTypeException e) {
LOGGER.warn("Failure when extracting string value for {}", local, e);
returnvalue = null;
if (obj instanceof ID) {
ID id = (ID) obj;
return "v2-" + StringUtils.leftPad(String.valueOf(id.getTable()), 4, '0');
} else if (obj instanceof IS) {
IS id = (IS) obj;
return "v2-" + StringUtils.leftPad(String.valueOf(id.getTable()), 4, '0');
}
}
} else if (local instanceof Primitive) {
Primitive prem = (Primitive) local;
returnvalue = prem.getValue();
} else {
returnvalue = local.toString();
return null;
}

return returnvalue;
}
private static String toStringValue(Object local, boolean allComponents) {

if (local == null) {
return null;
}
String returnvalue;
if (local instanceof Variable) {
returnvalue = convertVariesDataTypeToString(local, allComponents);
} else if (local instanceof Composite) {
Composite com = (Composite) local;
if (allComponents) {
returnvalue = getValueFromComposite(com);
} else {
try {
returnvalue = com.getComponent(0).toString();
} catch (DataTypeException e) {
LOGGER.warn("Failure when extracting string value for {}", local, e);
returnvalue = null;
}
}
} else if (local instanceof Primitive) {
Primitive prem = (Primitive) local;
returnvalue = prem.getValue();
} else {
returnvalue = local.toString();
}

private static String convertVariesDataTypeToString(Object obj, boolean allComponents) {
if (obj instanceof Variable) {
Variable v = (Variable) obj;
return getStringValue(v.getData(), allComponents);
return returnvalue;
}
return obj.toString();
}

private static String getValueFromComposite(Composite com) {
private static String convertVariesDataTypeToString(Object obj, boolean allComponents) {
if (obj instanceof Variable) {
Variable v = (Variable) obj;
return getStringValue(v.getData(), allComponents);
}
return obj.toString();
}

Type[] types = com.getComponents();
StringBuilder sb = new StringBuilder();
for (Type t : types) {
String text = t.toString();
if (StringUtils.isNotBlank(text)) {
sb.append(t.toString()).append(", ");
}
}
return StringUtils.stripEnd(sb.toString(), ", ");
private static String getValueFromComposite(Composite com) {

}
Type[] types = com.getComponents();
StringBuilder sb = new StringBuilder();
for (Type t : types) {
String text = t.toString();
if (StringUtils.isNotBlank(text)) {
sb.append(t.toString()).append(", ");
}
}
return StringUtils.stripEnd(sb.toString(), ", ");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static String generateName(Object prefix, Object first, Object middle, Ob
* Returns difference between time2 - time1 in minutes
*
* @param start DateTime
* @param end DateTime
* @param end DateTime
* @return Minutes in Long
*/

Expand Down Expand Up @@ -142,7 +142,15 @@ public static String split(Object input, String delimitter, int index) {
}

public static String concatenateWithChar(Object input, String delimiterChar) {
return Hl7DataHandlerUtil.getStringValue(input, true, delimiterChar);
// Engine converts the delimiter character to a String; need to fix escaped characters
// as they become 2 separate characters rather than 1.
// Currently handling '\n' specifically, have not found a more general solution.
String delimiter = delimiterChar;
if (delimiterChar.equals("\\n")) {
delimiter = Character.toString('\n'); // this works
}

return Hl7DataHandlerUtil.getStringValue(input, true, delimiter, false);
}

public static List<String> makeStringArray(String... strs) {
Expand All @@ -159,13 +167,13 @@ public static String getAddressUse(String xad7Type, String xad16Temp, String xad
LOGGER.info("Calculating address Use from XAD.7 {}, XAD.16 {}, XAD.17 {}", xad7Type, xad16Temp, xad17Bad);

String addressUse = "";
if (xad16Temp != null && xad16Temp.equalsIgnoreCase("Y")
|| ((xad16Temp == null || xad16Temp.isEmpty())
&& xad7Type != null && xad7Type.equalsIgnoreCase("C"))) {
if (xad16Temp != null && xad16Temp.equalsIgnoreCase("Y")
|| ((xad16Temp == null || xad16Temp.isEmpty())
&& xad7Type != null && xad7Type.equalsIgnoreCase("C"))) {
addressUse = "temp";
} else if (xad17Bad != null && xad17Bad.equalsIgnoreCase("Y")
|| ((xad17Bad == null || xad17Bad.isEmpty())
&& xad7Type != null && xad7Type.equalsIgnoreCase("BA"))) {
} else if (xad17Bad != null && xad17Bad.equalsIgnoreCase("Y")
|| ((xad17Bad == null || xad17Bad.isEmpty())
&& xad7Type != null && xad7Type.equalsIgnoreCase("BA"))) {
addressUse = "old";
} else if (xad7Type != null && xad7Type.equalsIgnoreCase("H")) {
addressUse = "home";
Expand All @@ -181,13 +189,13 @@ public static String getAddressType(String xad7Type, String xad18Type) {
LOGGER.info("Calculating address Type from XAD.7 {}, XAD.18 {}", xad7Type, xad18Type);

String addressType = "";
if (xad18Type != null && xad18Type.equalsIgnoreCase("M")
|| (xad18Type == null || xad18Type.isEmpty())
&& (xad7Type != null && xad7Type.equalsIgnoreCase("M"))) {
if (xad18Type != null && xad18Type.equalsIgnoreCase("M")
|| (xad18Type == null || xad18Type.isEmpty())
&& (xad7Type != null && xad7Type.equalsIgnoreCase("M"))) {
addressType = "postal";
} else if (xad18Type != null && xad18Type.equalsIgnoreCase("V")
|| (xad18Type == null || xad18Type.isEmpty())
&& (xad7Type != null && xad7Type.equalsIgnoreCase("SH"))) {
} else if (xad18Type != null && xad18Type.equalsIgnoreCase("V")
|| (xad18Type == null || xad18Type.isEmpty())
&& (xad7Type != null && xad7Type.equalsIgnoreCase("SH"))) {
addressType = "physical";
}
return addressType;
Expand Down Expand Up @@ -244,7 +252,7 @@ public static String getCodeableConceptDisplay(CodeableConcept codeableConcept)
// Takes all the pieces of telecom number from XTN, formats to a user friendly
// Telecom number based on rules documented in the steps
public static String getFormattedTelecomNumberValue(String xtn1Old, String xtn5Country, String xtn6Area,
String xtn7Local, String xtn8Extension, String xtn12Unformatted) {
String xtn7Local, String xtn8Extension, String xtn12Unformatted) {
String returnValue = "";

// If the local number exists...
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/hl7/resource/DiagnosticReport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ presentedForm:
condition: $obx2 EQUALS TX && $obx3 NULL
vars:
# This concatenates all OBX-5 lines together (the asterisk) and preserves blank lines (the ampersand). Multiple lines are concatenated with a tilde.
data: OBX.5 *&, GeneralUtils.concatenateWithChar(data, '~')
data: OBX.5 *&, GeneralUtils.concatenateWithChar(data, '\n')
title: OBR.4.2
date: OBX.14
mime: $code
Expand Down
Loading

0 comments on commit f0afee8

Please sign in to comment.