Search in sources :

Example 21 with ProgramStage

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

the class AnalyticsUtilsTest method testGetUidNameMapEventQuery.

@Test
public void testGetUidNameMapEventQuery() {
    ProgramStage psA = createProgramStage('A', 0);
    ProgramStage psB = createProgramStage('B', 0);
    Program prA = createProgram('A');
    prA.getProgramStages().add(psA);
    prA.getProgramStages().add(psB);
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('A');
    OrganisationUnit ouA = createOrganisationUnit('A');
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).addItem(new QueryItem(deA)).addItem(new QueryItem(deB)).addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA))).withDisplayProperty(DisplayProperty.NAME).build();
    Map<String, String> map = AnalyticsUtils.getUidNameMap(params);
    assertEquals(psA.getName(), map.get(psA.getUid()));
    assertEquals(psB.getName(), map.get(psB.getUid()));
    assertEquals(prA.getName(), map.get(prA.getUid()));
    assertEquals(deA.getName(), map.get(deA.getUid()));
    assertEquals(deB.getName(), map.get(deB.getUid()));
    assertEquals(ouA.getName(), map.get(ouA.getUid()));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 22 with ProgramStage

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

the class EventAnalyticsServiceTest method setUpTest.

@Override
public void setUpTest() throws IOException {
    Period peJan = createPeriod("2017-01");
    Period peFeb = createPeriod("2017-02");
    Period peMar = createPeriod("2017-03");
    Period peApril = createPeriod("2017-04");
    idObjectManager.save(peJan);
    idObjectManager.save(peFeb);
    idObjectManager.save(peMar);
    idObjectManager.save(peApril);
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    DataElement deC = createDataElement('C');
    DataElement deD = createDataElement('D');
    idObjectManager.save(deA);
    idObjectManager.save(deB);
    idObjectManager.save(deC);
    idObjectManager.save(deD);
    OrganisationUnit ouA = createOrganisationUnit('A');
    OrganisationUnit ouB = createOrganisationUnit('B');
    OrganisationUnit ouC = createOrganisationUnit('C');
    ouC.setOpeningDate(getDate(2016, 4, 10));
    ouC.setClosedDate(null);
    OrganisationUnit ouD = createOrganisationUnit('D');
    ouD.setOpeningDate(getDate(2016, 12, 10));
    ouD.setClosedDate(null);
    OrganisationUnit ouE = createOrganisationUnit('E');
    AnalyticsTestUtils.configureHierarchy(ouA, ouB, ouC, ouD, ouE);
    idObjectManager.save(ouA);
    idObjectManager.save(ouB);
    idObjectManager.save(ouC);
    idObjectManager.save(ouD);
    idObjectManager.save(ouE);
    Program programA = createProgram('A', null, null, Sets.newHashSet(ouA, ouB), null);
    programA.setUid("programA123");
    idObjectManager.save(programA);
    ProgramStage psA = createProgramStage('A', 0);
    psA.setUid("programStgA");
    psA.addDataElement(deA, 0);
    psA.addDataElement(deB, 1);
    idObjectManager.save(psA);
    ProgramStage psB = createProgramStage('B', 0);
    psB.setUid("programStgB");
    psB.addDataElement(deA, 0);
    psB.addDataElement(deB, 1);
    idObjectManager.save(psB);
    ProgramStage psC = createProgramStage('C', 0);
    psC.setUid("programStgC");
    psC.addDataElement(deA, 0);
    psC.addDataElement(deB, 1);
    idObjectManager.save(psC);
    programA.getProgramStages().add(psA);
    TrackedEntity trackedEntity = createTrackedEntity('A');
    idObjectManager.save(trackedEntity);
    org.hisp.dhis.trackedentity.TrackedEntityInstance maleA = createTrackedEntityInstance('A', ouA);
    maleA.setUid("person1234A");
    org.hisp.dhis.trackedentity.TrackedEntityInstance femaleB = createTrackedEntityInstance('B', ouB);
    femaleB.setUid("person1234B");
    maleA.setTrackedEntity(trackedEntity);
    femaleB.setTrackedEntity(trackedEntity);
    idObjectManager.save(maleA);
    idObjectManager.save(femaleB);
    programInstanceService.enrollTrackedEntityInstance(maleA, programA, null, null, ouA);
    programInstanceService.enrollTrackedEntityInstance(femaleB, programA, null, null, ouA);
    // Read event data from CSV file
    // --------------------------------------------------------------------
    ArrayList<String[]> eventDataLines = AnalyticsTestUtils.readInputFile("csv/eventData.csv");
    parseEventData(eventDataLines);
    // Generate analytics tables
    // --------------------------------------------------------------------
    analyticsTableGenerator.generateTables(null, null, null, false);
    // Set parameters
    // --------------------------------------------------------------------
    // all events in program A - 2017
    EventQueryParams events_2017_params = new EventQueryParams.Builder().withOrganisationUnits(Lists.newArrayList(ouA)).withStartDate(getDate(2017, 1, 1)).withEndDate(getDate(2017, 12, 31)).withProgram(programA).build();
    eventQueryParams.put("events_2017", events_2017_params);
    // Set results
    // --------------------------------------------------------------------
    Map<String, Double> events_2017_keyValue = new HashMap<>();
    events_2017_keyValue.put("ouabcdefghA", 6.0);
    results.put("events_2017", events_2017_keyValue);
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) HashMap(java.util.HashMap) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) Period(org.hisp.dhis.period.Period) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 23 with ProgramStage

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

the class AddProgramStageSectionAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    ProgramStage programStage = programStageService.getProgramStage(programStageId);
    // ---------------------------------------------------------------------
    // Section
    // ---------------------------------------------------------------------
    List<DataElement> dataElements = new ArrayList<>();
    for (Integer id : dataElementIds) {
        dataElements.add(dataElementService.getDataElement(id));
    }
    ProgramStageSection programStageSection = new ProgramStageSection(StringUtils.trimToNull(name), dataElements, programStage.getProgramStageSections().size());
    programStageSection.setAutoFields();
    // ---------------------------------------------------------------------
    // Program indicators
    // ---------------------------------------------------------------------
    List<ProgramIndicator> programIndicators = new ArrayList<>();
    for (Integer id : selectedIndicators) {
        ProgramIndicator indicator = programIndicatorService.getProgramIndicator(id);
        programIndicators.add(indicator);
    }
    programStageSection.setProgramIndicators(programIndicators);
    programStageSection.setProgramStage(programStage);
    // ---------------------------------------------------------------------
    // Update program stage
    // ---------------------------------------------------------------------
    Set<ProgramStageSection> sections = programStage.getProgramStageSections();
    sections.add(programStageSection);
    programStage.setProgramStageSections(sections);
    programStageService.updateProgramStage(programStage);
    return SUCCESS;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) ArrayList(java.util.ArrayList) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator)

Example 24 with ProgramStage

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

the class ViewDataEntryFormAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    programStage = programStageService.getProgramStage(programStageId);
    // ---------------------------------------------------------------------
    // Get dataEntryForm of selected program-stage
    // ---------------------------------------------------------------------
    dataEntryForm = programStage.getDataEntryForm();
    if (dataEntryForm != null) {
        dataEntryValue = programDataEntryService.prepareDataEntryFormForEdit(dataEntryForm.getHtmlCode());
    } else {
        dataEntryValue = "";
    }
    // ---------------------------------------------------------------------
    // Get existing Data Entry Forms
    // ---------------------------------------------------------------------
    List<Integer> listAssociationIds = new ArrayList<>();
    for (ProgramStage ps : programStage.getProgram().getProgramStages()) {
        listAssociationIds.add(ps.getId());
    }
    existingDataEntryForms = dataEntryFormService.listDistinctDataEntryFormByProgramStageIds(listAssociationIds);
    existingDataEntryForms.remove(dataEntryForm);
    // ---------------------------------------------------------------------
    // Get other program-stages into the program
    // ---------------------------------------------------------------------
    programStages = new ArrayList<>(programStage.getProgram().getProgramStages());
    programStages.remove(programStage);
    Collections.sort(programStages);
    // ---------------------------------------------------------------------
    // Get selected program-stage
    // ---------------------------------------------------------------------
    dataElements = new ArrayList<>(programStage.getAllDataElements());
    Collections.sort(dataElements);
    flags = systemSettingManager.getFlags();
    autoSave = (Boolean) userSettingService.getUserSetting(UserSettingKey.AUTO_SAVE_CASE_ENTRY_FORM);
    return SUCCESS;
}
Also used : ArrayList(java.util.ArrayList) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 25 with ProgramStage

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

the class AddProgramAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    displayIncidentDate = (displayIncidentDate == null) ? false : displayIncidentDate;
    ignoreOverdueEvents = (ignoreOverdueEvents == null) ? false : ignoreOverdueEvents;
    onlyEnrollOnce = (onlyEnrollOnce == null) ? false : onlyEnrollOnce;
    selectEnrollmentDatesInFuture = (selectEnrollmentDatesInFuture == null) ? false : selectEnrollmentDatesInFuture;
    selectIncidentDatesInFuture = (selectIncidentDatesInFuture == null) ? false : selectIncidentDatesInFuture;
    Program program = new Program();
    program.setName(StringUtils.trimToNull(name));
    program.setShortName(StringUtils.trimToNull(shortName));
    program.setDescription(StringUtils.trimToNull(description));
    program.setVersion(1);
    program.setEnrollmentDateLabel(StringUtils.trimToNull(enrollmentDateLabel));
    program.setIncidentDateLabel(StringUtils.trimToNull(incidentDateLabel));
    program.setProgramType(programType);
    program.setDisplayIncidentDate(displayIncidentDate);
    program.setOnlyEnrollOnce(onlyEnrollOnce);
    program.setSelectEnrollmentDatesInFuture(selectEnrollmentDatesInFuture);
    program.setSelectIncidentDatesInFuture(selectIncidentDatesInFuture);
    program.setSkipOffline(skipOffline);
    program.setDisplayFrontPageList(displayFrontPageList);
    program.setUseFirstStageDuringRegistration(useFirstStageDuringRegistration);
    program.setCaptureCoordinates(captureCoordinates);
    program.setExpiryDays(expiryDays);
    program.setCompleteEventsExpiryDays(completeEventsExpiryDays);
    if (programType == ProgramType.WITH_REGISTRATION) {
        program.setIgnoreOverdueEvents(ignoreOverdueEvents);
    } else {
        program.setIgnoreOverdueEvents(false);
    }
    periodTypeName = StringUtils.trimToNull(periodTypeName);
    if (periodTypeName != null) {
        PeriodType periodType = PeriodType.getPeriodTypeByName(periodTypeName);
        program.setExpiryPeriodType(periodService.getPeriodTypeByClass(periodType.getClass()));
    } else {
        program.setExpiryPeriodType(null);
    }
    if (relationshipTypeId != null) {
        RelationshipType relationshipType = relationshipTypeService.getRelationshipType(relationshipTypeId);
        program.setRelationshipType(relationshipType);
        program.setRelationshipFromA(relationshipFromA);
        program.setRelationshipText(relationshipText);
        Program relatedProgram = programService.getProgram(relatedProgramId);
        program.setRelatedProgram(relatedProgram);
    } else {
        program.setRelationshipType(null);
        program.setRelationshipFromA(null);
        program.setRelationshipText(null);
        program.setRelatedProgram(null);
    }
    if (trackedEntityId != null) {
        TrackedEntity trackedEntity = trackedEntityService.getTrackedEntity(trackedEntityId);
        program.setTrackedEntity(trackedEntity);
    }
    if (categoryComboId != null) {
        program.setCategoryCombo(categoryService.getDataElementCategoryCombo(categoryComboId));
    }
    if (workflowId != null && workflowId > 0) {
        program.setWorkflow(dataApprovalService.getWorkflow(workflowId));
    }
    programService.addProgram(program);
    int index = 0;
    for (String selectedPropertyId : selectedPropertyIds) {
        String[] ids = selectedPropertyId.split("_");
        if (ids[0].equals(TrackedEntityInstance.PREFIX_TRACKED_ENTITY_ATTRIBUTE)) {
            TrackedEntityAttribute attribute = trackedEntityAttributeService.getTrackedEntityAttribute(Integer.parseInt(ids[1]));
            ProgramTrackedEntityAttribute programAttribute = new ProgramTrackedEntityAttribute(program, attribute, personDisplayNames.get(index), mandatory.get(index), allowFutureDate.get(index));
            programAttribute.setRenderOptionsAsRadio(renderOptionsAsRadios.get(index));
            programAttribute.setAutoFields();
            program.getProgramAttributes().add(programAttribute);
        }
        index++;
    }
    if (jsonAttributeValues != null) {
        attributeService.updateAttributeValues(program, jsonAttributeValues);
    }
    programService.updateProgram(program);
    if (program.isWithoutRegistration()) {
        ProgramStage programStage = new ProgramStage();
        programStage.setName(name);
        programStage.setDescription(description);
        programStage.setProgram(program);
        programStage.setMinDaysFromStart(0);
        programStage.setAutoGenerateEvent(true);
        programStage.setExecutionDateLabel(REPORT_DATE_DESCRIPTION);
        programStageService.saveProgramStage(programStage);
    }
    if (program.isWithoutRegistration()) {
        // Add a new program-instance
        ProgramInstance programInstance = new ProgramInstance();
        programInstance.setEnrollmentDate(new Date());
        programInstance.setIncidentDate(new Date());
        programInstance.setProgram(program);
        programInstance.setStatus(ProgramStatus.ACTIVE);
        programInstanceService.addProgramInstance(programInstance);
    }
    return SUCCESS;
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Program(org.hisp.dhis.program.Program) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) ProgramInstance(org.hisp.dhis.program.ProgramInstance) RelationshipType(org.hisp.dhis.relationship.RelationshipType) ProgramStage(org.hisp.dhis.program.ProgramStage) Date(java.util.Date)

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