Refine search
@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)); }
personId = person.getPersonId(); setUuid(person.getUuid()); addresses = person.getAddresses(); names = person.getNames(); attributes = person.getAttributes(); gender = person.getGender(); birthdate = person.getBirthdate(); birthtime = person.getBirthDateTime(); birthdateEstimated = person.getBirthdateEstimated(); deathdateEstimated = person.getDeathdateEstimated(); dead = person.getDead(); deathDate = person.getDeathDate(); causeOfDeath = person.getCauseOfDeath(); causeOfDeathNonCoded = person.getCauseOfDeathNonCoded(); setPersonCreator(person.getPersonCreator()); setPersonDateCreated(person.getPersonDateCreated()); setPersonChangedBy(person.getPersonChangedBy()); setPersonDateChanged(person.getPersonDateChanged()); setPersonVoided(person.getPersonVoided()); setPersonVoidedBy(person.getPersonVoidedBy()); setPersonDateVoided(person.getPersonDateVoided()); setPersonVoidReason(person.getPersonVoidReason()); setPatient(person.getIsPatient());
private void checkGetPersonNameResultForVoidedPerson(PersonName expectedPersonAddress, Set<PersonName> personAddresses) { Person person = new Person(); person.setVoided(true); for (PersonName personName : personAddresses) { person.addName(personName); } PersonName actualPersonName = person.getPersonName(); assertEquals(expectedPersonAddress, actualPersonName); }
if (person.getAddresses() != null && !person.getAddresses().isEmpty()) { for (PersonAddress pAddress : person.getAddresses()) { if (pAddress.isBlank()){ person.removeAddress(pAddress); continue; if (person.getNames() != null && !person.getNames().isEmpty()) { for (PersonName pName : person.getNames()) { pName.setPerson(person); if (person.getAttributes() != null && !person.getAttributes().isEmpty()) { for (PersonAttribute pAttr : person.getAttributes()) { pAttr.setPerson(person); if (!person.getDead() && person.getCauseOfDeath() != null) { person.setCauseOfDeath(null); if (person.getPersonVoided()) { if (!StringUtils.hasLength(person.getPersonVoidReason())) { throw new APIException("Person.voided.bit", new Object[] { person }); if (person.getPersonVoidedBy() == null) { person.setPersonVoidedBy(creator); if (person.getPersonDateVoided() == null) { person.setPersonDateVoided(dateCreated); person.setPersonVoidedBy(null);
/** * @see BaseVoidHandler#handle(Voidable,User,Date,String) */ @Test public void handle_shouldNotSetDateVoidedIfNonNull() { Date d = new Date(new Date().getTime() - 1000); // a time that is not "now" VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); voidable.setDateVoided(d); // make dateVoided non null handler.handle(voidable, null, new Date(), " "); Assert.assertEquals(d, voidable.getDateVoided()); }
/** * @see PersonUnvoidHandler#handle(Person,User,Date,String) */ @Test public void handle_shouldNotActOnObjectsWithADifferentPersonDateVoided() { Date d = new Date(new Date().getTime() - 1000); // a time that isn't right now UnvoidHandler<Person> handler = new PersonUnvoidHandler(); Person person = new Person(); person.setPersonVoided(true); person.setPersonDateVoided(d); handler.handle(person, null, new Date(), "SOME REASON"); Assert.assertTrue(person.getPersonVoided()); } }
/** * @see PersonVoidHandler#handle(Person,User,Date,String) */ @Test public void handle_shouldNotSetPersonDateVoidedIfNonNull() { Date d = new Date(new Date().getTime() - 1000); // a time that is not "now" VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); person.setPersonDateVoided(d); // make personDateVoided non null handler.handle(person, null, new Date(), " "); assertEquals(d, person.getPersonDateVoided()); }
/** * @see BaseVoidHandler#handle(Voidable,User,Date,String) */ @Test public void handle_shouldSetDateVoided() { Date d = new Date(); VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); handler.handle(voidable, null, d, " "); Assert.assertEquals(d, voidable.getDateVoided()); }
Person p = new Person(); assertNotNull(p.getAddresses()); pa1.setDateCreated(new Date()); pa1.setVoided(false); p.addAddress(pa1); assertTrue("There should be 1 address in the person object but there is actually : " + p.getAddresses().size(), p .getAddresses().size() == 1); p.addAddress(pa1); assertTrue("There should be 1 address in the person object but there is actually : " + p.getAddresses().size(), p .getAddresses().size() == 1); p.addAddress(pa2); assertTrue("There should be 2 addresses in the person object but there is actually : " + p.getAddresses().size(), p .getAddresses().size() == 2); p.addAddress(pa3); assertTrue("There should be 2 addresses in the person object but there is actually : " + p.getAddresses().size(), p .getAddresses().size() == 2); p.addAddress(pa3); assertTrue("There should be 3 addresses in the person object but there is actually : " + p.getAddresses().size(), p .getAddresses().size() == 3);
Person p = new Person(); assertNotNull(p.getNames()); pa1.setDateCreated(new Date()); pa1.setVoided(false); p.addName(pa1); assertTrue("There should be 1 name in the person object but there is actually : " + p.getNames().size(), p .getNames().size() == 1); p.addName(pa1); assertTrue("There should be 1 name in the person object but there is actually : " + p.getNames().size(), p .getNames().size() == 1); p.addName(pa2); assertTrue("There should be 2 names in the person object but there is actually : " + p.getNames().size(), p .getNames().size() == 2); p.addName(pa3); assertTrue("There should be 2 names in the person object but there is actually : " + p.getNames().size(), p .getNames().size() == 2); pa4.setVoided(false); pa4.setVoided(true); p.addName(pa4);
/** * @see PersonService#savePerson(Person) */ @Test public void savePerson_shouldCreateNewObjectWhenPersonIdIsNull() throws Exception { User user = Context.getAuthenticatedUser(); Person person = new Person(); person.setPersonCreator(user); person.setPersonDateCreated(new Date()); person.setPersonChangedBy(user); person.setPersonDateChanged(new Date()); person.setGender("F"); Assert.assertNull(person.getId()); person.addName(new PersonName("givenName", "middleName", "familyName")); Person personSaved = Context.getPersonService().savePerson(person); Assert.assertNotNull(personSaved.getId()); }
@Test public void shouldSetDeadToTrueIfSetDeathdate() { Person p = new Person(); Date deathDate = new Date(); p.setDeathDate(deathDate); assertTrue ("Person must be dead(setDead(true)) inorder have a deathDate set for him", p.getDead()); }
/** * @see PersonUnvoidHandler#handle(Person,User,Date,String) */ @Test public void handle_shouldUnsetThePersonDateVoided() { UnvoidHandler<Person> handler = new PersonUnvoidHandler(); Person person = new Person(); person.setPersonVoided(true); person.setPersonDateVoided(new Date()); handler.handle(person, null, null, null); Assert.assertNull(person.getPersonDateVoided()); }
@Test public void shouldSerializeOpenMrsData() { Person originalPerson = new Person(); originalPerson.setGender("M"); originalPerson.setBirthdate(date); originalPerson.setBirthdateEstimated(false); originalPerson.setUuid("abc123"); originalPerson.setDateCreated(date); originalPerson.setCreator(user); originalPerson.setDateChanged(date); originalPerson.setChangedBy(user); originalPerson.setVoided(true); originalPerson.setVoidedBy(user); originalPerson.setDateVoided(date); originalPerson.setVoidReason("test"); assertThat(copyPerson.getGender(), is(originalPerson.getGender())); assertThat(copyPerson.getBirthdate(), is(originalPerson.getBirthdate())); assertThat(copyPerson.getBirthdateEstimated(), is(originalPerson.getBirthdateEstimated())); assertThat(copyPerson.getDateCreated(), is(originalPerson.getDateCreated())); assertThat(copyPerson.getCreator(), is(originalPerson.getCreator())); assertThat(copyPerson.getDateChanged(), is(originalPerson.getDateChanged())); assertThat(copyPerson.getChangedBy(), is(originalPerson.getChangedBy())); assertThat(copyPerson.getVoided(), is(originalPerson.getVoided())); assertThat(copyPerson.getVoidedBy(), is(originalPerson.getVoidedBy())); assertThat(copyPerson.getDateVoided(), is(originalPerson.getDateVoided())); assertThat(copyPerson.getVoidReason(), is(originalPerson.getVoidReason())); assertThat(copyPerson.getUuid(), is(originalPerson.getUuid()));
/** * @see org.openmrs.validator.PersonValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { Person person = new Person(1); person.setBirthdate(new Date()); person.setGender("g"); person.setPersonVoided(true); person.setPersonVoidReason("voidReason"); Errors errors = new BindException(person, "person"); PersonValidator personValidator = new PersonValidator(); personValidator.validate(person, errors); Assert.assertFalse(errors.hasErrors()); }
@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)); }
/** * @see PersonVoidHandler#handle(Person,User,Date,String) */ @Test public void handle_shouldSetPersonDateVoided() { Date d = new Date(); VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); handler.handle(person, null, d, " "); assertEquals(d, person.getPersonDateVoided()); }
birthdateEstimated = person.getBirthdate() != null && person.getBirthdateEstimated() != null && person.getBirthdate().equals(date) ? person.getBirthdateEstimated() : false; Double ageRemainder = BigDecimal.valueOf(age).subtract(BigDecimal.valueOf(Math.floor(age))).doubleValue(); if (ageRemainder.equals(Double.valueOf(0))) person.setBirthdateFromAge(age.intValue(), new Date()); //default to usual behavior from core else { //a decimal was entered Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.DAY_OF_MONTH, - Double.valueOf((ageRemainder * 365)).intValue()); //if patient is 2.2 years old, patient was 2.0 years 2.2 - (.2*365) days ago c.add(Calendar.YEAR, -1 * Double.valueOf(Math.floor(age)).intValue()); person.setBirthdate(birthdate); person.setBirthdateEstimated(birthdateEstimated);
@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); } }