Search in sources :

Example 81 with PatientIdentifier

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

the class PatientServiceTest method savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatientRegression1375.

/**
 * Regression test for ticket #1375: org.hibernate.NonUniqueObjectException caused by
 * PatientIdentifierValidator Manually construct a patient with a correctly-matching patientId
 * and patient identifier with validator. Calling PatientService.savePatient on that patient
 * leads to a call to PatientIdentifierValidator.validateIdentifier which used to load the
 * Patient for that identifier into the hibernate session, leading to a NonUniqueObjectException
 * when the calling saveOrUpdate on the manually constructed Patient.
 *
 * @see PatientService#savePatient(Patient)
 */
@Test
public void savePatient_shouldNotThrowANonUniqueObjectExceptionWhenCalledWithAHandConstructedPatientRegression1375() {
    Patient patient = new Patient();
    patient.setGender("M");
    patient.setPatientId(2);
    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);
    patientService.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 82 with PatientIdentifier

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

the class PatientDAOTest method getPatients_shouldNotGetNewPatientByWrongIdentifierStartMatch.

@Test
public void getPatients_shouldNotGetNewPatientByWrongIdentifierStartMatch() {
    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("OM292", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
    patient.addIdentifier(patientIdentifier);
    patientService.savePatient(patient);
    updateSearchIndex();
    List<Patient> patients = dao.getPatients("OM78", false, 0, null);
    Assert.assertEquals(0, patients.size());
    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 83 with PatientIdentifier

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

the class PatientDAOTest method getPatients_shouldEscapeUnderscoreCharacterInIdentifierPhrase.

/**
 * @throws SQLException
 * @see PatientDAO#getPatients(String,String,List<QPatientIdentifierType;>,null)
 */
@Test
public void getPatients_shouldEscapeUnderscoreCharacterInIdentifierPhrase() throws SQLException {
    deleteAllData();
    baseSetupWithStandardDataAndAuthentication();
    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 84 with PatientIdentifier

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

the class PatientServiceTest method mergePatients_shouldNotCopyOverDuplicatePatientIdentifiers.

/**
 * @see PatientService#mergePatients(Patient,Patient)
 */
@Test
public void mergePatients_shouldNotCopyOverDuplicatePatientIdentifiers() throws Exception {
    List<Location> locations = Context.getLocationService().getAllLocations();
    Assert.assertTrue(CollectionUtils.isNotEmpty(locations));
    // check if we have patient identifiers already
    PatientIdentifierType patientIdentifierType = Context.getPatientService().getPatientIdentifierType(5);
    Assert.assertNotNull(patientIdentifierType);
    // retrieve preferred patient and set gender
    Patient preferred = patientService.getPatient(999);
    // create new identifier for the preferred patient
    PatientIdentifier preferredIdentifier = new PatientIdentifier();
    preferredIdentifier.setIdentifier("9999-4");
    preferredIdentifier.setIdentifierType(patientIdentifierType);
    preferredIdentifier.setLocation(locations.get(0));
    preferred.addIdentifier(preferredIdentifier);
    preferred.addName(new PersonName("givenName", "middleName", "familyName"));
    patientService.savePatient(preferred);
    // merge with not preferred
    Patient notPreferred = patientService.getPatient(7);
    voidOrders(Collections.singleton(notPreferred));
    // create identifier with the same values for the non preferred patient
    PatientIdentifier nonPreferredIdentifier = new PatientIdentifier();
    nonPreferredIdentifier.setIdentifier("9999-4");
    nonPreferredIdentifier.setIdentifierType(patientIdentifierType);
    nonPreferredIdentifier.setLocation(locations.get(0));
    notPreferred.addIdentifier(nonPreferredIdentifier);
    patientService.savePatient(notPreferred);
    PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
    // should not copy the duplicate identifier to the winner
    Assert.assertEquals(notPreferred.getIdentifiers().size() - 1, audit.getPersonMergeLogData().getCreatedIdentifiers().size());
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 85 with PatientIdentifier

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

the class PatientServiceTest method checkPatientIdentifiers_shouldIgnoreVoidedPatientIdentifier.

/**
 * @see PatientService#checkPatientIdentifiers(Patient)
 */
@Test
public void checkPatientIdentifiers_shouldIgnoreVoidedPatientIdentifier() throws Exception {
    Patient patient = new Patient();
    PatientIdentifier patientIdentifier = new PatientIdentifier();
    patientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0));
    patientIdentifier.setLocation(new Location(1));
    patientIdentifier.setVoided(true);
    patientIdentifier.setVoidedBy(Context.getAuthenticatedUser());
    patientIdentifier.setVoidReason("Testing whether voided identifiers are ignored");
    patient.addIdentifier(patientIdentifier);
    // add a non-voided identifier so that the initial
    // "at least one nonvoided identifier" check passes
    patientIdentifier = new PatientIdentifier();
    patientIdentifier.setIdentifier("a non empty string");
    patientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0));
    patientIdentifier.setLocation(new Location(1));
    patientIdentifier.setVoided(false);
    patientIdentifier.setVoidedBy(Context.getAuthenticatedUser());
    patientIdentifier.setVoidReason("Testing whether voided identifiers are ignored");
    patient.addIdentifier(patientIdentifier);
    // If the identifier is ignored, it won't throw a
    // BlankIdentifierException as it should
    Context.getPatientService().checkPatientIdentifiers(patient);
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) 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