Search in sources :

Example 1 with NameTemplate

use of org.openmrs.layout.name.NameTemplate in project openmrs-module-pihcore by PIH.

the class NameTemplateSetup method configureNameTemplate.

public static void configureNameTemplate(NameSupport nameSupport) {
    NameTemplate nameTemplate = new NameTemplate();
    // we are redefining the short name template for use in our context
    nameTemplate.setCodeName("short");
    Map<String, String> nameMappings = new HashMap<String, String>();
    nameMappings.put("givenName", "zl.givenName");
    nameMappings.put("familyName", "zl.familyName");
    nameMappings.put("middleName", "zl.nickname");
    nameTemplate.setNameMappings(nameMappings);
    Map<String, String> sizeMappings = new HashMap<String, String>();
    sizeMappings.put("givenName", "50");
    sizeMappings.put("familyName", "50");
    sizeMappings.put("middleName", "50");
    nameTemplate.setSizeMappings(sizeMappings);
    List<String> lineByLineFormat = new ArrayList<String>();
    lineByLineFormat.add("familyName,");
    lineByLineFormat.add("givenName");
    lineByLineFormat.add("'middleName'");
    nameTemplate.setLineByLineFormat(lineByLineFormat);
    List<NameTemplate> templates = new ArrayList<NameTemplate>();
    templates.add(nameTemplate);
    // we blow away the other templates here, is that a bad thing?
    nameSupport.setLayoutTemplates(templates);
    nameSupport.setDefaultLayoutFormat("short");
}
Also used : HashMap(java.util.HashMap) NameTemplate(org.openmrs.layout.name.NameTemplate) ArrayList(java.util.ArrayList)

Example 2 with NameTemplate

use of org.openmrs.layout.name.NameTemplate in project openmrs-core by openmrs.

the class PersonName method getFullName.

/**
 * Convenience method to get all the names of this PersonName and concatenating them together
 * with spaces in between. If any part of {@link #getPrefix()}, {@link #getGivenName()},
 * {@link #getMiddleName()}, etc are null, they are not included in the returned name
 *
 * @return all of the parts of this {@link PersonName} joined with spaces
 * @should not put spaces around an empty middle name
 */
public String getFullName() {
    NameTemplate nameTemplate = null;
    try {
        nameTemplate = NameSupport.getInstance().getDefaultLayoutTemplate();
    } catch (APIException ex) {
        log.warn("No name layout format set");
    }
    if (nameTemplate != null) {
        return nameTemplate.format(this);
    }
    List<String> temp = new ArrayList<>();
    if (StringUtils.hasText(getPrefix())) {
        temp.add(getPrefix());
    }
    if (StringUtils.hasText(getGivenName())) {
        temp.add(getGivenName());
    }
    if (StringUtils.hasText(getMiddleName())) {
        temp.add(getMiddleName());
    }
    if (OpenmrsConstants.PERSON_NAME_FORMAT_LONG.equals(PersonName.getFormat())) {
        if (StringUtils.hasText(getFamilyNamePrefix())) {
            temp.add(getFamilyNamePrefix());
        }
        if (StringUtils.hasText(getFamilyName())) {
            temp.add(getFamilyName());
        }
        if (StringUtils.hasText(getFamilyName2())) {
            temp.add(getFamilyName2());
        }
        if (StringUtils.hasText(getFamilyNameSuffix())) {
            temp.add(getFamilyNameSuffix());
        }
        if (StringUtils.hasText(getDegree())) {
            temp.add(getDegree());
        }
    } else {
        if (StringUtils.hasText(getFamilyName())) {
            temp.add(getFamilyName());
        }
    }
    String nameString = StringUtils.collectionToDelimitedString(temp, " ");
    return nameString.trim();
}
Also used : APIException(org.openmrs.api.APIException) NameTemplate(org.openmrs.layout.name.NameTemplate) ArrayList(java.util.ArrayList) StringUtils.defaultString(org.apache.commons.lang3.StringUtils.defaultString)

Example 3 with NameTemplate

use of org.openmrs.layout.name.NameTemplate in project openmrs-module-pihcore by PIH.

the class NameTemplateComponentTest method verifyNameTemplateConfigured.

@Ignore
@Test
public void verifyNameTemplateConfigured() {
    activator = new PihCoreActivator();
    activator.contextRefreshed();
    assertThat(nameSupport.getDefaultLayoutFormat(), is("short"));
    NameTemplate nameTemplate = nameSupport.getLayoutTemplateByCodeName("short");
    assertThat(nameTemplate.getLineByLineFormat().get(0), is("givenName"));
    assertThat(nameTemplate.getLineByLineFormat().get(1), is("familyName"));
    assertThat(nameTemplate.getLineByLineFormat().get(2), is("middleName"));
    assertThat(nameTemplate.getNameMappings().get("givenName"), is("zl.givenName"));
    assertThat(nameTemplate.getNameMappings().get("familyName"), is("zl.familyName"));
    assertThat(nameTemplate.getNameMappings().get("middleName"), is("zl.nickname"));
}
Also used : NameTemplate(org.openmrs.layout.name.NameTemplate) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with NameTemplate

use of org.openmrs.layout.name.NameTemplate in project openmrs-module-pihcore by PIH.

the class NameTemplateSetup method configureNameTemplate.

public static void configureNameTemplate(NameSupport nameSupport, Config config) {
    if (config != null) {
        if (config.getCountry() == ConfigDescriptor.Country.PERU) {
            NameTemplate nameTemplate = new NameTemplate();
            // we are redefining the short name template for use in our context
            nameTemplate.setCodeName("short");
            Map<String, String> nameMappings = new HashMap<String, String>();
            nameMappings.put("givenName", "zl.givenName");
            nameMappings.put("familyName", "zl.familyName");
            nameMappings.put("familyName2", "zl.familyName2");
            nameTemplate.setNameMappings(nameMappings);
            Map<String, String> sizeMappings = new HashMap<String, String>();
            sizeMappings.put("givenName", "50");
            sizeMappings.put("familyName", "50");
            sizeMappings.put("familyName2", "50");
            nameTemplate.setSizeMappings(sizeMappings);
            List<String> lineByLineFormat = new ArrayList<String>();
            lineByLineFormat.add("familyName");
            lineByLineFormat.add("familyName2,");
            lineByLineFormat.add("givenName");
            nameTemplate.setLineByLineFormat(lineByLineFormat);
            List<NameTemplate> templates = new ArrayList<NameTemplate>();
            templates.add(nameTemplate);
            // we blow away the other templates here, is that a bad thing?
            nameSupport.setLayoutTemplates(templates);
            nameSupport.setDefaultLayoutFormat("short");
        } else {
            NameTemplate nameTemplate = new NameTemplate();
            // we are redefining the short name template for use in our context
            nameTemplate.setCodeName("short");
            Map<String, String> nameMappings = new HashMap<String, String>();
            nameMappings.put("givenName", "zl.givenName");
            nameMappings.put("familyName", "zl.familyName");
            nameMappings.put("middleName", "zl.nickname");
            nameTemplate.setNameMappings(nameMappings);
            Map<String, String> sizeMappings = new HashMap<String, String>();
            sizeMappings.put("givenName", "50");
            sizeMappings.put("familyName", "50");
            sizeMappings.put("middleName", "50");
            nameTemplate.setSizeMappings(sizeMappings);
            List<String> lineByLineFormat = new ArrayList<String>();
            lineByLineFormat.add("familyName,");
            lineByLineFormat.add("givenName");
            lineByLineFormat.add("'middleName'");
            nameTemplate.setLineByLineFormat(lineByLineFormat);
            List<NameTemplate> templates = new ArrayList<NameTemplate>();
            templates.add(nameTemplate);
            // we blow away the other templates here, is that a bad thing?
            nameSupport.setLayoutTemplates(templates);
            nameSupport.setDefaultLayoutFormat("short");
        }
    }
}
Also used : HashMap(java.util.HashMap) NameTemplate(org.openmrs.layout.name.NameTemplate) ArrayList(java.util.ArrayList)

Aggregations

NameTemplate (org.openmrs.layout.name.NameTemplate)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 StringUtils.defaultString (org.apache.commons.lang3.StringUtils.defaultString)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 APIException (org.openmrs.api.APIException)1