use of org.openmrs.PersonAddress in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldAuditCreatedAddresses.
/**
* @see PatientService#mergePatients(Patient,Patient)
*/
@Test
public void mergePatients_shouldAuditCreatedAddresses() throws Exception {
// retrieve preferred patient
Patient preferred = patientService.getPatient(999);
// retrieve notPreferredPatient and save it with a new address
Patient notPreferred = patientService.getPatient(2);
voidOrders(Collections.singleton(notPreferred));
PersonAddress address = new PersonAddress();
address.setAddress1("another address123");
address.setAddress2("another address234");
address.setCityVillage("another city");
address.setCountry("another country");
notPreferred.addAddress(address);
patientService.savePatient(notPreferred);
// merge the two patients and retrieve the audit object
PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
// find the UUID of the address that was added by the merge
String addedAddressUuid = null;
preferred = patientService.getPatient(999);
for (PersonAddress a : preferred.getAddresses()) {
if (a.getAddress1().equals(address.getAddress1())) {
addedAddressUuid = a.getUuid();
}
}
Assert.assertNotNull("expected new address was not found in the preferred patient after the merge", addedAddressUuid);
Assert.assertTrue("person address creation not audited", isValueInList(addedAddressUuid, audit.getPersonMergeLogData().getCreatedAddresses()));
}
use of org.openmrs.PersonAddress in project openmrs-core by openmrs.
the class PatientServiceTest method shouldCreatePatient.
@Test
public void shouldCreatePatient() throws Exception {
executeDataSet(CREATE_PATIENT_XML);
Patient patient = new Patient();
PersonName pName = new PersonName();
pName.setGivenName("Tom");
pName.setMiddleName("E.");
pName.setFamilyName("Patient");
patient.addName(pName);
PersonAddress pAddress = new PersonAddress();
pAddress.setAddress1("123 My street");
pAddress.setAddress2("Apt 402");
pAddress.setCityVillage("Anywhere city");
pAddress.setCountry("Some Country");
Set<PersonAddress> pAddressList = patient.getAddresses();
pAddressList.add(pAddress);
patient.setAddresses(pAddressList);
patient.addAddress(pAddress);
// patient.removeAddress(pAddress);
patient.setBirthdateEstimated(true);
patient.setBirthdate(new Date());
patient.setBirthdateEstimated(true);
patient.setDeathDate(new Date());
patient.setCauseOfDeath(new Concept());
patient.setGender("male");
List<PatientIdentifierType> patientIdTypes = patientService.getAllPatientIdentifierTypes();
assertNotNull(patientIdTypes);
PatientIdentifier patientIdentifier = new PatientIdentifier();
patientIdentifier.setIdentifier("123-0");
patientIdentifier.setIdentifierType(patientIdTypes.get(0));
patientIdentifier.setLocation(new Location(1));
patientIdentifier.setPreferred(true);
Set<PatientIdentifier> patientIdentifiers = new LinkedHashSet<>();
patientIdentifiers.add(patientIdentifier);
patient.setIdentifiers(patientIdentifiers);
patientService.savePatient(patient);
Patient createdPatient = patientService.getPatient(patient.getPatientId());
assertNotNull(createdPatient);
assertNotNull(createdPatient.getPatientId());
Patient createdPatientById = patientService.getPatient(createdPatient.getPatientId());
assertNotNull(createdPatientById);
}
use of org.openmrs.PersonAddress in project openmrs-core by openmrs.
the class PatientServiceTest method savePatient_shouldUpdateTheDateChangedAndChangedByOnUpdateOfThePersonAddress.
@Test
public void savePatient_shouldUpdateTheDateChangedAndChangedByOnUpdateOfThePersonAddress() throws Exception {
Patient patient = patientService.getPatient(2);
PersonAddress address = patient.getAddresses().iterator().next();
address.setAddress1("Modified Address");
patientService.savePatient(patient);
Context.evictFromSession(patient);
patient = patientService.getPatient(2);
PersonAddress personAddress = patient.getAddresses().iterator().next();
assertNotNull(personAddress.getDateChanged());
assertNotNull(personAddress.getChangedBy());
}
use of org.openmrs.PersonAddress in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldOnlyMarkAddressesOfPreferredPatientAsPreferred.
/**
* @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());
}
}
}
use of org.openmrs.PersonAddress in project openmrs-module-mirebalais by PIH.
the class WristbandTemplate method generateWristband.
public String generateWristband(Patient patient, Location location) {
// TODO figure out why this isn't getting autowired properly (at least for tests)
if (addressHierarchyService == null) {
addressHierarchyService = Context.getService(AddressHierarchyService.class);
}
StringBuffer data = new StringBuffer();
data.append("^XA");
// specify Unicode encoding
data.append("^CI28");
// set direct transfer type
data.append("^MTD");
// set orientation
data.append("^FWB");
// visit location & current data
data.append("^FO050,200^FB2150,1,0,L,0^AS^FD" + adtService.getLocationThatSupportsVisits(location).getName() + " " + fullDate.format(new Date()) + "^FS");
// patient name: for now, only printing given and family names
String patientName = null;
if (patient.getPersonName() != null) {
patientName = (patient.getPersonName().getGivenName() != null ? patient.getPersonName().getGivenName() : "") + " " + (patient.getPersonName().getFamilyName() != null ? patient.getPersonName().getFamilyName() : "");
}
data.append("^FO100,200^FB2150,1,0,L,0^AU^FD" + patientName + "^FS");
if (patient.getBirthdate() != null) {
// birthdate (we only show year if birthdate is estimated
DateFormat df = patient.getBirthdateEstimated() ? yearOnly : fullDate;
data.append("^FO160,200^FB2150,1,0,L,0^AU^FD" + df.format(patient.getBirthdate()) + "^FS");
}
if (patient.getAge() != null) {
// age
data.append("^FO160,200^FB1850,1,0,L,0^AT^FD" + messageSourceService.getMessage("coreapps.ageYears", Collections.singletonList(patient.getAge()).toArray(), locale) + "^FS");
}
// gender
data.append("^FO160,200^FB1650,1,0,L,0^AU^FD" + messageSourceService.getMessage("coreapps.gender." + patient.getGender(), null, locale) + " ");
// paper record identifier
PatientIdentifier paperRecordIdentifier = getAppropriatePaperRecordIdentifierForLocation(patient, location);
if (paperRecordIdentifier != null) {
data.append(paperRecordIdentifier.getIdentifier().substring(0, paperRecordIdentifier.getIdentifier().length() - 6) + " " + paperRecordIdentifier.getIdentifier().substring(paperRecordIdentifier.getIdentifier().length() - 6));
}
data.append("^FS");
// address (based on address hierarchy)
PersonAddress address = patient.getPersonAddress();
AddressHierarchyLevel level = addressHierarchyService.getBottomAddressHierarchyLevel();
int numberOfLevels = addressHierarchyService.getAddressHierarchyLevelsCount();
if (address != null && numberOfLevels > 0) {
int levelCount = 1;
if (LOWEST_LEVEL_ON_SEPARATE_LINE) {
String lowestLevelStr = AddressHierarchyUtil.getAddressFieldValue(address, level.getAddressField());
if (StringUtils.isNotBlank(address.getAddress2())) {
data.append("^FO220,200^FB2150,1,0,L,0^AS^FD" + lowestLevelStr + "^FS");
}
levelCount++;
}
StringBuffer addressStr = new StringBuffer();
while (levelCount < numberOfLevels || (!SKIP_HIGHEST_LEVEL && levelCount <= numberOfLevels) && level.getParent() != null) {
// level.getParent() should never equal null as long as levelCount <= numberOfLevels, but just to be safe we will check
level = level.getParent();
String levelStr = AddressHierarchyUtil.getAddressFieldValue(address, level.getAddressField());
if (StringUtils.isNotBlank(levelStr)) {
addressStr.append(levelStr + ", ");
}
levelCount++;
}
if (StringUtils.isNotBlank(addressStr.toString())) {
// trim off trailing comma and space
addressStr.delete(addressStr.length() - 2, addressStr.length());
data.append("^FO270,200^FB2150,1,0,L,0^AS^FD" + addressStr.toString() + "^FS");
}
}
// barcode with primary identifier
PatientIdentifier primaryIdentifier = patient.getPatientIdentifier(emrApiProperties.getPrimaryIdentifierType());
if (primaryIdentifier != null) {
data.append("^FO100,2400^AT^BY4^BC,150,N^FD" + primaryIdentifier.getIdentifier() + "^XZ");
}
return data.toString();
}
Aggregations