use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class AbstractEventService method getEventsGrid.
@Transactional(readOnly = true)
@Override
public Grid getEventsGrid(EventSearchParams params) {
User user = currentUserService.getCurrentUser();
if (params.getProgramStage() == null || params.getProgramStage().getProgram() == null) {
throw new IllegalQueryException("Program stage can not be null");
}
if (params.getProgramStage().getProgramStageDataElements() == null) {
throw new IllegalQueryException("Program stage should have at least one data element");
}
List<OrganisationUnit> organisationUnits = getOrganisationUnits(params, user);
params.handleCurrentUserSelectionMode(user);
if (params.isIncludeAllDataElements()) {
for (ProgramStageDataElement pde : params.getProgramStage().getProgramStageDataElements()) {
QueryItem qi = new QueryItem(pde.getDataElement(), pde.getDataElement().getLegendSet(), pde.getDataElement().getValueType(), pde.getDataElement().getAggregationType(), pde.getDataElement().hasOptionSet() ? pde.getDataElement().getOptionSet() : null);
params.getDataElements().add(qi);
}
} else {
if (params.getDataElements().isEmpty()) {
for (ProgramStageDataElement pde : params.getProgramStage().getProgramStageDataElements()) {
if (pde.getDisplayInReports()) {
QueryItem qi = new QueryItem(pde.getDataElement(), pde.getDataElement().getLegendSet(), pde.getDataElement().getValueType(), pde.getDataElement().getAggregationType(), pde.getDataElement().hasOptionSet() ? pde.getDataElement().getOptionSet() : null);
params.getDataElements().add(qi);
}
}
}
}
// ---------------------------------------------------------------------
// Grid headers
// ---------------------------------------------------------------------
Grid grid = new ListGrid();
for (String col : STATIC_EVENT_COLUMNS) {
grid.addHeader(new GridHeader(col, col));
}
for (QueryItem item : params.getDataElements()) {
grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getName()));
}
List<Map<String, String>> events = eventStore.getEventsGrid(params, organisationUnits);
for (Map<String, String> event : events) {
grid.addRow();
for (String col : STATIC_EVENT_COLUMNS) {
grid.addValue(event.get(col));
}
for (QueryItem item : params.getDataElements()) {
grid.addValue(event.get(item.getItemId()));
}
}
Map<String, Object> metaData = new HashMap<>();
if (params.isPaging()) {
final Pager pager;
if (params.isTotalPages()) {
int count = eventStore.getEventCount(params, organisationUnits);
pager = new Pager(params.getPageWithDefault(), count, params.getPageSizeWithDefault());
} else {
pager = handleLastPageFlag(params, grid);
}
metaData.put(PAGER_META_KEY, pager);
}
grid.setMetaData(metaData);
return grid;
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class DataValueCheck method validateMandatoryAttributes.
public void validateMandatoryAttributes(ImportConflicts importConflicts, WorkContext ctx, ImmutableEvent event) {
if (StringUtils.isEmpty(event.getProgramStage()))
return;
final IdScheme programStageIdScheme = ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme();
final IdScheme dataElementIdScheme = ctx.getImportOptions().getIdSchemes().getDataElementIdScheme();
final Map<String, Set<EventDataValue>> eventDataValueMap = ctx.getEventDataValueMap();
final boolean allowSingleUpdates = ctx.getImportOptions().isMergeDataValues();
ProgramStage programStage = ctx.getProgramStage(programStageIdScheme, event.getProgramStage());
final Set<ProgramStageDataElement> mandatoryDataElements = getMandatoryProgramStageDataElements(programStage);
// Data Element IDs associated to the current event
Set<String> dataValues = eventDataValueMap.get(event.getUid()).stream().map(EventDataValue::getDataElement).collect(Collectors.toSet());
if (allowSingleUpdates) {
final ProgramStageInstance programStageInstance = ctx.getProgramStageInstanceMap().get(event.getUid());
dataValues.addAll(programStageInstance.getEventDataValues().stream().filter(dv -> !StringUtils.isEmpty(dv.getValue().trim())).map(EventDataValue::getDataElement).collect(Collectors.toSet()));
}
for (ProgramStageDataElement mandatoryDataElement : mandatoryDataElements) {
String resolvedDataElementId = getIdentifierBasedOnIdScheme(mandatoryDataElement.getDataElement(), dataElementIdScheme);
if (!dataValues.contains(resolvedDataElementId)) {
importConflicts.addConflict(resolvedDataElementId, "value_required_but_not_provided");
}
}
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class ProgramSupplier method aggregateProgramAndAclData.
private void aggregateProgramAndAclData(Map<String, Program> programMap, Map<Long, DataElementSets> dataElementSetsMap) {
for (Program program : programMap.values()) {
for (ProgramStage programStage : program.getProgramStages()) {
DataElementSets dataElementSets = dataElementSetsMap.get(programStage.getId());
if (dataElementSets != null) {
Stream<ProgramStageDataElement> compulsoryProgramStageDataElementsStream = getOrEmpty(dataElementSets.getCompulsoryDataElements()).map(de -> new ProgramStageDataElement(programStage, de, true));
Stream<ProgramStageDataElement> nonCompulsoryProgramStageDataElementsStream = getOrEmpty(dataElementSets.getNonCompulsoryDataElements()).map(de -> new ProgramStageDataElement(programStage, de, false));
Set<ProgramStageDataElement> allProgramStageDataElements = Stream.concat(compulsoryProgramStageDataElementsStream, nonCompulsoryProgramStageDataElementsStream).collect(Collectors.toSet());
programStage.setProgramStageDataElements(allProgramStageDataElements);
}
}
}
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class ProgramStageDataElementObjectBundleHook method validate.
/**
* Validate that the RenderType (if any) conforms to the constraints of
* ValueType or OptionSet.
*/
@Override
public void validate(ProgramStageDataElement psda, ObjectBundle bundle, Consumer<ErrorReport> addReports) {
DeviceRenderTypeMap<ValueTypeRenderingObject> map = psda.getRenderType();
if (map == null) {
return;
}
DataElement de = psda.getDataElement();
for (ValueTypeRenderingObject renderingObject : map.values()) {
if (renderingObject.getType() == null) {
addReports.accept(new ErrorReport(ProgramStageDataElement.class, ErrorCode.E4011, "renderType.type"));
}
if (!ValidationUtils.validateRenderingType(ProgramStageDataElement.class, de.getValueType(), de.hasOptionSet(), renderingObject.getType())) {
addReports.accept(new ErrorReport(ProgramStageDataElement.class, ErrorCode.E4017, renderingObject.getType(), de.getValueType()));
}
}
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class EventImportTest method setUpTest.
@Override
protected void setUpTest() throws Exception {
userService = _userService;
organisationUnitA = createOrganisationUnit('A');
organisationUnitB = createOrganisationUnit('B');
manager.save(organisationUnitA);
manager.save(organisationUnitB);
TrackedEntityType trackedEntityType = createTrackedEntityType('A');
trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
org.hisp.dhis.trackedentity.TrackedEntityInstance maleA = createTrackedEntityInstance(organisationUnitA);
maleA.setTrackedEntityType(trackedEntityType);
manager.save(maleA);
trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
CategoryOption categoryOption1 = new CategoryOption("male");
categoryOption1.setAutoFields();
CategoryOption categoryOption2 = new CategoryOption("female");
categoryOption2.setAutoFields();
manager.save(Lists.newArrayList(categoryOption1, categoryOption2));
Category cat1 = new Category("cat1", DataDimensionType.DISAGGREGATION);
cat1.setShortName(cat1.getName());
cat1.setCategoryOptions(Lists.newArrayList(categoryOption1, categoryOption2));
manager.save(Lists.newArrayList(cat1));
CategoryCombo categoryCombo = manager.getByName(CategoryCombo.class, "default");
categoryCombo.setCategories(Lists.newArrayList(cat1));
dataElementA = createDataElement('A');
dataElementA.setValueType(ValueType.INTEGER);
dataElementA.setCategoryCombo(categoryCombo);
manager.save(dataElementA);
dataElementA2 = createDataElement('a');
dataElementA2.setValueType(ValueType.INTEGER);
dataElementA2.setCategoryCombo(categoryCombo);
manager.save(dataElementA2);
dataElementB = createDataElement('B');
dataElementB.setValueType(ValueType.INTEGER);
dataElementB.setCategoryCombo(categoryCombo);
manager.save(dataElementB);
programStageA = createProgramStage('A', 0);
programStageA.setFeatureType(FeatureType.POINT);
manager.save(programStageA);
programStageA2 = createProgramStage('a', 0);
programStageA2.setFeatureType(FeatureType.POINT);
programStageA2.setRepeatable(true);
manager.save(programStageA2);
programStageB = createProgramStage('B', 0);
programStageB.setFeatureType(FeatureType.POINT);
manager.save(programStageB);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setProgramType(ProgramType.WITH_REGISTRATION);
programA.setCategoryCombo(categoryCombo);
manager.save(programA);
programB = createProgram('B', new HashSet<>(), organisationUnitB);
programB.setProgramType(ProgramType.WITHOUT_REGISTRATION);
programB.setCategoryCombo(categoryCombo);
manager.save(programB);
ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
programStageDataElement.setDataElement(dataElementA);
programStageDataElement.setProgramStage(programStageA);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
ProgramStageDataElement programStageDataElementA2 = new ProgramStageDataElement();
programStageDataElementA2.setDataElement(dataElementA2);
programStageDataElementA2.setProgramStage(programStageA2);
programStageDataElementService.addProgramStageDataElement(programStageDataElementA2);
ProgramStageDataElement programStageDataElementB = new ProgramStageDataElement();
programStageDataElementB.setDataElement(dataElementB);
programStageDataElementB.setProgramStage(programStageB);
programStageDataElementService.addProgramStageDataElement(programStageDataElementB);
programStageA.getProgramStageDataElements().add(programStageDataElement);
programStageA2.getProgramStageDataElements().add(programStageDataElementA2);
programStageA.setProgram(programA);
programStageA2.setProgram(programA);
programA.getProgramStages().add(programStageA);
programA.getProgramStages().add(programStageA2);
programStageB.getProgramStageDataElements().add(programStageDataElementB);
programStageB.setProgram(programB);
programB.getProgramStages().add(programStageB);
manager.update(programStageA);
manager.update(programStageA2);
manager.update(programA);
manager.update(programStageB);
manager.update(programB);
pi = new ProgramInstance();
pi.setEnrollmentDate(new Date());
pi.setIncidentDate(new Date());
pi.setProgram(programB);
pi.setStatus(ProgramStatus.ACTIVE);
pi.setStoredBy("test");
pi.setName("EventImportTestPI");
pi.setUid(CodeGenerator.generateUid());
manager.save(pi);
event = createEvent("eventUid001");
createUserAndInjectSecurityContext(true);
// Flush all data to disk
manager.flush();
}
Aggregations