use of org.openmrs.PatientState in project openmrs-core by openmrs.
the class PatientProgramValidatorTest method validate_shouldFailIfAPatientStateHasAnInvalidWorkFlowState.
/**
* @see PatientProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfAPatientStateHasAnInvalidWorkFlowState() {
executeDataSet("org/openmrs/api/include/ProgramWorkflowServiceTest-otherProgramWorkflows.xml");
PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
PatientState patientState = program.getStates().iterator().next();
patientState.setState(Context.getProgramWorkflowService().getStateByUuid("31c82d66-245c-11e1-9cf0-00248140a5eb"));
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_shouldFailIfThereIsMoreThanOneStateWithANullStartDateInTheSameWorkflow.
/**
* @see PatientProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfThereIsMoreThanOneStateWithANullStartDateInTheSameWorkflow() {
ProgramWorkflowService pws = Context.getProgramWorkflowService();
Patient patient = Context.getPatientService().getPatient(6);
PatientProgram pp = new PatientProgram();
pp.setPatient(patient);
pp.setProgram(pws.getProgram(1));
ProgramWorkflow testWorkflow = pp.getProgram().getWorkflow(1);
// Add 2 other patient states with null start date
PatientState newPatientState1 = new PatientState();
newPatientState1.setState(testWorkflow.getState(1));
pp.getStates().add(newPatientState1);
PatientState newPatientState2 = new PatientState();
newPatientState2.setState(testWorkflow.getState(2));
pp.getStates().add(newPatientState2);
BindException errors = new BindException(pp, "");
new PatientProgramValidator().validate(pp, errors);
Assert.assertEquals(true, errors.hasFieldErrors("states"));
}
use of org.openmrs.PatientState in project openmrs-core by openmrs.
the class PatientProgramValidatorTest method validate_shouldFailIfAnyPatientStateHasANullWorkFlowState.
/**
* @see PatientProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfAnyPatientStateHasANullWorkFlowState() {
PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
PatientState patientState = program.getStates().iterator().next();
patientState.setState(null);
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_shouldPassForAValidProgram.
/**
* @see PatientProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldPassForAValidProgram() {
PatientProgram program = Context.getProgramWorkflowService().getPatientProgram(1);
PatientState patientState = program.getStates().iterator().next();
patientState.getPatientProgram().transitionToState(patientState.getState().getProgramWorkflow().getState(4), new Date());
ValidateUtil.validate(program);
}
use of org.openmrs.PatientState 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"));
}
Aggregations