/** * 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")); }
@Test public void shouldClearMillisecondsWhenUpdatingAnExistingObject() { Date dateWithMillisecond = new Date(567L); Date dateWithoutMillisecond = new Date(0L); Person person = personService.getPerson(1); person.setBirthdate(dateWithMillisecond); personService.savePerson(person); Context.flushSession(); assertThat(person.getBirthdate(), is(dateWithoutMillisecond)); }
assertThat(copyPerson.getBirthdate(), is(originalPerson.getBirthdate())); assertThat(copyPerson.getBirthdateEstimated(), is(originalPerson.getBirthdateEstimated())); assertThat(copyPerson.getDateCreated(), is(originalPerson.getDateCreated()));
@Test public void shouldClearMillisecondsWhenSavingANewObject() { Date dateWithMillisecond = new Date(567L); Date dateWithoutMillisecond = new Date(0L); Person person = new Person(); person.addName(new PersonName("Alice", null, "Paul")); person.setGender("F"); person.setBirthdate(dateWithMillisecond); personService.savePerson(person); Context.flushSession(); assertThat(person.getBirthdate(), is(dateWithoutMillisecond)); }
birthdate = person.getBirthdate(); birthtime = person.getBirthDateTime(); birthdateEstimated = person.getBirthdateEstimated();
validateBirthDate(errors, person.getBirthdate()); validateDeathDate(errors, person.getDeathDate(), person.getBirthdate());
birthdateEstimated = person.getBirthdate() != null && person.getBirthdateEstimated() != null && person.getBirthdate().equals(date) ? person.getBirthdateEstimated() : false;
@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); } }
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; }
Person person = new Person(); person.setBirthdateFromAge(expectedAge, new Date()); final Date expectedBirthDate = person.getBirthdate();
@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"); }