use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class ResourceTableServiceTest method setUpTest.
@Override
public void setUpTest() {
PeriodType pt = new MonthlyPeriodType();
DataElement deA = createDataElement('A');
DataElement deB = createDataElement('B');
idObjectManager.save(deA);
idObjectManager.save(deB);
DataElementGroup degA = createDataElementGroup('A');
DataElementGroup degB = createDataElementGroup('B');
degA.addDataElement(deA);
degB.addDataElement(deB);
idObjectManager.save(degA);
idObjectManager.save(degB);
DataElementGroupSet degsA = createDataElementGroupSet('A');
degsA.addDataElementGroup(degA);
degsA.addDataElementGroup(degB);
idObjectManager.save(degsA);
OrganisationUnit ouA = createOrganisationUnit('A');
OrganisationUnit ouB = createOrganisationUnit('B');
OrganisationUnit ouC = createOrganisationUnit('C');
ouB.setParent(ouA);
ouC.setParent(ouA);
ouA.getChildren().add(ouB);
ouA.getChildren().add(ouC);
idObjectManager.save(ouA);
idObjectManager.save(ouB);
idObjectManager.save(ouC);
DataSet dsA = createDataSet('A', pt);
DataSet dsB = createDataSet('B', pt);
dsA.addDataSetElement(deA);
dsB.addDataSetElement(deA);
dsA.addOrganisationUnit(ouA);
dsB.addOrganisationUnit(ouA);
dataSetService.addDataSet(dsA);
dataSetService.addDataSet(dsB);
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class DefaultPredictorService method predict.
// -------------------------------------------------------------------------
// Predictor run
// -------------------------------------------------------------------------
@Override
public int predict(Predictor predictor, Date startDate, Date endDate) {
log.info("Predicting for " + predictor.getName() + " from " + startDate.toString() + " to " + endDate.toString());
Expression generator = predictor.getGenerator();
Expression skipTest = predictor.getSampleSkipTest();
DataElement outputDataElement = predictor.getOutput();
Set<String> aggregates = expressionService.getAggregatesInExpression(generator.getExpression());
Map<String, Double> constantMap = constantService.getConstantMap();
List<Period> outputPeriods = getPeriodsBetweenDates(predictor.getPeriodType(), startDate, endDate);
ListMap<Period, Period> samplePeriodsMap = getSamplePeriodsMap(outputPeriods, predictor);
Set<Period> allSamplePeriods = samplePeriodsMap.uniqueValues();
Set<DataElementOperand> dataElementOperands = getDataElementOperands(aggregates, skipTest);
User currentUser = currentUserService.getCurrentUser();
DataElementCategoryOptionCombo outputOptionCombo = predictor.getOutputCombo() == null ? categoryService.getDefaultDataElementCategoryOptionCombo() : predictor.getOutputCombo();
List<OrganisationUnit> orgUnits = organisationUnitService.getOrganisationUnitsAtOrgUnitLevels(predictor.getOrganisationUnitLevels(), currentUser.getOrganisationUnits());
int predictionCount = 0;
for (OrganisationUnit orgUnit : orgUnits) {
MapMapMap<Period, String, DimensionalItemObject, Double> dataMap = dataElementOperands.isEmpty() ? null : dataValueService.getDataElementOperandValues(dataElementOperands, allSamplePeriods, orgUnit);
applySkipTest(dataMap, skipTest, constantMap);
for (Period period : outputPeriods) {
ListMapMap<String, String, Double> aggregateSampleMap = getAggregateSamples(dataMap, aggregates, samplePeriodsMap.get(period), constantMap);
for (String aoc : aggregateSampleMap.keySet()) {
ListMap<String, Double> aggregateValueMap = aggregateSampleMap.get(aoc);
Double value = expressionService.getExpressionValue(generator, new HashMap<>(), constantMap, null, period.getDaysInPeriod(), aggregateValueMap);
if (value != null && !value.isNaN() && !value.isInfinite()) {
writeDataValue(outputDataElement, period, orgUnit, outputOptionCombo, categoryService.getDataElementCategoryOptionCombo(aoc), value.toString(), currentUser.getUsername());
predictionCount++;
}
}
}
}
log.info("Generated " + predictionCount + " predictions for " + predictor.getName() + " from " + startDate.toString() + " to " + endDate.toString());
return predictionCount;
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class HibernateProgramInstanceStore method buildProgramInstanceHql.
private String buildProgramInstanceHql(ProgramInstanceQueryParams params) {
String hql = "from ProgramInstance pi";
SqlHelper hlp = new SqlHelper(true);
if (params.hasLastUpdated()) {
hql += hlp.whereAnd() + "pi.lastUpdated >= '" + getMediumDateString(params.getLastUpdated()) + "'";
}
if (params.hasTrackedEntityInstance()) {
hql += hlp.whereAnd() + "pi.entityInstance.uid = '" + params.getTrackedEntityInstance().getUid() + "'";
}
if (params.hasTrackedEntity()) {
hql += hlp.whereAnd() + "pi.entityInstance.trackedEntity.uid = '" + params.getTrackedEntity().getUid() + "'";
}
if (params.hasOrganisationUnits()) {
if (params.isOrganisationUnitMode(OrganisationUnitSelectionMode.DESCENDANTS)) {
String ouClause = "(";
SqlHelper orHlp = new SqlHelper(true);
for (OrganisationUnit organisationUnit : params.getOrganisationUnits()) {
ouClause += orHlp.or() + "pi.organisationUnit.path LIKE '" + organisationUnit.getPath() + "%'";
}
ouClause += ")";
hql += hlp.whereAnd() + ouClause;
} else {
hql += hlp.whereAnd() + "pi.organisationUnit.uid in (" + getQuotedCommaDelimitedString(getUids(params.getOrganisationUnits())) + ")";
}
}
if (params.hasProgram()) {
hql += hlp.whereAnd() + "pi.program.uid = '" + params.getProgram().getUid() + "'";
}
if (params.hasProgramStatus()) {
hql += hlp.whereAnd() + "pi.status = '" + params.getProgramStatus() + "'";
}
if (params.hasFollowUp()) {
hql += hlp.whereAnd() + "pi.followup = " + params.getFollowUp();
}
if (params.hasProgramStartDate()) {
hql += hlp.whereAnd() + "pi.enrollmentDate >= '" + getMediumDateString(params.getProgramStartDate()) + "'";
}
if (params.hasProgramEndDate()) {
hql += hlp.whereAnd() + "pi.enrollmentDate <= '" + getMediumDateString(params.getProgramEndDate()) + "'";
}
return hql;
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class DeliveryChannelStrategy method getOrganisationUnit.
protected OrganisationUnit getOrganisationUnit(ProgramMessage message) {
if (message.getRecipients().getOrganisationUnit() == null) {
return null;
}
String uid = message.getRecipients().getOrganisationUnit().getUid();
OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(uid);
message.getRecipients().setOrganisationUnit(orgUnit);
return orgUnit;
}
use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.
the class DefaultProgramInstanceService method countProgramInstances.
@Override
public int countProgramInstances(ProgramInstanceQueryParams params) {
decideAccess(params);
validate(params);
User user = currentUserService.getCurrentUser();
if (user != null && params.isOrganisationUnitMode(OrganisationUnitSelectionMode.ACCESSIBLE)) {
params.setOrganisationUnits(user.getDataViewOrganisationUnitsWithFallback());
params.setOrganisationUnitMode(OrganisationUnitSelectionMode.DESCENDANTS);
} else if (params.isOrganisationUnitMode(CHILDREN)) {
Set<OrganisationUnit> organisationUnits = new HashSet<>();
organisationUnits.addAll(params.getOrganisationUnits());
for (OrganisationUnit organisationUnit : params.getOrganisationUnits()) {
organisationUnits.addAll(organisationUnit.getChildren());
}
params.setOrganisationUnits(organisationUnits);
}
params.setSkipPaging(true);
return programInstanceStore.countProgramInstances(params);
}
Aggregations