Search in sources :

Example 6 with PatientProgram

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

the class PatientProgramValidatorTest method validate_shouldFailIfPatientProgramEnrolledDateIsInFuture.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfPatientProgramEnrolledDateIsInFuture() {
    PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
    Date date10DaysAfterSystemCurrentDate = new Date(System.currentTimeMillis() + 10 * 24 * 60 * 60 * 1000);
    program.setDateEnrolled(date10DaysAfterSystemCurrentDate);
    BindException errors = new BindException(program, "");
    new PatientProgramValidator().validate(program, errors);
    Assert.assertTrue(errors.hasFieldErrors("dateEnrolled"));
}
Also used : BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with PatientProgram

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

the class PatientProgramValidatorTest method validate_shouldFailIfAPatientProgramHasDuplicateStatesInTheSameWorkFlow.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfAPatientProgramHasDuplicateStatesInTheSameWorkFlow() {
    PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
    Set<PatientState> states = program.getStates();
    Assert.assertNotNull(states);
    PatientState patientState = states.iterator().next();
    PatientState duplicate = patientState.copy();
    states.add(duplicate);
    BindException errors = new BindException(program, "");
    new PatientProgramValidator().validate(program, errors);
    Assert.assertTrue(errors.hasFieldErrors("states"));
}
Also used : BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with PatientProgram

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

the class PatientProgramValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    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("voidReason");
    BindException errors = new BindException(pp, "program");
    new PatientProgramValidator().validate(pp, errors);
    Assert.assertEquals(false, errors.hasErrors());
}
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 9 with PatientProgram

use of org.openmrs.PatientProgram 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 10 with PatientProgram

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

the class PatientProgramValidatorTest method validate_shouldFailIfPatientProgramEndDateIsInFuture.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfPatientProgramEndDateIsInFuture() {
    PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
    Date date10DaysAfterSystemCurrentDate = new Date(System.currentTimeMillis() + 10 * 24 * 60 * 60 * 1000);
    program.setDateCompleted(date10DaysAfterSystemCurrentDate);
    BindException errors = new BindException(program, "");
    new PatientProgramValidator().validate(program, errors);
    Assert.assertTrue(errors.hasFieldErrors("dateCompleted"));
}
Also used : BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

PatientProgram (org.openmrs.PatientProgram)37 Test (org.junit.Test)30 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)27 BindException (org.springframework.validation.BindException)18 PatientState (org.openmrs.PatientState)17 Date (java.util.Date)14 Patient (org.openmrs.Patient)11 ProgramWorkflowService (org.openmrs.api.ProgramWorkflowService)7 Program (org.openmrs.Program)6 ProgramWorkflow (org.openmrs.ProgramWorkflow)5 ArrayList (java.util.ArrayList)3 ProgramWorkflowState (org.openmrs.ProgramWorkflowState)3 MissingPropertyException (groovy.lang.MissingPropertyException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1 DateTime (org.joda.time.DateTime)1