/** * Convenience method to calculate this person's age based on the birthdate For a person who * lived 1990 to 2000, age would be -5 in 1985, 5 in 1995, 10 in 2000, and 10 2010. * * @return Returns age as an Integer. * @should get correct age after death */ public Integer getAge() { return getAge(null); }
/** * @see Person#getAge(Date) */ @Test public void getAge_shouldGetAgeBeforeBirthday() { Calendar birthdate = Calendar.getInstance(); birthdate.set(2006, Calendar.JUNE, 2); Calendar onDate = Calendar.getInstance(); onDate.set(2008, Calendar.JUNE, 1); Person person = new Person(); person.setBirthdate(birthdate.getTime()); assertEquals(person.getAge(onDate.getTime()), 1, 0); }
/** * @see Person#getAge(Date) */ @Test public void getAge_shouldGetAgeAfterBirthday() { Calendar birthdate = Calendar.getInstance(); birthdate.set(2006, Calendar.JUNE, 2); Calendar onDate = Calendar.getInstance(); onDate.set(2008, Calendar.JUNE, 3); Person person = new Person(); person.setBirthdate(birthdate.getTime()); assertEquals(person.getAge(onDate.getTime()), 2, 0); }
/** * @see Person#getAge(Date) */ @Test public void getAge_shouldGetAgeOnBirthdayWithMinutesDefined() { Calendar birthdate = Calendar.getInstance(); birthdate.set(2006, Calendar.JUNE, 2, 9, 9, 9); Calendar onDate = Calendar.getInstance(); onDate.set(2008, Calendar.JUNE, 2, 7, 7, 7); Person person = new Person(); person.setBirthdate(birthdate.getTime()); assertEquals(person.getAge(onDate.getTime()), 2, 0); }
/** * @see Person#getAge(Date) */ @Test public void getAge_shouldGetAgeOnBirthdayWithNoMinutesDefined() { Calendar birthdate = Calendar.getInstance(); birthdate.set(2006, Calendar.JUNE, 2); Calendar onDate = Calendar.getInstance(); onDate.set(2008, Calendar.JUNE, 2); Person person = new Person(); person.setBirthdate(birthdate.getTime()); assertEquals(person.getAge(onDate.getTime()), 2, 0); }
/** * @see Person#getAge(Date) */ @Test public void getAge_shouldGetAgeWithGivenDateBeforeDeath() { Calendar birthdate = Calendar.getInstance(); birthdate.set(1990, Calendar.JUNE, 2); Calendar deathDate = Calendar.getInstance(); deathDate.set(2000, Calendar.JUNE, 3); Calendar givenDate = Calendar.getInstance(); givenDate.set(1995, Calendar.JUNE, 3); Person person = new Person(); person.setBirthdate(birthdate.getTime()); person.setDead(true); person.setDeathDate(deathDate.getTime()); assertEquals(5, person.getAge(givenDate.getTime()), 0); }
/** * @see Person#getAge(Date) */ @Test public void getAge_shouldGetAgeWithGivenDateAfterDeath() { Calendar birthdate = Calendar.getInstance(); birthdate.set(1990, Calendar.JUNE, 2); Calendar deathDate = Calendar.getInstance(); deathDate.set(2000, Calendar.JUNE, 3); Calendar givenDate = Calendar.getInstance(); givenDate.set(2010, Calendar.JUNE, 3); Person person = new Person(); person.setBirthdate(birthdate.getTime()); person.setDead(true); person.setDeathDate(deathDate.getTime()); assertEquals(10, person.getAge(givenDate.getTime()), 0); }
/** * @see Person#getAge(Date) */ @Test public void getAge_shouldGetAgeWithGivenDateBeforeBirth() { Calendar birthdate = Calendar.getInstance(); birthdate.set(1990, Calendar.JUNE, 2); Calendar deathDate = Calendar.getInstance(); deathDate.set(2000, Calendar.JUNE, 3); Calendar givenDate = Calendar.getInstance(); givenDate.set(1985, Calendar.JUNE, 3); Person person = new Person(); person.setBirthdate(birthdate.getTime()); person.setDead(true); person.setDeathDate(deathDate.getTime()); assertEquals(-5, person.getAge(givenDate.getTime()), 0); }
/** * @see Person#getAge() */ @Test public void getAge_shouldGetAgeAfterDeath() { Calendar birthdate = Calendar.getInstance(); birthdate.set(1990, Calendar.JUNE, 2); Calendar deathDate = Calendar.getInstance(); deathDate.set(2000, Calendar.JUNE, 3); Person person = new Person(); person.setBirthdate(birthdate.getTime()); person.setDead(true); person.setDeathDate(deathDate.getTime()); assertEquals(10, person.getAge(), 0); }
/** * Test that setting a person's age correctly sets their birth date and records that this is * inexact * * @throws ParseException * @throws Exception */ @Test public void shouldSetInexactBirthdateFromAge() throws ParseException { DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); Person p = new Person(); // Test that default values are correct assertNull(p.getAge()); assertFalse(p.getBirthdateEstimated()); // Test standard case and ensure estimated field is set to true p.setBirthdateFromAge(10, df.parse("2008-05-20")); assertEquals(p.getBirthdate(), df.parse("1998-01-01")); assertTrue(p.getBirthdateEstimated()); // Test boundary cases p.setBirthdateFromAge(52, df.parse("2002-01-01")); assertEquals(p.getBirthdate(), df.parse("1950-01-01")); p.setBirthdateFromAge(35, df.parse("2004-12-31")); assertEquals(p.getBirthdate(), df.parse("1969-01-01")); p.setBirthdateFromAge(0, df.parse("2008-05-20")); assertEquals(p.getBirthdate(), df.parse("2008-01-01")); }
public static OpenMRSPerson openMRSToMRSPerson(Person person) { Set<PersonName> personNames = person.getNames(); PersonName personName = getFirstName(personNames); final List<OpenMRSAttribute> attributes = project(person.getAttributes(), OpenMRSAttribute.class, on(PersonAttribute.class).getAttributeType().toString(), on(PersonAttribute.class).getValue()); List<MRSAttribute> personAttributes = new ArrayList<MRSAttribute>(); personAttributes.addAll(attributes); OpenMRSPerson mrsPerson = new OpenMRSPerson().firstName(personName.getGivenName()).middleName(personName.getMiddleName()) .lastName(personName.getFamilyName()).birthDateEstimated(person.getBirthdateEstimated()).gender(person.getGender()).age(person.getAge()) .address(getAddress(person)).attributes(personAttributes).dateOfBirth(new DateTime(person.getBirthdate())).dead(person.isDead()).deathDate(new DateTime(person.getDeathDate())); if (person.getId() != null) { mrsPerson.id(Integer.toString(person.getId())); } return mrsPerson; }
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("gender", getObject().getGender()); assertPropEquals("age", getObject().getAge()); assertPropEquals("birthdate", getObject().getBirthdate()); assertPropEquals("birthdateEstimated", getObject().getBirthdateEstimated()); assertPropEquals("dead", getObject().getDead()); assertPropEquals("deathDate", getObject().getDeathDate()); assertPropPresent("causeOfDeath"); assertPropPresent("preferredName"); assertPropPresent("preferredAddress"); assertPropPresent("attributes"); assertPropEquals("voided", getObject().getVoided()); }
@Override public void validateFullRepresentation() throws Exception { super.validateFullRepresentation(); assertPropEquals("gender", getObject().getGender()); assertPropEquals("age", getObject().getAge()); assertPropEquals("birthdate", getObject().getBirthdate()); assertPropEquals("birthdateEstimated", getObject().getBirthdateEstimated()); assertPropEquals("dead", getObject().getDead()); assertPropEquals("deathDate", getObject().getDeathDate()); assertPropPresent("causeOfDeath"); assertPropPresent("preferredName"); assertPropPresent("preferredAddress"); assertPropPresent("names"); assertPropPresent("addresses"); assertPropPresent("attributes"); assertPropEquals("voided", getObject().getVoided()); assertPropPresent("auditInfo"); }