PersonAttributeType healthCenterAttrType = Context.getPersonService().getPersonAttributeTypeByName( "Health Center");
@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)); }
/** * @see org.springframework.validation.Validator#validate(java.lang.Object, * org.springframework.validation.Errors) * @should fail validation if name is null * @should fail validation if format is empty * @should fail validation if name already in use * @should pass validation if description is null or empty or whitespace * @should pass validation if all fields are correct * @should pass validation if field lengths are correct * @should fail validation if field lengths are not correct */ @Override public void validate(Object obj, Errors errors) { PersonAttributeType patObj = (PersonAttributeType) obj; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "PersonAttributeType.error.nameEmpty"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "format", "PersonAttributeType.error.formatEmpty"); PersonService ps = Context.getPersonService(); PersonAttributeType pat = ps.getPersonAttributeTypeByName(patObj.getName()); if (pat != null && !pat.getUuid().equals(patObj.getUuid())) { errors.rejectValue("name", "PersonAttributeType.error.nameAlreadyInUse"); } ValidateUtil.validateFieldLengths(errors, obj.getClass(), "name", "format", "retireReason"); } }
/** * @see PersonService#getPersonAttributeTypeByName(String) */ @Test public void getPersonAttributeTypeByName_shouldReturnPersonAttributeTypeWhenNameMatchesGivenTypeName() throws Exception { PersonAttributeType attributeType = Context.getPersonService().getPersonAttributeTypeByName("Birthplace"); Assert.assertNotNull(attributeType); }
/** * @see PersonService#getPersonAttributeTypeByName(String) */ @Test public void getPersonAttributeTypeByName_shouldReturnNullWhenNoPersonAttributeTypeMatchGivenTypeName() throws Exception { PersonAttributeType attributeType = Context.getPersonService().getPersonAttributeTypeByName("Credit Card"); Assert.assertNull(attributeType); }
PersonAttributeType attributeType = personService.getPersonAttributeTypeByName("Birthplace"); attributeType.setSearchable(true); Context.getPersonService().savePersonAttributeType(attributeType);
personToUpdate.removeAttribute(personAttribute); personToUpdate.addAttribute(new PersonAttribute(personService.getPersonAttributeTypeByName(attribute.getName()), attribute.getValue()));
@Test public void setValue_shouldSetThePassedValueForNonAttributableClasses() throws ClassNotFoundException { PersonAttributeType type = personService.getPersonAttributeTypeByName("Race"); PersonAttribute attribute = new PersonAttribute(type, null); Assert.assertNull(attribute.getValue()); Assert.assertEquals("java.lang.String", type.getFormat()); Assert.assertFalse(Attributable.class.isAssignableFrom(Context.loadClass(type.getFormat()))); resource.setValue(attribute, "arab"); Assert.assertEquals("arab", attribute.getValue()); } }
openMrsPatient.removeAttribute(personAttribute); openMrsPatient.addAttribute(new PersonAttribute(personService.getPersonAttributeTypeByName(attribute.getName()), attribute.getValue()));
User mrsUserToOpenMRSUser(MRSUser mrsUser) { User user = getOrCreateUser(mrsUser.getUserId()); Person person = user.getPerson(); clearAttributes(user); MRSPerson mrsPerson = mrsUser.getPerson(); PersonName personName = new PersonName(mrsPerson.getFirstName(), mrsPerson.getMiddleName(), mrsPerson.getLastName()); person.addName(personName); person.setGender(PERSON_UNKNOWN_GENDER); for (MRSAttribute attribute : mrsPerson.getAttributes()) { PersonAttributeType attributeType = personService.getPersonAttributeTypeByName(attribute.getName()); person.addAttribute(new PersonAttribute(attributeType, attribute.getValue())); } Role role = userService.getRole(mrsUser.getSecurityRole()); user.addRole(role); addProviderRole(user, role); user.setSystemId(mrsUser.getSystemId()); user.setUsername(mrsUser.getUserName()); return user; }