use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramEditor method setAsText.
/**
* @should set using concept id
* @should set using concept uuid
* @should set using program id
* @should set using program uuid
*/
@Override
public void setAsText(String text) throws IllegalArgumentException {
if (StringUtils.hasText(text)) {
try {
if (text.startsWith("concept.")) {
Integer conceptId = Integer.valueOf(text.substring(text.indexOf('.') + 1));
Concept c = Context.getConceptService().getConcept(conceptId);
setValue(Context.getProgramWorkflowService().getProgramByName(c.getName().getName()));
} else {
Integer programId = Integer.valueOf(text);
setValue(Context.getProgramWorkflowService().getProgram(programId));
}
} catch (Exception ex) {
Program p;
if (text.startsWith("concept.")) {
Concept c = Context.getConceptService().getConceptByUuid(text.substring(text.indexOf('.') + 1));
p = Context.getProgramWorkflowService().getProgramByName(c.getName().getName());
} else {
p = Context.getProgramWorkflowService().getProgramByUuid(text);
}
setValue(p);
if (p == null) {
log.error("Error setting text: " + text, ex);
throw new IllegalArgumentException("Program not found: " + text, ex);
}
}
} else {
setValue(null);
}
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class WorkflowCollectionEditorTest method setAsText_shouldUpdateWorkflowsInProgram.
/**
* @see WorkflowCollectionEditor#setAsText(String)
*/
@Test
public void setAsText_shouldUpdateWorkflowsInProgram() {
Program program = Context.getProgramWorkflowService().getProgram(1);
WorkflowCollectionEditor editor = new WorkflowCollectionEditor();
Assert.assertEquals(2, program.getWorkflows().size());
editor.setAsText("1:3");
Assert.assertEquals(1, program.getWorkflows().size());
Assert.assertEquals(3, program.getWorkflows().iterator().next().getConcept().getConceptId().intValue());
Assert.assertEquals(3, program.getAllWorkflows().size());
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class HibernateProgramWorkflowDAO method getProgramsByName.
/**
* @see org.openmrs.api.db.ProgramWorkflowDAO#getProgramsByName(String, boolean)
*/
@Override
public List<Program> getProgramsByName(String programName, boolean includeRetired) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Program.class);
criteria.add(Restrictions.eq("name", programName));
if (!includeRetired) {
criteria.add(Restrictions.eq("retired", false));
}
@SuppressWarnings("unchecked") List<Program> list = criteria.list();
return list;
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramWorkflowServiceUnitTest method getProgramByName_shouldReturnNullWhenThereIsNoProgramForGivenName.
@Test
public void getProgramByName_shouldReturnNullWhenThereIsNoProgramForGivenName() {
ProgramWorkflowDAO mockDao = Mockito.mock(ProgramWorkflowDAO.class);
List<Program> noProgramWithGivenName = new ArrayList<>();
Mockito.stub(mockDao.getProgramsByName("A name", false)).toReturn(noProgramWithGivenName);
Mockito.stub(mockDao.getProgramsByName("A name", true)).toReturn(noProgramWithGivenName);
pws.setProgramWorkflowDAO(mockDao);
Assert.assertNull(pws.getProgramByName("A name"));
}
use of org.openmrs.Program in project openmrs-core by openmrs.
the class ProgramWorkflowServiceUnitTest method savePatientProgram_shouldFailForNullPatient.
@Test
public void savePatientProgram_shouldFailForNullPatient() {
exception.expect(APIException.class);
exception.expectMessage("PatientProgram requires a Patient and a Program");
PatientProgram patientProgram = new PatientProgram(1);
patientProgram.setProgram(new Program(1));
pws.savePatientProgram(patientProgram);
}
Aggregations