use of org.openmrs.Patient 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.Patient in project openmrs-core by openmrs.
the class PatientProgramValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see PatientProgramValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
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("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
BindException errors = new BindException(pp, "program");
new PatientProgramValidator().validate(pp, errors);
Assert.assertEquals(true, errors.hasFieldErrors("voidReason"));
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class PersonValidatorTest method shouldNotSetDeathBeforeBirth.
/**
* @see org.openmrs.validator.PersonValidator#validate(Object,Errors)
*/
@Test
public void shouldNotSetDeathBeforeBirth() {
Patient pa = new Patient(1);
Calendar birth = Calendar.getInstance();
birth.setTime(new Date());
birth.add(Calendar.YEAR, +5);
pa.setBirthdate(birth.getTime());
Calendar death = Calendar.getInstance();
death.setTime(new Date());
pa.setDeathDate(death.getTime());
Errors errors = new BindException(pa, "patient");
validator.validate(pa, errors);
Assert.assertTrue(errors.hasFieldErrors("deathDate"));
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class PersonValidatorTest method validate_shouldFailValidationIfPersonDoesNotHaveAtleastOneNonVoidedName.
/**
* @see PersonValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfPersonDoesNotHaveAtleastOneNonVoidedName() {
Patient pa = Context.getPatientService().getPatient(2);
pa.getNames().clear();
Errors errors = new BindException(pa, "patient");
validator.validate(pa, errors);
Assert.assertTrue(errors.hasFieldErrors("names"));
}
use of org.openmrs.Patient in project openmrs-core by openmrs.
the class PersonValidatorTest method validate_shouldFailValidationIfBirthdateMakesPatientOlderThat120YearsOld.
/**
* @see PersonValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfBirthdateMakesPatientOlderThat120YearsOld() {
Patient pa = new Patient(1);
Calendar birth = Calendar.getInstance();
birth.setTime(new Date());
birth.add(Calendar.YEAR, -125);
pa.setBirthdate(birth.getTime());
Errors errors = new BindException(pa, "patient");
validator.validate(pa, errors);
Assert.assertTrue(errors.hasFieldErrors("birthdate"));
}
Aggregations