本文整理汇总了Java中org.openmrs.Person.addName方法的典型用法代码示例。如果您正苦于以下问题:Java Person.addName方法的具体用法?Java Person.addName怎么用?Java Person.addName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openmrs.Person
的用法示例。
在下文中一共展示了Person.addName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupFormBackingObject
import org.openmrs.Person; //导入方法依赖的package包/类
/**
* Setup the person object. Should be called by the
* PersonFormController.formBackingObject(request)
*
* @param person
* @return the given person object
*/
protected Person setupFormBackingObject(Person person) {
// set a default name and address for the person. This allows us to use person.names[0] binding in the jsp
if (person.getNames().size() < 1) {
person.addName(new PersonName());
}
if (person.getAddresses().size() < 1) {
person.addAddress(new PersonAddress());
}
// initialize the user/person sets
// hibernate seems to have an issue with empty lists/sets if they aren't initialized
person.getAttributes().size();
return person;
}
示例2: createPerson
import org.openmrs.Person; //导入方法依赖的package包/类
/**
* Creates a new person stub.
*
* @param given
* @param middle
* @param family
* @param birthdate
* @param dateformat
* @param age
* @param gender
* @return PersonListItem person stub created
*/
public Object createPerson(String given, String middle, String family, String birthdate, String dateformat, String age,
String gender) {
log.error(given + " " + middle + " " + family + " " + birthdate + " " + dateformat + " " + age + " " + gender);
User user = Context.getAuthenticatedUser();
Person p = new Person();
p.setPersonCreator(user);
p.setPersonDateCreated(new Date());
p.setPersonChangedBy(user);
p.setPersonDateChanged(new Date());
if (StringUtils.isEmpty(gender)) {
log.error("Gender cannot be null.");
return String.valueOf("Gender cannot be null.");
} else if (gender.toUpperCase().contains("M")) {
p.setGender("M");
} else if (gender.toUpperCase().contains("F")) {
p.setGender("F");
} else {
log.error("Gender must be 'M' or 'F'.");
return new String("Gender must be 'M' or 'F'.");
}
if ("".equals(given) || "".equals(family)) {
log.error("Given name and family name cannot be null.");
return new String("Given name and family name cannot be null.");
}
PersonName name = new PersonName(given, middle, family);
name.setCreator(user);
name.setDateCreated(new Date());
name.setChangedBy(user);
name.setDateChanged(new Date());
p.addName(name);
try {
Date d = updateAge(birthdate, dateformat, age);
p.setBirthdate(d);
}
catch (java.text.ParseException pe) {
log.error(pe);
return new String("Birthdate cannot be parsed.");
}
p.setGender(gender);
Person person = Context.getPersonService().savePerson(p);
return PersonListItem.createBestMatch(person);
}
示例3: updatePersonNames
import org.openmrs.Person; //导入方法依赖的package包/类
/**
* Updates person names based on request parameters
*
* @param request
* @param person
*/
protected void updatePersonNames(HttpServletRequest request, Person person) {
Object[] objs = null;
objs = person.getNames().toArray();
for (int i = 0; i < objs.length; i++) {
if (request.getParameter("names[" + i + "].givenName") == null) {
person.removeName((PersonName) objs[i]);
}
}
//String[] prefs = request.getParameterValues("preferred"); (unreliable form info)
String[] gNames = ServletRequestUtils.getStringParameters(request, "givenName");
String[] mNames = ServletRequestUtils.getStringParameters(request, "middleName");
String[] fNamePrefixes = ServletRequestUtils.getStringParameters(request, "familyNamePrefix");
String[] fNames = ServletRequestUtils.getStringParameters(request, "familyName");
String[] fName2s = ServletRequestUtils.getStringParameters(request, "familyName2");
String[] fNameSuffixes = ServletRequestUtils.getStringParameters(request, "familyNameSuffix");
String[] degrees = ServletRequestUtils.getStringParameters(request, "degree");
String[] namePrefStatus = ServletRequestUtils.getStringParameters(request, "preferred");
if (gNames != null) {
for (int i = 0; i < gNames.length; i++) {
if (!"".equals(gNames[i])) { //skips invalid and blank address data box
PersonName pn = new PersonName();
if (namePrefStatus != null && namePrefStatus.length > i) {
pn.setPreferred(new Boolean(namePrefStatus[i]));
}
if (gNames.length >= i + 1) {
pn.setGivenName(gNames[i]);
}
if (mNames.length >= i + 1) {
pn.setMiddleName(mNames[i]);
}
if (fNamePrefixes.length >= i + 1) {
pn.setFamilyNamePrefix(fNamePrefixes[i]);
}
if (fNames.length >= i + 1) {
pn.setFamilyName(fNames[i]);
}
if (fName2s.length >= i + 1) {
pn.setFamilyName2(fName2s[i]);
}
if (fNameSuffixes.length >= i + 1) {
pn.setFamilyNameSuffix(fNameSuffixes[i]);
}
if (degrees.length >= i + 1) {
pn.setDegree(degrees[i]);
}
person.addName(pn);
}
}
Iterator<PersonName> names = person.getNames().iterator();
PersonName currentName = null;
PersonName preferredName = null;
while (names.hasNext()) {
currentName = names.next();
if (currentName.isPreferred()) {
if (preferredName != null) { // if there's a preferred name already exists, make it preferred=false
preferredName.setPreferred(false);
}
preferredName = currentName;
}
}
if ((preferredName == null) && (currentName != null)) { // No preferred name. Make the last name entry as preferred.
currentName.setPreferred(true);
}
}
}