Search in sources :

Example 21 with PatientIdentifier

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

the class PatientServiceTest method getCountOfPatients_shouldReturnTheRightCountOfPatientsWithAMatchingIdentifierWithNoDigits.

/**
 * @see PatientService#getCountOfPatients(String)
 */
@Test
public void getCountOfPatients_shouldReturnTheRightCountOfPatientsWithAMatchingIdentifierWithNoDigits() throws Exception {
    final String identifier = "XYZ";
    Patient patient = patientService.getPatient(2);
    Assert.assertEquals(0, patientService.getCountOfPatients(identifier).intValue());
    PatientIdentifier pId = new PatientIdentifier(identifier, patientService.getPatientIdentifierType(5), locationService.getLocation(1));
    patient.addIdentifier(pId);
    patientService.savePatient(patient);
    updateSearchIndex();
    Assert.assertEquals(1, patientService.getCountOfPatients(identifier).intValue());
}
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 22 with PatientIdentifier

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

the class PatientServiceTest method getPatients_shouldSupportSimpleRegex.

/**
 * @see PatientService#getPatients(String, String, java.util.List, boolean)
 */
@Test
public void getPatients_shouldSupportSimpleRegex() throws Exception {
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_REGEX, "^0*@SEARCH@([A-Z]+-[0-9])?$"));
    PatientIdentifier identifier = new PatientIdentifier("1234-4", new PatientIdentifierType(1), new Location(1));
    identifier.setCreator(new User(1));
    identifier.setDateCreated(new Date());
    Patient patient = Context.getPatientService().getPatient(2);
    patient.addIdentifier(identifier);
    Context.getPatientService().savePatient(patient);
    updateSearchIndex();
    assertEquals(1, Context.getPatientService().getPatients("1234-4").size());
}
Also used : User(org.openmrs.User) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Date(java.util.Date) GlobalProperty(org.openmrs.GlobalProperty) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 23 with PatientIdentifier

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

the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseAndIdTypeUniquenessIsNull.

/**
 * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
 */
@Test
public void isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseAndIdTypeUniquenessIsNull() throws Exception {
    PatientIdentifier duplicateId = patientService.getPatientIdentifier(1);
    Assert.assertNotNull(duplicateId.getLocation());
    PatientIdentifierType idType = duplicateId.getIdentifierType();
    Assert.assertNull(idType.getUniquenessBehavior());
    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)

Example 24 with PatientIdentifier

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

the class PatientServiceTest method voidPatientIdentifier_shouldThrowAnAPIExceptionIfTheReasonIsAnEmptyString.

@Test(expected = APIException.class)
public void voidPatientIdentifier_shouldThrowAnAPIExceptionIfTheReasonIsAnEmptyString() 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 25 with PatientIdentifier

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

the class PatientServiceTest method savePatientIdentifier_shouldCreateNewPatientIndentifier.

@Test
public void savePatientIdentifier_shouldCreateNewPatientIndentifier() throws Exception {
    PatientIdentifier patientIdentifier = new PatientIdentifier("677-56-6666", new PatientIdentifierType(4), new Location(1));
    Patient associatedPatient = patientService.getPatient(2);
    patientIdentifier.setPatient(associatedPatient);
    PatientIdentifier createdPatientIdentifier = patientService.savePatientIdentifier(patientIdentifier);
    Assert.assertNotNull(createdPatientIdentifier);
    Assert.assertNotNull(createdPatientIdentifier.getPatientIdentifierId());
}
Also used : 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)

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