/** * @return Returns the preferred. * * @deprecated as of 2.0, use {@link #getPreferred()} */ @Deprecated @JsonIgnore public Boolean isPreferred() { return getPreferred(); }
/** * @see java.lang.Comparable#compareTo(java.lang.Object) * Note: this comparator imposes orderings that are inconsistent with equals. */ @Override @SuppressWarnings("squid:S1210") public int compareTo(PersonAddress other) { int retValue = 0; if (other != null) { retValue = getVoided().compareTo(other.getVoided()); if (retValue == 0) { retValue = other.getPreferred().compareTo(getPreferred()); } if (retValue == 0 && getDateCreated() != null) { retValue = OpenmrsUtil.compareWithNullAsLatest(getDateCreated(), other.getDateCreated()); } if (retValue == 0) { retValue = OpenmrsUtil.compareWithNullAsGreatest(getPersonAddressId(), other.getPersonAddressId()); } // if we've gotten this far, just check all address values. If they are // equal, leave the objects at 0. If not, arbitrarily pick retValue=1 // and return that (they are not equal). if (retValue == 0 && !equalsContent(other)) { retValue = 1; } } return retValue; }
if (addr.getPreferred() && !addr.getVoided()) { return addr;
private void setPreferredPersonAddress(Person person) { PersonAddress preferredAddress = null; PersonAddress possiblePreferredAddress = person.getPersonAddress(); if (possiblePreferredAddress != null && possiblePreferredAddress.getPreferred() && !possiblePreferredAddress.getVoided()) { preferredAddress = possiblePreferredAddress; } for (PersonAddress address : person.getAddresses()) { if (preferredAddress == null && !address.getVoided()) { address.setPreferred(true); preferredAddress = address; continue; } if (!address.equals(preferredAddress)) { address.setPreferred(false); } } }
private void setPreferredPatientAddress(Patient patient) { PersonAddress preferredAddress = null; PersonAddress possiblePreferredAddress = patient.getPersonAddress(); if (possiblePreferredAddress != null && possiblePreferredAddress.getPreferred() && !possiblePreferredAddress.getVoided()) { preferredAddress = possiblePreferredAddress; } for (PersonAddress address : patient.getAddresses()) { if (preferredAddress == null && !address.getVoided()) { address.setPreferred(true); preferredAddress = address; continue; } if (!address.equals(preferredAddress)) { address.setPreferred(false); } } }
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldOnlyMarkAddressesOfPreferredPatientAsPreferred() throws Exception { Patient preferred = patientService.getPatient(7); Patient notPreferred = patientService.getPatient(8); // since the test data has no preferred addresses, we need to mark addresses to preferred to set up the test preferred.getPersonAddress().setPreferred(true); notPreferred.getPersonAddress().setPreferred(true); patientService.savePatient(preferred); patientService.savePatient(notPreferred); patientService.mergePatients(preferred, notPreferred); Assert.assertThat(preferred.getAddresses().size(), is(2)); // make sure only the address from the preferred patient is marked as preferred for (PersonAddress pa : preferred.getAddresses()) { if (pa.getCityVillage().equals("Jabali")) { Assert.assertFalse(pa.getPreferred()); } } }
/** * @see PersonService#savePerson(Person) */ @Test public void savePerson_shouldSetThePreferredNameAndAddressIfNoneIsSpecified() throws Exception { Person person = new Person(); person.setGender("M"); PersonName name = new PersonName("givenName", "middleName", "familyName"); person.addName(name); PersonAddress address = new PersonAddress(); address.setAddress1("some address"); person.addAddress(address); personService.savePerson(person); assertTrue(name.getPreferred()); assertTrue(address.getPreferred()); }
/** * @see PersonService#savePerson(Person) */ @Test public void savePerson_shouldNotSetThePreferredNameAndAddressIfTheyAlreadyExist() throws Exception { Person person = new Person(); person.setGender("M"); PersonName name = new PersonName("givenName", "middleName", "familyName"); PersonName preferredName = new PersonName("givenName", "middleName", "familyName"); preferredName.setPreferred(true); person.addName(name); person.addName(preferredName); PersonAddress address = new PersonAddress(); address.setAddress1("some address"); PersonAddress preferredAddress = new PersonAddress(); preferredAddress.setAddress1("another address"); preferredAddress.setPreferred(true); person.addAddress(address); person.addAddress(preferredAddress); personService.savePerson(person); assertTrue(preferredName.getPreferred()); assertTrue(preferredAddress.getPreferred()); Assert.assertFalse(name.getPreferred()); Assert.assertFalse(address.getPreferred()); }
/** * @see PersonService#savePerson(Person) */ @Test public void savePerson_shouldNotSetAVoidedNameOrAddressAsPreferred() throws Exception { Person person = new Person(); person.setGender("M"); PersonName name = new PersonName("givenName", "middleName", "familyName"); PersonName preferredName = new PersonName("givenName", "middleName", "familyName"); preferredName.setPreferred(true); preferredName.setVoided(true); person.addName(name); person.addName(preferredName); PersonAddress address = new PersonAddress(); address.setAddress1("some address"); PersonAddress preferredAddress = new PersonAddress(); preferredAddress.setAddress1("another address"); preferredAddress.setPreferred(true); preferredAddress.setVoided(true); person.addAddress(address); person.addAddress(preferredAddress); personService.savePerson(person); Assert.assertFalse(preferredName.getPreferred()); Assert.assertFalse(preferredAddress.getPreferred()); assertTrue(name.getPreferred()); assertTrue(address.getPreferred()); }
/** * @see PatientService#savePatient(Patient) */ @Test public void savePatient_shouldSetThePreferredNameAddressAndIdentifierIfNoneIsSpecified() throws Exception { Patient patient = new Patient(); patient.setGender("M"); PatientIdentifier identifier = new PatientIdentifier("QWERTY", patientService.getPatientIdentifierType(2), locationService.getLocation(1)); patient.addIdentifier(identifier); PersonName name = new PersonName("givenName", "middleName", "familyName"); patient.addName(name); PersonAddress address = new PersonAddress(); address.setAddress1("some address"); patient.addAddress(address); Context.getPatientService().savePatient(patient); Assert.assertTrue(identifier.getPreferred()); Assert.assertTrue(name.getPreferred()); Assert.assertTrue(address.getPreferred()); }
Assert.assertTrue(preferredIdentifier.getPreferred()); Assert.assertTrue(preferredName.getPreferred()); Assert.assertTrue(preferredAddress.getPreferred()); Assert.assertFalse(identifier.getPreferred()); Assert.assertFalse(name.getPreferred()); Assert.assertFalse(address.getPreferred());
Assert.assertFalse(preferredIdentifier.getPreferred()); Assert.assertFalse(preferredName.getPreferred()); Assert.assertFalse(preferredAddress.getPreferred()); Assert.assertTrue(identifier.getPreferred()); Assert.assertTrue(name.getPreferred()); Assert.assertTrue(address.getPreferred());
private static void copyAddressFields(PersonAddress existingAddress, PersonAddress address) { existingAddress.setPreferred(address.getPreferred()); existingAddress.setAddress1(address.getAddress1()); existingAddress.setAddress2(address.getAddress2()); existingAddress.setAddress3(address.getAddress3()); existingAddress.setAddress4(address.getAddress4()); existingAddress.setAddress5(address.getAddress5()); existingAddress.setAddress6(address.getAddress6()); existingAddress.setCityVillage(address.getCityVillage()); existingAddress.setCountry(address.getCountry()); existingAddress.setStateProvince(address.getStateProvince()); existingAddress.setCountyDistrict(address.getCountyDistrict()); existingAddress.setPostalCode(address.getPostalCode()); existingAddress.setLatitude(address.getLatitude()); existingAddress.setLongitude(address.getLongitude()); existingAddress.setDateCreated(address.getDateCreated()); }
@Override public void validateFullRepresentation() throws Exception { super.validateFullRepresentation(); assertPropEquals("preferred", getObject().getPreferred()); assertPropEquals("address1", getObject().getAddress1()); assertPropEquals("address2", getObject().getAddress2()); assertPropEquals("cityVillage", getObject().getCityVillage()); assertPropEquals("stateProvince", getObject().getStateProvince()); assertPropEquals("country", getObject().getCountry()); assertPropEquals("postalCode", getObject().getPostalCode()); assertPropEquals("countyDistrict", getObject().getCountyDistrict()); assertPropEquals("address3", getObject().getAddress3()); assertPropEquals("address4", getObject().getAddress4()); assertPropEquals("address5", getObject().getAddress5()); assertPropEquals("address6", getObject().getAddress6()); assertPropPresent("startDate"); assertPropPresent("endDate"); assertPropEquals("latitude", getObject().getLatitude()); assertPropEquals("longitude", getObject().getLongitude()); assertPropEquals("voided", getObject().getVoided()); assertPropPresent("auditInfo"); }
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("preferred", getObject().getPreferred()); assertPropEquals("address1", getObject().getAddress1()); assertPropEquals("address2", getObject().getAddress2()); assertPropEquals("cityVillage", getObject().getCityVillage()); assertPropEquals("stateProvince", getObject().getStateProvince()); assertPropEquals("country", getObject().getCountry()); assertPropEquals("postalCode", getObject().getPostalCode()); assertPropEquals("countyDistrict", getObject().getCountyDistrict()); assertPropEquals("address3", getObject().getAddress3()); assertPropEquals("address4", getObject().getAddress4()); assertPropEquals("address5", getObject().getAddress5()); assertPropEquals("address6", getObject().getAddress6()); assertPropPresent("startDate"); assertPropPresent("endDate"); assertPropEquals("latitude", getObject().getLatitude()); assertPropEquals("longitude", getObject().getLongitude()); assertPropEquals("voided", getObject().getVoided()); assertPropEquals("uuid", getObject().getUuid()); }
@Override public void validateFullRepresentation() throws Exception { super.validateFullRepresentation(); assertPropEquals("preferred", getObject().getPreferred()); assertPropEquals("address1", getObject().getAddress1()); assertPropEquals("address2", getObject().getAddress2());
@Override public void validateDefaultRepresentation() throws Exception { super.validateDefaultRepresentation(); assertPropEquals("preferred", getObject().getPreferred()); assertPropEquals("address1", getObject().getAddress1()); assertPropEquals("address2", getObject().getAddress2());