Search in sources :

Example 11 with LocationAttributeType

use of org.openmrs.LocationAttributeType in project openmrs-module-mirebalais by PIH.

the class MirebalaisHospitalActivatorComponentTest method verifyLocationAttributeNotOverwritten.

private void verifyLocationAttributeNotOverwritten() throws Exception {
    // make sure that when importing the location metadata package, the location
    // attribute we defined in the requiredDataTestDataset has not been overwritten
    Location location = Context.getLocationService().getLocation(1001);
    LocationAttributeType type = Context.getLocationService().getLocationAttributeType(1001);
    assertEquals(1, location.getActiveAttributes(type).size());
    assertEquals("Mark", location.getActiveAttributes(type).get(0).getValue().toString());
}
Also used : LocationAttributeType(org.openmrs.LocationAttributeType) Location(org.openmrs.Location)

Example 12 with LocationAttributeType

use of org.openmrs.LocationAttributeType 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();
    }
}
Also used : LocationAttribute(org.openmrs.LocationAttribute) LocationAttributeType(org.openmrs.LocationAttributeType)

Example 13 with LocationAttributeType

use of org.openmrs.LocationAttributeType in project openmrs-core by openmrs.

the class LocationServiceTest method getLocations_shouldNotFindAnyLocationsIfNoneHaveGivenAttributeValues.

/**
 * @see LocationService#getLocations(String, org.openmrs.Location, java.util.Map, boolean, Integer, Integer)
 */
@Test
public void getLocations_shouldNotFindAnyLocationsIfNoneHaveGivenAttributeValues() {
    // 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);
    Map<LocationAttributeType, Object> attrValues = new HashMap<>();
    attrValues.put(phoneAttrType, "xxxxxx");
    Assert.assertEquals(0, Context.getLocationService().getLocations(null, null, attrValues, true, null, null).size());
}
Also used : HashMap(java.util.HashMap) LocationAttributeType(org.openmrs.LocationAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with LocationAttributeType

use of org.openmrs.LocationAttributeType 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));
}
Also used : HashMap(java.util.HashMap) LocationAttribute(org.openmrs.LocationAttribute) LocationAttributeType(org.openmrs.LocationAttributeType) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with LocationAttributeType

use of org.openmrs.LocationAttributeType in project openmrs-core by openmrs.

the class LocationServiceTest method retireLocationAttributeType_shouldRetireALocationAttributeType.

/**
 * @see LocationService#retireLocationAttributeType(LocationAttributeType,String)
 */
@Test
public void retireLocationAttributeType_shouldRetireALocationAttributeType() {
    executeDataSet(LOC_ATTRIBUTE_DATA_XML);
    LocationAttributeType vat = Context.getLocationService().getLocationAttributeType(1);
    Assert.assertFalse(vat.getRetired());
    Assert.assertNull(vat.getRetiredBy());
    Assert.assertNull(vat.getDateRetired());
    Assert.assertNull(vat.getRetireReason());
    Context.getLocationService().retireLocationAttributeType(vat, "for testing");
    vat = Context.getLocationService().getLocationAttributeType(1);
    Assert.assertTrue(vat.getRetired());
    Assert.assertNotNull(vat.getRetiredBy());
    Assert.assertNotNull(vat.getDateRetired());
    Assert.assertEquals("for testing", vat.getRetireReason());
}
Also used : LocationAttributeType(org.openmrs.LocationAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

LocationAttributeType (org.openmrs.LocationAttributeType)16 Test (org.junit.Test)13 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)13 BindException (org.springframework.validation.BindException)6 Errors (org.springframework.validation.Errors)6 HashMap (java.util.HashMap)2 Location (org.openmrs.Location)2 LocationAttribute (org.openmrs.LocationAttribute)2 LocationService (org.openmrs.api.LocationService)1 FreeTextDatatype (org.openmrs.customdatatype.datatype.FreeTextDatatype)1