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"));
}
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"));
}
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());
}
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"));
}
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"));
}
Aggregations