Search in sources :

Example 16 with PatientState

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

Example 17 with PatientState

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

Example 18 with PatientState

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

Example 19 with PatientState

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