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