use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class DataElementControllerDocumentation method testCreateValidation.
@Test
public void testCreateValidation() throws Exception {
MockHttpSession session = getSession("F_DATAELEMENT_PUBLIC_ADD");
DataElement de = createDataElement('A');
de.setName(null);
mvc.perform(post("/dataElements").session(session).contentType(TestUtils.APPLICATION_JSON_UTF8).content(TestUtils.convertObjectToJsonBytes(de)));
de = manager.getByName(DataElement.class, "DataElementA");
assertNull(de);
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class DataElementControllerDocumentation method testAddDeleteCollectionItem.
@Test
public void testAddDeleteCollectionItem() throws Exception {
MockHttpSession session = getSession("ALL");
DataElement de = createDataElement('A');
manager.save(de);
Schema schema = schemaService.getSchema(DataElement.class);
List<Property> properties = schema.getProperties();
for (Property property : properties) {
if (property.isCollection()) {
String collectionName = property.getCollectionName();
IdentifiableObject item = createTestObject(property.getItemKlass(), 'A');
if (item == null) {
continue;
} else {
manager.save(item);
}
mvc.perform(post("/dataElements/" + de.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint("data-elements/add" + collectionName)).andExpect(status().isNoContent());
mvc.perform(delete("/dataElements/" + de.getUid() + "/" + collectionName + "/" + item.getUid()).session(session).contentType(TestUtils.APPLICATION_JSON_UTF8)).andDo(documentPrettyPrint("data-elements/delete" + collectionName)).andExpect(status().isNoContent());
}
}
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class AddProgramStageAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
minDaysFromStart = (minDaysFromStart == null) ? 0 : minDaysFromStart;
repeatable = (repeatable == null) ? false : repeatable;
autoGenerateEvent = (autoGenerateEvent == null) ? false : autoGenerateEvent;
validCompleteOnly = (validCompleteOnly == null) ? false : validCompleteOnly;
displayGenerateEventBox = (displayGenerateEventBox == null) ? false : displayGenerateEventBox;
captureCoordinates = (captureCoordinates == null) ? false : captureCoordinates;
relatedEntityInstance = (relatedEntityInstance == null) ? false : relatedEntityInstance;
generatedByEnrollmentDate = (generatedByEnrollmentDate == null) ? false : generatedByEnrollmentDate;
blockEntryForm = (blockEntryForm == null) ? false : blockEntryForm;
remindCompleted = (remindCompleted == null) ? false : remindCompleted;
allowGenerateNextVisit = (allowGenerateNextVisit == null) ? false : allowGenerateNextVisit;
openAfterEnrollment = (openAfterEnrollment == null) ? false : openAfterEnrollment;
preGenerateUID = (preGenerateUID == null) ? false : preGenerateUID;
hideDueDate = (hideDueDate == null) ? false : hideDueDate;
ProgramStage programStage = new ProgramStage();
Program program = programService.getProgram(id);
programStage.setName(StringUtils.trimToNull(name));
programStage.setDescription(StringUtils.trimToNull(description));
programStage.setProgram(program);
programStage.setStandardInterval(standardInterval);
programStage.setExecutionDateLabel(StringUtils.trimToNull(excecutionDateLabel));
programStage.setRepeatable(repeatable);
programStage.setMinDaysFromStart(minDaysFromStart);
programStage.setDisplayGenerateEventBox(displayGenerateEventBox);
programStage.setValidCompleteOnly(validCompleteOnly);
if (!hideDueDate) {
programStage.setDueDateLabel(StringUtils.trimToNull(dueDateLabel));
}
periodTypeName = StringUtils.trimToNull(periodTypeName);
if (periodTypeName != null) {
PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
programStage.setPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
} else {
programStage.setPeriodType(null);
}
if (program.isWithoutRegistration()) {
programStage.setAutoGenerateEvent(true);
} else {
programStage.setAutoGenerateEvent(autoGenerateEvent);
}
programStage.setCaptureCoordinates(captureCoordinates);
programStage.setBlockEntryForm(blockEntryForm);
programStage.setRemindCompleted(remindCompleted);
programStage.setGeneratedByEnrollmentDate(generatedByEnrollmentDate);
programStage.setAllowGenerateNextVisit(allowGenerateNextVisit);
programStage.setOpenAfterEnrollment(openAfterEnrollment);
programStage.setReportDateToUse(reportDateToUse);
programStage.setPreGenerateUID(preGenerateUID);
programStage.setSortOrder(program.getProgramStages().size() + 1);
programStage.setHideDueDate(hideDueDate);
program.getProgramStages().add(programStage);
if (jsonAttributeValues != null) {
attributeService.updateAttributeValues(programStage, jsonAttributeValues);
}
programStageService.saveProgramStage(programStage);
for (int i = 0; i < this.selectedDataElementsValidator.size(); i++) {
DataElement dataElement = dataElementService.getDataElement(selectedDataElementsValidator.get(i));
Boolean allowed = allowProvidedElsewhere.get(i) == null ? false : allowProvidedElsewhere.get(i);
Boolean displayInReport = displayInReports.get(i) == null ? false : displayInReports.get(i);
Boolean allowDate = allowFutureDates.get(i) == null ? false : allowFutureDates.get(i);
ProgramStageDataElement programStageDataElement = new ProgramStageDataElement(programStage, dataElement, this.compulsories.get(i), new Integer(i));
programStageDataElement.setAllowProvidedElsewhere(allowed);
programStageDataElement.setDisplayInReports(displayInReport);
programStageDataElement.setAllowFutureDate(allowDate);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
}
return SUCCESS;
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class DimensionalObjectUtilsTest method testGetUidMapIsSchemeCodeCompositeObject.
@Test
public void testGetUidMapIsSchemeCodeCompositeObject() {
Program prA = new Program();
prA.setUid("P123456789A");
prA.setCode("PCodeA");
DataElement deA = new DataElement("NameA");
DataElement deB = new DataElement("NameB");
deA.setUid("D123456789A");
deB.setUid("D123456789B");
deA.setCode("DCodeA");
deB.setCode("DCodeB");
ProgramDataElementDimensionItem pdeA = new ProgramDataElementDimensionItem(prA, deA);
ProgramDataElementDimensionItem pdeB = new ProgramDataElementDimensionItem(prA, deB);
List<ProgramDataElementDimensionItem> elements = Lists.newArrayList(pdeA, pdeB);
Map<String, String> map = DimensionalObjectUtils.getDimensionItemIdSchemeMap(elements, IdScheme.CODE);
assertEquals(2, map.size());
assertEquals("PCodeA.DCodeA", map.get("P123456789A.D123456789A"));
assertEquals("PCodeA.DCodeB", map.get("P123456789A.D123456789B"));
}
use of org.hisp.dhis.dataelement.DataElement in project dhis2-core by dhis2.
the class DimensionalObjectUtilsTest method testReplaceOperandTotalsWithDataElements.
@Test
public void testReplaceOperandTotalsWithDataElements() {
DataElement deA = new DataElement("NameA");
DataElement deB = new DataElement("NameB");
deA.setAutoFields();
deB.setAutoFields();
DataElementCategoryOptionCombo cocA = new DataElementCategoryOptionCombo();
cocA.setAutoFields();
DataElementOperand opA = new DataElementOperand(deA);
DataElementOperand opB = new DataElementOperand(deA, cocA);
DataElementOperand opC = new DataElementOperand(deB, cocA);
List<DimensionalItemObject> items = Lists.newArrayList(deB, opA, opB, opC);
assertEquals(4, items.size());
assertTrue(items.contains(deB));
assertTrue(items.contains(opA));
assertTrue(items.contains(opB));
assertTrue(items.contains(opC));
assertFalse(items.contains(deA));
items = DimensionalObjectUtils.replaceOperandTotalsWithDataElements(items);
assertEquals(4, items.size());
assertTrue(items.contains(deB));
assertFalse(items.contains(opA));
assertTrue(items.contains(opB));
assertTrue(items.contains(opC));
assertTrue(items.contains(deA));
}
Aggregations