use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class ObjectBundleServiceProgramTest method testCreateSimpleProgramNoReg.
@Test
void testCreateSimpleProgramNoReg() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_noreg.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
validate.forEachErrorReport(System.out::println);
assertFalse(validate.hasErrorReports());
objectBundleService.commit(bundle);
List<DataSet> dataSets = manager.getAll(DataSet.class);
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
List<User> users = manager.getAll(User.class);
List<ValidationRule> validationRules = manager.getAll(ValidationRule.class);
List<Program> programs = manager.getAll(Program.class);
List<ProgramStage> programStages = manager.getAll(ProgramStage.class);
List<ProgramStageDataElement> programStageDataElements = manager.getAll(ProgramStageDataElement.class);
assertFalse(dataSets.isEmpty());
assertFalse(organisationUnits.isEmpty());
assertFalse(dataElements.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(1, validationRules.size());
assertEquals(1, programs.size());
assertEquals(1, programStages.size());
assertEquals(3, programStageDataElements.size());
ProgramStage programStage = programStages.get(0);
assertEquals(3, programStage.getProgramStageDataElements().size());
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class TrackerAccessManagerTest method setUpTest.
@Override
protected void setUpTest() {
userService = _userService;
organisationUnitA = createOrganisationUnit('A');
organisationUnitB = createOrganisationUnit('B');
manager.save(organisationUnitA);
manager.save(organisationUnitB);
dataElementA = createDataElement('A');
dataElementB = createDataElement('B');
dataElementA.setValueType(ValueType.INTEGER);
dataElementB.setValueType(ValueType.INTEGER);
manager.save(dataElementA);
manager.save(dataElementB);
programStageA = createProgramStage('A', 0);
programStageB = createProgramStage('B', 0);
programStageB.setRepeatable(true);
manager.save(programStageA);
manager.save(programStageB);
programA = createProgram('A', new HashSet<>(), organisationUnitA);
programA.setProgramType(ProgramType.WITH_REGISTRATION);
programA.setAccessLevel(AccessLevel.PROTECTED);
programA.setPublicAccess(AccessStringHelper.FULL);
programA.addOrganisationUnit(organisationUnitB);
manager.save(programA);
ProgramStageDataElement programStageDataElement = new ProgramStageDataElement();
programStageDataElement.setDataElement(dataElementA);
programStageDataElement.setProgramStage(programStageA);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
programStageA.getProgramStageDataElements().add(programStageDataElement);
programStageA.setProgram(programA);
programStageDataElement = new ProgramStageDataElement();
programStageDataElement.setDataElement(dataElementB);
programStageDataElement.setProgramStage(programStageB);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
programStageB.getProgramStageDataElements().add(programStageDataElement);
programStageB.setProgram(programA);
programStageB.setMinDaysFromStart(2);
programA.getProgramStages().add(programStageA);
programA.getProgramStages().add(programStageB);
manager.update(programStageA);
manager.update(programStageB);
manager.update(programA);
trackedEntityType = createTrackedEntityType('A');
trackedEntityType.setPublicAccess(AccessStringHelper.FULL);
trackedEntityTypeService.addTrackedEntityType(trackedEntityType);
maleA = createTrackedEntityInstance(organisationUnitA);
maleB = createTrackedEntityInstance(organisationUnitB);
femaleA = createTrackedEntityInstance(organisationUnitA);
femaleB = createTrackedEntityInstance(organisationUnitB);
maleA.setTrackedEntityType(trackedEntityType);
maleB.setTrackedEntityType(trackedEntityType);
femaleA.setTrackedEntityType(trackedEntityType);
femaleB.setTrackedEntityType(trackedEntityType);
manager.save(maleA);
manager.save(maleB);
manager.save(femaleA);
manager.save(femaleB);
enrollmentService.addEnrollment(createEnrollment(programA.getUid(), maleA.getUid()), ImportOptions.getDefaultImportOptions());
// this is required because the event import takes place through JDBC
// and
// hibernate does not see
// the values inserted by the JDBC session. Clearing the session, forces
// hibernate to reload from db rather than
// using the session
sessionFactory.getCurrentSession().clear();
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class EventDataValuesValidationHook method validateMandatoryDataValues.
private void validateMandatoryDataValues(Event event, TrackerImportValidationContext context, ValidationErrorReporter reporter) {
if (StringUtils.isNotEmpty(event.getProgramStage())) {
ProgramStage programStage = context.getProgramStage(event.getProgramStage());
final List<String> mandatoryDataElements = programStage.getProgramStageDataElements().stream().filter(ProgramStageDataElement::isCompulsory).map(de -> context.getIdentifiers().getDataElementIdScheme().getIdentifier(de.getDataElement())).collect(Collectors.toList());
List<String> missingDataValue = validateMandatoryDataValue(programStage, event, mandatoryDataElements);
missingDataValue.forEach(de -> reporter.addError(event, E1303, de));
}
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class UpdateProgramStageAction 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 = programStageService.getProgramStage(id);
programStage.setName(StringUtils.trimToNull(name));
programStage.setDescription(StringUtils.trimToNull(description));
programStage.setStandardInterval(standardInterval);
programStage.setExecutionDateLabel(StringUtils.trimToNull(excecutionDateLabel));
programStage.setMinDaysFromStart(minDaysFromStart);
programStage.setRepeatable(repeatable);
programStage.setMinDaysFromStart(minDaysFromStart);
programStage.setDisplayGenerateEventBox(displayGenerateEventBox);
programStage.setBlockEntryForm(blockEntryForm);
programStage.setRemindCompleted(remindCompleted);
programStage.setGeneratedByEnrollmentDate(generatedByEnrollmentDate);
programStage.setAllowGenerateNextVisit(allowGenerateNextVisit);
programStage.setOpenAfterEnrollment(openAfterEnrollment);
programStage.setReportDateToUse(reportDateToUse);
programStage.setPreGenerateUID(preGenerateUID);
programStage.setHideDueDate(hideDueDate);
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 (programStage.getProgram().isWithoutRegistration()) {
programStage.setAutoGenerateEvent(true);
} else {
programStage.setAutoGenerateEvent(autoGenerateEvent);
}
programStage.setValidCompleteOnly(validCompleteOnly);
programStage.setCaptureCoordinates(captureCoordinates);
if (jsonAttributeValues != null) {
attributeService.updateAttributeValues(programStage, jsonAttributeValues);
}
Set<ProgramStageDataElement> programStageDataElements = new HashSet<>(programStage.getProgramStageDataElements());
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);
Boolean renderAsRadio = renderOptionsAsRadios.get(i) == null ? false : renderOptionsAsRadios.get(i);
ProgramStageDataElement programStageDataElement = programStageDataElementService.get(programStage, dataElement);
if (programStageDataElement == null) {
programStageDataElement = new ProgramStageDataElement(programStage, dataElement, this.compulsories.get(i), i);
programStageDataElement.setAllowProvidedElsewhere(allowed);
programStageDataElement.setDisplayInReports(displayInReport);
programStageDataElement.setAllowFutureDate(allowDate);
programStageDataElementService.addProgramStageDataElement(programStageDataElement);
programStageDataElement.setRenderOptionsAsRadio(renderAsRadio);
} else {
programStageDataElement.setCompulsory(this.compulsories.get(i));
programStageDataElement.setSortOrder(i);
programStageDataElement.setAllowProvidedElsewhere(allowed);
programStageDataElement.setDisplayInReports(displayInReport);
programStageDataElement.setAllowFutureDate(allowDate);
programStageDataElementService.updateProgramStageDataElement(programStageDataElement);
programStageDataElements.remove(programStageDataElement);
programStageDataElement.setRenderOptionsAsRadio(renderAsRadio);
}
}
for (ProgramStageSection section : programStage.getProgramStageSections()) {
for (ProgramStageDataElement element : programStageDataElements) {
section.getDataElements().remove(element.getDataElement());
}
programStageSectionService.updateProgramStageSection(section);
}
for (ProgramStageDataElement psdeDelete : programStageDataElements) {
programStage.getProgramStageDataElements().remove(psdeDelete);
programStageDataElementService.deleteProgramStageDataElement(psdeDelete);
}
programStageService.updateProgramStage(programStage);
programId = programStage.getProgram().getId();
return SUCCESS;
}
use of org.hisp.dhis.program.ProgramStageDataElement in project dhis2-core by dhis2.
the class JdbcEnrollmentAnalyticsTableManager method getDimensionColumns.
@Override
protected List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
final String dbl = statementBuilder.getDoubleColumnType();
final String numericClause = " and value " + statementBuilder.getRegexpMatch() + " '" + NUMERIC_LENIENT_REGEXP + "'";
final String dateClause = " and value " + statementBuilder.getRegexpMatch() + " '" + DATE_REGEXP + "'";
List<AnalyticsTableColumn> columns = new ArrayList<>();
List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
for (OrganisationUnitLevel level : levels) {
String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
}
for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "ougs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (PeriodType periodType : PeriodType.getAvailablePeriodTypes()) {
String column = quote(periodType.getName().toLowerCase());
columns.add(new AnalyticsTableColumn(column, "character varying(15)", "dps." + column));
}
for (ProgramStage programStage : table.getProgram().getProgramStages()) {
for (ProgramStageDataElement programStageDataElement : programStage.getProgramStageDataElements()) {
DataElement dataElement = programStageDataElement.getDataElement();
ValueType valueType = dataElement.getValueType();
String dataType = getColumnType(valueType);
String dataClause = dataElement.isNumericType() ? numericClause : dataElement.getValueType().isDate() ? dateClause : "";
String select = getSelectClause(valueType);
boolean skipIndex = NO_INDEX_VAL_TYPES.contains(dataElement.getValueType()) && !dataElement.hasOptionSet();
String sql = "(select " + select + " from trackedentitydatavalue tedv " + "inner join programstageinstance psi on psi.programstageinstanceid = tedv.programstageinstanceid " + "where psi.executiondate is not null " + "and psi.deleted is false " + "and psi.programinstanceid=pi.programinstanceid " + dataClause + " " + "and tedv.dataelementid=" + dataElement.getId() + " " + "and psi.programstageid=" + programStage.getId() + " " + "order by psi.executiondate desc " + "limit 1) as " + quote(programStage.getUid() + DB_SEPARATOR_ID + dataElement.getUid());
columns.add(new AnalyticsTableColumn(quote(programStage.getUid() + DB_SEPARATOR_ID + dataElement.getUid()), dataType, sql, skipIndex));
}
}
for (TrackedEntityAttribute attribute : table.getProgram().getNonConfidentialTrackedEntityAttributes()) {
String dataType = getColumnType(attribute.getValueType());
String dataClause = attribute.isNumericType() ? numericClause : attribute.isDateType() ? dateClause : "";
String select = getSelectClause(attribute.getValueType());
boolean skipIndex = NO_INDEX_VAL_TYPES.contains(attribute.getValueType()) && !attribute.hasOptionSet();
String sql = "(select " + select + " from trackedentityattributevalue " + "where trackedentityinstanceid=pi.trackedentityinstanceid " + "and trackedentityattributeid=" + attribute.getId() + dataClause + ") as " + quote(attribute.getUid());
columns.add(new AnalyticsTableColumn(quote(attribute.getUid()), dataType, sql, skipIndex));
}
AnalyticsTableColumn pi = new AnalyticsTableColumn(quote("pi"), "character(11) not null", "pi.uid");
AnalyticsTableColumn erd = new AnalyticsTableColumn(quote("enrollmentdate"), "timestamp", "pi.enrollmentdate");
AnalyticsTableColumn id = new AnalyticsTableColumn(quote("incidentdate"), "timestamp", "pi.incidentdate");
final String executionDateSql = "(select psi.executionDate from programstageinstance psi " + "where psi.programinstanceid=pi.programinstanceid " + "and psi.executiondate is not null " + "and psi.deleted is false " + "order by psi.executiondate desc " + "limit 1) as " + quote("executiondate");
AnalyticsTableColumn ed = new AnalyticsTableColumn(quote("executiondate"), "timestamp", executionDateSql);
final String dueDateSql = "(select psi.duedate from programstageinstance psi " + "where psi.programinstanceid = pi.programinstanceid " + "and psi.duedate is not null " + "and psi.deleted is false " + "order by psi.duedate desc " + "limit 1) as " + quote("duedate");
AnalyticsTableColumn dd = new AnalyticsTableColumn(quote("duedate"), "timestamp", dueDateSql);
AnalyticsTableColumn cd = new AnalyticsTableColumn(quote("completeddate"), "timestamp", "case status when 'COMPLETED' then enddate end");
AnalyticsTableColumn es = new AnalyticsTableColumn(quote("enrollmentstatus"), "character(50)", "pi.status");
AnalyticsTableColumn longitude = new AnalyticsTableColumn(quote("longitude"), dbl, "pi.longitude");
AnalyticsTableColumn latitude = new AnalyticsTableColumn(quote("latitude"), dbl, "pi.latitude");
AnalyticsTableColumn ou = new AnalyticsTableColumn(quote("ou"), "character(11) not null", "ou.uid");
AnalyticsTableColumn oun = new AnalyticsTableColumn(quote("ouname"), "character varying(230) not null", "ou.name");
AnalyticsTableColumn ouc = new AnalyticsTableColumn(quote("oucode"), "character varying(50)", "ou.code");
columns.addAll(Lists.newArrayList(pi, erd, id, ed, es, dd, cd, longitude, latitude, ou, oun, ouc));
if (databaseInfo.isSpatialSupport()) {
String alias = "(select ST_SetSRID(ST_MakePoint(pi.longitude, pi.latitude), 4326)) as geom";
columns.add(new AnalyticsTableColumn(quote("geom"), "geometry(Point, 4326)", alias, false, "gist"));
}
if (table.hasProgram() && table.getProgram().isRegistration()) {
columns.add(new AnalyticsTableColumn(quote("tei"), "character(11)", "tei.uid"));
}
return filterDimensionColumns(columns);
}
Aggregations