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);
}
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());
}
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());
}
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));
}
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);
}
Aggregations