use of org.openmrs.PatientState 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);
}
use of org.openmrs.PatientState 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"));
}
use of org.openmrs.PatientState 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"));
}
use of org.openmrs.PatientState 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"));
}
Aggregations