Search in sources :

Example 16 with PatientIdentifier

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));
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 17 with 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));
}
Also used : Patient(org.openmrs.Patient) Person(org.openmrs.Person) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 18 with PatientIdentifier

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);
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 19 with PatientIdentifier

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());
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 20 with PatientIdentifier

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());
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Aggregations

PatientIdentifier (org.openmrs.PatientIdentifier)103 Test (org.junit.Test)86 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)59 PatientIdentifierType (org.openmrs.PatientIdentifierType)51 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)47 Location (org.openmrs.Location)26 PersonName (org.openmrs.PersonName)19 Date (java.util.Date)15 PersonAddress (org.openmrs.PersonAddress)10 ArrayList (java.util.ArrayList)9 BindException (org.springframework.validation.BindException)8 User (org.openmrs.User)7 Errors (org.springframework.validation.Errors)7 Person (org.openmrs.Person)5 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)5 HL7Exception (ca.uhn.hl7v2.HL7Exception)3 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)3 CX (ca.uhn.hl7v2.model.v25.datatype.CX)3 Concept (org.openmrs.Concept)3