Search in sources :

Example 96 with PatientIdentifier

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

the class PatientDAOTest method getPatients_shouldGetCloseIdentifiersWithCorrectStartPhrase.

@Test
public void getPatients_shouldGetCloseIdentifiersWithCorrectStartPhrase() {
    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("BAH", false, 0, null);
    Assert.assertEquals(2, 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 97 with PatientIdentifier

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

the class PatientIdentifierValidatorTest method validateIdentifier_shouldPassIfInUseAndIdTypeUniquenessIsSetToNonUnique.

/**
 * @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier)
 */
@Test
public void validateIdentifier_shouldPassIfInUseAndIdTypeUniquenessIsSetToNonUnique() {
    PatientService patientService = Context.getPatientService();
    PatientIdentifier duplicateId = patientService.getPatientIdentifier(1);
    Assert.assertNotNull(duplicateId.getLocation());
    PatientIdentifierType idType = duplicateId.getIdentifierType();
    idType.setUniquenessBehavior(UniquenessBehavior.NON_UNIQUE);
    patientService.savePatientIdentifierType(idType);
    PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, duplicateId.getLocation());
    PatientIdentifierValidator.validateIdentifier(pi);
}
Also used : PatientService(org.openmrs.api.PatientService) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 98 with PatientIdentifier

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

the class PatientIdentifierValidatorTest method validateIdentifier_shouldFailValidationIfAnotherPatientHasAMatchingIdentifierOfTheSameType.

/**
 * @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier)
 */
@Test(expected = IdentifierNotUniqueException.class)
public void validateIdentifier_shouldFailValidationIfAnotherPatientHasAMatchingIdentifierOfTheSameType() {
    PatientIdentifier pi = Context.getPatientService().getPatientIdentifiers("7TU-8", null, null, null, null).get(0);
    pi.setIdentifier("101-6");
    PatientIdentifierValidator.validateIdentifier(pi);
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 99 with PatientIdentifier

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

the class PatientIdentifierValidatorTest method validateIdentifier_shouldFailValidationIfIdentifierIsBlank.

/**
 * @see PatientIdentifierValidator#validateIdentifier(String,PatientIdentifierType)
 */
@Test(expected = BlankIdentifierException.class)
public void validateIdentifier_shouldFailValidationIfIdentifierIsBlank() {
    PatientIdentifier identifier = new PatientIdentifier("", new PatientIdentifierType(1), new Location(1));
    PatientIdentifierValidator.validateIdentifier(identifier);
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 100 with PatientIdentifier

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

the class PatientIdentifierValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    PatientIdentifier pi = new PatientIdentifier("1TU-8", new PatientIdentifierType(1), null);
    PatientIdentifierType idType = pi.getIdentifierType();
    idType.setLocationBehavior(PatientIdentifierType.LocationBehavior.NOT_USED);
    pi.setVoidReason("voidReason");
    Errors errors = new BindException(pi, "pi");
    new PatientIdentifierValidator().validate(pi, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) 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