use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.
the class ProgramDataEntryServiceTest method setUpTest.
@Override
public void setUpTest() {
organisationUnit = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(organisationUnit);
DataEntryForm dataEntryFormA = new DataEntryForm("DataEntryForm-A");
dataEntryFormService.addDataEntryForm(dataEntryFormA);
Program program = createProgram('A', new HashSet<>(), organisationUnit);
programService.addProgram(program);
stageA = new ProgramStage("A", program);
program.getProgramStages().add(stageA);
stageA.setUid("StageA");
stageA.setSortOrder(1);
programStageService.saveProgramStage(stageA);
ProgramStage stageB = new ProgramStage("B", program);
program.getProgramStages().add(stageB);
stageB.setSortOrder(2);
programStageService.saveProgramStage(stageB);
Set<ProgramStage> programStages = new HashSet<>();
programStages.add(stageA);
programStages.add(stageB);
program.setProgramStages(programStages);
programService.updateProgram(program);
DataElement dataElementA = createDataElement('A');
dataElementA.setUid("DeA");
DataElement dataElementB = createDataElement('B');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
ProgramStageDataElement programStageDataElementA = new ProgramStageDataElement(stageA, dataElementA, false, 1);
stageA.getProgramStageDataElements().add(programStageDataElementA);
programStageDataElementService.addProgramStageDataElement(programStageDataElementA);
ProgramStageDataElement programStageDataElementB = new ProgramStageDataElement(stageA, dataElementB, false, 2);
stageA.getProgramStageDataElements().add(programStageDataElementB);
programStageDataElementService.addProgramStageDataElement(programStageDataElementB);
htmlCode = "<input id=\"StageA-DeA-val\" style=\"width:4em;text-align:center\" value=\"\" title=\"\" />";
}
use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.
the class ProgramStageStoreTest method testGetByDataEntryForm.
@Test
public void testGetByDataEntryForm() {
DataEntryForm formX = createDataEntryForm('X');
DataEntryForm formY = createDataEntryForm('Y');
dataEntryFormService.addDataEntryForm(formX);
dataEntryFormService.addDataEntryForm(formY);
stageA.setDataEntryForm(formX);
stageB.setDataEntryForm(formY);
programStageStore.save(stageA);
programStageStore.save(stageB);
programStageStore.save(stageC);
program.setProgramStages(Sets.newHashSet(stageA, stageB, stageC));
programService.updateProgram(program);
List<ProgramStage> hasFormX = programStageStore.getByDataEntryForm(formX);
assertEquals(1, hasFormX.size());
assertEquals(stageA, hasFormX.get(0));
}
use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.
the class LoadFormAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
dataSet = dataSetService.getDataSet(dataSetId);
if (dataSet == null) {
return INPUT;
}
FormType formType = dataSet.getFormType();
if (formType.isCustom() && dataSet.hasDataEntryForm()) {
dataEntryForm = dataSet.getDataEntryForm();
customDataEntryFormCode = dataEntryFormService.prepareDataEntryFormForEntry(dataEntryForm, dataSet, i18n);
return formType.toString();
}
// ---------------------------------------------------------------------
// Section / default form
// ---------------------------------------------------------------------
List<DataElement> dataElements = new ArrayList<>(dataSet.getDataElements());
if (dataElements.isEmpty()) {
return INPUT;
}
Collections.sort(dataElements);
orderedDataElements = ListMap.getListMap(dataElements, de -> de.getCategoryCombo(dataSet));
orderedCategoryCombos = getDataElementCategoryCombos(dataElements, dataSet);
for (DataElementCategoryCombo categoryCombo : orderedCategoryCombos) {
List<DataElementCategoryOptionCombo> optionCombos = categoryCombo.getSortedOptionCombos();
orderedCategoryOptionCombos.put(categoryCombo.getId(), optionCombos);
// -----------------------------------------------------------------
// Perform ordering of categories and their options so that they
// could be displayed as in the paper form. Note that the total
// number of entry cells to be generated are the multiple of options
// from each category.
// -----------------------------------------------------------------
numberOfTotalColumns.put(categoryCombo.getId(), optionCombos.size());
orderedCategories.put(categoryCombo.getId(), categoryCombo.getCategories());
Map<Integer, List<DataElementCategoryOption>> optionsMap = new HashMap<>();
for (DataElementCategory category : categoryCombo.getCategories()) {
optionsMap.put(category.getId(), category.getCategoryOptions());
}
orderedOptionsMap.put(categoryCombo.getId(), optionsMap);
// -----------------------------------------------------------------
// Calculating the number of times each category should be repeated
// -----------------------------------------------------------------
Map<Integer, Integer> catRepeat = new HashMap<>();
Map<Integer, Collection<Integer>> colRepeat = new HashMap<>();
int catColSpan = optionCombos.size();
for (DataElementCategory cat : categoryCombo.getCategories()) {
int categoryOptionSize = cat.getCategoryOptions().size();
if (categoryOptionSize > 0 && catColSpan >= categoryOptionSize) {
catColSpan = catColSpan / categoryOptionSize;
int total = optionCombos.size() / (catColSpan * categoryOptionSize);
Collection<Integer> cols = new ArrayList<>(total);
for (int i = 0; i < total; i++) {
cols.add(i);
}
colRepeat.put(cat.getId(), cols);
catRepeat.put(cat.getId(), catColSpan);
}
}
catColRepeat.put(categoryCombo.getId(), colRepeat);
}
// ---------------------------------------------------------------------
// Get data entry form
// ---------------------------------------------------------------------
DataSet dsOriginal = dataSet;
if (dataSet.getFormType().isDefault()) {
DataSet dataSetCopy = new DataSet();
dataSetCopy.setUid(dataSet.getUid());
dataSetCopy.setName(dataSet.getName());
dataSetCopy.setShortName(dataSet.getShortName());
dataSetCopy.setRenderAsTabs(dataSet.isRenderAsTabs());
dataSetCopy.setRenderHorizontally(dataSet.isRenderHorizontally());
dataSetCopy.setDataElementDecoration(dataSet.isDataElementDecoration());
dataSet = dataSetCopy;
for (int i = 0; i < orderedCategoryCombos.size(); i++) {
DataElementCategoryCombo categoryCombo = orderedCategoryCombos.get(i);
String name = !categoryCombo.isDefault() ? categoryCombo.getName() : dataSetCopy.getName();
Section section = new Section();
section.setUid(CodeGenerator.generateUid());
section.setId(i);
section.setName(name);
section.setSortOrder(i);
section.setDataSet(dataSetCopy);
dataSetCopy.getSections().add(section);
section.getDataElements().addAll(orderedDataElements.get(categoryCombo));
section.setIndicators(new ArrayList<>(dataSet.getIndicators()));
}
formType = FormType.SECTION;
}
if (CodeGenerator.isValidUid(multiOrganisationUnit)) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(multiOrganisationUnit);
List<OrganisationUnit> organisationUnitChildren = new ArrayList<>();
for (OrganisationUnit child : organisationUnit.getChildren()) {
if (child.getDataSets().contains(dsOriginal)) {
organisationUnitChildren.add(child);
}
}
Collections.sort(organisationUnitChildren);
organisationUnits.addAll(organisationUnitChildren);
getSectionForm(dataElements, dataSet);
formType = FormType.SECTION_MULTIORG;
}
getSectionForm(dataElements, dataSet);
return formType.toString();
}
use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.
the class ProgramDataEntryFormDeletionHandler method deleteProgramStage.
@Override
public void deleteProgramStage(ProgramStage programStage) {
DataEntryForm dataEntryForm = programStage.getDataEntryForm();
if (dataEntryForm != null) {
boolean flag = false;
Set<ProgramStage> programStages = programStage.getProgram().getProgramStages();
programStages.remove(programStage);
for (ProgramStage stage : programStages) {
if (stage.getDataEntryForm() != null) {
programStage.setDataEntryForm(null);
programStageService.updateProgramStage(programStage);
flag = true;
break;
}
}
if (!flag) {
dataEntryFormService.deleteDataEntryForm(dataEntryForm);
}
}
}
use of org.hisp.dhis.dataentryform.DataEntryForm in project dhis2-core by dhis2.
the class DataSetStoreTest method testGetByDataEntryForm.
@Test
public void testGetByDataEntryForm() {
DataEntryForm dataEntryFormX = createDataEntryForm('X');
DataEntryForm dataEntryFormY = createDataEntryForm('Y');
dataEntryFormService.addDataEntryForm(dataEntryFormX);
dataEntryFormService.addDataEntryForm(dataEntryFormY);
DataSet dataSetA = createDataSet('A', periodType);
DataSet dataSetB = createDataSet('B', periodType);
DataSet dataSetC = createDataSet('C', periodType);
dataSetA.setDataEntryForm(dataEntryFormX);
dataSetStore.save(dataSetA);
dataSetStore.save(dataSetB);
dataSetStore.save(dataSetC);
List<DataSet> dataSetsWithForm = dataSetStore.getDataSetsByDataEntryForm(dataEntryFormX);
assertEquals(1, dataSetsWithForm.size());
assertEquals(dataSetA, dataSetsWithForm.get(0));
dataSetC.setDataEntryForm(dataEntryFormX);
dataSetStore.update(dataSetC);
dataSetsWithForm = dataSetStore.getDataSetsByDataEntryForm(dataEntryFormX);
assertEquals(2, dataSetsWithForm.size());
assertTrue(dataSetsWithForm.contains(dataSetA));
assertTrue(dataSetsWithForm.contains(dataSetC));
dataSetB.setDataEntryForm(dataEntryFormY);
dataSetStore.update(dataSetB);
dataSetsWithForm = dataSetStore.getDataSetsByDataEntryForm(dataEntryFormY);
assertEquals(1, dataSetsWithForm.size());
assertTrue(dataSetsWithForm.contains(dataSetB));
}
Aggregations