Search in sources :

Example 71 with Patient

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

the class PatientProgramValidatorTest method validate_shouldNotFailIfPatientStateIsInRetiredWorkflow.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 * this test is to specifically validate fix for https://tickets.openmrs.org/browse/TRUNK-3670
 */
@Test
public void validate_shouldNotFailIfPatientStateIsInRetiredWorkflow() {
    ProgramWorkflowService pws = Context.getProgramWorkflowService();
    Patient patient = Context.getPatientService().getPatient(6);
    // create a patient program
    PatientProgram pp = new PatientProgram();
    pp.setPatient(patient);
    pp.setProgram(pws.getProgram(1));
    // add a test workflow, and put the patient in a state in that workflow
    ProgramWorkflow testWorkflow = pp.getProgram().getWorkflow(1);
    PatientState newPatientState = new PatientState();
    newPatientState.setState(testWorkflow.getState(1));
    pp.getStates().add(newPatientState);
    // now retire the workflow
    testWorkflow.setRetired(true);
    testWorkflow.setRetiredBy(Context.getAuthenticatedUser());
    testWorkflow.setRetireReason("test");
    BindException errors = new BindException(pp, "");
    new PatientProgramValidator().validate(pp, errors);
    Assert.assertEquals(false, errors.hasFieldErrors("states"));
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) ProgramWorkflowService(org.openmrs.api.ProgramWorkflowService) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 72 with Patient

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

the class PatientProgramValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    ProgramWorkflowService pws = Context.getProgramWorkflowService();
    Patient patient = Context.getPatientService().getPatient(6);
    PatientProgram pp = new PatientProgram();
    pp.setPatient(patient);
    pp.setProgram(pws.getProgram(1));
    pp.setDateEnrolled(new Date());
    pp.setVoidReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    BindException errors = new BindException(pp, "program");
    new PatientProgramValidator().validate(pp, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("voidReason"));
}
Also used : ProgramWorkflowService(org.openmrs.api.ProgramWorkflowService) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 73 with Patient

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

the class PersonValidatorTest method shouldNotSetDeathBeforeBirth.

/**
 * @see org.openmrs.validator.PersonValidator#validate(Object,Errors)
 */
@Test
public void shouldNotSetDeathBeforeBirth() {
    Patient pa = new Patient(1);
    Calendar birth = Calendar.getInstance();
    birth.setTime(new Date());
    birth.add(Calendar.YEAR, +5);
    pa.setBirthdate(birth.getTime());
    Calendar death = Calendar.getInstance();
    death.setTime(new Date());
    pa.setDeathDate(death.getTime());
    Errors errors = new BindException(pa, "patient");
    validator.validate(pa, errors);
    Assert.assertTrue(errors.hasFieldErrors("deathDate"));
}
Also used : Errors(org.springframework.validation.Errors) Calendar(java.util.Calendar) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 74 with Patient

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

the class PersonValidatorTest method validate_shouldFailValidationIfPersonDoesNotHaveAtleastOneNonVoidedName.

/**
 * @see PersonValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfPersonDoesNotHaveAtleastOneNonVoidedName() {
    Patient pa = Context.getPatientService().getPatient(2);
    pa.getNames().clear();
    Errors errors = new BindException(pa, "patient");
    validator.validate(pa, errors);
    Assert.assertTrue(errors.hasFieldErrors("names"));
}
Also used : Errors(org.springframework.validation.Errors) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 75 with Patient

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

the class PersonValidatorTest method validate_shouldFailValidationIfBirthdateMakesPatientOlderThat120YearsOld.

/**
 * @see PersonValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfBirthdateMakesPatientOlderThat120YearsOld() {
    Patient pa = new Patient(1);
    Calendar birth = Calendar.getInstance();
    birth.setTime(new Date());
    birth.add(Calendar.YEAR, -125);
    pa.setBirthdate(birth.getTime());
    Errors errors = new BindException(pa, "patient");
    validator.validate(pa, errors);
    Assert.assertTrue(errors.hasFieldErrors("birthdate"));
}
Also used : Errors(org.springframework.validation.Errors) Calendar(java.util.Calendar) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Patient (org.openmrs.Patient)389 Test (org.junit.Test)345 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)284 Date (java.util.Date)106 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)91 Encounter (org.openmrs.Encounter)76 PatientIdentifier (org.openmrs.PatientIdentifier)60 Location (org.openmrs.Location)57 OrderUtilTest (org.openmrs.order.OrderUtilTest)47 PersonName (org.openmrs.PersonName)43 DrugOrder (org.openmrs.DrugOrder)42 BindException (org.springframework.validation.BindException)38 Concept (org.openmrs.Concept)37 Order (org.openmrs.Order)36 PatientIdentifierType (org.openmrs.PatientIdentifierType)33 Errors (org.springframework.validation.Errors)33 Visit (org.openmrs.Visit)29 ArrayList (java.util.ArrayList)28 Obs (org.openmrs.Obs)28 TestOrder (org.openmrs.TestOrder)28