Search in sources :

Example 21 with Program

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

the class ProgramWorkflowServiceTest method getProgramByName_shouldReturnNullWhenNoProgramForGivenName.

@Test
public void getProgramByName_shouldReturnNullWhenNoProgramForGivenName() {
    Program p = pws.getProgramByName("unexisting program");
    assertNull(p);
}
Also used : PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 22 with Program

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

the class ProgramWorkflowServiceTest method saveProgram_shouldUpdateDetachedProgram.

/**
 * @see ProgramWorkflowService#saveProgram(Program)
 */
@Test
public void saveProgram_shouldUpdateDetachedProgram() {
    Program program = Context.getProgramWorkflowService().getProgramByUuid("eae98b4c-e195-403b-b34a-82d94103b2c0");
    program.setDescription("new description");
    Context.evictFromSession(program);
    program = Context.getProgramWorkflowService().saveProgram(program);
    Assert.assertEquals("new description", program.getDescription());
}
Also used : PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 23 with Program

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

the class ProgramWorkflowServiceTest method getProgramByUuid_shouldFindObjectGivenValidUuid.

/**
 * @see ProgramWorkflowService#getProgramByUuid(String)
 */
@Test
public void getProgramByUuid_shouldFindObjectGivenValidUuid() {
    String uuid = "eae98b4c-e195-403b-b34a-82d94103b2c0";
    Program program = Context.getProgramWorkflowService().getProgramByUuid(uuid);
    Assert.assertEquals(1, (int) program.getProgramId());
}
Also used : PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 24 with Program

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

the class ProgramWorkflowServiceTest method purgeProgram_shouldPurgeProgramWithPatientsEnrolled.

@Test
public void purgeProgram_shouldPurgeProgramWithPatientsEnrolled() {
    Program program = Context.getProgramWorkflowService().getProgram(2);
    // program has at least one patient enrolled
    List<PatientProgram> patientPrograms = Context.getProgramWorkflowService().getPatientPrograms(null, program, null, null, null, null, true);
    assertTrue(patientPrograms.size() > 0);
    Context.getProgramWorkflowService().purgeProgram(program);
    // should cascade to patient programs
    for (PatientProgram patientProgram : patientPrograms) {
        assertNull(Context.getProgramWorkflowService().getPatientProgram(patientProgram.getId()));
    }
    // make sure that the program was deleted properly
    assertNull(Context.getProgramWorkflowService().getProgram(2));
}
Also used : PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) PatientProgram(org.openmrs.PatientProgram) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 25 with Program

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

the class ProgramWorkflowServiceTest method saveProgram_shouldCreateProgramWorkflows.

/**
 * Tests creating a new program containing workflows and states
 *
 * @see ProgramWorkflowService#saveProgram(Program)
 */
@Test
public void saveProgram_shouldCreateProgramWorkflows() {
    int numBefore = Context.getProgramWorkflowService().getAllPrograms().size();
    Program program = new Program();
    program.setName("TEST PROGRAM");
    program.setDescription("TEST PROGRAM DESCRIPTION");
    program.setConcept(cs.getConcept(3));
    ProgramWorkflow workflow = new ProgramWorkflow();
    workflow.setConcept(cs.getConcept(4));
    program.addWorkflow(workflow);
    ProgramWorkflowState state1 = new ProgramWorkflowState();
    state1.setConcept(cs.getConcept(5));
    state1.setInitial(true);
    state1.setTerminal(false);
    workflow.addState(state1);
    ProgramWorkflowState state2 = new ProgramWorkflowState();
    state2.setConcept(cs.getConcept(6));
    state2.setInitial(false);
    state2.setTerminal(true);
    workflow.addState(state2);
    Context.getProgramWorkflowService().saveProgram(program);
    assertEquals("Failed to create program", numBefore + 1, Context.getProgramWorkflowService().getAllPrograms().size());
    Program p = Context.getProgramWorkflowService().getProgramByName("TEST PROGRAM");
    assertNotNull("Program is null", p);
    assertNotNull("Workflows is null", p.getWorkflows());
    assertEquals("Wrong number of workflows", 1, p.getWorkflows().size());
    ProgramWorkflow wf = p.getWorkflowByName("CIVIL STATUS");
    assertNotNull(wf);
    List<String> names = new ArrayList<>();
    for (ProgramWorkflowState s : wf.getStates()) {
        names.add(s.getConcept().getName().getName());
    }
    TestUtil.assertCollectionContentsEquals(Arrays.asList("SINGLE", "MARRIED"), names);
}
Also used : ProgramWorkflow(org.openmrs.ProgramWorkflow) PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) ProgramWorkflowState(org.openmrs.ProgramWorkflowState) ArrayList(java.util.ArrayList) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

Program (org.openmrs.Program)43 Test (org.junit.Test)35 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)26 PatientProgram (org.openmrs.PatientProgram)22 ProgramWorkflow (org.openmrs.ProgramWorkflow)8 BindException (org.springframework.validation.BindException)8 Errors (org.springframework.validation.Errors)8 Concept (org.openmrs.Concept)7 ArrayList (java.util.ArrayList)6 ProgramWorkflowState (org.openmrs.ProgramWorkflowState)6 Date (java.util.Date)4 Patient (org.openmrs.Patient)4 ProgramWorkflowDAO (org.openmrs.api.db.ProgramWorkflowDAO)2 MissingPropertyException (groovy.lang.MissingPropertyException)1 HashMap (java.util.HashMap)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1 Criteria (org.hibernate.Criteria)1 DateTime (org.joda.time.DateTime)1 Ignore (org.junit.Ignore)1