Search in sources :

Example 91 with PatientIdentifier

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

the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldReturnTrueWhenPatientIdentifierContainsAPatientAndAnotherPatientHasThisId.

/**
 * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
 */
@Test
public void isIdentifierInUseByAnotherPatient_shouldReturnTrueWhenPatientIdentifierContainsAPatientAndAnotherPatientHasThisId() throws Exception {
    PatientIdentifierType pit = patientService.getPatientIdentifierType(1);
    PatientIdentifier patientIdentifier = new PatientIdentifier("7TU-8", pit, null);
    patientIdentifier.setPatient(patientService.getPatient(2));
    Assert.assertTrue(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 92 with PatientIdentifier

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

the class PatientDAOTest method getPatients_shouldNotGetCloseIdentifiersWithWrongStartPhrase.

@Test
public void getPatients_shouldNotGetCloseIdentifiersWithWrongStartPhrase() {
    String oldPropertyValue = globalPropertiesTestHelper.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE, OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_SEARCH_MATCH_START);
    Patient patient = patientService.getPatient(2);
    PatientIdentifier patientIdentifier = new PatientIdentifier("BAH409", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
    patient.addIdentifier(patientIdentifier);
    patientService.savePatient(patient);
    // add closely matching identifier to a different patient
    Patient patient2 = patientService.getPatient(6);
    PatientIdentifier patientIdentifier6 = new PatientIdentifier("BAH509", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
    patientIdentifier6.setPreferred(true);
    patient2.addIdentifier(patientIdentifier6);
    patientService.savePatient(patient2);
    updateSearchIndex();
    // Check for partial identifier match
    List<Patient> patients = dao.getPatients("BAH5", false, 0, null);
    Assert.assertEquals(1, patients.size());
    Assert.assertEquals("BAH509", patients.get(0).getPatientIdentifier(5).toString());
    if (oldPropertyValue != null) {
        globalPropertiesTestHelper.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE, oldPropertyValue);
    } else {
        globalPropertiesTestHelper.purgeGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE);
    }
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 93 with PatientIdentifier

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

the class PatientDAOTest method getPatientIdentifiers_shouldFetchAllPatientIdentifiersBelongToGivenPatients.

/**
 * @see PatientDAO#getPatientIdentifiers(String,List,List,List,Boolean)
 */
@Test
public void getPatientIdentifiers_shouldFetchAllPatientIdentifiersBelongToGivenPatients() {
    // There is one identifier[id=12345K] in the test database for patient with id 6
    Patient patientWithId6 = Context.getPatientService().getPatient(6);
    // There is one identifier[id=6TS-4] in the test database for patient with id 7
    Patient patientWithId7 = Context.getPatientService().getPatient(7);
    List<Patient> patientsList = Arrays.asList(patientWithId6, patientWithId7);
    List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(null, new ArrayList<>(), new ArrayList<>(), patientsList, null);
    assertThat(patientIdentifiers, containsInAnyOrder(hasIdentifier("12345K"), hasIdentifier("6TS-4")));
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 94 with PatientIdentifier

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

the class PatientDAOTest method getPatients_shouldNotGetExcessPatientsOnIdentifierAndNameMatch.

/**
 * @see HibernatePatientDAO#getPatients(String, Integer, Integer)
 */
@Test
public void getPatients_shouldNotGetExcessPatientsOnIdentifierAndNameMatch() {
    Patient patient = patientService.getPatient(2);
    PatientIdentifier patientIdentifier = new PatientIdentifier("alpha", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
    patient.addIdentifier(patientIdentifier);
    patientService.savePatient(patient);
    updateSearchIndex();
    List<Patient> patients = dao.getPatients("alpha", 0, null);
    Assert.assertEquals(patient, patients.get(0));
    Assert.assertEquals(3, patients.size());
    List<Patient> first_patient = dao.getPatients("alpha", 0, 1);
    Assert.assertEquals(patient, first_patient.get(0));
    Assert.assertEquals(1, first_patient.size());
    List<Patient> two_patients_only = dao.getPatients("alpha", 0, 2);
    Assert.assertEquals(2, two_patients_only.size());
    List<Patient> second_patient = dao.getPatients("alpha", 1, 1);
    Assert.assertEquals(1, second_patient.size());
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 95 with PatientIdentifier

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

the class PatientDAOTest method getPatientIdentifiers_shouldNotGetVoidedPatientIdentifiers.

/**
 * @see PatientDAO#getPatientIdentifiers(String,List,List,List,Boolean)
 */
@Test
public void getPatientIdentifiers_shouldNotGetVoidedPatientIdentifiers() {
    List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(null, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null);
    // standartTestDataset.xml contains 5 non-voided identifiers
    // 
    // plus 1 non-voided identifier from HibernatePatientDAOTest-patients.xml
    Assert.assertEquals(8, patientIdentifiers.size());
    for (PatientIdentifier patientIdentifier : patientIdentifiers) {
        Assert.assertFalse(patientIdentifier.getVoided());
    }
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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