use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientDAOTest method getPatients_shouldGetCloseIdentifiersWithCorrectStartPhrase.
@Test
public void getPatients_shouldGetCloseIdentifiersWithCorrectStartPhrase() {
String oldPropertyValue = globalPropertiesTestHelper.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE, OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_SEARCH_MATCH_START);
Patient patient = patientService.getPatient(2);
PatientIdentifier patientIdentifier = new PatientIdentifier("BAH409", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
patient.addIdentifier(patientIdentifier);
patientService.savePatient(patient);
// add closely matching identifier to a different patient
Patient patient2 = patientService.getPatient(6);
PatientIdentifier patientIdentifier6 = new PatientIdentifier("BAH509", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
patientIdentifier6.setPreferred(true);
patient2.addIdentifier(patientIdentifier6);
patientService.savePatient(patient2);
updateSearchIndex();
// Check for partial identifier match
List<Patient> patients = dao.getPatients("BAH", false, 0, null);
Assert.assertEquals(2, patients.size());
if (oldPropertyValue != null) {
globalPropertiesTestHelper.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE, oldPropertyValue);
} else {
globalPropertiesTestHelper.purgeGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE);
}
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientIdentifierValidatorTest method validateIdentifier_shouldPassIfInUseAndIdTypeUniquenessIsSetToNonUnique.
/**
* @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier)
*/
@Test
public void validateIdentifier_shouldPassIfInUseAndIdTypeUniquenessIsSetToNonUnique() {
PatientService patientService = Context.getPatientService();
PatientIdentifier duplicateId = patientService.getPatientIdentifier(1);
Assert.assertNotNull(duplicateId.getLocation());
PatientIdentifierType idType = duplicateId.getIdentifierType();
idType.setUniquenessBehavior(UniquenessBehavior.NON_UNIQUE);
patientService.savePatientIdentifierType(idType);
PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, duplicateId.getLocation());
PatientIdentifierValidator.validateIdentifier(pi);
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientIdentifierValidatorTest method validateIdentifier_shouldFailValidationIfAnotherPatientHasAMatchingIdentifierOfTheSameType.
/**
* @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier)
*/
@Test(expected = IdentifierNotUniqueException.class)
public void validateIdentifier_shouldFailValidationIfAnotherPatientHasAMatchingIdentifierOfTheSameType() {
PatientIdentifier pi = Context.getPatientService().getPatientIdentifiers("7TU-8", null, null, null, null).get(0);
pi.setIdentifier("101-6");
PatientIdentifierValidator.validateIdentifier(pi);
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientIdentifierValidatorTest method validateIdentifier_shouldFailValidationIfIdentifierIsBlank.
/**
* @see PatientIdentifierValidator#validateIdentifier(String,PatientIdentifierType)
*/
@Test(expected = BlankIdentifierException.class)
public void validateIdentifier_shouldFailValidationIfIdentifierIsBlank() {
PatientIdentifier identifier = new PatientIdentifier("", new PatientIdentifierType(1), new Location(1));
PatientIdentifierValidator.validateIdentifier(identifier);
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientIdentifierValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.
/**
* @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier)
*/
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
PatientIdentifier pi = new PatientIdentifier("1TU-8", new PatientIdentifierType(1), null);
PatientIdentifierType idType = pi.getIdentifierType();
idType.setLocationBehavior(PatientIdentifierType.LocationBehavior.NOT_USED);
pi.setVoidReason("voidReason");
Errors errors = new BindException(pi, "pi");
new PatientIdentifierValidator().validate(pi, errors);
Assert.assertFalse(errors.hasErrors());
}
Aggregations