use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.
the class JdbcCompletenessTargetTableManager method getDimensionColumns.
@Override
public List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
List<AnalyticsTableColumn> columns = new ArrayList<>();
List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
List<DataElementCategory> attributeCategories = categoryService.getAttributeDataDimensionCategoriesNoAcl();
for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "ougs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (OrganisationUnitLevel level : levels) {
String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
}
for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "acs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (DataElementCategory category : attributeCategories) {
columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "acs." + quote(category.getUid()), category.getCreated()));
}
AnalyticsTableColumn ouOpening = new AnalyticsTableColumn(quote("ouopeningdate"), "date", "ou.openingdate");
AnalyticsTableColumn ouClosed = new AnalyticsTableColumn(quote("oucloseddate"), "date", "ou.closeddate");
AnalyticsTableColumn coStart = new AnalyticsTableColumn(quote("costartdate"), "date", "doc.costartdate");
AnalyticsTableColumn coEnd = new AnalyticsTableColumn(quote("coenddate"), "date", "doc.coenddate");
AnalyticsTableColumn ds = new AnalyticsTableColumn(quote("dx"), "character(11) not null", "ds.uid");
AnalyticsTableColumn ao = new AnalyticsTableColumn(quote("ao"), "character(11) not null", "ao.uid");
columns.addAll(Lists.newArrayList(ouOpening, ouClosed, coStart, coEnd, ds, ao));
return filterDimensionColumns(columns);
}
use of org.hisp.dhis.organisationunit.OrganisationUnitLevel 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);
}
use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.
the class JdbcCompletenessTableManager method getDimensionColumns.
@Override
public List<AnalyticsTableColumn> getDimensionColumns(AnalyticsTable table) {
List<AnalyticsTableColumn> columns = new ArrayList<>();
List<OrganisationUnitGroupSet> orgUnitGroupSets = idObjectManager.getDataDimensionsNoAcl(OrganisationUnitGroupSet.class);
List<OrganisationUnitLevel> levels = organisationUnitService.getFilledOrganisationUnitLevels();
List<CategoryOptionGroupSet> attributeCategoryOptionGroupSets = categoryService.getAttributeCategoryOptionGroupSetsNoAcl();
List<DataElementCategory> attributeCategories = categoryService.getAttributeDataDimensionCategoriesNoAcl();
for (OrganisationUnitGroupSet groupSet : orgUnitGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "ougs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (OrganisationUnitLevel level : levels) {
String column = quote(PREFIX_ORGUNITLEVEL + level.getLevel());
columns.add(new AnalyticsTableColumn(column, "character(11)", "ous." + column, level.getCreated()));
}
for (CategoryOptionGroupSet groupSet : attributeCategoryOptionGroupSets) {
columns.add(new AnalyticsTableColumn(quote(groupSet.getUid()), "character(11)", "acs." + quote(groupSet.getUid()), groupSet.getCreated()));
}
for (DataElementCategory category : attributeCategories) {
columns.add(new AnalyticsTableColumn(quote(category.getUid()), "character(11)", "acs." + quote(category.getUid()), category.getCreated()));
}
for (PeriodType periodType : PeriodType.getAvailablePeriodTypes()) {
String column = quote(periodType.getName().toLowerCase());
columns.add(new AnalyticsTableColumn(column, "character varying(15)", "ps." + column));
}
String timelyDateDiff = statementBuilder.getDaysBetweenDates("pe.enddate", statementBuilder.getCastToDate("cdr.date"));
String timelyAlias = "(select (" + timelyDateDiff + ") <= ds.timelydays) as timely";
AnalyticsTableColumn tm = new AnalyticsTableColumn(quote("timely"), "boolean", timelyAlias);
AnalyticsTableColumn ds = new AnalyticsTableColumn(quote("dx"), "character(11) not null", "ds.uid");
columns.addAll(Lists.newArrayList(ds, tm));
return filterDimensionColumns(columns);
}
use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.
the class DhisConvenienceTest method createPredictor.
/**
* Creates a Predictor
*
* @param output the data element where the predictor stores its predictions
* @param combo the category option combo (or null) under which the predictors are stored
* @param uniqueCharacter A unique character to identify the object.
* @param generator The right side expression.
* @param skipTest The skiptest expression
* @param periodType The period-type.
* @param organisationUnitLevel The unit level of organisations to be
* evaluated by this rule.
* @param sequentialSampleCount How many sequential past periods to sample.
* @param annualSampleCount How many years of past periods to sample.
* @param sequentialSkipCount How many periods in the current year to skip
*/
public static Predictor createPredictor(DataElement output, DataElementCategoryOptionCombo combo, String uniqueCharacter, Expression generator, Expression skipTest, PeriodType periodType, OrganisationUnitLevel organisationUnitLevel, int sequentialSampleCount, int sequentialSkipCount, int annualSampleCount) {
Predictor predictor = new Predictor();
Set<OrganisationUnitLevel> orgUnitlevels = Sets.newHashSet(organisationUnitLevel);
predictor.setAutoFields();
predictor.setOutput(output);
predictor.setOutputCombo(combo);
predictor.setName("Predictor" + uniqueCharacter);
predictor.setDescription("Description" + uniqueCharacter);
predictor.setGenerator(generator);
predictor.setSampleSkipTest(skipTest);
predictor.setPeriodType(periodType);
predictor.setOrganisationUnitLevels(orgUnitlevels);
predictor.setSequentialSampleCount(sequentialSampleCount);
predictor.setAnnualSampleCount(annualSampleCount);
predictor.setSequentialSkipCount(sequentialSkipCount);
return predictor;
}
use of org.hisp.dhis.organisationunit.OrganisationUnitLevel in project dhis2-core by dhis2.
the class PredictorServiceTest method setUpTest.
// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
orgUnitLevel1 = new OrganisationUnitLevel(1, "Level1");
organisationUnitService.addOrganisationUnitLevel(orgUnitLevel1);
dataElementA = createDataElement('A');
dataElementX = createDataElement('X', ValueType.NUMBER, AggregationType.NONE);
DataElement dataElementB = createDataElement('B');
DataElement dataElementC = createDataElement('C');
DataElement dataElementD = createDataElement('D');
dataElementService.addDataElement(dataElementA);
dataElementService.addDataElement(dataElementB);
dataElementService.addDataElement(dataElementC);
dataElementService.addDataElement(dataElementD);
dataElementService.addDataElement(dataElementX);
dataElements = new HashSet<>();
dataElements.add(dataElementA);
dataElements.add(dataElementB);
dataElements.add(dataElementC);
dataElements.add(dataElementD);
periodTypeMonthly = PeriodType.getPeriodTypeByName("Monthly");
CategoryOptionCombo categoryOptionCombo = categoryService.getDefaultCategoryOptionCombo();
defaultCombo = categoryService.getDefaultCategoryOptionCombo();
altCategoryOption = new CategoryOption("AltCategoryOption");
categoryService.addCategoryOption(altCategoryOption);
altCategory = createCategory('A', altCategoryOption);
categoryService.addCategory(altCategory);
altCategoryCombo = createCategoryCombo('Y', altCategory);
categoryService.addCategoryCombo(altCategoryCombo);
altCombo = createCategoryOptionCombo(altCategoryCombo, altCategoryOption);
optionCombos = new HashSet<>();
optionCombos.add(categoryOptionCombo);
optionCombos.add(altCombo);
categoryService.addCategoryOptionCombo(altCombo);
expressionA = new Expression("AVG(#{" + dataElementA.getUid() + "})+1.5*STDDEV(#{" + dataElementA.getUid() + "})", "descriptionA");
expressionB = new Expression("AVG(#{" + dataElementB.getUid() + "." + defaultCombo.getUid() + "})", "descriptionB");
expressionC = new Expression("135.79", "descriptionC");
expressionD = new Expression("34.98", "descriptionD");
}
Aggregations