@Test public void getPatients_shouldFindOnlySearchablePersonAttributes() { PersonAttributeType attributeType = personService.getPersonAttributeTypeByName("Birthplace"); attributeType.setSearchable(false); personService.savePersonAttributeType(attributeType); List<Patient> patients = patientService.getPatients("London"); assertThat(patients, is(empty())); attributeType = personService.getPersonAttributeTypeByName("Birthplace"); attributeType.setSearchable(true); personService.savePersonAttributeType(attributeType); patients = patientService.getPatients("London"); Patient patient = patientService.getPatient(2); assertThat(patients, contains(patient)); }
attributeType.setSearchable(true); Context.getPersonService().savePersonAttributeType(attributeType);
@Test public void setValue_shouldSetPassedValueIfCouldNotBeConvertedToAttributable() throws ClassNotFoundException { PersonAttributeType type = new PersonAttributeType(); type.setFormat("org.openmrs.Location"); type.setName("Second Home"); type.setDescription("Testing Attributable domain objects"); type.setSortWeight(5.5); type.setSearchable(false); type = personService.savePersonAttributeType(type); String nonExistenceLocationUuid = "this-uuid-does-not-exist-of-course"; PersonAttribute attribute = new PersonAttribute(type, null); Assert.assertNull(attribute.getValue()); Assert.assertTrue(Attributable.class.isAssignableFrom(Context.loadClass(type.getFormat()))); resource.setValue(attribute, nonExistenceLocationUuid); Assert.assertEquals(nonExistenceLocationUuid, attribute.getValue()); }
@Test public void setValue_shouldSetProperAttributableIdIfFound() { PersonAttributeType type = new PersonAttributeType(); type.setFormat("org.openmrs.Location"); type.setName("Second Home"); type.setDescription("Testing Attributable domain objects"); type.setSortWeight(5.5); type.setSearchable(false); type = personService.savePersonAttributeType(type); //Get the first location in from the list Location location = locationService.getAllLocations().get(0); PersonAttribute attribute = new PersonAttribute(type, null); attribute.setAttributeType(type); Assert.assertNull(attribute.getValue()); resource.setValue(attribute, location.getUuid()); Assert.assertEquals(location.getUuid(), attribute.getValue()); }