use of org.openmrs.LocationAttribute in project openmrs-module-mirebalais by PIH.
the class ZlEmrIdCardPrinter method getIssuingLocationName.
/**
* @return the issuing location in the format that it should be displayed on the id cards
*/
protected String getIssuingLocationName(Location location) {
LocationAttributeType attributeType = MetadataUtils.existing(LocationAttributeType.class, LocationAttributeTypes.NAME_TO_PRINT_ON_ID_CARD.uuid());
List<LocationAttribute> nameToPrintOnIdCard = location.getActiveAttributes(attributeType);
// there should never be more for than one specified name to print on the id card--max allowed for this attribute = 1
if (nameToPrintOnIdCard != null && nameToPrintOnIdCard.size() > 0) {
return (String) nameToPrintOnIdCard.get(0).getValue();
} else {
return location.getDisplayString();
}
}
use of org.openmrs.LocationAttribute in project openmrs-core by openmrs.
the class LocationServiceTest method getLocations_shouldGetLocationsHavingAllMatchingAttributeValues.
/**
* @see LocationService#getLocations(String, org.openmrs.Location, java.util.Map, boolean, Integer, Integer)
*/
@Test
public void getLocations_shouldGetLocationsHavingAllMatchingAttributeValues() {
// Save new phone number attribute type
LocationAttributeType phoneAttrType = new LocationAttributeType();
phoneAttrType.setName("Facility Phone");
phoneAttrType.setMinOccurs(0);
phoneAttrType.setMaxOccurs(1);
phoneAttrType.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype");
Context.getLocationService().saveLocationAttributeType(phoneAttrType);
// Save new email address attribute type
LocationAttributeType emailAttrType = new LocationAttributeType();
emailAttrType.setName("Facility Email");
emailAttrType.setMinOccurs(0);
emailAttrType.setMaxOccurs(1);
emailAttrType.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype");
Context.getLocationService().saveLocationAttributeType(emailAttrType);
// Assign phone number 0123456789 and email address admin@facility.com to location #1
Location location1 = Context.getLocationService().getLocation(1);
LocationAttribute la1a = new LocationAttribute();
la1a.setAttributeType(phoneAttrType);
la1a.setValue("0123456789");
location1.addAttribute(la1a);
LocationAttribute la1b = new LocationAttribute();
la1b.setAttributeType(emailAttrType);
la1b.setValue("admin@facility.com");
location1.addAttribute(la1b);
Context.getLocationService().saveLocation(location1);
// Assign same phone number 0123456789 to location #2
Location location2 = Context.getLocationService().getLocation(2);
LocationAttribute la2 = new LocationAttribute();
la2.setAttributeType(phoneAttrType);
la2.setValue("0123456789");
location2.addAttribute(la2);
Context.getLocationService().saveLocation(location2);
// Search for location #1 by phone number AND email address
Map<LocationAttributeType, Object> attrValues = new HashMap<>();
attrValues.put(phoneAttrType, "0123456789");
attrValues.put(emailAttrType, "admin@facility.com");
// Check that only location #1 is returned
List<Location> locations = Context.getLocationService().getLocations(null, null, attrValues, false, null, null);
Assert.assertEquals(1, locations.size());
Assert.assertEquals(location1, locations.get(0));
}
Aggregations