use of org.openmrs.module.coreapps.NameSupportCompatibility in project openmrs-module-coreapps by openmrs.
the class PatientHeaderFragmentController method getNames.
private Map<String, String> getNames(PersonName personName) {
NameSupportCompatibility nameSupport = Context.getRegisteredComponent("coreapps.NameSupportCompatibility", NameSupportCompatibility.class);
Map<String, String> nameFields = new LinkedHashMap<String, String>();
List<List<Map<String, String>>> lines = nameSupport.getLines();
String layoutToken = nameSupport.getLayoutToken();
// note that the assumption is one one field per "line", otherwise the labels that appear under each field may not render properly
try {
for (List<Map<String, String>> line : lines) {
String nameLabel = "";
String nameLine = "";
Boolean hasToken = false;
for (Map<String, String> lineToken : line) {
if (lineToken.get("isToken").equals(layoutToken)) {
String tokenValue = BeanUtils.getProperty(personName, lineToken.get("codeName"));
nameLabel = nameSupport.getNameMappings().get(lineToken.get("codeName"));
if (StringUtils.isNotBlank(tokenValue)) {
hasToken = true;
nameLine += tokenValue;
}
} else {
nameLine += lineToken.get("displayText");
}
}
// only display a line if there's a token within it we've been able to resolve
if (StringUtils.isNotBlank(nameLine) && hasToken) {
nameFields.put(nameLabel, nameLine);
}
}
return nameFields;
} catch (Exception e) {
throw new APIException("Unable to generate name fields for patient header", e);
}
}
Aggregations