Search in sources :

Example 36 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientDAOTest method getPatientIdentifiers_shouldFetchAllPatientIdentifiersBelongToGivenPatient.

/**
 * @see PatientDAO#getPatientIdentifiers(String,List,List,List,Boolean)
 */
@Test
public void getPatientIdentifiers_shouldFetchAllPatientIdentifiersBelongToGivenPatient() {
    // There are two identifiers in the test database for patient with id 2
    Patient patientWithId2 = Context.getPatientService().getPatient(2);
    List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(null, new ArrayList<>(), new ArrayList<>(), Collections.singletonList(patientWithId2), null);
    assertThat(patientIdentifiers, containsInAnyOrder(hasIdentifier("101"), hasIdentifier("101-6")));
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 37 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientDAOTest method getPatients_shouldEscapeAnAsterixCharacterInIdentifierPhrase.

/**
 * @see PatientDAO#getPatients(String,String,List<QPatientIdentifierType;>,null)
 */
@Test
public void getPatients_shouldEscapeAnAsterixCharacterInIdentifierPhrase() {
    // Note that all tests for wildcard should be pass in 2s due to the behaviour of wildcards,
    // that is we test for the size and actual patient object returned
    Patient patient2 = patientService.getPatient(2);
    PatientIdentifier patientIdentifier = new PatientIdentifier("*567", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
    patient2.addIdentifier(patientIdentifier);
    patientService.savePatient(patient2);
    // add closely matching identifier to a different patient
    Patient patient6 = patientService.getPatient(6);
    PatientIdentifier patientIdentifier6 = new PatientIdentifier("4567", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
    patientIdentifier6.setPreferred(true);
    patient6.addIdentifier(patientIdentifier6);
    patientService.savePatient(patient6);
    updateSearchIndex();
    // we expect only one matching patient
    int actualSize = dao.getPatients("*567", 0, null).size();
    Assert.assertEquals(1, actualSize);
    // if actually the search returned the matching patient
    Patient actualPatient = dao.getPatients("*567", 0, null).get(0);
    Assert.assertEquals(patient2, actualPatient);
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 38 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientServiceTest method savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatient.

/**
 * Regression test for http://dev.openmrs.org/ticket/1375
 *
 * @see PatientService#savePatient(Patient)
 */
@Test
public void savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatient() throws Exception {
    Patient patient = new Patient();
    patient.setGender("M");
    patient.setPatientId(2);
    // patient.setCreator(new User(1));
    // patient.setDateCreated date_created="2005-09-22 00:00:00.0"
    // changed_by="1" date_changed="2008-08-18 12:29:59.0"
    patient.addName(new PersonName("This", "Isa", "Test"));
    PatientIdentifier patientIdentifier = new PatientIdentifier("101-6", new PatientIdentifierType(1), new Location(1));
    patientIdentifier.setPreferred(true);
    patient.addIdentifier(patientIdentifier);
    Context.getPatientService().savePatient(patient);
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) 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 39 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientServiceTest method savePatientIdentifier_shouldThrowAnAPIExceptionIfThePatientIdentifierStringIsAnEmptyString.

@Test(expected = APIException.class)
public void savePatientIdentifier_shouldThrowAnAPIExceptionIfThePatientIdentifierStringIsAnEmptyString() throws Exception {
    PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7);
    patientIdentifier.setIdentifier("");
    patientService.savePatientIdentifier(patientIdentifier);
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 40 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseAndIdTypeUniquenessIsSetToUnique.

/**
 * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
 */
@Test
public void isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseAndIdTypeUniquenessIsSetToUnique() throws Exception {
    PatientIdentifier duplicateId = patientService.getPatientIdentifier(1);
    Assert.assertNotNull(duplicateId.getLocation());
    PatientIdentifierType idType = duplicateId.getIdentifierType();
    idType.setUniquenessBehavior(UniquenessBehavior.UNIQUE);
    patientService.savePatientIdentifierType(idType);
    PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, duplicateId.getLocation());
    Assert.assertTrue(patientService.isIdentifierInUseByAnotherPatient(pi));
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) 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