use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldIgnoreVoidedPatientIdentifiers.
/**
* @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
*/
@Test
public void isIdentifierInUseByAnotherPatient_shouldIgnoreVoidedPatientIdentifiers() throws Exception {
PatientIdentifierType pit = patientService.getPatientIdentifierType(2);
PatientIdentifier patientIdentifier = new PatientIdentifier("ABC123", pit, null);
Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier));
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatient_shouldCreateNewPatientFromExistingPersonPlusUserObject.
/**
* @see PatientService#savePatient(Patient)
*/
@Test
public void savePatient_shouldCreateNewPatientFromExistingPersonPlusUserObject() throws Exception {
// sanity check, make sure there isn't a 501 patient already
Patient oldPatient = patientService.getPatient(501);
Assert.assertNull(oldPatient);
// fetch Bruno from the database
Person existingPerson = Context.getPersonService().getPerson(501);
Context.clearSession();
Patient patient = new Patient(existingPerson);
PatientIdentifier patientIdentifier = new PatientIdentifier("some identifier", new PatientIdentifierType(2), new Location(1));
patientIdentifier.setPreferred(true);
patient.addIdentifier(patientIdentifier);
patientService.savePatient(patient);
Assert.assertEquals(501, patient.getPatientId().intValue());
// make sure a new row with a patient id WAS created
Assert.assertNotNull(patientService.getPatient(501));
// make sure a new row with a new person id WASN'T created
Assert.assertNull(patientService.getPatient(503));
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method voidPatientIdentifier_shouldThrowAnAPIExceptionIfTheReasonIsNull.
@Test(expected = APIException.class)
public void voidPatientIdentifier_shouldThrowAnAPIExceptionIfTheReasonIsNull() throws Exception {
PatientIdentifier patientIdentifierToVoid = patientService.getPatientIdentifier(3);
patientService.voidPatientIdentifier(patientIdentifierToVoid, null);
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatient_shouldNotSetAVoidedNameOrAddressOrIdentifierAsPreferred.
/**
* @see PatientService#savePatient(Patient)
*/
@Test
public void savePatient_shouldNotSetAVoidedNameOrAddressOrIdentifierAsPreferred() throws Exception {
Patient patient = new Patient();
patient.setGender("M");
PatientIdentifier identifier = new PatientIdentifier("QWERTY", patientService.getPatientIdentifierType(2), locationService.getLocation(1));
PatientIdentifier preferredIdentifier = new PatientIdentifier("QWERTY2", patientService.getPatientIdentifierType(2), locationService.getLocation(1));
preferredIdentifier.setPreferred(true);
preferredIdentifier.setVoided(true);
patient.addIdentifier(identifier);
patient.addIdentifier(preferredIdentifier);
PersonName name = new PersonName("givenName", "middleName", "familyName");
PersonName preferredName = new PersonName("givenName", "middleName", "familyName");
preferredName.setPreferred(true);
preferredName.setVoided(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);
preferredAddress.setVoided(true);
patient.addAddress(address);
patient.addAddress(preferredAddress);
patientService.savePatient(patient);
Assert.assertFalse(preferredIdentifier.getPreferred());
Assert.assertFalse(preferredName.getPreferred());
Assert.assertFalse(preferredAddress.getPreferred());
Assert.assertTrue(identifier.getPreferred());
Assert.assertTrue(name.getPreferred());
Assert.assertTrue(address.getPreferred());
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatient_shouldSetThePreferredNameAddressAndIdentifierIfNoneIsSpecified.
/**
* @see PatientService#savePatient(Patient)
*/
@Test
public void savePatient_shouldSetThePreferredNameAddressAndIdentifierIfNoneIsSpecified() throws Exception {
Patient patient = new Patient();
patient.setGender("M");
PatientIdentifier identifier = new PatientIdentifier("QWERTY", patientService.getPatientIdentifierType(2), locationService.getLocation(1));
patient.addIdentifier(identifier);
PersonName name = new PersonName("givenName", "middleName", "familyName");
patient.addName(name);
PersonAddress address = new PersonAddress();
address.setAddress1("some address");
patient.addAddress(address);
Context.getPatientService().savePatient(patient);
Assert.assertTrue(identifier.getPreferred());
Assert.assertTrue(name.getPreferred());
Assert.assertTrue(address.getPreferred());
}
Aggregations