use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method getCountOfPatients_shouldReturnTheRightCountOfPatientsWithAMatchingIdentifierWithNoDigits.
/**
* @see PatientService#getCountOfPatients(String)
*/
@Test
public void getCountOfPatients_shouldReturnTheRightCountOfPatientsWithAMatchingIdentifierWithNoDigits() throws Exception {
final String identifier = "XYZ";
Patient patient = patientService.getPatient(2);
Assert.assertEquals(0, patientService.getCountOfPatients(identifier).intValue());
PatientIdentifier pId = new PatientIdentifier(identifier, patientService.getPatientIdentifierType(5), locationService.getLocation(1));
patient.addIdentifier(pId);
patientService.savePatient(patient);
updateSearchIndex();
Assert.assertEquals(1, patientService.getCountOfPatients(identifier).intValue());
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method getPatients_shouldSupportSimpleRegex.
/**
* @see PatientService#getPatients(String, String, java.util.List, boolean)
*/
@Test
public void getPatients_shouldSupportSimpleRegex() throws Exception {
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_REGEX, "^0*@SEARCH@([A-Z]+-[0-9])?$"));
PatientIdentifier identifier = new PatientIdentifier("1234-4", new PatientIdentifierType(1), new Location(1));
identifier.setCreator(new User(1));
identifier.setDateCreated(new Date());
Patient patient = Context.getPatientService().getPatient(2);
patient.addIdentifier(identifier);
Context.getPatientService().savePatient(patient);
updateSearchIndex();
assertEquals(1, Context.getPatientService().getPatients("1234-4").size());
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseAndIdTypeUniquenessIsNull.
/**
* @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
*/
@Test
public void isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseAndIdTypeUniquenessIsNull() throws Exception {
PatientIdentifier duplicateId = patientService.getPatientIdentifier(1);
Assert.assertNotNull(duplicateId.getLocation());
PatientIdentifierType idType = duplicateId.getIdentifierType();
Assert.assertNull(idType.getUniquenessBehavior());
PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, duplicateId.getLocation());
Assert.assertTrue(patientService.isIdentifierInUseByAnotherPatient(pi));
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method voidPatientIdentifier_shouldThrowAnAPIExceptionIfTheReasonIsAnEmptyString.
@Test(expected = APIException.class)
public void voidPatientIdentifier_shouldThrowAnAPIExceptionIfTheReasonIsAnEmptyString() throws Exception {
PatientIdentifier patientIdentifierToVoid = patientService.getPatientIdentifier(3);
patientService.voidPatientIdentifier(patientIdentifierToVoid, "");
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatientIdentifier_shouldCreateNewPatientIndentifier.
@Test
public void savePatientIdentifier_shouldCreateNewPatientIndentifier() throws Exception {
PatientIdentifier patientIdentifier = new PatientIdentifier("677-56-6666", new PatientIdentifierType(4), new Location(1));
Patient associatedPatient = patientService.getPatient(2);
patientIdentifier.setPatient(associatedPatient);
PatientIdentifier createdPatientIdentifier = patientService.savePatientIdentifier(patientIdentifier);
Assert.assertNotNull(createdPatientIdentifier);
Assert.assertNotNull(createdPatientIdentifier.getPatientIdentifierId());
}
Aggregations