Search in sources :

Example 11 with PatientState

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"));
}
Also used : BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 12 with PatientState

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"));
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) ProgramWorkflowService(org.openmrs.api.ProgramWorkflowService) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 13 with PatientState

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"));
}
Also used : BindException(org.springframework.validation.BindException) PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 14 with PatientState

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);
}
Also used : PatientProgram(org.openmrs.PatientProgram) PatientState(org.openmrs.PatientState) Date(java.util.Date) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 15 with PatientState

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

PatientState (org.openmrs.PatientState)19 PatientProgram (org.openmrs.PatientProgram)17 Test (org.junit.Test)15 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)14 BindException (org.springframework.validation.BindException)11 Date (java.util.Date)7 ProgramWorkflow (org.openmrs.ProgramWorkflow)5 Patient (org.openmrs.Patient)3 ProgramWorkflowState (org.openmrs.ProgramWorkflowState)3 ProgramWorkflowService (org.openmrs.api.ProgramWorkflowService)3 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 PatientIdentifier (org.openmrs.PatientIdentifier)1 PatientIdentifierType (org.openmrs.PatientIdentifierType)1 Program (org.openmrs.Program)1 APIException (org.openmrs.api.APIException)1 PatientService (org.openmrs.api.PatientService)1 MessageSourceService (org.openmrs.messagesource.MessageSourceService)1