use of org.hisp.dhis.webapi.webdomain.form.Field in project dhis2-core by dhis2.
the class FormUtils method fromDataSet.
public static Form fromDataSet(DataSet dataSet, boolean metaData, Set<OrganisationUnit> userOrganisationUnits) {
Form form = new Form();
form.setLabel(dataSet.getDisplayName());
form.setSubtitle(dataSet.getDisplayShortName());
form.getOptions().put(KEY_PERIOD_TYPE, dataSet.getPeriodType().getName());
form.getOptions().put(KEY_OPEN_FUTURE_PERIODS, dataSet.getOpenFuturePeriods());
form.getOptions().put(KEY_EXPIRY_DAYS, dataSet.getExpiryDays());
form.setCategoryCombo(getCategoryCombo(dataSet, userOrganisationUnits));
if (dataSet.hasSections()) {
List<Section> sections = new ArrayList<>(dataSet.getSections());
Collections.sort(sections, SectionOrderComparator.INSTANCE);
for (Section section : sections) {
List<Field> fields = inputFromDataElements(new ArrayList<>(section.getDataElements()), new ArrayList<>(section.getGreyedFields()));
Group group = new Group();
group.setLabel(section.getDisplayName());
group.setDescription(section.getDescription());
group.setDataElementCount(section.getDataElements().size());
group.setFields(fields);
if (metaData) {
group.getMetaData().put(KEY_DATA_ELEMENTS, NameableObjectUtils.getAsNameableObjects(section.getDataElements()));
group.getMetaData().put(KEY_INDICATORS, NameableObjectUtils.getAsNameableObjects(section.getIndicators()));
}
form.getGroups().add(group);
}
} else {
List<Field> fields = inputFromDataElements(new ArrayList<>(dataSet.getDataElements()));
Group group = new Group();
group.setLabel(DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
group.setDescription(DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
group.setDataElementCount(dataSet.getDataElements().size());
group.setFields(fields);
if (metaData) {
group.getMetaData().put(KEY_DATA_ELEMENTS, NameableObjectUtils.getAsNameableObjects(new ArrayList<>(dataSet.getDataElements())));
}
form.getGroups().add(group);
}
return form;
}
use of org.hisp.dhis.webapi.webdomain.form.Field in project dhis2-core by dhis2.
the class FormUtils method inputFromDataElements.
private static List<Field> inputFromDataElements(List<DataElement> dataElements, final List<DataElementOperand> greyedFields) {
List<Field> fields = new ArrayList<>();
for (DataElement dataElement : dataElements) {
for (DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getSortedCategoryOptionCombos()) {
if (!isDisabled(dataElement, categoryOptionCombo, greyedFields)) {
Field field = new Field();
if (categoryOptionCombo.isDefault()) {
field.setLabel(dataElement.getDisplayFormName());
} else {
field.setLabel(dataElement.getDisplayFormName() + " " + categoryOptionCombo.getDisplayName());
}
field.setDataElement(dataElement.getUid());
field.setCategoryOptionCombo(categoryOptionCombo.getUid());
field.setType(inputTypeFromDataElement(dataElement));
if (dataElement.getOptionSet() != null) {
field.setOptionSet(dataElement.getOptionSet().getUid());
}
fields.add(field);
}
}
}
return fields;
}
use of org.hisp.dhis.webapi.webdomain.form.Field 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("captureCoordinates", programStage.getCaptureCoordinates());
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;
}
use of org.hisp.dhis.webapi.webdomain.form.Field in project dhis2-core by dhis2.
the class FormUtils method fillWithDataValues.
public static void fillWithDataValues(Form form, Collection<DataValue> dataValues) {
Map<String, Field> operandFieldMap = buildCacheMap(form);
for (DataValue dataValue : dataValues) {
DataElement dataElement = dataValue.getDataElement();
DataElementCategoryOptionCombo categoryOptionCombo = dataValue.getCategoryOptionCombo();
Field field = operandFieldMap.get(dataElement.getUid() + SEP + categoryOptionCombo.getUid());
if (field != null) {
field.setValue(dataValue.getValue());
field.setComment(dataValue.getComment());
}
}
}
Aggregations