Search in sources :

Example 76 with PatientIdentifier

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

Example 77 with PatientIdentifier

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

Example 78 with PatientIdentifier

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());
}
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 79 with PatientIdentifier

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

Example 80 with PatientIdentifier

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));
}
Also used : 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)

Aggregations

PatientIdentifier (org.openmrs.PatientIdentifier)116 Test (org.junit.Test)91 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 PatientIdentifierType (org.openmrs.PatientIdentifierType)57 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)47 Location (org.openmrs.Location)27 PersonName (org.openmrs.PersonName)24 Date (java.util.Date)19 PersonAddress (org.openmrs.PersonAddress)12 ArrayList (java.util.ArrayList)10 BindException (org.springframework.validation.BindException)8 User (org.openmrs.User)7 Errors (org.springframework.validation.Errors)7 SimpleDateFormat (java.text.SimpleDateFormat)5 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