Search in sources :

Example 16 with ProgramStage

use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.

the class SaveDataEntryFormAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    ProgramStage programStage = programStageService.getProgramStage(programStageId);
    Program program = programStage.getProgram();
    programId = program.getId();
    DataEntryForm dataEntryForm = null;
    if (dataEntryFormId == null) {
        dataEntryForm = programStage.getDataEntryForm();
    } else {
        dataEntryForm = dataEntryFormService.getDataEntryForm(dataEntryFormId);
    }
    if (dataEntryForm == null || !dataEntryForm.getHtmlCode().equals(designTextarea)) {
        program.increaseVersion();
    }
    designTextarea = dataEntryFormService.prepareDataEntryFormForSave(designTextarea);
    if (dataEntryForm == null) {
        program.increaseVersion();
        dataEntryForm = new DataEntryForm(StringUtils.trimToNull(name), designTextarea);
        dataEntryFormService.addDataEntryForm(dataEntryForm);
    } else {
        dataEntryForm.setName(StringUtils.trimToNull(name));
        dataEntryForm.setHtmlCode(designTextarea);
        dataEntryFormService.updateDataEntryForm(dataEntryForm);
    }
    programStage.setDataEntryForm(dataEntryForm);
    programStageService.updateProgramStage(programStage);
    return SUCCESS;
}
Also used : Program(org.hisp.dhis.program.Program) DataEntryForm(org.hisp.dhis.dataentryform.DataEntryForm) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 17 with ProgramStage

use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.

the class TrackedEntityDataValueStoreTest method setUpTest.

@Override
public void setUpTest() {
    OrganisationUnit organisationUnit = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(organisationUnit);
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    entityInstance = createTrackedEntityInstance('A', organisationUnit);
    entityInstanceService.addTrackedEntityInstance(entityInstance);
    Program program = createProgram('A', new HashSet<>(), organisationUnit);
    programService.addProgram(program);
    ProgramStage stageA = createProgramStage('A', 0);
    stageA.setProgram(program);
    programStageService.saveProgramStage(stageA);
    ProgramStage stageB = createProgramStage('B', 0);
    stageB.setProgram(program);
    programStageService.saveProgramStage(stageB);
    Set<ProgramStage> programStages = new HashSet<>();
    programStages.add(stageA);
    programStages.add(stageB);
    program.setProgramStages(programStages);
    programService.updateProgram(program);
    DateTime yesterDate = DateTime.now();
    yesterDate.withTimeAtStartOfDay();
    yesterDate.minusDays(1);
    yesterday = yesterDate.toDate();
    DateTime tomorrowDate = DateTime.now();
    tomorrowDate.withTimeAtStartOfDay();
    tomorrowDate.plusDays(1);
    tomorrow = tomorrowDate.toDate();
    programInstance = programInstanceService.enrollTrackedEntityInstance(entityInstance, program, yesterday, yesterday, organisationUnit);
    stageInstanceA = programStageInstanceService.createProgramStageInstance(programInstance, stageA, yesterday, yesterday, organisationUnit);
    stageInstanceB = programStageInstanceService.createProgramStageInstance(programInstance, stageB, yesterday, yesterday, organisationUnit);
    dataValueA = new TrackedEntityDataValue(stageInstanceA, dataElementA, "A");
    dataValueB = new TrackedEntityDataValue(stageInstanceA, dataElementB, "B");
    dataValueC = new TrackedEntityDataValue(stageInstanceB, dataElementA, "C");
    dataValueD = new TrackedEntityDataValue(stageInstanceB, dataElementB, "D");
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet)

Example 18 with ProgramStage

use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.

the class ActivityReportingServiceImpl method saveSingleEventWithoutRegistration.

@Override
public String saveSingleEventWithoutRegistration(org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStage mobileProgramStage, int orgUnitId) throws NotAllowedException {
    ProgramStage programStage = programStageService.getProgramStage(mobileProgramStage.getId());
    Program program = programStage.getProgram();
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setEnrollmentDate(new Date());
    programInstance.setIncidentDate(new Date());
    programInstance.setProgram(program);
    programInstance.setStatus(ProgramStatus.COMPLETED);
    programInstanceService.addProgramInstance(programInstance);
    ProgramStageInstance programStageInstance = new ProgramStageInstance();
    programStageInstance.setProgramInstance(programInstance);
    programStageInstance.setProgramStage(programStage);
    programStageInstance.setDueDate(new Date());
    programStageInstance.setExecutionDate(new Date());
    programStageInstance.setStatus(EventStatus.COMPLETED);
    programStageInstance.setOrganisationUnit(organisationUnitService.getOrganisationUnit(orgUnitId));
    programStageInstanceService.addProgramStageInstance(programStageInstance);
    for (org.hisp.dhis.api.mobile.model.LWUITmodel.ProgramStageDataElement mobileDataElement : mobileProgramStage.getDataElements()) {
        TrackedEntityDataValue trackedEntityDataValue = new TrackedEntityDataValue();
        trackedEntityDataValue.setDataElement(dataElementService.getDataElement(mobileDataElement.getId()));
        String value = mobileDataElement.getValue();
        if (value != null && !value.trim().equals("")) {
            trackedEntityDataValue.setValue(value);
            trackedEntityDataValue.setProgramStageInstance(programStageInstance);
            trackedEntityDataValue.setProvidedElsewhere(false);
            trackedEntityDataValue.setLastUpdated(new Date());
            dataValueService.saveTrackedEntityDataValue(trackedEntityDataValue);
        }
    }
    return SINGLE_EVENT_WITHOUT_REGISTRATION_UPLOADED;
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityDataValue(org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue) ProgramStage(org.hisp.dhis.program.ProgramStage) Date(java.util.Date) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 19 with ProgramStage

use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.

the class AnalyticsUtils method getUidNameMap.

/**
     * Returns a mapping of identifiers and names for the given event query.
     * 
     * @param params the event query.
     * @return a mapping of identifiers and names for the given event query.
     */
public static Map<String, String> getUidNameMap(EventQueryParams params) {
    Map<String, String> map = new HashMap<>();
    Program program = params.getProgram();
    ProgramStage stage = params.getProgramStage();
    map.put(program.getUid(), program.getDisplayProperty(params.getDisplayProperty()));
    if (stage != null) {
        map.put(stage.getUid(), stage.getName());
    } else {
        for (ProgramStage st : program.getProgramStages()) {
            map.put(st.getUid(), st.getName());
        }
    }
    if (params.hasValueDimension()) {
        map.put(params.getValue().getUid(), params.getValue().getDisplayProperty(params.getDisplayProperty()));
    }
    map.putAll(getUidDisplayPropertyMap(params.getItems(), params.getDisplayProperty()));
    map.putAll(getUidDisplayPropertyMap(params.getItemFilters(), params.getDisplayProperty()));
    map.putAll(getUidDisplayPropertyMap(params.getDimensions(), params.isHierarchyMeta(), params.getDisplayProperty()));
    map.putAll(getUidDisplayPropertyMap(params.getFilters(), params.isHierarchyMeta(), params.getDisplayProperty()));
    map.putAll(IdentifiableObjectUtils.getUidNameMap(params.getLegends()));
    return map;
}
Also used : Program(org.hisp.dhis.program.Program) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 20 with ProgramStage

use of org.hisp.dhis.program.ProgramStage 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);
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) ValueType(org.hisp.dhis.common.ValueType) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) UniqueArrayList(org.hisp.dhis.commons.collection.UniqueArrayList) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) ProgramStage(org.hisp.dhis.program.ProgramStage) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)

Aggregations

ProgramStage (org.hisp.dhis.program.ProgramStage)40 Program (org.hisp.dhis.program.Program)24 DataElement (org.hisp.dhis.dataelement.DataElement)13 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)10 ArrayList (java.util.ArrayList)7 ProgramInstance (org.hisp.dhis.program.ProgramInstance)7 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)7 PeriodType (org.hisp.dhis.period.PeriodType)6 Date (java.util.Date)5 ProgramStageSection (org.hisp.dhis.program.ProgramStageSection)5 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)5 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 List (java.util.List)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)3 ProgramTrackedEntityAttribute (org.hisp.dhis.program.ProgramTrackedEntityAttribute)3 TrackedEntityAttribute (org.hisp.dhis.trackedentity.TrackedEntityAttribute)3