Search in sources :

Example 6 with ProgramWorkflow

use of org.openmrs.ProgramWorkflow in project openmrs-core by openmrs.

the class StateConversionValidatorTest method validate_shouldFailValidationIfProgramWorkflowStateIsNullOrEmptyOrWhitespace.

/**
 * @see StateConversionValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfProgramWorkflowStateIsNullOrEmptyOrWhitespace() {
    ConceptStateConversion csc = new ConceptStateConversion();
    ProgramWorkflow workflow = Context.getProgramWorkflowService().getProgram(1).getAllWorkflows().iterator().next();
    csc.setConcept(Context.getConceptService().getConcept(3));
    csc.setProgramWorkflow(workflow);
    csc.setProgramWorkflowState(null);
    Errors errors = new BindException(csc, "csc");
    new StateConversionValidator().validate(csc, errors);
    Assert.assertTrue(errors.hasFieldErrors("programWorkflowState"));
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) ConceptStateConversion(org.openmrs.ConceptStateConversion) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with ProgramWorkflow

use of org.openmrs.ProgramWorkflow in project openmrs-core by openmrs.

the class ProgramWorkflowServiceTest method getWorkflow_shouldGetWorkflowAssociatedWithGivenIdIfWorkflowIdExists.

@Test
public void getWorkflow_shouldGetWorkflowAssociatedWithGivenIdIfWorkflowIdExists() {
    final Integer EXISTING_WORKFLOW_ID = 1;
    ProgramWorkflow workflow = pws.getWorkflow(EXISTING_WORKFLOW_ID);
    assertNotNull("ProgramWorkflow not found", workflow);
    assertThat(workflow.getId(), is(EXISTING_WORKFLOW_ID));
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with ProgramWorkflow

use of org.openmrs.ProgramWorkflow in project openmrs-core by openmrs.

the class ProgramWorkflowServiceTest method getWorkflowByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see ProgramWorkflowService#getWorkflowByUuid(String)
 */
@Test
public void getWorkflowByUuid_shouldFindObjectGivenValidUuid() {
    String uuid = "84f0effa-dd73-46cb-b931-7cd6be6c5f81";
    ProgramWorkflow programWorkflow = Context.getProgramWorkflowService().getWorkflowByUuid(uuid);
    Assert.assertEquals(1, (int) programWorkflow.getProgramWorkflowId());
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with ProgramWorkflow

use of org.openmrs.ProgramWorkflow in project openmrs-core by openmrs.

the class ProgramWorkflowServiceTest method retireProgram_shouldSaveTheRetiredProgramWithReason.

@Test
public void retireProgram_shouldSaveTheRetiredProgramWithReason() throws APIException {
    String reason = "Feeling well.";
    String uuid = "eae98b4c-e195-403b-b34a-82d94103b2c0";
    Program program = Context.getProgramWorkflowService().getProgramByUuid(uuid);
    Program retireProgram = pws.retireProgram(program, reason);
    assertTrue(retireProgram.getRetired());
    assertEquals(reason, retireProgram.getRetireReason());
    for (ProgramWorkflow programWorkflow : program.getAllWorkflows()) {
        assertTrue(programWorkflow.getRetired());
        for (ProgramWorkflowState programWorkflowState : programWorkflow.getStates()) {
            assertTrue(programWorkflowState.getRetired());
        }
    }
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) ProgramWorkflowState(org.openmrs.ProgramWorkflowState) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 10 with ProgramWorkflow

use of org.openmrs.ProgramWorkflow in project openmrs-core by openmrs.

the class ProgramWorkflowServiceTest method getSortedStates_shouldSortNamesContainingNumbersIntelligently.

/**
 * THIS TEST SHOULD BE IN THE CLASS 'PROGRAMWORKFLOWTEST.JAVA' BUT IT REQUIRES ACCESS TO THE DAO
 * LAYER
 *
 * @see ProgramWorkflow#getSortedStates()
 */
@Test
public void getSortedStates_shouldSortNamesContainingNumbersIntelligently() {
    ProgramWorkflow program = new ProgramWorkflow();
    ConceptName state1ConceptName = new ConceptName("Group 10", Context.getLocale());
    Concept state1Concept = new Concept();
    state1Concept.addName(state1ConceptName);
    ProgramWorkflowState state1 = new ProgramWorkflowState();
    state1.setConcept(state1Concept);
    program.addState(state1);
    ConceptName state2ConceptName = new ConceptName("Group 2", Context.getLocale());
    Concept state2Concept = new Concept();
    state2Concept.addName(state2ConceptName);
    ProgramWorkflowState state2 = new ProgramWorkflowState();
    state2.setConcept(state2Concept);
    program.addState(state2);
    Set<ProgramWorkflowState> sortedStates = program.getSortedStates();
    int x = 1;
    for (ProgramWorkflowState state : sortedStates) {
        if (x == 1) {
            Assert.assertEquals("Group 2", state.getConcept().getName(Context.getLocale()).getName());
        } else if (x == 2) {
            Assert.assertEquals("Group 10", state.getConcept().getName(Context.getLocale()).getName());
        } else {
            Assert.fail("Wha?!");
        }
        x++;
    }
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) Concept(org.openmrs.Concept) ProgramWorkflowState(org.openmrs.ProgramWorkflowState) ConceptName(org.openmrs.ConceptName) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ProgramWorkflow (org.openmrs.ProgramWorkflow)22 Test (org.junit.Test)16 PatientProgram (org.openmrs.PatientProgram)12 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)11 ProgramWorkflowState (org.openmrs.ProgramWorkflowState)9 Program (org.openmrs.Program)8 BindException (org.springframework.validation.BindException)6 Concept (org.openmrs.Concept)5 PatientState (org.openmrs.PatientState)5 ConceptStateConversion (org.openmrs.ConceptStateConversion)4 ProgramWorkflowService (org.openmrs.api.ProgramWorkflowService)4 Errors (org.springframework.validation.Errors)4 Date (java.util.Date)3 Patient (org.openmrs.Patient)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 ConceptName (org.openmrs.ConceptName)1 PatientIdentifier (org.openmrs.PatientIdentifier)1