Search in sources :

Example 1 with Program

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);
    }
}
Also used : Concept(org.openmrs.Concept) Program(org.openmrs.Program)

Example 2 with Program

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());
}
Also used : Program(org.openmrs.Program) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 3 with Program

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;
}
Also used : PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) Criteria(org.hibernate.Criteria)

Example 4 with Program

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"));
}
Also used : PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) ArrayList(java.util.ArrayList) ProgramWorkflowDAO(org.openmrs.api.db.ProgramWorkflowDAO) Test(org.junit.Test)

Example 5 with Program

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);
}
Also used : PatientProgram(org.openmrs.PatientProgram) Program(org.openmrs.Program) PatientProgram(org.openmrs.PatientProgram) Test(org.junit.Test)

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