Search in sources :

Example 16 with ProgramStageSection

use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.

the class DhisConvenienceTest method createProgramStageSection.

public static ProgramStageSection createProgramStageSection(char uniqueCharacter, Integer sortOrder) {
    ProgramStageSection section = new ProgramStageSection();
    section.setAutoFields();
    section.setName("ProgramStageSection" + uniqueCharacter);
    section.setSortOrder(sortOrder);
    return section;
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection)

Example 17 with ProgramStageSection

use of org.hisp.dhis.program.ProgramStageSection in project dhis2-core by dhis2.

the class FormUtils method fromProgram.

public static Form fromProgram(Program program) {
    Assert.notNull(program, "Program cannot be null");
    Form form = new Form();
    form.setLabel(program.getDisplayName());
    if (!StringUtils.isEmpty(program.getDescription())) {
        form.getOptions().put("description", program.getDescription());
    }
    if (!StringUtils.isEmpty(program.getEnrollmentDateLabel())) {
        form.getOptions().put("dateOfEnrollmentDescription", program.getEnrollmentDateLabel());
    }
    if (!StringUtils.isEmpty(program.getIncidentDateLabel())) {
        form.getOptions().put("dateOfIncidentDescription", program.getIncidentDateLabel());
    }
    form.getOptions().put("type", program.getProgramType().getValue());
    ProgramStage programStage = program.getProgramStageByStage(1);
    if (programStage == null) {
        if (program.isWithoutRegistration()) {
            throw new IllegalStateException("Program is without registration");
        } else {
            return form;
        }
    }
    form.getOptions().put("featureType", programStage.getFeatureType());
    if (programStage.getProgramStageSections().size() > 0) {
        for (ProgramStageSection section : programStage.getProgramStageSections()) {
            List<Field> fields = inputFromDataElements(section.getDataElements());
            Group group = new Group();
            group.setLabel(section.getDisplayName());
            group.setDataElementCount(section.getDataElements().size());
            group.setFields(fields);
            form.getGroups().add(group);
        }
    } else {
        List<Field> fields = inputFromProgramStageDataElements(new ArrayList<>(programStage.getProgramStageDataElements()));
        Group group = new Group();
        group.setLabel("default");
        group.setFields(fields);
        group.setDataElementCount(programStage.getProgramStageDataElements().size());
        form.getGroups().add(group);
    }
    return form;
}
Also used : ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) Field(org.hisp.dhis.webapi.webdomain.form.Field) Group(org.hisp.dhis.webapi.webdomain.form.Group) Form(org.hisp.dhis.webapi.webdomain.form.Form) ProgramStage(org.hisp.dhis.program.ProgramStage)

Aggregations

ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)17 ProgramStage (org.hisp.dhis.program.ProgramStage)7 DataElement (org.hisp.dhis.dataelement.DataElement)6 ArrayList (java.util.ArrayList)5 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)5 Program (org.hisp.dhis.program.Program)3 Test (org.junit.jupiter.api.Test)3 HashSet (java.util.HashSet)2 List (java.util.List)2 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)2 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)2 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)2 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)2 ProgramRule (org.hisp.dhis.programrule.ProgramRule)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 HashMap (java.util.HashMap)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 DataValue (org.hisp.dhis.api.mobile.model.DataValue)1 Program (org.hisp.dhis.api.mobile.model.Program)1 ProgramStage (org.hisp.dhis.api.mobile.model.ProgramStage)1