/** * Convenience method: sets a person's birth date from an age as of the given date Also sets * flag indicating that the birth date is inexact. This sets the person's birth date to January * 1 of the year that matches this age and date * * @param age (the age to set) * @param ageOnDate (null defaults to today) */ public void setBirthdateFromAge(int age, Date ageOnDate) { Calendar c = Calendar.getInstance(); c.setTime(ageOnDate == null ? new Date() : ageOnDate); c.set(Calendar.DATE, 1); c.set(Calendar.MONTH, Calendar.JANUARY); c.add(Calendar.YEAR, -1 * age); setBirthdate(c.getTime()); setBirthdateEstimated(true); }
@Test public void savePerson_shouldSavePersonWithBirthDateTime() throws ParseException { Person person = new Person(); person.setBirthtime(new SimpleDateFormat("HH:mm:ss").parse("15:23:56")); person.setBirthdate(new SimpleDateFormat("yyyy-MM-dd").parse("2012-05-29")); person.setDead(false); person.setVoided(false); person.setBirthdateEstimated(false); person.setId(345); hibernatePersonDAO.savePerson(person); Person savedPerson = hibernatePersonDAO.getPerson(345); Assert.assertEquals(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2012-05-29 15:23:56"), savedPerson.getBirthDateTime()); }
person.setBirthdateEstimated(true);
originalPerson.setGender("M"); originalPerson.setBirthdate(date); originalPerson.setBirthdateEstimated(false); originalPerson.setUuid("abc123"); originalPerson.setDateCreated(date);
@PropertySetter("age") public static void setAge(Person person, Integer age) throws ResourceDoesNotSupportOperationException { if (person.getBirthdate() == null && age != null) { person.setBirthdateFromAge(age, new Date()); person.setBirthdateEstimated(true); } }
person.setBirthdateEstimated(birthdateEstimated);
PersonHelper.updatePersonName(personToUpdate, person); personToUpdate.setBirthdate(person.getDateOfBirth().toDate()); personToUpdate.setBirthdateEstimated(person.getBirthDateEstimated()); personToUpdate.setGender(person.getGender());
public static Person createPerson(MRSPerson person, List<PersonAttributeType> allPersonAttributeTypes) { Person converted = new Person(); if (person.getDateOfBirth() != null) { converted.setBirthdate(person.getDateOfBirth().toDate()); } if (person.getDeathDate() != null) { converted.setDeathDate(person.getDeathDate().toDate()); } converted.setBirthdateEstimated((Boolean) ObjectUtils.defaultIfNull(person.getBirthDateEstimated(), false)); converted.setDead(person.isDead()); converted.setGender(person.getGender()); converted.addName(new PersonName(person.getFirstName(), person.getMiddleName(), person.getLastName())); if (person.getAddress() != null) { PersonAddress personAddress = new PersonAddress(); personAddress.setAddress1(person.getAddress()); converted.addAddress(personAddress); } for (MRSAttribute attribute : person.getAttributes()) { PersonAttributeType attributeType = (PersonAttributeType) selectUnique(allPersonAttributeTypes, having(on(PersonAttributeType.class).getName(), equalTo(attribute.getName()))); converted.addAttribute(new PersonAttribute(attributeType, attribute.getValue())); } return converted; }