/** * Convenience method to get the given name attribute on this person's preferred PersonName * * @return String given name of the person */ public String getGivenName() { PersonName personName = getPersonName(); if (personName == null) { return ""; } else { return personName.getGivenName(); } }
/** * Compares this PersonName object to the given otherName. This method differs from * {@link #equals(Object)} in that this method compares the inner fields of each name for * equality. Note: Null/empty fields on <code>otherName</code> /will not/ cause a false value to * be returned * * @param otherName PersonName with which to compare * @return boolean true/false whether or not they are the same names * @should return true if given middle and family name are equal */ public boolean equalsContent(PersonName otherName) { return new EqualsBuilder().append(defaultString(otherName.getPrefix()), defaultString(prefix)).append( defaultString(otherName.getGivenName()), defaultString(givenName)).append( defaultString(otherName.getMiddleName()), defaultString(middleName)).append( defaultString(otherName.getFamilyNamePrefix()), defaultString(familyNamePrefix)).append( defaultString(otherName.getDegree()), defaultString(degree)).append(defaultString(otherName.getFamilyName()), defaultString(familyName)).append(defaultString(otherName.getFamilyName2()), defaultString(familyName2)).append( defaultString(otherName.getFamilyNameSuffix()), defaultString(familyNameSuffix)).isEquals(); }
/** * @see org.openmrs.api.handler.SaveHandler#handle(org.openmrs.OpenmrsObject, org.openmrs.User, * java.util.Date, java.lang.String) */ @Override public void handle(PersonName personName, User creator, Date dateCreated, String other) { if (personName.getGivenName() != null) { personName.setGivenName(personName.getGivenName().trim()); } if (personName.getMiddleName() != null) { personName.setMiddleName(personName.getMiddleName().trim()); } if (personName.getFamilyName() != null) { personName.setFamilyName(personName.getFamilyName().trim()); } if (personName.getFamilyName2() != null) { personName.setFamilyName2(personName.getFamilyName2().trim()); } }
temp.add(getPrefix()); if (StringUtils.hasText(getGivenName())) { temp.add(getGivenName());
if (StringUtils.isBlank(personName.getGivenName()) || StringUtils.isBlank(personName.getGivenName().replaceAll("\"", ""))) { errors.rejectValue(getFieldKey("givenName", arrayInd, testInd), "Patient.names.required.given.family"); OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_NAME_REGEX); if (StringUtils.isNotBlank(namePattern)) { if (StringUtils.isNotBlank(personName.getGivenName()) && !personName.getGivenName().matches(namePattern)) { errors.rejectValue(getFieldKey("givenName", arrayInd, testInd), "GivenName.invalid");
ret = OpenmrsUtil.compareWithNullAsGreatest(name1.getGivenName() != null ? name1.getGivenName().toLowerCase() : null, name2.getGivenName() != null ? name2.getGivenName().toLowerCase() : null);
/** * @see PersonName#getGivenName() */ @Test public void getGivenName_shouldReturnObscuredNameIfObscure_patientsIsSetToTrue() { OpenmrsConstants.OBSCURE_PATIENTS = true; OpenmrsConstants.OBSCURE_PATIENTS_GIVEN_NAME = "given name"; Assert.assertEquals("given name", new PersonName().getGivenName()); OpenmrsConstants.OBSCURE_PATIENTS = false; // cleanup }
private void mergeNames(Patient preferred, Patient notPreferred, PersonMergeLogData mergedData) { // move all names // (must be done after all calls to services above so hbm doesn't try to save things prematurely (hacky) for (PersonName newName : notPreferred.getNames()) { boolean containsName = false; for (PersonName currentName : preferred.getNames()) { containsName = currentName.equalsContent(newName); if (containsName) { break; } } if (!containsName) { PersonName tmpName = constructTemporaryName(newName); preferred.addName(tmpName); mergedData.addCreatedName(tmpName.getUuid()); log.debug("Merging name " + newName.getGivenName() + " to " + preferred.getPatientId()); } } }
/** * @see PersonService#parsePersonName(String) */ @Test public void parsePersonName_shouldNotFailWhenEndingWithWhitespace() throws Exception { PersonName pname = Context.getPersonService().parsePersonName("John "); assertEquals("John", pname.getGivenName()); }
/** * @see PersonService#parsePersonName(String) */ @Test public void parsePersonName_shouldNotFailWhenEndingWithAComma() throws Exception { PersonName pname = Context.getPersonService().parsePersonName("John,"); assertEquals("John", pname.getGivenName()); }
/** * @see PatientService#mergePatients(Patient,Patient) */ @Test public void mergePatients_shouldCopyNonvoidedNamesToPreferredPatient() throws Exception { Patient preferred = patientService.getPatient(7); Patient notPreferred = patientService.getPatient(8); patientService.mergePatients(preferred, notPreferred); // make sure one of their addresses has the first name of "Anet" boolean found = false; for (PersonName pn : preferred.getNames()) { if (pn.getGivenName().equals("Anet")) { found = true; } } Assert.assertTrue("odd, user 7 didn't get user 8's names", found); }
if (pn.getGivenName() != null) { newName.setGivenName(String.valueOf(pn.getGivenName()));
/** * @see PersonService#parsePersonName(String) */ @Test public void parsePersonName_shouldParseTwoPersonNameWithoutComma() throws Exception { PersonName pname2 = Context.getPersonService().parsePersonName("John Doe"); assertEquals("Doe", pname2.getFamilyName()); assertEquals("John", pname2.getGivenName()); }
/** * This test should get the first/last name out of a string into a PersonName object. * * @see PersonService#parsePersonName(String) */ @Test public void parsePersonName_shouldParseTwoPersonNameWithComma() throws Exception { PersonName pname = Context.getPersonService().parsePersonName("Doe, John"); assertEquals("Doe", pname.getFamilyName()); assertEquals("John", pname.getGivenName()); // try without a space pname = Context.getPersonService().parsePersonName("Doe,John"); assertEquals("Doe", pname.getFamilyName()); assertEquals("John", pname.getGivenName()); }
ret = OpenmrsUtil.compareWithNullAsGreatest(pn1.getGivenName(), pn2.getGivenName());
/** * @see PatientService#getCountOfPatients(String) */ @Test public void getCountOfPatients_shouldReturnTheRightCountWhenAPatientHasMultipleMatchingPersonNames() throws Exception { // TODO H2 cannot execute the generated SQL because it requires all // fetched columns to be included in the group by clause Patient patient = patientService.getPatient(2); // sanity check Assert.assertTrue(patient.getPersonName().getGivenName().startsWith("Horati")); // add a name that will match the search phrase patient.addName(new PersonName("Horatio", "Test", "name")); Context.getPatientService().savePatient(patient); Assert.assertEquals(1, Context.getPatientService().getCountOfPatients("Hor").intValue()); }
/** * @see PersonService#parsePersonName(String) */ @Test public void parsePersonName_shouldParseFourPersonName() throws Exception { PersonName pname = Context.getPersonService().parsePersonName("John David Alex Smith"); assertEquals("John", pname.getGivenName()); assertEquals("David", pname.getMiddleName()); assertEquals("Alex", pname.getFamilyName()); assertEquals("Smith", pname.getFamilyName2()); }
pa3.setGivenName(pa1.getGivenName()); pa3.setFamilyName(pa1.getFamilyName()); pa3.setDateCreated(pa1.getDateCreated()); pa4.setGivenName(pa1.getGivenName() + "string to change the .equals method"); pa4.setFamilyName(pa1.getFamilyName()); pa4.setDateCreated(pa1.getDateCreated());
private void updateName(PersonName fromName, PersonName toName) { toName.setGivenName(fromName.getGivenName()); toName.setMiddleName(fromName.getMiddleName()); toName.setFamilyName(fromName.getFamilyName()); }
Assert.assertEquals(prefix, copy.getPrefix()); Assert.assertEquals(person, copy.getPerson()); Assert.assertEquals(givenName, copy.getGivenName()); Assert.assertEquals(middleName, copy.getMiddleName()); Assert.assertEquals(familyNamePrefix, copy.getFamilyNamePrefix());