Search in sources :

Example 1 with NameSupportCompatibility

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);
    }
}
Also used : APIException(org.openmrs.api.APIException) NameSupportCompatibility(org.openmrs.module.coreapps.NameSupportCompatibility) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) APIException(org.openmrs.api.APIException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 APIException (org.openmrs.api.APIException)1 NameSupportCompatibility (org.openmrs.module.coreapps.NameSupportCompatibility)1