Search in sources :

Example 71 with PatientIdentifier

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

the class PatientServiceTest method savePatientIdentifier_shouldUpdateAnExistingPatientIdentifier.

@Test
public void savePatientIdentifier_shouldUpdateAnExistingPatientIdentifier() throws Exception {
    PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7);
    patientIdentifier.setIdentifier("NEW-ID");
    PatientIdentifier updatedPatientIdentifier = patientService.savePatientIdentifier(patientIdentifier);
    Assert.assertNotNull(updatedPatientIdentifier);
    Assert.assertEquals("NEW-ID", updatedPatientIdentifier.getIdentifier());
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 72 with PatientIdentifier

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

the class PatientServiceTest method savePatientIdentifier_shouldAllowLocationToBeNullWhenLocationBehaviourIsNotUsed.

/**
 * @see PatientService#savePatientIdentifier(PatientIdentifier)
 */
@Test
public void savePatientIdentifier_shouldAllowLocationToBeNullWhenLocationBehaviourIsNotUsed() {
    PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7);
    patientIdentifier.setLocation(null);
    patientIdentifier.getIdentifierType().setLocationBehavior(PatientIdentifierType.LocationBehavior.NOT_USED);
    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 73 with PatientIdentifier

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

the class PatientServiceTest method getPatients_shouldSupportPatternUsingLastDigitAsCheckDigit.

/**
 * @see PatientService#getPatients(String, String, java.util.List, boolean)
 */
@Test
public void getPatients_shouldSupportPatternUsingLastDigitAsCheckDigit() throws Exception {
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_PATTERN, "@SEARCH@,0@SEARCH@,@SEARCH-1@-@CHECKDIGIT@,0@SEARCH-1@-@CHECKDIGIT@"));
    // "^(0*@SEARCH-1@-@CHECKDIGIT@)$"));
    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("12344").size());
    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 74 with PatientIdentifier

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

the class PatientServiceTest method savePatientIdentifier_shouldAllowLocationToBeNullWhenLocationBehaviourIsRequired.

/**
 * @see PatientService#savePatientIdentifier(PatientIdentifier)
 */
@Test(expected = ValidationException.class)
public void savePatientIdentifier_shouldAllowLocationToBeNullWhenLocationBehaviourIsRequired() {
    PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7);
    patientIdentifier.setLocation(null);
    patientIdentifier.getIdentifierType().setLocationBehavior(PatientIdentifierType.LocationBehavior.REQUIRED);
    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 75 with PatientIdentifier

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

the class PatientServiceTest method checkPatientIdentifiers_shouldRemovePatientIdentifierGivenItIsBlank.

/**
 * @see PatientService#checkPatientIdentifiers(Patient)
 */
@Test
public void checkPatientIdentifiers_shouldRemovePatientIdentifierGivenItIsBlank() throws Exception {
    // given
    Patient patient = new Patient();
    PatientIdentifier blankPatientIdentifier = new PatientIdentifier();
    blankPatientIdentifier.setIdentifier("");
    blankPatientIdentifier.setIdentifierType(new PatientIdentifierType(21345));
    blankPatientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0));
    patient.addIdentifier(blankPatientIdentifier);
    assertEquals(1, patient.getIdentifiers().size());
    try {
        // when
        Context.getPatientService().checkPatientIdentifiers(patient);
        // then
        fail("should throw BlankIdentifierException");
    } catch (BlankIdentifierException e) {
        assertEquals(0, patient.getIdentifiers().size());
    }
}
Also used : Patient(org.openmrs.Patient) 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)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