use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method voidPatientIdentifier_shouldThrowAnAPIExceptionIfTheReasonIsAWhiteSpaceCharacter.
@Test(expected = APIException.class)
public void voidPatientIdentifier_shouldThrowAnAPIExceptionIfTheReasonIsAWhiteSpaceCharacter() 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 getPatientIdentifierByUuid_shouldFindObjectGivenValidUuid.
/**
* @see PatientService#getPatientIdentifierByUuid(String)
*/
@Test
public void getPatientIdentifierByUuid_shouldFindObjectGivenValidUuid() throws Exception {
String uuid = "ff41928c-3bca-48d9-a4dc-9198f6b2873b";
PatientIdentifier patientIdentifier = Context.getPatientService().getPatientIdentifierByUuid(uuid);
Assert.assertEquals(1, (int) patientIdentifier.getPatientIdentifierId());
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatient_shouldNotSetThePreferredNameAddressAndIdentifierIfTheyAlreadyExist.
/**
* @see PatientService#savePatient(Patient)
*/
@Test
public void savePatient_shouldNotSetThePreferredNameAddressAndIdentifierIfTheyAlreadyExist() throws Exception {
Patient patient = new Patient();
patient.setGender("M");
PatientIdentifier identifier = new PatientIdentifier("QWERTY", patientService.getPatientIdentifierType(5), locationService.getLocation(1));
PatientIdentifier preferredIdentifier = new PatientIdentifier("QWERTY2", patientService.getPatientIdentifierType(2), locationService.getLocation(1));
preferredIdentifier.setPreferred(true);
patient.addIdentifier(identifier);
patient.addIdentifier(preferredIdentifier);
PersonName name = new PersonName("givenName", "middleName", "familyName");
PersonName preferredName = new PersonName("givenName", "middleName", "familyName");
preferredName.setPreferred(true);
patient.addName(name);
patient.addName(preferredName);
PersonAddress address = new PersonAddress();
address.setAddress1("some address");
PersonAddress preferredAddress = new PersonAddress();
preferredAddress.setAddress1("another address");
preferredAddress.setPreferred(true);
patient.addAddress(address);
patient.addAddress(preferredAddress);
patientService.savePatient(patient);
Assert.assertTrue(preferredIdentifier.getPreferred());
Assert.assertTrue(preferredName.getPreferred());
Assert.assertTrue(preferredAddress.getPreferred());
Assert.assertFalse(identifier.getPreferred());
Assert.assertFalse(name.getPreferred());
Assert.assertFalse(address.getPreferred());
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method checkPatientIdentifiers_shouldRemoveIdentifierAndThrowErrorWhenPatientHasBlankPatientIdentifier.
/**
* @see PatientService#checkPatientIdentifiers(Patient)
*/
@Test(expected = BlankIdentifierException.class)
public void checkPatientIdentifiers_shouldRemoveIdentifierAndThrowErrorWhenPatientHasBlankPatientIdentifier() throws Exception {
Patient patient = new Patient();
PatientIdentifier patientIdentifier = new PatientIdentifier();
patientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0));
patient.addIdentifier(patientIdentifier);
// Should throw blank identifier exception
Context.getPatientService().checkPatientIdentifiers(patient);
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldReturnFalseIfInUseForAnotherLocationAndIdUniquenessIsSetToLocation.
/**
* @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
*/
@Test
public void isIdentifierInUseByAnotherPatient_shouldReturnFalseIfInUseForAnotherLocationAndIdUniquenessIsSetToLocation() throws Exception {
PatientIdentifier duplicateId = patientService.getPatientIdentifier(1);
Assert.assertNotNull(duplicateId.getLocation());
PatientIdentifierType idType = duplicateId.getIdentifierType();
idType.setUniquenessBehavior(UniquenessBehavior.LOCATION);
patientService.savePatientIdentifierType(idType);
Location idLocation = locationService.getLocation(2);
// sanity check
Assert.assertNotSame(idLocation, duplicateId.getLocation());
PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, idLocation);
Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(pi));
}
Aggregations