@Override public void unretirePersonAttributeType(PersonAttributeType type) throws APIException { checkIfPersonAttributeTypesAreLocked(); type.setRetired(false); type.setDateRetired(null); type.setRetiredBy(null); type.setRetireReason(null); Context.getPersonService().savePersonAttributeType(type); }
@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)); }
Context.getPersonService().savePersonAttributeType(attributeType);
/** * @see PersonService#savePersonAttributeType(PersonAttributeType) * @throws PersonAttributeTypeLockedException */ @Test(expected = PersonAttributeTypeLockedException.class) public void savePersonAttributeType_shouldThrowAnErrorWhenTryingToSavePersonAttributeTypeWhilePersonAttributeTypesAreLocked() throws Exception { PersonService ps = Context.getPersonService(); createPersonAttributeTypeLockedGPAndSetValue("true"); PersonAttributeType pat = ps.getPersonAttributeType(1); pat.setDescription("New person attribute type"); ps.savePersonAttributeType(pat); }
/** * @see PersonService#savePersonAttributeType(PersonAttributeType) */ @Test public void savePersonAttributeType_shouldSetTheDateChangedAndChangedByOnUpdate() throws Exception { PersonService service = Context.getPersonService(); // get the type and change something about it PersonAttributeType pat = service.getPersonAttributeType(2); pat.setName("attr type name"); // save the type again service.savePersonAttributeType(pat); assertEquals(1, pat.getChangedBy().getId().intValue()); assertNotNull(pat.getDateChanged()); }
/** * @see PersonService#savePersonAttributeType(PersonAttributeType) */ @Test public void savePersonAttributeType_shouldSetTheDateCreatedAndCreatorOnNew() throws Exception { PersonService service = Context.getPersonService(); PersonAttributeType pat = new PersonAttributeType(); pat.setName("attr type name"); pat.setDescription("attr type desc"); pat.setFormat("java.lang.String"); service.savePersonAttributeType(pat); assertEquals(1, pat.getCreator().getId().intValue()); assertNotNull(pat.getDateCreated()); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object) */ @Override public PersonAttributeType save(PersonAttributeType delegate) { return service().savePersonAttributeType(delegate); }
/** * @see PersonService#purgePersonAttributeType(PersonAttributeType) */ @Test public void purgePersonAttributeType_shouldDeletePersonAttributeTypeFromDatabase() throws Exception { PersonService service = Context.getPersonService(); PersonAttributeType pat = new PersonAttributeType(); pat.setName("attr type name"); pat.setDescription("attr type desc"); pat.setFormat("java.lang.String"); service.savePersonAttributeType(pat); assertNotNull(pat.getId()); service.purgePersonAttributeType(pat); PersonAttributeType deletedPersonAttributeType = service.getPersonAttributeType(pat.getId()); Assert.assertNull(deletedPersonAttributeType); }
pat = service.savePersonAttributeType(pat); assertEquals("Race Updated", pat.getName());
@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()); }