Search in sources :

Example 66 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class EventTrackerConverterService method from.

private ProgramStageInstance from(TrackerPreheat preheat, Event event, ProgramStageInstance programStageInstance) {
    ProgramStage programStage = preheat.get(ProgramStage.class, event.getProgramStage());
    Program program = preheat.get(Program.class, event.getProgram());
    OrganisationUnit organisationUnit = preheat.get(OrganisationUnit.class, event.getOrgUnit());
    Date now = new Date();
    if (isNewEntity(programStageInstance)) {
        programStageInstance = new ProgramStageInstance();
        programStageInstance.setUid(!StringUtils.isEmpty(event.getEvent()) ? event.getEvent() : event.getUid());
        programStageInstance.setCreated(now);
        programStageInstance.setStoredBy(event.getStoredBy());
        programStageInstance.setCreatedByUserInfo(UserInfoSnapshot.from(preheat.getUser()));
    }
    programStageInstance.setLastUpdatedByUserInfo(UserInfoSnapshot.from(preheat.getUser()));
    programStageInstance.setLastUpdated(now);
    programStageInstance.setDeleted(false);
    programStageInstance.setCreatedAtClient(DateUtils.fromInstant(event.getCreatedAtClient()));
    programStageInstance.setLastUpdatedAtClient(DateUtils.fromInstant(event.getUpdatedAtClient()));
    programStageInstance.setProgramInstance(getProgramInstance(preheat, TrackerIdScheme.UID, event.getEnrollment(), program));
    programStageInstance.setProgramStage(programStage);
    programStageInstance.setOrganisationUnit(organisationUnit);
    programStageInstance.setExecutionDate(DateUtils.fromInstant(event.getOccurredAt()));
    programStageInstance.setDueDate(DateUtils.fromInstant(event.getScheduledAt()));
    String attributeOptionCombo = event.getAttributeOptionCombo();
    if (attributeOptionCombo != null) {
        programStageInstance.setAttributeOptionCombo(preheat.get(CategoryOptionCombo.class, event.getAttributeOptionCombo()));
    } else {
        programStageInstance.setAttributeOptionCombo((CategoryOptionCombo) preheat.getDefaults().get(CategoryOptionCombo.class));
    }
    programStageInstance.setGeometry(event.getGeometry());
    EventStatus previousStatus = programStageInstance.getStatus();
    Date completedDate = DateUtils.fromInstant(event.getCompletedAt());
    programStageInstance.setStatus(event.getStatus());
    if (!Objects.equal(previousStatus, programStageInstance.getStatus()) && programStageInstance.isCompleted()) {
        programStageInstance.setCompletedDate(completedDate == null ? new Date() : completedDate);
        programStageInstance.setCompletedBy(event.getCompletedBy() != null ? event.getCompletedBy() : preheat.getUsername());
    }
    if (programStage.isEnableUserAssignment()) {
        User assignedUser = preheat.get(User.class, event.getAssignedUser());
        programStageInstance.setAssignedUser(assignedUser);
    }
    if (program.isRegistration() && programStageInstance.getDueDate() == null && programStageInstance.getExecutionDate() != null) {
        programStageInstance.setDueDate(programStageInstance.getExecutionDate());
    }
    for (DataValue dataValue : event.getDataValues()) {
        EventDataValue eventDataValue = new EventDataValue();
        eventDataValue.setValue(dataValue.getValue());
        eventDataValue.setCreated(DateUtils.fromInstant(dataValue.getCreatedAt()));
        eventDataValue.setLastUpdated(new Date());
        eventDataValue.setProvidedElsewhere(dataValue.isProvidedElsewhere());
        // ensure dataElement is referred to by UID as multiple
        // dataElementIdSchemes are supported
        DataElement dataElement = preheat.get(DataElement.class, dataValue.getDataElement());
        eventDataValue.setDataElement(dataElement.getUid());
        eventDataValue.setLastUpdatedByUserInfo(UserInfoSnapshot.from(preheat.getUser()));
        User createdBy = preheat.getUsers().get(dataValue.getCreatedBy());
        eventDataValue.setCreatedByUserInfo(Optional.ofNullable(createdBy).map(u -> UserInfoSnapshot.from(createdBy)).orElseGet(() -> UserInfoSnapshot.from(preheat.getUser())));
        programStageInstance.getEventDataValues().add(eventDataValue);
    }
    if (isNotEmpty(event.getNotes())) {
        programStageInstance.getComments().addAll(notesConverterService.from(preheat, event.getNotes()));
    }
    return programStageInstance;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) User(org.hisp.dhis.user.User) DataValue(org.hisp.dhis.tracker.domain.DataValue) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) EventStatus(org.hisp.dhis.event.EventStatus) ProgramStage(org.hisp.dhis.program.ProgramStage) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) Date(java.util.Date) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo)

Example 67 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class DbChangeEventHandler method getDataValueId.

private Serializable getDataValueId(SourceRecord sourceRecord) {
    Schema schema = sourceRecord.keySchema();
    List<Field> allIdFields = schema.fields();
    Struct keyStruct = (Struct) sourceRecord.key();
    Long dataElementId = (Long) getIdFromField(keyStruct, allIdFields.get(0));
    Long periodId = (Long) getIdFromField(keyStruct, allIdFields.get(1));
    Long organisationUnitId = (Long) getIdFromField(keyStruct, allIdFields.get(2));
    Long categoryOptionComboId = (Long) getIdFromField(keyStruct, allIdFields.get(3));
    Long attributeOptionComboId = (Long) getIdFromField(keyStruct, allIdFields.get(4));
    DataElement dataElement = idObjectManager.get(DataElement.class, dataElementId);
    OrganisationUnit organisationUnit = idObjectManager.get(OrganisationUnit.class, organisationUnitId);
    CategoryOptionCombo categoryOptionCombo = idObjectManager.get(CategoryOptionCombo.class, categoryOptionComboId);
    CategoryOptionCombo attributeOptionCombo = idObjectManager.get(CategoryOptionCombo.class, attributeOptionComboId);
    Period period = periodService.getPeriod(periodId);
    return new DataValue(dataElement, period, organisationUnit, categoryOptionCombo, attributeOptionCombo);
}
Also used : Field(org.apache.kafka.connect.data.Field) DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataValue(org.hisp.dhis.datavalue.DataValue) Schema(org.apache.kafka.connect.data.Schema) Period(org.hisp.dhis.period.Period) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Struct(org.apache.kafka.connect.data.Struct)

Example 68 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class MinMaxDataElementStoreTest method testQuery.

@Test
void testQuery() {
    OrganisationUnit source1 = createOrganisationUnit('A');
    OrganisationUnit source2 = createOrganisationUnit('B');
    organisationUnitService.addOrganisationUnit(source1);
    organisationUnitService.addOrganisationUnit(source2);
    DataElement dataElement1 = createDataElement('A');
    DataElement dataElement2 = createDataElement('B');
    DataElement dataElement3 = createDataElement('C');
    DataElement dataElement4 = createDataElement('D');
    dataElementService.addDataElement(dataElement1);
    dataElementService.addDataElement(dataElement2);
    dataElementService.addDataElement(dataElement3);
    dataElementService.addDataElement(dataElement4);
    CategoryOptionCombo optionCombo = categoryService.getDefaultCategoryOptionCombo();
    MinMaxDataElement minMaxDataElement1 = new MinMaxDataElement(dataElement1, source1, optionCombo, 0, 100, false);
    MinMaxDataElement minMaxDataElement2 = new MinMaxDataElement(dataElement2, source2, optionCombo, 0, 100, false);
    MinMaxDataElement minMaxDataElement3 = new MinMaxDataElement(dataElement3, source2, optionCombo, 0, 100, false);
    MinMaxDataElement minMaxDataElement4 = new MinMaxDataElement(dataElement4, source2, optionCombo, 0, 100, false);
    minMaxDataElementStore.save(minMaxDataElement1);
    minMaxDataElementStore.save(minMaxDataElement2);
    minMaxDataElementStore.save(minMaxDataElement3);
    minMaxDataElementStore.save(minMaxDataElement4);
    MinMaxDataElementQueryParams params = new MinMaxDataElementQueryParams();
    List<String> filters = Lists.newArrayList();
    filters.add("dataElement.id:eq:" + dataElement1.getUid());
    params.setFilters(filters);
    List<MinMaxDataElement> result = minMaxDataElementStore.query(params);
    assertNotNull(result);
    assertEquals(1, result.size());
    params = new MinMaxDataElementQueryParams();
    filters.clear();
    filters.add("min:eq:0");
    params.setFilters(filters);
    result = minMaxDataElementStore.query(params);
    assertNotNull(result);
    assertEquals(4, result.size());
    filters.clear();
    filters.add("dataElement.id:in:[" + dataElement1.getUid() + "," + dataElement2.getUid() + "]");
    params.setFilters(filters);
    result = minMaxDataElementStore.query(params);
    assertNotNull(result);
    assertEquals(2, result.size());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 69 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class MinMaxDataElementStoreTest method testBasic.

@Test
void testBasic() {
    OrganisationUnit source1 = createOrganisationUnit('A');
    OrganisationUnit source2 = createOrganisationUnit('B');
    organisationUnitService.addOrganisationUnit(source1);
    organisationUnitService.addOrganisationUnit(source2);
    DataElement dataElement1 = createDataElement('A');
    DataElement dataElement2 = createDataElement('B');
    DataElement dataElement3 = createDataElement('C');
    DataElement dataElement4 = createDataElement('D');
    dataElementService.addDataElement(dataElement1);
    dataElementService.addDataElement(dataElement2);
    dataElementService.addDataElement(dataElement3);
    dataElementService.addDataElement(dataElement4);
    CategoryOptionCombo optionCombo = categoryService.getDefaultCategoryOptionCombo();
    MinMaxDataElement minMaxDataElement1 = new MinMaxDataElement(dataElement1, source1, optionCombo, 0, 100, false);
    MinMaxDataElement minMaxDataElement2 = new MinMaxDataElement(dataElement2, source2, optionCombo, 0, 100, false);
    MinMaxDataElement minMaxDataElement3 = new MinMaxDataElement(dataElement3, source2, optionCombo, 0, 100, false);
    MinMaxDataElement minMaxDataElement4 = new MinMaxDataElement(dataElement4, source2, optionCombo, 0, 100, false);
    minMaxDataElementStore.save(minMaxDataElement1);
    long mmdeid1 = minMaxDataElement1.getId();
    minMaxDataElementStore.save(minMaxDataElement2);
    minMaxDataElementStore.save(minMaxDataElement3);
    minMaxDataElementStore.save(minMaxDataElement4);
    // ----------------------------------------------------------------------
    // Assertions
    // ----------------------------------------------------------------------
    assertNotNull(minMaxDataElementStore.get(mmdeid1));
    assertTrue(minMaxDataElementStore.get(mmdeid1).getMax() == 100);
    List<DataElement> dataElements1 = new ArrayList<>();
    dataElements1.add(dataElement1);
    List<DataElement> dataElements2 = new ArrayList<>();
    dataElements2.add(dataElement2);
    dataElements2.add(dataElement3);
    dataElements2.add(dataElement4);
    assertNotNull(minMaxDataElementStore.get(source1, dataElement1, optionCombo));
    assertNull(minMaxDataElementStore.get(source2, dataElement1, optionCombo));
    assertEquals(1, minMaxDataElementStore.get(source1, dataElements1).size());
    assertEquals(3, minMaxDataElementStore.get(source2, dataElements2).size());
    minMaxDataElementStore.delete(minMaxDataElement1);
    assertNull(minMaxDataElementStore.get(mmdeid1));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElement(org.hisp.dhis.dataelement.DataElement) ArrayList(java.util.ArrayList) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 70 with CategoryOptionCombo

use of org.hisp.dhis.category.CategoryOptionCombo in project dhis2-core by dhis2.

the class DataApprovalController method removeApproval.

// -------------------------------------------------------------------------
// Delete
// -------------------------------------------------------------------------
@PreAuthorize("hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')")
@DeleteMapping(APPROVALS_PATH)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeApproval(@RequestParam(required = false) Set<String> ds, @RequestParam(required = false) Set<String> wf, @RequestParam String pe, @RequestParam String ou, @RequestParam(required = false) String aoc) throws WebMessageException {
    Set<DataApprovalWorkflow> workflows = getAndValidateWorkflows(ds, wf);
    Period period = getAndValidatePeriod(pe);
    OrganisationUnit organisationUnit = getAndValidateOrgUnit(ou);
    DataApprovalLevel dataApprovalLevel = getAndValidateApprovalLevel(organisationUnit);
    CategoryOptionCombo optionCombo = getAndValidateAttributeOptionCombo(aoc);
    User user = currentUserService.getCurrentUser();
    List<DataApproval> dataApprovalList = new ArrayList<>();
    for (DataApprovalWorkflow workflow : workflows) {
        dataApprovalList.addAll(getApprovalsAsList(dataApprovalLevel, workflow, period, organisationUnit, optionCombo, false, new Date(), user));
    }
    dataApprovalService.unapproveData(dataApprovalList);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataApprovalLevel(org.hisp.dhis.dataapproval.DataApprovalLevel) DataApproval(org.hisp.dhis.dataapproval.DataApproval) User(org.hisp.dhis.user.User) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Date(java.util.Date) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)218 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)94 DataElement (org.hisp.dhis.dataelement.DataElement)68 Period (org.hisp.dhis.period.Period)67 Test (org.junit.jupiter.api.Test)58 CategoryCombo (org.hisp.dhis.category.CategoryCombo)52 CategoryOption (org.hisp.dhis.category.CategoryOption)51 ArrayList (java.util.ArrayList)39 Program (org.hisp.dhis.program.Program)31 DataValue (org.hisp.dhis.datavalue.DataValue)30 Collectors (java.util.stream.Collectors)26 Category (org.hisp.dhis.category.Category)26 Date (java.util.Date)25 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)23 CategoryService (org.hisp.dhis.category.CategoryService)20 DataSet (org.hisp.dhis.dataset.DataSet)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 Event (org.hisp.dhis.tracker.domain.Event)20 ProgramInstance (org.hisp.dhis.program.ProgramInstance)16