Search in sources :

Example 31 with PatientProgram

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

the class PatientProgramValidatorTest method validate_shouldFailIfAPatientIsInMultipleStatesInTheSameWorkFlow.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfAPatientIsInMultipleStatesInTheSameWorkFlow() {
    PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
    PatientState patientState = program.getStates().iterator().next();
    patientState.getPatientProgram().transitionToState(patientState.getState().getProgramWorkflow().getState(4), new Date());
    // make the closed state active
    patientState.setEndDate(null);
    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) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 32 with PatientProgram

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

the class PatientProgramValidatorTest method validate_shouldPassIfAPatientIsInMultipleStatesInDifferentWorkFlows.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassIfAPatientIsInMultipleStatesInDifferentWorkFlows() {
    PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
    // Add another state to another work flow
    PatientState patientState2 = new PatientState();
    patientState2.setStartDate(new Date());
    patientState2.setState(Context.getProgramWorkflowService().getWorkflowByUuid("c66c8713-7df4-40de-96f6-dc4cce3432da").getState(5));
    program.getStates().add(patientState2);
    ValidateUtil.validate(program);
}
Also used : PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 33 with PatientProgram

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

the class PatientProgramValidatorTest method validate_shouldFailIfAnyPatientStateHasAnEndDateBeforeItsStartDate.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfAnyPatientStateHasAnEndDateBeforeItsStartDate() {
    PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
    PatientState patientState = program.getStates().iterator().next();
    Calendar c = Calendar.getInstance();
    patientState.setStartDate(c.getTime());
    // set to an old date
    c.set(1970, 2, 1);
    patientState.setEndDate(c.getTime());
    BindException errors = new BindException(program, "");
    new PatientProgramValidator().validate(program, errors);
    Assert.assertTrue(errors.hasFieldErrors("states"));
}
Also used : Calendar(java.util.Calendar) BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 34 with PatientProgram

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

the class PatientProgramValidatorTest method validate_shouldPassForPatientStatesThatHaveTheSameStartDatesInTheSameWorkFlow.

/**
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassForPatientStatesThatHaveTheSameStartDatesInTheSameWorkFlow() {
    PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
    PatientState patientState = program.getStates().iterator().next();
    // add a new state by moving the patient to a another one
    ProgramWorkflowState nextState = patientState.getState().getProgramWorkflow().getState(4);
    patientState.getPatientProgram().transitionToState(nextState, patientState.getStartDate());
    BindException errors = new BindException(program, "");
    new PatientProgramValidator().validate(program, errors);
    Assert.assertEquals(false, errors.hasFieldErrors("states"));
}
Also used : ProgramWorkflowState(org.openmrs.ProgramWorkflowState) BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 35 with PatientProgram

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

the class PatientProgramValidatorTest method validate_shouldFailIfAnyPatientStatesOverlapEachOtherInTheSameWorkFlow.

/**
 * @throws InterruptedException
 * @see PatientProgramValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfAnyPatientStatesOverlapEachOtherInTheSameWorkFlow() throws InterruptedException {
    PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
    // Addition of new states to this program in the test data can make this test useless, so catch it her
    Assert.assertEquals(1, program.getStates().size());
    PatientState patientState1 = program.getStates().iterator().next();
    // Add a state that comes after patientState1
    PatientState patientState2 = new PatientState();
    patientState2.setStartDate(new Date());
    patientState2.setState(Context.getProgramWorkflowService().getWorkflowByUuid("84f0effa-dd73-46cb-b931-7cd6be6c5f81").getState(1));
    // guarantees that startDate of patientState2 is atleast 10ms earlier
    Thread.sleep(10);
    patientState1.setEndDate(new Date());
    program.getStates().add(patientState2);
    BindException errors = new BindException(program, "");
    new PatientProgramValidator().validate(program, errors);
    Assert.assertEquals(true, errors.hasFieldErrors("states"));
}
Also used : BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) 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